Skip to content

Commit 5932f7b

Browse files
committed
[PatchableFunction] Use an empty DebugLoc
The current FirstMI.getDebugLoc() is actually null in almost all cases. If it isn't, the generated .loc will be considered initial. The .loc will have the prologue_end flag and terminate the prologue prematurely. Also use an overload of BuildMI that will not prepend PATCHABLE_FUNCTION_ENTRY to a MachineInstr bundle.
1 parent d82e993 commit 5932f7b

File tree

2 files changed

+6
-36
lines changed

2 files changed

+6
-36
lines changed

llvm/lib/CodeGen/PatchableFunction.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,9 @@ bool PatchableFunction::runOnMachineFunction(MachineFunction &MF) {
5858
if (MF.getFunction().hasFnAttribute("patchable-function-entry")) {
5959
MachineBasicBlock &FirstMBB = *MF.begin();
6060
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
61-
if (FirstMBB.empty()) {
62-
BuildMI(&FirstMBB, DebugLoc(),
63-
TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
64-
} else {
65-
MachineInstr &FirstMI = *FirstMBB.begin();
66-
BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
67-
TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
68-
}
61+
// The initial .loc covers PATCHABLE_FUNCTION_ENTER.
62+
BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
63+
TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
6964
return true;
7065
}
7166

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
# RUN: llc -mtriple=aarch64 -run-pass=patchable-function %s -o - | FileCheck %s
22

3+
## The initial .loc covers PATCHABLE_FUNCTION_ENTER.
4+
## Emitting a new .loc may create a prologue_end prematurely.
35
# CHECK: name: empty
46
# CHECK: bb.0.entry
5-
# CHECK: PATCHABLE_FUNCTION_ENTER debug-location !DILocation(line: 1,
6-
# CHECK-NEXT: RET undef $lr, debug-location !DILocation(line: 1,
7-
8-
## Empty entry MBB, no debug location.
9-
# CHECK: name: empty_entry
10-
# CHECK: bb.0.entry
117
# CHECK: PATCHABLE_FUNCTION_ENTER{{$}}
12-
# CHECK: bb.1.here
8+
# CHECK-NEXT: RET undef $lr, debug-location !DILocation(line: 1,
139

1410
--- |
1511
define void @empty() #0 !dbg !7 {
1612
entry:
1713
ret void, !dbg !10
1814
}
1915

20-
define void @empty_entry() #0 !dbg !11 {
21-
entry:
22-
br label %here
23-
here:
24-
ret void, !dbg !12
25-
}
26-
2716
attributes #0 = { "patchable-function-entry"="1" }
2817
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
2918
!1 = !DIFile(filename: "a.c", directory: "/tmp")
@@ -36,8 +25,6 @@
3625
!8 = !DISubroutineType(types: !9)
3726
!9 = !{null}
3827
!10 = !DILocation(line: 1, column: 61, scope: !7)
39-
!11 = distinct !DISubprogram(name: "empty_entry", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
40-
!12 = !DILocation(line: 2, column: 61, scope: !11)
4128

4229
...
4330
---
@@ -50,15 +37,3 @@ body: |
5037
RET undef $lr, debug-location !10
5138
5239
...
53-
---
54-
name: empty_entry
55-
alignment: 4
56-
tracksRegLiveness: true
57-
body: |
58-
bb.0.entry:
59-
liveins: $lr
60-
bb.1.here:
61-
liveins: $lr
62-
RET undef $lr, debug-location !12
63-
64-
...

0 commit comments

Comments
 (0)