[Mlir-commits] [mlir] b23c822 - [mlir][NFC] Clean up builder usage around constants/non-foldable ops
Matthias Springer
llvmlistbot at llvm.org
Fri Jun 30 05:01:08 PDT 2023
Author: Matthias Springer
Date: 2023-06-30T13:56:42+02:00
New Revision: b23c8225e8f914d9b0fe987c443eb19fca05344e
URL: https://github.com/llvm/llvm-project/commit/b23c8225e8f914d9b0fe987c443eb19fca05344e
DIFF: https://github.com/llvm/llvm-project/commit/b23c8225e8f914d9b0fe987c443eb19fca05344e.diff
LOG: [mlir][NFC] Clean up builder usage around constants/non-foldable ops
* Use `create` instead of `createOrFold` for constant ops. Constants cannot be folded any further.
* Use `create` instead of `createOrFold` for ops that do not have a folder.
* Use C++ op builders that take an `int` instead of creating a `ConstantIndexOp`.
* Create `tensor::DimOp` instead of `linalg::createOrFoldDimOp` when it is certain that the operand is a tensor.
Differential Revision: https://reviews.llvm.org/D154196
Added:
Modified:
mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp
mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
mlir/lib/Dialect/MemRef/Transforms/ResolveShapedTypeResultDims.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
index e764c8d30b6002..0fc1aaef0c7db4 100644
--- a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
+++ b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
@@ -29,7 +29,7 @@ using namespace mlir::amdgpu;
static Value createI32Constant(ConversionPatternRewriter &rewriter,
Location loc, int32_t value) {
Type llvmI32 = rewriter.getI32Type();
- return rewriter.createOrFold<LLVM::ConstantOp>(loc, llvmI32, value);
+ return rewriter.create<LLVM::ConstantOp>(loc, llvmI32, value);
}
namespace {
@@ -317,14 +317,14 @@ static Value mfmaConcatIfNeeded(ConversionPatternRewriter &rewriter,
return input;
int64_t numBytes = vectorType.getNumElements();
Type destType = rewriter.getIntegerType(numBytes * 8);
- Value result = rewriter.createOrFold<LLVM::ConstantOp>(
+ Value result = rewriter.create<LLVM::ConstantOp>(
loc, destType, rewriter.getIntegerAttr(destType, 0));
for (int64_t i = 0; i < numBytes; ++i) {
Value idxConst = createI32Constant(rewriter, loc, i);
Value element =
rewriter.create<LLVM::ExtractElementOp>(loc, input, idxConst);
Value extended = rewriter.create<LLVM::ZExtOp>(loc, destType, element);
- Value shiftConst = rewriter.createOrFold<LLVM::ConstantOp>(
+ Value shiftConst = rewriter.create<LLVM::ConstantOp>(
loc, destType, rewriter.getIntegerAttr(destType, i * 8));
Value shifted = rewriter.create<LLVM::ShlOp>(loc, extended, shiftConst);
result = rewriter.create<LLVM::OrOp>(loc, result, shifted);
diff --git a/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp b/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp
index f498d2c359e56c..a01fc9f117c2be 100644
--- a/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp
+++ b/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp
@@ -62,9 +62,7 @@ struct CloneOpConversion : public OpConversionPattern<bufferization::CloneOp> {
for (int i = 0; i < memrefType.getRank(); ++i) {
if (!memrefType.isDynamicDim(i))
continue;
- Value size = rewriter.createOrFold<arith::ConstantIndexOp>(loc, i);
- Value dim =
- rewriter.createOrFold<memref::DimOp>(loc, op.getInput(), size);
+ Value dim = rewriter.createOrFold<memref::DimOp>(loc, op.getInput(), i);
dynamicOperands.push_back(dim);
}
diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
index 3c1a63bf8e21a5..a2dfa0b8551180 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
@@ -2124,8 +2124,8 @@ struct RFFT2dConverter final : public OpRewritePattern<RFFT2dOp> {
affineDimsExpr(rewriter, 0, 1, 2)});
// Width and height dimensions of the original input.
- auto dimH = linalg::createOrFoldDimOp(rewriter, loc, input, 1);
- auto dimW = linalg::createOrFoldDimOp(rewriter, loc, input, 2);
+ auto dimH = rewriter.createOrFold<tensor::DimOp>(loc, input, 1);
+ auto dimW = rewriter.createOrFold<tensor::DimOp>(loc, input, 2);
// Constants and dimension sizes
auto twoPiAttr = rewriter.getFloatAttr(elementType, 6.283185307179586);
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
index 4eb8231e5e2bd3..2984b0f6d3f29e 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
@@ -71,8 +71,7 @@ mlir::bufferization::castOrReallocMemRefValue(OpBuilder &b, Value value,
for (int i = 0; i < destType.getRank(); ++i) {
if (destType.getShape()[i] != ShapedType::kDynamic)
continue;
- auto index = b.createOrFold<arith::ConstantIndexOp>(loc, i);
- Value size = b.create<memref::DimOp>(loc, value, index);
+ Value size = b.create<memref::DimOp>(loc, value, i);
dynamicOperands.push_back(size);
}
// TODO: Use alloc/memcpy callback from BufferizationOptions if called via
diff --git a/mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp b/mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp
index 21de15e2508813..14c44f27a6249e 100644
--- a/mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp
@@ -51,8 +51,7 @@ static void insertCopyLoops(ImplicitLocOpBuilder &b, Value from, Value to) {
ubs.reserve(lbs.size());
steps.reserve(lbs.size());
for (auto idx = 0; idx < rank; ++idx) {
- ubs.push_back(b.createOrFold<memref::DimOp>(
- from, b.create<arith::ConstantIndexOp>(idx)));
+ ubs.push_back(b.createOrFold<memref::DimOp>(from, idx));
steps.push_back(one);
}
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp b/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
index e952f9437ce8f9..319f73ba0d2896 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
@@ -59,11 +59,11 @@ static Value allocBuffer(ImplicitLocOpBuilder &b,
auto staticBufferType =
MemRefType::get(width * cst.value(), b.getIntegerType(8));
if (options.useAlloca) {
- return b.createOrFold<memref::AllocaOp>(staticBufferType, ValueRange{},
- alignmentAttr);
+ return b.create<memref::AllocaOp>(staticBufferType, ValueRange{},
+ alignmentAttr);
}
- return b.createOrFold<memref::AllocOp>(staticBufferType, ValueRange{},
- alignmentAttr);
+ return b.create<memref::AllocOp>(staticBufferType, ValueRange{},
+ alignmentAttr);
}
// Fallback dynamic buffer.
@@ -86,8 +86,8 @@ static std::optional<Value> defaultAllocBufferCallBack(
std::optional<unsigned> alignment, DataLayout &layout) {
ShapedType viewType = subView.getType();
ImplicitLocOpBuilder b(subView.getLoc(), builder);
- auto zero = b.createOrFold<arith::ConstantIndexOp>(0);
- auto one = b.createOrFold<arith::ConstantIndexOp>(1);
+ auto zero = b.create<arith::ConstantIndexOp>(0);
+ auto one = b.create<arith::ConstantIndexOp>(1);
Value allocSize = one;
for (const auto &size : llvm::enumerate(boundingSubViewSize))
diff --git a/mlir/lib/Dialect/MemRef/Transforms/ResolveShapedTypeResultDims.cpp b/mlir/lib/Dialect/MemRef/Transforms/ResolveShapedTypeResultDims.cpp
index 9e5fc73bea06a1..f18ae2cc9b6881 100644
--- a/mlir/lib/Dialect/MemRef/Transforms/ResolveShapedTypeResultDims.cpp
+++ b/mlir/lib/Dialect/MemRef/Transforms/ResolveShapedTypeResultDims.cpp
@@ -68,7 +68,7 @@ struct DimOfShapedTypeOpInterface : public OpRewritePattern<OpTy> {
Location loc = dimOp->getLoc();
rewriter.replaceOpWithNewOp<tensor::ExtractOp>(
dimOp, resultShape,
- rewriter.createOrFold<arith::ConstantIndexOp>(loc, *dimIndex));
+ rewriter.create<arith::ConstantIndexOp>(loc, *dimIndex).getResult());
return success();
}
};
More information about the Mlir-commits
mailing list