The guaranteed alignment of ptr+offset is only the minimum of
[oota-llvm.git] / include / llvm / LinkTimeOptimizer.h
index 52532b1947f2e09ad11bcef10763e399461bbea0..164232d20989b0559e5482a9f8a9178bdd527e1e 100644 (file)
@@ -24,6 +24,7 @@ namespace llvm {
 
   class Module;
   class GlobalValue;
+  class TargetMachine;
 
   enum LTOStatus {
     LTO_UNKNOWN,
@@ -44,7 +45,7 @@ namespace llvm {
     LTOInternalLinkage  // Rename collisions when linking (static functions)
   };
 
-  /// This class representes LLVM symbol information without exposing details
+  /// This class represents LLVM symbol information without exposing details
   /// of LLVM global values. It encapsulates symbol linkage information. This
   /// is typically used in hash_map where associated name identifies the 
   /// the symbol name.
@@ -55,11 +56,20 @@ namespace llvm {
     LTOLinkageTypes getLinkage() const { return linkage; }
     void mayBeNotUsed();
 
-  LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g) : linkage(lt), gv(g) {}
+    LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g, const std::string &n, 
+                const std::string &m, int a) : linkage(lt), 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;
     GlobalValue *gv;
+    std::string name;
+    std::string mangledName;
+    int alignment;
   };
 
   class string_compare {
@@ -68,24 +78,68 @@ 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<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 &, bool, 
+                                           const char *) = 0;
+    virtual void getTargetTriple(const std::string &, std::string &) = 0;
+    virtual void removeModule (const std::string &InputFilename) = 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<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<const char*> &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, bool saveTemps,
+                                   const char *);
+    void getTargetTriple(const std::string &InputFilename, 
+                         std::string &targetTriple);
+    void removeModule (const std::string &InputFilename);
+    void printVersion();
+
+    // Constructors and destructors
+    LTO() { 
+      /// TODO: Use Target info, it is available at this time.
+      Target = NULL; 
+    }
+    ~LTO();
+
+  private:
+    Module *getModule (const std::string &InputFilename);
+    enum LTOStatus optimize(Module *, std::ostream &, 
+                            std::vector<const char *> &);
+    void getTarget(Module *);
 
   private:
     std::vector<Module *> modules;
     NameToSymbolMap allSymbols;
+    NameToModuleMap allModules;
+    TargetMachine *Target;
   };
 
 } // End llvm namespace