David Neto dffa60ca98 spir-writer: handle break continuing block
The continuing block can exit the loop in very constrained ways:

When a break statement is placed such that it would exit from a loop’s
§ 7.3.8 Continuing Statement, then:

   - The break statement must appear as either:
     - The only statement in the if clause of an if statement that has:
       - no else clause or an empty else clause
       - no elseif clauses
     - The only statement in the else clause of an if statement that has an
       empty if clause and no elseif clauses.
   - That if statement must appear last in the continuing clause.

By design, this allows a lossless round-trip from SPIR-V to WGSL and
back to SPIR-V.  But that requires this special case construct in WGSL
to be translated to an OpBranchConditional with one target being
the loop's megre block (which is where 'break' branches to), and the
other targets the loop header (which is the loop backedge).  That
OpBranchConditional takes the place of the normal case of an
unconditional backedge.

Avoids errors like this:
 continue construct with the continue target X is not
 post dominated by the back-edge block Y

Fixed: 1034
Change-Id: If472a179380b8d77af746a3cd8e279c8a5e56b37
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59800
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-07-27 15:12:27 +00:00

224 lines
8.2 KiB
Plaintext

; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 131
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %theSSBO "theSSBO"
OpMemberName %theSSBO 0 "out_data"
OpName %x_4 "x_4"
OpName %buf1 "buf1"
OpMemberName %buf1 0 "injectionSwitch"
OpName %x_6 "x_6"
OpName %main_1 "main_1"
OpName %i "i"
OpName %GLF_live3s "GLF_live3s"
OpName %i_1 "i_1"
OpName %z "z"
OpName %main "main"
OpDecorate %theSSBO Block
OpMemberDecorate %theSSBO 0 Offset 0
OpDecorate %x_4 DescriptorSet 0
OpDecorate %x_4 Binding 0
OpDecorate %buf1 Block
OpMemberDecorate %buf1 0 Offset 0
OpDecorate %x_6 NonWritable
OpDecorate %x_6 DescriptorSet 0
OpDecorate %x_6 Binding 1
%int = OpTypeInt 32 1
%theSSBO = OpTypeStruct %int
%_ptr_StorageBuffer_theSSBO = OpTypePointer StorageBuffer %theSSBO
%x_4 = OpVariable %_ptr_StorageBuffer_theSSBO StorageBuffer
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%buf1 = OpTypeStruct %v2float
%_ptr_Uniform_buf1 = OpTypePointer Uniform %buf1
%x_6 = OpVariable %_ptr_Uniform_buf1 Uniform
%void = OpTypeVoid
%10 = OpTypeFunction %void
%_ptr_Function_int = OpTypePointer Function %int
%16 = OpConstantNull %int
%_ptr_Function_float = OpTypePointer Function %float
%19 = OpConstantNull %float
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%int_42 = OpConstant %int 42
%_ptr_Uniform_float = OpTypePointer Uniform %float
%uint_1 = OpConstant %uint 1
%bool = OpTypeBool
%uint_2 = OpConstant %uint 2
%uint_264 = OpConstant %uint 264
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%float_0 = OpConstant %float 0
%int_2 = OpConstant %int 2
%float_1 = OpConstant %float 1
%main_1 = OpFunction %void None %10
%13 = OpLabel
%i = OpVariable %_ptr_Function_int Function %16
%GLF_live3s = OpVariable %_ptr_Function_float Function %19
%i_1 = OpVariable %_ptr_Function_int Function %16
%z = OpVariable %_ptr_Function_int Function %16
%25 = OpAccessChain %_ptr_StorageBuffer_int %x_4 %uint_0
OpStore %25 %int_42
%28 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_0
%29 = OpLoad %float %28
%31 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_1
%32 = OpLoad %float %31
%33 = OpFOrdGreaterThan %bool %29 %32
OpSelectionMerge %35 None
OpBranchConditional %33 %36 %35
%36 = OpLabel
OpControlBarrier %uint_2 %uint_2 %uint_264
OpBranch %35
%35 = OpLabel
%40 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_0
%41 = OpLoad %float %40
%42 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_1
%43 = OpLoad %float %42
%44 = OpFOrdGreaterThan %bool %41 %43
OpSelectionMerge %45 None
OpBranchConditional %44 %46 %45
%46 = OpLabel
OpControlBarrier %uint_2 %uint_2 %uint_264
OpBranch %45
%45 = OpLabel
%48 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_1
%49 = OpLoad %float %48
%50 = OpConvertFToS %int %49
OpStore %i %50
OpBranch %51
%51 = OpLabel
OpLoopMerge %52 %53 None
OpBranch %54
%54 = OpLabel
%55 = OpLoad %int %i
%57 = OpSGreaterThan %bool %55 %int_0
OpSelectionMerge %58 None
OpBranchConditional %57 %59 %60
%59 = OpLabel
OpBranch %58
%60 = OpLabel
OpBranch %52
%58 = OpLabel
OpControlBarrier %uint_2 %uint_2 %uint_264
OpBranch %53
%53 = OpLabel
%62 = OpLoad %int %i
%64 = OpISub %int %62 %int_1
OpStore %i %64
OpBranch %51
%52 = OpLabel
OpStore %GLF_live3s %float_0
OpBranch %66
%66 = OpLabel
OpLoopMerge %67 %68 None
OpBranch %69
%69 = OpLabel
OpStore %i_1 %int_1
OpBranch %70
%70 = OpLabel
OpLoopMerge %71 %72 None
OpBranch %73
%73 = OpLabel
%74 = OpLoad %int %i_1
%76 = OpSLessThan %bool %74 %int_2
OpSelectionMerge %77 None
OpBranchConditional %76 %78 %79
%78 = OpLabel
OpBranch %77
%79 = OpLabel
OpBranch %71
%77 = OpLabel
%80 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_0
%81 = OpLoad %float %80
%83 = OpFOrdGreaterThan %bool %81 %float_1
OpSelectionMerge %84 None
OpBranchConditional %83 %85 %84
%85 = OpLabel
OpControlBarrier %uint_2 %uint_2 %uint_264
OpBranch %84
%84 = OpLabel
%87 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_0
%88 = OpLoad %float %87
%89 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_1
%90 = OpLoad %float %89
%91 = OpFOrdGreaterThan %bool %88 %90
OpSelectionMerge %92 None
OpBranchConditional %91 %93 %92
%93 = OpLabel
OpControlBarrier %uint_2 %uint_2 %uint_264
OpBranch %92
%92 = OpLabel
%95 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_1
%96 = OpLoad %float %95
%97 = OpConvertFToS %int %96
OpStore %z %97
OpBranch %98
%98 = OpLabel
OpLoopMerge %99 %100 None
OpBranch %101
%101 = OpLabel
%102 = OpLoad %int %z
%103 = OpSGreaterThan %bool %102 %int_0
OpSelectionMerge %104 None
OpBranchConditional %103 %105 %106
%105 = OpLabel
OpBranch %104
%106 = OpLabel
OpBranch %99
%104 = OpLabel
%107 = OpLoad %float %GLF_live3s
%108 = OpFAdd %float %107 %float_1
OpStore %GLF_live3s %108
OpBranch %100
%100 = OpLabel
%109 = OpLoad %int %z
%110 = OpISub %int %109 %int_1
OpStore %z %110
OpBranch %98
%99 = OpLabel
%111 = OpLoad %int %i_1
%112 = OpSGreaterThanEqual %bool %111 %int_1
OpSelectionMerge %113 None
OpBranchConditional %112 %114 %113
%114 = OpLabel
%115 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_0
%116 = OpLoad %float %115
%117 = OpFOrdGreaterThan %bool %116 %float_1
OpSelectionMerge %118 None
OpBranchConditional %117 %119 %118
%119 = OpLabel
OpControlBarrier %uint_2 %uint_2 %uint_264
OpBranch %118
%118 = OpLabel
OpBranch %113
%113 = OpLabel
OpBranch %72
%72 = OpLabel
%121 = OpLoad %int %i_1
%122 = OpIAdd %int %121 %int_1
OpStore %i_1 %122
OpBranch %70
%71 = OpLabel
OpBranch %68
%68 = OpLabel
%123 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_0
%124 = OpLoad %float %123
%125 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_1
%126 = OpLoad %float %125
%127 = OpFOrdGreaterThan %bool %124 %126
OpBranchConditional %127 %66 %67
%67 = OpLabel
OpReturn
OpFunctionEnd
%main = OpFunction %void None %10
%129 = OpLabel
%130 = OpFunctionCall %void %main_1
OpReturn
OpFunctionEnd