Add op create helper on CFG and ML builder.
Add create function on builder to make it easier to create ops of registered types. Enables doing `builder.create<AddFOp>(lhs, rhs)` as well as having default values on the build method.
This CL does not add a default build method (i.e., create<DimOp>(...) would fail).
PiperOrigin-RevId: 207268882
diff --git a/include/mlir/IR/Builders.h b/include/mlir/IR/Builders.h
index 3e4bbd7..795dde4 100644
--- a/include/mlir/IR/Builders.h
+++ b/include/mlir/IR/Builders.h
@@ -171,6 +171,12 @@
return op;
}
+ // Create operation of specific op type at the current insertion point.
+ template <typename OpTy, typename... Args>
+ OpPointer<OpTy> create(Args... args) {
+ return OpTy::build(this, args...);
+ }
+
// Terminators.
ReturnInst *createReturnInst(ArrayRef<CFGValue *> operands) {
@@ -262,6 +268,12 @@
return op;
}
+ // Create operation of specific op type at the current insertion point.
+ template <typename OpTy, typename... Args>
+ OpPointer<OpTy> create(Args... args) {
+ return OpTy::build(this, args...);
+ }
+
// Creates for statement. When step is not specified, it is set to 1.
ForStmt *createFor(AffineConstantExpr *lowerBound,
AffineConstantExpr *upperBound,