[llvm] cebf77f - [CodeGen][DebugInfo] Add missing DebugLoc for SplitCriticalEdge (#72192)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 7 18:44:38 PDT 2024
Author: Haohai Wen
Date: 2024-04-08T09:44:34+08:00
New Revision: cebf77fb936a7270c7e3fa5c4a7e76216321d385
URL: https://github.com/llvm/llvm-project/commit/cebf77fb936a7270c7e3fa5c4a7e76216321d385
DIFF: https://github.com/llvm/llvm-project/commit/cebf77fb936a7270c7e3fa5c4a7e76216321d385.diff
LOG: [CodeGen][DebugInfo] Add missing DebugLoc for SplitCriticalEdge (#72192)
In SplitCriticalEdge, DebugLoc of the branch instruction in new created
MBB was set to empty. It should be set and we can find proper DebugLoc
for it in most cases. This patch set it to non empty merged DebugLoc of
current MBB branches.
Added:
Modified:
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/test/CodeGen/X86/fsafdo_test1.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 4410fb7ecd23b6..b2114c250ac09d 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1137,7 +1137,6 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
MachineFunction *MF = getParent();
MachineBasicBlock *PrevFallthrough = getNextNode();
- DebugLoc DL; // FIXME: this is nowhere
MachineBasicBlock *NMBB = MF->CreateMachineBasicBlock();
NMBB->setCallFrameSize(Succ->getCallFrameSize());
@@ -1218,6 +1217,15 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
SlotIndexUpdateDelegate SlotUpdater(*MF, Indexes);
SmallVector<MachineOperand, 4> Cond;
const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo();
+
+ // In original 'this' BB, there must be a branch instruction targeting at
+ // Succ. We can not find it out since currently getBranchDestBlock was not
+ // implemented for all targets. However, if the merged DL has column or line
+ // number, the scope and non-zero column and line number is same with that
+ // branch instruction so we can safely use it.
+ DebugLoc DL, MergedDL = findBranchDebugLoc();
+ if (MergedDL && (MergedDL.getLine() || MergedDL.getCol()))
+ DL = MergedDL;
TII->insertBranch(*NMBB, Succ, nullptr, Cond, DL);
}
diff --git a/llvm/test/CodeGen/X86/fsafdo_test1.ll b/llvm/test/CodeGen/X86/fsafdo_test1.ll
index b5ae3915294cd7..61c0f59aba6f81 100644
--- a/llvm/test/CodeGen/X86/fsafdo_test1.ll
+++ b/llvm/test/CodeGen/X86/fsafdo_test1.ll
@@ -6,7 +6,7 @@
; V01: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
; V0: .loc 1 9 5 is_stmt 0 discriminator 11266 # foo.c:9:5
; V0: .loc 1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3
-; V1: .loc 1 9 5 is_stmt 0 discriminator 258 # foo.c:9:5
+; V1: .loc 1 9 5 is_stmt 0 discriminator 514 # foo.c:9:5
; V1: .loc 1 7 3 is_stmt 1 discriminator 258 # foo.c:7:3
; Check that variable __llvm_fs_discriminator__ is generated.
; V01: .type __llvm_fs_discriminator__, at object # @__llvm_fs_discriminator__
More information about the llvm-commits
mailing list