Skip to content

Commit 42bca85

Browse files
keryellxlauko
authored andcommitted
[CIR][Asm] Remove duplicated lambda & coroutine attributes (llvm#580)
Do not print in cir.func definition the 'attr { ... }' with coroutine or lambda attributes since they are already printed before the function name. Otherwise redundancy breaks a future parsing. Sort the attributes to be skipped so it is more obvious to see the list of attributes. Improve the tests to check there are no spurious attributes anymore.
1 parent 222ac34 commit 42bca85

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,9 @@ ::mlir::Region *cir::FuncOp::getCallableRegion() {
20252025
void cir::FuncOp::print(OpAsmPrinter &p) {
20262026
p << ' ';
20272027

2028+
// When adding a specific keyword here, do not forget to omit it in
2029+
// printFunctionAttributes below or there will be a syntax error when
2030+
// parsing
20282031
if (getBuiltin())
20292032
p << "builtin ";
20302033

@@ -2058,10 +2061,19 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
20582061
function_interface_impl::printFunctionAttributes(
20592062
p, *this,
20602063
// These are all omitted since they are custom printed already.
2061-
{getSymVisibilityAttrName(), getAliaseeAttrName(),
2062-
getFunctionTypeAttrName(), getLinkageAttrName(), getBuiltinAttrName(),
2063-
getNoProtoAttrName(), getGlobalCtorAttrName(), getGlobalDtorAttrName(),
2064-
getExtraAttrsAttrName()});
2064+
{
2065+
getAliaseeAttrName(),
2066+
getBuiltinAttrName(),
2067+
getCoroutineAttrName(),
2068+
getExtraAttrsAttrName(),
2069+
getFunctionTypeAttrName(),
2070+
getGlobalCtorAttrName(),
2071+
getGlobalDtorAttrName(),
2072+
getLambdaAttrName(),
2073+
getLinkageAttrName(),
2074+
getNoProtoAttrName(),
2075+
getSymVisibilityAttrName(),
2076+
});
20652077

20662078
if (auto aliaseeName = getAliasee()) {
20672079
p << " alias(";

clang/test/CIR/CodeGen/coro-task.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ folly::coro::Task<int> byRef(const std::string& s) {
461461
}
462462

463463
// FIXME: this could be less redundant than two allocas + reloads
464-
// CHECK: cir.func coroutine @_Z5byRefRKSt6string(%arg0: !cir.ptr<![[StdString]]>
464+
// CHECK: cir.func coroutine @_Z5byRefRKSt6string(%arg0: !cir.ptr<![[StdString]]> {{.*}}22 extra{{.*}}{
465465
// CHECK: %[[#AllocaParam:]] = cir.alloca !cir.ptr<![[StdString]]>, {{.*}} ["s", init]
466466
// CHECK: %[[#AllocaFnUse:]] = cir.alloca !cir.ptr<![[StdString]]>, {{.*}} ["s", init]
467467

@@ -478,7 +478,7 @@ folly::coro::Task<void> silly_coro() {
478478
// Make sure we properly handle OnFallthrough coro body sub stmt and
479479
// check there are not multiple co_returns emitted.
480480

481-
// CHECK: cir.func coroutine @_Z10silly_corov()
481+
// CHECK: cir.func coroutine @_Z10silly_corov() {{.*}}22 extra{{.*}}{
482482
// CHECK: cir.await(init, ready : {
483483
// CHECK: cir.call @_ZN5folly4coro4TaskIvE12promise_type11return_voidEv
484484
// CHECK-NOT: cir.call @_ZN5folly4coro4TaskIvE12promise_type11return_voidEv
@@ -490,7 +490,7 @@ folly::coro::Task<int> go1() {
490490
co_return co_await task;
491491
}
492492

493-
// CHECK: cir.func coroutine @_Z3go1v()
493+
// CHECK: cir.func coroutine @_Z3go1v() {{.*}}22 extra{{.*}}{
494494
// CHECK: %[[#IntTaskAddr:]] = cir.alloca ![[IntTask]], !cir.ptr<![[IntTask]]>, ["task", init]
495495

496496
// CHECK: cir.await(init, ready : {
@@ -525,16 +525,16 @@ folly::coro::Task<int> go1_lambda() {
525525
co_return co_await task;
526526
}
527527

528-
// CHECK: cir.func coroutine lambda internal private @_ZZ10go1_lambdavENK3$_0clEv
529-
// CHECK: cir.func coroutine @_Z10go1_lambdav()
528+
// CHECK: cir.func coroutine lambda internal private @_ZZ10go1_lambdavENK3$_0clEv{{.*}}22 extra{{.*}}{
529+
// CHECK: cir.func coroutine @_Z10go1_lambdav() {{.*}}22 extra{{.*}}{
530530

531531
folly::coro::Task<int> go4() {
532532
auto* fn = +[](int const& i) -> folly::coro::Task<int> { co_return i; };
533533
auto task = fn(3);
534534
co_return co_await std::move(task);
535535
}
536536

537-
// CHECK: cir.func coroutine @_Z3go4v()
537+
// CHECK: cir.func coroutine @_Z3go4v() {{.*}}22 extra{{.*}}{
538538

539539
// CHECK: cir.await(init, ready : {
540540
// CHECK: }, suspend : {

0 commit comments

Comments
 (0)