Skip to content

Commit bc9f172

Browse files
seven-milelanza
authored andcommitted
[CIR][Dialect][NFC] Fix double whitespaces in cir.func assembly (#1028)
This PR fixes the notorious double whitespaces introduced by visibility attribute, for `cir.func` only. It uses "leading whitespace" for every print. And the printing of visibility attr is properly guarded by a check of `!isDefault()`. Double whitespaces in test files are removed.
1 parent 1f3deff commit bc9f172

File tree

7 files changed

+22
-27
lines changed

7 files changed

+22
-27
lines changed

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

+13-18
Original file line numberDiff line numberDiff line change
@@ -2416,44 +2416,39 @@ ::mlir::Region *mlir::cir::FuncOp::getCallableRegion() {
24162416
}
24172417

24182418
void mlir::cir::FuncOp::print(OpAsmPrinter &p) {
2419-
p << ' ';
2420-
24212419
// When adding a specific keyword here, do not forget to omit it in
24222420
// printFunctionAttributes below or there will be a syntax error when
24232421
// parsing
24242422
if (getBuiltin())
2425-
p << "builtin ";
2423+
p << " builtin";
24262424

24272425
if (getCoroutine())
2428-
p << "coroutine ";
2426+
p << " coroutine";
24292427

24302428
if (getLambda())
2431-
p << "lambda ";
2429+
p << " lambda";
24322430

24332431
if (getNoProto())
2434-
p << "no_proto ";
2432+
p << " no_proto";
24352433

24362434
if (getComdat())
2437-
p << "comdat ";
2435+
p << " comdat";
24382436

24392437
if (getLinkage() != GlobalLinkageKind::ExternalLinkage)
2440-
p << stringifyGlobalLinkageKind(getLinkage()) << ' ';
2438+
p << ' ' << stringifyGlobalLinkageKind(getLinkage());
24412439

24422440
auto vis = getVisibility();
24432441
if (vis != mlir::SymbolTable::Visibility::Public)
2444-
p << vis << " ";
2442+
p << ' ' << vis;
24452443

24462444
auto cirVisibilityAttr = getGlobalVisibilityAttr();
2447-
printVisibilityAttr(p, cirVisibilityAttr);
2448-
// TODO: This is a problematic space to be handled conditionally by
2449-
// printVisibilityAttr which leads often to a double space in the output. But
2450-
// it looks like from here we have also switched from adding a conditional
2451-
// trailing space to inserting a leading space, to avoid trailing space at
2452-
// EOL.
2453-
// TODO: Only use the "insert leading space everywhere".
2454-
p << " ";
2445+
if (!cirVisibilityAttr.isDefault()) {
2446+
p << ' ';
2447+
printVisibilityAttr(p, cirVisibilityAttr);
2448+
}
24552449

24562450
// Print function name, signature, and control.
2451+
p << ' ';
24572452
p.printSymbolName(getSymName());
24582453
auto fnType = getFunctionType();
24592454
SmallVector<Type, 1> resultTypes;
@@ -2466,7 +2461,7 @@ void mlir::cir::FuncOp::print(OpAsmPrinter &p) {
24662461
p, *this, fnType.getInputs(), fnType.isVarArg(), {});
24672462

24682463
if (mlir::ArrayAttr annotations = getAnnotationsAttr()) {
2469-
p << " ";
2464+
p << ' ';
24702465
p.printAttribute(annotations);
24712466
}
24722467

clang/test/CIR/CodeGen/attribute-annotate-multiple.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ void bar() __attribute__((annotate("withargfunc", "os", 22))) {
2727
// BEFORE: cir.global external @tile = #cir.int<7> : !s32i
2828
// BEFORE-SAME: #cir.annotation<name = "cir.aie.device.tile", args = [42 : i8]>]
2929

30-
// BEFORE: cir.func @_Z3fooi(%arg0: !s32i) [#cir.annotation<name = "noargfunc", args = []>,
30+
// BEFORE: cir.func @_Z3fooi(%arg0: !s32i) [#cir.annotation<name = "noargfunc", args = []>,
3131
// BEFORE-SAME: #cir.annotation<name = "withargfunc", args = ["os", 23 : i32]>]
32-
// BEFORE: cir.func @_Z3barv() [#cir.annotation<name = "withargfunc", args = ["os", 22 : i32]>]
32+
// BEFORE: cir.func @_Z3barv() [#cir.annotation<name = "withargfunc", args = ["os", 22 : i32]>]
3333

3434

3535
// AFTER: module {{.*}}attribute-annotate-multiple.cpp" attributes

clang/test/CIR/CodeGen/goto.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void foo() {
284284
}
285285
}
286286

287-
// NOFLAT: cir.func @_Z3foov()
287+
// NOFLAT: cir.func @_Z3foov()
288288
// NOFLAT: cir.scope {
289289
// NOFLAT: cir.label "label"
290290
// NOFLAT: %0 = cir.alloca !ty_S, !cir.ptr<!ty_S>, ["agg.tmp0"]
@@ -324,7 +324,7 @@ extern "C" void case_follow_label(int v) {
324324
}
325325
}
326326

327-
// NOFLAT: cir.func @case_follow_label
327+
// NOFLAT: cir.func @case_follow_label
328328
// NOFLAT: cir.switch
329329
// NOFLAT: cir.case(equal, [#cir.int<1> : !s32i]) {
330330
// NOFLAT: cir.label "label"
@@ -348,7 +348,7 @@ extern "C" void default_follow_label(int v) {
348348
}
349349
}
350350

351-
// NOFLAT: cir.func @default_follow_label
351+
// NOFLAT: cir.func @default_follow_label
352352
// NOFLAT: cir.switch
353353
// NOFLAT: cir.case(anyof, [#cir.int<1> : !s32i, #cir.int<2> : !s32i]) {
354354
// NOFLAT: cir.call @action1()

clang/test/CIR/CodeGen/temporaries.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void f() {
1717
// CIR: cir.func private @_ZN1EC1Ev(!cir.ptr<!ty_E>) extra(#fn_attr)
1818
// CIR-NEXT: cir.func private @_ZN1EntEv(!cir.ptr<!ty_E>) -> !ty_E
1919
// CIR-NEXT: cir.func private @_ZN1ED1Ev(!cir.ptr<!ty_E>) extra(#fn_attr)
20-
// CIR-NEXT: cir.func @_Z1fv() extra(#fn_attr1) {
20+
// CIR-NEXT: cir.func @_Z1fv() extra(#fn_attr1) {
2121
// CIR-NEXT: cir.scope {
2222
// CIR-NEXT: %[[ONE:[0-9]+]] = cir.alloca !ty_E, !cir.ptr<!ty_E>, ["agg.tmp.ensured"] {alignment = 1 : i64}
2323
// CIR-NEXT: %[[TWO:[0-9]+]] = cir.alloca !ty_E, !cir.ptr<!ty_E>, ["ref.tmp0"] {alignment = 1 : i64}

clang/test/CIR/CodeGen/vtt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ namespace other {
171171
}
172172
}
173173

174-
// CIR-LABEL: cir.func @_ZN5other1BD1Ev(
174+
// CIR-LABEL: cir.func @_ZN5other1BD1Ev(
175175
// CIR-SAME: %[[VAL_0:.*]]: !cir.ptr<!ty_other3A3AB>
176176
// CIR: %[[VAL_1:.*]] = cir.alloca !cir.ptr<!ty_other3A3AB>, !cir.ptr<!cir.ptr<!ty_other3A3AB>>, ["this", init] {alignment = 8 : i64}
177177
// CIR: cir.store %[[VAL_0]], %[[VAL_1]] : !cir.ptr<!ty_other3A3AB>, !cir.ptr<!cir.ptr<!ty_other3A3AB>>

clang/test/CIR/Lowering/loops-with-break.cir

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ module {
166166
// [...]
167167
// CHECK: }
168168

169-
cir.func @testWhile() {
169+
cir.func @testWhile() {
170170
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64}
171171
%1 = cir.const #cir.int<0> : !s32i
172172
cir.store %1, %0 : !s32i, !cir.ptr<!s32i>

clang/test/CIR/Transforms/ternary-fold.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int test2(bool cond) {
3333
return cond ? x : y;
3434
}
3535

36-
// CIR-BEFORE: cir.func @_Z5test2b
36+
// CIR-BEFORE: cir.func @_Z5test2b
3737
// CIR-BEFORE: %[[#COND:]] = cir.load %{{.+}} : !cir.ptr<!cir.bool>, !cir.bool
3838
// CIR-BEFORE-NEXT: %{{.+}} = cir.ternary(%[[#COND]], true {
3939
// CIR-BEFORE-NEXT: %[[#A:]] = cir.const #cir.int<1> : !s32i

0 commit comments

Comments
 (0)