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

164 lines
6.0 KiB
Plaintext

; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 80
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %tint_symbol_1
OpExecutionMode %main OriginUpperLeft
OpName %buf0 "buf0"
OpMemberName %buf0 0 "zero"
OpName %x_6 "x_6"
OpName %x_GLF_color "x_GLF_color"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %returnRed_ "returnRed_"
OpName %x_33 "x_33"
OpName %x_34 "x_34"
OpName %x_48 "x_48"
OpName %x_36_phi "x_36_phi"
OpName %x_51_phi "x_51_phi"
OpName %x_48_phi "x_48_phi"
OpName %x_49_phi "x_49_phi"
OpName %main_1 "main_1"
OpName %main_out "main_out"
OpMemberName %main_out 0 "x_GLF_color_1"
OpName %tint_symbol_2 "tint_symbol_2"
OpName %tint_symbol "tint_symbol"
OpName %main "main"
OpDecorate %buf0 Block
OpMemberDecorate %buf0 0 Offset 0
OpDecorate %x_6 NonWritable
OpDecorate %x_6 DescriptorSet 0
OpDecorate %x_6 Binding 0
OpDecorate %tint_symbol_1 Location 0
OpMemberDecorate %main_out 0 Offset 0
%int = OpTypeInt 32 1
%buf0 = OpTypeStruct %int
%_ptr_Uniform_buf0 = OpTypePointer Uniform %buf0
%x_6 = OpVariable %_ptr_Uniform_buf0 Uniform
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Private_v4float = OpTypePointer Private %v4float
%9 = OpConstantNull %v4float
%x_GLF_color = OpVariable %_ptr_Private_v4float Private %9
%_ptr_Output_v4float = OpTypePointer Output %v4float
%tint_symbol_1 = OpVariable %_ptr_Output_v4float Output %9
%12 = OpTypeFunction %v4float
%bool = OpTypeBool
%false = OpConstantFalse %bool
%_ptr_Function_bool = OpTypePointer Function %bool
%19 = OpConstantNull %bool
%_ptr_Function_v4float = OpTypePointer Function %v4float
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_Uniform_int = OpTypePointer Uniform %int
%int_1 = OpConstant %int 1
%true = OpConstantTrue %bool
%float_1 = OpConstant %float 1
%float_0 = OpConstant %float 0
%48 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%49 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
%void = OpTypeVoid
%56 = OpTypeFunction %void
%main_out = OpTypeStruct %v4float
%68 = OpTypeFunction %void %main_out
%returnRed_ = OpFunction %v4float None %12
%14 = OpLabel
%x_33 = OpVariable %_ptr_Function_bool Function %19
%x_34 = OpVariable %_ptr_Function_v4float Function %9
%x_48 = OpVariable %_ptr_Function_v4float Function %9
%x_36_phi = OpVariable %_ptr_Function_bool Function %19
%x_51_phi = OpVariable %_ptr_Function_v4float Function %9
%x_48_phi = OpVariable %_ptr_Function_v4float Function %9
%x_49_phi = OpVariable %_ptr_Function_bool Function %19
OpStore %x_33 %false
OpStore %x_36_phi %false
OpBranch %25
%25 = OpLabel
OpLoopMerge %26 %27 None
OpBranch %28
%28 = OpLabel
%31 = OpLoad %bool %x_36_phi
OpBranch %32
%32 = OpLabel
OpLoopMerge %33 %34 None
OpBranch %35
%35 = OpLabel
%39 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0
%40 = OpLoad %int %39
%42 = OpIEqual %bool %40 %int_1
OpSelectionMerge %43 None
OpBranchConditional %42 %44 %43
%44 = OpLabel
OpStore %x_33 %true
OpStore %x_34 %48
OpStore %x_48_phi %48
OpStore %x_49_phi %true
OpBranch %33
%43 = OpLabel
OpBranch %34
%34 = OpLabel
OpStore %x_48_phi %49
OpStore %x_49_phi %false
OpBranchConditional %false %32 %33
%33 = OpLabel
%50 = OpLoad %v4float %x_48_phi
OpStore %x_48 %50
%51 = OpLoad %bool %x_49_phi
%52 = OpLoad %v4float %x_48
OpStore %x_51_phi %52
OpSelectionMerge %53 None
OpBranchConditional %51 %54 %53
%54 = OpLabel
OpBranch %26
%53 = OpLabel
OpStore %x_33 %true
OpStore %x_34 %48
OpStore %x_51_phi %48
OpBranch %26
%27 = OpLabel
OpStore %x_36_phi %false
OpBranch %25
%26 = OpLabel
%55 = OpLoad %v4float %x_51_phi
OpReturnValue %55
OpFunctionEnd
%main_1 = OpFunction %void None %56
%59 = OpLabel
OpBranch %60
%60 = OpLabel
OpLoopMerge %61 %62 None
OpBranch %63
%63 = OpLabel
%64 = OpFunctionCall %v4float %returnRed_
OpStore %x_GLF_color %64
OpSelectionMerge %65 None
OpBranchConditional %false %66 %67
%66 = OpLabel
OpBranch %65
%67 = OpLabel
OpBranch %61
%65 = OpLabel
OpBranch %62
%62 = OpLabel
OpBranch %60
%61 = OpLabel
OpReturn
OpFunctionEnd
%tint_symbol_2 = OpFunction %void None %68
%tint_symbol = OpFunctionParameter %main_out
%72 = OpLabel
%73 = OpCompositeExtract %v4float %tint_symbol 0
OpStore %tint_symbol_1 %73
OpReturn
OpFunctionEnd
%main = OpFunction %void None %56
%75 = OpLabel
%76 = OpFunctionCall %void %main_1
%78 = OpLoad %v4float %x_GLF_color
%79 = OpCompositeConstruct %main_out %78
%77 = OpFunctionCall %void %tint_symbol_2 %79
OpReturn
OpFunctionEnd