From a1bedd75a0ac79c472704ce80b30566c75d910ea Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 2 Jun 2015 04:15:51 +0000 Subject: [PATCH] [TableGen] Use range-based for loops. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238805 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Record.cpp | 21 ++++++++++----------- utils/TableGen/AsmMatcherEmitter.cpp | 4 ++-- utils/TableGen/CodeGenDAGPatterns.cpp | 12 ++++++------ utils/TableGen/CodeGenMapTable.cpp | 24 ++++++++++-------------- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 3097c4ee33e..02c54aaec93 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -504,8 +504,8 @@ Init *ListInit::convertInitializerTo(RecTy *Ty) const { // Verify that all of the elements of the list are subclasses of the // appropriate class! - for (unsigned i = 0, e = getSize(); i != e; ++i) - if (Init *CI = getElement(i)->convertInitializerTo(LRT->getElementType())) + for (Init *I : getValues()) + if (Init *CI = I->convertInitializerTo(LRT->getElementType())) Elements.push_back(CI); else return nullptr; @@ -541,9 +541,8 @@ Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) const { Resolved.reserve(getSize()); bool Changed = false; - for (unsigned i = 0, e = getSize(); i != e; ++i) { + for (Init *CurElt : getValues()) { Init *E; - Init *CurElt = getElement(i); do { E = CurElt; @@ -1744,8 +1743,8 @@ std::vector Record::getValueAsListOfDefs(StringRef FieldName) const { ListInit *List = getValueAsListInit(FieldName); std::vector Defs; - for (unsigned i = 0; i < List->getSize(); i++) { - if (DefInit *DI = dyn_cast(List->getElement(i))) + for (Init *I : List->getValues()) { + if (DefInit *DI = dyn_cast(I)) Defs.push_back(DI->getDef()); else PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + @@ -1778,8 +1777,8 @@ std::vector Record::getValueAsListOfInts(StringRef FieldName) const { ListInit *List = getValueAsListInit(FieldName); std::vector Ints; - for (unsigned i = 0; i < List->getSize(); i++) { - if (IntInit *II = dyn_cast(List->getElement(i))) + for (Init *I : List->getValues()) { + if (IntInit *II = dyn_cast(I)) Ints.push_back(II->getValue()); else PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + @@ -1796,9 +1795,9 @@ std::vector Record::getValueAsListOfStrings(StringRef FieldName) const { ListInit *List = getValueAsListInit(FieldName); std::vector Strings; - for (unsigned i = 0; i < List->getSize(); i++) { - if (StringInit *II = dyn_cast(List->getElement(i))) - Strings.push_back(II->getValue()); + for (Init *I : List->getValues()) { + if (StringInit *SI = dyn_cast(I)) + Strings.push_back(SI->getValue()); else PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + FieldName + "' does not have a list of strings initializer!"); diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp index 3ae41f11fa1..0d7c5ffbea1 100644 --- a/utils/TableGen/AsmMatcherEmitter.cpp +++ b/utils/TableGen/AsmMatcherEmitter.cpp @@ -1249,8 +1249,8 @@ void AsmMatcherInfo::buildOperandClasses() { CI->Kind = ClassInfo::UserClass0 + Index; ListInit *Supers = Rec->getValueAsListInit("SuperClasses"); - for (unsigned i = 0, e = Supers->getSize(); i != e; ++i) { - DefInit *DI = dyn_cast(Supers->getElement(i)); + for (Init *I : Supers->getValues()) { + DefInit *DI = dyn_cast(I); if (!DI) { PrintError(Rec->getLoc(), "Invalid super class reference!"); continue; diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp index 40ebdd99a7e..fa6fd43be09 100644 --- a/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/utils/TableGen/CodeGenDAGPatterns.cpp @@ -842,8 +842,8 @@ getPatternComplexity(const CodeGenDAGPatterns &CGP) const { /// std::string PatternToMatch::getPredicateCheck() const { std::string PredicateCheck; - for (unsigned i = 0, e = Predicates->getSize(); i != e; ++i) { - if (DefInit *Pred = dyn_cast(Predicates->getElement(i))) { + for (Init *I : Predicates->getValues()) { + if (DefInit *Pred = dyn_cast(I)) { Record *Def = Pred->getDef(); if (!Def->isSubClassOf("Predicate")) { #ifndef NDEBUG @@ -1999,8 +1999,8 @@ bool TreePatternNode::canPatternMatch(std::string &Reason, TreePattern::TreePattern(Record *TheRec, ListInit *RawPat, bool isInput, CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp), isInputPattern(isInput), HasError(false) { - for (unsigned i = 0, e = RawPat->getSize(); i != e; ++i) - Trees.push_back(ParseTreePattern(RawPat->getElement(i), "")); + for (Init *I : RawPat->getValues()) + Trees.push_back(ParseTreePattern(I, "")); } TreePattern::TreePattern(Record *TheRec, DagInit *Pat, bool isInput, @@ -2860,8 +2860,8 @@ static bool hasNullFragReference(DagInit *DI) { /// hasNullFragReference - Return true if any DAG in the list references /// the null_frag operator. static bool hasNullFragReference(ListInit *LI) { - for (unsigned i = 0, e = LI->getSize(); i != e; ++i) { - DagInit *DI = dyn_cast(LI->getElement(i)); + for (Init *I : LI->getValues()) { + DagInit *DI = dyn_cast(I); assert(DI && "non-dag in an instruction Pattern list?!"); if (hasNullFragReference(DI)) return true; diff --git a/utils/TableGen/CodeGenMapTable.cpp b/utils/TableGen/CodeGenMapTable.cpp index b52a91d0177..00c0b2e238d 100644 --- a/utils/TableGen/CodeGenMapTable.cpp +++ b/utils/TableGen/CodeGenMapTable.cpp @@ -132,8 +132,8 @@ public: PrintFatalError(MapRec->getLoc(), "InstrMapping record `" + MapRec->getName() + "' has empty " + "`ValueCols' field!"); - for (unsigned i = 0, e = ColValList->getSize(); i < e; i++) { - ListInit *ColI = dyn_cast(ColValList->getElement(i)); + for (Init *I : ColValList->getValues()) { + ListInit *ColI = dyn_cast(I); // Make sure that all the sub-lists in 'ValueCols' have same number of // elements as the fields in 'ColFields'. @@ -239,13 +239,11 @@ public: //===----------------------------------------------------------------------===// void MapTableEmitter::buildRowInstrMap() { - for (unsigned i = 0, e = InstrDefs.size(); i < e; i++) { - Record *CurInstr = InstrDefs[i]; + for (Record *CurInstr : InstrDefs) { std::vector KeyValue; ListInit *RowFields = InstrMapDesc.getRowFields(); - for (unsigned j = 0, endRF = RowFields->getSize(); j < endRF; j++) { - Init *RowFieldsJ = RowFields->getElement(j); - Init *CurInstrVal = CurInstr->getValue(RowFieldsJ)->getValue(); + for (Init *RowField : RowFields->getValues()) { + Init *CurInstrVal = CurInstr->getValue(RowField)->getValue(); KeyValue.push_back(CurInstrVal); } @@ -289,8 +287,7 @@ void MapTableEmitter::buildMapTable() { // constraints. const std::vector &ValueCols = InstrMapDesc.getValueCols(); unsigned NumOfCols = ValueCols.size(); - for (unsigned j = 0, endKI = KeyInstrVec.size(); j < endKI; j++) { - Record *CurKeyInstr = KeyInstrVec[j]; + for (Record *CurKeyInstr : KeyInstrVec) { std::vector ColInstrVec(NumOfCols); // Find the column instruction based on the constraints for the column. @@ -313,9 +310,8 @@ Record *MapTableEmitter::getInstrForColumn(Record *KeyInstr, std::vector KeyValue; // Construct KeyValue using KeyInstr's values for RowFields. - for (unsigned j = 0, endRF = RowFields->getSize(); j < endRF; j++) { - Init *RowFieldsJ = RowFields->getElement(j); - Init *KeyInstrVal = KeyInstr->getValue(RowFieldsJ)->getValue(); + for (Init *RowField : RowFields->getValues()) { + Init *KeyInstrVal = KeyInstr->getValue(RowField)->getValue(); KeyValue.push_back(KeyInstrVal); } @@ -478,8 +474,8 @@ void MapTableEmitter::emitTablesWithFunc(raw_ostream &OS) { OS << "// "<< InstrMapDesc.getName() << "\n"; OS << "int "<< InstrMapDesc.getName() << "(uint16_t Opcode"; if (ValueCols.size() > 1) { - for (unsigned i = 0, e = ColFields->getSize(); i < e; i++) { - std::string ColName = ColFields->getElement(i)->getAsUnquotedString(); + for (Init *CF : ColFields->getValues()) { + std::string ColName = CF->getAsUnquotedString(); OS << ", enum " << ColName << " in" << ColName << ") {\n"; } } else { OS << ") {\n"; } -- 2.34.1