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