Clean up the op builder APIs, and simplify the implementation of ops by making
OperationState contain a context and have the generic builder mechanics handle
the job of initializing the OperationState and setting the op name. NFC.
PiperOrigin-RevId: 209869948
diff --git a/include/mlir/IR/Builders.h b/include/mlir/IR/Builders.h
index 44fa224..95d73a4 100644
--- a/include/mlir/IR/Builders.h
+++ b/include/mlir/IR/Builders.h
@@ -175,7 +175,9 @@
/// Create operation of specific op type at the current insertion point.
template <typename OpTy, typename... Args>
OpPointer<OpTy> create(Args... args) {
- auto *inst = createOperation(OpTy::build(this, args...));
+ OperationState state(getContext(), OpTy::getOperationName());
+ OpTy::build(this, &state, args...);
+ auto *inst = createOperation(state);
auto result = inst->template getAs<OpTy>();
assert(result && "Builder didn't return the right type");
return result;
@@ -279,7 +281,9 @@
/// Create operation of specific op type at the current insertion point.
template <typename OpTy, typename... Args>
OpPointer<OpTy> create(Args... args) {
- auto stmt = createOperation(OpTy::build(this, args...));
+ OperationState state(getContext(), OpTy::getOperationName());
+ OpTy::build(this, &state, args...);
+ auto *stmt = createOperation(state);
auto result = stmt->template getAs<OpTy>();
assert(result && "Builder didn't return the right type");
return result;