When removing a function from the function set and adding it to deferred, we
[llvm.git] / tools / lto / LTOModule.h
blob1794d81c0a9c573058c46a3f1a1e02f593933616
1 //===-LTOModule.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 LTOModule class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LTO_MODULE_H
15 #define LTO_MODULE_H
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"
24 #include <vector>
25 #include <string>
28 // forward references to llvm classes
29 namespace llvm {
30 class Mangler;
31 class MemoryBuffer;
32 class GlobalValue;
33 class Value;
34 class Function;
39 // C++ class which implements the opaque lto_module_t
41 struct LTOModule {
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,
53 std::string& errMsg);
54 static LTOModule* makeLTOModule(int fd, const char *path,
55 off_t size,
56 std::string& errMsg);
57 static LTOModule* makeLTOModule(const void* mem, size_t length,
58 std::string& errMsg);
60 const char* getTargetTriple();
61 void setTargetTriple(const char*);
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(); }
68 private:
69 LTOModule(llvm::Module* m, llvm::TargetMachine* t);
71 void lazyParseSymbols();
72 void addDefinedSymbol(llvm::GlobalValue* def,
73 llvm::Mangler& mangler,
74 bool isFunction);
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,
88 std::string& name);
90 static bool isTargetMatch(llvm::MemoryBuffer* memBuffer,
91 const char* triplePrefix);
93 static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
94 std::string& errMsg);
95 static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
97 typedef llvm::StringMap<uint8_t> StringSet;
99 struct NameAndAttributes {
100 const char* name;
101 lto_symbol_attributes attributes;
104 llvm::OwningPtr<llvm::Module> _module;
105 llvm::OwningPtr<llvm::TargetMachine> _target;
106 bool _symbolsParsed;
107 std::vector<NameAndAttributes> _symbols;
108 // _defines and _undefines only needed to disambiguate tentative definitions
109 StringSet _defines;
110 llvm::StringMap<NameAndAttributes> _undefines;
113 #endif // LTO_MODULE_H