[Mlir-commits] [mlir] 380a1b2 - Use callables directly in any_of, count_if, etc (NFC)

Kazu Hirata llvmlistbot at llvm.org
Sat Jul 23 00:28:41 PDT 2022


Author: Kazu Hirata
Date: 2022-07-23T00:28:31-07:00
New Revision: 380a1b204c36cc8c6fdf28618d8a838aed8b7197

URL: https://github.com/llvm/llvm-project/commit/380a1b204c36cc8c6fdf28618d8a838aed8b7197
DIFF: https://github.com/llvm/llvm-project/commit/380a1b204c36cc8c6fdf28618d8a838aed8b7197.diff

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

Added: 
    

Modified: 
    llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
    mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
    mlir/lib/Conversion/LLVMCommon/VectorPattern.cpp
    mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
    mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
    mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp
    mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
    mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeConv2D.cpp
    mlir/lib/Interfaces/InferTypeOpInterface.cpp
    mlir/lib/Parser/Lexer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp b/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
index cd3da88d2d089..7b0e3b0472417 100644
--- a/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
+++ b/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
@@ -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();

diff  --git a/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp b/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
index 428d578d99ef8..c9b25f738a009 100644
--- a/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
@@ -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");

diff  --git a/mlir/lib/Conversion/LLVMCommon/VectorPattern.cpp b/mlir/lib/Conversion/LLVMCommon/VectorPattern.cpp
index 95aedef7764fe..040b3f4c72590 100644
--- a/mlir/lib/Conversion/LLVMCommon/VectorPattern.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/VectorPattern.cpp
@@ -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();

diff  --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index 2e574903b73c0..7abc107e9f634 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -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];
   }
 

diff  --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index bf9967f0001d3..d579c4f080c7b 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -948,9 +948,7 @@ class VectorTypeCastOpConversion
     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);

diff  --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp
index 4e189b4fd89d6..d00da763498a7 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp
@@ -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;

diff  --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
index 582c2cee9d074..416c72fe11ac9 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
@@ -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;

diff  --git a/mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeConv2D.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeConv2D.cpp
index 5898fadddef32..936e50a18f98c 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeConv2D.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeConv2D.cpp
@@ -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");

diff  --git a/mlir/lib/Interfaces/InferTypeOpInterface.cpp b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
index 237aa0dedc512..d703f64910bc3 100644
--- a/mlir/lib/Interfaces/InferTypeOpInterface.cpp
+++ b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
@@ -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 {

diff  --git a/mlir/lib/Parser/Lexer.cpp b/mlir/lib/Parser/Lexer.cpp
index cbebaf24159d4..43b0358655704 100644
--- a/mlir/lib/Parser/Lexer.cpp
+++ b/mlir/lib/Parser/Lexer.cpp
@@ -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.


        


More information about the Mlir-commits mailing list