[Mlir-commits] [mlir] 90736ba - [mlir][EmitC] Remove the type from the OpaqueAttr

Marius Brehler llvmlistbot at llvm.org
Fri Aug 12 00:14:06 PDT 2022


Author: Marius Brehler
Date: 2022-08-12T07:12:24Z
New Revision: 90736babcaeb5222ee5ba50a823b7acffdd5a4dd

URL: https://github.com/llvm/llvm-project/commit/90736babcaeb5222ee5ba50a823b7acffdd5a4dd
DIFF: https://github.com/llvm/llvm-project/commit/90736babcaeb5222ee5ba50a823b7acffdd5a4dd.diff

LOG: [mlir][EmitC] Remove the type from the OpaqueAttr

This removes the type from EmitC's opaque attribute. The value provided
as a StringRefParameter can always be emitted as is. In consquence the
constant and variable ops explicitly need to opaque attributes which are
no longer typed attributes.

Co-authored-by: Simon Camphausen <simon.camphausen at iml.fraunhofer.de>

Reviewed By: Mogball, jpienaar

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
    mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
    mlir/lib/Dialect/EmitC/IR/EmitC.cpp
    mlir/test/Target/Cpp/const.mlir
    mlir/test/Target/Cpp/variable.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index ac86e92c7c34..813898aa08d0 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -139,7 +139,7 @@ def EmitC_ConstantOp : EmitC_Op<"constant", [ConstantLike]> {
     ```
   }];
 
-  let arguments = (ins TypedAttrInterface:$value);
+  let arguments = (ins EmitC_OpaqueOrTypedAttr:$value);
   let results = (outs AnyType);
 
   let hasFolder = 1;
@@ -212,7 +212,7 @@ def EmitC_VariableOp : EmitC_Op<"variable", []> {
     ```
   }];
 
-  let arguments = (ins TypedAttrInterface:$value);
+  let arguments = (ins EmitC_OpaqueOrTypedAttr:$value);
   let results = (outs AnyType);
 
   let hasVerifier = 1;

diff  --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
index 22b2f55872d9..d69b1c20eaee 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
@@ -26,7 +26,7 @@ class EmitC_Attr<string name, string attrMnemonic, list<Trait> traits = []>
   let mnemonic = attrMnemonic;
 }
 
-def EmitC_OpaqueAttr : EmitC_Attr<"Opaque", "opaque", [TypedAttrInterface]> {
+def EmitC_OpaqueAttr : EmitC_Attr<"Opaque", "opaque"> {
   let summary = "An opaque attribute";
 
   let description = [{
@@ -41,10 +41,11 @@ def EmitC_OpaqueAttr : EmitC_Attr<"Opaque", "opaque", [TypedAttrInterface]> {
     ```
   }];
 
-  let parameters = (ins "Type":$type,
-                        StringRefParameter<"the opaque value">:$value);
+  let parameters = (ins StringRefParameter<"the opaque value">:$value);
 
   let hasCustomAssemblyFormat = 1;
 }
 
+def EmitC_OpaqueOrTypedAttr : AnyAttrOf<[EmitC_OpaqueAttr, TypedAttrInterface]>;
+
 #endif // MLIR_DIALECT_EMITC_IR_EMITCATTRIBUTES

diff  --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index b005506e3ed5..5b3a0f6a31fc 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -118,6 +118,9 @@ LogicalResult emitc::CallOp::verify() {
 
 /// The constant op requires that the attribute's type matches the return type.
 LogicalResult emitc::ConstantOp::verify() {
+  if (getValueAttr().isa<emitc::OpaqueAttr>())
+    return success();
+
   TypedAttr value = getValueAttr();
   Type type = getType();
   if (!value.getType().isa<NoneType>() && type != value.getType())
@@ -172,6 +175,9 @@ ParseResult IncludeOp::parse(OpAsmParser &parser, OperationState &result) {
 
 /// The variable op requires that the attribute's type matches the return type.
 LogicalResult emitc::VariableOp::verify() {
+  if (getValueAttr().isa<emitc::OpaqueAttr>())
+    return success();
+
   TypedAttr value = getValueAttr();
   Type type = getType();
   if (!value.getType().isa<NoneType>() && type != value.getType())
@@ -206,8 +212,7 @@ Attribute emitc::OpaqueAttr::parse(AsmParser &parser, Type type) {
   if (parser.parseGreater())
     return Attribute();
 
-  return get(parser.getContext(),
-             type ? type : NoneType::get(parser.getContext()), value);
+  return get(parser.getContext(), value);
 }
 
 void emitc::OpaqueAttr::print(AsmPrinter &printer) const {

diff  --git a/mlir/test/Target/Cpp/const.mlir b/mlir/test/Target/Cpp/const.mlir
index 6d4417ca1bda..cc8163cf8c64 100644
--- a/mlir/test/Target/Cpp/const.mlir
+++ b/mlir/test/Target/Cpp/const.mlir
@@ -7,7 +7,7 @@ func.func @emitc_constant() {
   %c2 = "emitc.constant"(){value = -1 : i32} : () -> i32
   %c3 = "emitc.constant"(){value = -1 : si8} : () -> si8
   %c4 = "emitc.constant"(){value = 255 : ui8} : () -> ui8
-  %c5 = "emitc.constant"(){value = #emitc.opaque<"CHAR_MIN"> : !emitc.opaque<"char">} : () -> !emitc.opaque<"char">
+  %c5 = "emitc.constant"(){value = #emitc.opaque<"CHAR_MIN">} : () -> !emitc.opaque<"char">
   return
 }
 // CPP-DEFAULT: void emitc_constant() {

diff  --git a/mlir/test/Target/Cpp/variable.mlir b/mlir/test/Target/Cpp/variable.mlir
index 46588e3d06b8..11f74b0a74eb 100644
--- a/mlir/test/Target/Cpp/variable.mlir
+++ b/mlir/test/Target/Cpp/variable.mlir
@@ -7,8 +7,8 @@ func.func @emitc_variable() {
   %c2 = "emitc.variable"(){value = -1 : i32} : () -> i32
   %c3 = "emitc.variable"(){value = -1 : si8} : () -> si8
   %c4 = "emitc.variable"(){value = 255 : ui8} : () -> ui8
-  %c5 = "emitc.variable"(){value = #emitc.opaque<""> : !emitc.ptr<i32>} : () -> !emitc.ptr<i32>
-  %c6 = "emitc.variable"(){value = #emitc.opaque<"NULL"> : !emitc.ptr<i32>} : () -> !emitc.ptr<i32>
+  %c5 = "emitc.variable"(){value = #emitc.opaque<"">} : () -> !emitc.ptr<i32>
+  %c6 = "emitc.variable"(){value = #emitc.opaque<"NULL">} : () -> !emitc.ptr<i32>
   return
 }
 // CPP-DEFAULT: void emitc_variable() {


        


More information about the Mlir-commits mailing list