Skip to content

Commit 7a4a83b

Browse files
[TableGen] Use range-based for loops (NFC) (#144283)
1 parent f71fb2d commit 7a4a83b

File tree

8 files changed

+37
-44
lines changed

8 files changed

+37
-44
lines changed

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,8 +1824,8 @@ bool TreePatternNode::UpdateNodeTypeFromInst(unsigned ResNo,
18241824
}
18251825

18261826
bool TreePatternNode::ContainsUnresolvedType(TreePattern &TP) const {
1827-
for (unsigned i = 0, e = Types.size(); i != e; ++i)
1828-
if (!TP.getInfer().isConcrete(Types[i], true))
1827+
for (const TypeSetByHwMode &Type : Types)
1828+
if (!TP.getInfer().isConcrete(Type, true))
18291829
return true;
18301830
for (const TreePatternNode &Child : children())
18311831
if (Child.ContainsUnresolvedType(TP))

llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
747747

748748
/// hasChild - Return true if N is any of our children.
749749
bool hasChild(const TreePatternNode *N) const {
750-
for (unsigned i = 0, e = Children.size(); i != e; ++i)
751-
if (Children[i].get() == N)
750+
for (const TreePatternNodePtr &Child : Children)
751+
if (Child.get() == N)
752752
return true;
753753
return false;
754754
}
@@ -1171,9 +1171,9 @@ class CodeGenDAGPatterns {
11711171
}
11721172

11731173
const CodeGenIntrinsic &getIntrinsic(const Record *R) const {
1174-
for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
1175-
if (Intrinsics[i].TheDef == R)
1176-
return Intrinsics[i];
1174+
for (const CodeGenIntrinsic &Intrinsic : Intrinsics)
1175+
if (Intrinsic.TheDef == R)
1176+
return Intrinsic;
11771177
llvm_unreachable("Unknown intrinsic!");
11781178
}
11791179

@@ -1280,8 +1280,8 @@ class CodeGenDAGPatterns {
12801280
inline bool SDNodeInfo::ApplyTypeConstraints(TreePatternNode &N,
12811281
TreePattern &TP) const {
12821282
bool MadeChange = false;
1283-
for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
1284-
MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP);
1283+
for (const SDTypeConstraint &TypeConstraint : TypeConstraints)
1284+
MadeChange |= TypeConstraint.ApplyTypeConstraint(N, *this, TP);
12851285
return MadeChange;
12861286
}
12871287

llvm/utils/TableGen/Common/CodeGenInstruction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ class CGIOperandList {
127127
/// getTiedOperand - If this operand is tied to another one, return the
128128
/// other operand number. Otherwise, return -1.
129129
int getTiedRegister() const {
130-
for (unsigned j = 0, e = Constraints.size(); j != e; ++j) {
131-
const CGIOperandList::ConstraintInfo &CI = Constraints[j];
130+
for (const CGIOperandList::ConstraintInfo &CI : Constraints) {
132131
if (CI.isTied())
133132
return CI.getTiedOperand();
134133
}

llvm/utils/TableGen/Common/CodeGenSchedule.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,13 +2232,10 @@ void PredTransitions::dump() const {
22322232
dbgs() << LS << SchedModels.getSchedRW(PC.RWIdx, PC.IsRead).Name << ":"
22332233
<< PC.Predicate->getName();
22342234
dbgs() << "},\n => {";
2235-
for (SmallVectorImpl<SmallVector<unsigned, 4>>::const_iterator
2236-
WSI = TI.WriteSequences.begin(),
2237-
WSE = TI.WriteSequences.end();
2238-
WSI != WSE; ++WSI) {
2235+
for (const auto &WS : TI.WriteSequences) {
22392236
dbgs() << "(";
22402237
ListSeparator LS;
2241-
for (unsigned N : *WSI)
2238+
for (unsigned N : WS)
22422239
dbgs() << LS << SchedModels.getSchedWrite(N).Name;
22432240
dbgs() << "),";
22442241
}

llvm/utils/TableGen/Common/DAGISelMatcher.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, indent Indent) const {
286286
OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
287287
<< CGI.Namespace << "::" << CGI.TheDef->getName() << ": <todo flags> ";
288288

289-
for (unsigned i = 0, e = VTs.size(); i != e; ++i)
290-
OS << ' ' << getEnumName(VTs[i]);
289+
for (MVT::SimpleValueType VT : VTs)
290+
OS << ' ' << getEnumName(VT);
291291
OS << '(';
292-
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
293-
OS << Operands[i] << ' ';
292+
for (unsigned Operand : Operands)
293+
OS << Operand << ' ';
294294
OS << ")\n";
295295
}
296296

llvm/utils/TableGen/DAGISelMatcherGen.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -526,23 +526,20 @@ void MatcherGen::EmitMatchCode(const TreePatternNode &N,
526526
EmitOperatorMatchCode(N, NodeNoTypes);
527527

528528
// If there are node predicates for this node, generate their checks.
529-
for (unsigned i = 0, e = N.getPredicateCalls().size(); i != e; ++i) {
530-
const TreePredicateCall &Pred = N.getPredicateCalls()[i];
529+
for (const TreePredicateCall &Pred : N.getPredicateCalls()) {
531530
SmallVector<unsigned, 4> Operands;
532531
if (Pred.Fn.usesOperands()) {
533532
TreePattern *TP = Pred.Fn.getOrigPatFragRecord();
534-
for (unsigned i = 0; i < TP->getNumArgs(); ++i) {
535-
std::string Name =
536-
("pred:" + Twine(Pred.Scope) + ":" + TP->getArgName(i)).str();
533+
for (const std::string &Arg : TP->getArgList()) {
534+
std::string Name = ("pred:" + Twine(Pred.Scope) + ":" + Arg).str();
537535
Operands.push_back(getNamedArgumentSlot(Name));
538536
}
539537
}
540538
AddMatcher(new CheckPredicateMatcher(Pred.Fn, Operands));
541539
}
542540

543-
for (unsigned i = 0, e = ResultsToTypeCheck.size(); i != e; ++i)
544-
AddMatcher(new CheckTypeMatcher(N.getSimpleType(ResultsToTypeCheck[i]),
545-
ResultsToTypeCheck[i]));
541+
for (unsigned I : ResultsToTypeCheck)
542+
AddMatcher(new CheckTypeMatcher(N.getSimpleType(I), I));
546543
}
547544

548545
/// EmitMatcherCode - Generate the code that matches the predicate of this
@@ -836,8 +833,8 @@ void MatcherGen::EmitResultInstructionAsOperand(
836833
// overridden, or which we aren't letting it override; emit the 'default
837834
// ops' operands.
838835
const DAGDefaultOperand &DefaultOp = CGP.getDefaultOperand(OperandNode);
839-
for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i)
840-
EmitResultOperand(*DefaultOp.DefaultOps[i], InstOps);
836+
for (const TreePatternNodePtr &Op : DefaultOp.DefaultOps)
837+
EmitResultOperand(*Op, InstOps);
841838
continue;
842839
}
843840

@@ -886,10 +883,10 @@ void MatcherGen::EmitResultInstructionAsOperand(
886883
if (isRoot && !PhysRegInputs.empty()) {
887884
// Emit all of the CopyToReg nodes for the input physical registers. These
888885
// occur in patterns like (mul:i8 AL:i8, GR8:i8:$src).
889-
for (unsigned i = 0, e = PhysRegInputs.size(); i != e; ++i) {
886+
for (const auto &PhysRegInput : PhysRegInputs) {
890887
const CodeGenRegister *Reg =
891-
CGP.getTargetInfo().getRegBank().getReg(PhysRegInputs[i].first);
892-
AddMatcher(new EmitCopyToRegMatcher(PhysRegInputs[i].second, Reg));
888+
CGP.getTargetInfo().getRegBank().getReg(PhysRegInput.first);
889+
AddMatcher(new EmitCopyToRegMatcher(PhysRegInput.second, Reg));
893890
}
894891

895892
// Even if the node has no other glue inputs, the resultant node must be
@@ -977,8 +974,8 @@ void MatcherGen::EmitResultInstructionAsOperand(
977974
NumFixedArityOperands, NextRecordedOperandNo));
978975

979976
// The non-chain and non-glue results of the newly emitted node get recorded.
980-
for (unsigned i = 0, e = ResultVTs.size(); i != e; ++i) {
981-
if (ResultVTs[i] == MVT::Other || ResultVTs[i] == MVT::Glue)
977+
for (MVT::SimpleValueType ResultVT : ResultVTs) {
978+
if (ResultVT == MVT::Other || ResultVT == MVT::Glue)
982979
break;
983980
OutputOps.push_back(NextRecordedOperandNo++);
984981
}

llvm/utils/TableGen/RegisterInfoEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,12 @@ void RegisterInfoEmitter::emitComposeSubRegIndices(raw_ostream &OS,
726726
// Output the rows.
727727
OS << " static const " << getMinimalTypeForRange(SubRegIndicesSize + 1, 32)
728728
<< " Rows[" << Rows.size() << "][" << SubRegIndicesSize << "] = {\n";
729-
for (unsigned r = 0, re = Rows.size(); r != re; ++r) {
729+
for (const auto &Row : Rows) {
730730
OS << " { ";
731-
for (unsigned i = 0, e = SubRegIndicesSize; i != e; ++i)
732-
if (Rows[r][i])
733-
OS << Rows[r][i]->getQualifiedName() << ", ";
731+
for (const llvm::CodeGenSubRegIndex *Elem :
732+
ArrayRef(&Row[0], SubRegIndicesSize))
733+
if (Elem)
734+
OS << Elem->getQualifiedName() << ", ";
734735
else
735736
OS << "0, ";
736737
OS << "},\n";
@@ -830,8 +831,7 @@ void RegisterInfoEmitter::emitComposeSubRegIndexLaneMask(raw_ostream &OS,
830831
for (size_t s = 0, se = Sequences.size(); s != se; ++s) {
831832
OS << " ";
832833
const SmallVectorImpl<MaskRolPair> &Sequence = Sequences[s];
833-
for (size_t p = 0, pe = Sequence.size(); p != pe; ++p) {
834-
const MaskRolPair &P = Sequence[p];
834+
for (const MaskRolPair &P : Sequence) {
835835
printMask(OS << "{ ", P.Mask);
836836
OS << format(", %2u }, ", P.RotateLeft);
837837
}

llvm/utils/TableGen/X86DisassemblerTables.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,9 @@ void DisassemblerTables::emitInstructionInfo(raw_ostream &o,
882882
N = ++OperandSetNum;
883883

884884
o << " { /* " << (OperandSetNum - 1) << " */\n";
885-
for (unsigned i = 0, e = OperandList.size(); i != e; ++i) {
886-
const char *Encoding = stringForOperandEncoding(OperandList[i].first);
887-
const char *Type = stringForOperandType(OperandList[i].second);
885+
for (const auto &[Enc, Ty] : OperandList) {
886+
const char *Encoding = stringForOperandEncoding(Enc);
887+
const char *Type = stringForOperandType(Ty);
888888
o << " { " << Encoding << ", " << Type << " },\n";
889889
}
890890
o << " },\n";

0 commit comments

Comments
 (0)