Skip to content

Commit 97e0573

Browse files
authored
[CIR] Start printing/parsing func 'attributes' (#169674)
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.
1 parent 3b9e203 commit 97e0573

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,20 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
19201920
return failure();
19211921
}
19221922

1923+
// Parse the rest of the attributes.
1924+
NamedAttrList parsedAttrs;
1925+
if (parser.parseOptionalAttrDictWithKeyword(parsedAttrs))
1926+
return failure();
1927+
1928+
for (StringRef disallowed : cir::FuncOp::getAttributeNames()) {
1929+
if (parsedAttrs.get(disallowed))
1930+
return parser.emitError(loc, "attribute '")
1931+
<< disallowed
1932+
<< "' should not be specified in the explicit attribute list";
1933+
}
1934+
1935+
state.attributes.append(parsedAttrs);
1936+
19231937
// Parse the optional function body.
19241938
auto *body = state.addRegion();
19251939
OptionalParseResult parseResult = parser.parseOptionalRegion(
@@ -2073,6 +2087,9 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
20732087
p << " inline(" << cir::stringifyInlineKind(inlineAttr.getValue()) << ")";
20742088
}
20752089

2090+
function_interface_impl::printFunctionAttributes(
2091+
p, *this, cir::FuncOp::getAttributeNames());
2092+
20762093
// Print the body if this is not an external function.
20772094
Region &body = getOperation()->getRegion(0);
20782095
if (!body.empty()) {

clang/test/CIR/IR/func.cir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,11 @@ cir.func @Foo_move_assign() special_member<#cir.cxx_assign<!rec_Foo, move>> {
186186
// CHECK: cir.func @Foo_move_assign() special_member<#cir.cxx_assign<!rec_Foo, move>> {
187187
// CHECK: cir.return
188188
// CHECK: }
189+
190+
cir.func @has_attrs() attributes {foo, baz = 5, floof = "flop"} {
191+
cir.return
192+
}
193+
194+
// CHECK: cir.func @has_attrs() attributes {baz = 5 : i64{{.*}}, floof = "flop", foo} {
195+
// CHECK: cir.return
196+
// CHECK: }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: cir-opt %s -verify-diagnostics
2+
3+
module {
4+
cir.func @l0() {
5+
cir.return
6+
}
7+
8+
cir.func @disallowedAttr() attributes {comdat} { // expected-error{{custom op 'cir.func' attribute 'comdat' should not be specified in the explicit attribute list}}
9+
cir.return
10+
}
11+
}

0 commit comments

Comments
 (0)