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

305 lines
10 KiB
Plaintext

; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 162
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %tint_symbol %tint_symbol_2
OpExecutionMode %main OriginUpperLeft
OpName %gl_FragCoord "gl_FragCoord"
OpName %x_GLF_color "x_GLF_color"
OpName %tint_symbol "tint_symbol"
OpName %tint_symbol_2 "tint_symbol_2"
OpName %main_1 "main_1"
OpName %c "c"
OpName %a "a"
OpName %i1 "i1"
OpName %i2 "i2"
OpName %i3 "i3"
OpName %i4 "i4"
OpName %i5 "i5"
OpName %i6 "i6"
OpName %i7 "i7"
OpName %i8_1 "i8_1"
OpName %main_out "main_out"
OpMemberName %main_out 0 "x_GLF_color_1"
OpName %tint_symbol_3 "tint_symbol_3"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %main "main"
OpDecorate %tint_symbol BuiltIn FragCoord
OpDecorate %tint_symbol_2 Location 0
OpMemberDecorate %main_out 0 Offset 0
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Private_v4float = OpTypePointer Private %v4float
%5 = OpConstantNull %v4float
%gl_FragCoord = OpVariable %_ptr_Private_v4float Private %5
%x_GLF_color = OpVariable %_ptr_Private_v4float Private %5
%_ptr_Input_v4float = OpTypePointer Input %v4float
%tint_symbol = OpVariable %_ptr_Input_v4float Input
%_ptr_Output_v4float = OpTypePointer Output %v4float
%tint_symbol_2 = OpVariable %_ptr_Output_v4float Output %5
%void = OpTypeVoid
%11 = OpTypeFunction %void
%_ptr_Function_v4float = OpTypePointer Function %v4float
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%20 = OpConstantNull %int
%float_0 = OpConstant %float 0
%float_1 = OpConstant %float 1
%31 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_1
%int_0 = OpConstant %int 0
%_ptr_Function_float = OpTypePointer Function %float
%int_1 = OpConstant %int 1
%bool = OpTypeBool
%int_17 = OpConstant %int 17
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_Private_float = OpTypePointer Private %float
%float_n1 = OpConstant %float -1
%uint_1 = OpConstant %uint 1
%main_out = OpTypeStruct %v4float
%149 = OpTypeFunction %void %main_out
%main_1 = OpFunction %void None %11
%14 = OpLabel
%c = OpVariable %_ptr_Function_v4float Function %5
%a = OpVariable %_ptr_Function_int Function %20
%i1 = OpVariable %_ptr_Function_int Function %20
%i2 = OpVariable %_ptr_Function_int Function %20
%i3 = OpVariable %_ptr_Function_int Function %20
%i4 = OpVariable %_ptr_Function_int Function %20
%i5 = OpVariable %_ptr_Function_int Function %20
%i6 = OpVariable %_ptr_Function_int Function %20
%i7 = OpVariable %_ptr_Function_int Function %20
%i8_1 = OpVariable %_ptr_Function_int Function %20
OpStore %c %31
OpStore %a %int_0
OpBranch %33
%33 = OpLabel
OpLoopMerge %34 %35 None
OpBranch %36
%36 = OpLabel
OpBranch %37
%37 = OpLabel
OpLoopMerge %38 %39 None
OpBranch %40
%40 = OpLabel
%41 = OpLoad %int %a
%43 = OpAccessChain %_ptr_Function_float %c %41
OpStore %43 %float_1
OpStore %i1 %int_0
OpBranch %44
%44 = OpLabel
OpLoopMerge %45 %46 None
OpBranch %47
%47 = OpLabel
%48 = OpLoad %int %i1
%50 = OpSLessThan %bool %48 %int_1
OpSelectionMerge %52 None
OpBranchConditional %50 %53 %54
%53 = OpLabel
OpBranch %52
%54 = OpLabel
OpBranch %45
%52 = OpLabel
OpStore %i2 %int_0
OpBranch %55
%55 = OpLabel
OpLoopMerge %56 %57 None
OpBranch %58
%58 = OpLabel
%59 = OpLoad %int %i2
%60 = OpSLessThan %bool %59 %int_1
OpSelectionMerge %61 None
OpBranchConditional %60 %62 %63
%62 = OpLabel
OpBranch %61
%63 = OpLabel
OpBranch %56
%61 = OpLabel
OpStore %i3 %int_0
OpBranch %64
%64 = OpLabel
OpLoopMerge %65 %66 None
OpBranch %67
%67 = OpLabel
%68 = OpLoad %int %i3
%69 = OpSLessThan %bool %68 %int_1
OpSelectionMerge %70 None
OpBranchConditional %69 %71 %72
%71 = OpLabel
OpBranch %70
%72 = OpLabel
OpBranch %65
%70 = OpLabel
OpStore %i4 %int_0
OpBranch %73
%73 = OpLabel
OpLoopMerge %74 %75 None
OpBranch %76
%76 = OpLabel
%77 = OpLoad %int %i4
%78 = OpSLessThan %bool %77 %int_1
OpSelectionMerge %79 None
OpBranchConditional %78 %80 %81
%80 = OpLabel
OpBranch %79
%81 = OpLabel
OpBranch %74
%79 = OpLabel
OpStore %i5 %int_0
OpBranch %82
%82 = OpLabel
OpLoopMerge %83 %84 None
OpBranch %85
%85 = OpLabel
%86 = OpLoad %int %i5
%87 = OpSLessThan %bool %86 %int_1
OpSelectionMerge %88 None
OpBranchConditional %87 %89 %90
%89 = OpLabel
OpBranch %88
%90 = OpLabel
OpBranch %83
%88 = OpLabel
OpStore %i6 %int_0
OpBranch %91
%91 = OpLabel
OpLoopMerge %92 %93 None
OpBranch %94
%94 = OpLabel
%95 = OpLoad %int %i6
%96 = OpSLessThan %bool %95 %int_1
OpSelectionMerge %97 None
OpBranchConditional %96 %98 %99
%98 = OpLabel
OpBranch %97
%99 = OpLabel
OpBranch %92
%97 = OpLabel
OpStore %i7 %int_0
OpBranch %100
%100 = OpLabel
OpLoopMerge %101 %102 None
OpBranch %103
%103 = OpLabel
%104 = OpLoad %int %i7
%105 = OpSLessThan %bool %104 %int_1
OpSelectionMerge %106 None
OpBranchConditional %105 %107 %108
%107 = OpLabel
OpBranch %106
%108 = OpLabel
OpBranch %101
%106 = OpLabel
OpStore %i8_1 %int_0
OpBranch %109
%109 = OpLabel
OpLoopMerge %110 %111 None
OpBranch %112
%112 = OpLabel
%113 = OpLoad %int %i8_1
%115 = OpSLessThan %bool %113 %int_17
OpSelectionMerge %116 None
OpBranchConditional %115 %117 %118
%117 = OpLabel
OpBranch %116
%118 = OpLabel
OpBranch %110
%116 = OpLabel
%119 = OpLoad %int %a
%120 = OpIAdd %int %119 %int_1
OpStore %a %120
OpBranch %111
%111 = OpLabel
%121 = OpLoad %int %i8_1
%122 = OpIAdd %int %121 %int_1
OpStore %i8_1 %122
OpBranch %109
%110 = OpLabel
OpBranch %102
%102 = OpLabel
%123 = OpLoad %int %i7
%124 = OpIAdd %int %123 %int_1
OpStore %i7 %124
OpBranch %100
%101 = OpLabel
OpBranch %93
%93 = OpLabel
%125 = OpLoad %int %i6
%126 = OpIAdd %int %125 %int_1
OpStore %i6 %126
OpBranch %91
%92 = OpLabel
OpBranch %84
%84 = OpLabel
%127 = OpLoad %int %i5
%128 = OpIAdd %int %127 %int_1
OpStore %i5 %128
OpBranch %82
%83 = OpLabel
OpBranch %75
%75 = OpLabel
%129 = OpLoad %int %i4
%130 = OpIAdd %int %129 %int_1
OpStore %i4 %130
OpBranch %73
%74 = OpLabel
OpBranch %66
%66 = OpLabel
%131 = OpLoad %int %i3
%132 = OpIAdd %int %131 %int_1
OpStore %i3 %132
OpBranch %64
%65 = OpLabel
OpBranch %57
%57 = OpLabel
%133 = OpLoad %int %i2
%134 = OpIAdd %int %133 %int_1
OpStore %i2 %134
OpBranch %55
%56 = OpLabel
OpBranch %46
%46 = OpLabel
%135 = OpLoad %int %i1
%136 = OpIAdd %int %135 %int_1
OpStore %i1 %136
OpBranch %44
%45 = OpLabel
OpBranch %39
%39 = OpLabel
%140 = OpAccessChain %_ptr_Private_float %gl_FragCoord %uint_0
%141 = OpLoad %float %140
%143 = OpFOrdLessThan %bool %141 %float_n1
OpBranchConditional %143 %37 %38
%38 = OpLabel
OpBranch %35
%35 = OpLabel
%145 = OpAccessChain %_ptr_Private_float %gl_FragCoord %uint_1
%146 = OpLoad %float %145
%147 = OpFOrdLessThan %bool %146 %float_n1
OpBranchConditional %147 %33 %34
%34 = OpLabel
%148 = OpLoad %v4float %c
OpStore %x_GLF_color %148
OpReturn
OpFunctionEnd
%tint_symbol_3 = OpFunction %void None %149
%tint_symbol_1 = OpFunctionParameter %main_out
%153 = OpLabel
%154 = OpCompositeExtract %v4float %tint_symbol_1 0
OpStore %tint_symbol_2 %154
OpReturn
OpFunctionEnd
%main = OpFunction %void None %11
%156 = OpLabel
%157 = OpLoad %v4float %tint_symbol
OpStore %gl_FragCoord %157
%158 = OpFunctionCall %void %main_1
%160 = OpLoad %v4float %x_GLF_color
%161 = OpCompositeConstruct %main_out %160
%159 = OpFunctionCall %void %tint_symbol_3 %161
OpReturn
OpFunctionEnd