Skip to content

Commit 5124c0e

Browse files
committed
Revert "[DWARF] Emit a worst-case prologue_end flag for pathological inputs (llvm#107849)"
This reverts commit bf483dd.
1 parent 44076c9 commit 5124c0e

9 files changed

+33
-405
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 24 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,16 +2062,6 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
20622062
unsigned LastAsmLine =
20632063
Asm->OutStreamer->getContext().getCurrentDwarfLoc().getLine();
20642064

2065-
if (!DL && MI == PrologEndLoc) {
2066-
// In rare situations, we might want to place the end of the prologue
2067-
// somewhere that doesn't have a source location already. It should be in
2068-
// the entry block.
2069-
assert(MI->getParent() == &*MI->getMF()->begin());
2070-
recordSourceLine(SP->getScopeLine(), 0, SP,
2071-
DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT);
2072-
return;
2073-
}
2074-
20752065
bool PrevInstInSameSection =
20762066
(!PrevInstBB ||
20772067
PrevInstBB->getSectionID() == MI->getParent()->getSectionID());
@@ -2147,109 +2137,32 @@ static std::pair<const MachineInstr *, bool>
21472137
findPrologueEndLoc(const MachineFunction *MF) {
21482138
// First known non-DBG_VALUE and non-frame setup location marks
21492139
// the beginning of the function body.
2150-
const auto &TII = *MF->getSubtarget().getInstrInfo();
2151-
const MachineInstr *NonTrivialInst = nullptr;
2140+
const MachineInstr *LineZeroLoc = nullptr;
21522141
const Function &F = MF->getFunction();
21532142

21542143
// Some instructions may be inserted into prologue after this function. Must
21552144
// keep prologue for these cases.
21562145
bool IsEmptyPrologue =
21572146
!(F.hasPrologueData() || F.getMetadata(LLVMContext::MD_func_sanitize));
2158-
2159-
// Helper lambda to examine each instruction and potentially return it
2160-
// as the prologue_end point.
2161-
auto ExamineInst = [&](const MachineInstr &MI)
2162-
-> std::optional<std::pair<const MachineInstr *, bool>> {
2163-
// Is this instruction trivial data shuffling or frame-setup?
2164-
bool isCopy = (TII.isCopyInstr(MI) ? true : false);
2165-
bool isTrivRemat = TII.isTriviallyReMaterializable(MI);
2166-
bool isFrameSetup = MI.getFlag(MachineInstr::FrameSetup);
2167-
2168-
if (!isFrameSetup && MI.getDebugLoc()) {
2169-
// Scan forward to try to find a non-zero line number. The
2170-
// prologue_end marks the first breakpoint in the function after the
2171-
// frame setup, and a compiler-generated line 0 location is not a
2172-
// meaningful breakpoint. If none is found, return the first
2173-
// location after the frame setup.
2174-
if (MI.getDebugLoc().getLine())
2175-
return std::make_pair(&MI, IsEmptyPrologue);
2176-
}
2177-
2178-
// Keep track of the first "non-trivial" instruction seen, i.e. anything
2179-
// that doesn't involve shuffling data around or is a frame-setup.
2180-
if (!isCopy && !isTrivRemat && !isFrameSetup && !NonTrivialInst)
2181-
NonTrivialInst = &MI;
2182-
2183-
IsEmptyPrologue = false;
2184-
return std::nullopt;
2185-
};
2186-
2187-
// Examine all the instructions at the start of the function. This doesn't
2188-
// necessarily mean just the entry block: unoptimised code can fall-through
2189-
// into an initial loop, and it makes sense to put the initial breakpoint on
2190-
// the first instruction of such a loop. However, if we pass branches, we're
2191-
// better off synthesising an early prologue_end.
2192-
auto CurBlock = MF->begin();
2193-
auto CurInst = CurBlock->begin();
2194-
while (true) {
2195-
// Skip empty blocks, in rare cases the entry can be empty.
2196-
if (CurInst == CurBlock->end()) {
2197-
++CurBlock;
2198-
CurInst = CurBlock->begin();
2199-
continue;
2200-
}
2201-
2202-
// Check whether this non-meta instruction a good position for prologue_end.
2203-
if (!CurInst->isMetaInstruction()) {
2204-
auto FoundInst = ExamineInst(*CurInst);
2205-
if (FoundInst)
2206-
return *FoundInst;
2207-
}
2208-
2209-
// Try to continue searching, but use a backup-location if substantive
2210-
// computation is happening.
2211-
auto NextInst = std::next(CurInst);
2212-
if (NextInst != CurInst->getParent()->end()) {
2213-
// Continue examining the current block.
2214-
CurInst = NextInst;
2215-
continue;
2216-
}
2217-
2218-
// We've reached the end of the block. Did we just look at a terminator?
2219-
if (CurInst->isTerminator()) {
2220-
// Some kind of "real" control flow is occurring. At the very least
2221-
// we would have to start exploring the CFG, a good signal that the
2222-
// prologue is over.
2223-
break;
2147+
for (const auto &MBB : *MF) {
2148+
for (const auto &MI : MBB) {
2149+
if (!MI.isMetaInstruction()) {
2150+
if (!MI.getFlag(MachineInstr::FrameSetup) && MI.getDebugLoc()) {
2151+
// Scan forward to try to find a non-zero line number. The
2152+
// prologue_end marks the first breakpoint in the function after the
2153+
// frame setup, and a compiler-generated line 0 location is not a
2154+
// meaningful breakpoint. If none is found, return the first
2155+
// location after the frame setup.
2156+
if (MI.getDebugLoc().getLine())
2157+
return std::make_pair(&MI, IsEmptyPrologue);
2158+
2159+
LineZeroLoc = &MI;
2160+
}
2161+
IsEmptyPrologue = false;
2162+
}
22242163
}
2225-
2226-
// If we've already fallen through into a loop, don't fall through
2227-
// further, use a backup-location.
2228-
if (CurBlock->pred_size() > 1)
2229-
break;
2230-
2231-
// Fall-through from entry to the next block. This is common at -O0 when
2232-
// there's no initialisation in the function. Bail if we're also at the
2233-
// end of the function.
2234-
if (++CurBlock == MF->end())
2235-
break;
2236-
CurInst = CurBlock->begin();
2237-
}
2238-
2239-
// We couldn't find any source-location, suggesting all meaningful information
2240-
// got optimised away. Set the prologue_end to be the first non-trivial
2241-
// instruction, which will get the scope line number. This is better than
2242-
// nothing.
2243-
// Only do this in the entry block, as we'll be giving it the scope line for
2244-
// the function. Return IsEmptyPrologue==true if we've picked the first
2245-
// instruction.
2246-
if (NonTrivialInst && NonTrivialInst->getParent() == &*MF->begin()) {
2247-
IsEmptyPrologue = NonTrivialInst == &*MF->begin()->begin();
2248-
return std::make_pair(NonTrivialInst, IsEmptyPrologue);
22492164
}
2250-
2251-
// If the entry path is empty, just don't have a prologue_end at all.
2252-
return std::make_pair(nullptr, IsEmptyPrologue);
2165+
return std::make_pair(LineZeroLoc, IsEmptyPrologue);
22532166
}
22542167

22552168
/// Register a source line with debug info. Returns the unique label that was
@@ -2281,21 +2194,12 @@ DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
22812194
bool IsEmptyPrologue = PrologEnd.second;
22822195

22832196
// If the prolog is empty, no need to generate scope line for the proc.
2284-
if (IsEmptyPrologue) {
2285-
// If there's nowhere to put a prologue_end flag, emit a scope line in case
2286-
// there are simply no source locations anywhere in the function.
2287-
if (PrologEndLoc) {
2288-
// Avoid trying to assign prologue_end to a line-zero location.
2289-
// Instructions with no DebugLoc at all are fine, they'll be given the
2290-
// scope line nuumber.
2291-
const DebugLoc &DL = PrologEndLoc->getDebugLoc();
2292-
if (!DL || DL->getLine() != 0)
2293-
return PrologEndLoc;
2294-
2295-
// Later, don't place the prologue_end flag on this line-zero location.
2296-
PrologEndLoc = nullptr;
2297-
}
2298-
}
2197+
if (IsEmptyPrologue)
2198+
// In degenerate cases, we can have functions with no source locations
2199+
// at all. These want a scope line, to avoid a totally empty function.
2200+
// Thus, only skip scope line if there's location to place prologue_end.
2201+
if (PrologEndLoc)
2202+
return PrologEndLoc;
22992203

23002204
// Ensure the compile unit is created if the function is called before
23012205
// beginFunction().

llvm/test/CodeGen/X86/no-non-zero-debug-loc-prologue.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
; RUN: llc -filetype=asm -mtriple=x86_64-apple-macosx12.0.0 -O0 %s -o - | FileCheck %s --implicit-check-not=prologue_end
1+
; RUN: llc -filetype=asm -mtriple=x86_64-apple-macosx12.0.0 -O0 %s -o - | FileCheck %s
22
; CHECK: Lfunc_begin0:
33
; CHECK-NEXT: .file{{.+}}
44
; CHECK-NEXT: .loc 1 1 0 ## test-small.c:1:0{{$}}
55
; CHECK-NEXT: .cfi_startproc
66
; CHECK-NEXT: ## %bb.{{[0-9]+}}:
7-
; CHECK-NEXT: .loc 1 0 1
7+
; CHECK-NEXT: .loc 1 0 1 prologue_end{{.*}}
88
define void @test() #0 !dbg !9 {
99
ret void, !dbg !12
1010
}
@@ -19,4 +19,4 @@ define void @test() #0 !dbg !9 {
1919
!9 = distinct !DISubprogram(name: "test", scope: !10, file: !10, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
2020
!10 = !DIFile(filename: "test-small.c", directory: "/Users/shubham/Development/test")
2121
!11 = !DISubroutineType(types: !7)
22-
!12 = !DILocation(line: 0, column: 1, scope: !9)
22+
!12 = !DILocation(line: 0, column: 1, scope: !9)

llvm/test/CodeGen/X86/pseudo_cmov_lower2.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
200200
; minus the DEBUG_VALUE line and changes in labels..
201201
define double @foo1_g(float %p1, double %p2, double %p3) nounwind !dbg !4 {
202202
; CHECK-LABEL: foo1_g:
203+
; CHECK: .file 1 "." "test.c"
204+
; CHECK-NEXT: .loc 1 3 0
203205
; CHECK: # %bb.0: # %entry
204-
; CHECK-NEXT: .file 1 "." "test.c"
205-
; CHECK-NEXT: .loc 1 3 0 prologue_end
206206
; CHECK-NEXT: xorps %xmm3, %xmm3
207207
; CHECK-NEXT: ucomiss %xmm3, %xmm0
208208
; CHECK-NEXT: movsd {{.*#+}} xmm0 = [1.25E+0,0.0E+0]

llvm/test/DebugInfo/MIR/X86/dbg-prologue-backup-loc2.mir

Lines changed: 0 additions & 134 deletions
This file was deleted.

llvm/test/DebugInfo/MIR/X86/empty-inline.mir

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
#
1414
# CHECK: Address Line Column File ISA Discriminator OpIndex Flags
1515
# CHECK-NEXT: ---
16-
# CHECK-NEXT: 25 0 1 0 0 0 is_stmt prologue_end
17-
# CHECK-NEXT: 29 28 1 0 0 0 is_stmt
16+
# CHECK-NEXT: 25 0 1 0 0 0 is_stmt
17+
# CHECK-NEXT: 29 28 1 0 0 0 is_stmt prologue_end
1818
# CHECK-NEXT: 29 28 1 0 0 0 is_stmt end_sequence
19-
2019
--- |
2120
source_filename = "t.ll"
2221
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

0 commit comments

Comments
 (0)