Remove more superfluous .str() and replace std::string concatenation with Twine.

Following r233392, http://llvm.org/viewvc/llvm-project?rev=233392&view=rev.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233555 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Yaron Keren 2015-03-30 15:42:36 +00:00
parent 65e878bd80
commit 6e92e7b09a
22 changed files with 52 additions and 53 deletions

View File

@ -95,16 +95,15 @@ static ExFunc lookupFunction(const Function *F) {
FunctionType *FT = F->getFunctionType(); FunctionType *FT = F->getFunctionType();
for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i) for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i)
ExtName += getTypeID(FT->getContainedType(i)); ExtName += getTypeID(FT->getContainedType(i));
ExtName += "_" + F->getName().str(); ExtName += ("_" + F->getName()).str();
sys::ScopedLock Writer(*FunctionsLock); sys::ScopedLock Writer(*FunctionsLock);
ExFunc FnPtr = (*FuncNames)[ExtName]; ExFunc FnPtr = (*FuncNames)[ExtName];
if (!FnPtr) if (!FnPtr)
FnPtr = (*FuncNames)["lle_X_" + F->getName().str()]; FnPtr = (*FuncNames)[("lle_X_" + F->getName()).str()];
if (!FnPtr) // Try calling a generic function... if it exists... if (!FnPtr) // Try calling a generic function... if it exists...
FnPtr = (ExFunc)(intptr_t) FnPtr = (ExFunc)(intptr_t)sys::DynamicLibrary::SearchForAddressOfSymbol(
sys::DynamicLibrary::SearchForAddressOfSymbol("lle_X_" + ("lle_X_" + F->getName()).str());
F->getName().str());
if (FnPtr) if (FnPtr)
ExportedFunctions->insert(std::make_pair(F, FnPtr)); // Cache for later ExportedFunctions->insert(std::make_pair(F, FnPtr)); // Cache for later
return FnPtr; return FnPtr;

View File

@ -298,12 +298,12 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
// //
if (isStringAttribute()) { if (isStringAttribute()) {
std::string Result; std::string Result;
Result += '\"' + getKindAsString().str() + '"'; Result += (Twine('"') + getKindAsString() + Twine('"')).str();
StringRef Val = pImpl->getValueAsString(); StringRef Val = pImpl->getValueAsString();
if (Val.empty()) return Result; if (Val.empty()) return Result;
Result += "=\"" + Val.str() + '"'; Result += ("=\"" + Val + Twine('"')).str();
return Result; return Result;
} }

View File

@ -745,7 +745,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
return; return;
} }
std::string Name = CI->getName().str(); llvm::StringRef Name = CI->getName();
if (!Name.empty()) if (!Name.empty())
CI->setName(Name + ".old"); CI->setName(Name + ".old");

View File

@ -147,7 +147,7 @@ const std::string DiagnosticInfoOptimizationBase::getLocationStr() const {
unsigned Column = 0; unsigned Column = 0;
if (isLocationAvailable()) if (isLocationAvailable())
getLocation(&Filename, &Line, &Column); getLocation(&Filename, &Line, &Column);
return Twine(Filename + ":" + Twine(Line) + ":" + Twine(Column)).str(); return (Filename + ":" + Twine(Line) + ":" + Twine(Column)).str();
} }
void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const { void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const {

View File

@ -555,7 +555,7 @@ FileInfo::openCoveragePath(StringRef CoveragePath) {
return llvm::make_unique<raw_null_ostream>(); return llvm::make_unique<raw_null_ostream>();
std::error_code EC; std::error_code EC;
auto OS = llvm::make_unique<raw_fd_ostream>(CoveragePath.str(), EC, auto OS = llvm::make_unique<raw_fd_ostream>(CoveragePath, EC,
sys::fs::F_Text); sys::fs::F_Text);
if (EC) { if (EC) {
errs() << EC.message() << "\n"; errs() << EC.message() << "\n";

View File

@ -267,7 +267,7 @@ LTOModule::objcClassNameFromExpression(const Constant *c, std::string &name) {
Constant *cn = gvn->getInitializer(); Constant *cn = gvn->getInitializer();
if (ConstantDataArray *ca = dyn_cast<ConstantDataArray>(cn)) { if (ConstantDataArray *ca = dyn_cast<ConstantDataArray>(cn)) {
if (ca->isCString()) { if (ca->isCString()) {
name = ".objc_class_name_" + ca->getAsCString().str(); name = (".objc_class_name_" + ca->getAsCString()).str();
return true; return true;
} }
} }

View File

@ -4606,7 +4606,7 @@ bool AsmParser::parseMSInlineAsm(
++InputIdx; ++InputIdx;
OutputDecls.push_back(OpDecl); OutputDecls.push_back(OpDecl);
OutputDeclsAddressOf.push_back(Operand.needAddressOf()); OutputDeclsAddressOf.push_back(Operand.needAddressOf());
OutputConstraints.push_back('=' + Operand.getConstraint().str()); OutputConstraints.push_back(("=" + Operand.getConstraint()).str());
AsmStrRewrites.push_back(AsmRewrite(AOK_Output, Start, SymName.size())); AsmStrRewrites.push_back(AsmRewrite(AOK_Output, Start, SymName.size()));
} else { } else {
InputDecls.push_back(OpDecl); InputDecls.push_back(OpDecl);

View File

@ -382,9 +382,7 @@ void WinCOFFObjectWriter::DefineSymbol(MCSymbolData const &SymbolData,
coff_symbol->Other = GetOrCreateCOFFSymbol(&SymRef->getSymbol()); coff_symbol->Other = GetOrCreateCOFFSymbol(&SymRef->getSymbol());
} else { } else {
std::string WeakName = std::string(".weak.") std::string WeakName = (".weak." + Symbol.getName() + ".default").str();
+ Symbol.getName().str()
+ ".default";
COFFSymbol *WeakDefault = createSymbol(WeakName); COFFSymbol *WeakDefault = createSymbol(WeakName);
WeakDefault->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE; WeakDefault->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
WeakDefault->Data.StorageClass = COFF::IMAGE_SYM_CLASS_EXTERNAL; WeakDefault->Data.StorageClass = COFF::IMAGE_SYM_CLASS_EXTERNAL;

View File

@ -1537,7 +1537,7 @@ bool ExportEntry::operator==(const ExportEntry &Other) const {
if (Stack.size() != Other.Stack.size()) if (Stack.size() != Other.Stack.size())
return false; return false;
// Not equal if different cumulative strings. // Not equal if different cumulative strings.
if (!CumulativeString.str().equals(Other.CumulativeString.str())) if (!CumulativeString.equals(Other.CumulativeString))
return false; return false;
// Equal if all nodes in both stacks match. // Equal if all nodes in both stacks match.
for (unsigned i=0; i < Stack.size(); ++i) { for (unsigned i=0; i < Stack.size(); ++i) {
@ -1559,7 +1559,7 @@ uint64_t ExportEntry::readULEB128(const uint8_t *&Ptr) {
} }
StringRef ExportEntry::name() const { StringRef ExportEntry::name() const {
return CumulativeString.str(); return CumulativeString;
} }
uint64_t ExportEntry::flags() const { uint64_t ExportEntry::flags() const {

View File

@ -395,7 +395,7 @@ Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option Opt,
Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option Opt, Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option Opt,
StringRef Value) const { StringRef Value) const {
unsigned Index = BaseArgs.MakeIndex(Opt.getName().str() + Value.str()); unsigned Index = BaseArgs.MakeIndex((Opt.getName() + Value).str());
SynthesizedArgs.push_back(make_unique<Arg>( SynthesizedArgs.push_back(make_unique<Arg>(
Opt, MakeArgString(Opt.getPrefix() + Opt.getName()), Index, Opt, MakeArgString(Opt.getPrefix() + Opt.getName()), Index,
BaseArgs.getArgString(Index) + Opt.getName().size(), BaseArg)); BaseArgs.getArgString(Index) + Opt.getName().size(), BaseArg));

View File

@ -313,7 +313,7 @@ static Option *LookupNearestOption(StringRef Arg,
if (RHS.empty() || !PermitValue) if (RHS.empty() || !PermitValue)
NearestString = OptionNames[i]; NearestString = OptionNames[i];
else else
NearestString = std::string(OptionNames[i]) + "=" + RHS.str(); NearestString = (Twine(OptionNames[i]) + "=" + RHS).str();
} }
} }
} }

View File

@ -92,7 +92,7 @@ static bool ExecGraphViewer(StringRef ExecPath, std::vector<const char *> &args,
errs() << " done. \n"; errs() << " done. \n";
} else { } else {
sys::ExecuteNoWait(ExecPath, args.data(), nullptr, nullptr, 0, &ErrMsg); sys::ExecuteNoWait(ExecPath, args.data(), nullptr, nullptr, 0, &ErrMsg);
errs() << "Remember to erase graph file: " << Filename.str() << "\n"; errs() << "Remember to erase graph file: " << Filename << "\n";
} }
return false; return false;
} }

View File

@ -15,6 +15,7 @@
#include "regex_impl.h" #include "regex_impl.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include <string> #include <string>
using namespace llvm; using namespace llvm;
@ -158,7 +159,7 @@ std::string Regex::sub(StringRef Repl, StringRef String,
RefValue < Matches.size()) RefValue < Matches.size())
Res += Matches[RefValue]; Res += Matches[RefValue];
else if (Error && Error->empty()) else if (Error && Error->empty())
*Error = "invalid backreference string '" + Ref.str() + "'"; *Error = ("invalid backreference string '" + Twine(Ref) + "'").str();
break; break;
} }
} }

View File

@ -207,7 +207,7 @@ GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const {
SmallString<60> Name; SmallString<60> Name;
raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "JTI" raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "JTI"
<< getFunctionNumber() << '_' << uid << '_' << uid2; << getFunctionNumber() << '_' << uid << '_' << uid2;
return OutContext.GetOrCreateSymbol(Name.str()); return OutContext.GetOrCreateSymbol(Name);
} }
@ -216,7 +216,7 @@ MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel() const {
SmallString<60> Name; SmallString<60> Name;
raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "SJLJEH" raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "SJLJEH"
<< getFunctionNumber(); << getFunctionNumber();
return OutContext.GetOrCreateSymbol(Name.str()); return OutContext.GetOrCreateSymbol(Name);
} }
bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
@ -597,7 +597,7 @@ void ARMAsmPrinter::emitAttributes() {
std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU); std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);
if (!FS.empty()) { if (!FS.empty()) {
if (!ArchFS.empty()) if (!ArchFS.empty())
ArchFS = ArchFS + "," + FS.str(); ArchFS = (Twine(ArchFS) + "," + FS).str();
else else
ArchFS = FS; ArchFS = FS;
} }

View File

@ -190,7 +190,7 @@ void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
ARM_MC::ParseARMTriple(TargetTriple.getTriple(), CPUString); ARM_MC::ParseARMTriple(TargetTriple.getTriple(), CPUString);
if (!FS.empty()) { if (!FS.empty()) {
if (!ArchFS.empty()) if (!ArchFS.empty())
ArchFS = ArchFS + "," + FS.str(); ArchFS = (Twine(ArchFS) + "," + FS).str();
else else
ArchFS = FS; ArchFS = FS;
} }

View File

@ -255,7 +255,7 @@ MCSubtargetInfo *ARM_MC::createARMMCSubtargetInfo(StringRef TT, StringRef CPU,
std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU); std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);
if (!FS.empty()) { if (!FS.empty()) {
if (!ArchFS.empty()) if (!ArchFS.empty())
ArchFS = ArchFS + "," + FS.str(); ArchFS = (Twine(ArchFS) + "," + FS).str();
else else
ArchFS = FS; ArchFS = FS;
} }

View File

@ -72,7 +72,7 @@ HexagonSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
HexagonSubtarget::HexagonSubtarget(StringRef TT, StringRef CPU, StringRef FS, HexagonSubtarget::HexagonSubtarget(StringRef TT, StringRef CPU, StringRef FS,
const TargetMachine &TM) const TargetMachine &TM)
: HexagonGenSubtargetInfo(TT, CPU, FS), CPUString(CPU.str()), : HexagonGenSubtargetInfo(TT, CPU, FS), CPUString(CPU),
InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this), InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
TSInfo(*TM.getDataLayout()), FrameLowering() { TSInfo(*TM.getDataLayout()), FrameLowering() {

View File

@ -62,7 +62,7 @@ GetJumpTableSymbol(const MachineOperand &MO) const {
} }
// Create a symbol for the name. // Create a symbol for the name.
return Ctx.GetOrCreateSymbol(Name.str()); return Ctx.GetOrCreateSymbol(Name);
} }
MCSymbol *MSP430MCInstLower:: MCSymbol *MSP430MCInstLower::
@ -79,7 +79,7 @@ GetConstantPoolIndexSymbol(const MachineOperand &MO) const {
} }
// Create a symbol for the name. // Create a symbol for the name.
return Ctx.GetOrCreateSymbol(Name.str()); return Ctx.GetOrCreateSymbol(Name);
} }
MCSymbol *MSP430MCInstLower:: MCSymbol *MSP430MCInstLower::

View File

@ -2571,7 +2571,7 @@ bool MipsAsmParser::parseRelocOperand(const MCExpr *&Res) {
if (Tok.isNot(AsmToken::Identifier)) if (Tok.isNot(AsmToken::Identifier))
return true; return true;
std::string Str = Tok.getIdentifier().str(); std::string Str = Tok.getIdentifier();
Parser.Lex(); // Eat the identifier. Parser.Lex(); // Eat the identifier.
// Now make an expression from the rest of the operand. // Now make an expression from the rest of the operand.

View File

@ -145,20 +145,20 @@ void NVPTXAsmPrinter::emitLineNumberAsDotLoc(const MachineInstr &MI) {
SmallString<128> FullPathName = dirName; SmallString<128> FullPathName = dirName;
if (!dirName.empty() && !sys::path::is_absolute(fileName)) { if (!dirName.empty() && !sys::path::is_absolute(fileName)) {
sys::path::append(FullPathName, fileName); sys::path::append(FullPathName, fileName);
fileName = FullPathName.str(); fileName = FullPathName;
} }
if (filenameMap.find(fileName.str()) == filenameMap.end()) if (filenameMap.find(fileName) == filenameMap.end())
return; return;
// Emit the line from the source file. // Emit the line from the source file.
if (InterleaveSrc) if (InterleaveSrc)
this->emitSrcInText(fileName.str(), curLoc.getLine()); this->emitSrcInText(fileName, curLoc.getLine());
std::stringstream temp; std::stringstream temp;
temp << "\t.loc " << filenameMap[fileName.str()] << " " << curLoc.getLine() temp << "\t.loc " << filenameMap[fileName] << " " << curLoc.getLine()
<< " " << curLoc.getCol(); << " " << curLoc.getCol();
OutStreamer.EmitRawText(Twine(temp.str().c_str())); OutStreamer.EmitRawText(temp.str());
} }
void NVPTXAsmPrinter::EmitInstruction(const MachineInstr *MI) { void NVPTXAsmPrinter::EmitInstruction(const MachineInstr *MI) {
@ -641,7 +641,7 @@ static bool usedInGlobalVarDef(const Constant *C) {
return false; return false;
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) { if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (GV->getName().str() == "llvm.used") if (GV->getName() == "llvm.used")
return false; return false;
return true; return true;
} }
@ -656,7 +656,7 @@ static bool usedInGlobalVarDef(const Constant *C) {
static bool usedInOneFunc(const User *U, Function const *&oneFunc) { static bool usedInOneFunc(const User *U, Function const *&oneFunc) {
if (const GlobalVariable *othergv = dyn_cast<GlobalVariable>(U)) { if (const GlobalVariable *othergv = dyn_cast<GlobalVariable>(U)) {
if (othergv->getName().str() == "llvm.used") if (othergv->getName() == "llvm.used")
return true; return true;
} }
@ -786,12 +786,12 @@ void NVPTXAsmPrinter::recordAndEmitFilenames(Module &M) {
SmallString<128> FullPathName = Dirname; SmallString<128> FullPathName = Dirname;
if (!Dirname.empty() && !sys::path::is_absolute(Filename)) { if (!Dirname.empty() && !sys::path::is_absolute(Filename)) {
sys::path::append(FullPathName, Filename); sys::path::append(FullPathName, Filename);
Filename = FullPathName.str(); Filename = FullPathName;
} }
if (filenameMap.find(Filename.str()) != filenameMap.end()) if (filenameMap.find(Filename) != filenameMap.end())
continue; continue;
filenameMap[Filename.str()] = i; filenameMap[Filename] = i;
OutStreamer.EmitDwarfFileDirective(i, "", Filename.str()); OutStreamer.EmitDwarfFileDirective(i, "", Filename);
++i; ++i;
} }
@ -801,11 +801,11 @@ void NVPTXAsmPrinter::recordAndEmitFilenames(Module &M) {
SmallString<128> FullPathName = Dirname; SmallString<128> FullPathName = Dirname;
if (!Dirname.empty() && !sys::path::is_absolute(Filename)) { if (!Dirname.empty() && !sys::path::is_absolute(Filename)) {
sys::path::append(FullPathName, Filename); sys::path::append(FullPathName, Filename);
Filename = FullPathName.str(); Filename = FullPathName;
} }
if (filenameMap.find(Filename.str()) != filenameMap.end()) if (filenameMap.find(Filename) != filenameMap.end())
continue; continue;
filenameMap[Filename.str()] = i; filenameMap[Filename] = i;
++i; ++i;
} }
} }
@ -1011,7 +1011,7 @@ void NVPTXAsmPrinter::emitLinkageDirective(const GlobalValue *V,
msg.append("Error: "); msg.append("Error: ");
msg.append("Symbol "); msg.append("Symbol ");
if (V->hasName()) if (V->hasName())
msg.append(V->getName().str()); msg.append(V->getName());
msg.append("has unsupported appending linkage type"); msg.append("has unsupported appending linkage type");
llvm_unreachable(msg.c_str()); llvm_unreachable(msg.c_str());
} else if (!V->hasInternalLinkage() && } else if (!V->hasInternalLinkage() &&
@ -1147,7 +1147,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
const Function *demotedFunc = nullptr; const Function *demotedFunc = nullptr;
if (!processDemoted && canDemoteGlobalVar(GVar, demotedFunc)) { if (!processDemoted && canDemoteGlobalVar(GVar, demotedFunc)) {
O << "// " << GVar->getName().str() << " has been demoted\n"; O << "// " << GVar->getName() << " has been demoted\n";
if (localDecls.find(demotedFunc) != localDecls.end()) if (localDecls.find(demotedFunc) != localDecls.end())
localDecls[demotedFunc].push_back(GVar); localDecls[demotedFunc].push_back(GVar);
else { else {
@ -1195,9 +1195,10 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
// The frontend adds zero-initializer to variables that don't have an // The frontend adds zero-initializer to variables that don't have an
// initial value, so skip warning for this case. // initial value, so skip warning for this case.
if (!GVar->getInitializer()->isNullValue()) { if (!GVar->getInitializer()->isNullValue()) {
std::string warnMsg = "initial value of '" + GVar->getName().str() + std::string warnMsg =
"' is not allowed in addrspace(" + ("initial value of '" + GVar->getName() +
llvm::utostr_32(PTy->getAddressSpace()) + ")"; "' is not allowed in addrspace(" +
Twine(llvm::utostr_32(PTy->getAddressSpace())) + ")").str();
report_fatal_error(warnMsg.c_str()); report_fatal_error(warnMsg.c_str());
} }
} }
@ -2086,7 +2087,7 @@ void NVPTXAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
void NVPTXAsmPrinter::emitSrcInText(StringRef filename, unsigned line) { void NVPTXAsmPrinter::emitSrcInText(StringRef filename, unsigned line) {
std::stringstream temp; std::stringstream temp;
LineReader *reader = this->getReader(filename.str()); LineReader *reader = this->getReader(filename);
temp << "\n//"; temp << "\n//";
temp << filename.str(); temp << filename.str();
temp << ":"; temp << ":";
@ -2094,7 +2095,7 @@ void NVPTXAsmPrinter::emitSrcInText(StringRef filename, unsigned line) {
temp << " "; temp << " ";
temp << reader->readLine(line); temp << reader->readLine(line);
temp << "\n"; temp << "\n";
this->OutStreamer.EmitRawText(Twine(temp.str())); this->OutStreamer.EmitRawText(temp.str());
} }
LineReader *NVPTXAsmPrinter::getReader(std::string filename) { LineReader *NVPTXAsmPrinter::getReader(std::string filename) {

View File

@ -104,7 +104,7 @@ void SITypeRewriter::visitCallInst(CallInst &I) {
SmallVector <Type*, 8> Types; SmallVector <Type*, 8> Types;
bool NeedToReplace = false; bool NeedToReplace = false;
Function *F = I.getCalledFunction(); Function *F = I.getCalledFunction();
std::string Name = F->getName().str(); std::string Name = F->getName();
for (unsigned i = 0, e = I.getNumArgOperands(); i != e; ++i) { for (unsigned i = 0, e = I.getNumArgOperands(); i != e; ++i) {
Value *Arg = I.getArgOperand(i); Value *Arg = I.getArgOperand(i);
if (Arg->getType() == v16i8) { if (Arg->getType() == v16i8) {

View File

@ -2571,7 +2571,7 @@ bool X86AsmParser::MatchAndEmitATTInstruction(SMLoc IDLoc, unsigned &Opcode,
SmallString<16> Tmp; SmallString<16> Tmp;
Tmp += Base; Tmp += Base;
Tmp += ' '; Tmp += ' ';
Op.setTokenValue(Tmp.str()); Op.setTokenValue(Tmp);
// If this instruction starts with an 'f', then it is a floating point stack // If this instruction starts with an 'f', then it is a floating point stack
// instruction. These come in up to three forms for 32-bit, 64-bit, and // instruction. These come in up to three forms for 32-bit, 64-bit, and