From 54de28779875ed67dcb41af76d4ea5a2269589e9 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Thu, 6 Oct 2016 15:12:22 +0000 Subject: [PATCH] Revert "Use StringRef in LTOModule implementation (NFC)" This reverts commit r282997, a windows bot is asserting in one test apparently. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283456 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/LTO/legacy/LTOModule.h | 36 ++++++++++++++----------- lib/LTO/LTOCodeGenerator.cpp | 2 +- lib/LTO/LTOModule.cpp | 54 +++++++++++++++++-------------------- tools/lto/lto.cpp | 33 +++++++++++------------ 4 files changed, 62 insertions(+), 63 deletions(-) diff --git a/include/llvm/LTO/legacy/LTOModule.h b/include/llvm/LTO/legacy/LTOModule.h index 6b1dbeb0639..2e46219be19 100644 --- a/include/llvm/LTO/legacy/LTOModule.h +++ b/include/llvm/LTO/legacy/LTOModule.h @@ -37,7 +37,7 @@ namespace llvm { struct LTOModule { private: struct NameAndAttributes { - StringRef name; + const char *name; uint32_t attributes; bool isFunction; const GlobalValue *symbol; @@ -54,7 +54,7 @@ private: // _defines and _undefines only needed to disambiguate tentative definitions StringSet<> _defines; StringMap _undefines; - std::vector _asm_undefines; + std::vector _asm_undefines; LTOModule(std::unique_ptr Obj, TargetMachine *TM); @@ -63,7 +63,7 @@ public: /// Returns 'true' if the file or memory contents is LLVM bitcode. static bool isBitcodeFile(const void *mem, size_t length); - static bool isBitcodeFile(StringRef path); + static bool isBitcodeFile(const char *path); /// Returns 'true' if the Module is produced for ThinLTO. bool isThinLTO(); @@ -91,13 +91,13 @@ public: /// InitializeAllAsmPrinters(); /// InitializeAllAsmParsers(); static ErrorOr> - createFromFile(LLVMContext &Context, StringRef path, + createFromFile(LLVMContext &Context, const char *path, const TargetOptions &options); static ErrorOr> - createFromOpenFile(LLVMContext &Context, int fd, StringRef path, size_t size, - const TargetOptions &options); + createFromOpenFile(LLVMContext &Context, int fd, const char *path, + size_t size, const TargetOptions &options); static ErrorOr> - createFromOpenFileSlice(LLVMContext &Context, int fd, StringRef path, + createFromOpenFileSlice(LLVMContext &Context, int fd, const char *path, size_t map_size, off_t offset, const TargetOptions &options); static ErrorOr> @@ -140,10 +140,10 @@ public: } /// Get the name of the symbol at the specified index. - StringRef getSymbolName(uint32_t index) { + const char *getSymbolName(uint32_t index) { if (index < _symbols.size()) return _symbols[index].name; - return StringRef(); + return nullptr; } const GlobalValue *getSymbolGV(uint32_t index) { @@ -152,9 +152,13 @@ public: return nullptr; } - StringRef getLinkerOpts() { return LinkerOpts; } + const char *getLinkerOpts() { + return LinkerOpts.c_str(); + } - const std::vector &getAsmUndefinedRefs() { return _asm_undefines; } + const std::vector &getAsmUndefinedRefs() { + return _asm_undefines; + } private: /// Parse metadata from the module @@ -170,22 +174,22 @@ private: bool isFunc); /// Add a defined symbol to the list. - void addDefinedSymbol(StringRef Name, const GlobalValue *def, + void addDefinedSymbol(const char *Name, const GlobalValue *def, bool isFunction); /// Add a data symbol as defined to the list. void addDefinedDataSymbol(const object::BasicSymbolRef &Sym); - void addDefinedDataSymbol(StringRef Name, const GlobalValue *v); + void addDefinedDataSymbol(const char*Name, const GlobalValue *v); /// Add a function symbol as defined to the list. void addDefinedFunctionSymbol(const object::BasicSymbolRef &Sym); - void addDefinedFunctionSymbol(StringRef Name, const Function *F); + void addDefinedFunctionSymbol(const char *Name, const Function *F); /// Add a global symbol from module-level ASM to the defined list. - void addAsmGlobalSymbol(StringRef, lto_symbol_attributes scope); + void addAsmGlobalSymbol(const char *, lto_symbol_attributes scope); /// Add a global symbol from module-level ASM to the undefined list. - void addAsmGlobalSymbolUndef(StringRef); + void addAsmGlobalSymbolUndef(const char *); /// Parse i386/ppc ObjC class data structure. void addObjCClass(const GlobalVariable *clgv); diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 81fb58a4e0a..1ade0fb7530 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -131,7 +131,7 @@ void LTOCodeGenerator::initializeLTOPasses() { } void LTOCodeGenerator::setAsmUndefinedRefs(LTOModule *Mod) { - const std::vector &undefs = Mod->getAsmUndefinedRefs(); + const std::vector &undefs = Mod->getAsmUndefinedRefs(); for (int i = 0, e = undefs.size(); i != e; ++i) AsmUndefinedRefs[undefs[i]] = 1; } diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index 5b46feb15b9..cca33546a43 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -62,7 +62,7 @@ bool LTOModule::isBitcodeFile(const void *Mem, size_t Length) { return bool(BCData); } -bool LTOModule::isBitcodeFile(StringRef Path) { +bool LTOModule::isBitcodeFile(const char *Path) { ErrorOr> BufferOrErr = MemoryBuffer::getFile(Path); if (!BufferOrErr) @@ -106,7 +106,7 @@ std::string LTOModule::getProducerString(MemoryBuffer *Buffer) { } ErrorOr> -LTOModule::createFromFile(LLVMContext &Context, StringRef path, +LTOModule::createFromFile(LLVMContext &Context, const char *path, const TargetOptions &options) { ErrorOr> BufferOrErr = MemoryBuffer::getFile(path); @@ -120,15 +120,15 @@ LTOModule::createFromFile(LLVMContext &Context, StringRef path, } ErrorOr> -LTOModule::createFromOpenFile(LLVMContext &Context, int fd, StringRef path, +LTOModule::createFromOpenFile(LLVMContext &Context, int fd, const char *path, size_t size, const TargetOptions &options) { return createFromOpenFileSlice(Context, fd, path, size, 0, options); } ErrorOr> -LTOModule::createFromOpenFileSlice(LLVMContext &Context, int fd, StringRef path, - size_t map_size, off_t offset, - const TargetOptions &options) { +LTOModule::createFromOpenFileSlice(LLVMContext &Context, int fd, + const char *path, size_t map_size, + off_t offset, const TargetOptions &options) { ErrorOr> BufferOrErr = MemoryBuffer::getOpenFileSlice(fd, path, map_size, offset); if (std::error_code EC = BufferOrErr.getError()) { @@ -280,7 +280,7 @@ void LTOModule::addObjCClass(const GlobalVariable *clgv) { _undefines.insert(std::make_pair(superclassName, NameAndAttributes())); if (IterBool.second) { NameAndAttributes &info = IterBool.first->second; - info.name = IterBool.first->first(); + info.name = IterBool.first->first().data(); info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; info.isFunction = false; info.symbol = clgv; @@ -293,7 +293,7 @@ void LTOModule::addObjCClass(const GlobalVariable *clgv) { auto Iter = _defines.insert(className).first; NameAndAttributes info; - info.name = Iter->first(); + info.name = Iter->first().data(); info.attributes = LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT; info.isFunction = false; @@ -319,7 +319,7 @@ void LTOModule::addObjCCategory(const GlobalVariable *clgv) { return; NameAndAttributes &info = IterBool.first->second; - info.name = IterBool.first->first(); + info.name = IterBool.first->first().data(); info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; info.isFunction = false; info.symbol = clgv; @@ -338,7 +338,7 @@ void LTOModule::addObjCClassRef(const GlobalVariable *clgv) { return; NameAndAttributes &info = IterBool.first->second; - info.name = IterBool.first->first(); + info.name = IterBool.first->first().data(); info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; info.isFunction = false; info.symbol = clgv; @@ -349,14 +349,13 @@ void LTOModule::addDefinedDataSymbol(const object::BasicSymbolRef &Sym) { { raw_svector_ostream OS(Buffer); Sym.printName(OS); - Buffer.c_str(); } const GlobalValue *V = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); - addDefinedDataSymbol(Buffer, V); + addDefinedDataSymbol(Buffer.c_str(), V); } -void LTOModule::addDefinedDataSymbol(StringRef Name, const GlobalValue *v) { +void LTOModule::addDefinedDataSymbol(const char *Name, const GlobalValue *v) { // Add to list of defined symbols. addDefinedSymbol(Name, v, false); @@ -411,20 +410,19 @@ void LTOModule::addDefinedFunctionSymbol(const object::BasicSymbolRef &Sym) { { raw_svector_ostream OS(Buffer); Sym.printName(OS); - Buffer.c_str(); } const Function *F = cast(IRFile->getSymbolGV(Sym.getRawDataRefImpl())); - addDefinedFunctionSymbol(Buffer, F); + addDefinedFunctionSymbol(Buffer.c_str(), F); } -void LTOModule::addDefinedFunctionSymbol(StringRef Name, const Function *F) { +void LTOModule::addDefinedFunctionSymbol(const char *Name, const Function *F) { // add to list of defined symbols addDefinedSymbol(Name, F, true); } -void LTOModule::addDefinedSymbol(StringRef Name, const GlobalValue *def, +void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def, bool isFunction) { // set alignment part log2() can have rounding errors uint32_t align = def->getAlignment(); @@ -473,8 +471,8 @@ void LTOModule::addDefinedSymbol(StringRef Name, const GlobalValue *def, // fill information structure NameAndAttributes info; StringRef NameRef = Iter->first(); - info.name = NameRef; - assert(NameRef.data()[NameRef.size()] == '\0'); + info.name = NameRef.data(); + assert(info.name[NameRef.size()] == '\0'); info.attributes = attr; info.isFunction = isFunction; info.symbol = def; @@ -485,7 +483,7 @@ void LTOModule::addDefinedSymbol(StringRef Name, const GlobalValue *def, /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the /// defined list. -void LTOModule::addAsmGlobalSymbol(StringRef name, +void LTOModule::addAsmGlobalSymbol(const char *name, lto_symbol_attributes scope) { auto IterBool = _defines.insert(name); @@ -493,7 +491,7 @@ void LTOModule::addAsmGlobalSymbol(StringRef name, if (!IterBool.second) return; - NameAndAttributes &info = _undefines[IterBool.first->first()]; + NameAndAttributes &info = _undefines[IterBool.first->first().data()]; if (info.symbol == nullptr) { // FIXME: This is trying to take care of module ASM like this: @@ -505,7 +503,7 @@ void LTOModule::addAsmGlobalSymbol(StringRef name, // much. // fill information structure - info.name = IterBool.first->first(); + info.name = IterBool.first->first().data(); info.attributes = LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | scope; info.isFunction = false; @@ -527,10 +525,10 @@ void LTOModule::addAsmGlobalSymbol(StringRef name, /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the /// undefined list. -void LTOModule::addAsmGlobalSymbolUndef(StringRef name) { +void LTOModule::addAsmGlobalSymbolUndef(const char *name) { auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes())); - _asm_undefines.push_back(IterBool.first->first()); + _asm_undefines.push_back(IterBool.first->first().data()); // we already have the symbol if (!IterBool.second) @@ -539,7 +537,7 @@ void LTOModule::addAsmGlobalSymbolUndef(StringRef name) { uint32_t attr = LTO_SYMBOL_DEFINITION_UNDEFINED; attr |= LTO_SYMBOL_SCOPE_DEFAULT; NameAndAttributes &info = IterBool.first->second; - info.name = IterBool.first->first(); + info.name = IterBool.first->first().data(); info.attributes = attr; info.isFunction = false; info.symbol = nullptr; @@ -552,7 +550,6 @@ void LTOModule::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym, { raw_svector_ostream OS(name); Sym.printName(OS); - name.c_str(); } auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes())); @@ -563,7 +560,7 @@ void LTOModule::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym, NameAndAttributes &info = IterBool.first->second; - info.name = IterBool.first->first(); + info.name = IterBool.first->first().data(); const GlobalValue *decl = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); @@ -590,9 +587,8 @@ void LTOModule::parseSymbols() { { raw_svector_ostream OS(Buffer); Sym.printName(OS); - Buffer.c_str(); } - StringRef Name(Buffer); + const char *Name = Buffer.c_str(); if (IsUndefined) addAsmGlobalSymbolUndef(Name); diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index 64014e5a8e5..7109cf4d909 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -170,7 +170,7 @@ const char* lto_get_error_message() { } bool lto_module_is_object_file(const char* path) { - return LTOModule::isBitcodeFile(StringRef(path)); + return LTOModule::isBitcodeFile(path); } bool lto_module_is_object_file_for_target(const char* path, @@ -178,8 +178,7 @@ bool lto_module_is_object_file_for_target(const char* path, ErrorOr> Buffer = MemoryBuffer::getFile(path); if (!Buffer) return false; - return LTOModule::isBitcodeForTarget(Buffer->get(), - StringRef(target_triplet_prefix)); + return LTOModule::isBitcodeForTarget(Buffer->get(), target_triplet_prefix); } bool lto_module_has_objc_category(const void *mem, size_t length) { @@ -201,15 +200,14 @@ lto_module_is_object_file_in_memory_for_target(const void* mem, std::unique_ptr buffer(LTOModule::makeBuffer(mem, length)); if (!buffer) return false; - return LTOModule::isBitcodeForTarget(buffer.get(), - StringRef(target_triplet_prefix)); + return LTOModule::isBitcodeForTarget(buffer.get(), target_triplet_prefix); } lto_module_t lto_module_create(const char* path) { lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); ErrorOr> M = - LTOModule::createFromFile(*LTOContext, StringRef(path), Options); + LTOModule::createFromFile(*LTOContext, path, Options); if (!M) return nullptr; return wrap(M->release()); @@ -218,8 +216,8 @@ lto_module_t lto_module_create(const char* path) { lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) { lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); - ErrorOr> M = LTOModule::createFromOpenFile( - *LTOContext, fd, StringRef(path), size, Options); + ErrorOr> M = + LTOModule::createFromOpenFile(*LTOContext, fd, path, size, Options); if (!M) return nullptr; return wrap(M->release()); @@ -232,7 +230,7 @@ lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path, lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); ErrorOr> M = LTOModule::createFromOpenFileSlice( - *LTOContext, fd, StringRef(path), map_size, offset, Options); + *LTOContext, fd, path, map_size, offset, Options); if (!M) return nullptr; return wrap(M->release()); @@ -253,8 +251,8 @@ lto_module_t lto_module_create_from_memory_with_path(const void* mem, const char *path) { lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); - ErrorOr> M = LTOModule::createFromBuffer( - *LTOContext, mem, length, Options, StringRef(path)); + ErrorOr> M = + LTOModule::createFromBuffer(*LTOContext, mem, length, Options, path); if (!M) return nullptr; return wrap(M->release()); @@ -269,8 +267,9 @@ lto_module_t lto_module_create_in_local_context(const void *mem, size_t length, std::unique_ptr Context = llvm::make_unique(); Context->setDiagnosticHandler(diagnosticHandler, nullptr, true); - ErrorOr> M = LTOModule::createInLocalContext( - std::move(Context), mem, length, Options, StringRef(path)); + ErrorOr> M = + LTOModule::createInLocalContext(std::move(Context), mem, length, Options, + path); if (!M) return nullptr; return wrap(M->release()); @@ -283,7 +282,7 @@ lto_module_t lto_module_create_in_codegen_context(const void *mem, lto_initialize(); llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); ErrorOr> M = LTOModule::createFromBuffer( - unwrap(cg)->getContext(), mem, length, Options, StringRef(path)); + unwrap(cg)->getContext(), mem, length, Options, path); return wrap(M->release()); } @@ -294,7 +293,7 @@ const char* lto_module_get_target_triple(lto_module_t mod) { } void lto_module_set_target_triple(lto_module_t mod, const char *triple) { - return unwrap(mod)->setTargetTriple(StringRef(triple)); + return unwrap(mod)->setTargetTriple(triple); } unsigned int lto_module_get_num_symbols(lto_module_t mod) { @@ -302,7 +301,7 @@ unsigned int lto_module_get_num_symbols(lto_module_t mod) { } const char* lto_module_get_symbol_name(lto_module_t mod, unsigned int index) { - return unwrap(mod)->getSymbolName(index).data(); + return unwrap(mod)->getSymbolName(index); } lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod, @@ -311,7 +310,7 @@ lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod, } const char* lto_module_get_linkeropts(lto_module_t mod) { - return unwrap(mod)->getLinkerOpts().data(); + return unwrap(mod)->getLinkerOpts(); } void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg, -- 2.11.0