From a03a6cedbad8fd3edae985ebd6b871974906cfa0 Mon Sep 17 00:00:00 2001 From: seven-mile Date: Wed, 30 Oct 2024 17:56:02 +0000 Subject: [PATCH] [CIR][Dialect][NFC] Fix double whitespaces in cir.func assembly --- clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 31 ++++++++----------- .../CodeGen/attribute-annotate-multiple.cpp | 4 +-- clang/test/CIR/CodeGen/goto.cpp | 6 ++-- clang/test/CIR/CodeGen/temporaries.cpp | 2 +- clang/test/CIR/CodeGen/vtt.cpp | 2 +- clang/test/CIR/Lowering/loops-with-break.cir | 2 +- clang/test/CIR/Transforms/ternary-fold.cpp | 2 +- 7 files changed, 22 insertions(+), 27 deletions(-) diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index f9b883905b84..a37bb99bf7a0 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -2416,44 +2416,39 @@ ::mlir::Region *mlir::cir::FuncOp::getCallableRegion() { } void mlir::cir::FuncOp::print(OpAsmPrinter &p) { - p << ' '; - // When adding a specific keyword here, do not forget to omit it in // printFunctionAttributes below or there will be a syntax error when // parsing if (getBuiltin()) - p << "builtin "; + p << " builtin"; if (getCoroutine()) - p << "coroutine "; + p << " coroutine"; if (getLambda()) - p << "lambda "; + p << " lambda"; if (getNoProto()) - p << "no_proto "; + p << " no_proto"; if (getComdat()) - p << "comdat "; + p << " comdat"; if (getLinkage() != GlobalLinkageKind::ExternalLinkage) - p << stringifyGlobalLinkageKind(getLinkage()) << ' '; + p << ' ' << stringifyGlobalLinkageKind(getLinkage()); auto vis = getVisibility(); if (vis != mlir::SymbolTable::Visibility::Public) - p << vis << " "; + p << ' ' << vis; auto cirVisibilityAttr = getGlobalVisibilityAttr(); - printVisibilityAttr(p, cirVisibilityAttr); - // TODO: This is a problematic space to be handled conditionally by - // printVisibilityAttr which leads often to a double space in the output. But - // it looks like from here we have also switched from adding a conditional - // trailing space to inserting a leading space, to avoid trailing space at - // EOL. - // TODO: Only use the "insert leading space everywhere". - p << " "; + if (!cirVisibilityAttr.isDefault()) { + p << ' '; + printVisibilityAttr(p, cirVisibilityAttr); + } // Print function name, signature, and control. + p << ' '; p.printSymbolName(getSymName()); auto fnType = getFunctionType(); SmallVector resultTypes; @@ -2466,7 +2461,7 @@ void mlir::cir::FuncOp::print(OpAsmPrinter &p) { p, *this, fnType.getInputs(), fnType.isVarArg(), {}); if (mlir::ArrayAttr annotations = getAnnotationsAttr()) { - p << " "; + p << ' '; p.printAttribute(annotations); } diff --git a/clang/test/CIR/CodeGen/attribute-annotate-multiple.cpp b/clang/test/CIR/CodeGen/attribute-annotate-multiple.cpp index ff970f3919f4..9c360d6bda02 100644 --- a/clang/test/CIR/CodeGen/attribute-annotate-multiple.cpp +++ b/clang/test/CIR/CodeGen/attribute-annotate-multiple.cpp @@ -27,9 +27,9 @@ void bar() __attribute__((annotate("withargfunc", "os", 22))) { // BEFORE: cir.global external @tile = #cir.int<7> : !s32i // BEFORE-SAME: #cir.annotation] -// BEFORE: cir.func @_Z3fooi(%arg0: !s32i) [#cir.annotation, +// BEFORE: cir.func @_Z3fooi(%arg0: !s32i) [#cir.annotation, // BEFORE-SAME: #cir.annotation] -// BEFORE: cir.func @_Z3barv() [#cir.annotation] +// BEFORE: cir.func @_Z3barv() [#cir.annotation] // AFTER: module {{.*}}attribute-annotate-multiple.cpp" attributes diff --git a/clang/test/CIR/CodeGen/goto.cpp b/clang/test/CIR/CodeGen/goto.cpp index aa7547d306df..840b6227696c 100644 --- a/clang/test/CIR/CodeGen/goto.cpp +++ b/clang/test/CIR/CodeGen/goto.cpp @@ -284,7 +284,7 @@ void foo() { } } -// NOFLAT: cir.func @_Z3foov() +// NOFLAT: cir.func @_Z3foov() // NOFLAT: cir.scope { // NOFLAT: cir.label "label" // NOFLAT: %0 = cir.alloca !ty_S, !cir.ptr, ["agg.tmp0"] @@ -324,7 +324,7 @@ extern "C" void case_follow_label(int v) { } } -// NOFLAT: cir.func @case_follow_label +// NOFLAT: cir.func @case_follow_label // NOFLAT: cir.switch // NOFLAT: cir.case(equal, [#cir.int<1> : !s32i]) { // NOFLAT: cir.label "label" @@ -348,7 +348,7 @@ extern "C" void default_follow_label(int v) { } } -// NOFLAT: cir.func @default_follow_label +// NOFLAT: cir.func @default_follow_label // NOFLAT: cir.switch // NOFLAT: cir.case(anyof, [#cir.int<1> : !s32i, #cir.int<2> : !s32i]) { // NOFLAT: cir.call @action1() diff --git a/clang/test/CIR/CodeGen/temporaries.cpp b/clang/test/CIR/CodeGen/temporaries.cpp index 589849bf52c3..2fbbe03b2370 100644 --- a/clang/test/CIR/CodeGen/temporaries.cpp +++ b/clang/test/CIR/CodeGen/temporaries.cpp @@ -17,7 +17,7 @@ void f() { // CIR: cir.func private @_ZN1EC1Ev(!cir.ptr) extra(#fn_attr) // CIR-NEXT: cir.func private @_ZN1EntEv(!cir.ptr) -> !ty_E // CIR-NEXT: cir.func private @_ZN1ED1Ev(!cir.ptr) extra(#fn_attr) -// CIR-NEXT: cir.func @_Z1fv() extra(#fn_attr1) { +// CIR-NEXT: cir.func @_Z1fv() extra(#fn_attr1) { // CIR-NEXT: cir.scope { // CIR-NEXT: %[[ONE:[0-9]+]] = cir.alloca !ty_E, !cir.ptr, ["agg.tmp.ensured"] {alignment = 1 : i64} // CIR-NEXT: %[[TWO:[0-9]+]] = cir.alloca !ty_E, !cir.ptr, ["ref.tmp0"] {alignment = 1 : i64} diff --git a/clang/test/CIR/CodeGen/vtt.cpp b/clang/test/CIR/CodeGen/vtt.cpp index 25437e295afc..797e94475ede 100644 --- a/clang/test/CIR/CodeGen/vtt.cpp +++ b/clang/test/CIR/CodeGen/vtt.cpp @@ -171,7 +171,7 @@ namespace other { } } -// CIR-LABEL: cir.func @_ZN5other1BD1Ev( +// CIR-LABEL: cir.func @_ZN5other1BD1Ev( // CIR-SAME: %[[VAL_0:.*]]: !cir.ptr // CIR: %[[VAL_1:.*]] = cir.alloca !cir.ptr, !cir.ptr>, ["this", init] {alignment = 8 : i64} // CIR: cir.store %[[VAL_0]], %[[VAL_1]] : !cir.ptr, !cir.ptr> diff --git a/clang/test/CIR/Lowering/loops-with-break.cir b/clang/test/CIR/Lowering/loops-with-break.cir index 34b6bfd7618e..6a7ef3e8c023 100644 --- a/clang/test/CIR/Lowering/loops-with-break.cir +++ b/clang/test/CIR/Lowering/loops-with-break.cir @@ -166,7 +166,7 @@ module { // [...] // CHECK: } - cir.func @testWhile() { + cir.func @testWhile() { %0 = cir.alloca !s32i, !cir.ptr, ["i", init] {alignment = 4 : i64} %1 = cir.const #cir.int<0> : !s32i cir.store %1, %0 : !s32i, !cir.ptr diff --git a/clang/test/CIR/Transforms/ternary-fold.cpp b/clang/test/CIR/Transforms/ternary-fold.cpp index 69934da793df..350502e8b9b7 100644 --- a/clang/test/CIR/Transforms/ternary-fold.cpp +++ b/clang/test/CIR/Transforms/ternary-fold.cpp @@ -33,7 +33,7 @@ int test2(bool cond) { return cond ? x : y; } -// CIR-BEFORE: cir.func @_Z5test2b +// CIR-BEFORE: cir.func @_Z5test2b // CIR-BEFORE: %[[#COND:]] = cir.load %{{.+}} : !cir.ptr, !cir.bool // CIR-BEFORE-NEXT: %{{.+}} = cir.ternary(%[[#COND]], true { // CIR-BEFORE-NEXT: %[[#A:]] = cir.const #cir.int<1> : !s32i