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/ADT/OwningPtr.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/ADT/StringMap.h"
22 #include "llvm-c/lto.h"
28 // forward references to llvm classes
40 // C++ class which implements the opaque lto_module_t
45 static bool isBitcodeFile(const void* mem, size_t length);
46 static bool isBitcodeFile(const char* path);
48 static bool isBitcodeFileForTarget(const void* mem,
49 size_t length, const char* triplePrefix);
51 static bool isBitcodeFileForTarget(const char* path,
52 const char* triplePrefix);
54 static LTOModule* makeLTOModule(const char* path,
55 llvm::LLVMContext* Context,
57 static LTOModule* makeLTOModule(const void* mem, size_t length,
58 llvm::LLVMContext* Context,
61 const char* getTargetTriple();
62 uint32_t getSymbolCount();
63 lto_symbol_attributes getSymbolAttributes(uint32_t index);
64 const char* getSymbolName(uint32_t index);
66 llvm::Module * getLLVVMModule() { return _module.get(); }
69 LTOModule(llvm::Module* m, llvm::TargetMachine* t);
71 void lazyParseSymbols();
72 void addDefinedSymbol(llvm::GlobalValue* def,
73 llvm::Mangler& mangler,
75 void addPotentialUndefinedSymbol(llvm::GlobalValue* decl,
76 llvm::Mangler &mangler);
77 void findExternalRefs(llvm::Value* value,
78 llvm::Mangler& mangler);
79 void addDefinedFunctionSymbol(llvm::Function* f,
80 llvm::Mangler &mangler);
81 void addDefinedDataSymbol(llvm::GlobalValue* v,
82 llvm::Mangler &mangler);
83 void addAsmGlobalSymbol(const char *);
84 void addObjCClass(llvm::GlobalVariable* clgv);
85 void addObjCCategory(llvm::GlobalVariable* clgv);
86 void addObjCClassRef(llvm::GlobalVariable* clgv);
87 bool objcClassNameFromExpression(llvm::Constant* c,
90 static bool isTargetMatch(llvm::MemoryBuffer* memBuffer,
91 const char* triplePrefix);
93 static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
94 llvm::LLVMContext* Context,
96 static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
98 typedef llvm::StringMap<uint8_t> StringSet;
100 struct NameAndAttributes {
102 lto_symbol_attributes attributes;
105 llvm::OwningPtr<llvm::Module> _module;
106 llvm::OwningPtr<llvm::TargetMachine> _target;
108 std::vector<NameAndAttributes> _symbols;
109 // _defines and _undefines only needed to disambiguate tentative definitions
111 llvm::StringMap<NameAndAttributes> _undefines;
114 extern std::string getFeatureString(const char *TargetTriple);
116 #endif // LTO_MODULE_H