1 //===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the general parts of a Target machine.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_TARGETMACHINE_H
15 #define LLVM_TARGET_TARGETMACHINE_H
17 #include "llvm/Target/TargetData.h"
22 class TargetInstrInfo;
23 class TargetInstrDescriptor;
24 class TargetSchedInfo;
26 class TargetFrameInfo;
27 class TargetCacheInfo;
28 class MachineCodeEmitter;
30 class FunctionPassManager;
34 //===----------------------------------------------------------------------===//
36 /// TargetMachine - Primary interface to the complete machine description for
37 /// the target machine. All target-specific information should be accessible
38 /// through this interface.
41 const std::string Name;
42 const TargetData DataLayout; // Calculates type size & alignment
44 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT
45 void operator=(const TargetMachine&); // DO NOT IMPLEMENT
47 TargetMachine(const std::string &name, // Can only create subclasses...
48 bool LittleEndian = false,
49 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
50 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
51 unsigned char LongAl = 8, unsigned char IntAl = 4,
52 unsigned char ShortAl = 2, unsigned char ByteAl = 1)
53 : Name(name), DataLayout(name, LittleEndian,
54 PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
55 IntAl, ShortAl, ByteAl) {}
57 virtual ~TargetMachine() {}
59 const std::string &getName() const { return Name; }
61 // Interfaces to the major aspects of target machine information:
62 // -- Instruction opcode and operand information
63 // -- Pipelines and scheduling information
64 // -- Register information
65 // -- Stack frame information
66 // -- Cache hierarchy information
67 // -- Machine-level optimization information (peephole only)
69 virtual const TargetInstrInfo& getInstrInfo() const = 0;
70 virtual const TargetSchedInfo& getSchedInfo() const = 0;
71 virtual const TargetRegInfo& getRegInfo() const = 0;
72 virtual const TargetFrameInfo& getFrameInfo() const = 0;
73 virtual const TargetCacheInfo& getCacheInfo() const = 0;
74 const TargetData &getTargetData() const { return DataLayout; }
76 /// getRegisterInfo - If register information is available, return it. If
77 /// not, return null. This is kept separate from RegInfo until RegInfo has
78 /// details of graph coloring register allocation removed from it.
80 virtual const MRegisterInfo* getRegisterInfo() const { return 0; }
82 // Data storage information
84 virtual unsigned findOptimalStorageSize(const Type* ty) const;
86 /// addPassesToJITCompile - Add passes to the specified pass manager to
87 /// implement a fast dynamic compiler for this target. Return true if this is
88 /// not supported for this target.
90 virtual bool addPassesToJITCompile(FunctionPassManager &PM) { return true; }
92 /// addPassesToEmitAssembly - Add passes to the specified pass manager to get
93 /// assembly langage code emitted. Typically this will involve several steps
94 /// of code generation. This method should return true if assembly emission
97 virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
101 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
102 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
103 /// actually outputting the machine code and resolving things like the address
104 /// of functions. This method should returns true if machine code emission is
107 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
108 MachineCodeEmitter &MCE) {
112 /// replaceMachineCodeForFunction - Make it so that calling the
113 /// function whose machine code is at OLD turns into a call to NEW,
114 /// perhaps by overwriting OLD with a branch to NEW.
116 /// FIXME: this is JIT-specific.
118 virtual void replaceMachineCodeForFunction (void *Old, void *New) {
119 assert (0 && "Current target cannot replace machine code for functions");
122 /// getJITStubForFunction - Create or return a stub for the specified
123 /// function. This stub acts just like the specified function, except that it
124 /// allows the "address" of the function to be taken without having to
125 /// generate code for it.
126 virtual void *getJITStubForFunction(Function *F, MachineCodeEmitter &MCE) {
131 } // End llvm namespace