Skip to content

Commit 36165ff

Browse files
committed
[CodeGen] Use temporary symbol for MBBs
Internal label names never occur in the symbol table, so when using an object streamer, there's no point in constructing these names and then adding them to hash tables -- they are never visible in the output. It's not possible to reuse createTempSymbol, because on BPF has a different prefix for globals and basic blocks right now.
1 parent 638d968 commit 36165ff

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

llvm/include/llvm/MC/MCContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,12 @@ class MCContext {
458458
MCSymbol *createNamedTempSymbol();
459459
MCSymbol *createNamedTempSymbol(const Twine &Name);
460460

461+
/// Get or create a symbol for a basic block. For non-always-emit symbols,
462+
/// this behaves like createTempSymbol, except that it uses the
463+
/// PrivateLabelPrefix instead of the PrivateGlobalPrefix. When AlwaysEmit is
464+
/// true, behaves like getOrCreateSymbol, prefixed with PrivateLabelPrefix.
465+
MCSymbol *createBlockSymbol(const Twine &Name, bool AlwaysEmit = false);
466+
461467
/// Create the definition of a directional local symbol for numbered label
462468
/// (used for "1:" definitions).
463469
MCSymbol *createDirectionalLocalSymbol(unsigned LocalLabelVal);

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ MCSymbol *MachineBasicBlock::getSymbol() const {
8080
}
8181
CachedMCSymbol = Ctx.getOrCreateSymbol(MF->getName() + Suffix);
8282
} else {
83-
const StringRef Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix();
84-
CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" +
85-
Twine(MF->getFunctionNumber()) +
86-
"_" + Twine(getNumber()));
83+
// If the block occurs as label in inline assembly, parsing the assembly
84+
// needs an actual label name => set AlwaysEmit in these cases.
85+
CachedMCSymbol = Ctx.createBlockSymbol(
86+
"BB" + Twine(MF->getFunctionNumber()) + "_" + Twine(getNumber()),
87+
/*AlwaysEmit=*/hasLabelMustBeEmitted());
8788
}
8889
}
8990
return CachedMCSymbol;
@@ -104,10 +105,9 @@ MCSymbol *MachineBasicBlock::getEndSymbol() const {
104105
if (!CachedEndMCSymbol) {
105106
const MachineFunction *MF = getParent();
106107
MCContext &Ctx = MF->getContext();
107-
auto Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix();
108-
CachedEndMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB_END" +
109-
Twine(MF->getFunctionNumber()) +
110-
"_" + Twine(getNumber()));
108+
CachedEndMCSymbol = Ctx.createBlockSymbol(
109+
"BB_END" + Twine(MF->getFunctionNumber()) + "_" + Twine(getNumber()),
110+
/*AlwaysEmit=*/false);
111111
}
112112
return CachedEndMCSymbol;
113113
}

llvm/lib/MC/MCContext.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ MCSymbol *MCContext::createNamedTempSymbol(const Twine &Name) {
309309
return createSymbol(NameSV, true, false);
310310
}
311311

312+
MCSymbol *MCContext::createBlockSymbol(const Twine &Name, bool AlwaysEmit) {
313+
if (AlwaysEmit)
314+
return getOrCreateSymbol(MAI->getPrivateLabelPrefix() + Name);
315+
316+
if (!UseNamesOnTempLabels)
317+
return createSymbolImpl(nullptr, /*IsTemporary=*/true);
318+
319+
SmallString<128> NameSV;
320+
raw_svector_ostream(NameSV) << MAI->getPrivateLabelPrefix() << Name;
321+
return createSymbol(NameSV, false, /*IsTemporary=*/true);
322+
}
323+
312324
MCSymbol *MCContext::createLinkerPrivateTempSymbol() {
313325
return createLinkerPrivateSymbol("tmp");
314326
}

llvm/test/CodeGen/AArch64/branch-relax-cross-section.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ body: |
473473
; INDIRECT-NEXT: successors: %bb.1
474474
; INDIRECT-NEXT: liveins: $x16
475475
; INDIRECT-NEXT: {{ $}}
476-
; INDIRECT-NEXT: $[[SCAVENGED_REGISTER:x[0-9]+]] = ADRP target-flags(aarch64-page) <mcsymbol .LBB5_1>
477-
; INDIRECT-NEXT: $[[SCAVENGED_REGISTER]] = ADDXri $[[SCAVENGED_REGISTER]], target-flags(aarch64-pageoff, aarch64-nc) <mcsymbol .LBB5_1>, 0
476+
; INDIRECT-NEXT: $[[SCAVENGED_REGISTER:x[0-9]+]] = ADRP target-flags(aarch64-page) <mcsymbol >
477+
; INDIRECT-NEXT: $[[SCAVENGED_REGISTER]] = ADDXri $[[SCAVENGED_REGISTER]], target-flags(aarch64-pageoff, aarch64-nc) <mcsymbol >, 0
478478
; INDIRECT-NEXT: BR $[[SCAVENGED_REGISTER]]
479479
480480
bb.0.entry:

llvm/test/CodeGen/BPF/objdump_cond_op.ll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
2727
br label %13
2828
; CHECK: r1 <<= 32
2929
; CHECK: r1 >>= 32
30-
; CHECK: if r1 != 2 goto +6 <LBB0_2>
30+
; CHECK: if r1 != 2 goto +6 <test+0x48>
3131

3232
; <label>:8: ; preds = %2
3333
%9 = icmp eq i32 %0, %1
@@ -38,32 +38,29 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
3838
; CHECK: r0 = *(u32 *)(r1 + 0)
3939
; CHECK: r0 *= r0
4040
; CHECK: r0 <<= 1
41-
; CHECK: goto +7 <LBB0_4>
41+
; CHECK: goto +7 <test+0x80>
4242

4343
; <label>:11: ; preds = %8
4444
%12 = shl nsw i32 %10, 2
4545
br label %13
4646

47-
; CHECK-LABEL: <LBB0_2>:
4847
; CHECK: r3 = 0 ll
4948
; CHECK: r0 = *(u32 *)(r3 + 0)
5049
; CHECK: r2 <<= 32
5150
; CHECK: r2 >>= 32
52-
; CHECK: if r1 == r2 goto +4 <LBB0_5>
51+
; CHECK: if r1 == r2 goto +4 <test+0x98>
5352
; CHECK: r0 <<= 2
5453

5554
; <label>:13: ; preds = %4, %11
5655
%14 = phi i32 [ %12, %11 ], [ %7, %4 ]
5756
store i32 %14, ptr @gbl, align 4
5857
br label %15
59-
; CHECK-LABEL: <LBB0_4>:
6058
; CHECK: r1 = 0 ll
6159
; CHECK: *(u32 *)(r1 + 0) = r0
6260

6361
; <label>:15: ; preds = %8, %13
6462
%16 = phi i32 [ %14, %13 ], [ %10, %8 ]
6563
ret i32 %16
66-
; CHECK-LABEL: <LBB0_5>:
6764
; CHECK: exit
6865
}
6966
attributes #0 = { norecurse nounwind }

llvm/test/CodeGen/BPF/objdump_cond_op_2.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
1414

1515
; <label>:4: ; preds = %2
1616
br label %5
17-
; CHECK: if r4 s>= r3 goto +10 <LBB0_2>
18-
; CHECK-LABEL: <LBB0_1>:
17+
; CHECK: if r4 s>= r3 goto +10 <test+0x90>
1918

2019
; <label>:5: ; preds = %4, %5
2120
%6 = phi i32 [ %9, %5 ], [ 0, %4 ]
@@ -27,12 +26,11 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
2726
%12 = icmp slt i32 %10, %11
2827
br i1 %12, label %5, label %13
2928
; CHECK: r1 = r3
30-
; CHECK: if r2 s> r3 goto -10 <LBB0_1>
29+
; CHECK: if r2 s> r3 goto -10 <test+0x40>
3130

3231
; <label>:13: ; preds = %5, %2
3332
%14 = phi i32 [ 0, %2 ], [ %9, %5 ]
3433
ret i32 %14
35-
; CHECK-LABEL: <LBB0_2>:
3634
; CHECK: exit
3735
}
3836
attributes #0 = { norecurse nounwind readnone }

0 commit comments

Comments
 (0)