Switch LTO to use MC. This takes the linking of libxul.so from about 7m to
[oota-llvm.git] / tools / lto / LTOCodeGenerator.h
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
23 #include <string>
24
25
26 //
27 // C++ class which implements the opaque lto_code_gen_t
28 //
29
30 struct LTOCodeGenerator {
31     static const char*        getVersionString();
32     
33                             LTOCodeGenerator();
34                             ~LTOCodeGenerator();
35                             
36     bool                addModule(struct LTOModule*, std::string& errMsg);
37     bool                setDebugInfo(lto_debug_model, std::string& errMsg);
38     bool                setCodePICModel(lto_codegen_model, std::string& errMsg);
39     void                setCpu(const char *cpu);
40     void                addMustPreserveSymbol(const char* sym);
41     bool                writeMergedModules(const char* path, 
42                                                            std::string& errMsg);
43     const void*         compile(size_t* length, std::string& errMsg);
44     void                setCodeGenDebugOptions(const char *opts); 
45 private:
46     bool                generateObjectFile(llvm::raw_ostream& out, 
47                                            std::string& errMsg);
48     void                applyScopeRestrictions();
49     bool                determineTarget(std::string& errMsg);
50     
51     typedef llvm::StringMap<uint8_t> StringSet;
52
53     llvm::LLVMContext&          _context;
54     llvm::Linker                _linker;
55     llvm::TargetMachine*        _target;
56     bool                        _emitDwarfDebugInfo;
57     bool                        _scopeRestrictionsDone;
58     lto_codegen_model           _codeModel;
59     StringSet                   _mustPreserveSymbols;
60     llvm::MemoryBuffer*         _nativeObjectFile;
61     std::vector<const char*>    _codegenOptions;
62     std::string                 _mCpu;
63 };
64
65 #endif // LTO_CODE_GENERATOR_H
66