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

478 lines
19 KiB
Plaintext

; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 321
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %tint_symbol_1
OpExecutionMode %main OriginUpperLeft
OpName %buf0 "buf0"
OpMemberName %buf0 0 "x_GLF_uniform_int_values"
OpName %x_6 "x_6"
OpName %x_GLF_color "x_GLF_color"
OpName %buf1 "buf1"
OpMemberName %buf1 0 "one"
OpName %x_19 "x_19"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %main_1 "main_1"
OpName %arr0 "arr0"
OpName %arr1 "arr1"
OpName %a "a"
OpName %limiter0 "limiter0"
OpName %limiter1 "limiter1"
OpName %b "b"
OpName %limiter2 "limiter2"
OpName %limiter3 "limiter3"
OpName %d "d"
OpName %ref0 "ref0"
OpName %ref1 "ref1"
OpName %i "i"
OpName %x_277 "x_277"
OpName %x_278_phi "x_278_phi"
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 %_arr_int_uint_20 ArrayStride 16
OpDecorate %x_6 NonWritable
OpDecorate %x_6 DescriptorSet 0
OpDecorate %x_6 Binding 0
OpDecorate %buf1 Block
OpMemberDecorate %buf1 0 Offset 0
OpDecorate %x_19 NonWritable
OpDecorate %x_19 DescriptorSet 0
OpDecorate %x_19 Binding 1
OpDecorate %tint_symbol_1 Location 0
OpDecorate %_arr_int_uint_10 ArrayStride 4
OpMemberDecorate %main_out 0 Offset 0
%int = OpTypeInt 32 1
%uint = OpTypeInt 32 0
%uint_20 = OpConstant %uint 20
%_arr_int_uint_20 = OpTypeArray %int %uint_20
%buf0 = OpTypeStruct %_arr_int_uint_20
%_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
%12 = OpConstantNull %v4float
%x_GLF_color = OpVariable %_ptr_Private_v4float Private %12
%buf1 = OpTypeStruct %int
%_ptr_Uniform_buf1 = OpTypePointer Uniform %buf1
%x_19 = OpVariable %_ptr_Uniform_buf1 Uniform
%_ptr_Output_v4float = OpTypePointer Output %v4float
%tint_symbol_1 = OpVariable %_ptr_Output_v4float Output %12
%void = OpTypeVoid
%18 = OpTypeFunction %void
%uint_10 = OpConstant %uint 10
%_arr_int_uint_10 = OpTypeArray %int %uint_10
%_ptr_Function__arr_int_uint_10 = OpTypePointer Function %_arr_int_uint_10
%26 = OpConstantNull %_arr_int_uint_10
%_ptr_Function_int = OpTypePointer Function %int
%30 = OpConstantNull %int
%uint_0 = OpConstant %uint 0
%int_3 = OpConstant %int 3
%_ptr_Uniform_int = OpTypePointer Uniform %int
%int_2 = OpConstant %int 2
%int_4 = OpConstant %int 4
%int_5 = OpConstant %int 5
%int_6 = OpConstant %int 6
%int_7 = OpConstant %int 7
%int_8 = OpConstant %int 8
%int_9 = OpConstant %int 9
%int_0 = OpConstant %int 0
%int_10 = OpConstant %int 10
%int_1 = OpConstant %int 1
%int_12 = OpConstant %int 12
%int_15 = OpConstant %int 15
%int_16 = OpConstant %int 16
%int_17 = OpConstant %int 17
%int_13 = OpConstant %int 13
%int_14 = OpConstant %int 14
%int_11 = OpConstant %int 11
%int_18 = OpConstant %int 18
%int_19 = OpConstant %int 19
%bool = OpTypeBool
%_ptr_Function_bool = OpTypePointer Function %bool
%273 = OpConstantNull %bool
%main_out = OpTypeStruct %v4float
%309 = OpTypeFunction %void %main_out
%main_1 = OpFunction %void None %18
%21 = OpLabel
%arr0 = OpVariable %_ptr_Function__arr_int_uint_10 Function %26
%arr1 = OpVariable %_ptr_Function__arr_int_uint_10 Function %26
%a = OpVariable %_ptr_Function_int Function %30
%limiter0 = OpVariable %_ptr_Function_int Function %30
%limiter1 = OpVariable %_ptr_Function_int Function %30
%b = OpVariable %_ptr_Function_int Function %30
%limiter2 = OpVariable %_ptr_Function_int Function %30
%limiter3 = OpVariable %_ptr_Function_int Function %30
%d = OpVariable %_ptr_Function_int Function %30
%ref0 = OpVariable %_ptr_Function__arr_int_uint_10 Function %26
%ref1 = OpVariable %_ptr_Function__arr_int_uint_10 Function %26
%i = OpVariable %_ptr_Function_int Function %30
%x_277 = OpVariable %_ptr_Function_bool Function %273
%x_278_phi = OpVariable %_ptr_Function_bool Function %273
%43 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_3
%44 = OpLoad %int %43
%46 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_2
%47 = OpLoad %int %46
%49 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_4
%50 = OpLoad %int %49
%52 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_5
%53 = OpLoad %int %52
%55 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_6
%56 = OpLoad %int %55
%58 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_7
%59 = OpLoad %int %58
%61 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_8
%62 = OpLoad %int %61
%64 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_9
%65 = OpLoad %int %64
%67 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_0
%68 = OpLoad %int %67
%70 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_10
%71 = OpLoad %int %70
%72 = OpCompositeConstruct %_arr_int_uint_10 %44 %47 %50 %53 %56 %59 %62 %65 %68 %71
OpStore %arr0 %72
%74 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_1
%75 = OpLoad %int %74
%77 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_12
%78 = OpLoad %int %77
%80 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_15
%81 = OpLoad %int %80
%83 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_16
%84 = OpLoad %int %83
%86 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_17
%87 = OpLoad %int %86
%89 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_13
%90 = OpLoad %int %89
%92 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_14
%93 = OpLoad %int %92
%95 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_11
%96 = OpLoad %int %95
%98 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_18
%99 = OpLoad %int %98
%101 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_19
%102 = OpLoad %int %101
%103 = OpCompositeConstruct %_arr_int_uint_10 %75 %78 %81 %84 %87 %90 %93 %96 %99 %102
OpStore %arr1 %103
%104 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_8
%105 = OpLoad %int %104
OpStore %a %105
OpBranch %106
%106 = OpLabel
OpLoopMerge %107 %108 None
OpBranch %109
%109 = OpLabel
%110 = OpLoad %int %a
%111 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_0
%112 = OpLoad %int %111
%113 = OpSLessThan %bool %110 %112
OpSelectionMerge %115 None
OpBranchConditional %113 %116 %117
%116 = OpLabel
OpBranch %115
%117 = OpLabel
OpBranch %107
%115 = OpLabel
%118 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_3
%119 = OpLoad %int %118
OpStore %limiter0 %119
OpBranch %120
%120 = OpLabel
OpLoopMerge %121 %122 None
OpBranch %123
%123 = OpLabel
%124 = OpLoad %int %limiter0
%125 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_4
%126 = OpLoad %int %125
%127 = OpSLessThan %bool %124 %126
OpSelectionMerge %128 None
OpBranchConditional %127 %129 %130
%129 = OpLabel
OpBranch %128
%130 = OpLabel
OpBranch %121
%128 = OpLabel
%131 = OpLoad %int %limiter0
%132 = OpIAdd %int %131 %int_1
OpStore %limiter0 %132
%133 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_2
%134 = OpLoad %int %133
OpStore %limiter1 %134
%135 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_3
%136 = OpLoad %int %135
OpStore %b %136
OpBranch %137
%137 = OpLabel
OpLoopMerge %138 %139 None
OpBranch %140
%140 = OpLabel
%141 = OpLoad %int %b
%142 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_1
%143 = OpLoad %int %142
%144 = OpSLessThan %bool %141 %143
OpSelectionMerge %145 None
OpBranchConditional %144 %146 %147
%146 = OpLabel
OpBranch %145
%147 = OpLabel
OpBranch %138
%145 = OpLabel
%148 = OpLoad %int %limiter1
%149 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_5
%150 = OpLoad %int %149
%151 = OpSGreaterThan %bool %148 %150
OpSelectionMerge %152 None
OpBranchConditional %151 %153 %152
%153 = OpLabel
OpBranch %138
%152 = OpLabel
%154 = OpLoad %int %limiter1
%155 = OpIAdd %int %154 %int_1
OpStore %limiter1 %155
%156 = OpLoad %int %b
%157 = OpLoad %int %a
%158 = OpAccessChain %_ptr_Function_int %arr1 %157
%159 = OpLoad %int %158
%160 = OpAccessChain %_ptr_Function_int %arr0 %156
OpStore %160 %159
OpBranch %139
%139 = OpLabel
%161 = OpLoad %int %b
%162 = OpIAdd %int %161 %int_1
OpStore %b %162
OpBranch %137
%138 = OpLabel
OpBranch %122
%122 = OpLabel
OpBranch %120
%121 = OpLabel
OpStore %limiter2 %int_0
OpBranch %163
%163 = OpLabel
OpLoopMerge %164 %165 None
OpBranch %166
%166 = OpLabel
%167 = OpLoad %int %limiter2
%168 = OpSLessThan %bool %167 %int_5
OpSelectionMerge %169 None
OpBranchConditional %168 %170 %171
%170 = OpLabel
OpBranch %169
%171 = OpLabel
OpBranch %164
%169 = OpLabel
%172 = OpLoad %int %limiter2
%173 = OpIAdd %int %172 %int_1
OpStore %limiter2 %173
%174 = OpAccessChain %_ptr_Function_int %arr1 %int_1
%175 = OpLoad %int %174
%176 = OpAccessChain %_ptr_Function_int %arr0 %int_1
OpStore %176 %175
OpBranch %165
%165 = OpLabel
OpBranch %163
%164 = OpLabel
OpBranch %177
%177 = OpLabel
OpLoopMerge %178 %179 None
OpBranch %180
%180 = OpLabel
OpStore %limiter3 %int_0
OpStore %d %int_0
OpBranch %181
%181 = OpLabel
OpLoopMerge %182 %183 None
OpBranch %184
%184 = OpLabel
%185 = OpLoad %int %d
%186 = OpSLessThan %bool %185 %int_10
OpSelectionMerge %187 None
OpBranchConditional %186 %188 %189
%188 = OpLabel
OpBranch %187
%189 = OpLabel
OpBranch %182
%187 = OpLabel
%190 = OpLoad %int %limiter3
%191 = OpSGreaterThan %bool %190 %int_4
OpSelectionMerge %192 None
OpBranchConditional %191 %193 %192
%193 = OpLabel
OpBranch %182
%192 = OpLabel
%194 = OpLoad %int %limiter3
%195 = OpIAdd %int %194 %int_1
OpStore %limiter3 %195
%196 = OpLoad %int %d
%197 = OpLoad %int %d
%198 = OpAccessChain %_ptr_Function_int %arr0 %197
%199 = OpLoad %int %198
%200 = OpAccessChain %_ptr_Function_int %arr1 %196
OpStore %200 %199
OpBranch %183
%183 = OpLabel
%201 = OpLoad %int %d
%202 = OpIAdd %int %201 %int_1
OpStore %d %202
OpBranch %181
%182 = OpLabel
OpBranch %179
%179 = OpLabel
%203 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_2
%204 = OpLoad %int %203
%205 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_3
%206 = OpLoad %int %205
%207 = OpIEqual %bool %204 %206
OpBranchConditional %207 %177 %178
%178 = OpLabel
OpBranch %108
%108 = OpLabel
%208 = OpLoad %int %a
%209 = OpIAdd %int %208 %int_1
OpStore %a %209
OpBranch %106
%107 = OpLabel
%210 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_11
%211 = OpLoad %int %210
%212 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_12
%213 = OpLoad %int %212
%214 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_11
%215 = OpLoad %int %214
%216 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_5
%217 = OpLoad %int %216
%218 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_6
%219 = OpLoad %int %218
%220 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_7
%221 = OpLoad %int %220
%222 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_8
%223 = OpLoad %int %222
%224 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_9
%225 = OpLoad %int %224
%226 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_0
%227 = OpLoad %int %226
%228 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_10
%229 = OpLoad %int %228
%230 = OpCompositeConstruct %_arr_int_uint_10 %211 %213 %215 %217 %219 %221 %223 %225 %227 %229
OpStore %ref0 %230
%231 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_11
%232 = OpLoad %int %231
%233 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_12
%234 = OpLoad %int %233
%235 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_11
%236 = OpLoad %int %235
%237 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_5
%238 = OpLoad %int %237
%239 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_6
%240 = OpLoad %int %239
%241 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_13
%242 = OpLoad %int %241
%243 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_14
%244 = OpLoad %int %243
%245 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_11
%246 = OpLoad %int %245
%247 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_18
%248 = OpLoad %int %247
%249 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_19
%250 = OpLoad %int %249
%251 = OpCompositeConstruct %_arr_int_uint_10 %232 %234 %236 %238 %240 %242 %244 %246 %248 %250
OpStore %ref1 %251
%252 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_2
%253 = OpLoad %int %252
%254 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_3
%255 = OpLoad %int %254
%256 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_3
%257 = OpLoad %int %256
%258 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_2
%259 = OpLoad %int %258
%260 = OpConvertSToF %float %253
%261 = OpConvertSToF %float %255
%262 = OpConvertSToF %float %257
%263 = OpConvertSToF %float %259
%264 = OpCompositeConstruct %v4float %260 %261 %262 %263
OpStore %x_GLF_color %264
%265 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_3
%266 = OpLoad %int %265
OpStore %i %266
OpBranch %267
%267 = OpLabel
OpLoopMerge %268 %269 None
OpBranch %270
%270 = OpLabel
%275 = OpLoad %int %i
%276 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_1
%277 = OpLoad %int %276
%278 = OpSLessThan %bool %275 %277
OpSelectionMerge %279 None
OpBranchConditional %278 %280 %281
%280 = OpLabel
OpBranch %279
%281 = OpLabel
OpBranch %268
%279 = OpLabel
%282 = OpLoad %int %i
%283 = OpAccessChain %_ptr_Function_int %arr0 %282
%284 = OpLoad %int %283
%285 = OpLoad %int %i
%286 = OpAccessChain %_ptr_Function_int %ref0 %285
%287 = OpLoad %int %286
%288 = OpINotEqual %bool %284 %287
OpStore %x_278_phi %288
%289 = OpLogicalNot %bool %288
OpSelectionMerge %290 None
OpBranchConditional %289 %291 %290
%291 = OpLabel
%292 = OpLoad %int %i
%293 = OpAccessChain %_ptr_Function_int %arr1 %292
%294 = OpLoad %int %293
%295 = OpLoad %int %i
%296 = OpAccessChain %_ptr_Function_int %ref1 %295
%297 = OpLoad %int %296
%298 = OpINotEqual %bool %294 %297
OpStore %x_277 %298
%299 = OpLoad %bool %x_277
OpStore %x_278_phi %299
OpBranch %290
%290 = OpLabel
%300 = OpLoad %bool %x_278_phi
OpSelectionMerge %301 None
OpBranchConditional %300 %302 %301
%302 = OpLabel
%303 = OpAccessChain %_ptr_Uniform_int %x_6 %uint_0 %int_3
%304 = OpLoad %int %303
%305 = OpConvertSToF %float %304
%306 = OpCompositeConstruct %v4float %305 %305 %305 %305
OpStore %x_GLF_color %306
OpBranch %301
%301 = OpLabel
OpBranch %269
%269 = OpLabel
%307 = OpLoad %int %i
%308 = OpIAdd %int %307 %int_1
OpStore %i %308
OpBranch %267
%268 = OpLabel
OpReturn
OpFunctionEnd
%tint_symbol_2 = OpFunction %void None %309
%tint_symbol = OpFunctionParameter %main_out
%313 = OpLabel
%314 = OpCompositeExtract %v4float %tint_symbol 0
OpStore %tint_symbol_1 %314
OpReturn
OpFunctionEnd
%main = OpFunction %void None %18
%316 = OpLabel
%317 = OpFunctionCall %void %main_1
%319 = OpLoad %v4float %x_GLF_color
%320 = OpCompositeConstruct %main_out %319
%318 = OpFunctionCall %void %tint_symbol_2 %320
OpReturn
OpFunctionEnd