Use callables directly in any_of, count_if, etc (NFC)

This commit is contained in:
Kazu Hirata 2022-07-23 00:28:31 -07:00
parent 3ccd4ce29c
commit 380a1b204c
10 changed files with 13 additions and 27 deletions

View File

@ -368,9 +368,7 @@ int main(int argc, char **argv) {
printf("%06x: %s\n", static_cast<unsigned int>(Codepoint), Name.c_str());
T.insert(Name, Codepoint);
LongestName =
std::max(LongestName, std::size_t(llvm::count_if(Name, [](char c) {
return llvm::isAlnum(c);
})));
std::max(LongestName, std::size_t(llvm::count_if(Name, llvm::isAlnum)));
NameCount++;
}
T.compact();

View File

@ -53,9 +53,8 @@ MemRefDescriptor::fromStaticShape(OpBuilder &builder, Location loc,
assert(succeeded(result) && "unexpected failure in stride computation");
assert(!ShapedType::isDynamicStrideOrOffset(offset) &&
"expected static offset");
assert(!llvm::any_of(strides, [](int64_t stride) {
return ShapedType::isDynamicStrideOrOffset(stride);
}) && "expected static strides");
assert(!llvm::any_of(strides, ShapedType::isDynamicStrideOrOffset) &&
"expected static strides");
auto convertedType = typeConverter.convertType(type);
assert(convertedType && "unexpected failure in memref type conversion");

View File

@ -120,8 +120,7 @@ LogicalResult LLVM::detail::vectorOneToOneRewrite(
assert(!operands.empty());
// Cannot convert ops if their operands are not of LLVM type.
if (!llvm::all_of(operands.getTypes(),
[](Type t) { return isCompatibleType(t); }))
if (!llvm::all_of(operands.getTypes(), isCompatibleType))
return failure();
auto llvmNDVectorTy = operands[0].getType();

View File

@ -1840,9 +1840,8 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<memref::ViewOp> {
if (!ShapedType::isDynamic(shape[idx]))
return createIndexConstant(rewriter, loc, shape[idx]);
// Count the number of dynamic dims in range [0, idx]
unsigned nDynamic = llvm::count_if(shape.take_front(idx), [](int64_t v) {
return ShapedType::isDynamic(v);
});
unsigned nDynamic =
llvm::count_if(shape.take_front(idx), ShapedType::isDynamic);
return dynamicSizes[nDynamic];
}

View File

@ -948,9 +948,7 @@ public:
if (!targetStrides)
return failure();
// Only support static strides for now, regardless of contiguity.
if (llvm::any_of(*targetStrides, [](int64_t stride) {
return ShapedType::isDynamicStrideOrOffset(stride);
}))
if (llvm::any_of(*targetStrides, ShapedType::isDynamicStrideOrOffset))
return failure();
auto int64Ty = IntegerType::get(rewriter.getContext(), 64);

View File

@ -21,9 +21,7 @@ static bool hasFullyDynamicLayoutMap(MemRefType type) {
SmallVector<int64_t, 4> strides;
if (failed(getStridesAndOffset(type, strides, offset)))
return false;
if (!llvm::all_of(strides, [](int64_t stride) {
return ShapedType::isDynamicStrideOrOffset(stride);
}))
if (!llvm::all_of(strides, ShapedType::isDynamicStrideOrOffset))
return false;
if (!ShapedType::isDynamicStrideOrOffset(offset))
return false;

View File

@ -427,8 +427,7 @@ mlir::linalg::LinalgPaddingPattern::returningMatchAndRewrite(
continue;
// Fail hoisting if the operand shape is not fully static.
if (llvm::any_of(paddedOp.getShape(opOperand),
[](int64_t size) { return ShapedType::isDynamic(size); }))
if (llvm::any_of(paddedOp.getShape(opOperand), ShapedType::isDynamic))
return failure();
tensor::PadOp hoistedOp;

View File

@ -31,9 +31,8 @@ struct Conv2DIsFullyConnected : public OpRewritePattern<tosa::Conv2DOp> {
ShapedType weightType = weight.getType().cast<ShapedType>();
ShapedType resultType = op.getType().cast<ShapedType>();
auto numDynamic = llvm::count_if(inputType.getShape(), [](int64_t d) {
return ShapedType::isDynamic(d);
});
auto numDynamic =
llvm::count_if(inputType.getShape(), ShapedType::isDynamic);
if (numDynamic > 1)
return rewriter.notifyMatchFailure(
op, "at most one dim in input may be dynamic");

View File

@ -100,10 +100,7 @@ bool ShapeAdaptor::hasStaticShape() const {
return true;
}
auto *stc = val.get<ShapedTypeComponents *>();
for (int64_t dim : stc->getDims())
if (ShapedType::isDynamic(dim))
return false;
return true;
return llvm::none_of(stc->getDims(), ShapedType::isDynamic);
}
int64_t ShapeAdaptor::getNumElements() const {

View File

@ -225,7 +225,7 @@ Token Lexer::lexBareIdentifierOrKeyword(const char *tokStart) {
StringRef spelling(tokStart, curPtr - tokStart);
auto isAllDigit = [](StringRef str) {
return llvm::all_of(str, [](char c) { return llvm::isDigit(c); });
return llvm::all_of(str, llvm::isDigit);
};
// Check for i123, si456, ui789.