Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class SPIRVInstructionSelector : public InstructionSelector {

bool selectOverflowArith(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I, unsigned Opcode) const;
bool selectDebugTrap(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I) const;

bool selectIntegerDot(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I, bool Signed) const;
Expand Down Expand Up @@ -975,16 +977,26 @@ bool SPIRVInstructionSelector::spvSelect(Register ResVReg,
// represent code after lowering or intrinsics which are not implemented but
// should not crash when found in a customer's LLVM IR input.
case TargetOpcode::G_TRAP:
case TargetOpcode::G_DEBUGTRAP:
case TargetOpcode::G_UBSANTRAP:
case TargetOpcode::DBG_LABEL:
return true;
case TargetOpcode::G_DEBUGTRAP:
return selectDebugTrap(ResVReg, ResType, I);

default:
return false;
}
}

bool SPIRVInstructionSelector::selectDebugTrap(Register ResVReg,
const SPIRVType *ResType,
MachineInstr &I) const {
unsigned Opcode = SPIRV::OpNop;
MachineBasicBlock &BB = *I.getParent();
return BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode))
.constrainAllUses(TII, TRI, RBI);
}

bool SPIRVInstructionSelector::selectExtInst(Register ResVReg,
const SPIRVType *ResType,
MachineInstr &I,
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/SPIRV/llvm-intrinsics/debugtrap.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s

; CHECK: OpNop
; CHECK-NEXT: OpReturn

declare void @llvm.debugtrap()

define spir_kernel void @foo(ptr addrspace(1) %a){
entry:
%a.addr = alloca ptr addrspace(1), align 4
store ptr addrspace(1) %a, ptr %a.addr, align 4
call void @llvm.debugtrap()
ret void
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
define spir_kernel void @foo(ptr %p) {
entry:
call void @llvm.trap()
call void @llvm.debugtrap()
call void @llvm.ubsantrap(i8 100)

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