[PATCH] D73301: [PatchableFunction] Allow empty entry MachineBasicBlock

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 15:52:56 PST 2020


MaskRay updated this revision to Diff 240036.
MaskRay added a comment.

Add MIR 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,30 @@
+## Test we can handle empty entry MBB.
+# RUN: llc -mtriple=aarch64 -run-pass=patchable-function %s -o - | FileCheck %s
+
+# CHECK: bb.0.entry
+# CHECK: PATCHABLE_FUNCTION_ENTER
+# CHECK: bb.1.here
+
+--- |
+  define internal fastcc void @empty_entry() "patchable-function-entry"="1" {
+  entry:
+    br label %here
+  here:
+    ret void
+  }
+...
+---
+name:            empty_entry
+alignment:       4
+tracksRegLiveness: true
+frameInfo:
+  maxAlignment:    1
+  maxCallFrameSize: 0
+machineFunctionInfo: {}
+body:             |
+  bb.0.entry:
+    liveins: $lr
+  bb.1.here:
+    liveins: $lr
+    RET undef $lr
+...
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.240036.patch
Type: text/x-patch
Size: 1848 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200123/8d0ea0f6/attachment.bin>


More information about the llvm-commits mailing list