[llvm] r312772 - [XRay][CodeGen][PowerPC] Fix tail exit codegen for XRay in PPC
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 18:47:57 PDT 2017
Author: dberris
Date: Thu Sep 7 18:47:56 2017
New Revision: 312772
URL: http://llvm.org/viewvc/llvm-project?rev=312772&view=rev
Log:
[XRay][CodeGen][PowerPC] Fix tail exit codegen for XRay in PPC
Summary:
This fixes code-gen for XRay in PPC. The regression wasn't caught by
codegen tests which we add in this change.
What happened was the following:
- For tail exits, we used to unconditionally prepend the returns/exits
with a pseudo-instruction that gets lowered to the instrumentation
sled (and leave the actual return/exit instruction as-is).
- Changes to the XRay instrumentation pass caused the tail exits to
suddenly also emit the tail exit pseudo-instruction, since the check
for whether a return instruction was also a call instruction meant it
was a tail exit instruction.
- None of the tests caught the regression either due to non-existent
tests, or the tests being disabled/removed for continuous breakage.
This change re-introduces some of the basic tests and verifies that
we're back to a state that allows the back-end to generate appropriate
XRay instrumented binaries for PPC in the presence of tail exits.
Reviewers: echristo, timshen
Subscribers: nemanjai, kbarton, llvm-commits
Differential Revision: https://reviews.llvm.org/D37570
Added:
llvm/trunk/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll
llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-hidden.ll
llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-sled.ll
Modified:
llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
Modified: llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp?rev=312772&r1=312771&r2=312772&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp (original)
+++ llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp Thu Sep 7 18:47:56 2017
@@ -14,8 +14,8 @@
//
//===---------------------------------------------------------------------===//
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Triple.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineDominators.h"
@@ -109,22 +109,13 @@ void XRayInstrumentation::replaceRetWith
void XRayInstrumentation::prependRetWithPatchableExit(
MachineFunction &MF, const TargetInstrInfo *TII) {
- for (auto &MBB : MF) {
- for (auto &T : MBB.terminators()) {
- unsigned Opc = 0;
+ for (auto &MBB : MF)
+ for (auto &T : MBB.terminators())
if (T.isReturn()) {
- Opc = TargetOpcode::PATCHABLE_FUNCTION_EXIT;
- }
- if (TII->isTailCall(T)) {
- Opc = TargetOpcode::PATCHABLE_TAIL_CALL;
- }
- if (Opc != 0) {
- // Prepend the return instruction with PATCHABLE_FUNCTION_EXIT or
- // PATCHABLE_TAIL_CALL .
- BuildMI(MBB, T, T.getDebugLoc(), TII->get(Opc));
+ // Prepend the return instruction with PATCHABLE_FUNCTION_EXIT.
+ BuildMI(MBB, T, T.getDebugLoc(),
+ TII->get(TargetOpcode::PATCHABLE_FUNCTION_EXIT));
}
- }
- }
}
bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) {
@@ -143,7 +134,7 @@ bool XRayInstrumentation::runOnMachineFu
// Count the number of MachineInstr`s in MachineFunction
int64_t MICount = 0;
- for (const auto& MBB : MF)
+ for (const auto &MBB : MF)
MICount += MBB.size();
// Check if we have a loop.
Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=312772&r1=312771&r2=312772&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Thu Sep 7 18:47:56 2017
@@ -1131,6 +1131,8 @@ void PPCLinuxAsmPrinter::EmitInstruction
break;
}
case TargetOpcode::PATCHABLE_TAIL_CALL:
+ // TODO: Define a trampoline `__xray_FunctionTailExit` and differentiate a
+ // normal function exit from a tail exit.
case TargetOpcode::PATCHABLE_RET:
// PPC's tail call instruction, e.g. PPC::TCRETURNdi8, doesn't really
// lower to a PPC::B instruction. The PPC::B instruction is generated
Added: llvm/trunk/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll?rev=312772&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll (added)
+++ llvm/trunk/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll Thu Sep 7 18:47:56 2017
@@ -0,0 +1,44 @@
+; RUN: llc -filetype=asm -o - -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
+; RUN: llc -filetype=asm -o - -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN: -relocation-model=pic < %s | FileCheck %s
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: .Ltmp0:
+; CHECK: b .Ltmp1
+; CHECK-NEXT: nop
+; CHECK-NEXT: std 0, -8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: bl __xray_FunctionEntry
+; CHECK-NEXT: nop
+; CHECK-NEXT: mtlr 0
+; CHECK-LABEL: .Ltmp1:
+ ret i32 0
+; CHECK-LABEL: .Ltmp2:
+; CHECK: blr
+; CHECK-NEXT: nop
+; CHECK-NEXT: std 0, -8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: bl __xray_FunctionExit
+; CHECK-NEXT: nop
+; CHECK-NEXT: mtlr 0
+}
+; CHECK-LABEL: xray_instr_map,"awo", at progbits,.text,unique,1
+; CHECK: .Lxray_sleds_start0:
+; CHECK-NEXT: .quad .Ltmp0
+; CHECK-NEXT: .quad foo
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .quad .Ltmp2
+; CHECK-NEXT: .quad foo
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+; CHECK-LABEL: xray_fn_idx,"awo", at progbits,.text,unique,1
+; CHECK: .p2align 4
+; CHECK-NEXT: .quad .Lxray_sleds_start0
+; CHECK-NEXT: .quad .Lxray_sleds_end0
+; CHECK-NEXT: .text
Added: llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-hidden.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-hidden.ll?rev=312772&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-hidden.ll (added)
+++ llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-hidden.ll Thu Sep 7 18:47:56 2017
@@ -0,0 +1,26 @@
+; RUN: llc -filetype=asm -o - -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
+
+declare hidden i32 @callee() nounwind noinline uwtable "function-instrument"="xray-always"
+
+define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: .Ltmp0:
+; CHECK: b .Ltmp1
+; CHECK-NEXT: nop
+; CHECK-NEXT: std 0, -8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: bl __xray_FunctionEntry
+; CHECK-NEXT: nop
+; CHECK-NEXT: mtlr 0
+; CHECK-LABEL: .Ltmp1:
+ %retval = tail call i32 @callee()
+ ret i32 %retval
+; CHECK-LABEL: .Ltmp2:
+; CHECK: b callee
+; CHECK-NEXT: nop
+; CHECK-NEXT: std 0, -8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: bl __xray_FunctionExit
+; CHECK-NEXT: nop
+; CHECK-NEXT: mtlr 0
+}
+
Added: llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-sled.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-sled.ll?rev=312772&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-sled.ll (added)
+++ llvm/trunk/test/CodeGen/PowerPC/xray-tail-call-sled.ll Thu Sep 7 18:47:56 2017
@@ -0,0 +1,44 @@
+; RUN: llc -filetype=asm -o - -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
+
+define i32 @callee() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: .Ltmp0:
+; CHECK: b .Ltmp1
+; CHECK-NEXT: nop
+; CHECK-NEXT: std 0, -8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: bl __xray_FunctionEntry
+; CHECK-NEXT: nop
+; CHECK-NEXT: mtlr 0
+; CHECK-LABEL: .Ltmp1:
+ ret i32 0
+; CHECK-LABEL: .Ltmp2:
+; CHECK: blr
+; CHECK-NEXT: nop
+; CHECK-NEXT: std 0, -8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: bl __xray_FunctionExit
+; CHECK-NEXT: nop
+; CHECK-NEXT: mtlr 0
+}
+
+define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: .Ltmp3:
+; CHECK: b .Ltmp4
+; CHECK-NEXT: nop
+; CHECK-NEXT: std 0, -8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: bl __xray_FunctionEntry
+; CHECK-NEXT: nop
+; CHECK-NEXT: mtlr 0
+; CHECK-LABEL: .Ltmp4:
+ %retval = tail call i32 @callee()
+ ret i32 %retval
+; CHECK-LABEL: .Ltmp5:
+; CHECK: blr
+; CHECK-NEXT: nop
+; CHECK-NEXT: std 0, -8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: bl __xray_FunctionExit
+; CHECK-NEXT: nop
+; CHECK-NEXT: mtlr 0
+}
More information about the llvm-commits
mailing list