msl: Implement compound assignment

Use the ExpandCompoundAssignment transform to convert compound
assignments to regular assignments.

Bug: tint:1325
Change-Id: I960bf6cd0ec3490cd58685a7c13b6a7c86395080
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/85283
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2022-03-31 22:30:10 +00:00
parent b9b6e69631
commit 60107e7435
33 changed files with 271 additions and 349 deletions

View File

@ -61,6 +61,7 @@
#include "src/tint/transform/array_length_from_uniform.h" #include "src/tint/transform/array_length_from_uniform.h"
#include "src/tint/transform/builtin_polyfill.h" #include "src/tint/transform/builtin_polyfill.h"
#include "src/tint/transform/canonicalize_entry_point_io.h" #include "src/tint/transform/canonicalize_entry_point_io.h"
#include "src/tint/transform/expand_compound_assignment.h"
#include "src/tint/transform/manager.h" #include "src/tint/transform/manager.h"
#include "src/tint/transform/module_scope_var_to_entry_point_param.h" #include "src/tint/transform/module_scope_var_to_entry_point_param.h"
#include "src/tint/transform/promote_initializers_to_const_var.h" #include "src/tint/transform/promote_initializers_to_const_var.h"
@ -174,6 +175,7 @@ SanitizedResult Sanitize(
manager.Add<transform::ZeroInitWorkgroupMemory>(); manager.Add<transform::ZeroInitWorkgroupMemory>();
} }
manager.Add<transform::CanonicalizeEntryPointIO>(); manager.Add<transform::CanonicalizeEntryPointIO>();
manager.Add<transform::ExpandCompoundAssignment>();
manager.Add<transform::PromoteSideEffectsToDecl>(); manager.Add<transform::PromoteSideEffectsToDecl>();
manager.Add<transform::UnwindDiscardFunctions>(); manager.Add<transform::UnwindDiscardFunctions>();
manager.Add<transform::PromoteInitializersToConstVar>(); manager.Add<transform::PromoteInitializersToConstVar>();

View File

@ -1,26 +1,29 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct tint_array_wrapper {
int4 arr[4];
};
struct S { struct S {
a : array<vec4<i32>, 4>, tint_array_wrapper a;
};
int foo(thread int* const tint_symbol_4) {
*(tint_symbol_4) = as_type<int>((as_type<uint>(*(tint_symbol_4)) + as_type<uint>(1)));
return *(tint_symbol_4);
} }
var<private> counter : i32; int bar(thread int* const tint_symbol_5) {
*(tint_symbol_5) = as_type<int>((as_type<uint>(*(tint_symbol_5)) + as_type<uint>(2)));
fn foo() -> i32 { return *(tint_symbol_5);
counter += 1;
return counter;
} }
fn bar() -> i32 { void tint_symbol(thread int* const tint_symbol_6) {
counter += 2; S x = {};
return counter; int const tint_symbol_3 = foo(tint_symbol_6);
int const tint_symbol_1_save = tint_symbol_3;
int const tint_symbol_2 = bar(tint_symbol_6);
x.a.arr[tint_symbol_1_save][tint_symbol_2] = as_type<int>((as_type<uint>(x.a.arr[tint_symbol_1_save][tint_symbol_2]) + as_type<uint>(5)));
} }
fn tint_symbol() {
var x = S();
let p = &(x);
(*(p)).a[foo()][bar()] += 5;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,19 +1,14 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
var<private> a : i32; void foo(int maybe_zero, thread int* const tint_symbol, thread float* const tint_symbol_1) {
*(tint_symbol) = (*(tint_symbol) / 0);
var<private> b : f32; *(tint_symbol) = (*(tint_symbol) % 0);
*(tint_symbol) = (*(tint_symbol) / maybe_zero);
fn foo(maybe_zero : i32) { *(tint_symbol) = (*(tint_symbol) % maybe_zero);
a /= 0; *(tint_symbol_1) = (*(tint_symbol_1) / 0.0f);
a %= 0; *(tint_symbol_1) = fmod(*(tint_symbol_1), 0.0f);
a /= maybe_zero; *(tint_symbol_1) = (*(tint_symbol_1) / float(maybe_zero));
a %= maybe_zero; *(tint_symbol_1) = fmod(*(tint_symbol_1), float(maybe_zero));
b /= 0.0;
b %= 0.0;
b /= f32(maybe_zero);
b %= f32(maybe_zero);
} }
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,35 +1,50 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, int a;
b : vec4<f32>, float4 b;
c : mat2x2<f32>, float2x2 c;
} };
@group(0) @binding(0) var<storage, read_write> v : S; int idx1(thread uint* const tint_symbol_5) {
*(tint_symbol_5) = (*(tint_symbol_5) + 1u);
var<private> i : u32;
fn idx1() -> i32 {
i += 1u;
return 1; return 1;
} }
fn idx2() -> i32 { int idx2(thread uint* const tint_symbol_6) {
i += 2u; *(tint_symbol_6) = (*(tint_symbol_6) + 2u);
return 1; return 1;
} }
fn idx3() -> i32 { int idx3(thread uint* const tint_symbol_7) {
i += 3u; *(tint_symbol_7) = (*(tint_symbol_7) + 3u);
return 1; return 1;
} }
fn foo() { struct tint_array_wrapper {
var a = array<f32, 4>(); float arr[4];
for(a[idx1()] *= 2.0; (a[idx2()] < 10.0); a[idx3()] += 1.0) { };
void foo(thread uint* const tint_symbol_8) {
tint_array_wrapper a = {.arr={}};
int const tint_symbol_2 = idx1(tint_symbol_8);
int const tint_symbol_save = tint_symbol_2;
{
a.arr[tint_symbol_save] = (a.arr[tint_symbol_save] * 2.0f);
while (true) {
int const tint_symbol_3 = idx2(tint_symbol_8);
if (!((a.arr[tint_symbol_3] < 10.0f))) {
break;
}
{
}
{
int const tint_symbol_4 = idx3(tint_symbol_8);
int const tint_symbol_1_save = tint_symbol_4;
a.arr[tint_symbol_1_save] = (a.arr[tint_symbol_1_save] + 1.0f);
}
}
} }
} }
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,13 +1,12 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
fn foo() { void foo() {
var<function> a : i32; int a = 0;
var<function> b : vec4<f32>; float4 b = 0.0f;
var<function> c : mat2x2<f32>; float2x2 c = float2x2(0.0f);
a /= 2; a = (a / 2);
b *= mat4x4<f32>(); b = (b * float4x4());
c *= 2.0; c = (c * 2.0f);
} }
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : mat4x4<f32>, /* 0x0000 */ float4x4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a - float4x4());
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a -= mat4x4<f32>();
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : mat4x4<f32>, /* 0x0000 */ float4x4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a + float4x4());
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a += mat4x4<f32>();
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : mat4x4<f32>, /* 0x0000 */ float4x4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a * 2.0f);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a *= 2.0;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : mat4x4<f32>, /* 0x0000 */ float4x4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a * float4x4());
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a *= mat4x4<f32>();
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,16 +1,9 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
var<private> a : i32; void foo(thread int* const tint_symbol, thread float4* const tint_symbol_1, thread float2x2* const tint_symbol_2) {
*(tint_symbol) = (*(tint_symbol) / 2);
var<private> b : vec4<f32>; *(tint_symbol_1) = (*(tint_symbol_1) * float4x4());
*(tint_symbol_2) = (*(tint_symbol_2) * 2.0f);
var<private> c : mat2x2<f32>;
fn foo() {
a /= 2;
b *= mat4x4<f32>();
c *= 2.0;
} }
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, /* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a & 2);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a &= 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, /* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a / 2);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a /= 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, /* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = as_type<int>((as_type<uint>((*(tint_symbol)).a) - as_type<uint>(2)));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a -= 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, /* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a % 2);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a %= 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, /* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a | 2);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a |= 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, /* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = as_type<int>((as_type<uint>((*(tint_symbol)).a) + as_type<uint>(2)));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a += 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, /* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = as_type<int>((as_type<uint>((*(tint_symbol)).a) * as_type<uint>(2)));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a *= 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : i32, /* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a ^ 2);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a ^= 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a & int4(2));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a &= vec4<i32>(2);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<f32>, /* 0x0000 */ float4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a / 2.0f);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a /= 2.0;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a / int4(2));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a /= vec4<i32>(2);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<f32>, /* 0x0000 */ float4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a - 2.0f);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a -= 2.0;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = as_type<int4>((as_type<uint4>((*(tint_symbol)).a) - as_type<uint4>(int4(2))));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a -= vec4<i32>(2);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a % 2);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a %= 2;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a % int4(2));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a %= vec4<i32>(2);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a | int4(2));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a |= vec4<i32>(2);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<f32>, /* 0x0000 */ float4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a + 2.0f);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a += 2.0;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = as_type<int4>((as_type<uint4>((*(tint_symbol)).a) + as_type<uint4>(int4(2))));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a += vec4<i32>(2);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<f32>, /* 0x0000 */ float4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a * float4x4());
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a *= mat4x4<f32>();
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<f32>, /* 0x0000 */ float4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a * 2.0f);
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a *= 2.0;
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = as_type<int4>((as_type<uint4>((*(tint_symbol)).a) * as_type<uint4>(int4(2))));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a *= vec4<i32>(2);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,14 +1,11 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
struct S { struct S {
a : vec4<i32>, /* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a ^ int4(2));
} }
@group(0) @binding(0) var<storage, read_write> v : S;
fn foo() {
v.a ^= vec4<i32>(2);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement

View File

@ -1,16 +1,9 @@
SKIP: FAILED #include <metal_stdlib>
using namespace metal;
var<workgroup> a : i32; void foo(threadgroup int* const tint_symbol, threadgroup float4* const tint_symbol_1, threadgroup float2x2* const tint_symbol_2) {
*(tint_symbol) = (*(tint_symbol) / 2);
var<workgroup> b : vec4<f32>; *(tint_symbol_1) = (*(tint_symbol_1) * float4x4());
*(tint_symbol_2) = (*(tint_symbol_2) * 2.0f);
var<workgroup> c : mat2x2<f32>;
fn foo() {
a /= 2;
b *= mat4x4<f32>();
c *= 2.0;
} }
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement