Skip to content

Commit dce6679

Browse files
authored
[mlir][NFC] update mlir/Dialect create APIs (16/n) (#149922)
See #147168 for more info.
1 parent 9844ba6 commit dce6679

27 files changed

+236
-219
lines changed

mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Operation *complex::ComplexDialect::materializeConstant(OpBuilder &builder,
4848
Type type,
4949
Location loc) {
5050
if (complex::ConstantOp::isBuildableWith(value, type)) {
51-
return builder.create<complex::ConstantOp>(loc, type,
52-
llvm::cast<ArrayAttr>(value));
51+
return complex::ConstantOp::create(builder, loc, type,
52+
llvm::cast<ArrayAttr>(value));
5353
}
5454
return arith::ConstantOp::materialize(builder, value, type, loc);
5555
}

mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ struct SimplifyCondBranchIdenticalSuccessors
312312
if (std::get<0>(it) == std::get<1>(it))
313313
mergedOperands.push_back(std::get<0>(it));
314314
else
315-
mergedOperands.push_back(rewriter.create<arith::SelectOp>(
316-
condbr.getLoc(), condition, std::get<0>(it), std::get<1>(it)));
315+
mergedOperands.push_back(
316+
arith::SelectOp::create(rewriter, condbr.getLoc(), condition,
317+
std::get<0>(it), std::get<1>(it)));
317318
}
318319

319320
rewriter.replaceOpWithNewOp<BranchOp>(condbr, trueDest, mergedOperands);
@@ -412,8 +413,8 @@ struct CondBranchTruthPropagation : public OpRewritePattern<CondBranchOp> {
412413
replaced = true;
413414

414415
if (!constantTrue)
415-
constantTrue = rewriter.create<arith::ConstantOp>(
416-
condbr.getLoc(), ty, rewriter.getBoolAttr(true));
416+
constantTrue = arith::ConstantOp::create(
417+
rewriter, condbr.getLoc(), ty, rewriter.getBoolAttr(true));
417418

418419
rewriter.modifyOpInPlace(use.getOwner(),
419420
[&] { use.set(constantTrue); });
@@ -427,8 +428,8 @@ struct CondBranchTruthPropagation : public OpRewritePattern<CondBranchOp> {
427428
replaced = true;
428429

429430
if (!constantFalse)
430-
constantFalse = rewriter.create<arith::ConstantOp>(
431-
condbr.getLoc(), ty, rewriter.getBoolAttr(false));
431+
constantFalse = arith::ConstantOp::create(
432+
rewriter, condbr.getLoc(), ty, rewriter.getBoolAttr(false));
432433

433434
rewriter.modifyOpInPlace(use.getOwner(),
434435
[&] { use.set(constantFalse); });

mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ struct CondBranchOpInterface
8787
destOperands.getAsOperandRange(), toRetain);
8888
SmallVector<Value> adaptedConditions(
8989
llvm::map_range(conditions, conditionModifier));
90-
auto deallocOp = builder.create<bufferization::DeallocOp>(
91-
condBr.getLoc(), memrefs, adaptedConditions, toRetain);
90+
auto deallocOp = bufferization::DeallocOp::create(
91+
builder, condBr.getLoc(), memrefs, adaptedConditions, toRetain);
9292
state.resetOwnerships(deallocOp.getRetained(), condBr->getBlock());
9393
for (auto [retained, ownership] : llvm::zip(
9494
deallocOp.getRetained(), deallocOp.getUpdatedConditions())) {
@@ -115,18 +115,19 @@ struct CondBranchOpInterface
115115
DeallocOp thenTakenDeallocOp = insertDeallocForBranch(
116116
condBr.getTrueDest(), condBr.getTrueDestOperandsMutable(),
117117
[&](Value cond) {
118-
return builder.create<arith::AndIOp>(condBr.getLoc(), cond,
119-
condBr.getCondition());
118+
return arith::AndIOp::create(builder, condBr.getLoc(), cond,
119+
condBr.getCondition());
120120
},
121121
thenMapping);
122122
DeallocOp elseTakenDeallocOp = insertDeallocForBranch(
123123
condBr.getFalseDest(), condBr.getFalseDestOperandsMutable(),
124124
[&](Value cond) {
125-
Value trueVal = builder.create<arith::ConstantOp>(
126-
condBr.getLoc(), builder.getBoolAttr(true));
127-
Value negation = builder.create<arith::XOrIOp>(
128-
condBr.getLoc(), trueVal, condBr.getCondition());
129-
return builder.create<arith::AndIOp>(condBr.getLoc(), cond, negation);
125+
Value trueVal = arith::ConstantOp::create(builder, condBr.getLoc(),
126+
builder.getBoolAttr(true));
127+
Value negation = arith::XOrIOp::create(
128+
builder, condBr.getLoc(), trueVal, condBr.getCondition());
129+
return arith::AndIOp::create(builder, condBr.getLoc(), cond,
130+
negation);
130131
},
131132
elseMapping);
132133

@@ -143,9 +144,9 @@ struct CondBranchOpInterface
143144

144145
for (Value retained : commonValues) {
145146
state.resetOwnerships(retained, condBr->getBlock());
146-
Value combinedOwnership = builder.create<arith::SelectOp>(
147-
condBr.getLoc(), condBr.getCondition(), thenMapping[retained],
148-
elseMapping[retained]);
147+
Value combinedOwnership = arith::SelectOp::create(
148+
builder, condBr.getLoc(), condBr.getCondition(),
149+
thenMapping[retained], elseMapping[retained]);
149150
state.updateOwnership(retained, combinedOwnership, condBr->getBlock());
150151
}
151152

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ void EmitCDialect::initialize() {
4747
Operation *EmitCDialect::materializeConstant(OpBuilder &builder,
4848
Attribute value, Type type,
4949
Location loc) {
50-
return builder.create<emitc::ConstantOp>(loc, type, value);
50+
return emitc::ConstantOp::create(builder, loc, type, value);
5151
}
5252

5353
/// Default callback for builders of ops carrying a region. Inserts a yield
5454
/// without arguments.
5555
void mlir::emitc::buildTerminatedBody(OpBuilder &builder, Location loc) {
56-
builder.create<emitc::YieldOp>(loc);
56+
emitc::YieldOp::create(builder, loc);
5757
}
5858

5959
bool mlir::emitc::isSupportedEmitCType(Type type) {

mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ExpressionOp createExpression(Operation *op, OpBuilder &builder) {
2424
Location loc = op->getLoc();
2525

2626
builder.setInsertionPointAfter(op);
27-
auto expressionOp = builder.create<emitc::ExpressionOp>(loc, resultType);
27+
auto expressionOp = emitc::ExpressionOp::create(builder, loc, resultType);
2828

2929
// Replace all op's uses with the new expression's result.
3030
result.replaceAllUsesWith(expressionOp.getResult());
@@ -33,7 +33,7 @@ ExpressionOp createExpression(Operation *op, OpBuilder &builder) {
3333
Region &region = expressionOp.getRegion();
3434
Block &block = region.emplaceBlock();
3535
builder.setInsertionPointToEnd(&block);
36-
auto yieldOp = builder.create<emitc::YieldOp>(loc, result);
36+
auto yieldOp = emitc::YieldOp::create(builder, loc, result);
3737

3838
// Move op into the new expression.
3939
op->moveBefore(yieldOp);

mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Value materializeAsUnrealizedCast(OpBuilder &builder, Type resultType,
2121
if (inputs.size() != 1)
2222
return Value();
2323

24-
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
24+
return UnrealizedConversionCastOp::create(builder, loc, resultType, inputs)
2525
.getResult(0);
2626
}
2727

mlir/lib/Dialect/EmitC/Transforms/WrapFuncInClass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
5050
PatternRewriter &rewriter) const override {
5151

5252
auto className = funcOp.getSymNameAttr().str() + "Class";
53-
ClassOp newClassOp = rewriter.create<ClassOp>(funcOp.getLoc(), className);
53+
ClassOp newClassOp = ClassOp::create(rewriter, funcOp.getLoc(), className);
5454

5555
SmallVector<std::pair<StringAttr, TypeAttr>> fields;
5656
rewriter.createBlock(&newClassOp.getBody());
@@ -67,15 +67,15 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
6767

6868
TypeAttr typeAttr = TypeAttr::get(val.getType());
6969
fields.push_back({fieldName, typeAttr});
70-
rewriter.create<emitc::FieldOp>(funcOp.getLoc(), fieldName, typeAttr,
71-
argAttr);
70+
emitc::FieldOp::create(rewriter, funcOp.getLoc(), fieldName, typeAttr,
71+
argAttr);
7272
}
7373

7474
rewriter.setInsertionPointToEnd(&newClassOp.getBody().front());
7575
FunctionType funcType = funcOp.getFunctionType();
7676
Location loc = funcOp.getLoc();
7777
FuncOp newFuncOp =
78-
rewriter.create<emitc::FuncOp>(loc, ("execute"), funcType);
78+
emitc::FuncOp::create(rewriter, loc, ("execute"), funcType);
7979

8080
rewriter.createBlock(&newFuncOp.getBody());
8181
newFuncOp.getBody().takeBody(funcOp.getBody());
@@ -85,7 +85,7 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
8585
newArguments.reserve(fields.size());
8686
for (auto &[fieldName, attr] : fields) {
8787
GetFieldOp arg =
88-
rewriter.create<emitc::GetFieldOp>(loc, attr.getValue(), fieldName);
88+
emitc::GetFieldOp::create(rewriter, loc, attr.getValue(), fieldName);
8989
newArguments.push_back(arg);
9090
}
9191

mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ struct FuncInlinerInterface : public DialectInlinerInterface {
6161

6262
// Replace the return with a branch to the dest.
6363
OpBuilder builder(op);
64-
builder.create<cf::BranchOp>(op->getLoc(), newDest, returnOp.getOperands());
64+
cf::BranchOp::create(builder, op->getLoc(), newDest,
65+
returnOp.getOperands());
6566
op->erase();
6667
}
6768

mlir/lib/Dialect/Func/IR/FuncOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ void FuncDialect::initialize() {
5050
Operation *FuncDialect::materializeConstant(OpBuilder &builder, Attribute value,
5151
Type type, Location loc) {
5252
if (ConstantOp::isBuildableWith(value, type))
53-
return builder.create<ConstantOp>(loc, type,
54-
llvm::cast<FlatSymbolRefAttr>(value));
53+
return ConstantOp::create(builder, loc, type,
54+
llvm::cast<FlatSymbolRefAttr>(value));
5555
return nullptr;
5656
}
5757

mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ transform::CastAndCallOp::apply(transform::TransformRewriter &rewriter,
170170
}
171171
}
172172

173-
auto callOp = rewriter.create<func::CallOp>(insertionPoint->getLoc(),
174-
targetFunction, inputs);
173+
auto callOp = func::CallOp::create(rewriter, insertionPoint->getLoc(),
174+
targetFunction, inputs);
175175

176176
// Cast the call results back to the expected types. If any conversions fail
177177
// this is a definite failure as the call has been constructed at this point.

0 commit comments

Comments
 (0)