From 83f3c615dde3fce5c0560c19316b08c1e6aa8c27 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 24 Sep 2021 00:15:49 +0000 Subject: [PATCH] Add missing storageType to AttrDef to ODS This is only noticeable when using an attribute across dialects I think. Previously the namespace would be ommited, but it wouldn't matter as long as the generated code stays within a single namespace. Differential Revision: https://reviews.llvm.org/D110367 --- mlir/include/mlir/IR/OpBase.td | 1 + mlir/test/mlir-tblgen/op-attribute.td | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 9dfff98bdcad..d5ec09822457 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -2861,6 +2861,7 @@ class AttrDef traits = [], AttrOrTypeDef<"Attr", name, traits, baseCppClass> { // The name of the C++ Attribute class. string cppClassName = name # "Attr"; + let storageType = dialect.cppNamespace # "::" # name # "Attr"; // The underlying C++ value type let returnType = dialect.cppNamespace # "::" # cppClassName; diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td index 02d63c04355b..1656b42cbf3c 100644 --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -6,6 +6,7 @@ include "mlir/IR/OpBase.td" def Test_Dialect : Dialect { let name = "test"; + let cppNamespace = "foobar"; } class NS_Op traits> : Op; @@ -17,6 +18,10 @@ def SomeAttr : Attr, "some attribute kind"> { let constBuilderCall = "some-const-builder-call($_builder, $0)"; } +def SomeAttrDef : AttrDef { +} + + // Test required, optional, default-valued attributes // --- @@ -271,6 +276,19 @@ def EOp : NS_Op<"e_op", []> { // DECL-LABEL: EOp declarations // DECL: static void build({{.*}}, uint32_t i32_attr, uint32_t dv_i32_attr, ::llvm::APFloat f64_attr, ::llvm::APFloat dv_f64_attr, ::llvm::StringRef str_attr, ::llvm::StringRef dv_str_attr, bool bool_attr, bool dv_bool_attr, ::SomeI32Enum enum_attr, ::SomeI32Enum dv_enum_attr = ::SomeI32Enum::case5) + +// Test proper namespacing for AttrDef +// --- + +def NamespaceOp : NS_Op<"namespace_op", []> { + let arguments = (ins + SomeAttrDef:$AttrDef + ); +} +// DECL: NamespaceOp +// DECL: foobar::SomeAttrAttr AttrDef() + + // Test mixing operands and attributes in arbitrary order // ---