[llvm] 8857202 - [llvm] Use llvm::find (NFC)

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 19 20:54:58 PST 2021


On 1/19/21 8:52 PM, Kazu Hirata wrote:
> The patch is intended to be a cleanup.  Specifically, I'm trying to 
> reduce repeated mentions of container names to improve readability, much 
> like std::ranges::find of C++20 would.
> 
> I'm not sure the std:: version is preferred.  Maybe we will prefer 
> std::ranges::find to llvm::find when we can use C++20 in the llvm source 
> code, but that will be a few years from now.
> 

Ok, makes sense.  Thanks for explaining.

-Tom


> On Tue, Jan 19, 2021 at 8:38 PM Tom Stellard <tstellar at redhat.com 
> <mailto:tstellar at redhat.com>> wrote:
> 
>     On 1/19/21 8:19 PM, Kazu Hirata via llvm-commits wrote:
>      >
>      > Author: Kazu Hirata
>      > Date: 2021-01-19T20:19:14-08:00
>      > New Revision: 885720248921324d28b983248dcc4056fd994a0f
>      >
>      > URL:
>     https://github.com/llvm/llvm-project/commit/885720248921324d28b983248dcc4056fd994a0f
>      > DIFF:
>     https://github.com/llvm/llvm-project/commit/885720248921324d28b983248dcc4056fd994a0f.diff
>      >
>      > LOG: [llvm] Use llvm::find (NFC)
>      >
> 
>     What is the purpose of this change?  Aren't the std:: versions
>     preferred?
> 
>     -Tom
> 
>      > Added:
>      >
>      >
>      > Modified:
>      >      llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>      >      llvm/lib/MCA/Stages/InstructionTables.cpp
>      >      llvm/lib/Support/DynamicLibrary.cpp
>      >      llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
>      >      llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp
>      >      llvm/lib/Transforms/Scalar/GuardWidening.cpp
>      >      llvm/lib/Transforms/Vectorize/VPlan.h
>      >      llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
>      >      llvm/utils/TableGen/SubtargetEmitter.cpp
>      >
>      > Removed:
>      >
>      >
>      >
>      >
>     ################################################################################
>      > diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>     b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>      > index ef83df8bdd96..1bee1421cac0 100644
>      > --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>      > +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>      > @@ -18957,8 +18957,7 @@ SDValue
>     DAGCombiner::reduceBuildVecToShuffle(SDNode *N) {
>      >       // Have we seen this input vector before?
>      >       // The vectors are expected to be tiny (usually 1 or 2
>     elements), so using
>      >       // a map back from SDValues to numbers isn't worth it.
>      > -    unsigned Idx = std::distance(
>      > -        VecIn.begin(), std::find(VecIn.begin(), VecIn.end(),
>     ExtractedFromVec));
>      > +    unsigned Idx = std::distance(VecIn.begin(), find(VecIn,
>     ExtractedFromVec));
>      >       if (Idx == VecIn.size())
>      >         VecIn.push_back(ExtractedFromVec);
>      >
>      >
>      > diff  --git a/llvm/lib/MCA/Stages/InstructionTables.cpp
>     b/llvm/lib/MCA/Stages/InstructionTables.cpp
>      > index a0cdfb89c553..93e368123066 100644
>      > --- a/llvm/lib/MCA/Stages/InstructionTables.cpp
>      > +++ b/llvm/lib/MCA/Stages/InstructionTables.cpp
>      > @@ -30,8 +30,7 @@ Error InstructionTables::execute(InstRef &IR) {
>      >       if (!Resource.second.size())
>      >         continue;
>      >       unsigned Cycles = Resource.second.size();
>      > -    unsigned Index = std::distance(
>      > -        Masks.begin(), std::find(Masks.begin(), Masks.end(),
>     Resource.first));
>      > +    unsigned Index = std::distance(Masks.begin(), find(Masks,
>     Resource.first));
>      >       const MCProcResourceDesc &ProcResource =
>     *SM.getProcResource(Index);
>      >       unsigned NumUnits = ProcResource.NumUnits;
>      >       if (!ProcResource.SubUnitsIdxBegin) {
>      >
>      > diff  --git a/llvm/lib/Support/DynamicLibrary.cpp
>     b/llvm/lib/Support/DynamicLibrary.cpp
>      > index d23716016fb2..bdf74623670b 100644
>      > --- a/llvm/lib/Support/DynamicLibrary.cpp
>      > +++ b/llvm/lib/Support/DynamicLibrary.cpp
>      > @@ -39,9 +39,7 @@ class DynamicLibrary::HandleSet {
>      >     HandleSet() : Process(nullptr) {}
>      >     ~HandleSet();
>      >
>      > -  HandleList::iterator Find(void *Handle) {
>      > -    return std::find(Handles.begin(), Handles.end(), Handle);
>      > -  }
>      > +  HandleList::iterator Find(void *Handle) { return find(Handles,
>     Handle); }
>      >
>      >     bool Contains(void *Handle) {
>      >       return Handle == Process || Find(Handle) != Handles.end();
>      >
>      > diff  --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
>     b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
>      > index fed1abb9549b..87b1c43961d7 100644
>      > --- a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
>      > +++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
>      > @@ -527,7 +527,7 @@ void HexagonSubtarget::restoreLatency(SUnit
>     *Src, SUnit *Dst) const {
>      >
>      >       // Update the latency of opposite edge too.
>      >       T.setSUnit(Src);
>      > -    auto F = std::find(Dst->Preds.begin(), Dst->Preds.end(), T);
>      > +    auto F = find(Dst->Preds, T);
>      >       assert(F != Dst->Preds.end());
>      >       F->setLatency(I.getLatency());
>      >     }
>      > @@ -544,7 +544,7 @@ void HexagonSubtarget::changeLatency(SUnit
>     *Src, SUnit *Dst, unsigned Lat)
>      >
>      >       // Update the latency of opposite edge too.
>      >       T.setSUnit(Src);
>      > -    auto F = std::find(Dst->Preds.begin(), Dst->Preds.end(), T);
>      > +    auto F = find(Dst->Preds, T);
>      >       assert(F != Dst->Preds.end());
>      >       F->setLatency(Lat);
>      >     }
>      >
>      > diff  --git a/llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp
>     b/llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp
>      > index 90cc81beb89d..5cee00c61fc1 100644
>      > --- a/llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp
>      > +++ b/llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp
>      > @@ -206,9 +206,9 @@ static bool splitMBB(BlockSplitInfo &BSI) {
>      >     NewMBB->splice(NewMBB->end(), ThisMBB, InsertPoint,
>     ThisMBB->end());
>      >     NewMBB->transferSuccessors(ThisMBB);
>      >     if (!ProbOrigTarget.isUnknown()) {
>      > -    auto MBBI = std::find(NewMBB->succ_begin(),
>     NewMBB->succ_end(), OrigTarget);
>      > +    auto MBBI = find(NewMBB->successors(), OrigTarget);
>      >       NewMBB->setSuccProbability(MBBI, ProbOrigTarget);
>      > -    MBBI = std::find(NewMBB->succ_begin(), NewMBB->succ_end(),
>     OrigFallThrough);
>      > +    MBBI = find(NewMBB->successors(), OrigFallThrough);
>      >       NewMBB->setSuccProbability(MBBI, ProbOrigFallThrough);
>      >     }
>      >
>      >
>      > diff  --git a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
>     b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
>      > index 1735266f0e58..6ce79bdb7076 100644
>      > --- a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
>      > +++ b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
>      > @@ -347,9 +347,8 @@ bool
>     GuardWideningImpl::eliminateInstrViaWidening(
>      >       const auto &GuardsInCurBB = GuardsInBlock.find(CurBB)->second;
>      >
>      >       auto I = GuardsInCurBB.begin();
>      > -    auto E = Instr->getParent() == CurBB
>      > -                 ? std::find(GuardsInCurBB.begin(),
>     GuardsInCurBB.end(), Instr)
>      > -                 : GuardsInCurBB.end();
>      > +    auto E = Instr->getParent() == CurBB ? find(GuardsInCurBB,
>     Instr)
>      > +                                         : GuardsInCurBB.end();
>      >
>      >   #ifndef NDEBUG
>      >       {
>      >
>      > diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.h
>     b/llvm/lib/Transforms/Vectorize/VPlan.h
>      > index 4500e761a6e1..8d907dbc857d 100644
>      > --- a/llvm/lib/Transforms/Vectorize/VPlan.h
>      > +++ b/llvm/lib/Transforms/Vectorize/VPlan.h
>      > @@ -413,14 +413,14 @@ class VPBlockBase {
>      >
>      >     /// Remove \p Predecessor from the predecessors of this block.
>      >     void removePredecessor(VPBlockBase *Predecessor) {
>      > -    auto Pos = std::find(Predecessors.begin(),
>     Predecessors.end(), Predecessor);
>      > +    auto Pos = find(Predecessors, Predecessor);
>      >       assert(Pos && "Predecessor does not exist");
>      >       Predecessors.erase(Pos);
>      >     }
>      >
>      >     /// Remove \p Successor from the successors of this block.
>      >     void removeSuccessor(VPBlockBase *Successor) {
>      > -    auto Pos = std::find(Successors.begin(), Successors.end(),
>     Successor);
>      > +    auto Pos = find(Successors, Successor);
>      >       assert(Pos && "Successor does not exist");
>      >       Successors.erase(Pos);
>      >     }
>      >
>      > diff  --git a/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
>     b/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
>      > index b7155398bd30..a67f1de67ed7 100644
>      > --- a/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
>      > +++ b/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
>      > @@ -121,8 +121,7 @@ void
>     GIMatchTreeBuilderLeafInfo::declareInstr(const GIMatchDagInstr
>     *Instr, unsi
>      >       Info.bindOperandVariable(VarBinding.second, ID,
>     VarBinding.first);
>      >
>      >     // Clear the bit indicating we haven't visited this instr.
>      > -  const auto &NodeI = std::find(MatchDag.instr_nodes_begin(),
>      > -                            MatchDag.instr_nodes_end(), Instr);
>      > +  const auto &NodeI = find(MatchDag.instr_nodes(), Instr);
>      >     assert(NodeI != MatchDag.instr_nodes_end() && "Instr isn't in
>     this DAG");
>      >     unsigned InstrIdx = MatchDag.getInstrNodeIdx(NodeI);
>      >     RemainingInstrNodes.reset(InstrIdx);
>      >
>      > diff  --git a/llvm/utils/TableGen/SubtargetEmitter.cpp
>     b/llvm/utils/TableGen/SubtargetEmitter.cpp
>      > index bd40d0e83dec..7d2b4b929df3 100644
>      > --- a/llvm/utils/TableGen/SubtargetEmitter.cpp
>      > +++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
>      > @@ -730,10 +730,8 @@ void
>     SubtargetEmitter::EmitLoadStoreQueueInfo(const CodeGenProcModel
>     &ProcModel,
>      >     unsigned QueueID = 0;
>      >     if (ProcModel.LoadQueue) {
>      >       const Record *Queue =
>     ProcModel.LoadQueue->getValueAsDef("QueueDescriptor");
>      > -    QueueID =
>      > -        1 + std::distance(ProcModel.ProcResourceDefs.begin(),
>      > -                         
>     std::find(ProcModel.ProcResourceDefs.begin(),
>      > -                                   
>     ProcModel.ProcResourceDefs.end(), Queue));
>      > +    QueueID = 1 + std::distance(ProcModel.ProcResourceDefs.begin(),
>      > +                                find(ProcModel.ProcResourceDefs,
>     Queue));
>      >     }
>      >     OS << "  " << QueueID << ", // Resource Descriptor for the
>     Load Queue\n";
>      >
>      > @@ -741,10 +739,8 @@ void
>     SubtargetEmitter::EmitLoadStoreQueueInfo(const CodeGenProcModel
>     &ProcModel,
>      >     if (ProcModel.StoreQueue) {
>      >       const Record *Queue =
>      >           ProcModel.StoreQueue->getValueAsDef("QueueDescriptor");
>      > -    QueueID =
>      > -        1 + std::distance(ProcModel.ProcResourceDefs.begin(),
>      > -                         
>     std::find(ProcModel.ProcResourceDefs.begin(),
>      > -                                   
>     ProcModel.ProcResourceDefs.end(), Queue));
>      > +    QueueID = 1 + std::distance(ProcModel.ProcResourceDefs.begin(),
>      > +                                find(ProcModel.ProcResourceDefs,
>     Queue));
>      >     }
>      >     OS << "  " << QueueID << ", // Resource Descriptor for the
>     Store Queue\n";
>      >   }
>      >
>      >
>      >
>      > _______________________________________________
>      > llvm-commits mailing list
>      > llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
>      > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>      >
> 



More information about the llvm-commits mailing list