-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[CodeGen] Use temp symbol for MBBs #95031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
1fc3704
to
36165ff
Compare
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-mc Author: None (aengelke) ChangesInternal 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. Full diff: https://github.com/llvm/llvm-project/pull/95031.diff 6 Files Affected:
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 72eae85467dc9..91b956a3aec60 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -458,6 +458,12 @@ class MCContext {
MCSymbol *createNamedTempSymbol();
MCSymbol *createNamedTempSymbol(const Twine &Name);
+ /// Get or create a symbol for a basic block. For non-always-emit symbols,
+ /// this behaves like createTempSymbol, except that it uses the
+ /// PrivateLabelPrefix instead of the PrivateGlobalPrefix. When AlwaysEmit is
+ /// true, behaves like getOrCreateSymbol, prefixed with PrivateLabelPrefix.
+ MCSymbol *createBlockSymbol(const Twine &Name, bool AlwaysEmit = false);
+
/// Create the definition of a directional local symbol for numbered label
/// (used for "1:" definitions).
MCSymbol *createDirectionalLocalSymbol(unsigned LocalLabelVal);
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 16505f21f0aad..abf43e39ee9a6 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -80,10 +80,11 @@ MCSymbol *MachineBasicBlock::getSymbol() const {
}
CachedMCSymbol = Ctx.getOrCreateSymbol(MF->getName() + Suffix);
} else {
- const StringRef Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix();
- CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" +
- Twine(MF->getFunctionNumber()) +
- "_" + Twine(getNumber()));
+ // If the block occurs as label in inline assembly, parsing the assembly
+ // needs an actual label name => set AlwaysEmit in these cases.
+ CachedMCSymbol = Ctx.createBlockSymbol(
+ "BB" + Twine(MF->getFunctionNumber()) + "_" + Twine(getNumber()),
+ /*AlwaysEmit=*/hasLabelMustBeEmitted());
}
}
return CachedMCSymbol;
@@ -104,10 +105,9 @@ MCSymbol *MachineBasicBlock::getEndSymbol() const {
if (!CachedEndMCSymbol) {
const MachineFunction *MF = getParent();
MCContext &Ctx = MF->getContext();
- auto Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix();
- CachedEndMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB_END" +
- Twine(MF->getFunctionNumber()) +
- "_" + Twine(getNumber()));
+ CachedEndMCSymbol = Ctx.createBlockSymbol(
+ "BB_END" + Twine(MF->getFunctionNumber()) + "_" + Twine(getNumber()),
+ /*AlwaysEmit=*/false);
}
return CachedEndMCSymbol;
}
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 1590054717960..4c69ef79f2064 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -309,6 +309,18 @@ MCSymbol *MCContext::createNamedTempSymbol(const Twine &Name) {
return createSymbol(NameSV, true, false);
}
+MCSymbol *MCContext::createBlockSymbol(const Twine &Name, bool AlwaysEmit) {
+ if (AlwaysEmit)
+ return getOrCreateSymbol(MAI->getPrivateLabelPrefix() + Name);
+
+ if (!UseNamesOnTempLabels)
+ return createSymbolImpl(nullptr, /*IsTemporary=*/true);
+
+ SmallString<128> NameSV;
+ raw_svector_ostream(NameSV) << MAI->getPrivateLabelPrefix() << Name;
+ return createSymbol(NameSV, false, /*IsTemporary=*/true);
+}
+
MCSymbol *MCContext::createLinkerPrivateTempSymbol() {
return createLinkerPrivateSymbol("tmp");
}
diff --git a/llvm/test/CodeGen/AArch64/branch-relax-cross-section.mir b/llvm/test/CodeGen/AArch64/branch-relax-cross-section.mir
index f8f0b76f1c9ff..db88bf0044a5f 100644
--- a/llvm/test/CodeGen/AArch64/branch-relax-cross-section.mir
+++ b/llvm/test/CodeGen/AArch64/branch-relax-cross-section.mir
@@ -473,8 +473,8 @@ body: |
; INDIRECT-NEXT: successors: %bb.1
; INDIRECT-NEXT: liveins: $x16
; INDIRECT-NEXT: {{ $}}
- ; INDIRECT-NEXT: $[[SCAVENGED_REGISTER:x[0-9]+]] = ADRP target-flags(aarch64-page) <mcsymbol .LBB5_1>
- ; INDIRECT-NEXT: $[[SCAVENGED_REGISTER]] = ADDXri $[[SCAVENGED_REGISTER]], target-flags(aarch64-pageoff, aarch64-nc) <mcsymbol .LBB5_1>, 0
+ ; INDIRECT-NEXT: $[[SCAVENGED_REGISTER:x[0-9]+]] = ADRP target-flags(aarch64-page) <mcsymbol >
+ ; INDIRECT-NEXT: $[[SCAVENGED_REGISTER]] = ADDXri $[[SCAVENGED_REGISTER]], target-flags(aarch64-pageoff, aarch64-nc) <mcsymbol >, 0
; INDIRECT-NEXT: BR $[[SCAVENGED_REGISTER]]
bb.0.entry:
diff --git a/llvm/test/CodeGen/BPF/objdump_cond_op.ll b/llvm/test/CodeGen/BPF/objdump_cond_op.ll
index 4a4fa84376cc8..3b2e6c1922fc4 100644
--- a/llvm/test/CodeGen/BPF/objdump_cond_op.ll
+++ b/llvm/test/CodeGen/BPF/objdump_cond_op.ll
@@ -27,7 +27,7 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
br label %13
; CHECK: r1 <<= 32
; CHECK: r1 >>= 32
-; CHECK: if r1 != 2 goto +6 <LBB0_2>
+; CHECK: if r1 != 2 goto +6 <test+0x48>
; <label>:8: ; preds = %2
%9 = icmp eq i32 %0, %1
@@ -38,32 +38,29 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
; CHECK: r0 = *(u32 *)(r1 + 0)
; CHECK: r0 *= r0
; CHECK: r0 <<= 1
-; CHECK: goto +7 <LBB0_4>
+; CHECK: goto +7 <test+0x80>
; <label>:11: ; preds = %8
%12 = shl nsw i32 %10, 2
br label %13
-; CHECK-LABEL: <LBB0_2>:
; CHECK: r3 = 0 ll
; CHECK: r0 = *(u32 *)(r3 + 0)
; CHECK: r2 <<= 32
; CHECK: r2 >>= 32
-; CHECK: if r1 == r2 goto +4 <LBB0_5>
+; CHECK: if r1 == r2 goto +4 <test+0x98>
; CHECK: r0 <<= 2
; <label>:13: ; preds = %4, %11
%14 = phi i32 [ %12, %11 ], [ %7, %4 ]
store i32 %14, ptr @gbl, align 4
br label %15
-; CHECK-LABEL: <LBB0_4>:
; CHECK: r1 = 0 ll
; CHECK: *(u32 *)(r1 + 0) = r0
; <label>:15: ; preds = %8, %13
%16 = phi i32 [ %14, %13 ], [ %10, %8 ]
ret i32 %16
-; CHECK-LABEL: <LBB0_5>:
; CHECK: exit
}
attributes #0 = { norecurse nounwind }
diff --git a/llvm/test/CodeGen/BPF/objdump_cond_op_2.ll b/llvm/test/CodeGen/BPF/objdump_cond_op_2.ll
index 4edd52a463ea9..8c9e91d4a80ea 100644
--- a/llvm/test/CodeGen/BPF/objdump_cond_op_2.ll
+++ b/llvm/test/CodeGen/BPF/objdump_cond_op_2.ll
@@ -14,8 +14,7 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
; <label>:4: ; preds = %2
br label %5
-; CHECK: if r4 s>= r3 goto +10 <LBB0_2>
-; CHECK-LABEL: <LBB0_1>:
+; CHECK: if r4 s>= r3 goto +10 <test+0x90>
; <label>:5: ; preds = %4, %5
%6 = phi i32 [ %9, %5 ], [ 0, %4 ]
@@ -27,12 +26,11 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
%12 = icmp slt i32 %10, %11
br i1 %12, label %5, label %13
; CHECK: r1 = r3
-; CHECK: if r2 s> r3 goto -10 <LBB0_1>
+; CHECK: if r2 s> r3 goto -10 <test+0x40>
; <label>:13: ; preds = %5, %2
%14 = phi i32 [ 0, %2 ], [ %9, %5 ]
ret i32 %14
-; CHECK-LABEL: <LBB0_2>:
; CHECK: exit
}
attributes #0 = { norecurse nounwind readnone }
|
Shall we consider this blocked by the resolution to BPF #95103 ? |
I don't think so. This maintains the existing functionality of separate label/global prefixes. Removing this distinction and cleaning up the code can be done later once all BPF also uses the same local/global prefix. The only BPF-related change is that basic block labels are no longer in the symbol table if they are not referenced by inline assembly. That should be fine, because @4ast said in #95103:
So this PR reduces this regression (although it does not fix it entirely, that's what #95103 originally was). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm as well
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.
36165ff
to
495ef59
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/478 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/405 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/422 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/360 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/133/builds/317 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/328 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/177/builds/308 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/78/builds/361 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/356 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/12/builds/379 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/2/builds/462 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/3/builds/319 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/332 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/564 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/423 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/360 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/376 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/372 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/280 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/638 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/507 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/368 Here is the relevant piece of the build log for the reference:
|
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.
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.