Skip to content

Commit ee4c8b5

Browse files
authored
[TableGen] Use llvm::enumerate in one place (NFC) (#136399)
1 parent c300033 commit ee4c8b5

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

llvm/utils/TableGen/Common/CodeGenInstAlias.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,26 +200,24 @@ CodeGenInstAlias::CodeGenInstAlias(const Record *R, const CodeGenTarget &T)
200200

201201
// Decode and validate the arguments of the result.
202202
unsigned AliasOpNo = 0;
203-
for (unsigned i = 0, e = ResultInst->Operands.size(); i != e; ++i) {
204-
203+
for (auto [OpIdx, OpInfo] : enumerate(ResultInst->Operands)) {
205204
// Tied registers don't have an entry in the result dag unless they're part
206205
// of a complex operand, in which case we include them anyways, as we
207206
// don't have any other way to specify the whole operand.
208-
if (ResultInst->Operands[i].MINumOperands == 1 &&
209-
ResultInst->Operands[i].getTiedRegister() != -1) {
207+
if (OpInfo.MINumOperands == 1 && OpInfo.getTiedRegister() != -1) {
210208
// Tied operands of different RegisterClass should be explicit within an
211209
// instruction's syntax and so cannot be skipped.
212-
int TiedOpNum = ResultInst->Operands[i].getTiedRegister();
213-
if (ResultInst->Operands[i].Rec->getName() ==
210+
int TiedOpNum = OpInfo.getTiedRegister();
211+
if (OpInfo.Rec->getName() ==
214212
ResultInst->Operands[TiedOpNum].Rec->getName())
215213
continue;
216214
}
217215

218216
if (AliasOpNo >= Result->getNumArgs())
219217
PrintFatalError(R->getLoc(), "not enough arguments for instruction!");
220218

221-
const Record *InstOpRec = ResultInst->Operands[i].Rec;
222-
unsigned NumSubOps = ResultInst->Operands[i].MINumOperands;
219+
const Record *InstOpRec = OpInfo.Rec;
220+
unsigned NumSubOps = OpInfo.MINumOperands;
223221
ResultOperand ResOp(static_cast<int64_t>(0));
224222
if (tryAliasOpMatch(Result, AliasOpNo, InstOpRec, (NumSubOps > 1),
225223
R->getLoc(), T, ResOp)) {
@@ -229,12 +227,12 @@ CodeGenInstAlias::CodeGenInstAlias(const Record *R, const CodeGenTarget &T)
229227
InstOpRec->getValueAsDef("ParserMatchClass")
230228
->getValueAsString("Name") != "Imm")) {
231229
ResultOperands.push_back(std::move(ResOp));
232-
ResultInstOperandIndex.emplace_back(i, -1);
230+
ResultInstOperandIndex.emplace_back(OpIdx, -1);
233231
++AliasOpNo;
234232

235233
// Otherwise, we need to match each of the suboperands individually.
236234
} else {
237-
const DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
235+
const DagInit *MIOI = OpInfo.MIOperandInfo;
238236
for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
239237
const Record *SubRec = cast<DefInit>(MIOI->getArg(SubOp))->getDef();
240238

@@ -244,7 +242,7 @@ CodeGenInstAlias::CodeGenInstAlias(const Record *R, const CodeGenTarget &T)
244242
Result->getArgName(AliasOpNo)->getAsUnquotedString() + "." +
245243
MIOI->getArgName(SubOp)->getAsUnquotedString(),
246244
SubRec);
247-
ResultInstOperandIndex.emplace_back(i, SubOp);
245+
ResultInstOperandIndex.emplace_back(OpIdx, SubOp);
248246
}
249247
++AliasOpNo;
250248
}
@@ -254,15 +252,15 @@ CodeGenInstAlias::CodeGenInstAlias(const Record *R, const CodeGenTarget &T)
254252
// If the argument did not match the instruction operand, and the operand
255253
// is composed of multiple suboperands, try matching the suboperands.
256254
if (NumSubOps > 1) {
257-
const DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
255+
const DagInit *MIOI = OpInfo.MIOperandInfo;
258256
for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
259257
if (AliasOpNo >= Result->getNumArgs())
260258
PrintFatalError(R->getLoc(), "not enough arguments for instruction!");
261259
const Record *SubRec = cast<DefInit>(MIOI->getArg(SubOp))->getDef();
262260
if (tryAliasOpMatch(Result, AliasOpNo, SubRec, false, R->getLoc(), T,
263261
ResOp)) {
264262
ResultOperands.push_back(ResOp);
265-
ResultInstOperandIndex.emplace_back(i, SubOp);
263+
ResultInstOperandIndex.emplace_back(OpIdx, SubOp);
266264
++AliasOpNo;
267265
} else {
268266
PrintFatalError(

0 commit comments

Comments
 (0)