• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
19 #include "llvm/LLVMContext.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/SmallPtrSet.h"
23 
24 #include <string>
25 
26 
27 //
28 // C++ class which implements the opaque lto_code_gen_t
29 //
30 
31 struct LTOCodeGenerator {
32     static const char*        getVersionString();
33 
34                             LTOCodeGenerator();
35                             ~LTOCodeGenerator();
36 
37     bool                addModule(struct LTOModule*, std::string& errMsg);
38     bool                setDebugInfo(lto_debug_model, std::string& errMsg);
39     bool                setCodePICModel(lto_codegen_model, std::string& errMsg);
40     void                setCpu(const char *cpu);
41     void                addMustPreserveSymbol(const char* sym);
42     bool                writeMergedModules(const char* path,
43                                                            std::string& errMsg);
44     bool                compile_to_file(const char** name, std::string& errMsg);
45     const void*         compile(size_t* length, std::string& errMsg);
46     void                setCodeGenDebugOptions(const char *opts);
47 private:
48     bool                generateObjectFile(llvm::raw_ostream& out,
49                                            std::string& errMsg);
50     void                applyScopeRestrictions();
51     void                applyRestriction(llvm::GlobalValue &GV,
52                                      std::vector<const char*> &mustPreserveList,
53                         llvm::SmallPtrSet<llvm::GlobalValue*, 8> &asmUsed,
54                                          llvm::Mangler &mangler);
55     bool                determineTarget(std::string& errMsg);
56 
57     typedef llvm::StringMap<uint8_t> StringSet;
58 
59     llvm::LLVMContext&          _context;
60     llvm::Linker                _linker;
61     llvm::TargetMachine*        _target;
62     bool                        _emitDwarfDebugInfo;
63     bool                        _scopeRestrictionsDone;
64     lto_codegen_model           _codeModel;
65     StringSet                   _mustPreserveSymbols;
66     StringSet                   _asmUndefinedRefs;
67     llvm::MemoryBuffer*         _nativeObjectFile;
68     std::vector<const char*>    _codegenOptions;
69     std::string                 _mCpu;
70     std::string                 _nativeObjectPath;
71 };
72 
73 #endif // LTO_CODE_GENERATOR_H
74 
75