1 //===-LTOModule.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 LTOModule class.
12 //===----------------------------------------------------------------------===//
17 #include "llvm/Module.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/ADT/OwningPtr.h"
21 #include "llvm/ADT/StringMap.h"
23 #include "llvm-c/lto.h"
29 // forward references to llvm classes
40 // C++ class which implements the opaque lto_module_t
44 static bool isBitcodeFile(const void* mem, size_t length);
45 static bool isBitcodeFile(const char* path);
47 static bool isBitcodeFileForTarget(const void* mem,
48 size_t length, const char* triplePrefix);
50 static bool isBitcodeFileForTarget(const char* path,
51 const char* triplePrefix);
53 static LTOModule* makeLTOModule(const char* path,
55 static LTOModule* makeLTOModule(int fd, const char *path,
58 static LTOModule* makeLTOModule(int fd, const char *path,
63 static LTOModule* makeLTOModule(const void* mem, size_t length,
66 const char* getTargetTriple();
67 void setTargetTriple(const char*);
68 uint32_t getSymbolCount();
69 lto_symbol_attributes getSymbolAttributes(uint32_t index);
70 const char* getSymbolName(uint32_t index);
72 llvm::Module * getLLVVMModule() { return _module.get(); }
73 const std::vector<const char*> &getAsmUndefinedRefs() {
74 return _asm_undefines;
78 LTOModule(llvm::Module* m, llvm::TargetMachine* t);
80 bool ParseSymbols(std::string &errMsg);
81 void addDefinedSymbol(llvm::GlobalValue* def,
82 llvm::Mangler& mangler,
84 void addPotentialUndefinedSymbol(llvm::GlobalValue* decl,
85 llvm::Mangler &mangler);
86 void addDefinedFunctionSymbol(llvm::Function* f,
87 llvm::Mangler &mangler);
88 void addDefinedDataSymbol(llvm::GlobalValue* v,
89 llvm::Mangler &mangler);
90 bool addAsmGlobalSymbols(std::string &errMsg);
91 void addAsmGlobalSymbol(const char *,
92 lto_symbol_attributes scope);
93 void addAsmGlobalSymbolUndef(const char *);
94 void addObjCClass(llvm::GlobalVariable* clgv);
95 void addObjCCategory(llvm::GlobalVariable* clgv);
96 void addObjCClassRef(llvm::GlobalVariable* clgv);
97 bool objcClassNameFromExpression(llvm::Constant* c,
100 static bool isTargetMatch(llvm::MemoryBuffer* memBuffer,
101 const char* triplePrefix);
103 static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
104 std::string& errMsg);
105 static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
107 typedef llvm::StringMap<uint8_t> StringSet;
109 struct NameAndAttributes {
111 lto_symbol_attributes attributes;
114 llvm::OwningPtr<llvm::Module> _module;
115 llvm::OwningPtr<llvm::TargetMachine> _target;
116 std::vector<NameAndAttributes> _symbols;
117 // _defines and _undefines only needed to disambiguate tentative definitions
119 llvm::StringMap<NameAndAttributes> _undefines;
120 std::vector<const char*> _asm_undefines;
121 llvm::MCContext _context;
124 #endif // LTO_MODULE_H