-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[mlir][NFC] update mlir/Dialect
create APIs (16/n)
#149922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][NFC] update mlir/Dialect
create APIs (16/n)
#149922
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
See llvm#147168 for more info.
3c5d31a
to
f8cd1d9
Compare
@llvm/pr-subscribers-mlir-func @llvm/pr-subscribers-backend-amdgpu Author: Maksim Levental (makslevental) ChangesSee #147168 for more info. Patch is 60.36 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149922.diff 27 Files Affected:
diff --git a/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp b/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
index f5a42c572ff96..0adfb51a228bb 100644
--- a/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
+++ b/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
@@ -48,8 +48,8 @@ Operation *complex::ComplexDialect::materializeConstant(OpBuilder &builder,
Type type,
Location loc) {
if (complex::ConstantOp::isBuildableWith(value, type)) {
- return builder.create<complex::ConstantOp>(loc, type,
- llvm::cast<ArrayAttr>(value));
+ return complex::ConstantOp::create(builder, loc, type,
+ llvm::cast<ArrayAttr>(value));
}
return arith::ConstantOp::materialize(builder, value, type, loc);
}
diff --git a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
index 0c11c76cf1f71..4a5c2a99c92aa 100644
--- a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
+++ b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
@@ -312,8 +312,9 @@ struct SimplifyCondBranchIdenticalSuccessors
if (std::get<0>(it) == std::get<1>(it))
mergedOperands.push_back(std::get<0>(it));
else
- mergedOperands.push_back(rewriter.create<arith::SelectOp>(
- condbr.getLoc(), condition, std::get<0>(it), std::get<1>(it)));
+ mergedOperands.push_back(
+ arith::SelectOp::create(rewriter, condbr.getLoc(), condition,
+ std::get<0>(it), std::get<1>(it)));
}
rewriter.replaceOpWithNewOp<BranchOp>(condbr, trueDest, mergedOperands);
@@ -412,8 +413,8 @@ struct CondBranchTruthPropagation : public OpRewritePattern<CondBranchOp> {
replaced = true;
if (!constantTrue)
- constantTrue = rewriter.create<arith::ConstantOp>(
- condbr.getLoc(), ty, rewriter.getBoolAttr(true));
+ constantTrue = arith::ConstantOp::create(
+ rewriter, condbr.getLoc(), ty, rewriter.getBoolAttr(true));
rewriter.modifyOpInPlace(use.getOwner(),
[&] { use.set(constantTrue); });
@@ -427,8 +428,8 @@ struct CondBranchTruthPropagation : public OpRewritePattern<CondBranchOp> {
replaced = true;
if (!constantFalse)
- constantFalse = rewriter.create<arith::ConstantOp>(
- condbr.getLoc(), ty, rewriter.getBoolAttr(false));
+ constantFalse = arith::ConstantOp::create(
+ rewriter, condbr.getLoc(), ty, rewriter.getBoolAttr(false));
rewriter.modifyOpInPlace(use.getOwner(),
[&] { use.set(constantFalse); });
diff --git a/mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp b/mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp
index a077f56f4f472..80dc0c597562d 100644
--- a/mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp
@@ -87,8 +87,8 @@ struct CondBranchOpInterface
destOperands.getAsOperandRange(), toRetain);
SmallVector<Value> adaptedConditions(
llvm::map_range(conditions, conditionModifier));
- auto deallocOp = builder.create<bufferization::DeallocOp>(
- condBr.getLoc(), memrefs, adaptedConditions, toRetain);
+ auto deallocOp = bufferization::DeallocOp::create(
+ builder, condBr.getLoc(), memrefs, adaptedConditions, toRetain);
state.resetOwnerships(deallocOp.getRetained(), condBr->getBlock());
for (auto [retained, ownership] : llvm::zip(
deallocOp.getRetained(), deallocOp.getUpdatedConditions())) {
@@ -115,18 +115,19 @@ struct CondBranchOpInterface
DeallocOp thenTakenDeallocOp = insertDeallocForBranch(
condBr.getTrueDest(), condBr.getTrueDestOperandsMutable(),
[&](Value cond) {
- return builder.create<arith::AndIOp>(condBr.getLoc(), cond,
- condBr.getCondition());
+ return arith::AndIOp::create(builder, condBr.getLoc(), cond,
+ condBr.getCondition());
},
thenMapping);
DeallocOp elseTakenDeallocOp = insertDeallocForBranch(
condBr.getFalseDest(), condBr.getFalseDestOperandsMutable(),
[&](Value cond) {
- Value trueVal = builder.create<arith::ConstantOp>(
- condBr.getLoc(), builder.getBoolAttr(true));
- Value negation = builder.create<arith::XOrIOp>(
- condBr.getLoc(), trueVal, condBr.getCondition());
- return builder.create<arith::AndIOp>(condBr.getLoc(), cond, negation);
+ Value trueVal = arith::ConstantOp::create(builder, condBr.getLoc(),
+ builder.getBoolAttr(true));
+ Value negation = arith::XOrIOp::create(
+ builder, condBr.getLoc(), trueVal, condBr.getCondition());
+ return arith::AndIOp::create(builder, condBr.getLoc(), cond,
+ negation);
},
elseMapping);
@@ -143,9 +144,9 @@ struct CondBranchOpInterface
for (Value retained : commonValues) {
state.resetOwnerships(retained, condBr->getBlock());
- Value combinedOwnership = builder.create<arith::SelectOp>(
- condBr.getLoc(), condBr.getCondition(), thenMapping[retained],
- elseMapping[retained]);
+ Value combinedOwnership = arith::SelectOp::create(
+ builder, condBr.getLoc(), condBr.getCondition(),
+ thenMapping[retained], elseMapping[retained]);
state.updateOwnership(retained, combinedOwnership, condBr->getBlock());
}
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index fccbca6ed05dd..568da8905cbc8 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -47,13 +47,13 @@ void EmitCDialect::initialize() {
Operation *EmitCDialect::materializeConstant(OpBuilder &builder,
Attribute value, Type type,
Location loc) {
- return builder.create<emitc::ConstantOp>(loc, type, value);
+ return emitc::ConstantOp::create(builder, loc, type, value);
}
/// Default callback for builders of ops carrying a region. Inserts a yield
/// without arguments.
void mlir::emitc::buildTerminatedBody(OpBuilder &builder, Location loc) {
- builder.create<emitc::YieldOp>(loc);
+ emitc::YieldOp::create(builder, loc);
}
bool mlir::emitc::isSupportedEmitCType(Type type) {
diff --git a/mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp b/mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp
index 12218f5072982..d5fe3b4ae1e7f 100644
--- a/mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp
+++ b/mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp
@@ -24,7 +24,7 @@ ExpressionOp createExpression(Operation *op, OpBuilder &builder) {
Location loc = op->getLoc();
builder.setInsertionPointAfter(op);
- auto expressionOp = builder.create<emitc::ExpressionOp>(loc, resultType);
+ auto expressionOp = emitc::ExpressionOp::create(builder, loc, resultType);
// Replace all op's uses with the new expression's result.
result.replaceAllUsesWith(expressionOp.getResult());
@@ -33,7 +33,7 @@ ExpressionOp createExpression(Operation *op, OpBuilder &builder) {
Region ®ion = expressionOp.getRegion();
Block &block = region.emplaceBlock();
builder.setInsertionPointToEnd(&block);
- auto yieldOp = builder.create<emitc::YieldOp>(loc, result);
+ auto yieldOp = emitc::YieldOp::create(builder, loc, result);
// Move op into the new expression.
op->moveBefore(yieldOp);
diff --git a/mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp b/mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp
index 72c8fd0f32485..ab7be8d6cedd9 100644
--- a/mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp
+++ b/mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp
@@ -21,7 +21,7 @@ Value materializeAsUnrealizedCast(OpBuilder &builder, Type resultType,
if (inputs.size() != 1)
return Value();
- return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
+ return UnrealizedConversionCastOp::create(builder, loc, resultType, inputs)
.getResult(0);
}
diff --git a/mlir/lib/Dialect/EmitC/Transforms/WrapFuncInClass.cpp b/mlir/lib/Dialect/EmitC/Transforms/WrapFuncInClass.cpp
index 17d436f6df028..612e8099eaf35 100644
--- a/mlir/lib/Dialect/EmitC/Transforms/WrapFuncInClass.cpp
+++ b/mlir/lib/Dialect/EmitC/Transforms/WrapFuncInClass.cpp
@@ -50,7 +50,7 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
PatternRewriter &rewriter) const override {
auto className = funcOp.getSymNameAttr().str() + "Class";
- ClassOp newClassOp = rewriter.create<ClassOp>(funcOp.getLoc(), className);
+ ClassOp newClassOp = ClassOp::create(rewriter, funcOp.getLoc(), className);
SmallVector<std::pair<StringAttr, TypeAttr>> fields;
rewriter.createBlock(&newClassOp.getBody());
@@ -67,15 +67,15 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
TypeAttr typeAttr = TypeAttr::get(val.getType());
fields.push_back({fieldName, typeAttr});
- rewriter.create<emitc::FieldOp>(funcOp.getLoc(), fieldName, typeAttr,
- argAttr);
+ emitc::FieldOp::create(rewriter, funcOp.getLoc(), fieldName, typeAttr,
+ argAttr);
}
rewriter.setInsertionPointToEnd(&newClassOp.getBody().front());
FunctionType funcType = funcOp.getFunctionType();
Location loc = funcOp.getLoc();
FuncOp newFuncOp =
- rewriter.create<emitc::FuncOp>(loc, ("execute"), funcType);
+ emitc::FuncOp::create(rewriter, loc, ("execute"), funcType);
rewriter.createBlock(&newFuncOp.getBody());
newFuncOp.getBody().takeBody(funcOp.getBody());
@@ -85,7 +85,7 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
newArguments.reserve(fields.size());
for (auto &[fieldName, attr] : fields) {
GetFieldOp arg =
- rewriter.create<emitc::GetFieldOp>(loc, attr.getValue(), fieldName);
+ emitc::GetFieldOp::create(rewriter, loc, attr.getValue(), fieldName);
newArguments.push_back(arg);
}
diff --git a/mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp b/mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp
index 3328d58551bff..c39e77d823b78 100644
--- a/mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp
+++ b/mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp
@@ -61,7 +61,8 @@ struct FuncInlinerInterface : public DialectInlinerInterface {
// Replace the return with a branch to the dest.
OpBuilder builder(op);
- builder.create<cf::BranchOp>(op->getLoc(), newDest, returnOp.getOperands());
+ cf::BranchOp::create(builder, op->getLoc(), newDest,
+ returnOp.getOperands());
op->erase();
}
diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
index d8309d81f4a3f..3c09a2124bd77 100644
--- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp
+++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
@@ -50,8 +50,8 @@ void FuncDialect::initialize() {
Operation *FuncDialect::materializeConstant(OpBuilder &builder, Attribute value,
Type type, Location loc) {
if (ConstantOp::isBuildableWith(value, type))
- return builder.create<ConstantOp>(loc, type,
- llvm::cast<FlatSymbolRefAttr>(value));
+ return ConstantOp::create(builder, loc, type,
+ llvm::cast<FlatSymbolRefAttr>(value));
return nullptr;
}
diff --git a/mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp b/mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp
index 11fc696a258c0..935d3e5ac331b 100644
--- a/mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp
+++ b/mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp
@@ -170,8 +170,8 @@ transform::CastAndCallOp::apply(transform::TransformRewriter &rewriter,
}
}
- auto callOp = rewriter.create<func::CallOp>(insertionPoint->getLoc(),
- targetFunction, inputs);
+ auto callOp = func::CallOp::create(rewriter, insertionPoint->getLoc(),
+ targetFunction, inputs);
// Cast the call results back to the expected types. If any conversions fail
// this is a definite failure as the call has been constructed at this point.
diff --git a/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp b/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
index a3638c8766a5c..b6c8cdf2f495a 100644
--- a/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
+++ b/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
@@ -46,9 +46,9 @@ struct CallOpSignatureConversion : public OpConversionPattern<CallOp> {
// Substitute with the new result types from the corresponding FuncType
// conversion.
- auto newCallOp = rewriter.create<CallOp>(
- callOp.getLoc(), callOp.getCallee(), convertedResults,
- flattenValues(adaptor.getOperands()));
+ auto newCallOp =
+ CallOp::create(rewriter, callOp.getLoc(), callOp.getCallee(),
+ convertedResults, flattenValues(adaptor.getOperands()));
SmallVector<ValueRange> replacements;
size_t offset = 0;
for (int i = 0, e = callOp->getNumResults(); i < e; ++i) {
diff --git a/mlir/lib/Dialect/Func/Utils/Utils.cpp b/mlir/lib/Dialect/Func/Utils/Utils.cpp
index 0e9662689ef78..f781ed2d591b4 100644
--- a/mlir/lib/Dialect/Func/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Func/Utils/Utils.cpp
@@ -44,8 +44,8 @@ func::replaceFuncWithNewOrder(RewriterBase &rewriter, func::FuncOp funcOp,
for (unsigned int idx : newResultsOrder)
newOutputTypes.push_back(origOutputTypes[idx]);
rewriter.setInsertionPoint(funcOp);
- auto newFuncOp = rewriter.create<func::FuncOp>(
- funcOp.getLoc(), funcOp.getName(),
+ auto newFuncOp = func::FuncOp::create(
+ rewriter, funcOp.getLoc(), funcOp.getName(),
rewriter.getFunctionType(newInputTypes, newOutputTypes));
Region &newRegion = newFuncOp.getBody();
@@ -80,7 +80,7 @@ func::replaceFuncWithNewOrder(RewriterBase &rewriter, func::FuncOp funcOp,
newReturnValues.push_back(returnOp.getOperand(idx));
rewriter.setInsertionPoint(returnOp);
auto newReturnOp =
- rewriter.create<func::ReturnOp>(newFuncOp.getLoc(), newReturnValues);
+ func::ReturnOp::create(rewriter, newFuncOp.getLoc(), newReturnValues);
newReturnOp->setDiscardableAttrs(returnOp->getDiscardableAttrDictionary());
rewriter.eraseOp(returnOp);
@@ -109,8 +109,9 @@ func::replaceCallOpWithNewOrder(RewriterBase &rewriter, func::CallOp callOp,
// Replace the kernel call operation with a new one that has the
// reordered arguments.
rewriter.setInsertionPoint(callOp);
- auto newCallOp = rewriter.create<func::CallOp>(
- callOp.getLoc(), callOp.getCallee(), newResultTypes, newArgsOrderValues);
+ auto newCallOp =
+ func::CallOp::create(rewriter, callOp.getLoc(), callOp.getCallee(),
+ newResultTypes, newArgsOrderValues);
newCallOp.setNoInlineAttr(callOp.getNoInlineAttr());
for (auto &&[newIndex, origIndex] : llvm::enumerate(newResultsOrder))
rewriter.replaceAllUsesWith(callOp.getResult(origIndex),
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 30b5ac9809139..d186a480c0ce5 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -136,12 +136,13 @@ int64_t GPUMappingMaskAttr::getMaxNumPhysicalIds() const { return 64; }
Value GPUMappingMaskAttr::createLogicalLinearMappingId(
OpBuilder &b, Value physicalLinearMappingId) const {
Location loc = physicalLinearMappingId.getLoc();
- Value mask = b.create<arith::ConstantOp>(loc, b.getI64IntegerAttr(getMask()));
- Value one = b.create<arith::ConstantOp>(loc, b.getI64IntegerAttr(1));
- Value filter = b.create<arith::ShLIOp>(loc, one, physicalLinearMappingId);
- filter = b.create<arith::SubIOp>(loc, filter, one);
- Value filteredId = b.create<arith::AndIOp>(loc, mask, filter);
- return b.create<math::CtPopOp>(loc, filteredId);
+ Value mask =
+ arith::ConstantOp::create(b, loc, b.getI64IntegerAttr(getMask()));
+ Value one = arith::ConstantOp::create(b, loc, b.getI64IntegerAttr(1));
+ Value filter = arith::ShLIOp::create(b, loc, one, physicalLinearMappingId);
+ filter = arith::SubIOp::create(b, loc, filter, one);
+ Value filteredId = arith::AndIOp::create(b, loc, mask, filter);
+ return math::CtPopOp::create(b, loc, filteredId);
}
/// 8 4 0
@@ -157,12 +158,14 @@ Value GPUMappingMaskAttr::createLogicalLinearMappingId(
Value GPUMappingMaskAttr::createIsActiveIdPredicate(
OpBuilder &b, Value physicalLinearMappingId) const {
Location loc = physicalLinearMappingId.getLoc();
- Value mask = b.create<arith::ConstantOp>(loc, b.getI64IntegerAttr(getMask()));
- Value one = b.create<arith::ConstantOp>(loc, b.getI64IntegerAttr(1));
- Value filter = b.create<arith::ShLIOp>(loc, one, physicalLinearMappingId);
- Value filtered = b.create<arith::AndIOp>(loc, mask, filter);
- Value zero = b.create<arith::ConstantOp>(loc, b.getI64IntegerAttr(0));
- return b.create<arith::CmpIOp>(loc, arith::CmpIPredicate::ne, filtered, zero);
+ Value mask =
+ arith::ConstantOp::create(b, loc, b.getI64IntegerAttr(getMask()));
+ Value one = arith::ConstantOp::create(b, loc, b.getI64IntegerAttr(1));
+ Value filter = arith::ShLIOp::create(b, loc, one, physicalLinearMappingId);
+ Value filtered = arith::AndIOp::create(b, loc, mask, filter);
+ Value zero = arith::ConstantOp::create(b, loc, b.getI64IntegerAttr(0));
+ return arith::CmpIOp::create(b, loc, arith::CmpIPredicate::ne, filtered,
+ zero);
}
int64_t GPUMemorySpaceMappingAttr::getMappingId() const {
@@ -1137,7 +1140,7 @@ struct FoldLaunchArguments : public OpRewritePattern<LaunchOp> {
OpBuilder::InsertionGuard guard(rewriter);
rewriter.setInsertionPointToStart(&op.getBody().front());
zero =
- rewriter.create<arith::ConstantIndexOp>(op.getLoc(), /*value=*/0);
+ arith::ConstantIndexOp::create(rewriter, op.getLoc(), /*value=*/0);
}
rewriter.replaceAllUsesWith(id, zero);
simplified = true;
@@ -1381,10 +1384,10 @@ static void printLaunchFuncOperands(OpAsmPrinter &printer, Operation *,
void ShuffleOp::build(OpBuilder &builder, OperationState &result, Value value,
int32_t offset, int32_t width, ShuffleMode mode) {
build(builder, result, value,
- builder.create<arith::ConstantOp>(result.location,
- builder.getI32IntegerAttr(offset)),
- builder.create<arith::ConstantOp>(result.location,
- builder.getI32IntegerAttr(width)),
+ arith::ConstantOp::create(builder, result.location,
+ builder.getI32IntegerAttr(offset)),
+ arith::ConstantOp::create(builder, result.location,
+ builder.getI32IntegerAttr(width)),
mode);
}
@@ -1395,10 +1398,10 @@ void ShuffleOp::build(OpBuilder &builder, OperationState &result, Value value,
void RotateOp::build(OpBuilder &builder, OperationState &result, Value value,
int32_t offset, int32_t width) {
build(builder, result, value,
- builder.create<arith::ConstantOp>(result.location,
- builder.getI32IntegerAttr(offset)),
- builder.create<arith::ConstantOp>(result.location,
- builder.getI32IntegerAttr(width)));
+ arith::ConstantOp::create(builder, result.location,
+ builder.getI32IntegerAttr(offset)),
+ arith::ConstantOp::create(builder, result.location,
+ ...
[truncated]
|
See #147168 for more info.