X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FLinkTimeOptimizer.h;h=eea0093e80f7caa3ec8a397400d465fdea12b27f;hb=4d515d0b09d43af59cd040bfb8bf1b7a2b992980;hp=d4de787154a8143830b8ad511d8ff1d81f450674;hpb=30235dad4b77ed83ca985030aff4fb4767551e5d;p=oota-llvm.git diff --git a/include/llvm/LinkTimeOptimizer.h b/include/llvm/LinkTimeOptimizer.h index d4de787154a..eea0093e80f 100644 --- a/include/llvm/LinkTimeOptimizer.h +++ b/include/llvm/LinkTimeOptimizer.h @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Devang Patel and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -19,11 +19,15 @@ #include #include #include +#include + +#define LLVM_LTO_VERSION 2 namespace llvm { class Module; class GlobalValue; + class TargetMachine; enum LTOStatus { LTO_UNKNOWN, @@ -41,7 +45,21 @@ namespace llvm { LTOExternalLinkage, // Externally visible function LTOLinkOnceLinkage, // Keep one copy of named function when linking (inline) LTOWeakLinkage, // Keep one copy of named function when linking (weak) - LTOInternalLinkage // Rename collisions when linking (static functions) + LTOInternalLinkage, // Rename collisions when linking (static functions) + LTOCommonLinkage // tentative definitions (usually equivalent to weak) + }; + + enum LTOVisibilityTypes { + LTODefaultVisibility = 0, ///< The GV is visible + LTOHiddenVisibility, ///< The GV is hidden + LTOProtectedVisibility ///< The GV is protected + }; + + + enum LTOCodeGenModel { + LTO_CGM_Static, + LTO_CGM_Dynamic, + LTO_CGM_DynamicNoPIC }; /// This class represents LLVM symbol information without exposing details @@ -53,19 +71,26 @@ namespace llvm { public: LTOLinkageTypes getLinkage() const { return linkage; } + LTOVisibilityTypes getVisibility() const { return visibility; } void mayBeNotUsed(); - LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g, std::string n, - std::string m) : linkage(lt), gv(g), name(n), mangledName(m) {} + LLVMSymbol (enum LTOLinkageTypes lt, enum LTOVisibilityTypes vis, + GlobalValue *g, const std::string &n, + const std::string &m, int a) : linkage(lt), visibility(vis), + gv(g), name(n), + mangledName(m), alignment(a) {} const char *getName() { return name.c_str(); } const char *getMangledName() { return mangledName.c_str(); } + int getAlignment() { return alignment; } private: enum LTOLinkageTypes linkage; + enum LTOVisibilityTypes visibility; GlobalValue *gv; std::string name; std::string mangledName; + int alignment; }; class string_compare { @@ -74,24 +99,73 @@ namespace llvm { 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, + string_compare> NameToSymbolMap; + typedef hash_map, + string_compare> NameToModuleMap; + virtual enum LTOStatus readLLVMObjectFile(const std::string &, + NameToSymbolMap &, + std::set &) = 0; + virtual enum LTOStatus optimizeModules(const std::string &, + std::vector &exportList, + std::string &targetTriple, + bool saveTemps, const char *) = 0; + virtual void getTargetTriple(const std::string &, std::string &) = 0; + virtual void removeModule (const std::string &InputFilename) = 0; + virtual void setCodeGenModel(LTOCodeGenModel CGM) = 0; + virtual void printVersion () = 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, - string_compare> NameToSymbolMap; + string_compare> NameToSymbolMap; + typedef hash_map, + string_compare> NameToModuleMap; enum LTOStatus readLLVMObjectFile(const std::string &InputFilename, - NameToSymbolMap &symbols, - std::set &references); + NameToSymbolMap &symbols, + std::set &references); enum LTOStatus optimizeModules(const std::string &OutputFilename, - std::vector &exportList); + std::vector &exportList, + std::string &targetTriple, + bool saveTemps, const char *); + void getTargetTriple(const std::string &InputFilename, + std::string &targetTriple); + void removeModule (const std::string &InputFilename); + void printVersion(); + + void setCodeGenModel(LTOCodeGenModel CGM) { + CGModel = CGM; + } + + // Constructors and destructors + LTO() : Target(NULL), CGModel(LTO_CGM_Dynamic) { + /// TODO: Use Target info, it is available at this time. + } + ~LTO(); + + private: + Module *getModule (const std::string &InputFilename); + enum LTOStatus optimize(Module *, std::ostream &, + std::vector &); + void getTarget(Module *); private: std::vector modules; NameToSymbolMap allSymbols; + NameToModuleMap allModules; + TargetMachine *Target; + LTOCodeGenModel CGModel; }; } // End llvm namespace @@ -100,6 +174,6 @@ namespace llvm { /// linker to use dlopen() interface to dynamically load LinkTimeOptimizer. /// extern "C" helps, because dlopen() interface uses name to find the symbol. extern "C" -llvm::LinkTimeOptimizer *createLLVMOptimizer(); +llvm::LinkTimeOptimizer *createLLVMOptimizer(unsigned VERSION = LLVM_LTO_VERSION); #endif