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. |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Bill Wendling | ab53bc7 | 2012-03-31 11:10:35 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file declares the LTOCodeGenerator class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 13 | |
| 14 | #ifndef LTO_CODE_GENERATOR_H |
| 15 | #define LTO_CODE_GENERATOR_H |
| 16 | |
| 17 | #include "llvm/Linker.h" |
| 18 | #include "llvm/ADT/StringMap.h" |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallPtrSet.h" |
Bill Wendling | ab53bc7 | 2012-03-31 11:10:35 +0000 | [diff] [blame] | 20 | #include "llvm-c/lto.h" |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 21 | #include <string> |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 22 | |
Bill Wendling | ab53bc7 | 2012-03-31 11:10:35 +0000 | [diff] [blame] | 23 | namespace llvm { |
| 24 | class LLVMContext; |
| 25 | class GlobalValue; |
| 26 | class Mangler; |
| 27 | class MemoryBuffer; |
| 28 | class TargetMachine; |
| 29 | class raw_ostream; |
| 30 | } |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 31 | |
Bill Wendling | ab53bc7 | 2012-03-31 11:10:35 +0000 | [diff] [blame] | 32 | //===----------------------------------------------------------------------===// |
| 33 | /// LTOCodeGenerator - C++ class which implements the opaque lto_code_gen_t |
| 34 | /// type. |
| 35 | /// |
Douglas Gregor | 1f29105 | 2009-12-23 17:05:07 +0000 | [diff] [blame] | 36 | struct LTOCodeGenerator { |
Bill Wendling | ab53bc7 | 2012-03-31 11:10:35 +0000 | [diff] [blame] | 37 | static const char *getVersionString(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 38 | |
Bill Wendling | ab53bc7 | 2012-03-31 11:10:35 +0000 | [diff] [blame] | 39 | LTOCodeGenerator(); |
| 40 | ~LTOCodeGenerator(); |
| 41 | |
| 42 | bool addModule(struct LTOModule*, std::string &errMsg); |
| 43 | bool setDebugInfo(lto_debug_model, std::string &errMsg); |
| 44 | bool setCodePICModel(lto_codegen_model, std::string &errMsg); |
Bill Wendling | 7baa27d | 2012-03-31 11:25:18 +0000 | [diff] [blame] | 45 | |
| 46 | void setCpu(const char* mCpu) { _mCpu = mCpu; } |
| 47 | |
| 48 | void addMustPreserveSymbol(const char* sym) { |
| 49 | _mustPreserveSymbols[sym] = 1; |
| 50 | } |
| 51 | |
Bill Wendling | ab53bc7 | 2012-03-31 11:10:35 +0000 | [diff] [blame] | 52 | bool writeMergedModules(const char *path, std::string &errMsg); |
| 53 | bool compile_to_file(const char **name, std::string &errMsg); |
| 54 | const void *compile(size_t *length, std::string &errMsg); |
| 55 | void setCodeGenDebugOptions(const char *opts); |
| 56 | |
| 57 | private: |
| 58 | bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg); |
| 59 | void applyScopeRestrictions(); |
| 60 | void applyRestriction(llvm::GlobalValue &GV, |
| 61 | std::vector<const char*> &mustPreserveList, |
| 62 | llvm::SmallPtrSet<llvm::GlobalValue*, 8> &asmUsed, |
| 63 | llvm::Mangler &mangler); |
| 64 | bool determineTarget(std::string &errMsg); |
| 65 | |
| 66 | typedef llvm::StringMap<uint8_t> StringSet; |
| 67 | |
| 68 | llvm::LLVMContext& _context; |
| 69 | llvm::Linker _linker; |
| 70 | llvm::TargetMachine* _target; |
| 71 | bool _emitDwarfDebugInfo; |
| 72 | bool _scopeRestrictionsDone; |
| 73 | lto_codegen_model _codeModel; |
| 74 | StringSet _mustPreserveSymbols; |
| 75 | StringSet _asmUndefinedRefs; |
| 76 | llvm::MemoryBuffer* _nativeObjectFile; |
| 77 | std::vector<char*> _codegenOptions; |
| 78 | std::string _mCpu; |
| 79 | std::string _nativeObjectPath; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | #endif // LTO_CODE_GENERATOR_H |