[Mlir-commits] [mlir] 4f0e0d9 - [mlir] Remove more OpBuilder args which are now injected

Jacques Pienaar llvmlistbot at llvm.org
Tue Sep 29 16:47:56 PDT 2020


Author: Jacques Pienaar
Date: 2020-09-29T16:47:21-07:00
New Revision: 4f0e0d92178d57137e26b1ac1be5f0409791912a

URL: https://github.com/llvm/llvm-project/commit/4f0e0d92178d57137e26b1ac1be5f0409791912a
DIFF: https://github.com/llvm/llvm-project/commit/4f0e0d92178d57137e26b1ac1be5f0409791912a.diff

LOG: [mlir] Remove more OpBuilder args which are now injected

NFC. Some small changes to make things more consistent but primarily
avoiding old behavior without any further change.

Added: 
    

Modified: 
    mlir/docs/Tutorials/Toy/Ch-2.md
    mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
    mlir/include/mlir/Dialect/GPU/GPUOps.td
    mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    mlir/include/mlir/Dialect/SCF/SCFOps.td
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
    mlir/include/mlir/Dialect/Vector/VectorOps.td
    mlir/test/lib/Dialect/Test/TestOps.td

Removed: 
    


################################################################################
diff  --git a/mlir/docs/Tutorials/Toy/Ch-2.md b/mlir/docs/Tutorials/Toy/Ch-2.md
index cc5b380a9f62..89134e264aa0 100644
--- a/mlir/docs/Tutorials/Toy/Ch-2.md
+++ b/mlir/docs/Tutorials/Toy/Ch-2.md
@@ -490,15 +490,14 @@ def ConstantOp : Toy_Op<"constant"> {
   // using `builder.create<ConstantOp>(...)`.
   let builders = [
     // Build a constant with a given constant tensor value.
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "DenseElementsAttr value", [{
+    OpBuilder<"DenseElementsAttr value", [{
       // Call into an autogenerated `build` method.
       build(builder, result, value.getType(), value);
     }]>,
 
     // Build a constant with a given constant floating-point value. This builder
     // creates a declaration for `ConstantOp::build` with the given parameters.
-    OpBuilder<"OpBuilder &builder, OperationState &result, double value">
+    OpBuilder<"double value">
   ];
 }
 ```

diff  --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
index 4294b88553f4..c47dcd3d5fe2 100644
--- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
+++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
@@ -73,9 +73,8 @@ def AffineApplyOp : Affine_Op<"apply", [NoSideEffect]> {
   // has a constant builder. That way we wouldn't need to explicitly specify the
   // result types here.
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "AffineMap map, ValueRange mapOperands", [{
-      build(builder, result, builder.getIndexType(), map, mapOperands);
+    OpBuilder<"AffineMap map, ValueRange mapOperands", [{
+      build($_builder, $_state, $_builder.getIndexType(), map, mapOperands);
     }]>
   ];
 
@@ -214,12 +213,10 @@ def AffineForOp : Affine_Op<"for",
 
   let skipDefaultBuilders = 1;
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "int64_t lowerBound, int64_t upperBound, int64_t step = 1, "
+    OpBuilder<"int64_t lowerBound, int64_t upperBound, int64_t step = 1, "
               "ValueRange iterArgs = llvm::None, function_ref<void(OpBuilder "
               "&, Location, Value, ValueRange)> bodyBuilder = nullptr">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "ValueRange lbOperands, AffineMap lbMap, "
+    OpBuilder<"ValueRange lbOperands, AffineMap lbMap, "
               "ValueRange ubOperands, AffineMap ubMap, "
               "int64_t step = 1, ValueRange iterArgs = llvm::None, "
               "function_ref<void(OpBuilder &, Location, Value, ValueRange)> "
@@ -413,10 +410,8 @@ def AffineIfOp : Affine_Op<"if",
   let skipDefaultBuilders = 1;
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "IntegerSet set, ValueRange args, bool withElseRegion">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "TypeRange resultTypes, IntegerSet set, ValueRange args,"
+    OpBuilder<"IntegerSet set, ValueRange args, bool withElseRegion">,
+    OpBuilder<"TypeRange resultTypes, IntegerSet set, ValueRange args,"
               "bool withElseRegion">,
   ];
 
@@ -508,14 +503,11 @@ def AffineLoadOp : AffineLoadOpBase<"load"> {
 
   let builders = [
     /// Builds an affine load op with the specified map and operands.
-    OpBuilder<"OpBuilder &builder, OperationState &result, AffineMap map, "
-                      "ValueRange operands">,
+    OpBuilder<"AffineMap map, ValueRange operands">,
     /// Builds an affine load op with an identity map and operands.
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value memref, "
-                      "ValueRange indices = {}">,
+    OpBuilder<"Value memref, ValueRange indices = {}">,
     /// Builds an affine load op with the specified map and its operands.
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value memref, "
-                      "AffineMap map, ValueRange mapOperands">
+    OpBuilder<"Value memref, AffineMap map, ValueRange mapOperands">
   ];
 
   let extraClassDeclaration = extraClassDeclarationBase;
@@ -530,10 +522,9 @@ class AffineMinMaxOpBase<string mnemonic, list<OpTrait> traits = []> :
   let results = (outs Index);
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, AffineMap affineMap, "
-              "ValueRange mapOperands",
+    OpBuilder<"AffineMap affineMap, ValueRange mapOperands",
     [{
-      build(builder, result, builder.getIndexType(), affineMap, mapOperands);
+      build($_builder, $_state, $_builder.getIndexType(), affineMap, mapOperands);
     }]>
   ];
 
@@ -656,17 +647,14 @@ def AffineParallelOp : Affine_Op<"parallel",
   let regions = (region SizedRegion<1>:$region);
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "TypeRange resultTypes, "
+    OpBuilder<"TypeRange resultTypes, "
               "ArrayRef<AtomicRMWKind> reductions, "
               "ArrayRef<int64_t> ranges">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "TypeRange resultTypes, "
+    OpBuilder<"TypeRange resultTypes, "
               "ArrayRef<AtomicRMWKind> reductions, "
               "AffineMap lbMap, ValueRange lbArgs, "
               "AffineMap ubMap, ValueRange ubArgs">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "TypeRange resultTypes, "
+    OpBuilder<"TypeRange resultTypes, "
               "ArrayRef<AtomicRMWKind> reductions, "
               "AffineMap lbMap, ValueRange lbArgs, "
               "AffineMap ubMap, ValueRange ubArgs, "
@@ -736,21 +724,20 @@ def AffinePrefetchOp : Affine_Op<"prefetch"> {
                    BoolAttr:$isDataCache);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value memref,"
-    "AffineMap map, ArrayRef<Value> mapOperands, bool isWrite,"
+    "Value memref, AffineMap map, ArrayRef<Value> mapOperands, bool isWrite,"
     "unsigned localityHint, bool isDataCache",
     [{
       assert(map.getNumInputs() == mapOperands.size()
              && "inconsistent index info");
-      auto localityHintAttr = builder.getI32IntegerAttr(localityHint);
-      auto isWriteAttr = builder.getBoolAttr(isWrite);
-      auto isDataCacheAttr = builder.getBoolAttr(isDataCache);
-      result.addOperands(memref);
-      result.addAttribute(getMapAttrName(), AffineMapAttr::get(map));
-      result.addOperands(mapOperands);
-      result.addAttribute(getLocalityHintAttrName(), localityHintAttr);
-      result.addAttribute(getIsWriteAttrName(), isWriteAttr);
-      result.addAttribute(getIsDataCacheAttrName(), isDataCacheAttr);
+      auto localityHintAttr = $_builder.getI32IntegerAttr(localityHint);
+      auto isWriteAttr = $_builder.getBoolAttr(isWrite);
+      auto isDataCacheAttr = $_builder.getBoolAttr(isDataCache);
+      $_state.addOperands(memref);
+      $_state.addAttribute(getMapAttrName(), AffineMapAttr::get(map));
+      $_state.addOperands(mapOperands);
+      $_state.addAttribute(getLocalityHintAttrName(), localityHintAttr);
+      $_state.addAttribute(getIsWriteAttrName(), isWriteAttr);
+      $_state.addAttribute(getIsDataCacheAttrName(), isDataCacheAttr);
     }]>];
 
   let extraClassDeclaration = [{
@@ -844,11 +831,9 @@ def AffineStoreOp : AffineStoreOpBase<"store"> {
 
   let skipDefaultBuilders = 1;
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-                      "Value valueToStore, Value memref, ValueRange indices">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-                      "Value valueToStore, Value memref, AffineMap map, "
-                      "ValueRange mapOperands">
+    OpBuilder<"Value valueToStore, Value memref, ValueRange indices">,
+    OpBuilder<"Value valueToStore, Value memref, AffineMap map, "
+              "ValueRange mapOperands">
   ];
 
   let extraClassDeclaration = extraClassDeclarationBase;
@@ -874,9 +859,9 @@ def AffineYieldOp : Affine_Op<"yield", [NoSideEffect, Terminator, ReturnLike]> {
 
   let arguments = (ins Variadic<AnyType>:$operands);
 
-  let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result", [{ build(b, result, llvm::None); }]
-  >];
+  let builders = [
+    OpBuilder<"", [{ build($_builder, $_state, llvm::None); }]>
+  ];
 
   let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
 }

diff  --git a/mlir/include/mlir/Dialect/GPU/GPUOps.td b/mlir/include/mlir/Dialect/GPU/GPUOps.td
index fd43065e9693..03d0a89bbcda 100644
--- a/mlir/include/mlir/Dialect/GPU/GPUOps.td
+++ b/mlir/include/mlir/Dialect/GPU/GPUOps.td
@@ -201,7 +201,7 @@ def GPU_GPUFuncOp : GPU_Op<"func", [HasParent<"GPUModuleOp">,
   let skipDefaultBuilders = 1;
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, StringRef name, "
+    OpBuilder<"StringRef name, "
               "FunctionType type, TypeRange workgroupAttributions = {}, "
               "TypeRange privateAttributions = {}, "
               "ArrayRef<NamedAttribute> attrs = {}">
@@ -371,11 +371,11 @@ def GPU_LaunchFuncOp : GPU_Op<"launch_func">,
   let skipDefaultBuilders = 1;
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, GPUFuncOp kernelFunc, "
+    OpBuilder<"GPUFuncOp kernelFunc, "
               "Value gridSizeX, Value gridSizeY, Value gridSizeZ, "
               "Value blockSizeX, Value blockSizeY, Value blockSizeZ, "
               "ValueRange kernelOperands">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, GPUFuncOp kernelFunc, "
+    OpBuilder<"GPUFuncOp kernelFunc, "
               "KernelDim3 gridSize, KernelDim3 blockSize, "
               "ValueRange kernelOperands">
   ];
@@ -490,7 +490,7 @@ def GPU_LaunchOp : GPU_Op<"launch">,
   let skipDefaultBuilders = 1;
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value gridSizeX,"
+    OpBuilder<"Value gridSizeX,"
               "Value gridSizeY, Value gridSizeZ, Value blockSizeX,"
               "Value blockSizeY, Value blockSizeZ">
   ];
@@ -716,8 +716,7 @@ def GPU_GPUModuleOp : GPU_Op<"module", [
 
     ```
   }];
-  let builders = [OpBuilder<"OpBuilder &builder, OperationState &result, "
-                            "StringRef name">];
+  let builders = [OpBuilder<"StringRef name">];
   let parser = [{ return ::parseGPUModuleOp(parser, result); }];
   let printer = [{ return ::print(p, *this); }];
   let regions = (region SizedRegion<1>:$body);

diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 39f22855e80e..b5b8e45eb21f 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -23,23 +23,22 @@ class LLVM_Builder<string builder> {
 }
 
 def LLVM_OneResultOpBuilder : OpBuilder<
-  "OpBuilder &, OperationState &result, Type resultType, "
-  "ValueRange operands, ArrayRef<NamedAttribute> attributes = {}",
+  "Type resultType, ValueRange operands, "
+  "ArrayRef<NamedAttribute> attributes = {}",
   [{
-    if (resultType) result.addTypes(resultType);
-    result.addOperands(operands);
+    if (resultType) $_state.addTypes(resultType);
+    $_state.addOperands(operands);
     for (auto namedAttr : attributes) {
-      result.addAttribute(namedAttr.first, namedAttr.second);
+      $_state.addAttribute(namedAttr.first, namedAttr.second);
     }
   }]>;
 
 def LLVM_ZeroResultOpBuilder : OpBuilder<
-  "OpBuilder &, OperationState &result, ValueRange operands, "
-  "ArrayRef<NamedAttribute> attributes = {}",
+  "ValueRange operands, ArrayRef<NamedAttribute> attributes = {}",
   [{
-    result.addOperands(operands);
+    $_state.addOperands(operands);
     for (auto namedAttr : attributes) {
-      result.addAttribute(namedAttr.first, namedAttr.second);
+      $_state.addAttribute(namedAttr.first, namedAttr.second);
     }
   }]>;
 
@@ -56,14 +55,13 @@ class LLVM_OneResultOp<string mnemonic, list<OpTrait> traits = []> :
 // Compatibility builder that takes an instance of wrapped llvm::VoidType
 // to indicate no result.
 def LLVM_VoidResultTypeOpBuilder : OpBuilder<
-  "OpBuilder &builder, OperationState &result, Type resultType, "
-  "ValueRange operands, ArrayRef<NamedAttribute> attributes = {}",
+  "Type resultType, ValueRange operands, ArrayRef<NamedAttribute> attributes = {}",
   [{
     auto llvmType = resultType.dyn_cast<LLVMType>(); (void)llvmType;
     assert(llvmType && "result must be an LLVM type");
     assert(llvmType.isVoidTy() &&
            "for zero-result operands, only 'void' is accepted as result type");
-    build(builder, result, operands, attributes);
+    build($_builder, $_state, operands, attributes);
   }]>;
 
 // Base class for LLVM operations with zero results.
@@ -73,12 +71,12 @@ class LLVM_ZeroResultOp<string mnemonic, list<OpTrait> traits = []> :
 
 // Opaque builder used for terminator operations that contain successors.
 def LLVM_TerminatorPassthroughOpBuilder : OpBuilder<
-  "OpBuilder &, OperationState &result, ValueRange operands, "
-  "SuccessorRange destinations, ArrayRef<NamedAttribute> attributes = {}",
+  "ValueRange operands, SuccessorRange destinations, "
+  "ArrayRef<NamedAttribute> attributes = {}",
   [{
-    result.addOperands(operands);
-    result.addSuccessors(destinations);
-    result.addAttributes(attributes);
+    $_state.addOperands(operands);
+    $_state.addSuccessors(destinations);
+    $_state.addAttributes(attributes);
   }]>;
 
 // Base class for LLVM terminator operations.  All terminator operations have
@@ -161,10 +159,9 @@ def LLVM_ICmpOp : LLVM_OneResultOp<"icmp", [NoSideEffect]>,
     $res = builder.CreateICmp(getLLVMCmpPredicate($predicate), $lhs, $rhs);
   }];
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, ICmpPredicate predicate, Value lhs, "
-    "Value rhs", [{
-      build(b, result, LLVMType::getInt1Ty(lhs.getType().getContext()),
-            b.getI64IntegerAttr(static_cast<int64_t>(predicate)), lhs, rhs);
+    "ICmpPredicate predicate, Value lhs, Value rhs", [{
+      build($_builder, $_state, LLVMType::getInt1Ty(lhs.getType().getContext()),
+            $_builder.getI64IntegerAttr(static_cast<int64_t>(predicate)), lhs, rhs);
     }]>];
   let parser = [{ return parseCmpOp<ICmpPredicate>(parser, result); }];
   let printer = [{ printICmpOp(p, *this); }];
@@ -208,10 +205,9 @@ def LLVM_FCmpOp : LLVM_OneResultOp<"fcmp", [NoSideEffect]>,
     $res = builder.CreateFCmp(getLLVMCmpPredicate($predicate), $lhs, $rhs);
   }];
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, FCmpPredicate predicate, Value lhs, "
-    "Value rhs", [{
-      build(b, result, LLVMType::getInt1Ty(lhs.getType().getContext()),
-            b.getI64IntegerAttr(static_cast<int64_t>(predicate)), lhs, rhs);
+    "FCmpPredicate predicate, Value lhs, Value rhs", [{
+      build($_builder, $_state, LLVMType::getInt1Ty(lhs.getType().getContext()),
+            $_builder.getI64IntegerAttr(static_cast<int64_t>(predicate)), lhs, rhs);
     }]>];
   let parser = [{ return parseCmpOp<FCmpPredicate>(parser, result); }];
   let printer = [{ printFCmpOp(p, *this); }];
@@ -264,12 +260,12 @@ def LLVM_AllocaOp :
     $res = inst;
   }];
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, Type resultType, Value arraySize, "
-    "unsigned alignment",
+    "Type resultType, Value arraySize, unsigned alignment",
     [{
       if (alignment == 0)
-        return build(b, result, resultType, arraySize, IntegerAttr());
-      build(b, result, resultType, arraySize, b.getI64IntegerAttr(alignment));
+        return build($_builder, $_state, resultType, arraySize, IntegerAttr());
+      build($_builder, $_state, resultType, arraySize,
+        $_builder.getI64IntegerAttr(alignment));
   }]>];
   let parser = [{ return parseAllocaOp(parser, result); }];
   let printer = [{ printAllocaOp(p, *this); }];
@@ -297,16 +293,14 @@ def LLVM_LoadOp :
     $res = inst;
   }];
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, Value addr, "
-    "unsigned alignment = 0, bool isVolatile = false, "
+    "Value addr, unsigned alignment = 0, bool isVolatile = false, "
     "bool isNonTemporal = false",
     [{
       auto type = addr.getType().cast<LLVMType>().getPointerElementTy();
-      build(b, result, type, addr, alignment, isVolatile, isNonTemporal);
+      build($_builder, $_state, type, addr, alignment, isVolatile, isNonTemporal);
     }]>,
     OpBuilder<
-    "OpBuilder &b, OperationState &result, Type t, Value addr, "
-    "unsigned alignment = 0, bool isVolatile = false, "
+    "Type t, Value addr, unsigned alignment = 0, bool isVolatile = false, "
     "bool isNonTemporal = false">];
   let parser = [{ return parseLoadOp(parser, result); }];
   let printer = [{ printLoadOp(p, *this); }];
@@ -323,8 +317,7 @@ def LLVM_StoreOp :
     auto *inst = builder.CreateStore($value, $addr, $volatile_);
   }] # setAlignmentCode # setNonTemporalMetadataCode;
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, Value value, Value addr, "
-    "unsigned alignment = 0, bool isVolatile = false, "
+    "Value value, Value addr, unsigned alignment = 0, bool isVolatile = false, "
     "bool isNonTemporal = false">
     ];
   let parser = [{ return parseStoreOp(parser, result); }];
@@ -383,19 +376,17 @@ def LLVM_InvokeOp : LLVM_Op<"invoke", [
                               AnySuccessor:$unwindDest);
 
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, TypeRange tys, "
-    "FlatSymbolRefAttr callee, ValueRange ops, Block* normal, "
+    "TypeRange tys, FlatSymbolRefAttr callee, ValueRange ops, Block* normal, "
     "ValueRange normalOps, Block* unwind, ValueRange unwindOps",
     [{
-      result.addAttribute("callee", callee);
-      build(b, result, tys, ops, normal, normalOps, unwind, unwindOps);
+      $_state.addAttribute("callee", callee);
+      build($_builder, $_state, tys, ops, normal, normalOps, unwind, unwindOps);
     }]>,
     OpBuilder<
-    "OpBuilder &b, OperationState &result, TypeRange tys, "
-    "ValueRange ops, Block* normal, "
+    "TypeRange tys, ValueRange ops, Block* normal, "
     "ValueRange normalOps, Block* unwind, ValueRange unwindOps",
     [{
-      build(b, result, tys, /*callee=*/FlatSymbolRefAttr(), ops, normalOps,
+      build($_builder, $_state, tys, /*callee=*/FlatSymbolRefAttr(), ops, normalOps,
             unwindOps, normal, unwind);
     }]>];
   let verifier = [{ return ::verify(*this);  }];
@@ -416,15 +407,15 @@ def LLVM_CallOp : LLVM_Op<"call">,
                              Variadic<LLVM_Type>)>,
                   Results<(outs Variadic<LLVM_Type>)> {
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, LLVMFuncOp func,"
-    "ValueRange operands, ArrayRef<NamedAttribute> attributes = {}",
+    "LLVMFuncOp func, ValueRange operands, "
+    "ArrayRef<NamedAttribute> attributes = {}",
     [{
       LLVMType resultType = func.getType().getFunctionResultType();
       if (!resultType.isVoidTy())
-        result.addTypes(resultType);
-      result.addAttribute("callee", builder.getSymbolRefAttr(func));
-      result.addAttributes(attributes);
-      result.addOperands(operands);
+        $_state.addTypes(resultType);
+      $_state.addAttribute("callee", $_builder.getSymbolRefAttr(func));
+      $_state.addAttributes(attributes);
+      $_state.addOperands(operands);
     }]>];
   let verifier = [{
     if (getNumResults() > 1)
@@ -441,8 +432,7 @@ def LLVM_ExtractElementOp : LLVM_OneResultOp<"extractelement", [NoSideEffect]>,
     $res = builder.CreateExtractElement($vector, $position);
   }];
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, Value vector, Value position,"
-    "ArrayRef<NamedAttribute> attrs = {}">];
+    "Value vector, Value position, ArrayRef<NamedAttribute> attrs = {}">];
   let parser = [{ return parseExtractElementOp(parser, result); }];
   let printer = [{ printExtractElementOp(p, *this); }];
 }
@@ -474,10 +464,9 @@ def LLVM_InsertValueOp : LLVM_OneResultOp<"insertvalue", [NoSideEffect]>,
                                      extractPosition($position));
   }];
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, Value container, Value value, "
-    "ArrayAttr position",
+    "Value container, Value value, ArrayAttr position",
     [{
-      build(b, result, container.getType(), container, value, position);
+      build($_builder, $_state, container.getType(), container, value, position);
     }]>];
   let parser = [{ return parseInsertValueOp(parser, result); }];
   let printer = [{ printInsertValueOp(p, *this); }];
@@ -491,8 +480,7 @@ def LLVM_ShuffleVectorOp
       $res = builder.CreateShuffleVector($v1, $v2, mask);
   }];
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, Value v1, Value v2, "
-    "ArrayAttr mask, ArrayRef<NamedAttribute> attrs = {}">];
+    "Value v1, Value v2, ArrayAttr mask, ArrayRef<NamedAttribute> attrs = {}">];
   let verifier = [{
     auto wrappedVectorType1 = v1().getType().cast<LLVMType>();
     auto wrappedVectorType2 = v2().getType().cast<LLVMType>();
@@ -517,9 +505,8 @@ def LLVM_SelectOp
       LLVM_Builder<
           "$res = builder.CreateSelect($condition, $trueValue, $falseValue);"> {
   let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, Value condition, Value lhs, "
-    "Value rhs", [{
-      build(b, result, lhs.getType(), condition, lhs, rhs);
+    "Value condition, Value lhs, Value rhs", [{
+      build($_builder, $_state, lhs.getType(), condition, lhs, rhs);
     }]>];
   let assemblyFormat = "operands attr-dict `:` type($condition) `,` type($res)";
 }
@@ -555,22 +542,21 @@ def LLVM_CondBrOp : LLVM_TerminatorOp<"cond_br",
   }];
 
   let builders = [OpBuilder<
-     "OpBuilder &builder, OperationState &result, Value condition,"
-     "Block *trueDest, ValueRange trueOperands,"
+     "Value condition, Block *trueDest, ValueRange trueOperands,"
      "Block *falseDest, ValueRange falseOperands,"
      "Optional<std::pair<uint32_t, uint32_t>> weights = {}", [{
         ElementsAttr weightsAttr;
         if (weights) {
           weightsAttr =
-              builder.getI32VectorAttr({static_cast<int32_t>(weights->first),
+              $_builder.getI32VectorAttr({static_cast<int32_t>(weights->first),
                                        static_cast<int32_t>(weights->second)});
         }
-        build(builder, result, condition, trueOperands, falseOperands, weightsAttr,
+        build($_builder, $_state, condition, trueOperands, falseOperands, weightsAttr,
               trueDest, falseDest);
   }]>, OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value condition,"
-    "Block *trueDest, Block *falseDest, ValueRange falseOperands = {}", [{
-      build(builder, result, condition, trueDest, ValueRange(), falseDest,
+    "Value condition, Block *trueDest, Block *falseDest, "
+    "ValueRange falseOperands = {}", [{
+      build($_builder, $_state, condition, trueDest, ValueRange(), falseDest,
             falseOperands);
   }]>, LLVM_TerminatorPassthroughOpBuilder];
 }
@@ -660,21 +646,21 @@ def LLVM_AddressOfOp
   let summary = "Creates a pointer pointing to a global or a function";
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, LLVMType resType, "
+    OpBuilder<"LLVMType resType, "
               "StringRef name, ArrayRef<NamedAttribute> attrs = {}", [{
-      result.addAttribute("global_name", builder.getSymbolRefAttr(name));
-      result.addAttributes(attrs);
-      result.addTypes(resType);}]>,
+      $_state.addAttribute("global_name",$_builder.getSymbolRefAttr(name));
+      $_state.addAttributes(attrs);
+      $_state.addTypes(resType);}]>,
 
-    OpBuilder<"OpBuilder &builder, OperationState &result, GlobalOp global, "
+    OpBuilder<"GlobalOp global, "
               "ArrayRef<NamedAttribute> attrs = {}", [{
-      build(builder, result,
+      build($_builder, $_state,
             global.getType().getPointerTo(global.addr_space()),
             global.sym_name(), attrs);}]>,
 
-    OpBuilder<"OpBuilder &builder, OperationState &result, LLVMFuncOp func, "
+    OpBuilder<"LLVMFuncOp func, "
               "ArrayRef<NamedAttribute> attrs = {}", [{
-      build(builder, result,
+      build($_builder, $_state,
             func.getType().getPointerTo(), func.getName(), attrs);}]>
   ];
 
@@ -721,7 +707,7 @@ def LLVM_GlobalOp
   let regions = (region AnyRegion:$initializer);
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, LLVMType type, "
+    OpBuilder<"LLVMType type, "
               "bool isConstant, Linkage linkage, StringRef name, "
               "Attribute value, unsigned addrSpace = 0, "
               "ArrayRef<NamedAttribute> attrs = {}">
@@ -769,7 +755,7 @@ def LLVM_LLVMFuncOp
   let skipDefaultBuilders = 1;
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, StringRef name, "
+    OpBuilder<"StringRef name, "
               "LLVMType type, Linkage linkage = Linkage::External, "
               "ArrayRef<NamedAttribute> attrs = {}, "
               "ArrayRef<MutableDictionaryAttr> argAttrs = {}">

diff  --git a/mlir/include/mlir/Dialect/SCF/SCFOps.td b/mlir/include/mlir/Dialect/SCF/SCFOps.td
index 179b4d773a3a..1011e0d7ef68 100644
--- a/mlir/include/mlir/Dialect/SCF/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/SCFOps.td
@@ -135,8 +135,7 @@ def ForOp : SCF_Op<"for",
 
   let skipDefaultBuilders = 1;
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "Value lowerBound, Value upperBound, Value step, "
+    OpBuilder<"Value lowerBound, Value upperBound, Value step, "
               "ValueRange iterArgs = llvm::None, "
               "function_ref<void(OpBuilder &, Location, Value, ValueRange)>"
               "    = nullptr">
@@ -236,10 +235,8 @@ def IfOp : SCF_Op<"if",
 
   let skipDefaultBuilders = 1;
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "Value cond, bool withElseRegion">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "TypeRange resultTypes, Value cond, bool withElseRegion">,
+    OpBuilder<"Value cond, bool withElseRegion">,
+    OpBuilder<"TypeRange resultTypes, Value cond, bool withElseRegion">,
     OpBuilder<
         "OpBuilder &builder, OperationState &result, TypeRange resultTypes, "
         "Value cond, "
@@ -327,14 +324,12 @@ def ParallelOp : SCF_Op<"parallel",
 
   let skipDefaultBuilders = 1;
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "ValueRange lowerBounds, ValueRange upperBounds, "
+    OpBuilder<"ValueRange lowerBounds, ValueRange upperBounds, "
               "ValueRange steps, ValueRange initVals, "
               "function_ref<void (OpBuilder &, Location, "
                                  "ValueRange, ValueRange)>"
               "  bodyBuilderFn = nullptr">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "ValueRange lowerBounds, ValueRange upperBounds, "
+    OpBuilder<"ValueRange lowerBounds, ValueRange upperBounds, "
               "ValueRange steps, "
               "function_ref<void (OpBuilder &, Location, ValueRange)>"
               "  bodyBuilderFn = nullptr">,
@@ -390,8 +385,7 @@ def ReduceOp : SCF_Op<"reduce", [HasParent<"ParallelOp">]> {
 
   let skipDefaultBuilders = 1;
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "Value operand, "
+    OpBuilder<"Value operand, "
               "function_ref<void (OpBuilder &, Location, Value, Value)>"
               "  bodyBuilderFn = nullptr">
   ];

diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index b944b34b1d9d..235a22a2ce3d 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -124,7 +124,7 @@ def Shape_ConstSizeOp : Shape_Op<"const_size", [
   let results = (outs Shape_SizeType:$result);
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, int64_t value">
+    OpBuilder<"int64_t value">
   ];
 
   let assemblyFormat = "$value attr-dict";
@@ -231,7 +231,7 @@ def Shape_GetExtentOp : Shape_Op<"get_extent", [NoSideEffect]> {
 
   let builders = [
     // Builder that allows passing a constant dimension as a simple integer.
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value shape, "
+    OpBuilder<"Value shape, "
               "int64_t dim">
   ];
 
@@ -332,7 +332,7 @@ def Shape_NumElementsOp : Shape_Op<"num_elements", [NoSideEffect]> {
   let results = (outs Shape_SizeOrIndexType:$result);
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value shape">,
+    OpBuilder<"Value shape">,
   ];
 
   let assemblyFormat = "$shape `:` type($shape) `->` type($result) attr-dict";
@@ -383,8 +383,7 @@ def Shape_ReduceOp : Shape_Op<"reduce",
   let regions = (region SizedRegion<1>:$region);
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "Value shape, ValueRange initVals">,
+    OpBuilder<"Value shape, ValueRange initVals">,
   ];
 
   let verifier = [{ return ::verify(*this); }];
@@ -406,7 +405,7 @@ def Shape_ShapeOfOp : Shape_Op<"shape_of", [NoSideEffect]> {
   let assemblyFormat = "$arg `:` type($arg) `->` type($result) attr-dict";
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value arg">
+    OpBuilder<"Value arg">
   ];
 
   let verifier = [{ return ::verifyShapeOrExtentTensorOp(*this); }];

diff  --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
index 649e941050a3..43d47941d0ab 100644
--- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -50,8 +50,8 @@ class CastOp<string mnemonic, list<OpTrait> traits = []> :
   let results = (outs AnyType);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, Type destType", [{
-       impl::buildCastOp(builder, result, source, destType);
+    "Value source, Type destType", [{
+       impl::buildCastOp($_builder, $_state, source, destType);
   }]>];
 
   let parser = [{
@@ -162,16 +162,16 @@ class AllocLikeOp<string mnemonic,
   let results = (outs Res<AnyMemRef, "", [MemAlloc<resource>]>);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, MemRefType memrefType", [{
-       result.types.push_back(memrefType);
+    "MemRefType memrefType", [{
+       $_state.types.push_back(memrefType);
      }]>,
     OpBuilder<
-    "OpBuilder &builder, OperationState &result, MemRefType memrefType, " #
-    "ValueRange operands, IntegerAttr alignment = IntegerAttr()", [{
-       result.addOperands(operands);
-       result.types.push_back(memrefType);
+    "MemRefType memrefType, ValueRange operands, "
+    "IntegerAttr alignment = IntegerAttr()", [{
+       $_state.addOperands(operands);
+       $_state.types.push_back(memrefType);
        if (alignment)
-         result.addAttribute(getAlignmentAttrName(), alignment);
+         $_state.addAttribute(getAlignmentAttrName(), alignment);
      }]>];
 
   let extraClassDeclaration = [{
@@ -612,8 +612,7 @@ def GenericAtomicRMWOp : Std_Op<"generic_atomic_rmw", [
 
   let skipDefaultBuilders = 1;
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "Value memref, ValueRange ivs">
+    OpBuilder<"Value memref, ValueRange ivs">
   ];
 
   let extraClassDeclaration = [{
@@ -668,10 +667,9 @@ def BranchOp : Std_Op<"br",
   let arguments = (ins Variadic<AnyType>:$destOperands);
   let successors = (successor AnySuccessor:$dest);
 
-  let builders = [OpBuilder<"OpBuilder &, OperationState &result, Block *dest, "
-                            "ValueRange destOperands = {}", [{
-    result.addSuccessors(dest);
-    result.addOperands(destOperands);
+  let builders = [OpBuilder<"Block *dest, ValueRange destOperands = {}", [{
+    $_state.addSuccessors(dest);
+    $_state.addOperands(destOperands);
   }]>];
 
   // BranchOp is fully verified by traits.
@@ -714,21 +712,18 @@ def CallOp : Std_Op<"call", [CallOpInterface, MemRefsNormalizable]> {
   let results = (outs Variadic<AnyType>);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, FuncOp callee,"
-    "ValueRange operands = {}", [{
-      result.addOperands(operands);
-      result.addAttribute("callee", builder.getSymbolRefAttr(callee));
-      result.addTypes(callee.getType().getResults());
+    "FuncOp callee, ValueRange operands = {}", [{
+      $_state.addOperands(operands);
+      $_state.addAttribute("callee",$_builder.getSymbolRefAttr(callee));
+      $_state.addTypes(callee.getType().getResults());
   }]>, OpBuilder<
-    "OpBuilder &builder, OperationState &result, SymbolRefAttr callee,"
-    "TypeRange results, ValueRange operands = {}", [{
-      result.addOperands(operands);
-      result.addAttribute("callee", callee);
-      result.addTypes(results);
+    "SymbolRefAttr callee, TypeRange results, ValueRange operands = {}", [{
+      $_state.addOperands(operands);
+      $_state.addAttribute("callee", callee);
+      $_state.addTypes(results);
   }]>, OpBuilder<
-    "OpBuilder &builder, OperationState &result, StringRef callee,"
-    "TypeRange results, ValueRange operands = {}", [{
-      build(builder, result, builder.getSymbolRefAttr(callee), results,
+    "StringRef callee, TypeRange results, ValueRange operands = {}", [{
+      build($_builder, $_state, $_builder.getSymbolRefAttr(callee), results,
             operands);
   }]>];
 
@@ -790,11 +785,10 @@ def CallIndirectOp : Std_Op<"call_indirect", [
   let results = (outs Variadic<AnyType>:$results);
 
   let builders = [OpBuilder<
-    "OpBuilder &, OperationState &result, Value callee,"
-    "ValueRange operands = {}", [{
-      result.operands.push_back(callee);
-      result.addOperands(operands);
-      result.addTypes(callee.getType().cast<FunctionType>().getResults());
+    "Value callee, ValueRange operands = {}", [{
+      $_state.operands.push_back(callee);
+      $_state.addOperands(operands);
+      $_state.addTypes(callee.getType().cast<FunctionType>().getResults());
   }]>];
 
   let extraClassDeclaration = [{
@@ -956,9 +950,8 @@ def CmpFOp : Std_Op<"cmpf",
   let results = (outs BoolLike:$result);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, CmpFPredicate predicate,"
-    "Value lhs, Value rhs", [{
-      ::buildCmpFOp(builder, result, predicate, lhs, rhs);
+    "CmpFPredicate predicate, Value lhs, Value rhs", [{
+      ::buildCmpFOp($_builder, $_state, predicate, lhs, rhs);
   }]>];
 
   let extraClassDeclaration = [{
@@ -1078,9 +1071,8 @@ def CmpIOp : Std_Op<"cmpi",
   let results = (outs BoolLike:$result);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, CmpIPredicate predicate,"
-    "Value lhs, Value rhs", [{
-      ::buildCmpIOp(builder, result, predicate, lhs, rhs);
+    "CmpIPredicate predicate, Value lhs, Value rhs", [{
+      ::buildCmpIOp($_builder, $_state, predicate, lhs, rhs);
   }]>];
 
   let extraClassDeclaration = [{
@@ -1176,15 +1168,14 @@ def CondBranchOp : Std_Op<"cond_br",
   let successors = (successor AnySuccessor:$trueDest, AnySuccessor:$falseDest);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value condition,"
-    "Block *trueDest, ValueRange trueOperands,"
+    "Value condition, Block *trueDest, ValueRange trueOperands,"
     "Block *falseDest, ValueRange falseOperands", [{
-      build(builder, result, condition, trueOperands, falseOperands, trueDest,
+      build($_builder, $_state, condition, trueOperands, falseOperands, trueDest,
             falseDest);
   }]>, OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value condition,"
-    "Block *trueDest, Block *falseDest, ValueRange falseOperands = {}", [{
-      build(builder, result, condition, trueDest, ValueRange(), falseDest,
+    "Value condition, Block *trueDest, Block *falseDest, "
+    "ValueRange falseOperands = {}", [{
+      build($_builder, $_state, condition, trueDest, ValueRange(), falseDest,
             falseOperands);
   }]>];
 
@@ -1309,9 +1300,8 @@ def ConstantOp : Std_Op<"constant",
   let arguments = (ins AnyAttr:$value);
   let results = (outs AnyType);
 
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Attribute value",
-    [{ build(builder, result, value.getType(), value); }]>];
+  let builders = [OpBuilder<"Attribute value",
+    [{ build($_builder, $_state, value.getType(), value); }]>];
 
   let extraClassDeclaration = [{
     Attribute getValue() { return getAttr("value"); }
@@ -1493,10 +1483,8 @@ def DimOp : Std_Op<"dim", [NoSideEffect]> {
   }];
 
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "Value memrefOrTensor, int64_t index">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, "
-              "Value memrefOrTensor, Value index">
+    OpBuilder<"Value memrefOrTensor, int64_t index">,
+    OpBuilder<"Value memrefOrTensor, Value index">
   ];
 
   let extraClassDeclaration = [{
@@ -1547,8 +1535,7 @@ def DynamicTensorFromElementsOp : Std_Op<"dynamic_tensor_from_elements",
 
   let builders = [
     // Build op and populate its body per callback function.
-    OpBuilder<"OpBuilder &b, OperationState &result, Type resultTy, "
-              "ValueRange dynamicExtents, "
+    OpBuilder<"Type resultTy, ValueRange dynamicExtents, "
               "function_ref<void(OpBuilder &, Location, ValueRange)>">,
   ];
 
@@ -1627,11 +1614,10 @@ def ExtractElementOp : Std_Op<"extract_element",
   let results = (outs AnyType:$result);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value aggregate,"
-    "ValueRange indices = {}", [{
+    "Value aggregate, ValueRange indices = {}", [{
       auto resType = aggregate.getType().cast<ShapedType>()
                                          .getElementType();
-      build(builder, result, resType, aggregate, indices);
+      build($_builder, $_state, resType, aggregate, indices);
     }]>];
 
   let extraClassDeclaration = [{
@@ -1681,10 +1667,9 @@ def TensorFromElementsOp : Std_Op<"tensor_from_elements", [
 
   let skipDefaultBuilders = 1;
   let builders = [
-    OpBuilder<"OpBuilder &b, OperationState &result, Type elementType,"
-    "ValueRange elements">,
+    OpBuilder<"Type elementType, ValueRange elements">,
     // Special case builder for when `elements` has size >=1.
-    OpBuilder<"OpBuilder &b, OperationState &result, ValueRange elements">
+    OpBuilder<"ValueRange elements">
   ];
 
   let hasCanonicalizer = 1;
@@ -1877,12 +1862,11 @@ def LoadOp : Std_Op<"load",
   let results = (outs AnyType:$result);
 
   let builders = [OpBuilder<
-    "OpBuilder &, OperationState &result, Value memref,"
-    "ValueRange indices = {}", [{
+    "Value memref, ValueRange indices = {}", [{
       auto memrefType = memref.getType().cast<MemRefType>();
-      result.addOperands(memref);
-      result.addOperands(indices);
-      result.types.push_back(memrefType.getElementType());
+      $_state.addOperands(memref);
+      $_state.addOperands(indices);
+      $_state.types.push_back(memrefType.getElementType());
   }]>];
 
   let extraClassDeclaration = [{
@@ -2169,9 +2153,9 @@ def RankOp : Std_Op<"rank", [NoSideEffect]> {
   let verifier = ?;
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value tensor", [{
-      auto indexType = builder.getIndexType();
-      build(builder, result, indexType, tensor);
+    "Value tensor", [{
+      auto indexType = $_builder.getIndexType();
+      build($_builder, $_state, indexType, tensor);
     }]>];
 
   let hasFolder = 1;
@@ -2241,9 +2225,7 @@ def ReturnOp : Std_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
 
   let arguments = (ins Variadic<AnyType>:$operands);
 
-  let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result", [{ build(b, result, llvm::None); }]
-  >];
+  let builders = [OpBuilder<"", [{ build($_builder, $_state, llvm::None); }]>];
 
   let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
 }
@@ -2307,10 +2289,9 @@ def SelectOp : Std_Op<"select", [NoSideEffect,
   let results = (outs AnyType:$result);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value condition,"
-    "Value trueValue, Value falseValue", [{
-      result.addOperands({condition, trueValue, falseValue});
-      result.addTypes(trueValue.getType());
+    "Value condition, Value trueValue, Value falseValue", [{
+      $_state.addOperands({condition, trueValue, falseValue});
+      $_state.addTypes(trueValue.getType());
   }]>];
 
   let extraClassDeclaration = [{
@@ -2465,10 +2446,9 @@ def SignExtendIOp : Std_Op<"sexti",
   let arguments = (ins SignlessIntegerLike:$value);
   let results = (outs SignlessIntegerLike);
 
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value value, Type destType", [{
-      result.addOperands(value);
-      result.addTypes(destType);
+  let builders = [OpBuilder<"Value value, Type destType", [{
+      $_state.addOperands(value);
+      $_state.addTypes(destType);
   }]>];
 
   let parser = [{
@@ -2540,9 +2520,8 @@ def SplatOp : Std_Op<"splat", [NoSideEffect,
   let results = (outs AnyTypeOf<[AnyVector, AnyStaticShapeTensor]>:$aggregate);
 
   let builders =
-      [OpBuilder<"OpBuilder &builder, OperationState &result, Value element, "
-                  "Type aggregateType",
-                  [{ build(builder, result, aggregateType, element); }]>];
+      [OpBuilder<"Value element, Type aggregateType",
+                  [{ build($_builder, $_state, aggregateType, element); }]>];
 
   let hasFolder = 1;
 
@@ -2619,9 +2598,9 @@ def StoreOp : Std_Op<"store",
                        Variadic<Index>:$indices);
 
   let builders = [OpBuilder<
-    "OpBuilder &, OperationState &result, Value valueToStore, Value memref", [{
-      result.addOperands(valueToStore);
-      result.addOperands(memref);
+    "Value valueToStore, Value memref", [{
+      $_state.addOperands(valueToStore);
+      $_state.addOperands(memref);
   }]>];
 
   let extraClassDeclaration = [{
@@ -2816,14 +2795,13 @@ def SubViewOp : Std_Op<"subview", [
   let builders = [
     // Build a SubViewOp with mixed static and dynamic entries.
     OpBuilder<
-      "OpBuilder &b, OperationState &result, Value source, "
-      "ArrayRef<int64_t> staticOffsets, ArrayRef<int64_t> staticSizes,"
-      "ArrayRef<int64_t> staticStrides, ValueRange offsets, ValueRange sizes, "
-      "ValueRange strides, ArrayRef<NamedAttribute> attrs = {}">,
+      "Value source, ArrayRef<int64_t> staticOffsets, "
+      "ArrayRef<int64_t> staticSizes, ArrayRef<int64_t> staticStrides, "
+      "ValueRange offsets, ValueRange sizes, ValueRange strides, "
+      "ArrayRef<NamedAttribute> attrs = {}">,
     // Build a SubViewOp with all dynamic entries.
     OpBuilder<
-      "OpBuilder &b, OperationState &result, Value source, "
-      "ValueRange offsets, ValueRange sizes, ValueRange strides, "
+      "Value source, ValueRange offsets, ValueRange sizes, ValueRange strides, "
       "ArrayRef<NamedAttribute> attrs = {}">
   ];
 
@@ -3073,14 +3051,14 @@ def TensorLoadOp : Std_Op<"tensor_load",
   let verifier = ?;
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value memref", [{
-      result.addOperands(memref);
-      result.addTypes(getTensorTypeFromMemRefType(memref.getType()));
+    "Value memref", [{
+      $_state.addOperands(memref);
+      $_state.addTypes(getTensorTypeFromMemRefType(memref.getType()));
   }]>];
 
   let extraClassDeclaration = [{
     /// The result of a tensor_load is always a tensor.
-    TensorType getType() { 
+    TensorType getType() {
       Type resultType = getResult().getType();
       if (resultType.isa<TensorType>())
         return resultType.cast<TensorType>();
@@ -3150,9 +3128,9 @@ def TruncateIOp : Std_Op<"trunci", [NoSideEffect, SameOperandsAndResultShape]> {
   let results = (outs SignlessIntegerLike);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value value, Type destType", [{
-      result.addOperands(value);
-      result.addTypes(destType);
+    "Value value, Type destType", [{
+      $_state.addOperands(value);
+      $_state.addTypes(destType);
   }]>];
 
   let parser = [{
@@ -3418,9 +3396,9 @@ def ZeroExtendIOp : Std_Op<"zexti", [NoSideEffect, SameOperandsAndResultShape]>
   let results = (outs SignlessIntegerLike);
 
   let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value value, Type destType", [{
-      result.addOperands(value);
-      result.addTypes(destType);
+    "Value value, Type destType", [{
+      $_state.addOperands(value);
+      $_state.addTypes(destType);
   }]>];
 
   let parser = [{

diff  --git a/mlir/include/mlir/Dialect/Vector/VectorOps.td b/mlir/include/mlir/Dialect/Vector/VectorOps.td
index 2aaec4475ccb..ecac0a3d4b1f 100644
--- a/mlir/include/mlir/Dialect/Vector/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/VectorOps.td
@@ -148,13 +148,13 @@ def Vector_ContractionOp :
       : vector<10xf16>, vector<10xf16> into f32
     ```
   }];
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value lhs, Value rhs, "
-    "Value acc, ArrayAttr indexingMaps, ArrayAttr iteratorTypes">,
-    OpBuilder<
-      "OpBuilder &builder, OperationState &result, Value lhs, Value rhs, "
-      "Value acc, ArrayRef<ArrayRef<AffineExpr>> indexingExprs, "
-      "ArrayRef<StringRef> iteratorTypes">];
+  let builders = [
+    OpBuilder<"Value lhs, Value rhs, Value acc, ArrayAttr indexingMaps, "
+              "ArrayAttr iteratorTypes">,
+    OpBuilder<"Value lhs, Value rhs, Value acc, "
+              "ArrayRef<ArrayRef<AffineExpr>> indexingExprs, "
+	      "ArrayRef<StringRef> iteratorTypes">
+  ];
   let extraClassDeclaration = [{
     VectorType getLhsType() {
       return lhs().getType().cast<VectorType>();
@@ -311,8 +311,9 @@ def Vector_ShuffleOp :
                : vector<2xf32>, vector<2xf32>       ; yields vector<4xf32>
     ```
   }];
-  let builders = [OpBuilder<"OpBuilder &builder, OperationState &result,"
-                            "Value v1, Value v2, ArrayRef<int64_t>">];
+  let builders = [
+    OpBuilder<"Value v1, Value v2, ArrayRef<int64_t>">
+  ];
   let extraClassDeclaration = [{
     static StringRef getMaskAttrName() { return "mask"; }
     VectorType getV1VectorType() {
@@ -353,12 +354,10 @@ def Vector_ExtractElementOp :
     $vector `[` $position `:` type($position) `]` attr-dict `:` type($vector)
   }];
 
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, "
-    "int64_t position">,
-    OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, "
-    "Value position">];
+  let builders = [
+    OpBuilder<"Value source, int64_t position">,
+    OpBuilder<"Value source, Value position">
+  ];
   let extraClassDeclaration = [{
     VectorType getVectorType() {
       return vector().getType().cast<VectorType>();
@@ -384,13 +383,12 @@ def Vector_ExtractOp :
     %2 = vector.extract %0[3, 3, 3]: vector<4x8x16xf32>
     ```
   }];
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source,"
-    "ArrayRef<int64_t> position">,
+  let builders = [
+    OpBuilder<"Value source, ArrayRef<int64_t> position">,
     // Convenience builder which assumes the values in `position` are defined by
     // ConstantIndexOp.
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value source,"
-    "ValueRange position">];
+    OpBuilder<"Value source, ValueRange position">
+  ];
   let extraClassDeclaration = [{
     static StringRef getPositionAttrName() { return "position"; }
     VectorType getVectorType() {
@@ -435,10 +433,10 @@ def Vector_ExtractSlicesOp :
                                    vector<2x2xf32>, vector<2x1xf32>>
     ```
   }];
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, TupleType tupleType, " #
-    "Value vector, ArrayRef<int64_t> sizes, " #
-    "ArrayRef<int64_t> strides">];
+  let builders = [
+    OpBuilder<"TupleType tupleType, Value vector, ArrayRef<int64_t> sizes, "
+              "ArrayRef<int64_t> strides">
+  ];
   let extraClassDeclaration = [{
     VectorType getSourceVectorType() {
       return vector().getType().cast<VectorType>();
@@ -481,9 +479,10 @@ def Vector_FMAOp :
   // Fully specified by traits.
   let verifier = ?;
   let assemblyFormat = "$lhs `,` $rhs `,` $acc attr-dict `:` type($lhs)";
-  let builders = [OpBuilder<
-    "OpBuilder &b, OperationState &result, Value lhs, Value rhs, Value acc",
-    "build(b, result, lhs.getType(), lhs, rhs, acc);">];
+  let builders = [
+    OpBuilder<"Value lhs, Value rhs, Value acc",
+      "build($_builder, $_state, lhs.getType(), lhs, rhs, acc);">
+  ];
   let extraClassDeclaration = [{
     VectorType getVectorType() { return lhs().getType().cast<VectorType>(); }
   }];
@@ -520,12 +519,10 @@ def Vector_InsertElementOp :
     type($result)
   }];
 
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, "
-    "Value dest, int64_t position">,
-    OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, "
-    "Value dest, Value position">];
+  let builders = [
+    OpBuilder<"Value source, Value dest, int64_t position">,
+    OpBuilder<"Value source, Value dest, Value position">
+  ];
   let extraClassDeclaration = [{
     Type getSourceType() { return source().getType(); }
     VectorType getDestVectorType() {
@@ -559,13 +556,11 @@ def Vector_InsertOp :
     $source `,` $dest $position attr-dict `:` type($source) `into` type($dest)
   }];
 
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, "
-    "Value dest, ArrayRef<int64_t> position">,
+  let builders = [
+    OpBuilder<"Value source, Value dest, ArrayRef<int64_t> position">,
     // Convenience builder which assumes all values are constant indices.
-    OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, "
-    "Value dest, ValueRange position">];
+    OpBuilder<"Value source, Value dest, ValueRange position">
+  ];
   let extraClassDeclaration = [{
     static StringRef getPositionAttrName() { return "position"; }
     Type getSourceType() { return source().getType(); }
@@ -666,9 +661,10 @@ def Vector_InsertStridedSliceOp :
     $source `,` $dest attr-dict `:` type($source) `into` type($dest)
   }];
 
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, Value dest, " #
-    "ArrayRef<int64_t> offsets, ArrayRef<int64_t> strides">];
+  let builders = [
+    OpBuilder<"Value source, Value dest, ArrayRef<int64_t> offsets, "
+              "ArrayRef<int64_t> strides">
+  ];
   let extraClassDeclaration = [{
     static StringRef getOffsetsAttrName() { return "offsets"; }
     static StringRef getStridesAttrName() { return "strides"; }
@@ -730,9 +726,8 @@ def Vector_OuterProductOp :
   }];
   let builders = [
     // Build an op without mask, use the type of `acc` as the return type.
-    OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value lhs, Value rhs, "
-    "Value acc">];
+    OpBuilder<"Value lhs, Value rhs, Value acc">
+  ];
   let extraClassDeclaration = [{
     VectorType getOperandVectorTypeLHS() {
       return lhs().getType().cast<VectorType>();
@@ -904,10 +899,10 @@ def Vector_ExtractStridedSliceOp :
       vector<4x8x16xf32> to vector<2x4x16xf32>
     ```
   }];
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source, " #
-    "ArrayRef<int64_t> offsets, ArrayRef<int64_t> sizes, " #
-    "ArrayRef<int64_t> strides">];
+  let builders = [
+    OpBuilder<"Value source, ArrayRef<int64_t> offsets, "
+              "ArrayRef<int64_t> sizes, ArrayRef<int64_t> strides">
+  ];
   let extraClassDeclaration = [{
     static StringRef getOffsetsAttrName() { return "offsets"; }
     static StringRef getSizesAttrName() { return "sizes"; }
@@ -1069,13 +1064,11 @@ def Vector_TransferReadOp :
 
   let builders = [
     // Builder that sets padding to zero.
-    OpBuilder<"OpBuilder &builder, OperationState &result, VectorType vector, "
-              "Value memref, ValueRange indices, AffineMap permutationMap, "
-              "ArrayRef<bool> maybeMasked = {}">,
+    OpBuilder<"VectorType vector, Value memref, ValueRange indices, "
+              "AffineMap permutationMap, ArrayRef<bool> maybeMasked = {}">,
     // Builder that sets permutation map (resp. padding) to
     // 'getMinorIdentityMap' (resp. zero).
-    OpBuilder<"OpBuilder &builder, OperationState &result, VectorType vector, "
-              "Value memref, ValueRange indices, "
+    OpBuilder<"VectorType vector, Value memref, ValueRange indices, "
               "ArrayRef<bool> maybeMasked = {}">
   ];
 
@@ -1154,11 +1147,10 @@ def Vector_TransferWriteOp :
 
   let builders = [
     // Builder that sets permutation map to 'getMinorIdentityMap'.
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value vector, "
-              "Value memref, ValueRange indices, "
+    OpBuilder<"Value vector, Value memref, ValueRange indices, "
               "ArrayRef<bool> maybeMasked = {}">,
-    OpBuilder<"OpBuilder &builder, OperationState &result, Value vector, "
-              "Value memref, ValueRange indices, AffineMap permutationMap">,
+    OpBuilder<"Value vector, Value memref, ValueRange indices, "
+              "AffineMap permutationMap">,
   ];
 
   let hasFolder = 1;
@@ -1602,8 +1594,9 @@ def Vector_TypeCastOp :
 
   /// Build the canonical memRefType with a single vector.
   /// E.g. memref<4 x 5 x vector<6 x f32>> -> memref<vector<4 x 5 x 6 x f32>>.
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value source">];
+  let builders = [
+    OpBuilder<"Value source">
+  ];
 
   let extraClassDeclaration = [{
     MemRefType getMemRefType() {
@@ -1756,9 +1749,9 @@ def Vector_TransposeOp :
                           [c, f] ]
     ```
   }];
-  let builders = [OpBuilder<
-    "OpBuilder &builder, OperationState &result, Value vector, "
-    "ArrayRef<int64_t> transp">];
+  let builders = [
+    OpBuilder<"Value vector, ArrayRef<int64_t> transp">
+  ];
   let extraClassDeclaration = [{
     VectorType getVectorType() {
       return vector().getType().cast<VectorType>();
@@ -1902,14 +1895,14 @@ def Vector_MatmulOp : Vector_Op<"matrix_multiply", [NoSideEffect,
     ```
   }];
   let builders = [
-   OpBuilder<"OpBuilder &builder, OperationState &result, Value lhs, Value rhs, "
-             "unsigned lhsRows, unsigned lhsColumns, unsigned rhsColumns",
+   OpBuilder<"Value lhs, Value rhs, unsigned lhsRows, unsigned lhsColumns, "
+             "unsigned rhsColumns",
    [{
-     result.addOperands({lhs, rhs});
-     result.addAttribute("lhs_rows", builder.getI32IntegerAttr(lhsRows));
-     result.addAttribute("lhs_columns", builder.getI32IntegerAttr(lhsColumns));
-     result.addAttribute("rhs_columns", builder.getI32IntegerAttr(rhsColumns));
-     result.addTypes(VectorType::get(lhsRows * rhsColumns,
+     $_state.addOperands({lhs, rhs});
+     $_state.addAttribute("lhs_rows",$_builder.getI32IntegerAttr(lhsRows));
+     $_state.addAttribute("lhs_columns",$_builder.getI32IntegerAttr(lhsColumns));
+     $_state.addAttribute("rhs_columns",$_builder.getI32IntegerAttr(rhsColumns));
+     $_state.addTypes(VectorType::get(lhsRows * rhsColumns,
        lhs.getType().cast<VectorType>().getElementType()));
    }]>,
   ];

diff  --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 3743e39d0566..6f3c8f5aee68 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -636,8 +636,7 @@ def OpFuncRef : TEST_Op<"op_funcref"> {
   let description = [{
     The "test.op_funcref" is a test op with a reference to a function symbol.
   }];
-  let builders = [OpBuilder<[{OpBuilder &builder, OperationState &state,
-                             FuncOp function}]>];
+  let builders = [OpBuilder<[{FuncOp function}]>];
 }
 
 // Pattern add the argument plus a increasing static number hidden in
@@ -1132,12 +1131,12 @@ def LegalOpB : TEST_Op<"legal_op_b">, Results<(outs I32)>;
 def IllegalOpTerminator : TEST_Op<"illegal_op_terminator", [Terminator]>;
 def IllegalOpWithRegion : TEST_Op<"illegal_op_with_region"> {
   let skipDefaultBuilders = 1;
-  let builders = [OpBuilder<"OpBuilder &builder, OperationState &state",
-                  [{ Region *bodyRegion = state.addRegion();
-                     OpBuilder::InsertionGuard g(builder);
-                     Block *body = builder.createBlock(bodyRegion);
-                     builder.setInsertionPointToEnd(body);
-                     builder.create<IllegalOpTerminator>(state.location);
+  let builders = [OpBuilder<"",
+                  [{ Region *bodyRegion = $_state.addRegion();
+                     OpBuilder::InsertionGuard g($_builder);
+                     Block *body = $_builder.createBlock(bodyRegion);
+                     $_builder.setInsertionPointToEnd(body);
+                     $_builder.create<IllegalOpTerminator>($_state.location);
                   }]>];
 }
 def IllegalOpWithRegionAnchor : TEST_Op<"illegal_op_with_region_anchor">;
@@ -1176,8 +1175,7 @@ def TestRegionBuilderOp : TEST_Op<"region_builder">;
 def TestReturnOp : TEST_Op<"return", [ReturnLike, Terminator]> {
   let arguments = (ins Variadic<AnyType>);
   let builders = [
-    OpBuilder<"OpBuilder &builder, OperationState &state",
-              [{ build(builder, state, {}); }]>
+    OpBuilder<"", [{ build($_builder, $_state, {}); }]>
   ];
 }
 def TestCastOp : TEST_Op<"cast">,


        


More information about the Mlir-commits mailing list