Apply the scope restrictions after parsing the command line options. There may be...
[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 #ifndef LTO_CODE_GENERATOR_H
15 #define LTO_CODE_GENERATOR_H
16
17 #include "llvm/Linker.h"
18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm-c/lto.h"
21 #include <string>
22
23 namespace llvm {
24   class LLVMContext;
25   class GlobalValue;
26   class Mangler;
27   class MemoryBuffer;
28   class TargetMachine;
29   class raw_ostream;
30 }
31
32 //===----------------------------------------------------------------------===//
33 /// LTOCodeGenerator - C++ class which implements the opaque lto_code_gen_t
34 /// type.
35 ///
36 struct LTOCodeGenerator {
37   static const char *getVersionString();
38
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);
45
46   void setCpu(const char* mCpu) { _mCpu = mCpu; }
47
48   void addMustPreserveSymbol(const char* sym) {
49     _mustPreserveSymbols[sym] = 1;
50   }
51
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   void enableInternalizePass() { _runInternalizePass = true; }
58
59 private:
60   bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg);
61   void applyScopeRestrictions();
62   void applyRestriction(llvm::GlobalValue &GV,
63                         std::vector<const char*> &mustPreserveList,
64                         llvm::SmallPtrSet<llvm::GlobalValue*, 8> &asmUsed,
65                         llvm::Mangler &mangler);
66   bool determineTarget(std::string &errMsg);
67
68   typedef llvm::StringMap<uint8_t> StringSet;
69
70   llvm::LLVMContext&          _context;
71   llvm::Linker                _linker;
72   llvm::TargetMachine*        _target;
73   bool                        _emitDwarfDebugInfo;
74   bool                        _scopeRestrictionsDone;
75   bool                        _runInternalizePass;
76   lto_codegen_model           _codeModel;
77   StringSet                   _mustPreserveSymbols;
78   StringSet                   _asmUndefinedRefs;
79   llvm::MemoryBuffer*         _nativeObjectFile;
80   std::vector<char*>          _codegenOptions;
81   std::string                 _mCpu;
82   std::string                 _nativeObjectPath;
83 };
84
85 #endif // LTO_CODE_GENERATOR_H