Skip to content

Commit fffe84e

Browse files
committed
[NFC][TableGen] Use StringRef::str() instead of casting
1 parent 802d8d9 commit fffe84e

34 files changed

+188
-212
lines changed

llvm/include/llvm/TableGen/Record.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,7 @@ class StringInit final : public TypedInit {
745745
return "[{" + Value.str() + "}]";
746746
}
747747

748-
std::string getAsUnquotedString() const override {
749-
return std::string(Value);
750-
}
748+
std::string getAsUnquotedString() const override { return Value.str(); }
751749

752750
const Init *getBit(unsigned Bit) const override {
753751
llvm_unreachable("Illegal bit reference off string");

llvm/lib/TableGen/Record.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -1787,22 +1787,21 @@ const Init *TernOpInit::Fold(const Record *CurRec) const {
17871787
return Val->getDefInit();
17881788
}
17891789
if (LHSv && MHSv && RHSv) {
1790-
std::string Val = std::string(RHSv->getName());
1790+
std::string Val = RHSv->getName().str();
17911791
if (LHSv->getAsString() == RHSv->getAsString())
1792-
Val = std::string(MHSv->getName());
1792+
Val = MHSv->getName().str();
17931793
return VarInit::get(Val, getType());
17941794
}
17951795
if (LHSs && MHSs && RHSs) {
1796-
std::string Val = std::string(RHSs->getValue());
1796+
std::string Val = RHSs->getValue().str();
17971797

17981798
std::string::size_type found;
17991799
std::string::size_type idx = 0;
18001800
while (true) {
1801-
found = Val.find(std::string(LHSs->getValue()), idx);
1801+
found = Val.find(LHSs->getValue().str(), idx);
18021802
if (found == std::string::npos)
18031803
break;
1804-
Val.replace(found, LHSs->getValue().size(),
1805-
std::string(MHSs->getValue()));
1804+
Val.replace(found, LHSs->getValue().size(), MHSs->getValue().str());
18061805
idx = found + MHSs->getValue().size();
18071806
}
18081807

@@ -2417,7 +2416,7 @@ const RecTy *DefInit::getFieldType(const StringInit *FieldName) const {
24172416
return nullptr;
24182417
}
24192418

2420-
std::string DefInit::getAsString() const { return std::string(Def->getName()); }
2419+
std::string DefInit::getAsString() const { return Def->getName().str(); }
24212420

24222421
static void ProfileVarDefInit(FoldingSetNodeID &ID, const Record *Class,
24232422
ArrayRef<const ArgumentInit *> Args) {

llvm/lib/TableGen/SetTheory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct SequenceOp : public SetTheory::Operator {
191191

192192
std::string Format;
193193
if (const auto *SI = dyn_cast<StringInit>(Expr->arg_begin()[0]))
194-
Format = std::string(SI->getValue());
194+
Format = SI->getValue().str();
195195
else
196196
PrintFatalError(Loc, "Format must be a string: " + Expr->getAsString());
197197

llvm/lib/TableGen/TGParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,7 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
43264326
// through its template argument names. Substs contains a substitution
43274327
// value for each argument, either the value specified or the default.
43284328
// Then we can resolve the template arguments.
4329-
MultiClass *MC = MultiClasses[std::string(Ref.Rec->getName())].get();
4329+
MultiClass *MC = MultiClasses[Ref.Rec->getName().str()].get();
43304330
assert(MC && "Didn't lookup multiclass correctly?");
43314331

43324332
SubstStack Substs;

llvm/lib/TableGen/TGParser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class TGVarScope {
131131
}
132132

133133
void addVar(StringRef Name, const Init *I) {
134-
bool Ins = Vars.try_emplace(std::string(Name), I).second;
134+
bool Ins = Vars.try_emplace(Name.str(), I).second;
135135
(void)Ins;
136136
assert(Ins && "Local variable already exists");
137137
}

llvm/utils/TableGen/AsmMatcherEmitter.cpp

+20-19
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ bool MatchableInfo::validate(StringRef CommentDelimiter, bool IsAlias) const {
11141114
// Verify that any operand is only mentioned once.
11151115
// We reject aliases and ignore instructions for now.
11161116
if (!IsAlias && TheDef->getValueAsString("AsmMatchConverter").empty() &&
1117-
Tok[0] == '$' && !OperandNames.insert(std::string(Tok)).second) {
1117+
Tok[0] == '$' && !OperandNames.insert(Tok.str()).second) {
11181118
LLVM_DEBUG({
11191119
errs() << "warning: '" << TheDef->getName() << "': "
11201120
<< "ignoring instruction with tied operand '" << Tok << "'\n";
@@ -1170,15 +1170,15 @@ static std::string getEnumNameForToken(StringRef Str) {
11701170
}
11711171

11721172
ClassInfo *AsmMatcherInfo::getTokenClass(StringRef Token) {
1173-
ClassInfo *&Entry = TokenClasses[std::string(Token)];
1173+
ClassInfo *&Entry = TokenClasses[Token.str()];
11741174

11751175
if (!Entry) {
11761176
Classes.emplace_front();
11771177
Entry = &Classes.front();
11781178
Entry->Kind = ClassInfo::Token;
11791179
Entry->ClassName = "Token";
11801180
Entry->Name = "MCK_" + getEnumNameForToken(Token);
1181-
Entry->ValueName = std::string(Token);
1181+
Entry->ValueName = Token.str();
11821182
Entry->PredicateMethod = "<invalid>";
11831183
Entry->RenderMethod = "<invalid>";
11841184
Entry->ParserMethod = "";
@@ -1352,11 +1352,11 @@ void AsmMatcherInfo::buildRegisterClasses(
13521352

13531353
const Init *DiagnosticType = Def->getValueInit("DiagnosticType");
13541354
if (const StringInit *SI = dyn_cast<StringInit>(DiagnosticType))
1355-
CI->DiagnosticType = std::string(SI->getValue());
1355+
CI->DiagnosticType = SI->getValue().str();
13561356

13571357
const Init *DiagnosticString = Def->getValueInit("DiagnosticString");
13581358
if (const StringInit *SI = dyn_cast<StringInit>(DiagnosticString))
1359-
CI->DiagnosticString = std::string(SI->getValue());
1359+
CI->DiagnosticString = SI->getValue().str();
13601360

13611361
// If we have a diagnostic string but the diagnostic type is not specified
13621362
// explicitly, create an anonymous diagnostic type.
@@ -1376,11 +1376,12 @@ void AsmMatcherInfo::buildRegisterClasses(
13761376
assert(CI && "Missing singleton register class info!");
13771377

13781378
if (CI->ValueName.empty()) {
1379-
CI->ClassName = std::string(Rec->getName());
1379+
CI->ClassName = Rec->getName().str();
13801380
CI->Name = "MCK_" + Rec->getName().str();
1381-
CI->ValueName = std::string(Rec->getName());
1382-
} else
1381+
CI->ValueName = Rec->getName().str();
1382+
} else {
13831383
CI->ValueName = CI->ValueName + "," + Rec->getName().str();
1384+
}
13841385
}
13851386
}
13861387

@@ -1413,14 +1414,14 @@ void AsmMatcherInfo::buildOperandClasses() {
14131414
else
14141415
CI->SuperClasses.push_back(SC);
14151416
}
1416-
CI->ClassName = std::string(Rec->getValueAsString("Name"));
1417+
CI->ClassName = Rec->getValueAsString("Name").str();
14171418
CI->Name = "MCK_" + CI->ClassName;
1418-
CI->ValueName = std::string(Rec->getName());
1419+
CI->ValueName = Rec->getName().str();
14191420

14201421
// Get or construct the predicate method name.
14211422
const Init *PMName = Rec->getValueInit("PredicateMethod");
14221423
if (const StringInit *SI = dyn_cast<StringInit>(PMName)) {
1423-
CI->PredicateMethod = std::string(SI->getValue());
1424+
CI->PredicateMethod = SI->getValue().str();
14241425
} else {
14251426
assert(isa<UnsetInit>(PMName) && "Unexpected PredicateMethod field!");
14261427
CI->PredicateMethod = "is" + CI->ClassName;
@@ -1429,7 +1430,7 @@ void AsmMatcherInfo::buildOperandClasses() {
14291430
// Get or construct the render method name.
14301431
const Init *RMName = Rec->getValueInit("RenderMethod");
14311432
if (const StringInit *SI = dyn_cast<StringInit>(RMName)) {
1432-
CI->RenderMethod = std::string(SI->getValue());
1433+
CI->RenderMethod = SI->getValue().str();
14331434
} else {
14341435
assert(isa<UnsetInit>(RMName) && "Unexpected RenderMethod field!");
14351436
CI->RenderMethod = "add" + CI->ClassName + "Operands";
@@ -1438,15 +1439,15 @@ void AsmMatcherInfo::buildOperandClasses() {
14381439
// Get the parse method name or leave it as empty.
14391440
const Init *PRMName = Rec->getValueInit("ParserMethod");
14401441
if (const StringInit *SI = dyn_cast<StringInit>(PRMName))
1441-
CI->ParserMethod = std::string(SI->getValue());
1442+
CI->ParserMethod = SI->getValue().str();
14421443

14431444
// Get the diagnostic type and string or leave them as empty.
14441445
const Init *DiagnosticType = Rec->getValueInit("DiagnosticType");
14451446
if (const StringInit *SI = dyn_cast<StringInit>(DiagnosticType))
1446-
CI->DiagnosticType = std::string(SI->getValue());
1447+
CI->DiagnosticType = SI->getValue().str();
14471448
const Init *DiagnosticString = Rec->getValueInit("DiagnosticString");
14481449
if (const StringInit *SI = dyn_cast<StringInit>(DiagnosticString))
1449-
CI->DiagnosticString = std::string(SI->getValue());
1450+
CI->DiagnosticString = SI->getValue().str();
14501451
// If we have a DiagnosticString, we need a DiagnosticType for use within
14511452
// the matcher.
14521453
if (!CI->DiagnosticString.empty() && CI->DiagnosticType.empty())
@@ -1459,7 +1460,7 @@ void AsmMatcherInfo::buildOperandClasses() {
14591460
// Get or construct the default method name.
14601461
const Init *DMName = Rec->getValueInit("DefaultMethod");
14611462
if (const StringInit *SI = dyn_cast<StringInit>(DMName)) {
1462-
CI->DefaultMethod = std::string(SI->getValue());
1463+
CI->DefaultMethod = SI->getValue().str();
14631464
} else {
14641465
assert(isa<UnsetInit>(DMName) && "Unexpected DefaultMethod field!");
14651466
CI->DefaultMethod = "default" + CI->ClassName + "Operands";
@@ -1905,7 +1906,7 @@ void MatchableInfo::buildAliasResultOperands(bool AliasConstraintsAreChecked) {
19051906
}
19061907

19071908
// Handle all the suboperands for this operand.
1908-
const std::string &OpName = OpInfo.Name;
1909+
StringRef OpName = OpInfo.Name;
19091910
for (; AliasOpNo < LastOpNo &&
19101911
CGA.ResultInstOperandIndex[AliasOpNo].first == Idx;
19111912
++AliasOpNo) {
@@ -3051,8 +3052,8 @@ emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
30513052
static void emitAsmTiedOperandConstraints(CodeGenTarget &Target,
30523053
AsmMatcherInfo &Info, raw_ostream &OS,
30533054
bool HasOptionalOperands) {
3054-
std::string AsmParserName =
3055-
std::string(Info.AsmParser->getValueAsString("AsmParserClassName"));
3055+
StringRef AsmParserName =
3056+
Info.AsmParser->getValueAsString("AsmParserClassName");
30563057
OS << "static bool ";
30573058
OS << "checkAsmTiedOperandConstraints(const " << Target.getName()
30583059
<< AsmParserName << "&AsmParser,\n";

llvm/utils/TableGen/AsmWriterEmitter.cpp

+23-20
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void AsmWriterEmitter::FindUniqueOperandCommands(
192192
InstIdxs[idx].push_back(i);
193193
} else {
194194
UniqueOperandCommands.push_back(std::move(Command));
195-
InstrsForCase.push_back(std::string(Inst.CGI->TheDef->getName()));
195+
InstrsForCase.push_back(Inst.CGI->TheDef->getName().str());
196196
InstIdxs.emplace_back();
197197
InstIdxs.back().push_back(i);
198198

@@ -592,9 +592,9 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName,
592592
// "NoRegAltName" is special. We don't need to do a lookup for that,
593593
// as it's just a reference to the default register name.
594594
if (AltName == "" || AltName == "NoRegAltName") {
595-
AsmName = std::string(Reg.TheDef->getValueAsString("AsmName"));
595+
AsmName = Reg.TheDef->getValueAsString("AsmName").str();
596596
if (AsmName.empty())
597-
AsmName = std::string(Reg.getName());
597+
AsmName = Reg.getName().str();
598598
} else {
599599
// Make sure the register has an alternate name for this index.
600600
std::vector<const Record *> AltNameList =
@@ -612,7 +612,7 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName,
612612
PrintFatalError(Reg.TheDef->getLoc(),
613613
"Register definition missing alt name for '" +
614614
AltName + "'.");
615-
AsmName = std::string(AltNames[Idx]);
615+
AsmName = AltNames[Idx].str();
616616
}
617617
}
618618
StringTable.add(AsmName);
@@ -939,7 +939,7 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
939939
}) -
940940
PrintMethods.begin();
941941
if (static_cast<unsigned>(PrintMethodIdx) == PrintMethods.size())
942-
PrintMethods.emplace_back(std::string(PrintMethod), IsPCRel);
942+
PrintMethods.emplace_back(PrintMethod.str(), IsPCRel);
943943
}
944944
}
945945

@@ -951,12 +951,14 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
951951
const Record *R = CGA.ResultOperands[i].getRecord();
952952
if (R->isSubClassOf("RegisterOperand"))
953953
R = R->getValueAsDef("RegClass");
954-
IAP.addCond(std::string(
954+
IAP.addCond(
955955
formatv("AliasPatternCond::K_RegClass, {}::{}RegClassID",
956-
Namespace, R->getName())));
956+
Namespace, R->getName())
957+
.str());
957958
} else {
958-
IAP.addCond(std::string(formatv("AliasPatternCond::K_TiedReg, {}",
959-
IAP.getOpIndex(ROName))));
959+
IAP.addCond(formatv("AliasPatternCond::K_TiedReg, {}",
960+
IAP.getOpIndex(ROName))
961+
.str());
960962
}
961963
} else {
962964
// Assume all printable operands are desired for now. This can be
@@ -972,8 +974,7 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
972974
} else
973975
break; // No conditions on this operand at all
974976
}
975-
IAP.addCond(
976-
std::string(formatv("AliasPatternCond::K_Custom, {}", Entry)));
977+
IAP.addCond(formatv("AliasPatternCond::K_Custom, {}", Entry).str());
977978
}
978979
break;
979980
}
@@ -985,20 +986,21 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
985986
if (Imm != Imm32)
986987
PrintFatalError("Matching an alias with an immediate out of the "
987988
"range of int32_t is not supported");
988-
IAP.addCond(std::string(
989-
formatv("AliasPatternCond::K_Imm, uint32_t({})", Imm32)));
989+
IAP.addCond(
990+
formatv("AliasPatternCond::K_Imm, uint32_t({})", Imm32).str());
990991
break;
991992
}
992993
case CodeGenInstAlias::ResultOperand::K_Reg:
993994
if (!CGA.ResultOperands[i].getRegister()) {
994-
IAP.addCond(std::string(
995-
formatv("AliasPatternCond::K_Reg, {}::NoRegister", Namespace)));
995+
IAP.addCond(
996+
formatv("AliasPatternCond::K_Reg, {}::NoRegister", Namespace)
997+
.str());
996998
break;
997999
}
9981000

9991001
StringRef Reg = CGA.ResultOperands[i].getRegister()->getName();
1000-
IAP.addCond(std::string(
1001-
formatv("AliasPatternCond::K_Reg, {}::{}", Namespace, Reg)));
1002+
IAP.addCond(
1003+
formatv("AliasPatternCond::K_Reg, {}::{}", Namespace, Reg).str());
10021004
break;
10031005
}
10041006

@@ -1051,9 +1053,10 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
10511053
!cast<DefInit>(Arg)->getDef()->isSubClassOf("SubtargetFeature"))
10521054
PrintFatalError(R->getLoc(), "Invalid AssemblerCondDag!");
10531055

1054-
IAP.addCond(std::string(formatv(
1055-
"AliasPatternCond::K_{}{}Feature, {}::{}", IsOr ? "Or" : "",
1056-
IsNeg ? "Neg" : "", Namespace, Arg->getAsString())));
1056+
IAP.addCond(formatv("AliasPatternCond::K_{}{}Feature, {}::{}",
1057+
IsOr ? "Or" : "", IsNeg ? "Neg" : "", Namespace,
1058+
Arg->getAsString())
1059+
.str());
10571060
}
10581061
// If an AssemblerPredicate with ors is used, note end of list should
10591062
// these be combined.

llvm/utils/TableGen/CodeEmitterGen.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
142142
}
143143

144144
std::pair<unsigned, unsigned> SO = CGI.Operands.getSubOperandNumber(OpIdx);
145-
std::string &EncoderMethodName =
145+
const std::string &EncoderMethodName =
146146
CGI.Operands[SO.first].EncoderMethodNames[SO.second];
147147

148148
if (UseAPInt)
@@ -309,8 +309,7 @@ CodeEmitterGen::getInstructionCases(const Record *R,
309309
" case " + itostr(DefaultMode) + ": InstBitsByHw = InstBits";
310310
} else {
311311
Case += " case " + itostr(ModeId) +
312-
": InstBitsByHw = InstBits_" +
313-
std::string(HWM.getMode(ModeId).Name);
312+
": InstBitsByHw = InstBits_" + HWM.getMode(ModeId).Name.str();
314313
}
315314
Case += "; break;\n";
316315
}
@@ -362,7 +361,7 @@ void CodeEmitterGen::addInstructionCasesForEncoding(
362361
if (RV.isNonconcreteOK() || RV.getValue()->isComplete())
363362
continue;
364363

365-
Success &= addCodeToMergeInOperand(R, BI, std::string(RV.getName()), Case,
364+
Success &= addCodeToMergeInOperand(R, BI, RV.getName().str(), Case,
366365
BitOffsetCase, Target);
367366
}
368367
// Avoid empty switches.

llvm/utils/TableGen/CodeGenMapTable.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ class InstrMap {
102102
std::vector<const ListInit *> ValueCols;
103103

104104
public:
105-
InstrMap(const Record *MapRec) {
106-
Name = std::string(MapRec->getName());
107-
105+
InstrMap(const Record *MapRec) : Name(MapRec->getName().str()) {
108106
// FilterClass - It's used to reduce the search space only to the
109107
// instructions that define the kind of relationship modeled by
110108
// this InstrMapping object/record.
@@ -133,8 +131,8 @@ class InstrMap {
133131

134132
// Each instruction map must specify at least one column for it to be valid.
135133
if (ColValList->empty())
136-
PrintFatalError(MapRec->getLoc(), "InstrMapping record `" +
137-
MapRec->getName() + "' has empty " +
134+
PrintFatalError(MapRec->getLoc(), "InstrMapping record `" + Name +
135+
"' has empty " +
138136
"`ValueCols' field!");
139137

140138
for (const Init *I : ColValList->getValues()) {
@@ -144,7 +142,7 @@ class InstrMap {
144142
// elements as the fields in 'ColFields'.
145143
if (ColI->size() != ColFields->size())
146144
PrintFatalError(MapRec->getLoc(),
147-
"Record `" + MapRec->getName() +
145+
"Record `" + Name +
148146
"', field `ValueCols' entries don't match with " +
149147
" the entries in 'ColFields'!");
150148
ValueCols.push_back(ColI);
@@ -188,7 +186,7 @@ class MapTableEmitter {
188186
MapTableEmitter(const CodeGenTarget &Target, const RecordKeeper &Records,
189187
const Record *IMRec)
190188
: Target(Target), InstrMapDesc(IMRec) {
191-
const std::string &FilterClass = InstrMapDesc.getFilterClass();
189+
StringRef FilterClass = InstrMapDesc.getFilterClass();
192190
InstrDefs = Records.getAllDerivedDefinitions(FilterClass);
193191
}
194192

llvm/utils/TableGen/Common/AsmWriterInst.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct AsmWriterOperand {
3838
unsigned MIOpNo = 0;
3939

4040
/// Str - For isLiteralTextOperand, this IS the literal text. For
41-
/// isMachineInstrOperand, this is the PrinterMethodName for the operand..
41+
/// isMachineInstrOperand, this is the PrinterMethodName for the operand.
4242
/// For isLiteralStatementOperand, this is the code to insert verbatim
4343
/// into the asm writer.
4444
std::string Str;

0 commit comments

Comments
 (0)