Skip to content

Commit 1cc07a0

Browse files
[mlir] Use *Set::insert_range (NFC) (#133043)
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration.
1 parent 40d251d commit 1cc07a0

File tree

15 files changed

+23
-51
lines changed

15 files changed

+23
-51
lines changed

mlir/include/mlir/Dialect/Tosa/IR/TargetEnv.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ class TargetEnv {
2727
TargetEnv() {}
2828
explicit TargetEnv(const SmallVectorImpl<Profile> &profiles,
2929
const SmallVectorImpl<Extension> &extensions) {
30-
for (Profile prof : profiles)
31-
enabledProfiles.insert(prof);
30+
enabledProfiles.insert_range(profiles);
3231

33-
for (Extension ext : extensions)
34-
enabledExtensions.insert(ext);
32+
enabledExtensions.insert_range(extensions);
3533
}
3634

3735
void addProfile(Profile p) { enabledProfiles.insert(p); }

mlir/lib/Analysis/Liveness.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,11 @@ struct BlockInfoBuilder {
6868
// operands as used. All defined value will be removed from the used set
6969
// at the end.
7070
block->walk([&](Operation *op) {
71-
for (Value result : op->getResults())
72-
defValues.insert(result);
73-
for (Value operand : op->getOperands())
74-
useValues.insert(operand);
71+
defValues.insert_range(op->getResults());
72+
useValues.insert_range(op->getOperands());
7573
for (Region &region : op->getRegions())
7674
for (Block &child : region.getBlocks())
77-
for (BlockArgument arg : child.getArguments())
78-
defValues.insert(arg);
75+
defValues.insert_range(child.getArguments());
7976
});
8077
llvm::set_subtract(useValues, defValues);
8178
}

mlir/lib/Analysis/TopologicalSortUtils.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,8 @@ bool mlir::computeTopologicalSorting(
116116
return true;
117117

118118
// The set of operations that have not yet been scheduled.
119-
DenseSet<Operation *> unscheduledOps;
120-
121119
// Mark all operations as unscheduled.
122-
for (Operation *op : ops)
123-
unscheduledOps.insert(op);
120+
DenseSet<Operation *> unscheduledOps(llvm::from_range, ops);
124121

125122
unsigned nextScheduledOp = 0;
126123

mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ transform::CastAndCallOp::apply(transform::TransformRewriter &rewriter,
5151

5252
SetVector<Value> outputs;
5353
if (getOutputs()) {
54-
for (auto output : state.getPayloadValues(getOutputs()))
55-
outputs.insert(output);
54+
outputs.insert_range(state.getPayloadValues(getOutputs()));
5655

5756
// Verify that the set of output values to be replaced is unique.
5857
if (outputs.size() !=

mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,7 @@ static bool memcpyCanRewire(MemcpyLike op, const DestructurableMemorySlot &slot,
13451345
return false;
13461346

13471347
if (op.getSrc() == slot.ptr)
1348-
for (Attribute index : llvm::make_first_range(slot.subelementTypes))
1349-
usedIndices.insert(index);
1348+
usedIndices.insert_range(llvm::make_first_range(slot.subelementTypes));
13501349

13511350
return true;
13521351
}

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4390,9 +4390,7 @@ static bool isInvalidPackingPosSpecification(ArrayRef<int64_t> dimsPos,
43904390
size_t dimsPosSize = dimsPos.size();
43914391
if (dimsPosSize > rank)
43924392
return true;
4393-
DenseSet<int64_t> uniqued;
4394-
for (int64_t dim : dimsPos)
4395-
uniqued.insert(dim);
4393+
DenseSet<int64_t> uniqued(llvm::from_range, dimsPos);
43964394
if (dimsPosSize != uniqued.size())
43974395
return true;
43984396
return llvm::any_of(dimsPos, [rank](int64_t dimPos) {

mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,7 @@ struct LinalgDetensorize
458458
});
459459

460460
for (Block &block : llvm::drop_begin(func.getFunctionBody(), 1))
461-
for (BlockArgument blockArgument : block.getArguments())
462-
blockArgsToDetensor.insert(blockArgument);
461+
blockArgsToDetensor.insert_range(block.getArguments());
463462
}
464463
};
465464

mlir/lib/Dialect/MLProgram/Transforms/PipelineGlobalOps.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,9 @@ LogicalResult MLProgramPipelineGlobals::buildGlobalMap(ModuleOp module) {
104104
work.push_back(symbol);
105105
});
106106

107-
for (auto load : opLoadSymbols[work[i]])
108-
loadSymbols.insert(load);
107+
loadSymbols.insert_range(opLoadSymbols[work[i]]);
109108

110-
for (auto store : opStoreSymbols[work[i]])
111-
storeSymbols.insert(store);
109+
storeSymbols.insert_range(opStoreSymbols[work[i]]);
112110
}
113111

114112
loadSymbolsMap[thisSymbol] = std::move(loadSymbols);

mlir/lib/Dialect/SCF/IR/SCF.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,9 +4052,7 @@ struct WhileRemoveDuplicatedResults : public OpRewritePattern<WhileOp> {
40524052
ConditionOp condOp = op.getConditionOp();
40534053
ValueRange condOpArgs = condOp.getArgs();
40544054

4055-
llvm::SmallPtrSet<Value, 8> argsSet;
4056-
for (Value arg : condOpArgs)
4057-
argsSet.insert(arg);
4055+
llvm::SmallPtrSet<Value, 8> argsSet(llvm::from_range, condOpArgs);
40584056

40594057
if (argsSet.size() == condOpArgs.size())
40604058
return rewriter.notifyMatchFailure(op, "No results to remove");

mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ bool LoopPipelinerInternal::initializeLoopInfo(
207207
static SetVector<Value> getNestedOperands(Operation *op) {
208208
SetVector<Value> operands;
209209
op->walk([&](Operation *nestedOp) {
210-
for (Value operand : nestedOp->getOperands()) {
211-
operands.insert(operand);
212-
}
210+
operands.insert_range(nestedOp->getOperands());
213211
});
214212
return operands;
215213
}

0 commit comments

Comments
 (0)