[Mlir-commits] [mlir] [mlir][spirv] Add definition for OpKill (PR #126554)
Igor Wodiany
llvmlistbot at llvm.org
Tue Feb 11 02:41:09 PST 2025
https://github.com/IgWod-IMG updated https://github.com/llvm/llvm-project/pull/126554
>From 7d5a942aa0a3aa3e87d9248892b03fbb80747f72 Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Thu, 6 Feb 2025 14:37:30 +0000
Subject: [PATCH] [mlir][spirv] Add definition for OpKill
Although the operation is deprecated in the most recent version
of the SPIR-V spec, it is still used by older shaders, so having
it defined is valuable and incurs negligible maintenance overhead,
due to op simplicity.
---
.../mlir/Dialect/SPIRV/IR/SPIRVBase.td | 3 +-
.../Dialect/SPIRV/IR/SPIRVControlFlowOps.td | 42 +++++++++++++++++++
.../Dialect/SPIRV/IR/control-flow-ops.mlir | 12 ++++++
mlir/test/Target/SPIRV/terminator.mlir | 6 +++
4 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
index 6b2e4189aea028e..16bccd2b72d18f5 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
@@ -4472,6 +4472,7 @@ def SPIRV_OC_OpSelectionMerge : I32EnumAttrCase<"OpSelectionMerge
def SPIRV_OC_OpLabel : I32EnumAttrCase<"OpLabel", 248>;
def SPIRV_OC_OpBranch : I32EnumAttrCase<"OpBranch", 249>;
def SPIRV_OC_OpBranchConditional : I32EnumAttrCase<"OpBranchConditional", 250>;
+def SPIRV_OC_OpKill : I32EnumAttrCase<"OpKill", 252>;
def SPIRV_OC_OpReturn : I32EnumAttrCase<"OpReturn", 253>;
def SPIRV_OC_OpReturnValue : I32EnumAttrCase<"OpReturnValue", 254>;
def SPIRV_OC_OpUnreachable : I32EnumAttrCase<"OpUnreachable", 255>;
@@ -4599,7 +4600,7 @@ def SPIRV_OpcodeAttr :
SPIRV_OC_OpAtomicAnd, SPIRV_OC_OpAtomicOr, SPIRV_OC_OpAtomicXor,
SPIRV_OC_OpPhi, SPIRV_OC_OpLoopMerge, SPIRV_OC_OpSelectionMerge,
SPIRV_OC_OpLabel, SPIRV_OC_OpBranch, SPIRV_OC_OpBranchConditional,
- SPIRV_OC_OpReturn, SPIRV_OC_OpReturnValue, SPIRV_OC_OpUnreachable,
+ SPIRV_OC_OpKill, SPIRV_OC_OpReturn, SPIRV_OC_OpReturnValue, SPIRV_OC_OpUnreachable,
SPIRV_OC_OpGroupBroadcast, SPIRV_OC_OpGroupIAdd, SPIRV_OC_OpGroupFAdd,
SPIRV_OC_OpGroupFMin, SPIRV_OC_OpGroupUMin, SPIRV_OC_OpGroupSMin,
SPIRV_OC_OpGroupFMax, SPIRV_OC_OpGroupUMax, SPIRV_OC_OpGroupSMax,
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td
index cc2f0e4962d8a8a..ade20f915c0c3be 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td
@@ -242,6 +242,48 @@ def SPIRV_FunctionCallOp : SPIRV_Op<"FunctionCall", [
// -----
+def SPIRV_KillOp : SPIRV_Op<"Kill", [Terminator]> {
+ let summary = [{
+ Deprecated (use OpTerminateInvocation or OpDemoteToHelperInvocation).
+ }];
+
+ let description = [{
+ Fragment-shader discard.
+
+ Ceases all further processing in any invocation that executes it: Only
+ instructions these invocations executed before OpKill have observable
+ side effects. If this instruction is executed in non-uniform control
+ flow, all subsequent control flow is non-uniform (for invocations that
+ continue to execute).
+
+ This instruction must be the last instruction in a block.
+
+ This instruction is only valid in the Fragment Execution Model.
+
+ <!-- End of AutoGen section -->
+
+ #### Example:
+
+ ```mlir
+ spirv.Kill
+ ```
+ }];
+
+ let availability = [
+ MinVersion<SPIRV_V_1_0>,
+ MaxVersion<SPIRV_V_1_6>,
+ Extension<[]>,
+ Capability<[SPIRV_C_Shader]>
+ ];
+
+ let arguments = (ins);
+ let results = (outs);
+ let assemblyFormat = "attr-dict";
+ let hasVerifier = 0;
+}
+
+// -----
+
def SPIRV_LoopOp : SPIRV_Op<"mlir.loop", [InFunctionScope]> {
let summary = "Define a structured loop.";
diff --git a/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir b/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir
index 8496448759f0c99..1d1e2840a579a62 100644
--- a/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir
@@ -789,3 +789,15 @@ func.func @unreachable() {
// expected-error @+1 {{cannot be used in reachable block}}
spirv.Unreachable
}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.Kill
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: func @kill
+func.func @kill() {
+ // CHECK: spirv.Kill
+ spirv.Kill
+}
diff --git a/mlir/test/Target/SPIRV/terminator.mlir b/mlir/test/Target/SPIRV/terminator.mlir
index 065b68b9bdfbb80..8338a575681f129 100644
--- a/mlir/test/Target/SPIRV/terminator.mlir
+++ b/mlir/test/Target/SPIRV/terminator.mlir
@@ -24,4 +24,10 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
// CHECK-NOT: spirv.Unreachable
spirv.Unreachable
}
+
+ // CHECK-LABEL: @kill
+ spirv.func @kill() -> () "None" {
+ // CHECK: spirv.Kill
+ spirv.Kill
+ }
}
More information about the Mlir-commits
mailing list