[Mlir-commits] [mlir] 5f8a808 - [mlir] Add constBuilderCall to TypeAttr to simplify builders

Lei Zhang llvmlistbot at llvm.org
Wed Feb 24 10:04:15 PST 2021


Author: Lei Zhang
Date: 2021-02-24T13:04:03-05:00
New Revision: 5f8a80882b72695978035a25002d365d0dd84803

URL: https://github.com/llvm/llvm-project/commit/5f8a80882b72695978035a25002d365d0dd84803
DIFF: https://github.com/llvm/llvm-project/commit/5f8a80882b72695978035a25002d365d0dd84803.diff

LOG: [mlir] Add constBuilderCall to TypeAttr to simplify builders

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D97344

Added: 
    

Modified: 
    mlir/include/mlir/IR/OpBase.td
    mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp
    mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index 417c32570adb..bf3a6adc4200 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -1074,7 +1074,9 @@ class TypeAttrBase<string retType, string summary> :
   let convertFromStorage = "$_self.getValue().cast<" # retType # ">()";
 }
 
-def TypeAttr : TypeAttrBase<"::mlir::Type", "any type attribute">;
+def TypeAttr : TypeAttrBase<"::mlir::Type", "any type attribute"> {
+  let constBuilderCall = "::mlir::TypeAttr::get($0)";
+}
 
 // The mere presence of unit attributes has a meaning.  Therefore, unit
 // attributes are always treated as optional and accessors to them return

diff  --git a/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp b/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp
index 2775f778719a..c2db461cae79 100644
--- a/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp
+++ b/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp
@@ -264,9 +264,8 @@ class AllocOpPattern final : public OpConversionPattern<AllocOp> {
       std::string varName =
           std::string("__workgroup_mem__") +
           std::to_string(std::distance(varOps.begin(), varOps.end()));
-      varOp = rewriter.create<spirv::GlobalVariableOp>(
-          loc, TypeAttr::get(spirvType), varName,
-          /*initializer = */ nullptr);
+      varOp = rewriter.create<spirv::GlobalVariableOp>(loc, spirvType, varName,
+                                                       /*initializer=*/nullptr);
     }
 
     // Get pointer to global variable at the current scope.

diff  --git a/mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp b/mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp
index e42860e87942..a024d6c1f58b 100644
--- a/mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp
+++ b/mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp
@@ -61,9 +61,9 @@ GlobalCreator::GlobalCreator(ModuleOp module) {
     auto global = globalBuilder.create<GlobalMemrefOp>(
         op.getLoc(), (Twine("__constant_") + os.str()).str(),
         /*sym_visibility=*/globalBuilder.getStringAttr("private"),
-        /*type=*/
-        TypeAttr::get(typeConverter.convertType(type)), /*initial_value=*/
-        op.getValue().cast<ElementsAttr>(), /*constant=*/true);
+        /*type=*/typeConverter.convertType(type),
+        /*initial_value=*/op.getValue().cast<ElementsAttr>(),
+        /*constant=*/true);
     symbolTable.insert(global);
     // The symbol table inserts at the end of the module, but globals are a bit
     // nicer if they are at the beginning.


        


More information about the Mlir-commits mailing list