Skip to content

Commit 4e8c9d2

Browse files
authored
[TableGen] Use std::pair instead of std::make_pair. NFC. (#123174)
Also use brace initialization and emplace to avoid explicitly constructing std::pair, and the same for std::tuple.
1 parent 4481030 commit 4e8c9d2

36 files changed

+120
-129
lines changed

llvm/include/llvm/TableGen/Record.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ class Record {
18161816
assert(!CorrespondingDefInit &&
18171817
"changing type of record after it has been referenced");
18181818
assert(!isSubClassOf(R) && "Already subclassing record!");
1819-
SuperClasses.push_back(std::make_pair(R, Range));
1819+
SuperClasses.emplace_back(R, Range);
18201820
}
18211821

18221822
/// If there are any field references that refer to fields that have been
@@ -1971,21 +1971,20 @@ class RecordKeeper {
19711971
}
19721972

19731973
void addClass(std::unique_ptr<Record> R) {
1974-
bool Ins = Classes.insert(std::make_pair(std::string(R->getName()),
1975-
std::move(R))).second;
1974+
bool Ins =
1975+
Classes.try_emplace(std::string(R->getName()), std::move(R)).second;
19761976
(void)Ins;
19771977
assert(Ins && "Class already exists");
19781978
}
19791979

19801980
void addDef(std::unique_ptr<Record> R) {
1981-
bool Ins = Defs.insert(std::make_pair(std::string(R->getName()),
1982-
std::move(R))).second;
1981+
bool Ins = Defs.try_emplace(std::string(R->getName()), std::move(R)).second;
19831982
(void)Ins;
19841983
assert(Ins && "Record already exists");
19851984
}
19861985

19871986
void addExtraGlobal(StringRef Name, const Init *I) {
1988-
bool Ins = ExtraGlobals.insert(std::make_pair(std::string(Name), I)).second;
1987+
bool Ins = ExtraGlobals.try_emplace(std::string(Name), I).second;
19891988
(void)Ins;
19901989
assert(!getDef(Name));
19911990
assert(Ins && "Global already exists");
@@ -2071,14 +2070,14 @@ struct LessRecordRegister {
20712070
for (size_t I = 0, E = Rec.size(); I != E; ++I, ++Len) {
20722071
bool IsDigit = isDigit(Curr[I]);
20732072
if (IsDigit != IsDigitPart) {
2074-
Parts.push_back(std::make_pair(IsDigitPart, StringRef(Start, Len)));
2073+
Parts.emplace_back(IsDigitPart, StringRef(Start, Len));
20752074
Len = 0;
20762075
Start = &Curr[I];
20772076
IsDigitPart = isDigit(Curr[I]);
20782077
}
20792078
}
20802079
// Push the last part.
2081-
Parts.push_back(std::make_pair(IsDigitPart, StringRef(Start, Len)));
2080+
Parts.emplace_back(IsDigitPart, StringRef(Start, Len));
20822081
}
20832082

20842083
size_t size() { return Parts.size(); }

llvm/lib/TableGen/Record.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ const StringInit *StringInit::get(RecordKeeper &RK, StringRef V,
671671
detail::RecordKeeperImpl &RKImpl = RK.getImpl();
672672
auto &InitMap = Fmt == SF_String ? RKImpl.StringInitStringPool
673673
: RKImpl.StringInitCodePool;
674-
auto &Entry = *InitMap.insert(std::make_pair(V, nullptr)).first;
674+
auto &Entry = *InitMap.try_emplace(V, nullptr).first;
675675
if (!Entry.second)
676676
Entry.second = new (RKImpl.Allocator) StringInit(RK, Entry.getKey(), Fmt);
677677
return Entry.second;
@@ -1674,7 +1674,7 @@ static const Init *ForeachDagApply(const Init *LHS, const DagInit *MHSd,
16741674
else
16751675
NewArg = ItemApply(LHS, Arg, RHS, CurRec);
16761676

1677-
NewArgs.push_back(std::make_pair(NewArg, ArgName));
1677+
NewArgs.emplace_back(NewArg, ArgName);
16781678
if (Arg != NewArg)
16791679
Change = true;
16801680
}
@@ -2260,7 +2260,7 @@ const VarInit *VarInit::get(StringRef VN, const RecTy *T) {
22602260

22612261
const VarInit *VarInit::get(const Init *VN, const RecTy *T) {
22622262
detail::RecordKeeperImpl &RK = T->getRecordKeeper().getImpl();
2263-
VarInit *&I = RK.TheVarInitPool[std::make_pair(T, VN)];
2263+
VarInit *&I = RK.TheVarInitPool[{T, VN}];
22642264
if (!I)
22652265
I = new (RK.Allocator) VarInit(VN, T);
22662266
return I;
@@ -2285,7 +2285,7 @@ const Init *VarInit::resolveReferences(Resolver &R) const {
22852285

22862286
const VarBitInit *VarBitInit::get(const TypedInit *T, unsigned B) {
22872287
detail::RecordKeeperImpl &RK = T->getRecordKeeper().getImpl();
2288-
VarBitInit *&I = RK.TheVarBitInitPool[std::make_pair(T, B)];
2288+
VarBitInit *&I = RK.TheVarBitInitPool[{T, B}];
22892289
if (!I)
22902290
I = new (RK.Allocator) VarBitInit(T, B);
22912291
return I;
@@ -2461,7 +2461,7 @@ std::string VarDefInit::getAsString() const {
24612461

24622462
const FieldInit *FieldInit::get(const Init *R, const StringInit *FN) {
24632463
detail::RecordKeeperImpl &RK = R->getRecordKeeper().getImpl();
2464-
FieldInit *&I = RK.TheFieldInitPool[std::make_pair(R, FN)];
2464+
FieldInit *&I = RK.TheFieldInitPool[{R, FN}];
24652465
if (!I)
24662466
I = new (RK.Allocator) FieldInit(R, FN);
24672467
return I;

llvm/lib/TableGen/TGLexer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class TGLexer {
234234
std::pair<int64_t, unsigned> getCurBinaryIntVal() const {
235235
assert(CurCode == tgtok::BinaryIntVal &&
236236
"This token isn't a binary integer");
237-
return std::make_pair(CurIntVal, (CurPtr - TokStart)-2);
237+
return {CurIntVal, (CurPtr - TokStart) - 2};
238238
}
239239

240240
SMLoc getLoc() const;

llvm/lib/TableGen/TGParser.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,7 @@ void TGParser::ParseDagArgList(
31623162
Lex.Lex(); // eat the VarName.
31633163
}
31643164

3165-
Result.push_back(std::make_pair(Val, VarName));
3165+
Result.emplace_back(Val, VarName);
31663166
}
31673167
if (!consume(tgtok::comma))
31683168
break;
@@ -4152,9 +4152,8 @@ bool TGParser::ParseMultiClass() {
41524152
return TokError("expected identifier after multiclass for name");
41534153
std::string Name = Lex.getCurStrVal();
41544154

4155-
auto Result =
4156-
MultiClasses.insert(std::make_pair(Name,
4157-
std::make_unique<MultiClass>(Name, Lex.getLoc(),Records)));
4155+
auto Result = MultiClasses.try_emplace(
4156+
Name, std::make_unique<MultiClass>(Name, Lex.getLoc(), Records));
41584157

41594158
if (!Result.second)
41604159
return TokError("multiclass '" + Name + "' already defined");

llvm/lib/TableGen/TGParser.h

Lines changed: 1 addition & 1 deletion
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.insert(std::make_pair(std::string(Name), I)).second;
134+
bool Ins = Vars.try_emplace(std::string(Name), I).second;
135135
(void)Ins;
136136
assert(Ins && "Local variable already exists");
137137
}

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ void AsmMatcherInfo::buildRegisterClasses(
12991299

13001300
if (!ContainingSet.empty()) {
13011301
RegisterSets.insert(ContainingSet);
1302-
RegisterMap.insert(std::pair(CGR.TheDef, ContainingSet));
1302+
RegisterMap.try_emplace(CGR.TheDef, ContainingSet);
13031303
}
13041304
}
13051305

@@ -1320,7 +1320,7 @@ void AsmMatcherInfo::buildRegisterClasses(
13201320
CI->DiagnosticType = "";
13211321
CI->IsOptional = false;
13221322
CI->DefaultMethod = ""; // unused
1323-
RegisterSetClasses.insert(std::pair(RS, CI));
1323+
RegisterSetClasses.try_emplace(RS, CI);
13241324
++Index;
13251325
}
13261326

@@ -1362,7 +1362,7 @@ void AsmMatcherInfo::buildRegisterClasses(
13621362
if (!CI->DiagnosticString.empty() && CI->DiagnosticType.empty())
13631363
CI->DiagnosticType = RC.getName();
13641364

1365-
RegisterClassClasses.insert(std::pair(Def, CI));
1365+
RegisterClassClasses.try_emplace(Def, CI);
13661366
}
13671367

13681368
// Populate the map for individual registers.
@@ -2823,7 +2823,7 @@ emitMnemonicAliasVariant(raw_ostream &OS, const AsmMatcherInfo &Info,
28232823

28242824
MatchCode += "return;";
28252825

2826-
Cases.push_back(std::pair(AliasEntry.first, MatchCode));
2826+
Cases.emplace_back(AliasEntry.first, MatchCode);
28272827
}
28282828
StringMatcher("Mnemonic", Cases, OS).Emit(Indent);
28292829
}

llvm/utils/TableGen/AsmWriterEmitter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ static void EmitInstructions(std::vector<AsmWriterInst> &Insts, raw_ostream &O,
144144
O << " switch (MI->getOpcode()) {\n";
145145
O << " default: llvm_unreachable(\"Unexpected opcode.\");\n";
146146
std::vector<std::pair<std::string, AsmWriterOperand>> OpsToPrint;
147-
OpsToPrint.push_back(std::pair(FirstInst.CGI->Namespace.str() + "::" +
148-
FirstInst.CGI->TheDef->getName().str(),
149-
FirstInst.Operands[i]));
147+
OpsToPrint.emplace_back(FirstInst.CGI->Namespace.str() +
148+
"::" + FirstInst.CGI->TheDef->getName().str(),
149+
FirstInst.Operands[i]);
150150

151151
for (const AsmWriterInst &AWI : SimilarInsts) {
152-
OpsToPrint.push_back(std::pair(
153-
AWI.CGI->Namespace.str() + "::" + AWI.CGI->TheDef->getName().str(),
154-
AWI.Operands[i]));
152+
OpsToPrint.emplace_back(AWI.CGI->Namespace.str() +
153+
"::" + AWI.CGI->TheDef->getName().str(),
154+
AWI.Operands[i]);
155155
}
156156
std::reverse(OpsToPrint.begin(), OpsToPrint.end());
157157
while (!OpsToPrint.empty())
@@ -722,7 +722,7 @@ class IAPrinter {
722722
void addOperand(StringRef Op, int OpIdx, int PrintMethodIdx = -1) {
723723
assert(OpIdx >= 0 && OpIdx < 0xFE && "Idx out of range");
724724
assert(PrintMethodIdx >= -1 && PrintMethodIdx < 0xFF && "Idx out of range");
725-
OpMap[Op] = std::pair(OpIdx, PrintMethodIdx);
725+
OpMap[Op] = {OpIdx, PrintMethodIdx};
726726
}
727727

728728
unsigned getNumMIOps() { return NumMIOps; }
@@ -753,7 +753,7 @@ class IAPrinter {
753753
Next = I;
754754
}
755755

756-
return std::pair(StringRef(Start, I - Start), Next);
756+
return {StringRef(Start, I - Start), Next};
757757
}
758758

759759
std::string formatAliasString(uint32_t &UnescapedSize) {
@@ -854,8 +854,8 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
854854
continue; // Aliases with priority 0 are never emitted.
855855

856856
const DagInit *DI = R->getValueAsDag("ResultInst");
857-
AliasMap[getQualifiedName(DI->getOperatorAsDef(R->getLoc()))].insert(
858-
std::pair(CodeGenInstAlias(R, Target), Priority));
857+
AliasMap[getQualifiedName(DI->getOperatorAsDef(R->getLoc()))].emplace(
858+
CodeGenInstAlias(R, Target), Priority);
859859
}
860860

861861
// A map of which conditions need to be met for each instruction operand

llvm/utils/TableGen/Basic/DirectiveEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static void emitLeafTable(const DirectiveLanguage &DirLang, raw_ostream &OS,
495495
DenseMap<const Record *, int> DirId; // Record * -> llvm::omp::Directive
496496

497497
for (auto [Idx, Rec] : enumerate(Directives))
498-
DirId.insert(std::make_pair(Rec, Idx));
498+
DirId.try_emplace(Rec, Idx);
499499

500500
using LeafList = std::vector<int>;
501501
int MaxLeafCount = getMaxLeafCount(DirLang);
@@ -675,7 +675,7 @@ static void generateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
675675
D.getAssociation()->getName() + "'");
676676
}
677677
if (AS != Association::FromLeaves) {
678-
AsMap.insert(std::make_pair(R, AS));
678+
AsMap.try_emplace(R, AS);
679679
return AS;
680680
}
681681
// Compute the association from leaf constructs.
@@ -701,7 +701,7 @@ static void generateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
701701

702702
assert(Result != Association::Invalid);
703703
assert(Result != Association::FromLeaves);
704-
AsMap.insert(std::make_pair(R, Result));
704+
AsMap.try_emplace(R, Result);
705705
return Result;
706706
};
707707

llvm/utils/TableGen/Basic/RISCVTargetDefEmitter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ static void emitRISCVExtensionBitmask(const RecordKeeper &RK, raw_ostream &OS) {
241241
ExtName.consume_front("experimental-");
242242

243243
#ifndef NDEBUG
244-
assert(Seen.insert(std::make_pair(GroupIDVal, BitPosVal)).second &&
245-
"duplicated bitmask");
244+
assert(Seen.insert({GroupIDVal, BitPosVal}).second && "duplicated bitmask");
246245
#endif
247246

248247
OS.indent(4) << "{"

llvm/utils/TableGen/Basic/SequenceToOffsetTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SequenceToOffsetTable {
9393
if (I != Seqs.end() && isSuffix(Seq, I->first))
9494
return;
9595

96-
I = Seqs.insert(I, std::pair(Seq, 0u));
96+
I = Seqs.insert(I, {Seq, 0u});
9797

9898
// The entry before I may be a suffix of Seq that can now be erased.
9999
if (I != Seqs.begin() && isSuffix((--I)->first, Seq))

llvm/utils/TableGen/CodeEmitterGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ CodeEmitterGen::getInstructionCases(const Record *R,
338338
Append(" }\n");
339339
}
340340
Append(" }\n");
341-
return std::pair(std::move(Case), std::move(BitOffsetCase));
341+
return {std::move(Case), std::move(BitOffsetCase)};
342342
}
343343
}
344344
addInstructionCasesForEncoding(R, R, Target, Case, BitOffsetCase);
345-
return std::pair(std::move(Case), std::move(BitOffsetCase));
345+
return {std::move(Case), std::move(BitOffsetCase)};
346346
}
347347

348348
void CodeEmitterGen::addInstructionCasesForEncoding(

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,7 +3006,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30063006
// Check that the ComplexPattern uses are consistent: "(MY_PAT $a, $b)"
30073007
// and "(MY_PAT $b, $a)" should not be allowed in the same pattern;
30083008
// neither should "(MY_PAT_1 $a, $b)" and "(MY_PAT_2 $a, $b)".
3009-
auto OperandId = std::make_pair(Operator, i);
3009+
auto OperandId = std::pair(Operator, i);
30103010
auto [PrevOp, Inserted] =
30113011
ComplexPatternOperands.try_emplace(Child->getName(), OperandId);
30123012
if (!Inserted && PrevOp->getValue() != OperandId) {
@@ -3218,7 +3218,7 @@ void CodeGenDAGPatterns::ParseNodeInfo() {
32183218
const CodeGenHwModes &CGH = getTargetInfo().getHwModes();
32193219

32203220
for (const Record *R : reverse(Records.getAllDerivedDefinitions("SDNode")))
3221-
SDNodes.insert(std::pair(R, SDNodeInfo(R, CGH)));
3221+
SDNodes.try_emplace(R, SDNodeInfo(R, CGH));
32223222

32233223
// Get the builtin intrinsic nodes.
32243224
intrinsic_void_sdnode = getSDNodeNamed("intrinsic_void");
@@ -3348,8 +3348,7 @@ void CodeGenDAGPatterns::ParseDefaultOperands() {
33483348
// SomeSDnode so that we can parse this.
33493349
std::vector<std::pair<const Init *, const StringInit *>> Ops;
33503350
for (unsigned op = 0, e = DefaultInfo->getNumArgs(); op != e; ++op)
3351-
Ops.push_back(
3352-
std::pair(DefaultInfo->getArg(op), DefaultInfo->getArgName(op)));
3351+
Ops.emplace_back(DefaultInfo->getArg(op), DefaultInfo->getArgName(op));
33533352
const DagInit *DI = DagInit::get(SomeSDNode, nullptr, Ops);
33543353

33553354
// Create a TreePattern to parse this.

llvm/utils/TableGen/Common/CodeGenHwModes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ HwModeSelect::HwModeSelect(const Record *R, CodeGenHwModes &CGH) {
5151
}
5252
for (auto [Mode, Object] : zip_equal(Modes, Objects)) {
5353
unsigned ModeId = CGH.getHwModeId(Mode);
54-
Items.push_back(std::pair(ModeId, Object));
54+
Items.emplace_back(ModeId, Object);
5555
}
5656
}
5757

@@ -70,13 +70,13 @@ CodeGenHwModes::CodeGenHwModes(const RecordKeeper &RK) : Records(RK) {
7070
if (R->getName() == DefaultModeName)
7171
continue;
7272
Modes.emplace_back(R);
73-
ModeIds.insert(std::pair(R, Modes.size()));
73+
ModeIds.try_emplace(R, Modes.size());
7474
}
7575

7676
assert(Modes.size() <= 32 && "number of HwModes exceeds maximum of 32");
7777

7878
for (const Record *R : Records.getAllDerivedDefinitions("HwModeSelect")) {
79-
auto P = ModeSelects.emplace(std::pair(R, HwModeSelect(R, *this)));
79+
auto P = ModeSelects.emplace(R, HwModeSelect(R, *this));
8080
assert(P.second);
8181
(void)P;
8282
}

llvm/utils/TableGen/Common/CodeGenInstAlias.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ CodeGenInstAlias::CodeGenInstAlias(const Record *R, const CodeGenTarget &T)
229229
InstOpRec->getValueAsDef("ParserMatchClass")
230230
->getValueAsString("Name") != "Imm")) {
231231
ResultOperands.push_back(std::move(ResOp));
232-
ResultInstOperandIndex.push_back(std::pair(i, -1));
232+
ResultInstOperandIndex.emplace_back(i, -1);
233233
++AliasOpNo;
234234

235235
// Otherwise, we need to match each of the suboperands individually.
@@ -244,7 +244,7 @@ CodeGenInstAlias::CodeGenInstAlias(const Record *R, const CodeGenTarget &T)
244244
Result->getArgName(AliasOpNo)->getAsUnquotedString() + "." +
245245
MIOI->getArgName(SubOp)->getAsUnquotedString(),
246246
SubRec);
247-
ResultInstOperandIndex.push_back(std::pair(i, SubOp));
247+
ResultInstOperandIndex.emplace_back(i, SubOp);
248248
}
249249
++AliasOpNo;
250250
}
@@ -262,7 +262,7 @@ CodeGenInstAlias::CodeGenInstAlias(const Record *R, const CodeGenTarget &T)
262262
if (tryAliasOpMatch(Result, AliasOpNo, SubRec, false, R->getLoc(), T,
263263
ResOp)) {
264264
ResultOperands.push_back(ResOp);
265-
ResultInstOperandIndex.push_back(std::pair(i, SubOp));
265+
ResultInstOperandIndex.emplace_back(i, SubOp);
266266
++AliasOpNo;
267267
} else {
268268
PrintFatalError(

llvm/utils/TableGen/Common/CodeGenInstruction.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
175175
}
176176

177177
OpInfo.SubOpNames[j] = SubArgName;
178-
SubOpAliases[SubArgName] = std::pair(i, j);
178+
SubOpAliases[SubArgName] = {i, j};
179179
}
180180
} else if (!EncoderMethod.empty()) {
181181
// If we have no explicit sub-op dag, but have an top-level encoder
@@ -276,7 +276,7 @@ CGIOperandList::ParseOperandName(StringRef Op, bool AllowWholeOp) {
276276
Op + "'");
277277

278278
// Otherwise, return the operand.
279-
return std::pair(OpIdx, 0U);
279+
return {OpIdx, 0U};
280280
}
281281

282282
// Find the suboperand number involved.
@@ -289,13 +289,13 @@ CGIOperandList::ParseOperandName(StringRef Op, bool AllowWholeOp) {
289289
// Find the operand with the right name.
290290
for (unsigned i = 0, e = MIOpInfo->getNumArgs(); i != e; ++i)
291291
if (MIOpInfo->getArgNameStr(i) == SubOpName)
292-
return std::pair(OpIdx, i);
292+
return {OpIdx, i};
293293

294294
// Otherwise, didn't find it!
295295
PrintFatalError(TheDef->getLoc(), TheDef->getName() +
296296
": unknown suboperand name in '" + Op +
297297
"'");
298-
return std::pair(0U, 0U);
298+
return {0U, 0U};
299299
}
300300

301301
static void ParseConstraint(StringRef CStr, CGIOperandList &Ops,

0 commit comments

Comments
 (0)