Skip to content

Commit 0c1acc9

Browse files
[SPIRV] Added lowering for the debugtrap intrinsic (#157442)
Mapped llvm.debugtrap intrinsic to OpNop in the SPIR-V backend, since SPIR-V has no direct equivalent with tests.
1 parent 047ddbf commit 0c1acc9

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ class SPIRVInstructionSelector : public InstructionSelector {
197197

198198
bool selectOverflowArith(Register ResVReg, const SPIRVType *ResType,
199199
MachineInstr &I, unsigned Opcode) const;
200+
bool selectDebugTrap(Register ResVReg, const SPIRVType *ResType,
201+
MachineInstr &I) const;
200202

201203
bool selectIntegerDot(Register ResVReg, const SPIRVType *ResType,
202204
MachineInstr &I, bool Signed) const;
@@ -999,16 +1001,26 @@ bool SPIRVInstructionSelector::spvSelect(Register ResVReg,
9991001
// represent code after lowering or intrinsics which are not implemented but
10001002
// should not crash when found in a customer's LLVM IR input.
10011003
case TargetOpcode::G_TRAP:
1002-
case TargetOpcode::G_DEBUGTRAP:
10031004
case TargetOpcode::G_UBSANTRAP:
10041005
case TargetOpcode::DBG_LABEL:
10051006
return true;
1007+
case TargetOpcode::G_DEBUGTRAP:
1008+
return selectDebugTrap(ResVReg, ResType, I);
10061009

10071010
default:
10081011
return false;
10091012
}
10101013
}
10111014

1015+
bool SPIRVInstructionSelector::selectDebugTrap(Register ResVReg,
1016+
const SPIRVType *ResType,
1017+
MachineInstr &I) const {
1018+
unsigned Opcode = SPIRV::OpNop;
1019+
MachineBasicBlock &BB = *I.getParent();
1020+
return BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode))
1021+
.constrainAllUses(TII, TRI, RBI);
1022+
}
1023+
10121024
bool SPIRVInstructionSelector::selectExtInst(Register ResVReg,
10131025
const SPIRVType *ResType,
10141026
MachineInstr &I,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
2+
3+
; CHECK: OpNop
4+
; CHECK-NEXT: OpReturn
5+
6+
declare void @llvm.debugtrap()
7+
8+
define spir_kernel void @foo(ptr addrspace(1) %a){
9+
entry:
10+
%a.addr = alloca ptr addrspace(1), align 4
11+
store ptr addrspace(1) %a, ptr %a.addr, align 4
12+
call void @llvm.debugtrap()
13+
ret void
14+
}

llvm/test/CodeGen/SPIRV/llvm-intrinsics/ignore-llvm-intrinsic.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
define spir_kernel void @foo(ptr %p) {
1212
entry:
1313
call void @llvm.trap()
14-
call void @llvm.debugtrap()
1514
call void @llvm.ubsantrap(i8 100)
1615

1716
%r1 = call ptr @llvm.invariant.start.p0(i64 1024, ptr %p)

0 commit comments

Comments
 (0)