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/GlobalValue.h"
19 #include "llvm/Constants.h"
20 #include "llvm/Support/Mangler.h"
21 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/ADT/StringMap.h"
24 #include "llvm-c/lto.h"
30 // C++ class which implements the opaque lto_module_t
35 static bool isBitcodeFile(const void* mem, size_t length);
36 static bool isBitcodeFile(const char* path);
38 static bool isBitcodeFileForTarget(const void* mem,
39 size_t length, const char* triplePrefix);
41 static bool isBitcodeFileForTarget(const char* path,
42 const char* triplePrefix);
44 static LTOModule* makeLTOModule(const char* path, std::string& errMsg);
45 static LTOModule* makeLTOModule(const void* mem, size_t length,
49 const char* getTargetTriple();
50 uint32_t getSymbolCount();
51 lto_symbol_attributes getSymbolAttributes(uint32_t index);
52 const char* getSymbolName(uint32_t index);
54 llvm::Module * getLLVVMModule() { return _module; }
55 bool targetSupported() { return (_target != NULL); }
58 LTOModule(llvm::Module* m, llvm::TargetMachine* t);
60 void addDefinedSymbol(llvm::GlobalValue* def,
61 llvm::Mangler& mangler,
63 void addUndefinedSymbol(const char* name);
64 void findExternalRefs(llvm::Value* value,
65 llvm::Mangler& mangler);
67 typedef llvm::StringMap<uint8_t> StringSet;
69 struct NameAndAttributes {
71 lto_symbol_attributes attributes;
74 llvm::Module * _module;
75 llvm::TargetMachine * _target;
77 std::vector<NameAndAttributes> _symbols;
78 StringSet _defines; // only needed to disambiguate tentative definitions
79 StringSet _undefines; // only needed to disambiguate tentative definitions
82 #endif // LTO_MODULE_H