[llvm] 20a568c - [Propeller]: Use a descriptive temporary symbol name for the end of the basic block.
Rahman Lavaee via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 5 13:17:36 PDT 2020
Author: Rahman Lavaee
Date: 2020-08-05T13:17:19-07:00
New Revision: 20a568c29db0117a6f32861826fedbb33329e759
URL: https://github.com/llvm/llvm-project/commit/20a568c29db0117a6f32861826fedbb33329e759
DIFF: https://github.com/llvm/llvm-project/commit/20a568c29db0117a6f32861826fedbb33329e759.diff
LOG: [Propeller]: Use a descriptive temporary symbol name for the end of the basic block.
This patch changes the functionality of AsmPrinter to name the basic block end labels as LBB_END${i}_${j}, with ${i} being the identifier for the function and ${j} being the identifier for the basic block. The new naming scheme is consistent with how basic block labels are named (.LBB${i}_{j}), and how function end symbol are named (.Lfunc_end${i}) and helps to write stronger tests for the upcoming patch for BB-Info section (as proposed in https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html). The end label is used with basicblock-labels (BB-Info section in future) and basicblock-sections to compute the size of basic blocks and basic block sections, respectively. For BB sections, the section containing the entry basic block will not have a BB end label since it already gets the function end-label.
This label is cached for every basic block (CachedEndMCSymbol) like the label for the basic block (CachedMCSymbol).
Differential Revision: https://reviews.llvm.org/D83885
Added:
Modified:
llvm/include/llvm/CodeGen/MachineBasicBlock.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/test/CodeGen/X86/basic-block-sections-clusters.ll
llvm/test/CodeGen/X86/basic-block-sections-listbb.ll
llvm/test/CodeGen/X86/basic-block-sections.ll
llvm/test/DebugInfo/X86/basic-block-sections_1.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index 0360e706cbc4..144457a1bc47 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -174,8 +174,9 @@ class MachineBasicBlock
/// is only computed once and is cached.
mutable MCSymbol *CachedMCSymbol = nullptr;
- /// Used during basic block sections to mark the end of a basic block.
- MCSymbol *EndMCSymbol = nullptr;
+ /// Marks the end of the basic block. Used during basic block sections to
+ /// calculate the size of the basic block, or the BB section ending with it.
+ mutable MCSymbol *CachedEndMCSymbol = nullptr;
// Intrusive list support
MachineBasicBlock() = default;
@@ -474,6 +475,9 @@ class MachineBasicBlock
/// Sets the section ID for this basic block.
void setSectionID(MBBSectionID V) { SectionID = V; }
+ /// Returns the MCSymbol marking the end of this basic block.
+ MCSymbol *getEndSymbol() const;
+
/// Returns true if this block may have an INLINEASM_BR (overestimate, by
/// checking if any of the successors are indirect targets of any inlineasm_br
/// in the function).
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 78f18ab8aff6..ae7bea9c97cc 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1173,24 +1173,20 @@ void AsmPrinter::emitFunctionBody() {
}
}
- // We need a temporary symbol for the end of this basic block, if either we
- // have BBLabels enabled and we want to emit size directive for the BBs, or
- // if this basic blocks marks the end of a section (except the section
+ // We must emit temporary symbol for the end of this basic block, if either
+ // we have BBLabels enabled and we want to emit size directive for the BBs,
+ // or if this basic blocks marks the end of a section (except the section
// containing the entry basic block as the end symbol for that section is
// CurrentFnEnd).
- MCSymbol *CurrentBBEnd = nullptr;
if ((MAI->hasDotTypeDotSizeDirective() && MF->hasBBLabels()) ||
- (MBB.isEndSection() && !MBB.sameSection(&MF->front()))) {
- CurrentBBEnd = OutContext.createTempSymbol();
- OutStreamer->emitLabel(CurrentBBEnd);
- }
+ (MBB.isEndSection() && !MBB.sameSection(&MF->front())))
+ OutStreamer->emitLabel(MBB.getEndSymbol());
// Helper for emitting the size directive associated with a basic block
// symbol.
auto emitELFSizeDirective = [&](MCSymbol *SymForSize) {
- assert(CurrentBBEnd && "Basicblock end symbol not set!");
const MCExpr *SizeExp = MCBinaryExpr::createSub(
- MCSymbolRefExpr::create(CurrentBBEnd, OutContext),
+ MCSymbolRefExpr::create(MBB.getEndSymbol(), OutContext),
MCSymbolRefExpr::create(SymForSize, OutContext), OutContext);
OutStreamer->emitELFSize(SymForSize, SizeExp);
};
@@ -1207,7 +1203,7 @@ void AsmPrinter::emitFunctionBody() {
if (MAI->hasDotTypeDotSizeDirective())
emitELFSizeDirective(CurrentSectionBeginSym);
MBBSectionRanges[MBB.getSectionIDNum()] =
- MBBSectionRange{CurrentSectionBeginSym, CurrentBBEnd};
+ MBBSectionRange{CurrentSectionBeginSym, MBB.getEndSymbol()};
}
}
emitBasicBlockEnd(MBB);
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 626c04074a61..ebdd17fc728d 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -100,6 +100,17 @@ MCSymbol *MachineBasicBlock::getSymbol() const {
return CachedMCSymbol;
}
+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()));
+ }
+ return CachedEndMCSymbol;
+}
raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineBasicBlock &MBB) {
MBB.print(OS);
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-clusters.ll b/llvm/test/CodeGen/X86/basic-block-sections-clusters.ll
index 12759496fddd..1fd76f470cfa 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-clusters.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-clusters.ll
@@ -42,14 +42,18 @@ declare i32 @baz() #1
; LINUX-SECTIONS1-NOT: .section
; LINUX-SECTIONS1-LABEL: foo:
; LINUX-SECTIONS1-NOT: .section
+; LINUX-SECTIONS1-NOT: .LBB_END0_{{0-9}}+
; LINUX-SECTIONS1-LABEL: # %bb.2:
+; LINUX-SECTIONS1-NOT: .LBB_END0_{{0-9}}+
; LINUX-SECTIONS1: .section .text.foo,"ax", at progbits,unique,1
; LINUX-SECTIONS1-LABEL: foo.1:
-; LINUX-SECTIONS1-LABEL: .Ltmp0:
-; LINUX-SECTIONS1-NEXT: .size foo.1, .Ltmp0-foo.1
+; LINUX-SECTIONS1-LABEL: .LBB_END0_1:
+; LINUX-SECTIONS1-NEXT: .size foo.1, .LBB_END0_1-foo.1
; LINUX-SECTIONS1-NOT: .section
; LINUX-SECTIONS1: .section .text.unlikely.foo,"ax", at progbits
; LINUX-SECTIONS1-LABEL: foo.cold:
+; LINUX-SECTIONS1-LABEL: .LBB_END0_3:
+; LINUX-SECTIONS1-NEXT: .size foo.cold, .LBB_END0_3-foo.cold
; LINUX-SECTIONS1: .section .text.foo,"ax", at progbits
; LINUX-SECTIONS1-LABEL: .Lfunc_end0:
; LINUX-SECTIONS1-NEXT: .size foo, .Lfunc_end0-foo
@@ -57,14 +61,18 @@ declare i32 @baz() #1
; LINUX-SECTIONS2: .section .text.foo,"ax", at progbits
; LINUX-SECTIONS2-NOT: .section
; LINUX-SECTIONS2-LABEL: foo:
+; LINUX-SECTIONS2-NOT: .LBB_END0_{{0-9}}+
; LINUX-SECTIONS2-NOT: .section
; LINUX-SECTIONS2-LABEL: # %bb.2:
+; LINUX-SECTIONS2-NOT: .LBB_END0_{{0-9}}+
; LINUX-SECTIONS2: .section .text.foo,"ax", at progbits,unique,1
; LINUX-SECTIONS2-NEXT: foo.0:
+; LINUX-SECTIONS2-NOT: .LBB_END0_{{0-9}}+
; LINUX-SECTIONS2-NOT: .section
; LINUX-SECTIONS2-LABEL: .LBB0_3:
-; LINUX-SECTIONS2-LABEL: .Ltmp0:
-; LINUX-SECTIONS2-NEXT: .size foo.0, .Ltmp0-foo.0
+; LINUX-SECTIONS2-LABEL: .LBB_END0_3:
+; LINUX-SECTIONS2-NEXT: .size foo.0, .LBB_END0_3-foo.0
; LINUX-SECTIONS2: .section .text.foo,"ax", at progbits
+; LINUX-SECTIONS2-NOT: .LBB_END0_{{0-9}}+
; LINUX-SECTIONS2-LABEL: .Lfunc_end0:
; LINUX-SECTIONS2-NEXT: .size foo, .Lfunc_end0-foo
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-listbb.ll b/llvm/test/CodeGen/X86/basic-block-sections-listbb.ll
index ab729ecf9eb2..53bf56e67fe5 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-listbb.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-listbb.ll
@@ -36,8 +36,11 @@ declare i32 @_Z3foov() #1
; LINUX-SECTIONS-NOT: .section .text._Z3bazb._Z3bazb.{{[0-9]+}},"ax", at progbits
; LINUX-SECTIONS-LABEL: # %bb.1:
; LINUX-SECTIONS-NEXT: callq _Z3barv
-; LINUX-SECTIONS: .section .text._Z3bazb._Z3bazb.{{[0-9]+}},"ax", at progbits
-; LINUX-SECTIONS-LABEL: _Z3bazb.{{[0-9]+}}:
+; LINUX-SECTIONS: .section .text._Z3bazb.[[SECTION_LABEL:_Z3bazb.[0-9]+]],"ax", at progbits
+; LINUX-SECTIONS-NEXT: [[SECTION_LABEL]]:
; LINUX-SECTIONS-NEXT: callq _Z3foov
-; LINUX-SECTIONS: .Ltmp0:
-; LINUX-SECTIONS-NEXT: .size _Z3bazb.{{[0-9]+}}, .Ltmp0-_Z3bazb.{{[0-9]+}}
+; LINUX-SECTIONS: .LBB_END0_2:
+; LINUX-SECTIONS-NEXT: .size [[SECTION_LABEL]], .LBB_END0_2-[[SECTION_LABEL]]
+; LINUX-SECTIONS: .section .text._Z3bazb,"ax", at progbits
+; LINUX-SECTIONS: .Lfunc_end0:
+; LINUX-SECTIONS-NEXT: .size _Z3bazb, .Lfunc_end0-_Z3bazb
diff --git a/llvm/test/CodeGen/X86/basic-block-sections.ll b/llvm/test/CodeGen/X86/basic-block-sections.ll
index d996f5e9f539..81bb5d5b4c91 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections.ll
@@ -30,9 +30,9 @@ declare i32 @_Z3foov() #1
; LINUX-SECTIONS: _Z3bazb:
; LINUX-SECTIONS: .section .text._Z3bazb._Z3bazb.1,"ax", at progbits
; LINUX-SECTIONS: _Z3bazb.1:
-; LINUX-SECTIONS: .Ltmp0:
-; LINUX-SECTIONS-NEXT: .size _Z3bazb.1, .Ltmp0-_Z3bazb.1
+; LINUX-SECTIONS: .LBB_END0_1:
+; LINUX-SECTIONS-NEXT: .size _Z3bazb.1, .LBB_END0_1-_Z3bazb.1
; LINUX-SECTIONS: .section .text._Z3bazb._Z3bazb.2,"ax", at progbits
; LINUX-SECTIONS: _Z3bazb.2:
-; LINUX-SECTIONS: .Ltmp1:
-; LINUX-SECTIONS-NEXT: .size _Z3bazb.2, .Ltmp1-_Z3bazb.2
+; LINUX-SECTIONS: .LBB_END0_2:
+; LINUX-SECTIONS-NEXT: .size _Z3bazb.2, .LBB_END0_2-_Z3bazb.2
diff --git a/llvm/test/DebugInfo/X86/basic-block-sections_1.ll b/llvm/test/DebugInfo/X86/basic-block-sections_1.ll
index 655e84731cba..9c6ae3bf5f72 100644
--- a/llvm/test/DebugInfo/X86/basic-block-sections_1.ll
+++ b/llvm/test/DebugInfo/X86/basic-block-sections_1.ll
@@ -25,24 +25,24 @@
; BB-SECTIONS-ASM: .Ltmp{{[0-9]+}}:
; BB-SECTIONS-ASM-NEXT: .loc 1 2 7 is_stmt
; BB-SECTIONS-ASM: _Z3fooi.1:
-; BB-SECTIONS-ASM: .Ltmp{{[0-9]+}}:
-; BB-SECTIONS-ASM: .size _Z3fooi.1, .Ltmp{{[0-9]+}}-_Z3fooi.1
+; BB-SECTIONS-ASM: .LBB_END0_{{[0-9]+}}:
+; BB-SECTIONS-ASM: .size _Z3fooi.1, .LBB_END0_{{[0-9]+}}-_Z3fooi.1
; BB-SECTIONS-ASM: _Z3fooi.2:
; BB-SECTIONS-ASM: .Ltmp{{[0-9]+}}:
-; BB-SECTIONS-ASM-NEXT: .Ltmp{{[0-9]+}}:
-; BB-SECTIONS-ASM: .size _Z3fooi.2, .Ltmp{{[0-9]+}}-_Z3fooi.2
+; BB-SECTIONS-ASM-NEXT: .LBB_END0_{{[0-9]+}}:
+; BB-SECTIONS-ASM: .size _Z3fooi.2, .LBB_END0_{{[0-9]+}}-_Z3fooi.2
; BB-SECTIONS-ASM: _Z3fooi.3:
; BB-SECTIONS-ASM: .Ltmp{{[0-9]+}}:
-; BB-SECTIONS-ASM-NEXT: .Ltmp{{[0-9]+}}:
-; BB-SECTIONS-ASM: .size _Z3fooi.3, .Ltmp{{[0-9]+}}-_Z3fooi.3
+; BB-SECTIONS-ASM-NEXT: .LBB_END0_{{[0-9]+}}:
+; BB-SECTIONS-ASM: .size _Z3fooi.3, .LBB_END0_{{[0-9]+}}-_Z3fooi.3
; BB-SECTIONS-ASM: .Lfunc_end0:
; BB-SECTIONS-ASM: .Ldebug_ranges0:
; BB-SECTIONS-ASM-NEXT: .quad _Z3fooi.1
-; BB-SECTIONS-ASM-NEXT: .quad .Ltmp{{[0-9]+}}
+; BB-SECTIONS-ASM-NEXT: .quad .LBB_END0_{{[0-9]+}}
; BB-SECTIONS-ASM-NEXT: .quad _Z3fooi.2
-; BB-SECTIONS-ASM-NEXT: .quad .Ltmp{{[0-9]+}}
+; BB-SECTIONS-ASM-NEXT: .quad .LBB_END0_{{[0-9]+}}
; BB-SECTIONS-ASM-NEXT: .quad _Z3fooi.3
-; BB-SECTIONS-ASM-NEXT: .quad .Ltmp{{[0-9]+}}
+; BB-SECTIONS-ASM-NEXT: .quad .LBB_END0_{{[0-9]+}}
; BB-SECTIONS-ASM-NEXT: .quad .Lfunc_begin0
; BB-SECTIONS-ASM-NEXT: .quad .Lfunc_end0
; BB-SECTIONS-ASM-NEXT: .quad 0
More information about the llvm-commits
mailing list