Skip to content

Commit 50a3ff3

Browse files
committed
[PatchableFunction] Allow empty entry MachineBasicBlock
Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D73301
1 parent 0d61cd2 commit 50a3ff3

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

llvm/lib/CodeGen/PatchableFunction.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ static bool doesNotGeneratecode(const MachineInstr &MI) {
5757
bool PatchableFunction::runOnMachineFunction(MachineFunction &MF) {
5858
if (MF.getFunction().hasFnAttribute("patchable-function-entry")) {
5959
MachineBasicBlock &FirstMBB = *MF.begin();
60-
MachineInstr &FirstMI = *FirstMBB.begin();
6160
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
62-
BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
63-
TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
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+
}
6469
return true;
6570
}
6671

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# RUN: llc -mtriple=aarch64 -run-pass=patchable-function %s -o - | FileCheck %s
2+
3+
# CHECK: name: empty
4+
# 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
11+
# CHECK: PATCHABLE_FUNCTION_ENTER{{$}}
12+
# CHECK: bb.1.here
13+
14+
--- |
15+
define void @empty() #0 !dbg !7 {
16+
entry:
17+
ret void, !dbg !10
18+
}
19+
20+
define void @empty_entry() #0 !dbg !11 {
21+
entry:
22+
br label %here
23+
here:
24+
ret void, !dbg !12
25+
}
26+
27+
attributes #0 = { "patchable-function-entry"="1" }
28+
!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)
29+
!1 = !DIFile(filename: "a.c", directory: "/tmp")
30+
!2 = !{}
31+
!3 = !{i32 7, !"Dwarf Version", i32 4}
32+
!4 = !{i32 2, !"Debug Info Version", i32 3}
33+
!5 = !{i32 1, !"wchar_size", i32 4}
34+
!6 = !{!"clang version 11.0.0 "}
35+
!7 = distinct !DISubprogram(name: "empty", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
36+
!8 = !DISubroutineType(types: !9)
37+
!9 = !{null}
38+
!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)
41+
42+
...
43+
---
44+
name: empty
45+
alignment: 4
46+
tracksRegLiveness: true
47+
body: |
48+
bb.0.entry:
49+
liveins: $lr
50+
RET undef $lr, debug-location !10
51+
52+
...
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)