Skip to content

Commit 89d8035

Browse files
committed
Use llvm::append_range where applicable
It knows the size, so no need to call reserve beforehand. NFCI.
1 parent 5dde9c1 commit 89d8035

File tree

9 files changed

+20
-54
lines changed

9 files changed

+20
-54
lines changed

mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@ Type LLVMTypeConverter::convertFunctionSignature(
220220
result.addInputs(en.index(), converted);
221221
}
222222

223-
SmallVector<Type, 8> argTypes;
224-
argTypes.reserve(llvm::size(result.getConvertedTypes()));
225-
for (Type type : result.getConvertedTypes())
226-
argTypes.push_back(type);
227-
228223
// If function does not return anything, create the void result type,
229224
// if it returns on element, convert it, otherwise pack the result types into
230225
// a struct.
@@ -233,7 +228,8 @@ Type LLVMTypeConverter::convertFunctionSignature(
233228
: packFunctionResults(funcTy.getResults());
234229
if (!resultType)
235230
return {};
236-
return LLVM::LLVMFunctionType::get(resultType, argTypes, isVariadic);
231+
return LLVM::LLVMFunctionType::get(resultType, result.getConvertedTypes(),
232+
isVariadic);
237233
}
238234

239235
/// Converts the function type to a C-compatible format, in particular using

mlir/lib/Dialect/Affine/Analysis/Utils.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,22 +1218,14 @@ MemRefAccess::MemRefAccess(Operation *loadOrStoreOpInst) {
12181218
if (auto loadOp = dyn_cast<AffineReadOpInterface>(loadOrStoreOpInst)) {
12191219
memref = loadOp.getMemRef();
12201220
opInst = loadOrStoreOpInst;
1221-
auto loadMemrefType = loadOp.getMemRefType();
1222-
indices.reserve(loadMemrefType.getRank());
1223-
for (auto index : loadOp.getMapOperands()) {
1224-
indices.push_back(index);
1225-
}
1221+
llvm::append_range(indices, loadOp.getMapOperands());
12261222
} else {
12271223
assert(isa<AffineWriteOpInterface>(loadOrStoreOpInst) &&
12281224
"Affine read/write op expected");
12291225
auto storeOp = cast<AffineWriteOpInterface>(loadOrStoreOpInst);
12301226
opInst = loadOrStoreOpInst;
12311227
memref = storeOp.getMemRef();
1232-
auto storeMemrefType = storeOp.getMemRefType();
1233-
indices.reserve(storeMemrefType.getRank());
1234-
for (auto index : storeOp.getMapOperands()) {
1235-
indices.push_back(index);
1236-
}
1228+
llvm::append_range(indices, storeOp.getMapOperands());
12371229
}
12381230
}
12391231

mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,8 @@ struct MemRefDependenceGraph {
527527
void addToNode(unsigned id, const SmallVectorImpl<Operation *> &loads,
528528
const SmallVectorImpl<Operation *> &stores) {
529529
Node *node = getNode(id);
530-
for (auto *loadOpInst : loads)
531-
node->loads.push_back(loadOpInst);
532-
for (auto *storeOpInst : stores)
533-
node->stores.push_back(storeOpInst);
530+
llvm::append_range(node->loads, loads);
531+
llvm::append_range(node->stores, stores);
534532
}
535533

536534
void clearNodeLoadAndStores(unsigned id) {

mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,9 +2660,7 @@ static AffineIfOp createSeparationCondition(MutableArrayRef<AffineForOp> loops,
26602660

26612661
FlatAffineValueConstraints cst;
26622662
SmallVector<Operation *, 8> ops;
2663-
ops.reserve(loops.size());
2664-
for (AffineForOp forOp : loops)
2665-
ops.push_back(forOp);
2663+
llvm::append_range(ops, loops);
26662664
(void)getIndexSet(ops, &cst);
26672665

26682666
// Remove constraints that are independent of these loop IVs.

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,11 @@ struct LinalgDetensorize : public LinalgDetensorizeBase<LinalgDetensorize> {
256256
SmallVector<Value> workList;
257257

258258
func->walk([&](cf::CondBranchOp condBr) {
259-
for (auto operand : condBr.getOperands()) {
260-
workList.push_back(operand);
261-
}
259+
llvm::append_range(workList, condBr.getOperands());
262260
});
263261

264262
func->walk([&](cf::BranchOp br) {
265-
for (auto operand : br.getOperands()) {
266-
workList.push_back(operand);
267-
}
263+
llvm::append_range(workList, br.getOperands());
268264
});
269265

270266
DenseSet<Value> visitedValues;
@@ -310,8 +306,7 @@ struct LinalgDetensorize : public LinalgDetensorizeBase<LinalgDetensorize> {
310306
// detensorable and if so, their operands will be added to workList to
311307
// potentially discover other parts of the detensorable component.
312308
for (auto *user : currentItem.getUsers())
313-
for (Value result : user->getResults())
314-
workList.push_back(result);
309+
llvm::append_range(workList, user->getResults());
315310

316311
// 2 - Look backward:
317312
// 2.1 - The current item is defined by a block argument. If the owner
@@ -383,10 +378,7 @@ struct LinalgDetensorize : public LinalgDetensorizeBase<LinalgDetensorize> {
383378
}
384379

385380
opsToDetensor.insert(genericOp);
386-
387-
for (Value genericOpOperand : genericOp.inputs())
388-
workList.push_back(genericOpOperand);
389-
381+
llvm::append_range(workList, genericOp.inputs());
390382
continue;
391383
}
392384

@@ -405,8 +397,7 @@ struct LinalgDetensorize : public LinalgDetensorizeBase<LinalgDetensorize> {
405397
if (llvm::all_of(
406398
currentItemDefiningOp->getResultTypes(),
407399
[&](Type resultType) { return resultType.isIntOrFloat(); }))
408-
for (Value scalarOpOperand : currentItemDefiningOp->getOperands())
409-
workList.push_back(scalarOpOperand);
400+
llvm::append_range(workList, currentItemDefiningOp->getOperands());
410401
}
411402

412403
// Since the cost model gives up on some ops (see the details of step 2.2

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static Value genAllocaScalar(ConversionPatternRewriter &rewriter, Location loc,
177177

178178
/// Generates a temporary buffer of the given type and given contents.
179179
static Value genBuffer(ConversionPatternRewriter &rewriter, Location loc,
180-
ArrayRef<Value> values) {
180+
ValueRange values) {
181181
unsigned sz = values.size();
182182
assert(sz >= 1);
183183
Value buffer = genAlloca(rewriter, loc, sz, values[0].getType());
@@ -205,10 +205,7 @@ static void newParams(ConversionPatternRewriter &rewriter,
205205
params.push_back(genBuffer(rewriter, loc, attrs));
206206
// Dimension sizes array of the enveloping tensor. Useful for either
207207
// verification of external data, or for construction of internal data.
208-
SmallVector<Value, 4> sizes;
209-
for (Value s : szs)
210-
sizes.push_back(s);
211-
params.push_back(genBuffer(rewriter, loc, sizes));
208+
params.push_back(genBuffer(rewriter, loc, szs));
212209
// Dimension order permutation array. This is the "identity" permutation by
213210
// default, or otherwise the "reverse" permutation of a given ordering, so
214211
// that indices can be mapped quickly to the right position.

mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ Optional<SmallVector<ReassociationIndices>> mlir::composeReassociationIndices(
116116
for (ReassociationIndicesRef consumerIndices : consumerReassociations) {
117117
ReassociationIndices reassociations;
118118
for (int64_t consumerIndex : consumerIndices) {
119-
for (int64_t producerIndex : producerReassociations[consumerIndex])
120-
reassociations.push_back(producerIndex);
119+
llvm::append_range(reassociations, producerReassociations[consumerIndex]);
121120
}
122121
composedIndices.push_back(std::move(reassociations));
123122
}

mlir/lib/IR/AffineMap.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,19 +727,16 @@ AffineMap mlir::getProjectedMap(AffineMap map,
727727
//===----------------------------------------------------------------------===//
728728

729729
MutableAffineMap::MutableAffineMap(AffineMap map)
730-
: numDims(map.getNumDims()), numSymbols(map.getNumSymbols()),
731-
context(map.getContext()) {
732-
for (auto result : map.getResults())
733-
results.push_back(result);
734-
}
730+
: results(map.getResults().begin(), map.getResults().end()),
731+
numDims(map.getNumDims()), numSymbols(map.getNumSymbols()),
732+
context(map.getContext()) {}
735733

736734
void MutableAffineMap::reset(AffineMap map) {
737735
results.clear();
738736
numDims = map.getNumDims();
739737
numSymbols = map.getNumSymbols();
740738
context = map.getContext();
741-
for (auto result : map.getResults())
742-
results.push_back(result);
739+
llvm::append_range(results, map.getResults());
743740
}
744741

745742
bool MutableAffineMap::isMultipleOf(unsigned idx, int64_t factor) const {

mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
303303
// TODO: refactor function type creation which usually occurs in std-LLVM
304304
// conversion.
305305
SmallVector<Type, 8> operandTypes;
306-
operandTypes.reserve(inlineAsmOp.getOperands().size());
307-
for (auto t : inlineAsmOp.getOperands().getTypes())
308-
operandTypes.push_back(t);
306+
llvm::append_range(operandTypes, inlineAsmOp.getOperands().getTypes());
309307

310308
Type resultType;
311309
if (inlineAsmOp.getNumResults() == 0) {

0 commit comments

Comments
 (0)