[llvm] r283456 - Revert "Use StringRef in LTOModule implementation (NFC)"
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 6 08:12:23 PDT 2016
Author: mehdi_amini
Date: Thu Oct 6 10:12:22 2016
New Revision: 283456
URL: http://llvm.org/viewvc/llvm-project?rev=283456&view=rev
Log:
Revert "Use StringRef in LTOModule implementation (NFC)"
This reverts commit r282997, a windows bot is asserting in
one test apparently.
Modified:
llvm/trunk/include/llvm/LTO/legacy/LTOModule.h
llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
llvm/trunk/lib/LTO/LTOModule.cpp
llvm/trunk/tools/lto/lto.cpp
Modified: llvm/trunk/include/llvm/LTO/legacy/LTOModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/legacy/LTOModule.h?rev=283456&r1=283455&r2=283456&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/legacy/LTOModule.h (original)
+++ llvm/trunk/include/llvm/LTO/legacy/LTOModule.h Thu Oct 6 10:12:22 2016
@@ -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<NameAndAttributes> _undefines;
- std::vector<StringRef> _asm_undefines;
+ std::vector<const char*> _asm_undefines;
LTOModule(std::unique_ptr<object::IRObjectFile> 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<std::unique_ptr<LTOModule>>
- createFromFile(LLVMContext &Context, StringRef path,
+ createFromFile(LLVMContext &Context, const char *path,
const TargetOptions &options);
static ErrorOr<std::unique_ptr<LTOModule>>
- 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<std::unique_ptr<LTOModule>>
- 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<std::unique_ptr<LTOModule>>
@@ -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<StringRef> &getAsmUndefinedRefs() { return _asm_undefines; }
+ const std::vector<const char*> &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);
Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=283456&r1=283455&r2=283456&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Thu Oct 6 10:12:22 2016
@@ -131,7 +131,7 @@ void LTOCodeGenerator::initializeLTOPass
}
void LTOCodeGenerator::setAsmUndefinedRefs(LTOModule *Mod) {
- const std::vector<StringRef> &undefs = Mod->getAsmUndefinedRefs();
+ const std::vector<const char *> &undefs = Mod->getAsmUndefinedRefs();
for (int i = 0, e = undefs.size(); i != e; ++i)
AsmUndefinedRefs[undefs[i]] = 1;
}
Modified: llvm/trunk/lib/LTO/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=283456&r1=283455&r2=283456&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOModule.cpp (original)
+++ llvm/trunk/lib/LTO/LTOModule.cpp Thu Oct 6 10:12:22 2016
@@ -62,7 +62,7 @@ bool LTOModule::isBitcodeFile(const void
return bool(BCData);
}
-bool LTOModule::isBitcodeFile(StringRef Path) {
+bool LTOModule::isBitcodeFile(const char *Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFile(Path);
if (!BufferOrErr)
@@ -106,7 +106,7 @@ std::string LTOModule::getProducerString
}
ErrorOr<std::unique_ptr<LTOModule>>
-LTOModule::createFromFile(LLVMContext &Context, StringRef path,
+LTOModule::createFromFile(LLVMContext &Context, const char *path,
const TargetOptions &options) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFile(path);
@@ -120,15 +120,15 @@ LTOModule::createFromFile(LLVMContext &C
}
ErrorOr<std::unique_ptr<LTOModule>>
-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<std::unique_ptr<LTOModule>>
-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<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getOpenFileSlice(fd, path, map_size, offset);
if (std::error_code EC = BufferOrErr.getError()) {
@@ -280,7 +280,7 @@ void LTOModule::addObjCClass(const Globa
_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 Globa
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 Gl
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 Gl
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(con
{
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
{
raw_svector_ostream OS(Buffer);
Sym.printName(OS);
- Buffer.c_str();
}
const Function *F =
cast<Function>(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(StringR
// 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(StringR
/// 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(Strin
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(Strin
// 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(Strin
/// 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(
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::addPotentialUndefinedSym
{
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::addPotentialUndefinedSym
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);
Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=283456&r1=283455&r2=283456&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Thu Oct 6 10:12:22 2016
@@ -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_targe
ErrorOr<std::unique_ptr<MemoryBuffer>> 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_
std::unique_ptr<MemoryBuffer> 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<std::unique_ptr<LTOModule>> 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 cha
lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
lto_initialize();
llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
- ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createFromOpenFile(
- *LTOContext, fd, StringRef(path), size, Options);
+ ErrorOr<std::unique_ptr<LTOModule>> 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_a
lto_initialize();
llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
ErrorOr<std::unique_ptr<LTOModule>> 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_memo
const char *path) {
lto_initialize();
llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
- ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createFromBuffer(
- *LTOContext, mem, length, Options, StringRef(path));
+ ErrorOr<std::unique_ptr<LTOModule>> 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_
std::unique_ptr<LLVMContext> Context = llvm::make_unique<LLVMContext>();
Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
- ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createInLocalContext(
- std::move(Context), mem, length, Options, StringRef(path));
+ ErrorOr<std::unique_ptr<LTOModule>> 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_codege
lto_initialize();
llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
ErrorOr<std::unique_ptr<LTOModule>> 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
}
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(
}
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_sym
}
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,
More information about the llvm-commits
mailing list