Skip to content

Commit

Permalink
[llvm] Use llvm::unique (NFC) (#95628)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata authored Jun 15, 2024
1 parent bb3091a commit 7c6d0d2
Show file tree
Hide file tree
Showing 32 changed files with 55 additions and 73 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/IntervalTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ class IntervalTree {
References.push_back(std::addressof(Data));
}
std::stable_sort(Points.begin(), Points.end());
auto Last = std::unique(Points.begin(), Points.end());
auto Last = llvm::unique(Points);
Points.erase(Last, Points.end());

EndPoints.assign(Points.begin(), Points.end());
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ExecutionEngine/Orc/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class SymbolLookupSet {
/// by construction, this method can be used to turn it into a proper set.
void removeDuplicates() {
sortByAddress();
auto LastI = std::unique(Symbols.begin(), Symbols.end());
auto LastI = llvm::unique(Symbols);
Symbols.erase(LastI, Symbols.end());
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,7 @@ void InstrProfSymtab::finalizeSymtab() {
llvm::sort(MD5NameMap, less_first());
llvm::sort(MD5FuncMap, less_first());
llvm::sort(AddrToMD5Map, less_first());
AddrToMD5Map.erase(std::unique(AddrToMD5Map.begin(), AddrToMD5Map.end()),
AddrToMD5Map.end());
AddrToMD5Map.erase(llvm::unique(AddrToMD5Map), AddrToMD5Map.end());
Sorted = true;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/Delinearization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void llvm::findArrayDimensions(ScalarEvolution &SE,

// Remove duplicates.
array_pod_sort(Terms.begin(), Terms.end());
Terms.erase(std::unique(Terms.begin(), Terms.end()), Terms.end());
Terms.erase(llvm::unique(Terms), Terms.end());

// Put larger terms first.
llvm::sort(Terms, [](const SCEV *LHS, const SCEV *RHS) {
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Analysis/ImportedFunctionsInliningStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ void ImportedFunctionsInliningStatistics::dump(const bool Verbose) {
void ImportedFunctionsInliningStatistics::calculateRealInlines() {
// Removing duplicated Callers.
llvm::sort(NonImportedCallers);
NonImportedCallers.erase(
std::unique(NonImportedCallers.begin(), NonImportedCallers.end()),
NonImportedCallers.end());
NonImportedCallers.erase(llvm::unique(NonImportedCallers),
NonImportedCallers.end());

for (const auto &Name : NonImportedCallers) {
auto &Node = *NodesMap[Name];
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/StackSafetyAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ void StackSafetyDataFlowAnalysis<CalleeTy>::runDataFlow() {
Callees.push_back(CS.first.Callee);

llvm::sort(Callees);
Callees.erase(std::unique(Callees.begin(), Callees.end()), Callees.end());
Callees.erase(llvm::unique(Callees), Callees.end());

for (auto &Callee : Callees)
Callers[Callee].push_back(F.first);
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ void AccelTableBase::finalize(AsmPrinter *Asm, StringRef Prefix) {
[](const AccelTableData *A, const AccelTableData *B) {
return *A < *B;
});
E.second.Values.erase(
std::unique(E.second.Values.begin(), E.second.Values.end()),
E.second.Values.end());
E.second.Values.erase(llvm::unique(E.second.Values), E.second.Values.end());
}

// Figure out how many buckets we need, then compute the bucket contents and
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ class DebugLocEntry {
if (Values.size() == 1)
return;
llvm::sort(Values);
Values.erase(std::unique(Values.begin(), Values.end(),
[](const DbgValueLoc &A, const DbgValueLoc &B) {
return A.getExpression() == B.getExpression();
}),
Values.erase(llvm::unique(Values,
[](const DbgValueLoc &A, const DbgValueLoc &B) {
return A.getExpression() == B.getExpression();
}),
Values.end());
}

Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,11 +1130,11 @@ sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
return !!FragmentB;
return FragmentA->OffsetInBits < FragmentB->OffsetInBits;
});
GVEs.erase(std::unique(GVEs.begin(), GVEs.end(),
[](DwarfCompileUnit::GlobalExpr A,
DwarfCompileUnit::GlobalExpr B) {
return A.Expr == B.Expr;
}),
GVEs.erase(llvm::unique(GVEs,
[](DwarfCompileUnit::GlobalExpr A,
DwarfCompileUnit::GlobalExpr B) {
return A.Expr == B.Expr;
}),
GVEs.end());
return GVEs;
}
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6271,9 +6271,7 @@ bool CodeGenPrepare::splitLargeGEPOffsets() {
};
// Sorting all the GEPs of the same data structures based on the offsets.
llvm::sort(LargeOffsetGEPs, compareGEPOffset);
LargeOffsetGEPs.erase(
std::unique(LargeOffsetGEPs.begin(), LargeOffsetGEPs.end()),
LargeOffsetGEPs.end());
LargeOffsetGEPs.erase(llvm::unique(LargeOffsetGEPs), LargeOffsetGEPs.end());
// Skip if all the GEPs have the same offsets.
if (LargeOffsetGEPs.front().second == LargeOffsetGEPs.back().second)
continue;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/RegisterCoalescer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4248,8 +4248,7 @@ bool RegisterCoalescer::runOnMachineFunction(MachineFunction &fn) {
// Removing sub-register operands may allow GR32_ABCD -> GR32 and DPR_VFP2 ->
// DPR inflation.
array_pod_sort(InflateRegs.begin(), InflateRegs.end());
InflateRegs.erase(std::unique(InflateRegs.begin(), InflateRegs.end()),
InflateRegs.end());
InflateRegs.erase(llvm::unique(InflateRegs), InflateRegs.end());
LLVM_DEBUG(dbgs() << "Trying to inflate " << InflateRegs.size()
<< " regs.\n");
for (Register Reg : InflateRegs) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/SplitKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ void SplitAnalysis::analyzeUses() {

// Remove duplicates, keeping the smaller slot for each instruction.
// That is what we want for early clobbers.
UseSlots.erase(std::unique(UseSlots.begin(), UseSlots.end(),
SlotIndex::isSameInstr),
UseSlots.erase(llvm::unique(UseSlots, SlotIndex::isSameInstr),
UseSlots.end());

// Compute per-live block info.
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,14 @@ collectContributionData(DWARFContext::unit_iterator_range Units) {
// type units in dwo or dwp files) share contributions. We don't want
// to report them more than once.
Contributions.erase(
std::unique(Contributions.begin(), Contributions.end(),
[](const std::optional<StrOffsetsContributionDescriptor> &L,
const std::optional<StrOffsetsContributionDescriptor> &R) {
if (L && R)
return L->Base == R->Base && L->Size == R->Size;
return false;
}),
llvm::unique(
Contributions,
[](const std::optional<StrOffsetsContributionDescriptor> &L,
const std::optional<StrOffsetsContributionDescriptor> &R) {
if (L && R)
return L->Base == R->Base && L->Size == R->Size;
return false;
}),
Contributions.end());
return Contributions;
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6079,8 +6079,7 @@ bool AsmParser::parseMSInlineAsm(

// Set the unique clobbers.
array_pod_sort(ClobberRegs.begin(), ClobberRegs.end());
ClobberRegs.erase(std::unique(ClobberRegs.begin(), ClobberRegs.end()),
ClobberRegs.end());
ClobberRegs.erase(llvm::unique(ClobberRegs), ClobberRegs.end());
Clobbers.assign(ClobberRegs.size(), std::string());
for (unsigned I = 0, E = ClobberRegs.size(); I != E; ++I) {
raw_string_ostream OS(Clobbers[I]);
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/MC/MCParser/MasmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7443,8 +7443,7 @@ bool MasmParser::parseMSInlineAsm(

// Set the unique clobbers.
array_pod_sort(ClobberRegs.begin(), ClobberRegs.end());
ClobberRegs.erase(std::unique(ClobberRegs.begin(), ClobberRegs.end()),
ClobberRegs.end());
ClobberRegs.erase(llvm::unique(ClobberRegs), ClobberRegs.end());
Clobbers.assign(ClobberRegs.size(), std::string());
for (unsigned I = 0, E = ClobberRegs.size(); I != E; ++I) {
raw_string_ostream OS(Clobbers[I]);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void RegisterFile::collectWrites(
sort(Writes, [](const WriteRef &Lhs, const WriteRef &Rhs) {
return Lhs.getWriteState() < Rhs.getWriteState();
});
auto It = std::unique(Writes.begin(), Writes.end());
auto It = llvm::unique(Writes);
Writes.resize(std::distance(Writes.begin(), It));
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ std::vector<StringRef> CoverageMapping::getUniqueSourceFiles() const {
for (const auto &Function : getCoveredFunctions())
llvm::append_range(Filenames, Function.Filenames);
llvm::sort(Filenames);
auto Last = std::unique(Filenames.begin(), Filenames.end());
auto Last = llvm::unique(Filenames);
Filenames.erase(Last, Filenames.end());
return Filenames;
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {

// Remove duplicate binary ids.
llvm::sort(BinaryIds);
BinaryIds.erase(std::unique(BinaryIds.begin(), BinaryIds.end()),
BinaryIds.end());
BinaryIds.erase(llvm::unique(BinaryIds), BinaryIds.end());

for (const auto &BI : BinaryIds) {
// Increment by binary id length data type size.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/NVPTX/NVVMReflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static bool runNVVMReflect(Function &F, unsigned SmVersion) {
// Removing via isInstructionTriviallyDead may add duplicates to the ToRemove
// array. Filter out the duplicates before starting to erase from parent.
std::sort(ToRemove.begin(), ToRemove.end());
auto NewLastIter = std::unique(ToRemove.begin(), ToRemove.end());
auto NewLastIter = llvm::unique(ToRemove);
ToRemove.erase(NewLastIter, ToRemove.end());

for (Instruction *I : ToRemove)
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13353,11 +13353,11 @@ static SDValue lowerV8I16GeneralSingleInputShuffle(
SmallVector<int, 4> LoInputs;
copy_if(LoMask, std::back_inserter(LoInputs), [](int M) { return M >= 0; });
array_pod_sort(LoInputs.begin(), LoInputs.end());
LoInputs.erase(std::unique(LoInputs.begin(), LoInputs.end()), LoInputs.end());
LoInputs.erase(llvm::unique(LoInputs), LoInputs.end());
SmallVector<int, 4> HiInputs;
copy_if(HiMask, std::back_inserter(HiInputs), [](int M) { return M >= 0; });
array_pod_sort(HiInputs.begin(), HiInputs.end());
HiInputs.erase(std::unique(HiInputs.begin(), HiInputs.end()), HiInputs.end());
HiInputs.erase(llvm::unique(HiInputs), HiInputs.end());
int NumLToL = llvm::lower_bound(LoInputs, 4) - LoInputs.begin();
int NumHToL = LoInputs.size() - NumLToL;
int NumLToH = llvm::lower_bound(HiInputs, 4) - HiInputs.begin();
Expand Down Expand Up @@ -14245,13 +14245,11 @@ static SDValue lowerV16I8Shuffle(const SDLoc &DL, ArrayRef<int> Mask,
copy_if(Mask, std::back_inserter(LoInputs),
[](int M) { return M >= 0 && M < 8; });
array_pod_sort(LoInputs.begin(), LoInputs.end());
LoInputs.erase(std::unique(LoInputs.begin(), LoInputs.end()),
LoInputs.end());
LoInputs.erase(llvm::unique(LoInputs), LoInputs.end());
SmallVector<int, 4> HiInputs;
copy_if(Mask, std::back_inserter(HiInputs), [](int M) { return M >= 8; });
array_pod_sort(HiInputs.begin(), HiInputs.end());
HiInputs.erase(std::unique(HiInputs.begin(), HiInputs.end()),
HiInputs.end());
HiInputs.erase(llvm::unique(HiInputs), HiInputs.end());

bool TargetLo = LoInputs.size() >= HiInputs.size();
ArrayRef<int> InPlaceInputs = TargetLo ? LoInputs : HiInputs;
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,8 @@ X86LoadValueInjectionLoadHardeningPass::getGadgetGraph(

// Remove duplicate transmitters
llvm::sort(DefTransmitters);
DefTransmitters.erase(
std::unique(DefTransmitters.begin(), DefTransmitters.end()),
DefTransmitters.end());
DefTransmitters.erase(llvm::unique(DefTransmitters),
DefTransmitters.end());
};

// Find all of the transmitters
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/X86/X86SpeculativeLoadHardening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,7 @@ X86SpeculativeLoadHardeningPass::tracePredStateThroughCFG(

// Sort and unique the codes to minimize them.
llvm::sort(UncondCodeSeq);
UncondCodeSeq.erase(std::unique(UncondCodeSeq.begin(), UncondCodeSeq.end()),
UncondCodeSeq.end());
UncondCodeSeq.erase(llvm::unique(UncondCodeSeq), UncondCodeSeq.end());

// Build a checking version of the successor.
BuildCheckingBlockForSuccAndConds(MBB, *UncondSucc, /*SuccCount*/ 1,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static bool replaceConstantExprOp(ConstantExpr *CE, Pass *P) {
do {
SmallVector<WeakTrackingVH, 8> WUsers(CE->users());
llvm::sort(WUsers);
WUsers.erase(std::unique(WUsers.begin(), WUsers.end()), WUsers.end());
WUsers.erase(llvm::unique(WUsers), WUsers.end());
while (!WUsers.empty())
if (WeakTrackingVH WU = WUsers.pop_back_val()) {
if (PHINode *PN = dyn_cast<PHINode>(WU)) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {

// Make a strictly ascending list of offsets as required by addAccess()
llvm::sort(Offsets);
auto *Last = std::unique(Offsets.begin(), Offsets.end());
auto *Last = llvm::unique(Offsets);
Offsets.erase(Last, Offsets.end());

VectorType *VT = dyn_cast<VectorType>(&Ty);
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ bool PlaceSafepointsPass::runImpl(Function &F, const TargetLibraryInfo &TLI) {
// We can sometimes end up with duplicate poll locations. This happens if
// a single loop is visited more than once. The fact this happens seems
// wrong, but it does happen for the split-backedge.ll test case.
PollLocations.erase(std::unique(PollLocations.begin(), PollLocations.end()),
PollLocations.end());
PollLocations.erase(llvm::unique(PollLocations), PollLocations.end());

// Insert a poll at each point the analysis pass identified
// The poll location must be the terminator of a loop latch block.
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Scalar/Reassociate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,10 +1815,10 @@ ReassociatePass::buildMinimalMultiplyDAG(IRBuilderBase &Builder,
}
// Unique factors with equal powers -- we've folded them into the first one's
// base.
Factors.erase(std::unique(Factors.begin(), Factors.end(),
[](const Factor &LHS, const Factor &RHS) {
return LHS.Power == RHS.Power;
}),
Factors.erase(llvm::unique(Factors,
[](const Factor &LHS, const Factor &RHS) {
return LHS.Power == RHS.Power;
}),
Factors.end());

// Iteratively collect the base of each factor with an add power into the
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ static void relocationViaAlloca(
}

llvm::sort(Uses);
auto Last = std::unique(Uses.begin(), Uses.end());
auto Last = llvm::unique(Uses);
Uses.erase(Last, Uses.end());

for (Instruction *Use : Uses) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2178,8 +2178,7 @@ checkVectorTypesForPromotion(Partition &P, const DataLayout &DL,
cast<FixedVectorType>(LHSTy)->getNumElements();
};
llvm::sort(CandidateTys, RankVectorTypesComp);
CandidateTys.erase(std::unique(CandidateTys.begin(), CandidateTys.end(),
RankVectorTypesEq),
CandidateTys.erase(llvm::unique(CandidateTys, RankVectorTypesEq),
CandidateTys.end());
} else {
// The only way to have the same element type in every vector type is to
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4905,7 +4905,7 @@ bool SimplifyCFGOpt::SimplifyBranchOnICmpChain(BranchInst *BI,
// There might be duplicate constants in the list, which the switch
// instruction can't handle, remove them now.
array_pod_sort(Values.begin(), Values.end(), ConstantIntSortPredicate);
Values.erase(std::unique(Values.begin(), Values.end()), Values.end());
Values.erase(llvm::unique(Values), Values.end());

// If Extra was used, we require at least two switch values to do the
// transformation. A switch with one value is just a conditional branch.
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static void filterByAccelName(
getDies(DICtx, DICtx.getDebugNames(), Name, Dies);
}
llvm::sort(Dies);
Dies.erase(std::unique(Dies.begin(), Dies.end()), Dies.end());
Dies.erase(llvm::unique(Dies), Dies.end());

DIDumpOptions DumpOpts = getDumpOpts(DICtx);
DumpOpts.GetNameForDWARFReg = GetNameForDWARFReg;
Expand Down Expand Up @@ -646,7 +646,7 @@ static bool collectObjectSources(ObjectFile &Obj, DWARFContext &DICtx,

// Dedup and order the sources.
llvm::sort(Sources);
Sources.erase(std::unique(Sources.begin(), Sources.end()), Sources.end());
Sources.erase(llvm::unique(Sources), Sources.end());

for (StringRef Name : Sources)
OS << Name << "\n";
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-nm/llvm-nm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2395,8 +2395,7 @@ exportSymbolNamesFromFiles(const std::vector<std::string> &InputFilenames) {
llvm::erase_if(SymbolList,
[](const NMSymbol &s) { return !s.shouldPrint(); });
sortSymbolList(SymbolList);
SymbolList.erase(std::unique(SymbolList.begin(), SymbolList.end()),
SymbolList.end());
SymbolList.erase(llvm::unique(SymbolList), SymbolList.end());
printExportSymbolList(SymbolList);
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,8 +1570,7 @@ static void addSymbolizer(
LabelAddrs.insert(LabelAddrs.end(), LabelAddrsRef.begin(),
LabelAddrsRef.end());
llvm::sort(LabelAddrs);
LabelAddrs.resize(std::unique(LabelAddrs.begin(), LabelAddrs.end()) -
LabelAddrs.begin());
LabelAddrs.resize(llvm::unique(LabelAddrs) - LabelAddrs.begin());
// Add the labels.
for (unsigned LabelNum = 0; LabelNum != LabelAddrs.size(); ++LabelNum) {
auto Name = std::make_unique<std::string>();
Expand Down

0 comments on commit 7c6d0d2

Please sign in to comment.