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

251 lines
9.2 KiB
Plaintext

; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 142
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %tint_symbol_1
OpExecutionMode %main OriginUpperLeft
OpName %buf0 "buf0"
OpMemberName %buf0 0 "injectionSwitch"
OpName %x_6 "x_6"
OpName %x_GLF_color "x_GLF_color"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %main_1 "main_1"
OpName %i "i"
OpName %GLF_dead5cols "GLF_dead5cols"
OpName %GLF_dead5rows "GLF_dead5rows"
OpName %GLF_dead5c "GLF_dead5c"
OpName %GLF_dead5r "GLF_dead5r"
OpName %msb10 "msb10"
OpName %donor_replacementGLF_dead5sums "donor_replacementGLF_dead5sums"
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
OpDecorate %_arr_float_uint_9 ArrayStride 4
OpMemberDecorate %main_out 0 Offset 0
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%buf0 = OpTypeStruct %v2float
%_ptr_Uniform_buf0 = OpTypePointer Uniform %buf0
%x_6 = OpVariable %_ptr_Uniform_buf0 Uniform
%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
%void = OpTypeVoid
%12 = OpTypeFunction %void
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%19 = OpConstantNull %int
%uint = OpTypeInt 32 0
%uint_9 = OpConstant %uint 9
%_arr_float_uint_9 = OpTypeArray %float %uint_9
%_ptr_Function__arr_float_uint_9 = OpTypePointer Function %_arr_float_uint_9
%30 = OpConstantNull %_arr_float_uint_9
%int_0 = OpConstant %int 0
%uint_0 = OpConstant %uint 0
%_ptr_Uniform_float = OpTypePointer Uniform %float
%bool = OpTypeBool
%uint_1 = OpConstant %uint 1
%float_0 = OpConstant %float 0
%int_2 = OpConstant %int 2
%int_4 = OpConstant %int 4
%int_9 = OpConstant %int 9
%_ptr_Function_float = OpTypePointer Function %float
%float_1 = OpConstant %float 1
%int_1 = OpConstant %int 1
%int_200 = OpConstant %int 200
%129 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%main_out = OpTypeStruct %v4float
%130 = OpTypeFunction %void %main_out
%main_1 = OpFunction %void None %12
%15 = OpLabel
%i = OpVariable %_ptr_Function_int Function %19
%GLF_dead5cols = OpVariable %_ptr_Function_int Function %19
%GLF_dead5rows = OpVariable %_ptr_Function_int Function %19
%GLF_dead5c = OpVariable %_ptr_Function_int Function %19
%GLF_dead5r = OpVariable %_ptr_Function_int Function %19
%msb10 = OpVariable %_ptr_Function_int Function %19
%donor_replacementGLF_dead5sums = OpVariable %_ptr_Function__arr_float_uint_9 Function %30
OpStore %i %int_0
OpBranch %32
%32 = OpLabel
OpLoopMerge %33 %34 None
OpBranch %35
%35 = OpLabel
%36 = OpLoad %int %i
%39 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_0
%40 = OpLoad %float %39
%41 = OpConvertFToS %int %40
%42 = OpSGreaterThanEqual %bool %36 %41
OpSelectionMerge %44 None
OpBranchConditional %42 %45 %44
%45 = OpLabel
OpBranch %33
%44 = OpLabel
%47 = OpAccessChain %_ptr_Uniform_float %x_6 %uint_0 %uint_1
%48 = OpLoad %float %47
%50 = OpFOrdGreaterThan %bool %float_0 %48
OpSelectionMerge %51 None
OpBranchConditional %50 %52 %51
%52 = OpLabel
OpStore %GLF_dead5cols %int_2
OpBranch %54
%54 = OpLabel
OpLoopMerge %55 %56 None
OpBranch %57
%57 = OpLabel
%58 = OpLoad %int %GLF_dead5cols
%60 = OpSLessThanEqual %bool %58 %int_4
OpSelectionMerge %61 None
OpBranchConditional %60 %62 %63
%62 = OpLabel
OpBranch %61
%63 = OpLabel
OpBranch %55
%61 = OpLabel
OpStore %GLF_dead5rows %int_2
OpBranch %64
%64 = OpLabel
OpLoopMerge %65 %66 None
OpBranch %67
%67 = OpLabel
%68 = OpLoad %int %GLF_dead5rows
%69 = OpSLessThanEqual %bool %68 %int_4
OpSelectionMerge %70 None
OpBranchConditional %69 %71 %72
%71 = OpLabel
OpBranch %70
%72 = OpLabel
OpBranch %65
%70 = OpLabel
OpStore %GLF_dead5c %int_0
OpBranch %73
%73 = OpLabel
OpLoopMerge %74 %75 None
OpBranch %76
%76 = OpLabel
%77 = OpLoad %int %GLF_dead5c
%78 = OpLoad %int %GLF_dead5cols
%79 = OpSLessThan %bool %77 %78
OpSelectionMerge %80 None
OpBranchConditional %79 %81 %82
%81 = OpLabel
OpBranch %80
%82 = OpLabel
OpBranch %74
%80 = OpLabel
OpStore %GLF_dead5r %int_0
OpBranch %83
%83 = OpLabel
OpLoopMerge %84 %85 None
OpBranch %86
%86 = OpLabel
%87 = OpLoad %int %GLF_dead5r
%88 = OpLoad %int %GLF_dead5rows
%89 = OpSLessThan %bool %87 %88
OpSelectionMerge %90 None
OpBranchConditional %89 %91 %92
%91 = OpLabel
OpBranch %90
%92 = OpLabel
OpBranch %84
%90 = OpLabel
%93 = OpLoad %int %msb10
OpSelectionMerge %94 None
OpSwitch %93 %95 1 %96 8 %96
%96 = OpLabel
%97 = OpLoad %int %msb10
%98 = OpLoad %int %msb10
%99 = OpLoad %int %msb10
%101 = OpSGreaterThanEqual %bool %97 %int_0
OpSelectionMerge %102 None
OpBranchConditional %101 %103 %102
%103 = OpLabel
%105 = OpSLessThan %bool %98 %int_9
OpBranch %102
%102 = OpLabel
%106 = OpPhi %bool %101 %96 %105 %103
%100 = OpSelect %int %106 %99 %int_0
%108 = OpAccessChain %_ptr_Function_float %donor_replacementGLF_dead5sums %100
%109 = OpLoad %float %108
%110 = OpAccessChain %_ptr_Function_float %donor_replacementGLF_dead5sums %100
%112 = OpFAdd %float %109 %float_1
OpStore %110 %112
OpBranch %94
%95 = OpLabel
OpBranch %94
%94 = OpLabel
OpBranch %85
%85 = OpLabel
%113 = OpLoad %int %GLF_dead5r
%115 = OpIAdd %int %113 %int_1
OpStore %GLF_dead5r %115
OpBranch %83
%84 = OpLabel
OpBranch %75
%75 = OpLabel
%116 = OpLoad %int %GLF_dead5c
%117 = OpIAdd %int %116 %int_1
OpStore %GLF_dead5c %117
OpBranch %73
%74 = OpLabel
%118 = OpLoad %int %msb10
%119 = OpIAdd %int %118 %int_1
OpStore %msb10 %119
OpBranch %66
%66 = OpLabel
%120 = OpLoad %int %GLF_dead5rows
%121 = OpIAdd %int %120 %int_1
OpStore %GLF_dead5rows %121
OpBranch %64
%65 = OpLabel
OpBranch %56
%56 = OpLabel
%122 = OpLoad %int %GLF_dead5cols
%123 = OpIAdd %int %122 %int_1
OpStore %GLF_dead5cols %123
OpBranch %54
%55 = OpLabel
OpBranch %51
%51 = OpLabel
%124 = OpLoad %int %i
%125 = OpIAdd %int %124 %int_1
OpStore %i %125
OpBranch %34
%34 = OpLabel
%126 = OpLoad %int %i
%128 = OpSLessThan %bool %126 %int_200
OpBranchConditional %128 %32 %33
%33 = OpLabel
OpStore %x_GLF_color %129
OpReturn
OpFunctionEnd
%tint_symbol_2 = OpFunction %void None %130
%tint_symbol = OpFunctionParameter %main_out
%134 = OpLabel
%135 = OpCompositeExtract %v4float %tint_symbol 0
OpStore %tint_symbol_1 %135
OpReturn
OpFunctionEnd
%main = OpFunction %void None %12
%137 = OpLabel
%138 = OpFunctionCall %void %main_1
%140 = OpLoad %v4float %x_GLF_color
%141 = OpCompositeConstruct %main_out %140
%139 = OpFunctionCall %void %tint_symbol_2 %141
OpReturn
OpFunctionEnd