Skip to content

Commit 6cb087a

Browse files
[XRay] Fix tail call sleds for AArch64 (#141403)
This addresses issue #141051. XRay uses a special event kind for tail calls on some architectures. This feature is implemented on AArch64, but wasn't fully activated. Tests in `llvm/test/CodeGen/AArch64/xray-tail-call-sled.ll` were incomplete and did not check for the emitted sled type. This patch correctly enables emission of tail call sleds on AArch64 and fixes the tests to check the sled kind.
1 parent 7454098 commit 6cb087a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

llvm/lib/CodeGen/XRayInstrumentation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,9 @@ bool XRayInstrumentation::run(MachineFunction &MF) {
296296
case Triple::ArchType::riscv64: {
297297
// For the architectures which don't have a single return instruction
298298
InstrumentationOptions op;
299-
// RISC-V supports patching tail calls.
300-
op.HandleTailcall = MF.getTarget().getTargetTriple().isRISCV();
299+
// AArch64 and RISC-V support patching tail calls.
300+
op.HandleTailcall = MF.getTarget().getTargetTriple().isAArch64() ||
301+
MF.getTarget().getTargetTriple().isRISCV();
301302
op.HandleAllReturns = true;
302303
prependRetWithPatchableExit(MF, TII, op);
303304
break;

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ unsigned AArch64InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
162162
F.getFnAttributeAsParsedInteger("patchable-function-entry", 9) * 4;
163163
break;
164164
case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
165+
case TargetOpcode::PATCHABLE_TAIL_CALL:
165166
case TargetOpcode::PATCHABLE_TYPED_EVENT_CALL:
166167
// An XRay sled can be 4 bytes of alignment plus a 32-byte block.
167168
NumBytes = 36;

llvm/test/CodeGen/AArch64/xray-tail-call-sled.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ define i32 @callee() nounwind noinline uwtable "function-instrument"="xray-alway
2121
; CHECK-LINUX-LABEL: .Lxray_sleds_start0:
2222
; CHECK-LINUX-NEXT: [[TMP:.Ltmp[0-9]+]]:
2323
; CHECK-LINUX: .xword .Lxray_sled_0-[[TMP]]
24+
; CHECK-LINUX: .xword
25+
; CHECK-LINUX-NEXT: .byte 0x00
2426
; CHECK-LINUX: [[TMP:.Ltmp[0-9]+]]:
2527
; CHECK-LINUX-NEXT: .xword .Lxray_sled_1-[[TMP]]
28+
; CHECK-LINUX: .xword
29+
; CHECK-LINUX-NEXT: .byte 0x01
2630
; CHECK-LINUX-LABEL: Lxray_sleds_end0:
2731
; CHECK-LINUX-LABEL: .section xray_fn_idx,"ao",@progbits,callee{{$}}
2832
; CHECK-LINUX: .xword .Lxray_sleds_start0
@@ -32,8 +36,12 @@ define i32 @callee() nounwind noinline uwtable "function-instrument"="xray-alway
3236
; CHECK-MACOS-LABEL: lxray_sleds_start0:
3337
; CHECK-MACOS-NEXT: [[TMP:Ltmp[0-9]+]]:
3438
; CHECK-MACOS: .quad Lxray_sled_0-[[TMP]]
39+
; CHECK-MACOS-NEXT: .quad
40+
; CHECK-MACOS-NEXT: .byte 0x00
3541
; CHECK-MACOS: [[TMP:Ltmp[0-9]+]]:
3642
; CHECK-MACOS-NEXT: .quad Lxray_sled_1-[[TMP]]
43+
; CHECK-MACOS-NEXT: .quad
44+
; CHECK-MACOS-NEXT: .byte 0x01
3745
; CHECK-MACOS-LABEL: Lxray_sleds_end0:
3846
; CHECK-MACOS-LABEL: .section __DATA,xray_fn_idx,regular,live_support{{$}}
3947
; CHECK-MACOS: [[IDX:lxray_fn_idx[0-9]+]]:
@@ -60,7 +68,11 @@ define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-alway
6068
; CHECK-LINUX-LABEL: .section xray_instr_map,"ao",@progbits,caller{{$}}
6169
; CHECK-LINUX-LABEL: Lxray_sleds_start1:
6270
; CHECK-LINUX: .xword .Lxray_sled_2
71+
; CHECK-LINUX-NEXT: .xword
72+
; CHECK-LINUX-NEXT: .byte 0x00
6373
; CHECK-LINUX: .xword .Lxray_sled_3
74+
; CHECK-LINUX-NEXT: .xword
75+
; CHECK-LINUX-NEXT: .byte 0x02
6476
; CHECK-LINUX-LABEL: Lxray_sleds_end1:
6577
; CHECK-LINUX-LABEL: .section xray_fn_idx,"ao",@progbits,caller{{$}}
6678
; CHECK-LINUX: [[IDX:\.Lxray_fn_idx[0-9]+]]:
@@ -70,7 +82,11 @@ define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-alway
7082
; CHECK-MACOS-LABEL: .section __DATA,xray_instr_map,regular,live_support{{$}}
7183
; CHECK-MACOS-LABEL: lxray_sleds_start1:
7284
; CHECK-MACOS: .quad Lxray_sled_2
85+
; CHECK-MACOS-NEXT: .quad
86+
; CHECK-MACOS-NEXT: .byte 0x00
7387
; CHECK-MACOS: .quad Lxray_sled_3
88+
; CHECK-MACOS-NEXT: .quad
89+
; CHECK-MACOS-NEXT: .byte 0x02
7490
; CHECK-MACOS-LABEL: Lxray_sleds_end1:
7591
; CHECK-MACOS-LABEL: .section __DATA,xray_fn_idx,regular,live_support{{$}}
7692
; CHECK-MACOS: [[IDX:lxray_fn_idx[0-9]+]]:

0 commit comments

Comments
 (0)