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/TargetInstrItineraries.h" 00018 #include <cassert> 00019 #include <string> 00020 00021 namespace llvm { 00022 00023 class TargetData; 00024 class TargetSubtarget; 00025 class TargetInstrInfo; 00026 class TargetInstrDescriptor; 00027 class TargetJITInfo; 00028 class TargetLowering; 00029 class TargetFrameInfo; 00030 class MachineCodeEmitter; 00031 class MRegisterInfo; 00032 class Module; 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_, // Cannot be named PIC due to collision with -DPIC 00043 DynamicNoPIC 00044 }; 00045 } 00046 00047 // Code model types. 00048 namespace CodeModel { 00049 enum Model { 00050 Default, 00051 Small, 00052 Kernel, 00053 Medium, 00054 Large 00055 }; 00056 } 00057 00058 //===----------------------------------------------------------------------===// 00059 /// 00060 /// TargetMachine - Primary interface to the complete machine description for 00061 /// the target machine. All target-specific information should be accessible 00062 /// through this interface. 00063 /// 00064 class TargetMachine { 00065 const std::string Name; 00066 00067 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT 00068 void operator=(const TargetMachine&); // DO NOT IMPLEMENT 00069 protected: // Can only create subclasses... 00070 TargetMachine(const std::string &name) : Name(name) { }; 00071 00072 /// This constructor is used for targets that support arbitrary TargetData 00073 /// layouts, like the C backend. It initializes the TargetData to match that 00074 /// of the specified module. 00075 /// 00076 TargetMachine(const std::string &name, const Module &M); 00077 00078 /// getSubtargetImpl - virtual method implemented by subclasses that returns 00079 /// a reference to that target's TargetSubtarget-derived member variable. 00080 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; } 00081 public: 00082 virtual ~TargetMachine(); 00083 00084 /// getModuleMatchQuality - This static method should be implemented by 00085 /// targets to indicate how closely they match the specified module. This is 00086 /// used by the LLC tool to determine which target to use when an explicit 00087 /// -march option is not specified. If a target returns zero, it will never 00088 /// be chosen without an explicit -march option. 00089 static unsigned getModuleMatchQuality(const Module &M) { return 0; } 00090 00091 /// getJITMatchQuality - This static method should be implemented by targets 00092 /// that provide JIT capabilities to indicate how suitable they are for 00093 /// execution on the current host. If a value of 0 is returned, the target 00094 /// will not be used unless an explicit -march option is used. 00095 static unsigned getJITMatchQuality() { return 0; } 00096 00097 00098 const std::string &getName() const { return Name; } 00099 00100 // Interfaces to the major aspects of target machine information: 00101 // -- Instruction opcode and operand information 00102 // -- Pipelines and scheduling information 00103 // -- Stack frame information 00104 // -- Selection DAG lowering information 00105 // 00106 virtual const TargetInstrInfo *getInstrInfo() const { return 0; } 00107 virtual const TargetFrameInfo *getFrameInfo() const { return 0; } 00108 virtual TargetLowering *getTargetLowering() const { return 0; } 00109 virtual const TargetData *getTargetData() const { return 0; } 00110 00111 /// getSubtarget - This method returns a pointer to the specified type of 00112 /// TargetSubtarget. In debug builds, it verifies that the object being 00113 /// returned is of the correct type. 00114 template<typename STC> const STC &getSubtarget() const { 00115 const TargetSubtarget *TST = getSubtargetImpl(); 00116 assert(TST && dynamic_cast<const STC*>(TST) && 00117 "Not the right kind of subtarget!"); 00118 return *static_cast<const STC*>(TST); 00119 } 00120 00121 /// getRegisterInfo - If register information is available, return it. If 00122 /// not, return null. This is kept separate from RegInfo until RegInfo has 00123 /// details of graph coloring register allocation removed from it. 00124 /// 00125 virtual const MRegisterInfo* getRegisterInfo() const { return 0; } 00126 00127 /// getJITInfo - If this target supports a JIT, return information for it, 00128 /// otherwise return null. 00129 /// 00130 virtual TargetJITInfo *getJITInfo() { return 0; } 00131 00132 /// getInstrItineraryData - Returns instruction itinerary data for the target 00133 /// or specific subtarget. 00134 /// 00135 virtual const InstrItineraryData getInstrItineraryData() const { 00136 return InstrItineraryData(); 00137 } 00138 00139 /// getRelocationModel - Returns the code generation relocation model. The 00140 /// choices are static, PIC, and dynamic-no-pic, and target default. 00141 static Reloc::Model getRelocationModel(); 00142 00143 /// setRelocationModel - Sets the code generation relocation model. 00144 static void setRelocationModel(Reloc::Model Model); 00145 00146 /// getCodeModel - Returns the code model. The choices are small, kernel, 00147 /// medium, large, and target default. 00148 static CodeModel::Model getCodeModel(); 00149 00150 /// setCodeModel - Sets the code model. 00151 static void setCodeModel(CodeModel::Model Model); 00152 00153 /// CodeGenFileType - These enums are meant to be passed into 00154 /// addPassesToEmitFile to indicate what type of file to emit. 00155 enum CodeGenFileType { 00156 AssemblyFile, ObjectFile, DynamicLibrary 00157 }; 00158 00159 /// addPassesToEmitFile - Add passes to the specified pass manager to get 00160 /// the specified file emitted. Typically this will involve several steps of 00161 /// code generation. If Fast is set to true, the code generator should emit 00162 /// code as fast as possible, without regard for compile time. This method 00163 /// should return true if emission of this file type is not supported. 00164 /// 00165 virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out, 00166 CodeGenFileType FileType, bool Fast) { 00167 return true; 00168 } 00169 00170 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to 00171 /// get machine code emitted. This uses a MachineCodeEmitter object to handle 00172 /// actually outputting the machine code and resolving things like the address 00173 /// of functions. This method should returns true if machine code emission is 00174 /// not supported. 00175 /// 00176 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM, 00177 MachineCodeEmitter &MCE) { 00178 return true; 00179 } 00180 }; 00181 00182 } // End llvm namespace 00183 00184 #endif