Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit f7f70f7

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312772 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 575526c commit f7f70f7

File tree

5 files changed

+123
-16
lines changed

5 files changed

+123
-16
lines changed

lib/CodeGen/XRayInstrumentation.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
//
1515
//===---------------------------------------------------------------------===//
1616

17-
#include "llvm/ADT/SmallVector.h"
1817
#include "llvm/ADT/STLExtras.h"
18+
#include "llvm/ADT/SmallVector.h"
1919
#include "llvm/ADT/Triple.h"
2020
#include "llvm/CodeGen/MachineBasicBlock.h"
2121
#include "llvm/CodeGen/MachineDominators.h"
@@ -109,22 +109,13 @@ void XRayInstrumentation::replaceRetWithPatchableRet(
109109

110110
void XRayInstrumentation::prependRetWithPatchableExit(
111111
MachineFunction &MF, const TargetInstrInfo *TII) {
112-
for (auto &MBB : MF) {
113-
for (auto &T : MBB.terminators()) {
114-
unsigned Opc = 0;
112+
for (auto &MBB : MF)
113+
for (auto &T : MBB.terminators())
115114
if (T.isReturn()) {
116-
Opc = TargetOpcode::PATCHABLE_FUNCTION_EXIT;
117-
}
118-
if (TII->isTailCall(T)) {
119-
Opc = TargetOpcode::PATCHABLE_TAIL_CALL;
120-
}
121-
if (Opc != 0) {
122-
// Prepend the return instruction with PATCHABLE_FUNCTION_EXIT or
123-
// PATCHABLE_TAIL_CALL .
124-
BuildMI(MBB, T, T.getDebugLoc(), TII->get(Opc));
115+
// Prepend the return instruction with PATCHABLE_FUNCTION_EXIT.
116+
BuildMI(MBB, T, T.getDebugLoc(),
117+
TII->get(TargetOpcode::PATCHABLE_FUNCTION_EXIT));
125118
}
126-
}
127-
}
128119
}
129120

130121
bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) {
@@ -143,7 +134,7 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) {
143134

144135
// Count the number of MachineInstr`s in MachineFunction
145136
int64_t MICount = 0;
146-
for (const auto& MBB : MF)
137+
for (const auto &MBB : MF)
147138
MICount += MBB.size();
148139

149140
// Check if we have a loop.

lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,8 @@ void PPCLinuxAsmPrinter::EmitInstruction(const MachineInstr *MI) {
11311131
break;
11321132
}
11331133
case TargetOpcode::PATCHABLE_TAIL_CALL:
1134+
// TODO: Define a trampoline `__xray_FunctionTailExit` and differentiate a
1135+
// normal function exit from a tail exit.
11341136
case TargetOpcode::PATCHABLE_RET:
11351137
// PPC's tail call instruction, e.g. PPC::TCRETURNdi8, doesn't really
11361138
// lower to a PPC::B instruction. The PPC::B instruction is generated
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; RUN: llc -filetype=asm -o - -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
2+
; RUN: llc -filetype=asm -o - -mtriple=powerpc64le-unknown-linux-gnu \
3+
; RUN: -relocation-model=pic < %s | FileCheck %s
4+
5+
define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
6+
; CHECK-LABEL: .Ltmp0:
7+
; CHECK: b .Ltmp1
8+
; CHECK-NEXT: nop
9+
; CHECK-NEXT: std 0, -8(1)
10+
; CHECK-NEXT: mflr 0
11+
; CHECK-NEXT: bl __xray_FunctionEntry
12+
; CHECK-NEXT: nop
13+
; CHECK-NEXT: mtlr 0
14+
; CHECK-LABEL: .Ltmp1:
15+
ret i32 0
16+
; CHECK-LABEL: .Ltmp2:
17+
; CHECK: blr
18+
; CHECK-NEXT: nop
19+
; CHECK-NEXT: std 0, -8(1)
20+
; CHECK-NEXT: mflr 0
21+
; CHECK-NEXT: bl __xray_FunctionExit
22+
; CHECK-NEXT: nop
23+
; CHECK-NEXT: mtlr 0
24+
}
25+
; CHECK-LABEL: xray_instr_map,"awo",@progbits,.text,unique,1
26+
; CHECK: .Lxray_sleds_start0:
27+
; CHECK-NEXT: .quad .Ltmp0
28+
; CHECK-NEXT: .quad foo
29+
; CHECK-NEXT: .byte 0x00
30+
; CHECK-NEXT: .byte 0x01
31+
; CHECK-NEXT: .byte 0x00
32+
; CHECK-NEXT: .space 13
33+
; CHECK-NEXT: .quad .Ltmp2
34+
; CHECK-NEXT: .quad foo
35+
; CHECK-NEXT: .byte 0x01
36+
; CHECK-NEXT: .byte 0x01
37+
; CHECK-NEXT: .byte 0x00
38+
; CHECK-NEXT: .space 13
39+
; CHECK-NEXT: .Lxray_sleds_end0:
40+
; CHECK-LABEL: xray_fn_idx,"awo",@progbits,.text,unique,1
41+
; CHECK: .p2align 4
42+
; CHECK-NEXT: .quad .Lxray_sleds_start0
43+
; CHECK-NEXT: .quad .Lxray_sleds_end0
44+
; CHECK-NEXT: .text
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llc -filetype=asm -o - -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
2+
3+
declare hidden i32 @callee() nounwind noinline uwtable "function-instrument"="xray-always"
4+
5+
define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" {
6+
; CHECK-LABEL: .Ltmp0:
7+
; CHECK: b .Ltmp1
8+
; CHECK-NEXT: nop
9+
; CHECK-NEXT: std 0, -8(1)
10+
; CHECK-NEXT: mflr 0
11+
; CHECK-NEXT: bl __xray_FunctionEntry
12+
; CHECK-NEXT: nop
13+
; CHECK-NEXT: mtlr 0
14+
; CHECK-LABEL: .Ltmp1:
15+
%retval = tail call i32 @callee()
16+
ret i32 %retval
17+
; CHECK-LABEL: .Ltmp2:
18+
; CHECK: b callee
19+
; CHECK-NEXT: nop
20+
; CHECK-NEXT: std 0, -8(1)
21+
; CHECK-NEXT: mflr 0
22+
; CHECK-NEXT: bl __xray_FunctionExit
23+
; CHECK-NEXT: nop
24+
; CHECK-NEXT: mtlr 0
25+
}
26+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; RUN: llc -filetype=asm -o - -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
2+
3+
define i32 @callee() nounwind noinline uwtable "function-instrument"="xray-always" {
4+
; CHECK-LABEL: .Ltmp0:
5+
; CHECK: b .Ltmp1
6+
; CHECK-NEXT: nop
7+
; CHECK-NEXT: std 0, -8(1)
8+
; CHECK-NEXT: mflr 0
9+
; CHECK-NEXT: bl __xray_FunctionEntry
10+
; CHECK-NEXT: nop
11+
; CHECK-NEXT: mtlr 0
12+
; CHECK-LABEL: .Ltmp1:
13+
ret i32 0
14+
; CHECK-LABEL: .Ltmp2:
15+
; CHECK: blr
16+
; CHECK-NEXT: nop
17+
; CHECK-NEXT: std 0, -8(1)
18+
; CHECK-NEXT: mflr 0
19+
; CHECK-NEXT: bl __xray_FunctionExit
20+
; CHECK-NEXT: nop
21+
; CHECK-NEXT: mtlr 0
22+
}
23+
24+
define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" {
25+
; CHECK-LABEL: .Ltmp3:
26+
; CHECK: b .Ltmp4
27+
; CHECK-NEXT: nop
28+
; CHECK-NEXT: std 0, -8(1)
29+
; CHECK-NEXT: mflr 0
30+
; CHECK-NEXT: bl __xray_FunctionEntry
31+
; CHECK-NEXT: nop
32+
; CHECK-NEXT: mtlr 0
33+
; CHECK-LABEL: .Ltmp4:
34+
%retval = tail call i32 @callee()
35+
ret i32 %retval
36+
; CHECK-LABEL: .Ltmp5:
37+
; CHECK: blr
38+
; CHECK-NEXT: nop
39+
; CHECK-NEXT: std 0, -8(1)
40+
; CHECK-NEXT: mflr 0
41+
; CHECK-NEXT: bl __xray_FunctionExit
42+
; CHECK-NEXT: nop
43+
; CHECK-NEXT: mtlr 0
44+
}

0 commit comments

Comments
 (0)