Skip to content

Commit 7d5a942

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 7d5a942

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,48 @@ def SPIRV_FunctionCallOp : SPIRV_Op<"FunctionCall", [
242242

243243
// -----
244244

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

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)