Skip to content

Commit fab2bb8

Browse files
authored
Add llvm::min/max_element and use it in llvm/ and mlir/ directories. (#84678)
For some reason this was missing from STLExtras.
1 parent 6bec4fc commit fab2bb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+111
-119
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,22 @@ auto upper_bound(R &&Range, T &&Value, Compare C) {
19711971
std::forward<T>(Value), C);
19721972
}
19731973

1974+
template <typename R> auto min_element(R &&Range) {
1975+
return std::min_element(adl_begin(Range), adl_end(Range));
1976+
}
1977+
1978+
template <typename R, typename Compare> auto min_element(R &&Range, Compare C) {
1979+
return std::min_element(adl_begin(Range), adl_end(Range), C);
1980+
}
1981+
1982+
template <typename R> auto max_element(R &&Range) {
1983+
return std::max_element(adl_begin(Range), adl_end(Range));
1984+
}
1985+
1986+
template <typename R, typename Compare> auto max_element(R &&Range, Compare C) {
1987+
return std::max_element(adl_begin(Range), adl_end(Range), C);
1988+
}
1989+
19741990
template <typename R>
19751991
void stable_sort(R &&Range) {
19761992
std::stable_sort(adl_begin(Range), adl_end(Range));

llvm/include/llvm/CodeGen/RegAllocPBQP.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,8 @@ class RegAllocSolverImpl {
462462
NodeStack.push_back(NId);
463463
G.disconnectAllNeighborsFromNode(NId);
464464
} else if (!NotProvablyAllocatableNodes.empty()) {
465-
NodeSet::iterator NItr =
466-
std::min_element(NotProvablyAllocatableNodes.begin(),
467-
NotProvablyAllocatableNodes.end(),
468-
SpillCostComparator(G));
465+
NodeSet::iterator NItr = llvm::min_element(NotProvablyAllocatableNodes,
466+
SpillCostComparator(G));
469467
NodeId NId = *NItr;
470468
NotProvablyAllocatableNodes.erase(NItr);
471469
NodeStack.push_back(NId);

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10839,10 +10839,9 @@ bool ScalarEvolution::isKnownViaInduction(ICmpInst::Predicate Pred,
1083910839
#endif
1084010840

1084110841
const Loop *MDL =
10842-
*std::max_element(LoopsUsed.begin(), LoopsUsed.end(),
10843-
[&](const Loop *L1, const Loop *L2) {
10844-
return DT.properlyDominates(L1->getHeader(), L2->getHeader());
10845-
});
10842+
*llvm::max_element(LoopsUsed, [&](const Loop *L1, const Loop *L2) {
10843+
return DT.properlyDominates(L1->getHeader(), L2->getHeader());
10844+
});
1084610845

1084710846
// Get init and post increment value for LHS.
1084810847
auto SplitLHS = SplitIntoInitAndPostInc(MDL, LHS);

llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ uint32_t PDBFile::getNumStreams() const {
8686
}
8787

8888
uint32_t PDBFile::getMaxStreamSize() const {
89-
return *std::max_element(ContainerLayout.StreamSizes.begin(),
90-
ContainerLayout.StreamSizes.end());
89+
return *llvm::max_element(ContainerLayout.StreamSizes);
9190
}
9291

9392
uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const {

llvm/lib/IR/DataLayout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ Type *DataLayout::getSmallestLegalIntType(LLVMContext &C, unsigned Width) const
898898
}
899899

900900
unsigned DataLayout::getLargestLegalIntTypeSizeInBits() const {
901-
auto Max = std::max_element(LegalIntWidths.begin(), LegalIntWidths.end());
901+
auto Max = llvm::max_element(LegalIntWidths);
902902
return Max != LegalIntWidths.end() ? *Max : 0;
903903
}
904904

llvm/lib/ObjCopy/MachO/MachOWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ size_t MachOWriter::totalSize() const {
126126
}
127127

128128
if (!Ends.empty())
129-
return *std::max_element(Ends.begin(), Ends.end());
129+
return *llvm::max_element(Ends);
130130

131131
// Otherwise, we have only Mach header and load commands.
132132
return headerSize() + loadCommandsSize();

llvm/lib/ProfileData/GCOV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ void Context::collectFunction(GCOVFunction &f, Summary &summary) {
703703
for (const GCOVBlock &b : f.blocksRange()) {
704704
if (b.lines.empty())
705705
continue;
706-
uint32_t maxLineNum = *std::max_element(b.lines.begin(), b.lines.end());
706+
uint32_t maxLineNum = *llvm::max_element(b.lines);
707707
if (maxLineNum >= si.lines.size())
708708
si.lines.resize(maxLineNum + 1);
709709
for (uint32_t lineNum : b.lines) {

llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ bool SVEIntrinsicOpts::coalescePTrueIntrinsicCalls(
138138
return false;
139139

140140
// Find the ptrue with the most lanes.
141-
auto *MostEncompassingPTrue = *std::max_element(
142-
PTrues.begin(), PTrues.end(), [](auto *PTrue1, auto *PTrue2) {
141+
auto *MostEncompassingPTrue =
142+
*llvm::max_element(PTrues, [](auto *PTrue1, auto *PTrue2) {
143143
auto *PTrue1VTy = cast<ScalableVectorType>(PTrue1->getType());
144144
auto *PTrue2VTy = cast<ScalableVectorType>(PTrue2->getType());
145145
return PTrue1VTy->getElementCount().getKnownMinValue() <

llvm/lib/Target/AMDGPU/GCNILPSched.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ GCNILPScheduler::schedule(ArrayRef<const SUnit*> BotRoots,
313313
Schedule.reserve(SUnits.size());
314314
while (true) {
315315
if (AvailQueue.empty() && !PendingQueue.empty()) {
316-
auto EarliestSU = std::min_element(
317-
PendingQueue.begin(), PendingQueue.end(),
318-
[=](const Candidate& C1, const Candidate& C2) {
319-
return C1.SU->getHeight() < C2.SU->getHeight();
320-
})->SU;
316+
auto EarliestSU =
317+
llvm::min_element(PendingQueue, [=](const Candidate &C1,
318+
const Candidate &C2) {
319+
return C1.SU->getHeight() < C2.SU->getHeight();
320+
})->SU;
321321
advanceToCycle(std::max(CurCycle + 1, EarliestSU->getHeight()));
322322
}
323323
if (AvailQueue.empty())

llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,8 @@ bool SIFixSGPRCopies::needToBeConvertedToVALU(V2SCopyInfo *Info) {
973973
Info->Score = 0;
974974
return true;
975975
}
976-
Info->Siblings = SiblingPenalty[*std::max_element(
977-
Info->SChain.begin(), Info->SChain.end(),
978-
[&](MachineInstr *A, MachineInstr *B) -> bool {
976+
Info->Siblings = SiblingPenalty[*llvm::max_element(
977+
Info->SChain, [&](MachineInstr *A, MachineInstr *B) -> bool {
979978
return SiblingPenalty[A].size() < SiblingPenalty[B].size();
980979
})];
981980
Info->Siblings.remove_if([&](unsigned ID) { return ID == Info->ID; });

0 commit comments

Comments
 (0)