[Mlir-commits] [mlir] [mlir][NFC] update `mlir/Dialect` create APIs (33/n) (PR #150659)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jul 25 10:17:29 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-gpu
Author: Maksim Levental (makslevental)
<details>
<summary>Changes</summary>
See https://github.com/llvm/llvm-project/pull/147168 for more info.
---
Patch is 30.68 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/150659.diff
23 Files Affected:
- (modified) mlir/lib/Dialect/AMX/IR/AMXDialect.cpp (+1-2)
- (modified) mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp (+2-4)
- (modified) mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp (+2-4)
- (modified) mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp (+1-2)
- (modified) mlir/lib/Dialect/GPU/Transforms/ShuffleRewriter.cpp (+2-4)
- (modified) mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp (+1-2)
- (modified) mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp (+2-3)
- (modified) mlir/lib/Dialect/MemRef/Transforms/RuntimeOpVerification.cpp (+2-3)
- (modified) mlir/lib/Dialect/Quant/Transforms/LowerQuantOps.cpp (+40-44)
- (modified) mlir/lib/Dialect/SCF/Transforms/BufferizableOpInterfaceImpl.cpp (+4-4)
- (modified) mlir/lib/Dialect/SCF/Utils/Utils.cpp (+2-3)
- (modified) mlir/lib/Dialect/Shape/IR/Shape.cpp (+1-2)
- (modified) mlir/lib/Dialect/Shard/Transforms/Partition.cpp (+11-14)
- (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp (+5-7)
- (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseGPUCodegen.cpp (+5-5)
- (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseIterationToScf.cpp (+2-2)
- (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp (+8-8)
- (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp (+2-4)
- (modified) mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp (+4-5)
- (modified) mlir/lib/Dialect/Tensor/Transforms/IndependenceTransforms.cpp (+2-3)
- (modified) mlir/lib/Dialect/Tensor/Transforms/ReshapePatterns.cpp (+3-4)
- (modified) mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp (+2-3)
- (modified) mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeDepthwise.cpp (+4-6)
``````````diff
diff --git a/mlir/lib/Dialect/AMX/IR/AMXDialect.cpp b/mlir/lib/Dialect/AMX/IR/AMXDialect.cpp
index 748ff1edbfeb2..8c1786d3fbeae 100644
--- a/mlir/lib/Dialect/AMX/IR/AMXDialect.cpp
+++ b/mlir/lib/Dialect/AMX/IR/AMXDialect.cpp
@@ -96,8 +96,7 @@ static Value getStride(Location loc, MemRefType mType, Value base,
MemRefDescriptor memrefDescriptor(base);
auto attr = rewriter.getI64IntegerAttr(bytes);
Value scale = LLVM::ConstantOp::create(rewriter, loc, llvmInt64Type, attr);
- return rewriter
- .create<LLVM::MulOp>(loc, llvmInt64Type, scale,
+ return LLVM::MulOp::create(rewriter, loc, llvmInt64Type, scale,
memrefDescriptor.stride(rewriter, loc, preLast))
.getResult();
}
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
index 994d48505d24f..3a49bf01a0c06 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
@@ -688,8 +688,7 @@ FailureOr<Value> bufferization::getBuffer(RewriterBase &rewriter, Value value,
if (failed(bufferType))
return failure();
ensureToBufferOpIsValid(value, *bufferType);
- return rewriter
- .create<bufferization::ToBufferOp>(value.getLoc(), *bufferType, value)
+ return bufferization::ToBufferOp::create(rewriter, value.getLoc(), *bufferType, value)
.getResult();
}
@@ -772,8 +771,7 @@ FailureOr<Value> BufferizationOptions::createAlloc(OpBuilder &b, Location loc,
// Default bufferallocation via AllocOp.
if (bufferAlignment != 0)
- return b
- .create<memref::AllocOp>(loc, type, dynShape,
+ return memref::AllocOp::create(b, loc, type, dynShape,
b.getI64IntegerAttr(bufferAlignment))
.getResult();
return memref::AllocOp::create(b, loc, type, dynShape).getResult();
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp b/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp
index f0d65b04ee447..8b8f1445603c5 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp
@@ -483,8 +483,7 @@ func::FuncOp mlir::bufferization::buildDeallocationLibraryFunction(
// Build the first for loop that computes aliasing with retained
// memrefs.
Value noRetainAlias =
- builder
- .create<scf::ForOp>(
+ scf::ForOp::create(builder,
loc, c0, toRetainSize, c1, trueValue,
[&](OpBuilder &builder, Location loc, Value i,
ValueRange iterArgs) {
@@ -517,8 +516,7 @@ func::FuncOp mlir::bufferization::buildDeallocationLibraryFunction(
// Build the second for loop that adds aliasing with previously
// deallocated memrefs.
Value noAlias =
- builder
- .create<scf::ForOp>(
+ scf::ForOp::create(builder,
loc, c0, outerIter, c1, noRetainAlias,
[&](OpBuilder &builder, Location loc, Value i,
ValueRange iterArgs) {
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp b/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp
index 64c178dfe76d8..5af63d4787087 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp
@@ -750,8 +750,7 @@ Value BufferDeallocation::materializeMemrefWithGuaranteedOwnership(
// Insert a runtime check and only clone if we still don't have ownership at
// runtime.
- Value maybeClone = builder
- .create<scf::IfOp>(
+ Value maybeClone = scf::IfOp::create(builder,
memref.getLoc(), condition,
[&](OpBuilder &builder, Location loc) {
scf::YieldOp::create(builder, loc, newMemref);
diff --git a/mlir/lib/Dialect/GPU/Transforms/ShuffleRewriter.cpp b/mlir/lib/Dialect/GPU/Transforms/ShuffleRewriter.cpp
index d88f4d56d9009..dd0ae6a047f5b 100644
--- a/mlir/lib/Dialect/GPU/Transforms/ShuffleRewriter.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/ShuffleRewriter.cpp
@@ -60,13 +60,11 @@ struct GpuShuffleRewriter : public OpRewritePattern<gpu::ShuffleOp> {
// Shuffle the values.
ValueRange loRes =
- rewriter
- .create<gpu::ShuffleOp>(op.getLoc(), lo, op.getOffset(),
+ gpu::ShuffleOp::create(rewriter, op.getLoc(), lo, op.getOffset(),
op.getWidth(), op.getMode())
.getResults();
ValueRange hiRes =
- rewriter
- .create<gpu::ShuffleOp>(op.getLoc(), hi, op.getOffset(),
+ gpu::ShuffleOp::create(rewriter, op.getLoc(), hi, op.getOffset(),
op.getWidth(), op.getMode())
.getResults();
diff --git a/mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp b/mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp
index b9e2dd5b19a6f..37fd0bf32191d 100644
--- a/mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp
@@ -197,8 +197,7 @@ Value createSubgroupShuffleReduction(OpBuilder &builder, Location loc,
// Parallel reduction using butterfly shuffles.
for (unsigned i = ci.clusterStride; i < ci.clusterStride * ci.clusterSize;
i <<= 1) {
- Value shuffled = builder
- .create<gpu::ShuffleOp>(loc, packFn(laneVal), i,
+ Value shuffled = gpu::ShuffleOp::create(builder, loc, packFn(laneVal), i,
/*width=*/ci.subgroupSize,
/*mode=*/gpu::ShuffleMode::XOR)
.getShuffleResult();
diff --git a/mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp b/mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp
index 66c1aa6bf3fe1..d5e2b97e501e6 100644
--- a/mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp
+++ b/mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp
@@ -56,9 +56,8 @@ FailureOr<Value> memref::buildIndependentOp(OpBuilder &b,
// Create a memref::SubViewOp.
SmallVector<OpFoldResult> offsets(newSizes.size(), b.getIndexAttr(0));
SmallVector<OpFoldResult> strides(newSizes.size(), b.getIndexAttr(1));
- return b
- .create<SubViewOp>(loc, newAllocaOp, offsets, allocaOp.getMixedSizes(),
- strides)
+ return SubViewOp::create(b, loc, newAllocaOp, offsets,
+ allocaOp.getMixedSizes(), strides)
.getResult();
}
diff --git a/mlir/lib/Dialect/MemRef/Transforms/RuntimeOpVerification.cpp b/mlir/lib/Dialect/MemRef/Transforms/RuntimeOpVerification.cpp
index 1f03e9ae8d6a1..d3a77c026379e 100644
--- a/mlir/lib/Dialect/MemRef/Transforms/RuntimeOpVerification.cpp
+++ b/mlir/lib/Dialect/MemRef/Transforms/RuntimeOpVerification.cpp
@@ -185,9 +185,8 @@ struct CopyOpInterface
int64_t dim) -> Value {
return type.isDynamicDim(dim)
? DimOp::create(builder, loc, memRef, dim).getResult()
- : builder
- .create<arith::ConstantIndexOp>(loc,
- type.getDimSize(dim))
+ : arith::ConstantIndexOp::create(builder, loc,
+ type.getDimSize(dim))
.getResult();
};
Value sourceDim = getDimSize(copyOp.getSource(), rankedSourceType, i);
diff --git a/mlir/lib/Dialect/Quant/Transforms/LowerQuantOps.cpp b/mlir/lib/Dialect/Quant/Transforms/LowerQuantOps.cpp
index 58cd160948f7f..9e37bc5163f71 100644
--- a/mlir/lib/Dialect/Quant/Transforms/LowerQuantOps.cpp
+++ b/mlir/lib/Dialect/Quant/Transforms/LowerQuantOps.cpp
@@ -148,16 +148,14 @@ flattenUnrankedTensorAroundAxis(OpBuilder &builder, Location loc, Value input,
auto axisValue = arith::ConstantIndexOp::create(builder, loc, axis);
auto axisNextValue = arith::ConstantIndexOp::create(builder, loc, axis + 1);
auto shapeLeft =
- builder
- .create<shape::SplitAtOp>(loc, TypeRange{shapeType, shapeType},
- inputShape, axisValue)
+ shape::SplitAtOp::create(builder, loc, TypeRange{shapeType, shapeType},
+ inputShape, axisValue)
.getResult(0);
auto sizeLeft =
shape::NumElementsOp::create(builder, loc, indexType, shapeLeft);
auto shapeRight =
- builder
- .create<shape::SplitAtOp>(loc, TypeRange{shapeType, shapeType},
- inputShape, axisNextValue)
+ shape::SplitAtOp::create(builder, loc, TypeRange{shapeType, shapeType},
+ inputShape, axisNextValue)
.getResult(1);
auto sizeRight =
shape::NumElementsOp::create(builder, loc, indexType, shapeRight);
@@ -557,25 +555,24 @@ Value convertPerChannelRanked(OpBuilder &builder, Location loc, Operation *op,
SmallVector<AffineMap> indexingMaps{
builder.getMultiDimIdentityMap(inputRank), channelAxisAffineMap,
channelAxisAffineMap, builder.getMultiDimIdentityMap(inputRank)};
- auto result = builder
- .create<linalg::GenericOp>(
- loc,
- init.getType(), // resultType
- ValueRange{input, scales, zeroPoints}, // inputs
- ValueRange{init}, // outputs
- indexingMaps, iteratorTypes,
- [&](OpBuilder &builder, Location loc, ValueRange args) {
- assert(args.size() == 4);
- auto input = args[0];
- auto scale = args[1];
- auto zeroPoint = args[2];
-
- auto result =
- convertRanked(builder, loc, op, input, {}, scale,
- zeroPoint, quantizedType);
-
- linalg::YieldOp::create(builder, loc, result);
- })
+ auto result = linalg::GenericOp::create(
+ builder, loc,
+ init.getType(), // resultType
+ ValueRange{input, scales, zeroPoints}, // inputs
+ ValueRange{init}, // outputs
+ indexingMaps, iteratorTypes,
+ [&](OpBuilder &builder, Location loc, ValueRange args) {
+ assert(args.size() == 4);
+ auto input = args[0];
+ auto scale = args[1];
+ auto zeroPoint = args[2];
+
+ auto result =
+ convertRanked(builder, loc, op, input, {}, scale,
+ zeroPoint, quantizedType);
+
+ linalg::YieldOp::create(builder, loc, result);
+ })
.getResult(0);
return result;
@@ -660,25 +657,24 @@ Value convertSubChannel(OpBuilder &builder, Location loc, Operation *op,
SmallVector<AffineMap> indexingMaps{
builder.getMultiDimIdentityMap(inputRank), affineMap, affineMap,
builder.getMultiDimIdentityMap(inputRank)};
- auto result = builder
- .create<linalg::GenericOp>(
- loc,
- init.getType(), // resultType
- ValueRange{input, scales, zeroPoints}, // inputs
- ValueRange{init}, // outputs
- indexingMaps, iteratorTypes,
- [&](OpBuilder &builder, Location loc, ValueRange args) {
- assert(args.size() == 4);
- auto input = args[0];
- auto scale = args[1];
- auto zeroPoint = args[2];
-
- auto result =
- convertRanked(builder, loc, op, input, {}, scale,
- zeroPoint, quantizedType);
-
- linalg::YieldOp::create(builder, loc, result);
- })
+ auto result = linalg::GenericOp::create(
+ builder, loc,
+ init.getType(), // resultType
+ ValueRange{input, scales, zeroPoints}, // inputs
+ ValueRange{init}, // outputs
+ indexingMaps, iteratorTypes,
+ [&](OpBuilder &builder, Location loc, ValueRange args) {
+ assert(args.size() == 4);
+ auto input = args[0];
+ auto scale = args[1];
+ auto zeroPoint = args[2];
+
+ auto result =
+ convertRanked(builder, loc, op, input, {}, scale,
+ zeroPoint, quantizedType);
+
+ linalg::YieldOp::create(builder, loc, result);
+ })
.getResult(0);
return result;
diff --git a/mlir/lib/Dialect/SCF/Transforms/BufferizableOpInterfaceImpl.cpp b/mlir/lib/Dialect/SCF/Transforms/BufferizableOpInterfaceImpl.cpp
index 64c4d607e3fb9..f8799c52e8797 100644
--- a/mlir/lib/Dialect/SCF/Transforms/BufferizableOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/SCF/Transforms/BufferizableOpInterfaceImpl.cpp
@@ -497,10 +497,10 @@ getBbArgReplacements(RewriterBase &rewriter, Block::BlockArgListType bbArgs,
size_t idx = it.index();
Value val = it.value();
if (tensorIndices.contains(idx)) {
- result.push_back(rewriter
- .create<bufferization::ToTensorOp>(
- val.getLoc(), oldBbArgs[idx].getType(), val)
- .getResult());
+ result.push_back(
+ bufferization::ToTensorOp::create(rewriter, val.getLoc(),
+ oldBbArgs[idx].getType(), val)
+ .getResult());
} else {
result.push_back(val);
}
diff --git a/mlir/lib/Dialect/SCF/Utils/Utils.cpp b/mlir/lib/Dialect/SCF/Utils/Utils.cpp
index 5b0c60415a6c4..57317951d609c 100644
--- a/mlir/lib/Dialect/SCF/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/SCF/Utils/Utils.cpp
@@ -827,9 +827,8 @@ static Value getProductOfIntsOrIndexes(RewriterBase &rewriter, Location loc,
productOf = v;
}
if (!productOf) {
- productOf = rewriter
- .create<arith::ConstantOp>(
- loc, rewriter.getOneAttr(getType(values.front())))
+ productOf = arith::ConstantOp::create(
+ rewriter, loc, rewriter.getOneAttr(getType(values.front())))
.getResult();
}
return productOf.value();
diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index e24f0f87e781d..50985c1c131f5 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -1702,8 +1702,7 @@ struct ShapeOfOpToConstShapeOp : public OpRewritePattern<shape::ShapeOfOp> {
return failure();
Location loc = op.getLoc();
Value constShape =
- rewriter
- .create<ConstShapeOp>(loc,
+ ConstShapeOp::create(rewriter, loc,
rewriter.getIndexTensorAttr(type.getShape()))
.getResult();
if (constShape.getType() != op.getResult().getType())
diff --git a/mlir/lib/Dialect/Shard/Transforms/Partition.cpp b/mlir/lib/Dialect/Shard/Transforms/Partition.cpp
index 5fe55669c90db..3e3d4768853e5 100644
--- a/mlir/lib/Dialect/Shard/Transforms/Partition.cpp
+++ b/mlir/lib/Dialect/Shard/Transforms/Partition.cpp
@@ -70,10 +70,8 @@ splitLastAxisInResharding(ImplicitLocOpBuilder &builder,
TypedValue<ShapedType> sourceShard, GridOp grid,
int64_t splitTensorAxis, GridAxis splitGridAxis) {
TypedValue<ShapedType> targetShard = cast<TypedValue<ShapedType>>(
- builder
- .create<AllSliceOp>(sourceShard, grid,
- ArrayRef<GridAxis>(splitGridAxis),
- splitTensorAxis)
+ AllSliceOp::create(builder, sourceShard, grid,
+ ArrayRef<GridAxis>(splitGridAxis), splitTensorAxis)
.getResult());
Sharding targetSharding = targetShardingInSplitLastAxis(
builder.getContext(), sourceSharding, splitTensorAxis, splitGridAxis);
@@ -420,16 +418,15 @@ tryUpdateHaloInResharding(ImplicitLocOpBuilder &builder, GridOp grid,
// Finally update the halo.
auto updateHaloResult =
- builder
- .create<UpdateHaloOp>(
- sourceShard.getLoc(),
- RankedTensorType::get(outShape,
- sourceShard.getType().getElementType()),
- initOprnd, grid.getSymName(),
- GridAxesArrayAttr::get(builder.getContext(),
- sourceSharding.getSplitAxes()),
- targetSharding.getDynamicHaloSizes(),
- targetSharding.getStaticHaloSizes())
+ UpdateHaloOp::create(
+ builder, sourceShard.getLoc(),
+ RankedTensorType::get(outShape,
+ sourceShard.getType().getElementType()),
+ initOprnd, grid.getSymName(),
+ GridAxesArrayAttr::get(builder.getContext(),
+ sourceSharding.getSplitAxes()),
+ targetSharding.getDynamicHaloSizes(),
+ targetSharding.getStaticHaloSizes())
.getResult();
return std::make_tuple(cast<TypedValue<ShapedType>>(updateHaloResult),
targetSharding);
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp
index a52872dd093d8..3b4140edd1641 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp
@@ -931,10 +931,9 @@ createQuickSort(OpBuilder &builder, ModuleOp module, func::FuncOp func,
FlatSymbolRefAttr partitionFunc = getMangledSortHelperFunc(
builder, func, {IndexType::get(context)}, kPartitionFuncNamePrefix, xPerm,
ny, args.drop_back(nTrailingP), createPartitionFunc);
- Value p = builder
- .create<func::CallOp>(loc, partitionFunc,
- TypeRange{IndexType::get(context)},
- args.drop_back(nTrailingP))
+ Value p = func::CallOp::create(builder, loc, partitionFunc,
+ TypeRange{IndexType::get(context)},
+ args.drop_back(nTrailingP))
.getResult(0);
Value lenLow = arith::SubIOp::create(builder, loc, p, lo);
@@ -1028,9 +1027,8 @@ static void createSortStableFunc(OpBuilder &builder, ModuleOp module,
FlatSymbolRefAttr searchFunc = getMangledSortHelperFunc(
builder, func, {IndexType::get(context)}, kBinarySearchFuncNamePrefix,
xPerm, ny, operands, createBinarySearchFunc);
- Value p = builder
- .create<func::CallOp>(loc, searchFunc, TypeRange{c1.getType()},
- operands)
+ Value p = func::CallOp::create(builder, loc, searchFunc,
+ TypeRange{c1.getType()}, operands)
.getResult(0);
// Move the value at data[i] to a temporary location.
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseGPUCodegen.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseGPUCodegen.cpp
index a317abd6c560b..0bd1d34c3504b 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseGPUCodegen.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseGPUCodegen.cpp
@@ -98,10 +98,10 @@ static Value genLaunchGPUFunc(OpBuilder &builder, gpu::GPUFuncOp gpuFunc,
Value...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/150659
More information about the Mlir-commits
mailing list