wgpu/naga/tests/out/msl/break-if.msl
Jim Blandy 3fda684eb9 [naga msl-out] Defeat the MSL compiler's infinite loop analysis.
See the comments in the code for details.

This patch emits the definition of the macro only when the first loop
is encountered. This does make that first loop's code look a bit odd:
it would be more natural to define the macro at the top of the
file. (See the modified files in `naga/tests/out/msl`.)

Rejected alternatives:

- We could emit the macro definition unconditionally at the top of the
  file. But this changes every MSL snapshot output file, whereas only
  eight of them actually contain loops.

- We could have the validator flag modules that contain loops. But the
  changes end up being not small, and spread across the validator, so
  this seems disproportionate. If we had other consumers of this
  information, it might make sense.

- We could change the MSL backend to allow text to be generated out of
  order, so that we can decide whether to define the macro after we've
  generated all the function bodies. But at the moment this seems like
  unnecessary complexity, although it might be worth doing in the
  future if we had additional uses for it - say, to conditionally emit
  helper function definitions.

Fixes #4972.
2024-09-18 11:01:51 -04:00

87 lines
1.6 KiB
Plaintext

// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>
using metal::uint;
void breakIfEmpty(
) {
#define LOOP_IS_REACHABLE if (volatile bool unpredictable_jump_over_loop = true; unpredictable_jump_over_loop)
bool loop_init = true;
LOOP_IS_REACHABLE while(true) {
if (!loop_init) {
if (true) {
break;
}
}
loop_init = false;
}
return;
}
void breakIfEmptyBody(
bool a
) {
bool b = {};
bool c = {};
bool loop_init_1 = true;
LOOP_IS_REACHABLE while(true) {
if (!loop_init_1) {
b = a;
bool _e2 = b;
c = a != _e2;
bool _e5 = c;
if (a == c) {
break;
}
}
loop_init_1 = false;
}
return;
}
void breakIf(
bool a_1
) {
bool d = {};
bool e = {};
bool loop_init_2 = true;
LOOP_IS_REACHABLE while(true) {
if (!loop_init_2) {
bool _e5 = e;
if (a_1 == e) {
break;
}
}
loop_init_2 = false;
d = a_1;
bool _e2 = d;
e = a_1 != _e2;
}
return;
}
void breakIfSeparateVariable(
) {
uint counter = 0u;
bool loop_init_3 = true;
LOOP_IS_REACHABLE while(true) {
if (!loop_init_3) {
uint _e5 = counter;
if (counter == 5u) {
break;
}
}
loop_init_3 = false;
uint _e3 = counter;
counter = _e3 + 1u;
}
return;
}
kernel void main_(
) {
return;
}