[llvm] r290091 - [XRay] Fix assertion failure on empty machine basic blocks (PR 31424)
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 19 01:20:39 PST 2016
Author: dberris
Date: Mon Dec 19 03:20:38 2016
New Revision: 290091
URL: http://llvm.org/viewvc/llvm-project?rev=290091&view=rev
Log:
[XRay] Fix assertion failure on empty machine basic blocks (PR 31424)
The original version of the code in XRayInstrumentation.cpp assumed that
functions may not have empty machine basic blocks (or that the first one
couldn't be). This change addresses that by special-casing that specific
situation.
We provide two .mir test-cases to make sure we're handling this
appropriately.
Fixes llvm.org/PR31424.
Reviewers: chandlerc
Subscribers: varno, llvm-commits
Differential Revision: https://reviews.llvm.org/D27913
Added:
llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir
llvm/trunk/test/CodeGen/X86/xray-empty-function.mir
Modified:
llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
Modified: llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp?rev=290091&r1=290090&r2=290091&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp (original)
+++ llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp Mon Dec 19 03:20:38 2016
@@ -129,7 +129,15 @@ bool XRayInstrumentation::runOnMachineFu
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 @@ bool XRayInstrumentation::runOnMachineFu
// 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));
Added: llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir?rev=290091&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir (added)
+++ llvm/trunk/test/CodeGen/X86/xray-empty-firstmbb.mir Mon Dec 19 03:20:38 2016
@@ -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
+...
Added: llvm/trunk/test/CodeGen/X86/xray-empty-function.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-empty-function.mir?rev=290091&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xray-empty-function.mir (added)
+++ llvm/trunk/test/CodeGen/X86/xray-empty-function.mir Mon Dec 19 03:20:38 2016
@@ -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
+...
+
More information about the llvm-commits
mailing list