Skip to content

Commit 11ca2be

Browse files
seven-milelanza
authored andcommitted
[CIR][CodeGen] Use the same SSA name as OG's for string literals (#1073)
This PR changes the naming format of string literals from `.str1` to `.str.1`, making it easier to reuse the existing testcases of OG CodeGen.
1 parent 18a3820 commit 11ca2be

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ CIRGenModule::getAddrOfConstantStringFromLiteral(const StringLiteral *S,
15361536
SmallString<256> StringNameBuffer = Name;
15371537
llvm::raw_svector_ostream Out(StringNameBuffer);
15381538
if (StringLiteralCnt)
1539-
Out << StringLiteralCnt;
1539+
Out << '.' << StringLiteralCnt;
15401540
Name = Out.str();
15411541
StringLiteralCnt++;
15421542

clang/test/CIR/CodeGen/dtors-scopes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void dtor1() {
2424

2525
// DTOR_BODY: cir.func linkonce_odr @_ZN1CD2Ev{{.*}}{
2626
// DTOR_BODY: %2 = cir.get_global @printf
27-
// DTOR_BODY: %3 = cir.get_global @".str2"
27+
// DTOR_BODY: %3 = cir.get_global @".str.2"
2828
// DTOR_BODY: %4 = cir.cast(array_to_ptrdecay, %3
2929
// DTOR_BODY: %5 = cir.call @printf(%4)
3030
// DTOR_BODY: cir.return

clang/test/CIR/CodeGen/globals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ int use_func() { return func<int>(); }
5252
// CHECK-NEXT: cir.global "private" constant cir_private dsolocal @".str" = #cir.const_array<"example\00" : !cir.array<!s8i x 8>> : !cir.array<!s8i x 8> {alignment = 1 : i64}
5353
// CHECK-NEXT: cir.global external @s = #cir.global_view<@".str"> : !cir.ptr<!s8i>
5454

55-
// CHECK-NEXT: cir.global "private" constant cir_private dsolocal @".str1" = #cir.const_array<"example1\00" : !cir.array<!s8i x 9>> : !cir.array<!s8i x 9> {alignment = 1 : i64}
56-
// CHECK-NEXT: cir.global external @s1 = #cir.global_view<@".str1"> : !cir.ptr<!s8i>
55+
// CHECK-NEXT: cir.global "private" constant cir_private dsolocal @".str.1" = #cir.const_array<"example1\00" : !cir.array<!s8i x 9>> : !cir.array<!s8i x 9> {alignment = 1 : i64}
56+
// CHECK-NEXT: cir.global external @s1 = #cir.global_view<@".str.1"> : !cir.ptr<!s8i>
5757

5858
// CHECK-NEXT: cir.global external @s2 = #cir.global_view<@".str"> : !cir.ptr<!s8i>
5959

clang/test/CIR/CodeGen/initlist-ptr-ptr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void test() {
5454
// LLVM: %"class.std::initializer_list<const char *>" = type { ptr, ptr }
5555

5656
// LLVM: @.str = private constant [3 x i8] c"xy\00"
57-
// LLVM: @.str1 = private constant [3 x i8] c"uv\00"
57+
// LLVM: @.str.1 = private constant [3 x i8] c"uv\00"
5858

5959
// LLVM: define linkonce_odr void @_ZSt1fIPKcEvSt16initializer_listIT_E(%"class.std::initializer_list<const char *>" [[ARG0:%.*]])
6060
// LLVM: [[LOCAL_PTR:%.*]] = alloca %"class.std::initializer_list<const char *>", i64 1, align 8,
@@ -70,7 +70,7 @@ void test() {
7070
// LLVM: [[PTR_FIRST_ELEM:%.*]] = getelementptr ptr, ptr [[ELEM_ARRAY_PTR]], i32 0,
7171
// LLVM: store ptr @.str, ptr [[PTR_FIRST_ELEM]], align 8,
7272
// LLVM: [[PTR_SECOND_ELEM:%.*]] = getelementptr ptr, ptr [[PTR_FIRST_ELEM]], i64 1,
73-
// LLVM: store ptr @.str1, ptr [[PTR_SECOND_ELEM]], align 8,
73+
// LLVM: store ptr @.str.1, ptr [[PTR_SECOND_ELEM]], align 8,
7474
// LLVM: [[INIT_START_FLD_PTR:%.*]] = getelementptr %"class.std::initializer_list<const char *>", ptr [[INIT_STRUCT]], i32 0, i32 0,
7575
// LLVM: [[INIT_END_FLD_PTR:%.*]] = getelementptr %"class.std::initializer_list<const char *>", ptr [[INIT_STRUCT]], i32 0, i32 1,
7676
// LLVM: [[ELEM_ARRAY_END:%.*]] = getelementptr [2 x ptr], ptr [[ELEM_ARRAY_PTR]], i64 2,

clang/test/CIR/CodeGen/predefined.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ void m() {
1313
// CHECK: %0 = cir.get_global @".str" : !cir.ptr<!cir.array<!s8i x 7>>
1414
// CHECK: %1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s8i x 7>>), !cir.ptr<!s8i>
1515
// CHECK: %2 = cir.const #cir.int<79> : !s32i
16-
// CHECK: %3 = cir.get_global @".str1" : !cir.ptr<!cir.array<!s8i x 9>>
16+
// CHECK: %3 = cir.get_global @".str.1" : !cir.ptr<!cir.array<!s8i x 9>>
1717
// CHECK: %4 = cir.cast(array_to_ptrdecay, %3 : !cir.ptr<!cir.array<!s8i x 9>>), !cir.ptr<!s8i>
18-
// CHECK: %5 = cir.get_global @".str2" : !cir.ptr<!cir.array<!s8i x 5>>
18+
// CHECK: %5 = cir.get_global @".str.2" : !cir.ptr<!cir.array<!s8i x 5>>
1919
// CHECK: %6 = cir.cast(array_to_ptrdecay, %5 : !cir.ptr<!cir.array<!s8i x 5>>), !cir.ptr<!s8i>
2020
// CHECK: cir.call @__assert2(%1, %2, %4, %6) : (!cir.ptr<!s8i>, !s32i, !cir.ptr<!s8i>, !cir.ptr<!s8i>) -> ()
2121
// CHECK: cir.return

clang/test/CIR/IR/global.cir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module {
1111
cir.global external @rgb2 = #cir.const_struct<{#cir.int<0> : !s8i, #cir.int<5> : !s64i, #cir.ptr<null> : !cir.ptr<!s8i>}> : !cir.struct<struct {!s8i, !s64i, !cir.ptr<!s8i>}>
1212
cir.global "private" constant internal @".str" : !cir.array<!s8i x 8> {alignment = 1 : i64}
1313
cir.global "private" internal @c : !s32i
14-
cir.global "private" constant internal @".str2" = #cir.const_array<"example\00" : !cir.array<!s8i x 8>> : !cir.array<!s8i x 8> {alignment = 1 : i64}
15-
cir.global external @s = #cir.global_view<@".str2"> : !cir.ptr<!s8i>
14+
cir.global "private" constant internal @".str.2" = #cir.const_array<"example\00" : !cir.array<!s8i x 8>> : !cir.array<!s8i x 8> {alignment = 1 : i64}
15+
cir.global external @s = #cir.global_view<@".str.2"> : !cir.ptr<!s8i>
1616
cir.func @use_global() {
1717
%0 = cir.get_global @a : !cir.ptr<!s32i>
1818
cir.return
@@ -80,8 +80,8 @@ module {
8080
// CHECK: cir.global external @b = #cir.const_array<"example\00" : !cir.array<!s8i x 8>>
8181
// CHECK: cir.global "private" constant internal @".str" : !cir.array<!s8i x 8> {alignment = 1 : i64}
8282
// CHECK: cir.global "private" internal @c : !s32i
83-
// CHECK: cir.global "private" constant internal @".str2" = #cir.const_array<"example\00" : !cir.array<!s8i x 8>> : !cir.array<!s8i x 8> {alignment = 1 : i64}
84-
// CHECK: cir.global external @s = #cir.global_view<@".str2"> : !cir.ptr<!s8i>
83+
// CHECK: cir.global "private" constant internal @".str.2" = #cir.const_array<"example\00" : !cir.array<!s8i x 8>> : !cir.array<!s8i x 8> {alignment = 1 : i64}
84+
// CHECK: cir.global external @s = #cir.global_view<@".str.2"> : !cir.ptr<!s8i>
8585

8686

8787
// CHECK: cir.func @use_global()

clang/test/CIR/IR/invalid.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ module {
353353

354354
module {
355355
// expected-error@+1 {{expected type declaration for string literal}}
356-
cir.global "private" constant external @".str2" = #cir.const_array<"example\00"> {alignment = 1 : i64}
356+
cir.global "private" constant external @".str.2" = #cir.const_array<"example\00"> {alignment = 1 : i64}
357357
}
358358

359359
// -----

clang/test/CIR/Lowering/globals.cir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ module {
4141
// MLIR: %0 = llvm.mlir.addressof @a : !llvm.ptr
4242
// MLIR: llvm.return %0 : !llvm.ptr
4343
// MLIR: }
44-
cir.global "private" constant internal @".str1" = #cir.const_array<"example1\00" : !cir.array<!s8i x 9>> : !cir.array<!s8i x 9> {alignment = 1 : i64}
45-
cir.global external @s1 = #cir.global_view<@".str1"> : !cir.ptr<!s8i>
44+
cir.global "private" constant internal @".str.1" = #cir.const_array<"example1\00" : !cir.array<!s8i x 9>> : !cir.array<!s8i x 9> {alignment = 1 : i64}
45+
cir.global external @s1 = #cir.global_view<@".str.1"> : !cir.ptr<!s8i>
4646
cir.global external @s2 = #cir.global_view<@".str"> : !cir.ptr<!s8i>
4747
cir.func @_Z10use_globalv() {
4848
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["li", init] {alignment = 4 : i64}

0 commit comments

Comments
 (0)