[PATCH] D73301: [PatchableFunction] Allow empty entry MachineBasicBlock
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 24 09:46:14 PST 2020
MaskRay updated this revision to Diff 240235.
MaskRay added a comment.
Simplify test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73301/new/
https://reviews.llvm.org/D73301
Files:
llvm/lib/CodeGen/PatchableFunction.cpp
llvm/test/CodeGen/AArch64/patchable-function-entry-empty.mir
Index: llvm/test/CodeGen/AArch64/patchable-function-entry-empty.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/patchable-function-entry-empty.mir
@@ -0,0 +1,64 @@
+# RUN: llc -mtriple=aarch64 -run-pass=patchable-function %s -o - | FileCheck %s
+
+# CHECK: name: empty
+# CHECK: bb.0.entry
+# CHECK: PATCHABLE_FUNCTION_ENTER debug-location !DILocation(line: 1,
+# CHECK-NEXT: RET undef $lr, debug-location !DILocation(line: 1,
+
+## Empty entry MBB, no debug location.
+# CHECK: name: empty_entry
+# CHECK: bb.0.entry
+# CHECK: PATCHABLE_FUNCTION_ENTER{{$}}
+# CHECK: bb.1.here
+
+--- |
+ define void @empty() #0 !dbg !7 {
+ entry:
+ ret void, !dbg !10
+ }
+
+ define void @empty_entry() #0 !dbg !11 {
+ entry:
+ br label %here
+ here:
+ ret void, !dbg !12
+ }
+
+ attributes #0 = { "patchable-function-entry"="1" }
+ !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)
+ !1 = !DIFile(filename: "a.c", directory: "/tmp")
+ !2 = !{}
+ !3 = !{i32 7, !"Dwarf Version", i32 4}
+ !4 = !{i32 2, !"Debug Info Version", i32 3}
+ !5 = !{i32 1, !"wchar_size", i32 4}
+ !6 = !{!"clang version 11.0.0 "}
+ !7 = distinct !DISubprogram(name: "empty", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
+ !8 = !DISubroutineType(types: !9)
+ !9 = !{null}
+ !10 = !DILocation(line: 1, column: 61, scope: !7)
+ !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)
+ !12 = !DILocation(line: 2, column: 61, scope: !11)
+
+...
+---
+name: empty
+alignment: 4
+tracksRegLiveness: true
+body: |
+ bb.0.entry:
+ liveins: $lr
+ RET undef $lr, debug-location !10
+
+...
+---
+name: empty_entry
+alignment: 4
+tracksRegLiveness: true
+body: |
+ bb.0.entry:
+ liveins: $lr
+ bb.1.here:
+ liveins: $lr
+ RET undef $lr, debug-location !12
+
+...
Index: llvm/lib/CodeGen/PatchableFunction.cpp
===================================================================
--- llvm/lib/CodeGen/PatchableFunction.cpp
+++ llvm/lib/CodeGen/PatchableFunction.cpp
@@ -57,10 +57,15 @@
bool PatchableFunction::runOnMachineFunction(MachineFunction &MF) {
if (MF.getFunction().hasFnAttribute("patchable-function-entry")) {
MachineBasicBlock &FirstMBB = *MF.begin();
- MachineInstr &FirstMI = *FirstMBB.begin();
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
- BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
- TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
+ if (FirstMBB.empty()) {
+ BuildMI(&FirstMBB, DebugLoc(),
+ TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
+ } else {
+ MachineInstr &FirstMI = *FirstMBB.begin();
+ BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
+ TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
+ }
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73301.240235.patch
Type: text/x-patch
Size: 3350 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200124/358873ab/attachment.bin>
More information about the llvm-commits
mailing list