Skip to content

[Transforms] Use range constructors of *Set (NFC) #133203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/ExtractGV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void makeVisible(GlobalValue &GV, bool Delete) {
/// global values specified.
ExtractGVPass::ExtractGVPass(std::vector<GlobalValue *> &GVs, bool deleteS,
bool keepConstInit)
: Named(GVs.begin(), GVs.end()), deleteStuff(deleteS),
: Named(llvm::from_range, GVs), deleteStuff(deleteS),
keepConstInit(keepConstInit) {}

PreservedAnalyses ExtractGVPass::run(Module &M, ModuleAnalysisManager &) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/GlobalOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,10 +2319,10 @@ class LLVMUsed {
LLVMUsed(Module &M) {
SmallVector<GlobalValue *, 4> Vec;
UsedV = collectUsedGlobalVariables(M, Vec, false);
Used = {Vec.begin(), Vec.end()};
Used = {llvm::from_range, Vec};
Vec.clear();
CompilerUsedV = collectUsedGlobalVariables(M, Vec, true);
CompilerUsed = {Vec.begin(), Vec.end()};
CompilerUsed = {llvm::from_range, Vec};
}

using iterator = SmallPtrSet<GlobalValue *, 4>::iterator;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5874,7 +5874,7 @@ PreservedAnalyses OpenMPOptCGSCCPass::run(LazyCallGraph::SCC &C,
bool PostLink = LTOPhase == ThinOrFullLTOPhase::FullLTOPostLink ||
LTOPhase == ThinOrFullLTOPhase::ThinLTOPostLink ||
LTOPhase == ThinOrFullLTOPhase::ThinLTOPreLink;
SetVector<Function *> Functions(SCC.begin(), SCC.end());
SetVector<Function *> Functions(llvm::from_range, SCC);
OMPInformationCache InfoCache(*(Functions.back()->getParent()), AG, Allocator,
/*CGSCC*/ &Functions, PostLink);

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,8 +1591,7 @@ bool GVNPass::PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
// that we only have to insert *one* load (which means we're basically moving
// the load, not inserting a new one).

SmallPtrSet<BasicBlock *, 4> Blockers(UnavailableBlocks.begin(),
UnavailableBlocks.end());
SmallPtrSet<BasicBlock *, 4> Blockers(llvm::from_range, UnavailableBlocks);

// Let's find the first basic block with more than one predecessor. Walk
// backwards through predecessors if needed.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/GVNSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class GVNSink {

unsigned NumSunk = 0;
ReversePostOrderTraversal<Function*> RPOT(&F);
VN.setReachableBBs(BasicBlocksSet(RPOT.begin(), RPOT.end()));
VN.setReachableBBs(BasicBlocksSet(llvm::from_range, RPOT));
// Populate reverse post-order to order basic blocks in deterministic
// order. Any arbitrary ordering will work in this case as long as they are
// deterministic. The node ordering of newly created basic blocks
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ void InferAddressSpacesImpl::inferAddressSpaces(
ArrayRef<WeakTrackingVH> Postorder,
ValueToAddrSpaceMapTy &InferredAddrSpace,
PredicatedAddrSpaceMapTy &PredicatedAS) const {
SetVector<Value *> Worklist(Postorder.begin(), Postorder.end());
SetVector<Value *> Worklist(llvm::from_range, Postorder);
// Initially, all expressions are in the uninitialized address space.
for (Value *V : Postorder)
InferredAddrSpace[V] = UninitializedAddressSpace;
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Transforms/Scalar/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1564,8 +1564,7 @@ static void splitPredecessorsOfLoopExit(PHINode *PN, DominatorTree *DT,
#ifndef NDEBUG
SmallVector<BasicBlock *, 32> ExitBlocks;
CurLoop->getUniqueExitBlocks(ExitBlocks);
SmallPtrSet<BasicBlock *, 32> ExitBlockSet(ExitBlocks.begin(),
ExitBlocks.end());
SmallPtrSet<BasicBlock *, 32> ExitBlockSet(llvm::from_range, ExitBlocks);
#endif
BasicBlock *ExitBB = PN->getParent();
assert(ExitBlockSet.count(ExitBB) && "Expect the PHI is in an exit block.");
Expand Down Expand Up @@ -1699,8 +1698,7 @@ static bool sink(Instruction &I, LoopInfo *LI, DominatorTree *DT,
#ifndef NDEBUG
SmallVector<BasicBlock *, 32> ExitBlocks;
CurLoop->getUniqueExitBlocks(ExitBlocks);
SmallPtrSet<BasicBlock *, 32> ExitBlockSet(ExitBlocks.begin(),
ExitBlocks.end());
SmallPtrSet<BasicBlock *, 32> ExitBlockSet(llvm::from_range, ExitBlocks);
#endif

// Clones of this instruction. Don't create more than one per exit block!
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void llvm::DeleteDeadBlocks(ArrayRef <BasicBlock *> BBs, DomTreeUpdater *DTU,
bool KeepOneInputPHIs) {
#ifndef NDEBUG
// Make sure that all predecessors of each dead block is also dead.
SmallPtrSet<BasicBlock *, 4> Dead(BBs.begin(), BBs.end());
SmallPtrSet<BasicBlock *, 4> Dead(llvm::from_range, BBs);
assert(Dead.size() == BBs.size() && "Duplicating blocks?");
for (auto *BB : Dead)
for (BasicBlock *Pred : predecessors(BB))
Expand Down Expand Up @@ -1261,7 +1261,7 @@ static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
ArrayRef<BasicBlock *> Preds, BranchInst *BI,
bool HasLoopExit) {
// Otherwise, create a new PHI node in NewBB for each PHI node in OrigBB.
SmallPtrSet<BasicBlock *, 16> PredSet(Preds.begin(), Preds.end());
SmallPtrSet<BasicBlock *, 16> PredSet(llvm::from_range, Preds);
for (BasicBlock::iterator I = OrigBB->begin(); isa<PHINode>(I); ) {
PHINode *PN = cast<PHINode>(I++);

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) {
SmallVector<std::string, 8> Mappings;
VFABI::getVectorVariantNames(CI, Mappings);
Module *M = CI.getModule();
const SetVector<StringRef> OriginalSetOfMappings(Mappings.begin(),
Mappings.end());
const SetVector<StringRef> OriginalSetOfMappings(llvm::from_range, Mappings);

auto AddVariantDecl = [&](const ElementCount &VF, bool Predicate) {
const VecDesc *VD = TLI.getVectorMappingInfo(ScalarName, VF, Predicate);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,8 @@ void PromoteMem2Reg::run() {
AllocaLookup[Allocas[AllocaNum]] = AllocaNum;

// Unique the set of defining blocks for efficient lookup.
SmallPtrSet<BasicBlock *, 32> DefBlocks(Info.DefiningBlocks.begin(),
Info.DefiningBlocks.end());
SmallPtrSet<BasicBlock *, 32> DefBlocks(llvm::from_range,
Info.DefiningBlocks);

// Determine which blocks the value is live in. These are blocks which lead
// to uses.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2389,8 +2389,8 @@ void SCEVExpanderCleaner::cleanup() {

auto InsertedInstructions = Expander.getAllInsertedInstructions();
#ifndef NDEBUG
SmallPtrSet<Instruction *, 8> InsertedSet(InsertedInstructions.begin(),
InsertedInstructions.end());
SmallPtrSet<Instruction *, 8> InsertedSet(llvm::from_range,
InsertedInstructions);
(void)InsertedSet;
#endif
// Remove sets with value handles.
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 @@ -2721,7 +2721,7 @@ bool CompatibleSets::shouldBelongToSameSet(ArrayRef<InvokeInst *> Invokes) {

// In the normal destination, the incoming values for these two `invoke`s
// must be compatible.
SmallPtrSet<Value *, 16> EquivalenceSet(Invokes.begin(), Invokes.end());
SmallPtrSet<Value *, 16> EquivalenceSet(llvm::from_range, Invokes);
if (!incomingValuesAreCompatible(
NormalBB, {Invokes[0]->getParent(), Invokes[1]->getParent()},
&EquivalenceSet))
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7325,8 +7325,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
continue;

const auto &ChainOps = RdxDesc.getReductionOpChain(RedPhi, OrigLoop);
SetVector<Instruction *> ChainOpsAndOperands(ChainOps.begin(),
ChainOps.end());
SetVector<Instruction *> ChainOpsAndOperands(llvm::from_range, ChainOps);
auto IsZExtOrSExt = [](const unsigned Opcode) -> bool {
return Opcode == Instruction::ZExt || Opcode == Instruction::SExt;
};
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ class BoUpSLP {

auto CheckSameEntryOrFail = [&]() {
if (ArrayRef<TreeEntry *> TEs1 = R.getTreeEntries(V1); !TEs1.empty()) {
SmallPtrSet<TreeEntry *, 4> Set(TEs1.begin(), TEs1.end());
SmallPtrSet<TreeEntry *, 4> Set(llvm::from_range, TEs1);
if (ArrayRef<TreeEntry *> TEs2 = R.getTreeEntries(V2);
!TEs2.empty() &&
any_of(TEs2, [&](TreeEntry *E) { return Set.contains(E); }))
Expand Down Expand Up @@ -8938,7 +8938,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
}
return;
}
SmallPtrSet<Value *, 8> Values(E->Scalars.begin(), E->Scalars.end());
SmallPtrSet<Value *, 8> Values(llvm::from_range, E->Scalars);
if (all_of(VL, [&](Value *V) {
return isa<PoisonValue>(V) || Values.contains(V);
})) {
Expand Down Expand Up @@ -9038,8 +9038,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
SmallBitVector OpcodeMask(getAltInstrMask(VL, Opcode0, Opcode1));
// Enable split node, only if all nodes do not form legal alternate
// instruction (like X86 addsub).
SmallPtrSet<Value *, 4> UOp1(Op1.begin(), Op1.end());
SmallPtrSet<Value *, 4> UOp2(Op2.begin(), Op2.end());
SmallPtrSet<Value *, 4> UOp1(llvm::from_range, Op1);
SmallPtrSet<Value *, 4> UOp2(llvm::from_range, Op2);
if (UOp1.size() <= 1 || UOp2.size() <= 1 ||
TTI.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask) ||
!hasFullVectorsOrPowerOf2(TTI, Op1.front()->getType(), Op1.size()) ||
Expand Down Expand Up @@ -14265,7 +14265,7 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
return std::nullopt;
auto *NodeUI = DT->getNode(TEInsertBlock);
assert(NodeUI && "Should only process reachable instructions");
SmallPtrSet<Value *, 4> GatheredScalars(VL.begin(), VL.end());
SmallPtrSet<Value *, 4> GatheredScalars(llvm::from_range, VL);
auto CheckOrdering = [&](const Instruction *InsertPt) {
// Argument InsertPt is an instruction where vector code for some other
// tree entry (one that shares one or more scalars with TE) is going to be
Expand Down Expand Up @@ -21455,7 +21455,7 @@ class HorizontalReduction {
}
}
V.transformNodes();
SmallPtrSet<Value *, 4> VLScalars(VL.begin(), VL.end());
SmallPtrSet<Value *, 4> VLScalars(llvm::from_range, VL);
// Gather externally used values.
SmallPtrSet<Value *, 4> Visited;
for (unsigned Cnt = 0; Cnt < NumReducedVals; ++Cnt) {
Expand Down Expand Up @@ -23343,7 +23343,7 @@ bool SLPVectorizerPass::vectorizeGEPIndices(BasicBlock *BB, BoUpSLP &R) {
// SetVector here to preserve program order. If the index computations
// are vectorizable and begin with loads, we want to minimize the chance
// of having to reorder them later.
SetVector<Value *> Candidates(GEPList.begin(), GEPList.end());
SetVector<Value *> Candidates(llvm::from_range, GEPList);

// Some of the candidates may have already been vectorized after we
// initially collected them or their index is optimized to constant value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const LegalityResult &LegalityAnalysis::canVectorize(ArrayRef<Value *> Bndl,
[BB](auto *V) { return cast<Instruction>(V)->getParent() != BB; }))
return createLegalityResult<Pack>(ResultReason::DiffBBs);
// Pack if instructions repeat, i.e., require some sort of broadcast.
SmallPtrSet<Value *, 8> Unique(Bndl.begin(), Bndl.end());
SmallPtrSet<Value *, 8> Unique(llvm::from_range, Bndl);
if (Unique.size() != Bndl.size())
return createLegalityResult<Pack>(ResultReason::RepeatedInstrs);

Expand Down