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
39 // C++ class which implements the opaque lto_module_t
43 static bool isBitcodeFile(const void* mem, size_t length);
44 static bool isBitcodeFile(const char* path);
46 static bool isBitcodeFileForTarget(const void* mem,
47 size_t length, const char* triplePrefix);
49 static bool isBitcodeFileForTarget(const char* path,
50 const char* triplePrefix);
52 static LTOModule* makeLTOModule(const char* path,
54 static LTOModule* makeLTOModule(int fd, const char *path,
57 static LTOModule* makeLTOModule(int fd, const char *path,
62 static LTOModule* makeLTOModule(const void* mem, size_t length,
65 const char* getTargetTriple();
66 void setTargetTriple(const char*);
67 uint32_t getSymbolCount();
68 lto_symbol_attributes getSymbolAttributes(uint32_t index);
69 const char* getSymbolName(uint32_t index);
71 llvm::Module * getLLVVMModule() { return _module.get(); }
72 const std::vector<const char*> &getAsmUndefinedRefs() {
73 return _asm_undefines;
77 LTOModule(llvm::Module* m, llvm::TargetMachine* t);
80 void addDefinedSymbol(llvm::GlobalValue* def,
81 llvm::Mangler& mangler,
83 void addPotentialUndefinedSymbol(llvm::GlobalValue* decl,
84 llvm::Mangler &mangler);
85 void addDefinedFunctionSymbol(llvm::Function* f,
86 llvm::Mangler &mangler);
87 void addDefinedDataSymbol(llvm::GlobalValue* v,
88 llvm::Mangler &mangler);
89 bool addAsmGlobalSymbols(llvm::MCContext &Context);
90 void addAsmGlobalSymbol(const char *,
91 lto_symbol_attributes scope);
92 void addAsmGlobalSymbolUndef(const char *);
93 void addObjCClass(llvm::GlobalVariable* clgv);
94 void addObjCCategory(llvm::GlobalVariable* clgv);
95 void addObjCClassRef(llvm::GlobalVariable* clgv);
96 bool objcClassNameFromExpression(llvm::Constant* c,
99 static bool isTargetMatch(llvm::MemoryBuffer* memBuffer,
100 const char* triplePrefix);
102 static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
103 std::string& errMsg);
104 static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
106 typedef llvm::StringMap<uint8_t> StringSet;
108 struct NameAndAttributes {
110 lto_symbol_attributes attributes;
113 llvm::OwningPtr<llvm::Module> _module;
114 llvm::OwningPtr<llvm::TargetMachine> _target;
115 std::vector<NameAndAttributes> _symbols;
116 // _defines and _undefines only needed to disambiguate tentative definitions
118 llvm::StringMap<NameAndAttributes> _undefines;
119 std::vector<const char*> _asm_undefines;
122 #endif // LTO_MODULE_H