Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 1 | //===-LTOCodeGenerator.h - LLVM Link Time Optimizer -----------------------===// |
| 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 declares the LTOCodeGenerator class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | |
| 15 | #ifndef LTO_CODE_GENERATOR_H |
| 16 | #define LTO_CODE_GENERATOR_H |
| 17 | |
| 18 | #include "llvm/Linker.h" |
Owen Anderson | 8b477ed | 2009-07-01 16:58:40 +0000 | [diff] [blame] | 19 | #include "llvm/LLVMContext.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringMap.h" |
Devang Patel | a93ae71 | 2008-07-03 22:53:14 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 22 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 23 | #include <string> |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 24 | |
| 25 | |
| 26 | // |
| 27 | // C++ class which implements the opaque lto_code_gen_t |
| 28 | // |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 29 | |
Douglas Gregor | 1f29105 | 2009-12-23 17:05:07 +0000 | [diff] [blame] | 30 | struct LTOCodeGenerator { |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 31 | static const char* getVersionString(); |
| 32 | |
Owen Anderson | 0e7a546 | 2009-07-02 00:31:14 +0000 | [diff] [blame] | 33 | LTOCodeGenerator(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 34 | ~LTOCodeGenerator(); |
| 35 | |
Douglas Gregor | 7aed446 | 2009-12-23 18:27:13 +0000 | [diff] [blame] | 36 | bool addModule(struct LTOModule*, std::string& errMsg); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 37 | bool setDebugInfo(lto_debug_model, std::string& errMsg); |
| 38 | bool setCodePICModel(lto_codegen_model, std::string& errMsg); |
Rafael Espindola | 2d643ef | 2010-08-11 00:15:13 +0000 | [diff] [blame] | 39 | void setCpu(const char *cpu); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 40 | void addMustPreserveSymbol(const char* sym); |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 41 | bool writeMergedModules(const char* path, |
| 42 | std::string& errMsg); |
| 43 | const void* compile(size_t* length, std::string& errMsg); |
Nick Kledzik | 920ae98 | 2008-07-08 21:14:10 +0000 | [diff] [blame] | 44 | void setCodeGenDebugOptions(const char *opts); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 45 | private: |
Rafael Espindola | e9efea1 | 2011-02-24 21:04:06 +0000 | [diff] [blame^] | 46 | bool generateObjectFile(llvm::raw_ostream& out, |
| 47 | std::string& errMsg); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 48 | void applyScopeRestrictions(); |
| 49 | bool determineTarget(std::string& errMsg); |
| 50 | |
| 51 | typedef llvm::StringMap<uint8_t> StringSet; |
| 52 | |
Owen Anderson | 4434ed4 | 2009-07-01 23:13:44 +0000 | [diff] [blame] | 53 | llvm::LLVMContext& _context; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 54 | llvm::Linker _linker; |
| 55 | llvm::TargetMachine* _target; |
| 56 | bool _emitDwarfDebugInfo; |
| 57 | bool _scopeRestrictionsDone; |
| 58 | lto_codegen_model _codeModel; |
| 59 | StringSet _mustPreserveSymbols; |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 60 | llvm::MemoryBuffer* _nativeObjectFile; |
Nick Kledzik | 920ae98 | 2008-07-08 21:14:10 +0000 | [diff] [blame] | 61 | std::vector<const char*> _codegenOptions; |
Rafael Espindola | 2d643ef | 2010-08-11 00:15:13 +0000 | [diff] [blame] | 62 | std::string _mCpu; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #endif // LTO_CODE_GENERATOR_H |
| 66 | |