LLVM API Documentation
00001 //===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file describes the general parts of a Target machine. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_TARGET_TARGETMACHINE_H 00015 #define LLVM_TARGET_TARGETMACHINE_H 00016 00017 #include "llvm/Target/TargetData.h" 00018 #include "llvm/Target/TargetInstrItineraries.h" 00019 #include <cassert> 00020 00021 namespace llvm { 00022 00023 class TargetSubtarget; 00024 class TargetInstrInfo; 00025 class TargetInstrDescriptor; 00026 class TargetJITInfo; 00027 class TargetLowering; 00028 class TargetSchedInfo; 00029 class SparcV9RegInfo; 00030 class TargetFrameInfo; 00031 class MachineCodeEmitter; 00032 class MRegisterInfo; 00033 class FunctionPassManager; 00034 class PassManager; 00035 class Pass; 00036 00037 // Relocation model types. 00038 namespace Reloc { 00039 enum Model { 00040 Default, 00041 Static, 00042 PIC, 00043 DynamicNoPIC 00044 }; 00045 } 00046 00047 //===----------------------------------------------------------------------===// 00048 /// 00049 /// TargetMachine - Primary interface to the complete machine description for 00050 /// the target machine. All target-specific information should be accessible 00051 /// through this interface. 00052 /// 00053 class TargetMachine { 00054 const std::string Name; 00055 const TargetData DataLayout; // Calculates type size & alignment 00056 00057 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT 00058 void operator=(const TargetMachine&); // DO NOT IMPLEMENT 00059 protected: // Can only create subclasses... 00060 TargetMachine(const std::string &name, bool LittleEndian = false, 00061 unsigned char PtrSize = 8, unsigned char PtrAl = 8, 00062 unsigned char DoubleAl = 8, unsigned char FloatAl = 4, 00063 unsigned char LongAl = 8, unsigned char IntAl = 4, 00064 unsigned char ShortAl = 2, unsigned char ByteAl = 1, 00065 unsigned char BoolAl = 1); 00066 00067 TargetMachine(const std::string &name, const TargetData &TD); 00068 00069 /// This constructor is used for targets that support arbitrary TargetData 00070 /// layouts, like the C backend. It initializes the TargetData to match that 00071 /// of the specified module. 00072 /// 00073 TargetMachine(const std::string &name, const Module &M); 00074 00075 /// getSubtargetImpl - virtual method implemented by subclasses that returns 00076 /// a reference to that target's TargetSubtarget-derived member variable. 00077 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; } 00078 public: 00079 virtual ~TargetMachine(); 00080 00081 /// getModuleMatchQuality - This static method should be implemented by 00082 /// targets to indicate how closely they match the specified module. This is 00083 /// used by the LLC tool to determine which target to use when an explicit 00084 /// -march option is not specified. If a target returns zero, it will never 00085 /// be chosen without an explicit -march option. 00086 static unsigned getModuleMatchQuality(const Module &M) { return 0; } 00087 00088 /// getJITMatchQuality - This static method should be implemented by targets 00089 /// that provide JIT capabilities to indicate how suitable they are for 00090 /// execution on the current host. If a value of 0 is returned, the target 00091 /// will not be used unless an explicit -march option is used. 00092 static unsigned getJITMatchQuality() { return 0; } 00093 00094 00095 const std::string &getName() const { return Name; } 00096 00097 // Interfaces to the major aspects of target machine information: 00098 // -- Instruction opcode and operand information 00099 // -- Pipelines and scheduling information 00100 // -- Stack frame information 00101 // -- Selection DAG lowering information 00102 // 00103 virtual const TargetInstrInfo *getInstrInfo() const { return 0; } 00104 virtual const TargetFrameInfo *getFrameInfo() const { return 0; } 00105 virtual TargetLowering *getTargetLowering() const { return 0; } 00106 const TargetData &getTargetData() const { return DataLayout; } 00107 00108 /// getSubtarget - This method returns a pointer to the specified type of 00109 /// TargetSubtarget. In debug builds, it verifies that the object being 00110 /// returned is of the correct type. 00111 template<typename STC> const STC &getSubtarget() const { 00112 const TargetSubtarget *TST = getSubtargetImpl(); 00113 assert(TST && dynamic_cast<const STC*>(TST) && 00114 "Not the right kind of subtarget!"); 00115 return *static_cast<const STC*>(TST); 00116 } 00117 00118 /// getRegisterInfo - If register information is available, return it. If 00119 /// not, return null. This is kept separate from RegInfo until RegInfo has 00120 /// details of graph coloring register allocation removed from it. 00121 /// 00122 virtual const MRegisterInfo* getRegisterInfo() const { return 0; } 00123 00124 /// getJITInfo - If this target supports a JIT, return information for it, 00125 /// otherwise return null. 00126 /// 00127 virtual TargetJITInfo *getJITInfo() { return 0; } 00128 00129 /// getInstrItineraryData - Returns instruction itinerary data for the target 00130 /// or specific subtarget. 00131 /// 00132 virtual const InstrItineraryData getInstrItineraryData() const { 00133 return InstrItineraryData(); 00134 } 00135 00136 // These are deprecated interfaces. 00137 virtual const TargetSchedInfo *getSchedInfo() const { return 0; } 00138 virtual const SparcV9RegInfo *getRegInfo() const { return 0; } 00139 00140 /// getRelocationModel - Returns the code generation relocation model. The 00141 /// choices are static, PIC, and dynamic-no-pic, and target default. 00142 static Reloc::Model getRelocationModel(); 00143 00144 /// setRelocationModel - Sets the code generation relocation model. 00145 static void setRelocationModel(Reloc::Model Model); 00146 00147 /// CodeGenFileType - These enums are meant to be passed into 00148 /// addPassesToEmitFile to indicate what type of file to emit. 00149 enum CodeGenFileType { 00150 AssemblyFile, ObjectFile, DynamicLibrary 00151 }; 00152 00153 /// addPassesToEmitFile - Add passes to the specified pass manager to get 00154 /// the specified file emitted. Typically this will involve several steps of 00155 /// code generation. If Fast is set to true, the code generator should emit 00156 /// code as fast as possible, without regard for compile time. This method 00157 /// should return true if emission of this file type is not supported. 00158 /// 00159 virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out, 00160 CodeGenFileType FileType, bool Fast) { 00161 return true; 00162 } 00163 00164 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to 00165 /// get machine code emitted. This uses a MachineCodeEmitter object to handle 00166 /// actually outputting the machine code and resolving things like the address 00167 /// of functions. This method should returns true if machine code emission is 00168 /// not supported. 00169 /// 00170 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM, 00171 MachineCodeEmitter &MCE) { 00172 return true; 00173 } 00174 }; 00175 00176 } // End llvm namespace 00177 00178 #endif