[llvm] [SPIRV] Added lowering for the debugtrap intrinsic (PR #157442)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 05:49:52 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Subash B (SubashBoopathi)
<details>
<summary>Changes</summary>
Mapped llvm.debugtrap intrinsic to OpNop in the SPIR-V backend, since SPIR-V has no direct equivalent with tests.
---
Full diff: https://github.com/llvm/llvm-project/pull/157442.diff
2 Files Affected:
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+13-1)
- (added) llvm/test/CodeGen/SPIRV/llvm-intrinsics/debugtrap.ll (+15)
``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 6608b3f2cbefd..ec28d1e1c15cb 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -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;
@@ -951,16 +953,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,
diff --git a/llvm/test/CodeGen/SPIRV/llvm-intrinsics/debugtrap.ll b/llvm/test/CodeGen/SPIRV/llvm-intrinsics/debugtrap.ll
new file mode 100644
index 0000000000000..3f5fedf243cde
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/llvm-intrinsics/debugtrap.ll
@@ -0,0 +1,15 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
+
+; CHECK-DAG: OpCapability Addresses
+; CHECK-DAG: OpName %[[#]] "foo"
+; CHECK-DAG: OpNop
+
+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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/157442
More information about the llvm-commits
mailing list