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/builtin_polyfill.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/module_scope_var_to_entry_point_param.h"
#include "src/tint/transform/promote_initializers_to_const_var.h"
@ -174,6 +175,7 @@ SanitizedResult Sanitize(
manager.Add<transform::ZeroInitWorkgroupMemory>();
}
manager.Add<transform::CanonicalizeEntryPointIO>();
manager.Add<transform::ExpandCompoundAssignment>();
manager.Add<transform::PromoteSideEffectsToDecl>();
manager.Add<transform::UnwindDiscardFunctions>();
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 {
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;
fn foo() -> i32 {
counter += 1;
return counter;
int bar(thread int* const tint_symbol_5) {
*(tint_symbol_5) = as_type<int>((as_type<uint>(*(tint_symbol_5)) + as_type<uint>(2)));
return *(tint_symbol_5);
}
fn bar() -> i32 {
counter += 2;
return counter;
void tint_symbol(thread int* const tint_symbol_6) {
S x = {};
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>
var<private> a : i32;
var<private> b : f32;
fn foo(maybe_zero : i32) {
a /= 0;
a %= 0;
a /= maybe_zero;
a %= maybe_zero;
b /= 0.0;
b %= 0.0;
b /= f32(maybe_zero);
b %= f32(maybe_zero);
using namespace metal;
void foo(int maybe_zero, thread int* const tint_symbol, thread float* const tint_symbol_1) {
*(tint_symbol) = (*(tint_symbol) / 0);
*(tint_symbol) = (*(tint_symbol) % 0);
*(tint_symbol) = (*(tint_symbol) / maybe_zero);
*(tint_symbol) = (*(tint_symbol) % maybe_zero);
*(tint_symbol_1) = (*(tint_symbol_1) / 0.0f);
*(tint_symbol_1) = fmod(*(tint_symbol_1), 0.0f);
*(tint_symbol_1) = (*(tint_symbol_1) / float(maybe_zero));
*(tint_symbol_1) = fmod(*(tint_symbol_1), float(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 {
a : i32,
b : vec4<f32>,
c : mat2x2<f32>,
}
int a;
float4 b;
float2x2 c;
};
@group(0) @binding(0) var<storage, read_write> v : S;
var<private> i : u32;
fn idx1() -> i32 {
i += 1u;
int idx1(thread uint* const tint_symbol_5) {
*(tint_symbol_5) = (*(tint_symbol_5) + 1u);
return 1;
}
fn idx2() -> i32 {
i += 2u;
int idx2(thread uint* const tint_symbol_6) {
*(tint_symbol_6) = (*(tint_symbol_6) + 2u);
return 1;
}
fn idx3() -> i32 {
i += 3u;
int idx3(thread uint* const tint_symbol_7) {
*(tint_symbol_7) = (*(tint_symbol_7) + 3u);
return 1;
}
fn foo() {
var a = array<f32, 4>();
for(a[idx1()] *= 2.0; (a[idx2()] < 10.0); a[idx3()] += 1.0) {
struct tint_array_wrapper {
float arr[4];
};
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>
fn foo() {
var<function> a : i32;
var<function> b : vec4<f32>;
var<function> c : mat2x2<f32>;
a /= 2;
b *= mat4x4<f32>();
c *= 2.0;
using namespace metal;
void foo() {
int a = 0;
float4 b = 0.0f;
float2x2 c = float2x2(0.0f);
a = (a / 2);
b = (b * float4x4());
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 {
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 {
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 {
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 {
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>
var<private> a : i32;
var<private> b : vec4<f32>;
var<private> c : mat2x2<f32>;
fn foo() {
a /= 2;
b *= mat4x4<f32>();
c *= 2.0;
using namespace metal;
void foo(thread int* const tint_symbol, thread float4* const tint_symbol_1, thread float2x2* const tint_symbol_2) {
*(tint_symbol) = (*(tint_symbol) / 2);
*(tint_symbol_1) = (*(tint_symbol_1) * float4x4());
*(tint_symbol_2) = (*(tint_symbol_2) * 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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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>
var<workgroup> a : i32;
var<workgroup> b : vec4<f32>;
var<workgroup> c : mat2x2<f32>;
fn foo() {
a /= 2;
b *= mat4x4<f32>();
c *= 2.0;
using namespace metal;
void foo(threadgroup int* const tint_symbol, threadgroup float4* const tint_symbol_1, threadgroup float2x2* const tint_symbol_2) {
*(tint_symbol) = (*(tint_symbol) / 2);
*(tint_symbol_1) = (*(tint_symbol_1) * float4x4());
*(tint_symbol_2) = (*(tint_symbol_2) * 2.0f);
}
Failed to generate: error: unknown statement type: tint::ast::CompoundAssignmentStatement