Skip to content

Commit 7a300c4

Browse files
committed
[mlir] Use llvm::filter_to_vector. NFC.
This got recently added to SmallVectorExtras: #117460.
1 parent 2ed8c5d commit 7a300c4

File tree

9 files changed

+32
-37
lines changed

9 files changed

+32
-37
lines changed

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,9 @@ computeTargetSize(PatternRewriter &rewriter, Location loc, IndexPool &indexPool,
701701

702702
// Filter operands with dynamic dimension
703703
auto operandsWithDynamicDim =
704-
llvm::to_vector(llvm::make_filter_range(operands, [&](Value operand) {
704+
llvm::filter_to_vector(operands, [&](Value operand) {
705705
return cast<RankedTensorType>(operand.getType()).isDynamicDim(dim);
706-
}));
706+
});
707707

708708
// If no operand has a dynamic dimension, it means all sizes were 1
709709
if (operandsWithDynamicDim.empty())

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ SmallVector<Value> mlir::LLVM::MemsetInlineOp::getAccessedOperands() {
9999
}
100100

101101
SmallVector<Value> mlir::LLVM::CallOp::getAccessedOperands() {
102-
return llvm::to_vector(
103-
llvm::make_filter_range(getArgOperands(), [](Value arg) {
104-
return isa<LLVMPointerType>(arg.getType());
105-
}));
102+
return llvm::filter_to_vector(getArgOperands(), [](Value arg) {
103+
return isa<LLVMPointerType>(arg.getType());
104+
});
106105
}
107106

108107
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.cpp.inc"

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,8 @@ static void calculateTileOffsetsAndSizes(
375375
b.setInsertionPointToStart(forallOp.getBody(0));
376376

377377
SmallVector<Value> threadIds = forallOp.getInductionVars();
378-
SmallVector<OpFoldResult> nonZeroNumThreads =
379-
llvm::to_vector(llvm::make_filter_range(numThreads, [](OpFoldResult ofr) {
380-
return !isConstantIntValue(ofr, 0);
381-
}));
378+
SmallVector<OpFoldResult> nonZeroNumThreads = llvm::filter_to_vector(
379+
numThreads, [](OpFoldResult ofr) { return !isConstantIntValue(ofr, 0); });
382380
int64_t nLoops = loopRanges.size();
383381
tiledOffsets.reserve(nLoops);
384382
tiledSizes.reserve(nLoops);
@@ -656,10 +654,8 @@ FailureOr<linalg::ForallReductionTilingResult> linalg::tileReductionUsingForall(
656654

657655
Operation *tiledOp = nullptr;
658656

659-
SmallVector<OpFoldResult> nonZeroNumThreads =
660-
llvm::to_vector(llvm::make_filter_range(numThreads, [](OpFoldResult ofr) {
661-
return !isConstantIntValue(ofr, 0);
662-
}));
657+
SmallVector<OpFoldResult> nonZeroNumThreads = llvm::filter_to_vector(
658+
numThreads, [](OpFoldResult ofr) { return !isConstantIntValue(ofr, 0); });
663659
SmallVector<Value> materializedNonZeroNumThreads =
664660
getValueOrCreateConstantIndexOp(b, loc, nonZeroNumThreads);
665661

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,8 @@ getPackUnpackNormalizedPerm(int rank, ArrayRef<int64_t> perm) {
10901090
SmallVector<int64_t> vec(rank, kNonTiledMarker);
10911091
for (auto [index, value] : llvm::enumerate(perm))
10921092
vec[value] = index;
1093-
SmallVector<int64_t> normalizedPerm = llvm::to_vector(llvm::make_filter_range(
1094-
vec, [&](int64_t v) { return v != kNonTiledMarker; }));
1093+
SmallVector<int64_t> normalizedPerm = llvm::filter_to_vector(
1094+
vec, [&](int64_t v) { return v != kNonTiledMarker; });
10951095
// This inverts the permutation in addition to normalizing so invert back.
10961096
return invertPermutationVector(normalizedPerm);
10971097
}

mlir/lib/Dialect/Shape/IR/Shape.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,8 @@ struct RemoveEmptyShapeOperandsPattern : public OpRewritePattern<OpTy> {
695695
}
696696
return true;
697697
};
698-
auto newOperands = llvm::to_vector<8>(
699-
llvm::make_filter_range(op->getOperands(), isPotentiallyNonEmptyShape));
698+
auto newOperands = llvm::filter_to_vector<8>(op->getOperands(),
699+
isPotentiallyNonEmptyShape);
700700

701701
// Reduce op to equivalent without empty shape operands.
702702
if (newOperands.size() < op.getNumOperands()) {

mlir/lib/IR/Operation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,10 +1309,10 @@ LogicalResult OpTrait::impl::verifyNoRegionArguments(Operation *op) {
13091309

13101310
LogicalResult OpTrait::impl::verifyElementwise(Operation *op) {
13111311
auto isMappableType = llvm::IsaPred<VectorType, TensorType>;
1312-
auto resultMappableTypes = llvm::to_vector<1>(
1313-
llvm::make_filter_range(op->getResultTypes(), isMappableType));
1314-
auto operandMappableTypes = llvm::to_vector<2>(
1315-
llvm::make_filter_range(op->getOperandTypes(), isMappableType));
1312+
auto resultMappableTypes =
1313+
llvm::filter_to_vector<1>(op->getResultTypes(), isMappableType);
1314+
auto operandMappableTypes =
1315+
llvm::filter_to_vector<2>(op->getOperandTypes(), isMappableType);
13161316

13171317
// If the op only has scalar operand/result types, then we have nothing to
13181318
// check.

mlir/lib/IR/TypeUtilities.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ LogicalResult mlir::verifyCompatibleShapes(TypeRange types) {
141141
}
142142

143143
// Remove all unranked shapes
144-
auto shapes = llvm::to_vector<8>(llvm::make_filter_range(
145-
shapedTypes, [](auto shapedType) { return shapedType.hasRank(); }));
144+
auto shapes = llvm::filter_to_vector<8>(
145+
shapedTypes, [](auto shapedType) { return shapedType.hasRank(); });
146146
if (shapes.empty())
147147
return success();
148148

mlir/lib/Interfaces/DataLayoutInterfaces.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,11 @@ mlir::detail::getDevicePropertyValue(DataLayoutEntryInterface entry) {
304304
DataLayoutEntryList
305305
mlir::detail::filterEntriesForType(DataLayoutEntryListRef entries,
306306
TypeID typeID) {
307-
return llvm::to_vector<4>(llvm::make_filter_range(
307+
return llvm::filter_to_vector<4>(
308308
entries, [typeID](DataLayoutEntryInterface entry) {
309309
auto type = llvm::dyn_cast_if_present<Type>(entry.getKey());
310310
return type && type.getTypeID() == typeID;
311-
}));
311+
});
312312
}
313313

314314
DataLayoutEntryInterface
@@ -393,9 +393,9 @@ static DataLayoutSpecInterface getCombinedDataLayout(Operation *leaf) {
393393

394394
// Create the list of non-null specs (null/missing specs can be safely
395395
// ignored) from the outermost to the innermost.
396-
auto nonNullSpecs = llvm::to_vector<2>(llvm::make_filter_range(
396+
auto nonNullSpecs = llvm::filter_to_vector<2>(
397397
llvm::reverse(specs),
398-
[](DataLayoutSpecInterface iface) { return iface != nullptr; }));
398+
[](DataLayoutSpecInterface iface) { return iface != nullptr; });
399399

400400
// Combine the specs using the innermost as anchor.
401401
if (DataLayoutSpecInterface current = getSpec(leaf))

mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "mlir/TableGen/GenInfo.h"
1111
#include "llvm/ADT/MapVector.h"
1212
#include "llvm/ADT/STLExtras.h"
13+
#include "llvm/ADT/SmallVectorExtras.h"
1314
#include "llvm/Support/CommandLine.h"
1415
#include "llvm/Support/FormatVariadic.h"
1516
#include "llvm/TableGen/Error.h"
@@ -161,13 +162,12 @@ void printParseConditional(mlir::raw_indented_ostream &ios,
161162
return formatv("read{0}", capitalize(name));
162163
};
163164

164-
auto parsedArgs =
165-
llvm::to_vector(make_filter_range(args, [](const Init *const attr) {
166-
const Record *def = cast<DefInit>(attr)->getDef();
167-
if (def->isSubClassOf("Array"))
168-
return true;
169-
return !def->getValueAsString("cParser").empty();
170-
}));
165+
auto parsedArgs = llvm::filter_to_vector(args, [](const Init *const attr) {
166+
const Record *def = cast<DefInit>(attr)->getDef();
167+
if (def->isSubClassOf("Array"))
168+
return true;
169+
return !def->getValueAsString("cParser").empty();
170+
});
171171

172172
interleave(
173173
zip(parsedArgs, argNames),
@@ -277,8 +277,8 @@ void Generator::emitParseHelper(StringRef kind, StringRef returnType,
277277
printParseConditional(ios, args, argNames);
278278

279279
// Compute args to pass to create method.
280-
auto passedArgs = llvm::to_vector(make_filter_range(
281-
argNames, [](StringRef str) { return !str.starts_with("_"); }));
280+
auto passedArgs = llvm::filter_to_vector(
281+
argNames, [](StringRef str) { return !str.starts_with("_"); });
282282
std::string argStr;
283283
raw_string_ostream argStream(argStr);
284284
interleaveComma(passedArgs, argStream,

0 commit comments

Comments
 (0)