[llvm] r207911 - Move LTOModule and LTOCodeGenerator to the llvm namespace.

Rafael Espindola rafael.espindola at gmail.com
Sat May 3 07:59:52 PDT 2014


Author: rafael
Date: Sat May  3 09:59:52 2014
New Revision: 207911

URL: http://llvm.org/viewvc/llvm-project?rev=207911&view=rev
Log:
Move LTOModule and LTOCodeGenerator to the llvm namespace.

Modified:
    llvm/trunk/include/llvm-c/lto.h
    llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
    llvm/trunk/include/llvm/LTO/LTOModule.h
    llvm/trunk/tools/lto/lto.cpp

Modified: llvm/trunk/include/llvm-c/lto.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/lto.h?rev=207911&r1=207910&r2=207911&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/lto.h (original)
+++ llvm/trunk/include/llvm-c/lto.h Sat May  3 09:59:52 2014
@@ -84,10 +84,10 @@ typedef enum {
 } lto_codegen_model;
 
 /** opaque reference to a loaded object module */
-typedef struct LTOModule*         lto_module_t;
+typedef struct LLVMOpaqueLTOModule *lto_module_t;
 
 /** opaque reference to a code generator */
-typedef struct LTOCodeGenerator*  lto_code_gen_t;
+typedef struct LLVMOpaqueLTOCodeGenerator *lto_code_gen_t;
 
 #ifdef __cplusplus
 extern "C" {

Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=207911&r1=207910&r2=207911&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Sat May  3 09:59:52 2014
@@ -53,7 +53,6 @@ namespace llvm {
   class TargetLibraryInfo;
   class TargetMachine;
   class raw_ostream;
-}
 
 //===----------------------------------------------------------------------===//
 /// C++ class which implements the opaque lto_code_gen_t type.
@@ -67,7 +66,7 @@ struct LTOCodeGenerator {
   // Merge given module, return true on success.
   bool addModule(struct LTOModule*, std::string &errMsg);
 
-  void setTargetOptions(llvm::TargetOptions options);
+  void setTargetOptions(TargetOptions options);
   void setDebugInfo(lto_debug_model);
   void setCodePICModel(lto_codegen_model);
 
@@ -120,41 +119,37 @@ struct LTOCodeGenerator {
 private:
   void initializeLTOPasses();
 
-  bool generateObjectFile(llvm::raw_ostream &out,
-                          bool disableOpt,
-                          bool disableInline,
-                          bool disableGVNLoadPRE,
-                          std::string &errMsg);
+  bool generateObjectFile(raw_ostream &out, bool disableOpt, bool disableInline,
+                          bool disableGVNLoadPRE, std::string &errMsg);
   void applyScopeRestrictions();
-  void applyRestriction(llvm::GlobalValue &GV,
-                        const llvm::ArrayRef<llvm::StringRef> &Libcalls,
-                        std::vector<const char*> &MustPreserveList,
-                        llvm::SmallPtrSet<llvm::GlobalValue*, 8> &AsmUsed,
-                        llvm::Mangler &Mangler);
+  void applyRestriction(GlobalValue &GV, const ArrayRef<StringRef> &Libcalls,
+                        std::vector<const char *> &MustPreserveList,
+                        SmallPtrSet<GlobalValue *, 8> &AsmUsed,
+                        Mangler &Mangler);
   bool determineTarget(std::string &errMsg);
 
-  static void DiagnosticHandler(const llvm::DiagnosticInfo &DI, void *Context);
+  static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context);
 
-  void DiagnosticHandler2(const llvm::DiagnosticInfo &DI);
+  void DiagnosticHandler2(const DiagnosticInfo &DI);
 
-  typedef llvm::StringMap<uint8_t> StringSet;
+  typedef StringMap<uint8_t> StringSet;
 
-  llvm::LLVMContext &Context;
-  llvm::Linker Linker;
-  llvm::TargetMachine *TargetMach;
+  LLVMContext &Context;
+  Linker Linker;
+  TargetMachine *TargetMach;
   bool EmitDwarfDebugInfo;
   bool ScopeRestrictionsDone;
   lto_codegen_model CodeModel;
   StringSet MustPreserveSymbols;
   StringSet AsmUndefinedRefs;
-  llvm::MemoryBuffer *NativeObjectFile;
+  MemoryBuffer *NativeObjectFile;
   std::vector<char *> CodegenOptions;
   std::string MCpu;
   std::string MAttr;
   std::string NativeObjectPath;
-  llvm::TargetOptions Options;
+  TargetOptions Options;
   lto_diagnostic_handler_t DiagHandler;
   void *DiagContext;
 };
-
+}
 #endif // LTO_CODE_GENERATOR_H

Modified: llvm/trunk/include/llvm/LTO/LTOModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOModule.h?rev=207911&r1=207910&r2=207911&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOModule.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOModule.h Sat May  3 09:59:52 2014
@@ -31,25 +31,24 @@ namespace llvm {
   class MemoryBuffer;
   class TargetOptions;
   class Value;
-}
 
 //===----------------------------------------------------------------------===//
 /// C++ class which implements the opaque lto_module_t type.
 ///
 struct LTOModule {
 private:
-  typedef llvm::StringMap<uint8_t> StringSet;
+  typedef StringMap<uint8_t> StringSet;
 
   struct NameAndAttributes {
     const char        *name;
     uint32_t           attributes;
     bool               isFunction;
-    const llvm::GlobalValue *symbol;
+    const GlobalValue *symbol;
   };
 
-  std::unique_ptr<llvm::Module>           _module;
-  std::unique_ptr<llvm::TargetMachine>    _target;
-  llvm::MCObjectFileInfo ObjFileInfo;
+  std::unique_ptr<Module> _module;
+  std::unique_ptr<TargetMachine> _target;
+  MCObjectFileInfo ObjFileInfo;
   StringSet                               _linkeropt_strings;
   std::vector<const char *>               _deplibs;
   std::vector<const char *>               _linkeropts;
@@ -57,14 +56,15 @@ private:
 
   // _defines and _undefines only needed to disambiguate tentative definitions
   StringSet                               _defines;
-  llvm::StringMap<NameAndAttributes>      _undefines;
+  StringMap<NameAndAttributes> _undefines;
   std::vector<const char*>                _asm_undefines;
-  llvm::MCContext                         _context;
+  MCContext _context;
 
   // Use mangler to add GlobalPrefix to names to match linker names.
-  llvm::Mangler                           _mangler;
+  Mangler _mangler;
+
+  LTOModule(Module *m, TargetMachine *t);
 
-  LTOModule(llvm::Module *m, llvm::TargetMachine *t);
 public:
   /// Returns 'true' if the file or memory contents is LLVM bitcode.
   static bool isBitcodeFile(const void *mem, size_t length);
@@ -86,20 +86,16 @@ public:
   /// InitializeAllTargetMCs();
   /// InitializeAllAsmPrinters();
   /// InitializeAllAsmParsers();
-  static LTOModule *makeLTOModule(const char* path,
-                                  llvm::TargetOptions options,
+  static LTOModule *makeLTOModule(const char *path, TargetOptions options,
                                   std::string &errMsg);
-  static LTOModule *makeLTOModule(int fd, const char *path,
-                                  size_t size, llvm::TargetOptions options,
+  static LTOModule *makeLTOModule(int fd, const char *path, size_t size,
+                                  TargetOptions options, std::string &errMsg);
+  static LTOModule *makeLTOModule(int fd, const char *path, size_t map_size,
+                                  off_t offset, TargetOptions options,
                                   std::string &errMsg);
-  static LTOModule *makeLTOModule(int fd, const char *path,
-                                  size_t map_size,
-                                  off_t offset, llvm::TargetOptions options,
-                                  std::string& errMsg);
   static LTOModule *makeLTOModule(const void *mem, size_t length,
-                                  llvm::TargetOptions options,
-                                  std::string &errMsg,
-                                  llvm::StringRef path = "");
+                                  TargetOptions options, std::string &errMsg,
+                                  StringRef path = "");
 
   /// Return the Module's target triple.
   const char *getTargetTriple() {
@@ -155,7 +151,7 @@ public:
   }
 
   /// Return the Module.
-  llvm::Module *getLLVVMModule() { return _module.get(); }
+  Module *getLLVVMModule() { return _module.get(); }
 
   const std::vector<const char*> &getAsmUndefinedRefs() {
     return _asm_undefines;
@@ -171,16 +167,16 @@ private:
   bool parseSymbols(std::string &errMsg);
 
   /// Add a symbol which isn't defined just yet to a list to be resolved later.
-  void addPotentialUndefinedSymbol(const llvm::GlobalValue *dcl, bool isFunc);
+  void addPotentialUndefinedSymbol(const GlobalValue *dcl, bool isFunc);
 
   /// Add a defined symbol to the list.
-  void addDefinedSymbol(const llvm::GlobalValue *def, bool isFunction);
+  void addDefinedSymbol(const GlobalValue *def, bool isFunction);
 
   /// Add a function symbol as defined to the list.
-  void addDefinedFunctionSymbol(const llvm::Function *f);
+  void addDefinedFunctionSymbol(const Function *f);
 
   /// Add a data symbol as defined to the list.
-  void addDefinedDataSymbol(const llvm::GlobalValue *v);
+  void addDefinedDataSymbol(const GlobalValue *v);
 
   /// Add global symbols from module-level ASM to the defined or undefined
   /// lists.
@@ -193,30 +189,28 @@ private:
   void addAsmGlobalSymbolUndef(const char *);
 
   /// Parse i386/ppc ObjC class data structure.
-  void addObjCClass(const llvm::GlobalVariable *clgv);
+  void addObjCClass(const GlobalVariable *clgv);
 
   /// Parse i386/ppc ObjC category data structure.
-  void addObjCCategory(const llvm::GlobalVariable *clgv);
+  void addObjCCategory(const GlobalVariable *clgv);
 
   /// Parse i386/ppc ObjC class list data structure.
-  void addObjCClassRef(const llvm::GlobalVariable *clgv);
+  void addObjCClassRef(const GlobalVariable *clgv);
 
   /// Get string that the data pointer points to.
-  bool objcClassNameFromExpression(const llvm::Constant* c, std::string &name);
+  bool objcClassNameFromExpression(const Constant *c, std::string &name);
 
   /// Returns 'true' if the memory buffer is for the specified target triple.
-  static bool isTargetMatch(llvm::MemoryBuffer *memBuffer,
-                            const char *triplePrefix);
+  static bool isTargetMatch(MemoryBuffer *memBuffer, const char *triplePrefix);
 
   /// Create an LTOModule (private version). N.B. This method takes ownership of
   /// the buffer.
-  static LTOModule *makeLTOModule(llvm::MemoryBuffer *buffer,
-                                  llvm::TargetOptions options,
+  static LTOModule *makeLTOModule(MemoryBuffer *buffer, TargetOptions options,
                                   std::string &errMsg);
 
   /// Create a MemoryBuffer from a memory range with an optional name.
-  static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length,
-                                        llvm::StringRef name = "");
+  static MemoryBuffer *makeBuffer(const void *mem, size_t length,
+                                  StringRef name = "");
 };
-
+}
 #endif // LTO_MODULE_H

Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=207911&r1=207910&r2=207911&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Sat May  3 09:59:52 2014
@@ -56,8 +56,12 @@ static void lto_initialize() {
   }
 }
 
+DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LTOCodeGenerator, lto_code_gen_t);
+DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LTOModule, lto_module_t);
+
 // Convert the subtarget features into a string to pass to LTOCodeGenerator.
 static void lto_add_attrs(lto_code_gen_t cg) {
+  LTOCodeGenerator *CG = unwrap(cg);
   if (MAttrs.size()) {
     std::string attrs;
     for (unsigned i = 0; i < MAttrs.size(); ++i) {
@@ -66,7 +70,7 @@ static void lto_add_attrs(lto_code_gen_t
       attrs.append(MAttrs[i]);
     }
 
-    cg->setAttr(attrs.c_str());
+    CG->setAttr(attrs.c_str());
   }
 }
 
@@ -101,13 +105,14 @@ lto_module_is_object_file_in_memory_for_
 lto_module_t lto_module_create(const char* path) {
   lto_initialize();
   llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
-  return LTOModule::makeLTOModule(path, Options, sLastErrorString);
+  return wrap(LTOModule::makeLTOModule(path, Options, sLastErrorString));
 }
 
 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
   lto_initialize();
   llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
-  return LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString);
+  return wrap(
+      LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString));
 }
 
 lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path,
@@ -116,14 +121,14 @@ lto_module_t lto_module_create_from_fd_a
                                                  off_t offset) {
   lto_initialize();
   llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
-  return LTOModule::makeLTOModule(fd, path, map_size, offset, Options,
-                                  sLastErrorString);
+  return wrap(LTOModule::makeLTOModule(fd, path, map_size, offset, Options,
+                                       sLastErrorString));
 }
 
 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
   lto_initialize();
   llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
-  return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
+  return wrap(LTOModule::makeLTOModule(mem, length, Options, sLastErrorString));
 }
 
 lto_module_t lto_module_create_from_memory_with_path(const void* mem,
@@ -131,54 +136,53 @@ lto_module_t lto_module_create_from_memo
                                                      const char *path) {
   lto_initialize();
   llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
-  return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path);
+  return wrap(
+      LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path));
 }
 
-void lto_module_dispose(lto_module_t mod) {
-  delete mod;
-}
+void lto_module_dispose(lto_module_t mod) { delete unwrap(mod); }
 
 const char* lto_module_get_target_triple(lto_module_t mod) {
-  return mod->getTargetTriple();
+  return unwrap(mod)->getTargetTriple();
 }
 
 void lto_module_set_target_triple(lto_module_t mod, const char *triple) {
-  return mod->setTargetTriple(triple);
+  return unwrap(mod)->setTargetTriple(triple);
 }
 
 unsigned int lto_module_get_num_symbols(lto_module_t mod) {
-  return mod->getSymbolCount();
+  return unwrap(mod)->getSymbolCount();
 }
 
 const char* lto_module_get_symbol_name(lto_module_t mod, unsigned int index) {
-  return mod->getSymbolName(index);
+  return unwrap(mod)->getSymbolName(index);
 }
 
 lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod,
                                                       unsigned int index) {
-  return mod->getSymbolAttributes(index);
+  return unwrap(mod)->getSymbolAttributes(index);
 }
 
 unsigned int lto_module_get_num_deplibs(lto_module_t mod) {
-  return mod->getDependentLibraryCount();
+  return unwrap(mod)->getDependentLibraryCount();
 }
 
 const char* lto_module_get_deplib(lto_module_t mod, unsigned int index) {
-  return mod->getDependentLibrary(index);
+  return unwrap(mod)->getDependentLibrary(index);
 }
 
 unsigned int lto_module_get_num_linkeropts(lto_module_t mod) {
-  return mod->getLinkerOptCount();
+  return unwrap(mod)->getLinkerOptCount();
 }
 
 const char* lto_module_get_linkeropt(lto_module_t mod, unsigned int index) {
-  return mod->getLinkerOpt(index);
+  return unwrap(mod)->getLinkerOpt(index);
 }
 
 void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg,
                                         lto_diagnostic_handler_t diag_handler,
                                         void *ctxt) {
-  cg->setDiagnosticHandler(diag_handler, ctxt);
+  unwrap(cg)->setDiagnosticHandler(diag_handler, ctxt);
 }
 
 lto_code_gen_t lto_codegen_create(void) {
@@ -189,33 +193,31 @@ lto_code_gen_t lto_codegen_create(void)
   LTOCodeGenerator *CodeGen = new LTOCodeGenerator();
   if (CodeGen)
     CodeGen->setTargetOptions(Options);
-  return CodeGen;
+  return wrap(CodeGen);
 }
 
-void lto_codegen_dispose(lto_code_gen_t cg) {
-  delete cg;
-}
+void lto_codegen_dispose(lto_code_gen_t cg) { delete unwrap(cg); }
 
 bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) {
-  return !cg->addModule(mod, sLastErrorString);
+  return !unwrap(cg)->addModule(unwrap(mod), sLastErrorString);
 }
 
 bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) {
-  cg->setDebugInfo(debug);
+  unwrap(cg)->setDebugInfo(debug);
   return false;
 }
 
 bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) {
-  cg->setCodePICModel(model);
+  unwrap(cg)->setCodePICModel(model);
   return false;
 }
 
 void lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu) {
-  return cg->setCpu(cpu);
+  return unwrap(cg)->setCpu(cpu);
 }
 
 void lto_codegen_set_attr(lto_code_gen_t cg, const char *attr) {
-  return cg->setAttr(attr);
+  return unwrap(cg)->setAttr(attr);
 }
 
 void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char *path) {
@@ -229,38 +231,38 @@ void lto_codegen_set_assembler_args(lto_
 
 void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg,
                                           const char *symbol) {
-  cg->addMustPreserveSymbol(symbol);
+  unwrap(cg)->addMustPreserveSymbol(symbol);
 }
 
 bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
   if (!parsedOptions) {
-    cg->parseCodeGenDebugOptions();
+    unwrap(cg)->parseCodeGenDebugOptions();
     lto_add_attrs(cg);
     parsedOptions = true;
   }
-  return !cg->writeMergedModules(path, sLastErrorString);
+  return !unwrap(cg)->writeMergedModules(path, sLastErrorString);
 }
 
 const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
   if (!parsedOptions) {
-    cg->parseCodeGenDebugOptions();
+    unwrap(cg)->parseCodeGenDebugOptions();
     lto_add_attrs(cg);
     parsedOptions = true;
   }
-  return cg->compile(length, DisableOpt, DisableInline, DisableGVNLoadPRE,
-                     sLastErrorString);
+  return unwrap(cg)->compile(length, DisableOpt, DisableInline,
+                             DisableGVNLoadPRE, sLastErrorString);
 }
 
 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
   if (!parsedOptions) {
-    cg->parseCodeGenDebugOptions();
+    unwrap(cg)->parseCodeGenDebugOptions();
     lto_add_attrs(cg);
     parsedOptions = true;
   }
-  return !cg->compile_to_file(name, DisableOpt, DisableInline, DisableGVNLoadPRE,
-                              sLastErrorString);
+  return !unwrap(cg)->compile_to_file(name, DisableOpt, DisableInline,
+                                      DisableGVNLoadPRE, sLastErrorString);
 }
 
 void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {
-  cg->setCodeGenDebugOptions(opt);
+  unwrap(cg)->setCodeGenDebugOptions(opt);
 }





More information about the llvm-commits mailing list