Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
13 KiB

  1. //===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the TargetMachine and LLVMTargetMachine classes.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TARGET_TARGETMACHINE_H
  14. #define LLVM_TARGET_TARGETMACHINE_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/Pass.h"
  17. #include "llvm/Support/CodeGen.h"
  18. #include "llvm/Target/TargetOptions.h"
  19. #include <cassert>
  20. #include <string>
  21. namespace llvm {
  22. class InstrItineraryData;
  23. class JITCodeEmitter;
  24. class GlobalValue;
  25. class MCAsmInfo;
  26. class MCCodeGenInfo;
  27. class MCContext;
  28. class PassManagerBase;
  29. class Target;
  30. class DataLayout;
  31. class TargetFrameLowering;
  32. class TargetInstrInfo;
  33. class TargetIntrinsicInfo;
  34. class TargetJITInfo;
  35. class TargetLowering;
  36. class TargetPassConfig;
  37. class TargetRegisterInfo;
  38. class TargetSelectionDAGInfo;
  39. class TargetSubtargetInfo;
  40. class ScalarTargetTransformInfo;
  41. class VectorTargetTransformInfo;
  42. class formatted_raw_ostream;
  43. class raw_ostream;
  44. //===----------------------------------------------------------------------===//
  45. ///
  46. /// TargetMachine - Primary interface to the complete machine description for
  47. /// the target machine. All target-specific information should be accessible
  48. /// through this interface.
  49. ///
  50. class TargetMachine {
  51. TargetMachine(const TargetMachine &) LLVM_DELETED_FUNCTION;
  52. void operator=(const TargetMachine &) LLVM_DELETED_FUNCTION;
  53. protected: // Can only create subclasses.
  54. TargetMachine(const Target &T, StringRef TargetTriple,
  55. StringRef CPU, StringRef FS, const TargetOptions &Options);
  56. /// TheTarget - The Target that this machine was created for.
  57. const Target &TheTarget;
  58. /// TargetTriple, TargetCPU, TargetFS - Triple string, CPU name, and target
  59. /// feature strings the TargetMachine instance is created with.
  60. std::string TargetTriple;
  61. std::string TargetCPU;
  62. std::string TargetFS;
  63. /// CodeGenInfo - Low level target information such as relocation model.
  64. const MCCodeGenInfo *CodeGenInfo;
  65. /// AsmInfo - Contains target specific asm information.
  66. ///
  67. const MCAsmInfo *AsmInfo;
  68. unsigned MCRelaxAll : 1;
  69. unsigned MCNoExecStack : 1;
  70. unsigned MCSaveTempLabels : 1;
  71. unsigned MCUseLoc : 1;
  72. unsigned MCUseCFI : 1;
  73. unsigned MCUseDwarfDirectory : 1;
  74. public:
  75. virtual ~TargetMachine();
  76. const Target &getTarget() const { return TheTarget; }
  77. const StringRef getTargetTriple() const { return TargetTriple; }
  78. const StringRef getTargetCPU() const { return TargetCPU; }
  79. const StringRef getTargetFeatureString() const { return TargetFS; }
  80. /// getSubtargetImpl - virtual method implemented by subclasses that returns
  81. /// a reference to that target's TargetSubtargetInfo-derived member variable.
  82. virtual const TargetSubtargetInfo *getSubtargetImpl() const { return 0; }
  83. mutable TargetOptions Options;
  84. /// \brief Reset the target options based on the function's attributes.
  85. void resetTargetOptions(const MachineFunction *MF) const;
  86. // Interfaces to the major aspects of target machine information:
  87. // -- Instruction opcode and operand information
  88. // -- Pipelines and scheduling information
  89. // -- Stack frame information
  90. // -- Selection DAG lowering information
  91. //
  92. virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
  93. virtual const TargetFrameLowering *getFrameLowering() const { return 0; }
  94. virtual const TargetLowering *getTargetLowering() const { return 0; }
  95. virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
  96. virtual const DataLayout *getDataLayout() const { return 0; }
  97. /// getMCAsmInfo - Return target specific asm information.
  98. ///
  99. const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
  100. /// getSubtarget - This method returns a pointer to the specified type of
  101. /// TargetSubtargetInfo. In debug builds, it verifies that the object being
  102. /// returned is of the correct type.
  103. template<typename STC> const STC &getSubtarget() const {
  104. return *static_cast<const STC*>(getSubtargetImpl());
  105. }
  106. /// getRegisterInfo - If register information is available, return it. If
  107. /// not, return null. This is kept separate from RegInfo until RegInfo has
  108. /// details of graph coloring register allocation removed from it.
  109. ///
  110. virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
  111. /// getIntrinsicInfo - If intrinsic information is available, return it. If
  112. /// not, return null.
  113. ///
  114. virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { return 0; }
  115. /// getJITInfo - If this target supports a JIT, return information for it,
  116. /// otherwise return null.
  117. ///
  118. virtual TargetJITInfo *getJITInfo() { return 0; }
  119. /// getInstrItineraryData - Returns instruction itinerary data for the target
  120. /// or specific subtarget.
  121. ///
  122. virtual const InstrItineraryData *getInstrItineraryData() const {
  123. return 0;
  124. }
  125. /// hasMCRelaxAll - Check whether all machine code instructions should be
  126. /// relaxed.
  127. bool hasMCRelaxAll() const { return MCRelaxAll; }
  128. /// setMCRelaxAll - Set whether all machine code instructions should be
  129. /// relaxed.
  130. void setMCRelaxAll(bool Value) { MCRelaxAll = Value; }
  131. /// hasMCSaveTempLabels - Check whether temporary labels will be preserved
  132. /// (i.e., not treated as temporary).
  133. bool hasMCSaveTempLabels() const { return MCSaveTempLabels; }
  134. /// setMCSaveTempLabels - Set whether temporary labels will be preserved
  135. /// (i.e., not treated as temporary).
  136. void setMCSaveTempLabels(bool Value) { MCSaveTempLabels = Value; }
  137. /// hasMCNoExecStack - Check whether an executable stack is not needed.
  138. bool hasMCNoExecStack() const { return MCNoExecStack; }
  139. /// setMCNoExecStack - Set whether an executabel stack is not needed.
  140. void setMCNoExecStack(bool Value) { MCNoExecStack = Value; }
  141. /// hasMCUseLoc - Check whether we should use dwarf's .loc directive.
  142. bool hasMCUseLoc() const { return MCUseLoc; }
  143. /// setMCUseLoc - Set whether all we should use dwarf's .loc directive.
  144. void setMCUseLoc(bool Value) { MCUseLoc = Value; }
  145. /// hasMCUseCFI - Check whether we should use dwarf's .cfi_* directives.
  146. bool hasMCUseCFI() const { return MCUseCFI; }
  147. /// setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
  148. void setMCUseCFI(bool Value) { MCUseCFI = Value; }
  149. /// hasMCUseDwarfDirectory - Check whether we should use .file directives with
  150. /// explicit directories.
  151. bool hasMCUseDwarfDirectory() const { return MCUseDwarfDirectory; }
  152. /// setMCUseDwarfDirectory - Set whether all we should use .file directives
  153. /// with explicit directories.
  154. void setMCUseDwarfDirectory(bool Value) { MCUseDwarfDirectory = Value; }
  155. /// getRelocationModel - Returns the code generation relocation model. The
  156. /// choices are static, PIC, and dynamic-no-pic, and target default.
  157. Reloc::Model getRelocationModel() const;
  158. /// getCodeModel - Returns the code model. The choices are small, kernel,
  159. /// medium, large, and target default.
  160. CodeModel::Model getCodeModel() const;
  161. /// getTLSModel - Returns the TLS model which should be used for the given
  162. /// global variable.
  163. TLSModel::Model getTLSModel(const GlobalValue *GV) const;
  164. /// getOptLevel - Returns the optimization level: None, Less,
  165. /// Default, or Aggressive.
  166. CodeGenOpt::Level getOptLevel() const;
  167. void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
  168. bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
  169. /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
  170. ///
  171. static bool getAsmVerbosityDefault();
  172. /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
  173. /// is false.
  174. static void setAsmVerbosityDefault(bool);
  175. /// getDataSections - Return true if data objects should be emitted into their
  176. /// own section, corresponds to -fdata-sections.
  177. static bool getDataSections();
  178. /// getFunctionSections - Return true if functions should be emitted into
  179. /// their own section, corresponding to -ffunction-sections.
  180. static bool getFunctionSections();
  181. /// setDataSections - Set if the data are emit into separate sections.
  182. static void setDataSections(bool);
  183. /// setFunctionSections - Set if the functions are emit into separate
  184. /// sections.
  185. static void setFunctionSections(bool);
  186. /// \brief Register analysis passes for this target with a pass manager.
  187. virtual void addAnalysisPasses(PassManagerBase &) {}
  188. /// CodeGenFileType - These enums are meant to be passed into
  189. /// addPassesToEmitFile to indicate what type of file to emit, and returned by
  190. /// it to indicate what type of file could actually be made.
  191. enum CodeGenFileType {
  192. CGFT_AssemblyFile,
  193. CGFT_ObjectFile,
  194. CGFT_Null // Do not emit any output.
  195. };
  196. /// addPassesToEmitFile - Add passes to the specified pass manager to get the
  197. /// specified file emitted. Typically this will involve several steps of code
  198. /// generation. This method should return true if emission of this file type
  199. /// is not supported, or false on success.
  200. virtual bool addPassesToEmitFile(PassManagerBase &,
  201. formatted_raw_ostream &,
  202. CodeGenFileType,
  203. bool /*DisableVerify*/ = true,
  204. AnalysisID StartAfter = 0,
  205. AnalysisID StopAfter = 0) {
  206. return true;
  207. }
  208. /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
  209. /// get machine code emitted. This uses a JITCodeEmitter object to handle
  210. /// actually outputting the machine code and resolving things like the address
  211. /// of functions. This method returns true if machine code emission is
  212. /// not supported.
  213. ///
  214. virtual bool addPassesToEmitMachineCode(PassManagerBase &,
  215. JITCodeEmitter &,
  216. bool /*DisableVerify*/ = true) {
  217. return true;
  218. }
  219. /// addPassesToEmitMC - Add passes to the specified pass manager to get
  220. /// machine code emitted with the MCJIT. This method returns true if machine
  221. /// code is not supported. It fills the MCContext Ctx pointer which can be
  222. /// used to build custom MCStreamer.
  223. ///
  224. virtual bool addPassesToEmitMC(PassManagerBase &,
  225. MCContext *&,
  226. raw_ostream &,
  227. bool /*DisableVerify*/ = true) {
  228. return true;
  229. }
  230. };
  231. /// LLVMTargetMachine - This class describes a target machine that is
  232. /// implemented with the LLVM target-independent code generator.
  233. ///
  234. class LLVMTargetMachine : public TargetMachine {
  235. protected: // Can only create subclasses.
  236. LLVMTargetMachine(const Target &T, StringRef TargetTriple,
  237. StringRef CPU, StringRef FS, TargetOptions Options,
  238. Reloc::Model RM, CodeModel::Model CM,
  239. CodeGenOpt::Level OL);
  240. public:
  241. /// \brief Register analysis passes for this target with a pass manager.
  242. ///
  243. /// This registers target independent analysis passes.
  244. virtual void addAnalysisPasses(PassManagerBase &PM);
  245. /// createPassConfig - Create a pass configuration object to be used by
  246. /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
  247. virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
  248. /// addPassesToEmitFile - Add passes to the specified pass manager to get the
  249. /// specified file emitted. Typically this will involve several steps of code
  250. /// generation.
  251. virtual bool addPassesToEmitFile(PassManagerBase &PM,
  252. formatted_raw_ostream &Out,
  253. CodeGenFileType FileType,
  254. bool DisableVerify = true,
  255. AnalysisID StartAfter = 0,
  256. AnalysisID StopAfter = 0);
  257. /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
  258. /// get machine code emitted. This uses a JITCodeEmitter object to handle
  259. /// actually outputting the machine code and resolving things like the address
  260. /// of functions. This method returns true if machine code emission is
  261. /// not supported.
  262. ///
  263. virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
  264. JITCodeEmitter &MCE,
  265. bool DisableVerify = true);
  266. /// addPassesToEmitMC - Add passes to the specified pass manager to get
  267. /// machine code emitted with the MCJIT. This method returns true if machine
  268. /// code is not supported. It fills the MCContext Ctx pointer which can be
  269. /// used to build custom MCStreamer.
  270. ///
  271. virtual bool addPassesToEmitMC(PassManagerBase &PM,
  272. MCContext *&Ctx,
  273. raw_ostream &OS,
  274. bool DisableVerify = true);
  275. /// addCodeEmitter - This pass should be overridden by the target to add a
  276. /// code emitter, if supported. If this is not supported, 'true' should be
  277. /// returned.
  278. virtual bool addCodeEmitter(PassManagerBase &,
  279. JITCodeEmitter &) {
  280. return true;
  281. }
  282. };
  283. } // End llvm namespace
  284. #endif