Skip to content

Commit 284a5c2

Browse files
authored
[mlir][NFC] update mlir/examples create APIs (31/n) (llvm#150652)
See llvm#147168 for more info.
1 parent c090ed5 commit 284a5c2

File tree

29 files changed

+235
-228
lines changed

29 files changed

+235
-228
lines changed

mlir/docs/Interfaces.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def MyInterface : OpInterface<"MyInterface"> {
563563
template <typename ConcreteOp>
564564
struct Model : public Concept {
565565
Operation *create(OpBuilder &builder, Location loc) const override {
566-
return builder.create<ConcreteOp>(loc);
566+
return ConcreteOp::create(builder, loc);
567567
}
568568
}
569569
};
@@ -574,7 +574,7 @@ def MyInterface : OpInterface<"MyInterface"> {
574574
}],
575575
"Operation *", "create", (ins "OpBuilder &":$builder, "Location":$loc),
576576
/*methodBody=*/[{
577-
return builder.create<ConcreteOp>(loc);
577+
return ConcreteOp::create(builder, loc);
578578
}]>,
579579
580580
InterfaceMethod<[{

mlir/docs/PDLL.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ be defined by specifying a string code block after the rewrite declaration:
14831483
14841484
```pdll
14851485
Rewrite BuildOp(value: Value) -> (foo: Op<my_dialect.foo>, bar: Op<my_dialect.bar>) [{
1486-
return {rewriter.create<my_dialect::FooOp>(value), rewriter.create<my_dialect::BarOp>()};
1486+
return {my_dialect::FooOp::create(rewriter, value), my_dialect::BarOp::create(rewriter)};
14871487
}];
14881488
14891489
Pattern {
@@ -1508,7 +1508,7 @@ translated into:
15081508

15091509
```c++
15101510
std::tuple<my_dialect::FooOp, my_dialect::BarOp> BuildOp(Value value) {
1511-
return {rewriter.create<my_dialect::FooOp>(value), rewriter.create<my_dialect::BarOp>()};
1511+
return {my_dialect::FooOp::create(rewriter, value), my_dialect::BarOp::create(rewriter)};
15121512
}
15131513
```
15141514
@@ -1530,23 +1530,23 @@ below describes the various result translation scenarios:
15301530
15311531
```pdll
15321532
Rewrite createOp() [{
1533-
rewriter.create<my_dialect::FooOp>();
1533+
my_dialect::FooOp::create(rewriter);
15341534
}];
15351535
```
15361536

15371537
In the case where a native `Rewrite` has no results, the native function returns `void`:
15381538

15391539
```c++
15401540
void createOp(PatternRewriter &rewriter) {
1541-
rewriter.create<my_dialect::FooOp>();
1541+
my_dialect::FooOp::create(rewriter);
15421542
}
15431543
```
15441544
15451545
* Single Result
15461546
15471547
```pdll
15481548
Rewrite createOp() -> Op<my_dialect.foo> [{
1549-
return rewriter.create<my_dialect::FooOp>();
1549+
return my_dialect::FooOp::create(rewriter);
15501550
}];
15511551
```
15521552

@@ -1555,7 +1555,7 @@ native type for that single result:
15551555

15561556
```c++
15571557
my_dialect::FooOp createOp(PatternRewriter &rewriter) {
1558-
return rewriter.create<my_dialect::FooOp>();
1558+
return my_dialect::FooOp::create(rewriter);
15591559
}
15601560
```
15611561

mlir/docs/Tutorials/QuickstartRewrites.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def : Pat<(TF_LeakyReluOp:$old_value, $arg, F32Attr:$a),
130130
```c++
131131
static Value createTFLLeakyRelu(PatternRewriter &rewriter, Operation *op,
132132
Value operand, Attribute attr) {
133-
return rewriter.create<mlir::TFL::LeakyReluOp>(
133+
return mlir::TFL::LeakyReluOp::create(rewriter,
134134
op->getLoc(), operands[0].getType(), /*arg=*/operands[0],
135135
/*alpha=*/cast<FloatAttr>(attrs[0]));
136136
}
@@ -194,10 +194,10 @@ LogicalResult circt::MulOp::canonicalize(MulOp op, PatternRewriter &rewriter) {
194194
// mul(x, c) -> shl(x, log2(c)), where c is a power of two.
195195
if (inputs.size() == 2 && matchPattern(inputs.back(), m_RConstant(value)) &&
196196
value.isPowerOf2()) {
197-
auto shift = rewriter.create<rtl::ConstantOp>(op.getLoc(), op.getType(),
197+
auto shift = rtl::ConstantOp::create(rewriter, op.getLoc(), op.getType(),
198198
value.exactLogBase2());
199199
auto shlOp =
200-
rewriter.create<comb::ShlOp>(op.getLoc(), inputs[0], shift);
200+
comb::ShlOp::create(rewriter, op.getLoc(), inputs[0], shift);
201201
rewriter.replaceOpWithNewOp<MulOp>(op, op.getType(),
202202
ArrayRef<Value>(shlOp));
203203
return success();

mlir/docs/Tutorials/Toy/Ch-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def ConstantOp : Toy_Op<"constant"> {
521521
522522
// Add custom build methods for the constant operation. These methods populate
523523
// the `state` that MLIR uses to create operations, i.e. these are used when
524-
// using `builder.create<ConstantOp>(...)`.
524+
// using `ConstantOp::create(builder, ...)`.
525525
let builders = [
526526
// Build a constant with a given constant tensor value.
527527
OpBuilder<(ins "DenseElementsAttr":$value), [{

mlir/docs/Tutorials/Toy/Ch-4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
300300
Operation *materializeCallConversion(OpBuilder &builder, Value input,
301301
Type resultType,
302302
Location conversionLoc) const final {
303-
return builder.create<CastOp>(conversionLoc, resultType, input);
303+
return CastOp::create(builder, conversionLoc, resultType, input);
304304
}
305305
};
306306
```

mlir/docs/Tutorials/Toy/Ch-5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct TransposeOpLowering : public mlir::ConversionPattern {
136136
// Transpose the elements by generating a load from the reverse
137137
// indices.
138138
SmallVector<mlir::Value, 2> reverseIvs(llvm::reverse(loopIvs));
139-
return rewriter.create<mlir::AffineLoadOp>(loc, input, reverseIvs);
139+
return mlir::AffineLoadOp::create(rewriter, loc, input, reverseIvs);
140140
});
141141
return success();
142142
}

mlir/docs/Tutorials/Toy/Ch-6.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static FlatSymbolRefAttr getOrInsertPrintf(PatternRewriter &rewriter,
4747
// Insert the printf function into the body of the parent module.
4848
PatternRewriter::InsertionGuard insertGuard(rewriter);
4949
rewriter.setInsertionPointToStart(module.getBody());
50-
rewriter.create<LLVM::LLVMFuncOp>(module.getLoc(), "printf", llvmFnType);
50+
LLVM::LLVMFuncOp::create(rewriter, module.getLoc(), "printf", llvmFnType);
5151
return SymbolRefAttr::get("printf", context);
5252
}
5353
```

mlir/docs/Tutorials/Toy/Ch-7.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ mlir::Operation *ToyDialect::materializeConstant(mlir::OpBuilder &builder,
488488
mlir::Type type,
489489
mlir::Location loc) {
490490
if (isa<StructType>(type))
491-
return builder.create<StructConstantOp>(loc, type,
491+
return StructConstantOp::create(builder, loc, type,
492492
cast<mlir::ArrayAttr>(value));
493-
return builder.create<ConstantOp>(loc, type,
493+
return ConstantOp::create(builder, loc, type,
494494
cast<mlir::DenseElementsAttr>(value));
495495
}
496496
```

mlir/examples/toy/Ch2/include/toy/Ops.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def ConstantOp : Toy_Op<"constant", [Pure]> {
7070

7171
// Add custom build methods for the constant operation. These method populates
7272
// the `state` that MLIR uses to create operations, i.e. these are used when
73-
// using `builder.create<ConstantOp>(...)`.
73+
// using `ConstantOp::create(builder, ...)`.
7474
let builders = [
7575
// Build a constant with a given constant tensor value.
7676
OpBuilder<(ins "DenseElementsAttr":$value), [{

mlir/examples/toy/Ch2/mlir/MLIRGen.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class MLIRGenImpl {
121121
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
122122
getType(VarType{}));
123123
auto funcType = builder.getFunctionType(argTypes, {});
124-
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
125-
funcType);
124+
return mlir::toy::FuncOp::create(builder, location, proto.getName(),
125+
funcType);
126126
}
127127

128128
/// Emit a new function and add it to the MLIR module.
@@ -166,7 +166,7 @@ class MLIRGenImpl {
166166
if (!entryBlock.empty())
167167
returnOp = dyn_cast<ReturnOp>(entryBlock.back());
168168
if (!returnOp) {
169-
builder.create<ReturnOp>(loc(funcAST.getProto()->loc()));
169+
ReturnOp::create(builder, loc(funcAST.getProto()->loc()));
170170
} else if (returnOp.hasOperand()) {
171171
// Otherwise, if this return operation has an operand then add a result to
172172
// the function.
@@ -202,9 +202,9 @@ class MLIRGenImpl {
202202
// support '+' and '*'.
203203
switch (binop.getOp()) {
204204
case '+':
205-
return builder.create<AddOp>(location, lhs, rhs);
205+
return AddOp::create(builder, location, lhs, rhs);
206206
case '*':
207-
return builder.create<MulOp>(location, lhs, rhs);
207+
return MulOp::create(builder, location, lhs, rhs);
208208
}
209209

210210
emitError(location, "invalid binary operator '") << binop.getOp() << "'";
@@ -235,8 +235,8 @@ class MLIRGenImpl {
235235
}
236236

237237
// Otherwise, this return operation has zero operands.
238-
builder.create<ReturnOp>(location,
239-
expr ? ArrayRef(expr) : ArrayRef<mlir::Value>());
238+
ReturnOp::create(builder, location,
239+
expr ? ArrayRef(expr) : ArrayRef<mlir::Value>());
240240
return mlir::success();
241241
}
242242

@@ -280,7 +280,7 @@ class MLIRGenImpl {
280280

281281
// Build the MLIR op `toy.constant`. This invokes the `ConstantOp::build`
282282
// method.
283-
return builder.create<ConstantOp>(loc(lit.loc()), type, dataAttribute);
283+
return ConstantOp::create(builder, loc(lit.loc()), type, dataAttribute);
284284
}
285285

286286
/// Recursive helper function to accumulate the data that compose an array
@@ -325,13 +325,13 @@ class MLIRGenImpl {
325325
"does not accept multiple arguments");
326326
return nullptr;
327327
}
328-
return builder.create<TransposeOp>(location, operands[0]);
328+
return TransposeOp::create(builder, location, operands[0]);
329329
}
330330

331331
// Otherwise this is a call to a user-defined function. Calls to
332332
// user-defined functions are mapped to a custom call that takes the callee
333333
// name as an attribute.
334-
return builder.create<GenericCallOp>(location, callee, operands);
334+
return GenericCallOp::create(builder, location, callee, operands);
335335
}
336336

337337
/// Emit a print expression. It emits specific operations for two builtins:
@@ -341,13 +341,13 @@ class MLIRGenImpl {
341341
if (!arg)
342342
return mlir::failure();
343343

344-
builder.create<PrintOp>(loc(call.loc()), arg);
344+
PrintOp::create(builder, loc(call.loc()), arg);
345345
return mlir::success();
346346
}
347347

348348
/// Emit a constant for a single number (FIXME: semantic? broadcast?)
349349
mlir::Value mlirGen(NumberExprAST &num) {
350-
return builder.create<ConstantOp>(loc(num.loc()), num.getValue());
350+
return ConstantOp::create(builder, loc(num.loc()), num.getValue());
351351
}
352352

353353
/// Dispatch codegen for the right expression subclass using RTTI.
@@ -391,8 +391,8 @@ class MLIRGenImpl {
391391
// with specific shape, we emit a "reshape" operation. It will get
392392
// optimized out later as needed.
393393
if (!vardecl.getType().shape.empty()) {
394-
value = builder.create<ReshapeOp>(loc(vardecl.loc()),
395-
getType(vardecl.getType()), value);
394+
value = ReshapeOp::create(builder, loc(vardecl.loc()),
395+
getType(vardecl.getType()), value);
396396
}
397397

398398
// Register the value in the symbol table.

0 commit comments

Comments
 (0)