[PATCH] D27913: [XRay] Fix assertion failure on empty machine basic blocks (PR 31424)

Dean Michael Berris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 19 01:31:14 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL290091: [XRay] Fix assertion failure on empty machine basic blocks (PR 31424) (authored by dberris).

Changed prior to commit:
  https://reviews.llvm.org/D27913?vs=81924&id=81930#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27913

Files:
  llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
  llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir
  llvm/trunk/test/CodeGen/X86/xray-empty-function.mir


Index: llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
+++ llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
@@ -129,7 +129,15 @@
       return false; // Function is too small.
   }
 
-  auto &FirstMBB = *MF.begin();
+  // We look for the first non-empty MachineBasicBlock, so that we can insert
+  // the function instrumentation in the appropriate place.
+  auto MBI =
+      find_if(MF, [&](const MachineBasicBlock &MBB) { return !MBB.empty(); });
+  if (MBI == MF.end())
+    return false; // The function is empty.
+
+  auto *TII = MF.getSubtarget().getInstrInfo();
+  auto &FirstMBB = *MBI;
   auto &FirstMI = *FirstMBB.begin();
 
   if (!MF.getSubtarget().isXRaySupported()) {
@@ -142,7 +150,6 @@
 
   // First, insert an PATCHABLE_FUNCTION_ENTER as the first instruction of the
   // MachineFunction.
-  auto *TII = MF.getSubtarget().getInstrInfo();
   BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
           TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
 
Index: llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir
===================================================================
--- llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir
+++ llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir
@@ -0,0 +1,23 @@
+# RUN: llc -run-pass xray-instrumentation -mtriple=x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+#
+# Make sure we can handle empty first basic blocks.
+
+--- |
+
+  define i32 @foo() noinline uwtable "xray-instruction-threshold"="1" {
+  entry:
+    unreachable
+  }
+
+...
+
+---
+name: foo
+tracksRegLiveness: true
+liveins:
+  - { reg: '%edi'}
+body:            |
+  bb.0.entry:
+    liveins: %edi
+    ; CHECK-NOT: PATCHABLE_FUNCTION_ENTER
+...
Index: llvm/trunk/test/CodeGen/X86/xray-empty-function.mir
===================================================================
--- llvm/trunk/test/CodeGen/X86/xray-empty-function.mir
+++ llvm/trunk/test/CodeGen/X86/xray-empty-function.mir
@@ -0,0 +1,13 @@
+# RUN: llc -run-pass xray-instrumentation -mtriple=x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+#
+# Make sure we can handle empty functions.
+---
+name: empty
+tracksRegLiveness: true
+liveins:
+  - { reg: '%edi'}
+body:            |
+  bb.0:
+    ; CHECK-NOT: PATCHABLE_FUNCTION_ENTER
+...
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27913.81930.patch
Type: text/x-patch
Size: 2355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161219/b15d2439/attachment.bin>


More information about the llvm-commits mailing list