diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp --- a/llvm/lib/ObjectYAML/DWARFYAML.cpp +++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp @@ -59,22 +59,20 @@ DWARFYAML::Data::getAbbrevTableInfoByID(uint64_t ID) const { if (AbbrevTableInfoMap.empty()) { uint64_t AbbrevTableOffset = 0; - for (auto &AbbrevTable : enumerate(DebugAbbrev)) { + for (const auto &[Index, AbbrevTable] : enumerate(DebugAbbrev)) { // If the abbrev table's ID isn't specified, we use the index as its ID. - uint64_t AbbrevTableID = - AbbrevTable.value().ID.value_or(AbbrevTable.index()); + uint64_t AbbrevTableID = AbbrevTable.ID.value_or(Index); auto It = AbbrevTableInfoMap.insert( - {AbbrevTableID, AbbrevTableInfo{/*Index=*/AbbrevTable.index(), + {AbbrevTableID, AbbrevTableInfo{/*Index=*/Index, /*Offset=*/AbbrevTableOffset}}); if (!It.second) return createStringError( errc::invalid_argument, "the ID (%" PRIu64 ") of abbrev table with index %zu has been used " "by abbrev table with index %" PRIu64, - AbbrevTableID, AbbrevTable.index(), It.first->second.Index); + AbbrevTableID, Index, It.first->second.Index); - AbbrevTableOffset += - getAbbrevTableContentByIndex(AbbrevTable.index()).size(); + AbbrevTableOffset += getAbbrevTableContentByIndex(Index).size(); } } diff --git a/llvm/lib/ObjectYAML/MinidumpEmitter.cpp b/llvm/lib/ObjectYAML/MinidumpEmitter.cpp --- a/llvm/lib/ObjectYAML/MinidumpEmitter.cpp +++ b/llvm/lib/ObjectYAML/MinidumpEmitter.cpp @@ -236,8 +236,8 @@ Obj.Header.StreamDirectoryRVA = File.allocateArray(ArrayRef(StreamDirectory)); Obj.Header.NumberOfStreams = StreamDirectory.size(); - for (auto &Stream : enumerate(Obj.Streams)) - StreamDirectory[Stream.index()] = layout(File, *Stream.value()); + for (const auto &[Index, Stream] : enumerate(Obj.Streams)) + StreamDirectory[Index] = layout(File, *Stream); File.writeTo(Out); return true; diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -349,16 +349,16 @@ static SmallBitVector buildUseMask(int VF, ArrayRef Mask, UseMask MaskArg) { SmallBitVector UseMask(VF, true); - for (auto P : enumerate(Mask)) { - if (P.value() == UndefMaskElem) { + for (auto [Idx, Value] : enumerate(Mask)) { + if (Value == UndefMaskElem) { if (MaskArg == UseMask::UndefsAsMask) - UseMask.reset(P.index()); + UseMask.reset(Idx); continue; } - if (MaskArg == UseMask::FirstArg && P.value() < VF) - UseMask.reset(P.value()); - else if (MaskArg == UseMask::SecondArg && P.value() >= VF) - UseMask.reset(P.value() - VF); + if (MaskArg == UseMask::FirstArg && Value < VF) + UseMask.reset(Value); + else if (MaskArg == UseMask::SecondArg && Value >= VF) + UseMask.reset(Value - VF); } return UseMask; } @@ -3959,7 +3959,7 @@ return std::get<1>(X) < std::get<1>(Y); }); int InitialOffset = std::get<1>(Vec[0]); - AnyConsecutive |= all_of(enumerate(Vec), [InitialOffset](auto &P) { + AnyConsecutive |= all_of(enumerate(Vec), [InitialOffset](auto &&P) { return std::get<1>(P.value()) == int(P.index()) + InitialOffset; }); } diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp @@ -101,9 +101,9 @@ continue; std::set ArgIndexesToKeep; - for (auto &Arg : enumerate(F->args())) - if (ArgsToKeep.count(&Arg.value())) - ArgIndexesToKeep.insert(Arg.index()); + for (const auto &[Index, Arg] : enumerate(F->args())) + if (ArgsToKeep.count(&Arg)) + ArgIndexesToKeep.insert(Index); auto *ClonedFunc = CloneFunction(F, VMap); // In order to preserve function order, we move Clone after old Function diff --git a/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp b/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp --- a/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp +++ b/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp @@ -222,7 +222,7 @@ // 5, 5, 5 EXPECT_EQ(3u, TestState->Callbacks.count()); - for (auto I : enumerate(IndicesToVisit)) + for (const auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } @@ -251,7 +251,7 @@ // 2, 4, 7 EXPECT_EQ(3u, TestState->Callbacks.count()); - for (auto I : enumerate(IndicesToVisit)) + for (const auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } @@ -280,7 +280,7 @@ // 2, 4, 7 EXPECT_EQ(3u, TestState->Callbacks.count()); - for (auto &I : enumerate(IndicesToVisit)) + for (const auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } @@ -311,7 +311,7 @@ // [0, 2] EXPECT_EQ(3u, TestState->Callbacks.count()); - for (auto I : enumerate(IndicesToVisit)) + for (const auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } @@ -341,7 +341,7 @@ // 5, 7 EXPECT_EQ(2u, TestState->Callbacks.count()); - for (auto &I : enumerate(IndicesToVisit)) + for (const auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } diff --git a/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp b/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp --- a/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp +++ b/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp @@ -89,20 +89,20 @@ TraversableEdges(MatchDag.getNumEdges()), TestablePredicates(MatchDag.getNumPredicates()) { // Number all the predicates in this DAG - for (auto &P : enumerate(MatchDag.predicates())) { - PredicateIDs.insert(std::make_pair(P.value(), P.index())); + for (const auto &[Idx, P] : enumerate(MatchDag.predicates())) { + PredicateIDs.insert(std::make_pair(P, Idx)); } // Number all the predicate dependencies in this DAG and set up a bitvector // for each predicate indicating the unsatisfied dependencies. - for (auto &Dep : enumerate(MatchDag.predicate_edges())) { - PredicateDepIDs.insert(std::make_pair(Dep.value(), Dep.index())); + for (const auto &[Idx, Dep] : enumerate(MatchDag.predicate_edges())) { + PredicateDepIDs.insert(std::make_pair(Dep, Idx)); } UnsatisfiedPredDepsForPred.resize(MatchDag.getNumPredicates(), BitVector(PredicateDepIDs.size())); - for (auto &Dep : enumerate(MatchDag.predicate_edges())) { - unsigned ID = PredicateIDs.lookup(Dep.value()->getPredicate()); - UnsatisfiedPredDepsForPred[ID].set(Dep.index()); + for (const auto &[Idx, Dep] : enumerate(MatchDag.predicate_edges())) { + unsigned ID = PredicateIDs.lookup(Dep->getPredicate()); + UnsatisfiedPredDepsForPred[ID].set(Idx); } } @@ -134,10 +134,10 @@ // Mark the dependencies that are now satisfied as a result of this // instruction and mark any predicates whose dependencies are fully // satisfied. - for (auto &Dep : enumerate(MatchDag.predicate_edges())) { + for (const auto &Dep : enumerate(MatchDag.predicate_edges())) { if (Dep.value()->getRequiredMI() == Instr && Dep.value()->getRequiredMO() == nullptr) { - for (auto &DepsFor : enumerate(UnsatisfiedPredDepsForPred)) { + for (const auto &DepsFor : enumerate(UnsatisfiedPredDepsForPred)) { DepsFor.value().reset(Dep.index()); if (DepsFor.value().none()) TestablePredicates.set(DepsFor.index()); @@ -157,10 +157,9 @@ // When an operand becomes reachable, we potentially activate some traversals. // Record the edges that can now be followed as a result of this // instruction. - for (auto &E : enumerate(MatchDag.edges())) { - if (E.value()->getFromMI() == Instr && - E.value()->getFromMO()->getIdx() == OpIdx) { - TraversableEdges.set(E.index()); + for (const auto &[Idx, E] : enumerate(MatchDag.edges())) { + if (E->getFromMI() == Instr && E->getFromMO()->getIdx() == OpIdx) { + TraversableEdges.set(Idx); } } @@ -168,10 +167,10 @@ // Clear the dependencies that are now satisfied as a result of this // operand and activate any predicates whose dependencies are fully // satisfied. - for (auto &Dep : enumerate(MatchDag.predicate_edges())) { + for (const auto &Dep : enumerate(MatchDag.predicate_edges())) { if (Dep.value()->getRequiredMI() == Instr && Dep.value()->getRequiredMO() && Dep.value()->getRequiredMO()->getIdx() == OpIdx) { - for (auto &DepsFor : enumerate(UnsatisfiedPredDepsForPred)) { + for (const auto &DepsFor : enumerate(UnsatisfiedPredDepsForPred)) { DepsFor.value().reset(Dep.index()); if (DepsFor.value().none()) TestablePredicates.set(DepsFor.index()); @@ -536,22 +535,22 @@ BitVector PossibleLeaves = getPossibleLeavesForPartition(PartitionIdx); // Consume any predicates we handled. - for (auto &EnumeratedLeaf : enumerate(Builder.getPossibleLeaves())) { - if (!PossibleLeaves[EnumeratedLeaf.index()]) + for (const auto &[Index, EnumeratedLeaf] : + enumerate(Builder.getPossibleLeaves())) { + if (!PossibleLeaves[Index]) continue; - auto &Leaf = EnumeratedLeaf.value(); - const auto &TestedPredicatesForLeaf = - TestedPredicates[EnumeratedLeaf.index()]; + const auto &TestedPredicatesForLeaf = TestedPredicates[Index]; for (unsigned PredIdx : TestedPredicatesForLeaf.set_bits()) { - LLVM_DEBUG(dbgs() << " " << Leaf.getName() << " tested predicate #" - << PredIdx << " of " << TestedPredicatesForLeaf.size() - << " " << *Leaf.getPredicate(PredIdx) << "\n"); - Leaf.RemainingPredicates.reset(PredIdx); - Leaf.TestablePredicates.reset(PredIdx); + LLVM_DEBUG(dbgs() << " " << EnumeratedLeaf.getName() + << " tested predicate #" << PredIdx << " of " + << TestedPredicatesForLeaf.size() << " " + << *EnumeratedLeaf.getPredicate(PredIdx) << "\n"); + EnumeratedLeaf.RemainingPredicates.reset(PredIdx); + EnumeratedLeaf.TestablePredicates.reset(PredIdx); } - SubBuilder.addLeaf(Leaf); + SubBuilder.addLeaf(EnumeratedLeaf); } // Nothing to do, we don't know anything about this instruction as a result @@ -571,11 +570,11 @@ if (!InstrInfo) continue; const GIMatchDagInstr *Instr = InstrInfo->getInstrNode(); - for (auto &E : enumerate(Leaf.getMatchDag().edges())) { - if (E.value()->getFromMI() == Instr && - E.value()->getFromMO()->getIdx() < CGI->Operands.size()) { - ReferencedOperands.resize(E.value()->getFromMO()->getIdx() + 1); - ReferencedOperands.set(E.value()->getFromMO()->getIdx()); + for (const auto &E : Leaf.getMatchDag().edges()) { + if (E->getFromMI() == Instr && + E->getFromMO()->getIdx() < CGI->Operands.size()) { + ReferencedOperands.resize(E->getFromMO()->getIdx() + 1); + ReferencedOperands.set(E->getFromMO()->getIdx()); } } } @@ -715,16 +714,16 @@ std::vector TraversedEdgesByNewLeaves; // Consume any edges we handled. - for (auto &EnumeratedLeaf : enumerate(Builder.getPossibleLeaves())) { - if (!PossibleLeaves[EnumeratedLeaf.index()]) + for (const auto &[Index, EnumeratedLeaf] : + enumerate(Builder.getPossibleLeaves())) { + if (!PossibleLeaves[Index]) continue; - auto &Leaf = EnumeratedLeaf.value(); - const auto &TraversedEdgesForLeaf = TraversedEdges[EnumeratedLeaf.index()]; + const auto &TraversedEdgesForLeaf = TraversedEdges[Index]; TraversedEdgesByNewLeaves.push_back(TraversedEdgesForLeaf); - Leaf.RemainingEdges.reset(TraversedEdgesForLeaf); - Leaf.TraversableEdges.reset(TraversedEdgesForLeaf); - SubBuilder.addLeaf(Leaf); + EnumeratedLeaf.RemainingEdges.reset(TraversedEdgesForLeaf); + EnumeratedLeaf.TraversableEdges.reset(TraversedEdgesForLeaf); + SubBuilder.addLeaf(EnumeratedLeaf); } // Nothing to do. The only thing we know is that it isn't a vreg-def.