1 //===- TargetMachine.h ----------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef MCLD_CODEGEN_TARGETMACHINE_H 10 #define MCLD_CODEGEN_TARGETMACHINE_H 11 #include <llvm/Support/CodeGen.h> 12 #include <string> 13 14 namespace llvm { 15 16 class Target; 17 class TargetData; 18 class TargetMachine; 19 class MCContext; 20 class raw_ostream; 21 class formatted_raw_ostream; 22 namespace legacy { 23 class PassManagerBase; 24 } // namepsace legacy 25 } // namespace llvm 26 27 namespace mcld { 28 29 class Module; 30 class Target; 31 class FileHandle; 32 class LinkerConfig; 33 class ToolOutputFile; 34 35 enum CodeGenFileType { 36 CGFT_ASMFile, 37 CGFT_OBJFile, 38 CGFT_DSOFile, 39 CGFT_EXEFile, 40 CGFT_PARTIAL, 41 CGFT_BINARY, 42 CGFT_NULLFile 43 }; 44 45 46 /** \class mcld::MCLDTargetMachine 47 * \brief mcld::MCLDTargetMachine is a object adapter of LLVMTargetMachine. 48 */ 49 class MCLDTargetMachine 50 { 51 public: 52 /// Adapter of llvm::TargetMachine 53 /// 54 MCLDTargetMachine(llvm::TargetMachine& pTM, 55 const llvm::Target& pLLMVTarget, 56 const mcld::Target& pMCLDTarget, 57 const std::string& pTriple); 58 59 virtual ~MCLDTargetMachine(); 60 61 /// getTarget - adapt llvm::TargetMachine::getTarget 62 const mcld::Target& getTarget() const; 63 64 /// getTM - return adapted the llvm::TargetMachine. getTM()65 const llvm::TargetMachine& getTM() const { return m_TM; } getTM()66 llvm::TargetMachine& getTM() { return m_TM; } 67 68 /// appPassesToEmitFile - The target function which we has to modify as 69 /// upstreaming. 70 bool addPassesToEmitFile(llvm::legacy::PassManagerBase &, 71 mcld::ToolOutputFile& pOutput, 72 mcld::CodeGenFileType, 73 llvm::CodeGenOpt::Level, 74 mcld::Module& pModule, 75 mcld::LinkerConfig& pConfig, 76 bool DisableVerify = true); 77 78 private: 79 /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for 80 /// both emitting to assembly files or machine code output. 81 bool addCommonCodeGenPasses(llvm::legacy::PassManagerBase &, 82 mcld::CodeGenFileType, 83 llvm::CodeGenOpt::Level, 84 bool DisableVerify, 85 llvm::MCContext *&OutCtx); 86 87 bool addCompilerPasses(llvm::legacy::PassManagerBase &pPM, 88 llvm::formatted_raw_ostream &pOutput, 89 llvm::MCContext *&OutCtx); 90 91 bool addAssemblerPasses(llvm::legacy::PassManagerBase &pPM, 92 llvm::raw_ostream &pOutput, 93 llvm::MCContext *&OutCtx); 94 95 bool addLinkerPasses(llvm::legacy::PassManagerBase &pPM, 96 mcld::LinkerConfig& pConfig, 97 mcld::Module& pModule, 98 mcld::FileHandle& pFileHandle, 99 llvm::MCContext *&OutCtx); 100 101 private: 102 llvm::TargetMachine &m_TM; 103 const llvm::Target *m_pLLVMTarget; 104 const mcld::Target *m_pMCLDTarget; 105 const std::string& m_Triple; 106 }; 107 108 } // namespace of mcld 109 110 #endif 111 112