1 //===-LTOCodeGenerator.h - LLVM Link Time Optimizer -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the LTOCodeGenerator class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LTO_CODE_GENERATOR_H
15 #define LTO_CODE_GENERATOR_H
17 #include "llvm-c/lto.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/Linker.h"
33 //===----------------------------------------------------------------------===//
34 /// LTOCodeGenerator - C++ class which implements the opaque lto_code_gen_t
37 struct LTOCodeGenerator {
38 static const char *getVersionString();
43 bool addModule(struct LTOModule*, std::string &errMsg);
44 bool setDebugInfo(lto_debug_model, std::string &errMsg);
45 bool setCodePICModel(lto_codegen_model, std::string &errMsg);
47 void setCpu(const char* mCpu) { _mCpu = mCpu; }
49 void addMustPreserveSymbol(const char* sym) {
50 _mustPreserveSymbols[sym] = 1;
53 bool writeMergedModules(const char *path, std::string &errMsg);
54 bool compile_to_file(const char **name, std::string &errMsg);
55 const void *compile(size_t *length, std::string &errMsg);
56 void setCodeGenDebugOptions(const char *opts);
59 void initializeLTOPasses();
61 bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg);
62 void applyScopeRestrictions();
63 void applyRestriction(llvm::GlobalValue &GV,
64 std::vector<const char*> &mustPreserveList,
65 llvm::SmallPtrSet<llvm::GlobalValue*, 8> &asmUsed,
66 llvm::Mangler &mangler);
67 bool determineTarget(std::string &errMsg);
69 typedef llvm::StringMap<uint8_t> StringSet;
71 llvm::LLVMContext& _context;
73 llvm::TargetMachine* _target;
74 bool _emitDwarfDebugInfo;
75 bool _scopeRestrictionsDone;
76 lto_codegen_model _codeModel;
77 StringSet _mustPreserveSymbols;
78 StringSet _asmUndefinedRefs;
79 llvm::MemoryBuffer* _nativeObjectFile;
80 std::vector<char*> _codegenOptions;
82 std::string _nativeObjectPath;
85 #endif // LTO_CODE_GENERATOR_H