diff --git a/include/llvm-c/lto.h b/include/llvm-c/lto.h index 84e22b32e0c..51079896d7f 100644 --- a/include/llvm-c/lto.h +++ b/include/llvm-c/lto.h @@ -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" { diff --git a/include/llvm/LTO/LTOCodeGenerator.h b/include/llvm/LTO/LTOCodeGenerator.h index ee3b90d9c60..bef6e9c6a72 100644 --- a/include/llvm/LTO/LTOCodeGenerator.h +++ b/include/llvm/LTO/LTOCodeGenerator.h @@ -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 &Libcalls, - std::vector &MustPreserveList, - llvm::SmallPtrSet &AsmUsed, - llvm::Mangler &Mangler); + void applyRestriction(GlobalValue &GV, const ArrayRef &Libcalls, + std::vector &MustPreserveList, + SmallPtrSet &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 StringSet; + typedef StringMap 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 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 diff --git a/include/llvm/LTO/LTOModule.h b/include/llvm/LTO/LTOModule.h index 66ce88d959c..f1b1480ad66 100644 --- a/include/llvm/LTO/LTOModule.h +++ b/include/llvm/LTO/LTOModule.h @@ -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 StringSet; + typedef StringMap StringSet; struct NameAndAttributes { const char *name; uint32_t attributes; bool isFunction; - const llvm::GlobalValue *symbol; + const GlobalValue *symbol; }; - std::unique_ptr _module; - std::unique_ptr _target; - llvm::MCObjectFileInfo ObjFileInfo; + std::unique_ptr _module; + std::unique_ptr _target; + MCObjectFileInfo ObjFileInfo; StringSet _linkeropt_strings; std::vector _deplibs; std::vector _linkeropts; @@ -57,14 +56,15 @@ private: // _defines and _undefines only needed to disambiguate tentative definitions StringSet _defines; - llvm::StringMap _undefines; + StringMap _undefines; std::vector _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 &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 diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index e43f6d671ba..7e9196393d5 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -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 cg) { 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_target(const void* mem, 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_at_offset(int fd, const char *path, 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_memory_with_path(const void* mem, 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_code_gen_t cg, const char **args, 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); }