mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[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.
This commit is contained in:
@@ -1920,6 +1920,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::FuncOp::getAttributeNames()) {
|
||||
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(
|
||||
@@ -2073,6 +2087,9 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
|
||||
p << " inline(" << cir::stringifyInlineKind(inlineAttr.getValue()) << ")";
|
||||
}
|
||||
|
||||
function_interface_impl::printFunctionAttributes(
|
||||
p, *this, cir::FuncOp::getAttributeNames());
|
||||
|
||||
// Print the body if this is not an external function.
|
||||
Region &body = getOperation()->getRegion(0);
|
||||
if (!body.empty()) {
|
||||
|
||||
@@ -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 {baz = 5 : i64{{.*}}, floof = "flop", foo} {
|
||||
// CHECK: cir.return
|
||||
// CHECK: }
|
||||
|
||||
11
clang/test/CIR/IR/invalid-func-attr.cir
Normal file
11
clang/test/CIR/IR/invalid-func-attr.cir
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user