convert some uses of printBasicBlockLabel to use GetMBBSymbol
[llvm/avr.git] / tools / lto / LTOModule.h
blob8fd3915e28ca46bf16ac91c34f86329462c7af0d
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 class LTOModule {
42 public:
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,
54 std::string& errMsg);
55 static LTOModule* makeLTOModule(const void* mem, size_t length,
56 std::string& errMsg);
58 const char* getTargetTriple();
59 uint32_t getSymbolCount();
60 lto_symbol_attributes getSymbolAttributes(uint32_t index);
61 const char* getSymbolName(uint32_t index);
63 llvm::Module * getLLVVMModule() { return _module.get(); }
65 private:
66 LTOModule(llvm::Module* m, llvm::TargetMachine* t);
68 void lazyParseSymbols();
69 void addDefinedSymbol(llvm::GlobalValue* def,
70 llvm::Mangler& mangler,
71 bool isFunction);
72 void addPotentialUndefinedSymbol(llvm::GlobalValue* decl,
73 llvm::Mangler &mangler);
74 void findExternalRefs(llvm::Value* value,
75 llvm::Mangler& mangler);
76 void addDefinedFunctionSymbol(llvm::Function* f,
77 llvm::Mangler &mangler);
78 void addDefinedDataSymbol(llvm::GlobalValue* v,
79 llvm::Mangler &mangler);
80 void addAsmGlobalSymbol(const char *);
81 void addObjCClass(llvm::GlobalVariable* clgv);
82 void addObjCCategory(llvm::GlobalVariable* clgv);
83 void addObjCClassRef(llvm::GlobalVariable* clgv);
84 bool objcClassNameFromExpression(llvm::Constant* c,
85 std::string& name);
87 static bool isTargetMatch(llvm::MemoryBuffer* memBuffer,
88 const char* triplePrefix);
90 static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
91 std::string& errMsg);
92 static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
94 typedef llvm::StringMap<uint8_t> StringSet;
96 struct NameAndAttributes {
97 const char* name;
98 lto_symbol_attributes attributes;
101 llvm::OwningPtr<llvm::Module> _module;
102 llvm::OwningPtr<llvm::TargetMachine> _target;
103 bool _symbolsParsed;
104 std::vector<NameAndAttributes> _symbols;
105 // _defines and _undefines only needed to disambiguate tentative definitions
106 StringSet _defines;
107 llvm::StringMap<NameAndAttributes> _undefines;
110 extern std::string getFeatureString(const char *TargetTriple);
112 #endif // LTO_MODULE_H