https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/169674

>From 8f98574f7b0c21ccc1904005e25144e08f0c1496 Mon Sep 17 00:00:00 2001
From: erichkeane <[email protected]>
Date: Wed, 26 Nov 2025 06:33:28 -0800
Subject: [PATCH 1/4] [CIR] Start printing/parsing func 'attributes'

This patch adds a print and parse ability for the func to have
MLIR-standard 'attributes' printed along side the standard function.

This patch also seeds the initial "disallowed" list so that we don't
print things that we have custom printing for, AND will disallow them
from being parsed. I believe this list to be complete, and it passes all
tests.

This printing of attributes is necessary for testing some OpenACC things
that putting into the normal func-printing seems unnecessary.
---
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  | 19 +++++++++++++++++++
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp       | 17 +++++++++++++++++
 clang/test/CIR/IR/func.cir                    |  8 ++++++++
 clang/test/CIR/IR/invalid-func-attr.cir       | 11 +++++++++++
 4 files changed, 55 insertions(+)
 create mode 100644 clang/test/CIR/IR/invalid-func-attr.cir

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index 3e062add6633a..c0333305ad030 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -509,6 +509,25 @@ def CIR_FuncType : CIR_Type<"Func", "func"> {
     /// Returns a clone of this function type with the given argument
     /// and result types.
     FuncType clone(mlir::TypeRange inputs, mlir::TypeRange results) const;
+
+    /// A list of mlir attributes that shouldn't appear in the generic
+    /// 'attributes' list, and instead are handled via other syntax.
+    static constexpr llvm::StringRef disallowedFromAttrList[] = {
+        "alias",
+        "builtin",
+        "comdat",
+        "coroutine",
+        "cxx_special_member",
+        "dso_local",
+        "function_type",
+        "global_ctor_priority",
+        "global_dtor_priority",
+        "global_visibility",
+        "inline_kind",
+        "lambda",
+        "linkage",
+        "no_proto",
+        "sym_visibility"};
   }];
 }
 
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 6bf543cf794b7..5c1e4010c5469 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1824,6 +1824,20 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, 
OperationState &state) {
       return failure();
   }
 
+  // Parse the rest of the attributes.
+  NamedAttrList parsedAttrs;
+  if (parser.parseOptionalAttrDictWithKeyword(parsedAttrs))
+    return failure();
+
+  for (StringRef disallowed : cir::FuncType::disallowedFromAttrList) {
+    if (parsedAttrs.get(disallowed))
+      return parser.emitError(loc, "attribute '")
+             << disallowed
+             << "' should not be specified in the explicit attribute list";
+  }
+
+  state.attributes.append(parsedAttrs);
+
   // Parse the optional function body.
   auto *body = state.addRegion();
   OptionalParseResult parseResult = parser.parseOptionalRegion(
@@ -1977,6 +1991,9 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
     p << " inline(" << cir::stringifyInlineKind(inlineAttr.getValue()) << ")";
   }
 
+  function_interface_impl::printFunctionAttributes(
+      p, *this, cir::FuncType::disallowedFromAttrList);
+
   // Print the body if this is not an external function.
   Region &body = getOperation()->getRegion(0);
   if (!body.empty()) {
diff --git a/clang/test/CIR/IR/func.cir b/clang/test/CIR/IR/func.cir
index 10df27b7e168f..2b3ee24995f40 100644
--- a/clang/test/CIR/IR/func.cir
+++ b/clang/test/CIR/IR/func.cir
@@ -186,3 +186,11 @@ cir.func @Foo_move_assign() 
special_member<#cir.cxx_assign<!rec_Foo, move>> {
 // CHECK: cir.func @Foo_move_assign() special_member<#cir.cxx_assign<!rec_Foo, 
move>> {
 // CHECK:   cir.return
 // CHECK: }
+
+cir.func @has_attrs() attributes {foo, baz = 5, floof = "flop"} {
+  cir.return
+}
+
+// CHECK: cir.func @has_attrs() attributes {bz = 5, floof = "flop", foo} {
+// CHECK:   cir.return
+// CHECK: }
diff --git a/clang/test/CIR/IR/invalid-func-attr.cir 
b/clang/test/CIR/IR/invalid-func-attr.cir
new file mode 100644
index 0000000000000..aaaaba7a7bf6f
--- /dev/null
+++ b/clang/test/CIR/IR/invalid-func-attr.cir
@@ -0,0 +1,11 @@
+// RUN: cir-opt %s -verify-diagnostics
+
+module {
+  cir.func @l0() {
+    cir.return
+  }
+
+  cir.func @disallowedAttr() attributes {comdat} { // expected-error{{custom 
op 'cir.func' attribute 'comdat' should not be specified in the explicit 
attribute list}}
+    cir.return
+  }
+}

>From a2caecf669ff4061526e9d10bb184a98d7a47eeb Mon Sep 17 00:00:00 2001
From: erichkeane <[email protected]>
Date: Wed, 26 Nov 2025 08:42:56 -0800
Subject: [PATCH 2/4] Fix 'vim stole my letter' problem in test

---
 clang/test/CIR/IR/func.cir | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CIR/IR/func.cir b/clang/test/CIR/IR/func.cir
index 2b3ee24995f40..285968ff7db67 100644
--- a/clang/test/CIR/IR/func.cir
+++ b/clang/test/CIR/IR/func.cir
@@ -191,6 +191,6 @@ cir.func @has_attrs() attributes {foo, baz = 5, floof = 
"flop"} {
   cir.return
 }
 
-// CHECK: cir.func @has_attrs() attributes {bz = 5, floof = "flop", foo} {
+// CHECK: cir.func @has_attrs() attributes {baz = 5, floof = "flop", foo} {
 // CHECK:   cir.return
 // CHECK: }

>From 450e9aa9dfba67283e360945f18a4747a6305380 Mon Sep 17 00:00:00 2001
From: erichkeane <[email protected]>
Date: Wed, 26 Nov 2025 09:13:57 -0800
Subject: [PATCH 3/4] add type of the int, which for some reason passed locally
 at one point... good grief.

---
 clang/test/CIR/IR/func.cir | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CIR/IR/func.cir b/clang/test/CIR/IR/func.cir
index 285968ff7db67..d8906ab3e1301 100644
--- a/clang/test/CIR/IR/func.cir
+++ b/clang/test/CIR/IR/func.cir
@@ -191,6 +191,6 @@ cir.func @has_attrs() attributes {foo, baz = 5, floof = 
"flop"} {
   cir.return
 }
 
-// CHECK: cir.func @has_attrs() attributes {baz = 5, floof = "flop", foo} {
+// CHECK: cir.func @has_attrs() attributes {baz = 5 : i64{{.*}}, floof = 
"flop", foo} {
 // CHECK:   cir.return
 // CHECK: }

>From 896cc91f0fe542ef80fc50b18e1438ba9e3184d9 Mon Sep 17 00:00:00 2001
From: erichkeane <[email protected]>
Date: Wed, 26 Nov 2025 11:19:31 -0800
Subject: [PATCH 4/4] Change to the getAttributesName function for our list of
 disallowed attributes

---
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  | 19 -------------------
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp       |  4 ++--
 2 files changed, 2 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index c0333305ad030..3e062add6633a 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -509,25 +509,6 @@ def CIR_FuncType : CIR_Type<"Func", "func"> {
     /// Returns a clone of this function type with the given argument
     /// and result types.
     FuncType clone(mlir::TypeRange inputs, mlir::TypeRange results) const;
-
-    /// A list of mlir attributes that shouldn't appear in the generic
-    /// 'attributes' list, and instead are handled via other syntax.
-    static constexpr llvm::StringRef disallowedFromAttrList[] = {
-        "alias",
-        "builtin",
-        "comdat",
-        "coroutine",
-        "cxx_special_member",
-        "dso_local",
-        "function_type",
-        "global_ctor_priority",
-        "global_dtor_priority",
-        "global_visibility",
-        "inline_kind",
-        "lambda",
-        "linkage",
-        "no_proto",
-        "sym_visibility"};
   }];
 }
 
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 5c1e4010c5469..8852295f8a06a 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1829,7 +1829,7 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, 
OperationState &state) {
   if (parser.parseOptionalAttrDictWithKeyword(parsedAttrs))
     return failure();
 
-  for (StringRef disallowed : cir::FuncType::disallowedFromAttrList) {
+  for (StringRef disallowed : cir::FuncOp::getAttributeNames()) {
     if (parsedAttrs.get(disallowed))
       return parser.emitError(loc, "attribute '")
              << disallowed
@@ -1992,7 +1992,7 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
   }
 
   function_interface_impl::printFunctionAttributes(
-      p, *this, cir::FuncType::disallowedFromAttrList);
+      p, *this, cir::FuncOp::getAttributeNames());
 
   // Print the body if this is not an external function.
   Region &body = getOperation()->getRegion(0);

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to