Skip to content

Commit 9109766

Browse files
committed
[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.
1 parent f304049 commit 9109766

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4472,6 +4472,7 @@ def SPIRV_OC_OpSelectionMerge : I32EnumAttrCase<"OpSelectionMerge
44724472
def SPIRV_OC_OpLabel : I32EnumAttrCase<"OpLabel", 248>;
44734473
def SPIRV_OC_OpBranch : I32EnumAttrCase<"OpBranch", 249>;
44744474
def SPIRV_OC_OpBranchConditional : I32EnumAttrCase<"OpBranchConditional", 250>;
4475+
def SPIRV_OC_OpKill : I32EnumAttrCase<"OpKill", 252>;
44754476
def SPIRV_OC_OpReturn : I32EnumAttrCase<"OpReturn", 253>;
44764477
def SPIRV_OC_OpReturnValue : I32EnumAttrCase<"OpReturnValue", 254>;
44774478
def SPIRV_OC_OpUnreachable : I32EnumAttrCase<"OpUnreachable", 255>;
@@ -4599,7 +4600,7 @@ def SPIRV_OpcodeAttr :
45994600
SPIRV_OC_OpAtomicAnd, SPIRV_OC_OpAtomicOr, SPIRV_OC_OpAtomicXor,
46004601
SPIRV_OC_OpPhi, SPIRV_OC_OpLoopMerge, SPIRV_OC_OpSelectionMerge,
46014602
SPIRV_OC_OpLabel, SPIRV_OC_OpBranch, SPIRV_OC_OpBranchConditional,
4602-
SPIRV_OC_OpReturn, SPIRV_OC_OpReturnValue, SPIRV_OC_OpUnreachable,
4603+
SPIRV_OC_OpKill, SPIRV_OC_OpReturn, SPIRV_OC_OpReturnValue, SPIRV_OC_OpUnreachable,
46034604
SPIRV_OC_OpGroupBroadcast, SPIRV_OC_OpGroupIAdd, SPIRV_OC_OpGroupFAdd,
46044605
SPIRV_OC_OpGroupFMin, SPIRV_OC_OpGroupUMin, SPIRV_OC_OpGroupSMin,
46054606
SPIRV_OC_OpGroupFMax, SPIRV_OC_OpGroupUMax, SPIRV_OC_OpGroupSMax,

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,50 @@ def SPIRV_FunctionCallOp : SPIRV_Op<"FunctionCall", [
242242

243243
// -----
244244

245+
def SPIRV_KillOp : SPIRV_Op<"Kill", [Terminator]>,
246+
CppDeprecated<"use 'spirv.TerminateInvocation' or 'spirv.DemoteToHelperInvocation' instead">
247+
{
248+
let summary = [{
249+
Deprecated (use OpTerminateInvocation or OpDemoteToHelperInvocation).
250+
}];
251+
252+
let description = [{
253+
Fragment-shader discard.
254+
255+
Ceases all further processing in any invocation that executes it: Only
256+
instructions these invocations executed before OpKill have observable
257+
side effects. If this instruction is executed in non-uniform control
258+
flow, all subsequent control flow is non-uniform (for invocations that
259+
continue to execute).
260+
261+
This instruction must be the last instruction in a block.
262+
263+
This instruction is only valid in the Fragment Execution Model.
264+
265+
<!-- End of AutoGen section -->
266+
267+
#### Example:
268+
269+
```mlir
270+
spirv.Kill
271+
```
272+
}];
273+
274+
let availability = [
275+
MinVersion<SPIRV_V_1_0>,
276+
MaxVersion<SPIRV_V_1_6>,
277+
Extension<[]>,
278+
Capability<[SPIRV_C_Shader]>
279+
];
280+
281+
let arguments = (ins);
282+
let results = (outs);
283+
let assemblyFormat = "attr-dict";
284+
let hasVerifier = 0;
285+
}
286+
287+
// -----
288+
245289
def SPIRV_LoopOp : SPIRV_Op<"mlir.loop", [InFunctionScope]> {
246290
let summary = "Define a structured loop.";
247291

mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,3 +789,15 @@ func.func @unreachable() {
789789
// expected-error @+1 {{cannot be used in reachable block}}
790790
spirv.Unreachable
791791
}
792+
793+
// -----
794+
795+
//===----------------------------------------------------------------------===//
796+
// spirv.Kill
797+
//===----------------------------------------------------------------------===//
798+
799+
// CHECK-LABEL: func @kill
800+
func.func @kill() {
801+
// CHECK: spirv.Kill
802+
spirv.Kill
803+
}

mlir/test/Target/SPIRV/terminator.mlir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
2424
// CHECK-NOT: spirv.Unreachable
2525
spirv.Unreachable
2626
}
27+
28+
// CHECK-LABEL: @kill
29+
spirv.func @kill() -> () "None" {
30+
// CHECK: spirv.Kill
31+
spirv.Kill
32+
}
2733
}

0 commit comments

Comments
 (0)