From f822a05a88df229792d09a0040e72a4bc34fac7b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 1 Feb 2020 13:28:19 -0800 Subject: [PATCH] [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. --- lib/CodeGen/PatchableFunction.cpp | 11 ++----- .../patchable-function-entry-empty.mir | 31 ++----------------- 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/lib/CodeGen/PatchableFunction.cpp b/lib/CodeGen/PatchableFunction.cpp index a8466396f9b..ca44b7a5398 100644 --- a/lib/CodeGen/PatchableFunction.cpp +++ b/lib/CodeGen/PatchableFunction.cpp @@ -58,14 +58,9 @@ bool PatchableFunction::runOnMachineFunction(MachineFunction &MF) { if (MF.getFunction().hasFnAttribute("patchable-function-entry")) { MachineBasicBlock &FirstMBB = *MF.begin(); const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo(); - 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)); - } + // The initial .loc covers PATCHABLE_FUNCTION_ENTER. + BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(), + TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER)); return true; } diff --git a/test/CodeGen/AArch64/patchable-function-entry-empty.mir b/test/CodeGen/AArch64/patchable-function-entry-empty.mir index 032e07aacbc..36513297ede 100644 --- a/test/CodeGen/AArch64/patchable-function-entry-empty.mir +++ b/test/CodeGen/AArch64/patchable-function-entry-empty.mir @@ -1,15 +1,11 @@ # RUN: llc -mtriple=aarch64 -run-pass=patchable-function %s -o - | FileCheck %s +## The initial .loc covers PATCHABLE_FUNCTION_ENTER. +## Emitting a new .loc may create a prologue_end prematurely. # 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 +# CHECK-NEXT: RET undef $lr, debug-location !DILocation(line: 1, --- | define void @empty() #0 !dbg !7 { @@ -17,13 +13,6 @@ 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") @@ -36,8 +25,6 @@ !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) ... --- @@ -50,15 +37,3 @@ body: | 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 - -...