void mayBeNotUsed();
LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g, const std::string &n,
- const std::string &m) : linkage(lt), gv(g), name(n),
- mangledName(m) {}
+ const std::string &m) : linkage(lt), gv(g), name(n),
+ mangledName(m) {}
const char *getName() { return name.c_str(); }
const char *getMangledName() { return mangledName.c_str(); }
return (strcmp(left, right) == 0);
}
};
-
+
+ /// This is abstract class to facilitate dlopen() interface.
+ /// See LTO below for more info.
+ class LinkTimeOptimizer {
+ public:
+ typedef hash_map<const char*, LLVMSymbol*, hash<const char*>,
+ string_compare> NameToSymbolMap;
+ typedef hash_map<const char*, Module*, hash<const char*>,
+ string_compare> NameToModuleMap;
+ virtual enum LTOStatus readLLVMObjectFile(const std::string &,
+ NameToSymbolMap &,
+ std::set<std::string> &) = 0;
+ virtual enum LTOStatus optimizeModules(const std::string &,
+ std::vector<const char*> &,
+ std::string &) = 0;
+ virtual void getTargetTriple(const std::string &, std::string &) = 0;
+ virtual ~LinkTimeOptimizer() = 0;
+ };
+
/// This is the main link time optimization class. It exposes simple API
/// to perform link time optimization using LLVM intermodular optimizer.
- class LinkTimeOptimizer {
+ class LTO : public LinkTimeOptimizer {
public:
typedef hash_map<const char*, LLVMSymbol*, hash<const char*>,
- string_compare> NameToSymbolMap;
+ string_compare> NameToSymbolMap;
+ typedef hash_map<const char*, Module*, hash<const char*>,
+ string_compare> NameToModuleMap;
enum LTOStatus readLLVMObjectFile(const std::string &InputFilename,
- NameToSymbolMap &symbols,
- std::set<std::string> &references);
+ NameToSymbolMap &symbols,
+ std::set<std::string> &references);
enum LTOStatus optimizeModules(const std::string &OutputFilename,
- std::vector<const char*> &exportList);
+ std::vector<const char*> &exportList,
+ std::string &targetTriple);
+ void getTargetTriple(const std::string &InputFilename, std::string &targetTriple);
+
+ private:
+ Module *getModule (const std::string &InputFilename);
private:
std::vector<Module *> modules;
NameToSymbolMap allSymbols;
+ NameToModuleMap allModules;
};
} // End llvm namespace