tint: ProgramBuilder: Rename Const() to Let()

These methods produce `let` declarations.
With creation-time expressions, we'll need to add `const` declarations.

Note that module-scope `let` declarations have been removed in the spec (for `const`). ProgramBuilder::GlobalConst() has not been renamed, although it still currently produces 'let' declarations.

Bug: tint:1504
Change-Id: I34f6d62236f0572163fc9c2d8fddfe4503817422
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88305
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2022-04-28 14:35:04 +00:00
committed by Dawn LUCI CQ
parent 3e9077d04e
commit e85fe161cd
60 changed files with 502 additions and 518 deletions

View File

@@ -59,48 +59,47 @@ struct BuiltinPolyfill::State {
auto V = [&](uint32_t value) -> const ast::Expression* {
return ScalarOrVector(width, value);
};
b.Func(
name, {b.Param("v", T(ty))}, T(ty),
{
// var x = U(v);
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
// let b16 = select(0, 16, x <= 0x0000ffff);
b.Decl(b.Const("b16", nullptr,
b.Call("select", V(0), V(16),
b.LessThanEqual("x", V(0x0000ffff))))),
// x = x << b16;
b.Assign("x", b.Shl("x", "b16")),
// let b8 = select(0, 8, x <= 0x00ffffff);
b.Decl(b.Const("b8", nullptr,
b.Call("select", V(0), V(8),
b.LessThanEqual("x", V(0x00ffffff))))),
// x = x << b8;
b.Assign("x", b.Shl("x", "b8")),
// let b4 = select(0, 4, x <= 0x0fffffff);
b.Decl(b.Const("b4", nullptr,
b.Call("select", V(0), V(4),
b.LessThanEqual("x", V(0x0fffffff))))),
// x = x << b4;
b.Assign("x", b.Shl("x", "b4")),
// let b2 = select(0, 2, x <= 0x3fffffff);
b.Decl(b.Const("b2", nullptr,
b.Call("select", V(0), V(2),
b.LessThanEqual("x", V(0x3fffffff))))),
// x = x << b2;
b.Assign("x", b.Shl("x", "b2")),
// let b1 = select(0, 1, x <= 0x7fffffff);
b.Decl(b.Const("b1", nullptr,
b.Call("select", V(0), V(1),
b.LessThanEqual("x", V(0x7fffffff))))),
// let is_zero = select(0, 1, x == 0);
b.Decl(b.Const("is_zero", nullptr,
b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
// return R((b16 | b8 | b4 | b2 | b1) + zero);
b.Return(b.Construct(
T(ty),
b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"),
"is_zero"))),
});
b.Func(name, {b.Param("v", T(ty))}, T(ty),
{
// var x = U(v);
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
// let b16 = select(0, 16, x <= 0x0000ffff);
b.Decl(b.Let("b16", nullptr,
b.Call("select", V(0), V(16),
b.LessThanEqual("x", V(0x0000ffff))))),
// x = x << b16;
b.Assign("x", b.Shl("x", "b16")),
// let b8 = select(0, 8, x <= 0x00ffffff);
b.Decl(b.Let("b8", nullptr,
b.Call("select", V(0), V(8),
b.LessThanEqual("x", V(0x00ffffff))))),
// x = x << b8;
b.Assign("x", b.Shl("x", "b8")),
// let b4 = select(0, 4, x <= 0x0fffffff);
b.Decl(b.Let("b4", nullptr,
b.Call("select", V(0), V(4),
b.LessThanEqual("x", V(0x0fffffff))))),
// x = x << b4;
b.Assign("x", b.Shl("x", "b4")),
// let b2 = select(0, 2, x <= 0x3fffffff);
b.Decl(b.Let("b2", nullptr,
b.Call("select", V(0), V(2),
b.LessThanEqual("x", V(0x3fffffff))))),
// x = x << b2;
b.Assign("x", b.Shl("x", "b2")),
// let b1 = select(0, 1, x <= 0x7fffffff);
b.Decl(b.Let("b1", nullptr,
b.Call("select", V(0), V(1),
b.LessThanEqual("x", V(0x7fffffff))))),
// let is_zero = select(0, 1, x == 0);
b.Decl(b.Let("is_zero", nullptr,
b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
// return R((b16 | b8 | b4 | b2 | b1) + zero);
b.Return(b.Construct(
T(ty),
b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"),
"is_zero"))),
});
return name;
}
@@ -127,48 +126,47 @@ struct BuiltinPolyfill::State {
}
return b.Construct(b.ty.vec<bool>(width), value);
};
b.Func(
name, {b.Param("v", T(ty))}, T(ty),
{
// var x = U(v);
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
// let b16 = select(16, 0, bool(x & 0x0000ffff));
b.Decl(b.Const(
"b16", nullptr,
b.Call("select", V(16), V(0), B(b.And("x", V(0x0000ffff)))))),
// x = x >> b16;
b.Assign("x", b.Shr("x", "b16")),
// let b8 = select(8, 0, bool(x & 0x000000ff));
b.Decl(b.Const(
"b8", nullptr,
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
// x = x >> b8;
b.Assign("x", b.Shr("x", "b8")),
// let b4 = select(4, 0, bool(x & 0x0000000f));
b.Decl(b.Const(
"b4", nullptr,
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
// x = x >> b4;
b.Assign("x", b.Shr("x", "b4")),
// let b2 = select(2, 0, bool(x & 0x00000003));
b.Decl(b.Const(
"b2", nullptr,
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
// x = x >> b2;
b.Assign("x", b.Shr("x", "b2")),
// let b1 = select(1, 0, bool(x & 0x00000001));
b.Decl(b.Const(
"b1", nullptr,
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
// let is_zero = select(0, 1, x == 0);
b.Decl(b.Const("is_zero", nullptr,
b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
// return R((b16 | b8 | b4 | b2 | b1) + zero);
b.Return(b.Construct(
T(ty),
b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"),
"is_zero"))),
});
b.Func(name, {b.Param("v", T(ty))}, T(ty),
{
// var x = U(v);
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
// let b16 = select(16, 0, bool(x & 0x0000ffff));
b.Decl(b.Let("b16", nullptr,
b.Call("select", V(16), V(0),
B(b.And("x", V(0x0000ffff)))))),
// x = x >> b16;
b.Assign("x", b.Shr("x", "b16")),
// let b8 = select(8, 0, bool(x & 0x000000ff));
b.Decl(b.Let(
"b8", nullptr,
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
// x = x >> b8;
b.Assign("x", b.Shr("x", "b8")),
// let b4 = select(4, 0, bool(x & 0x0000000f));
b.Decl(b.Let(
"b4", nullptr,
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
// x = x >> b4;
b.Assign("x", b.Shr("x", "b4")),
// let b2 = select(2, 0, bool(x & 0x00000003));
b.Decl(b.Let(
"b2", nullptr,
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
// x = x >> b2;
b.Assign("x", b.Shr("x", "b2")),
// let b1 = select(1, 0, bool(x & 0x00000001));
b.Decl(b.Let(
"b1", nullptr,
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
// let is_zero = select(0, 1, x == 0);
b.Decl(b.Let("is_zero", nullptr,
b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
// return R((b16 | b8 | b4 | b2 | b1) + zero);
b.Return(b.Construct(
T(ty),
b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"),
"is_zero"))),
});
return name;
}
@@ -190,14 +188,14 @@ struct BuiltinPolyfill::State {
};
ast::StatementList body = {
b.Decl(b.Const("s", nullptr, b.Call("min", "offset", W))),
b.Decl(b.Const("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
b.Decl(b.Let("s", nullptr, b.Call("min", "offset", W))),
b.Decl(b.Let("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
};
switch (polyfill.extract_bits) {
case Level::kFull:
body.emplace_back(b.Decl(b.Const("shl", nullptr, b.Sub(W, "e"))));
body.emplace_back(b.Decl(b.Const("shr", nullptr, b.Add("shl", "s"))));
body.emplace_back(b.Decl(b.Let("shl", nullptr, b.Sub(W, "e"))));
body.emplace_back(b.Decl(b.Let("shr", nullptr, b.Add("shl", "s"))));
body.emplace_back(b.Return(b.Shr(b.Shl("v", vecN_u32(b.Expr("shl"))),
vecN_u32(b.Expr("shr")))));
break;
@@ -264,37 +262,37 @@ struct BuiltinPolyfill::State {
// var x = select(U(v), ~U(v), v < 0); (signed)
b.Decl(b.Var("x", nullptr, x)),
// let b16 = select(0, 16, bool(x & 0xffff0000));
b.Decl(b.Const("b16", nullptr,
b.Call("select", V(0), V(16),
B(b.And("x", V(0xffff0000)))))),
b.Decl(b.Let("b16", nullptr,
b.Call("select", V(0), V(16),
B(b.And("x", V(0xffff0000)))))),
// x = x >> b16;
b.Assign("x", b.Shr("x", "b16")),
// let b8 = select(0, 8, bool(x & 0x0000ff00));
b.Decl(b.Const(
b.Decl(b.Let(
"b8", nullptr,
b.Call("select", V(0), V(8), B(b.And("x", V(0x0000ff00)))))),
// x = x >> b8;
b.Assign("x", b.Shr("x", "b8")),
// let b4 = select(0, 4, bool(x & 0x000000f0));
b.Decl(b.Const(
b.Decl(b.Let(
"b4", nullptr,
b.Call("select", V(0), V(4), B(b.And("x", V(0x000000f0)))))),
// x = x >> b4;
b.Assign("x", b.Shr("x", "b4")),
// let b2 = select(0, 2, bool(x & 0x0000000c));
b.Decl(b.Const(
b.Decl(b.Let(
"b2", nullptr,
b.Call("select", V(0), V(2), B(b.And("x", V(0x0000000c)))))),
// x = x >> b2;
b.Assign("x", b.Shr("x", "b2")),
// let b1 = select(0, 1, bool(x & 0x00000002));
b.Decl(b.Const(
b.Decl(b.Let(
"b1", nullptr,
b.Call("select", V(0), V(1), B(b.And("x", V(0x00000002)))))),
// let is_zero = select(0, 0xffffffff, x == 0);
b.Decl(b.Const("is_zero", nullptr,
b.Call("select", V(0), V(0xffffffff),
b.Equal("x", V(0))))),
b.Decl(b.Let(
"is_zero", nullptr,
b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
// return R(b16 | b8 | b4 | b2 | b1 | zero);
b.Return(b.Construct(
T(ty),
@@ -332,37 +330,37 @@ struct BuiltinPolyfill::State {
// var x = U(v);
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
// let b16 = select(16, 0, bool(x & 0x0000ffff));
b.Decl(b.Const("b16", nullptr,
b.Call("select", V(16), V(0),
B(b.And("x", V(0x0000ffff)))))),
b.Decl(b.Let("b16", nullptr,
b.Call("select", V(16), V(0),
B(b.And("x", V(0x0000ffff)))))),
// x = x >> b16;
b.Assign("x", b.Shr("x", "b16")),
// let b8 = select(8, 0, bool(x & 0x000000ff));
b.Decl(b.Const(
b.Decl(b.Let(
"b8", nullptr,
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
// x = x >> b8;
b.Assign("x", b.Shr("x", "b8")),
// let b4 = select(4, 0, bool(x & 0x0000000f));
b.Decl(b.Const(
b.Decl(b.Let(
"b4", nullptr,
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
// x = x >> b4;
b.Assign("x", b.Shr("x", "b4")),
// let b2 = select(2, 0, bool(x & 0x00000003));
b.Decl(b.Const(
b.Decl(b.Let(
"b2", nullptr,
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
// x = x >> b2;
b.Assign("x", b.Shr("x", "b2")),
// let b1 = select(1, 0, bool(x & 0x00000001));
b.Decl(b.Const(
b.Decl(b.Let(
"b1", nullptr,
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
// let is_zero = select(0, 0xffffffff, x == 0);
b.Decl(b.Const("is_zero", nullptr,
b.Call("select", V(0), V(0xffffffff),
b.Equal("x", V(0))))),
b.Decl(b.Let(
"is_zero", nullptr,
b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
// return R(b16 | b8 | b4 | b2 | b1 | is_zero);
b.Return(b.Construct(
T(ty),
@@ -399,14 +397,14 @@ struct BuiltinPolyfill::State {
};
ast::StatementList body = {
b.Decl(b.Const("s", nullptr, b.Call("min", "offset", W))),
b.Decl(b.Const("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
b.Decl(b.Let("s", nullptr, b.Call("min", "offset", W))),
b.Decl(b.Let("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
};
switch (polyfill.insert_bits) {
case Level::kFull:
// let mask = ((1 << s) - 1) ^ ((1 << e) - 1)
body.emplace_back(b.Decl(b.Const(
body.emplace_back(b.Decl(b.Let(
"mask", nullptr,
b.Xor(b.Sub(b.Shl(1u, "s"), 1u), b.Sub(b.Shl(1u, "e"), 1u)))));
// return ((n << s) & mask) | (v & ~mask)

View File

@@ -215,8 +215,8 @@ void CalculateArrayLength::Run(CloneContext& ctx,
}
uint32_t array_stride = array_type->Size();
auto* array_length_var = ctx.dst->Decl(
ctx.dst->Const(name, ctx.dst->ty.u32(),
ctx.dst->Div(total_size, array_stride)));
ctx.dst->Let(name, ctx.dst->ty.u32(),
ctx.dst->Div(total_size, array_stride)));
// Insert the array length calculations at the top of the block
ctx.InsertBefore(block->statements, block->statements[0],

View File

@@ -562,8 +562,8 @@ struct CanonicalizeEntryPointIO::State {
wrapper_body.push_back(ctx.dst->CallStmt(call_inner));
} else {
// Capture the result of calling the original function.
auto* inner_result = ctx.dst->Const(
ctx.dst->Symbols().New("inner_result"), nullptr, call_inner);
auto* inner_result = ctx.dst->Let(ctx.dst->Symbols().New("inner_result"),
nullptr, call_inner);
wrapper_body.push_back(ctx.dst->Decl(inner_result));
// Process the original return type to determine the outputs that the

View File

@@ -80,8 +80,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateDefaultStridedArray) {
b.Global("arr", b.ty.array<f32, 4>(4), ast::StorageClass::kPrivate);
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("a", b.ty.array<f32, 4>(4), b.Expr("arr"))),
b.Decl(b.Const("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
b.Decl(b.Let("a", b.ty.array<f32, 4>(4), b.Expr("arr"))),
b.Decl(b.Let("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
},
{
b.Stage(ast::PipelineStage::kCompute),
@@ -117,8 +117,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateStridedArray) {
b.Global("arr", b.ty.array<f32, 4>(32), ast::StorageClass::kPrivate);
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("a", b.ty.array<f32, 4>(32), b.Expr("arr"))),
b.Decl(b.Const("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
b.Decl(b.Let("a", b.ty.array<f32, 4>(32), b.Expr("arr"))),
b.Decl(b.Let("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
},
{
b.Stage(ast::PipelineStage::kCompute),
@@ -163,10 +163,10 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformStridedArray) {
b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("a", b.ty.array<f32, 4>(32),
b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
b.Decl(b.Let("a", b.ty.array<f32, 4>(32),
b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
},
{
b.Stage(ast::PipelineStage::kCompute),
@@ -214,19 +214,19 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformDefaultStridedArray) {
b.Structure("S", {b.Member("a", b.ty.array(b.ty.vec4<f32>(), 4, 16))});
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("a", b.ty.array(b.ty.vec4<f32>(), 4, 16),
b.MemberAccessor("s", "a"))),
b.Decl(b.Const(
"b", b.ty.f32(),
b.IndexAccessor(b.IndexAccessor(b.MemberAccessor("s", "a"), 1),
2))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(b.Let("a", b.ty.array(b.ty.vec4<f32>(), 4, 16),
b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(
b.IndexAccessor(b.MemberAccessor("s", "a"), 1), 2))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
auto* expect =
R"(
@@ -266,10 +266,10 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageStridedArray) {
b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("a", b.ty.array<f32, 4>(32),
b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
b.Decl(b.Let("a", b.ty.array<f32, 4>(32),
b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
},
{
b.Stage(ast::PipelineStage::kCompute),
@@ -316,17 +316,17 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageDefaultStridedArray) {
auto* S = b.Structure("S", {b.Member("a", b.ty.array<f32, 4>(4))});
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("a", b.ty.array<f32, 4>(4),
b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(b.Let("a", b.ty.array<f32, 4>(4), b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
auto* expect = R"(
struct S {
@@ -476,22 +476,22 @@ TEST_F(DecomposeStridedArrayTest, ReadWriteViaPointerLets) {
auto* S = b.Structure("S", {b.Member("a", b.ty.array<f32, 4>(32))});
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("a", nullptr,
b.AddressOf(b.MemberAccessor("s", "a")))),
b.Decl(b.Const("b", nullptr,
b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
b.Decl(b.Const("c", nullptr, b.Deref("b"))),
b.Decl(b.Const("d", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
b.Assign(b.Deref("b"), b.Construct(b.ty.array<f32, 4>(32), 1.0f,
2.0f, 3.0f, 4.0f)),
b.Assign(b.IndexAccessor(b.Deref("b"), 1), 5.0f),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(b.Let("a", nullptr, b.AddressOf(b.MemberAccessor("s", "a")))),
b.Decl(b.Let("b", nullptr,
b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
b.Decl(b.Let("c", nullptr, b.Deref("b"))),
b.Decl(b.Let("d", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
b.Assign(b.Deref("b"),
b.Construct(b.ty.array<f32, 4>(32), 1.0f, 2.0f, 3.0f, 4.0f)),
b.Assign(b.IndexAccessor(b.Deref("b"), 1), 5.0f),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
auto* expect =
R"(
@@ -544,10 +544,9 @@ TEST_F(DecomposeStridedArrayTest, PrivateAliasedStridedArray) {
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(
b.Const("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
b.Decl(b.Let("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
b.Assign(b.MemberAccessor("s", "a"),
b.Construct(b.ty.type_name("ARR"))),
b.Assign(b.MemberAccessor("s", "a"),
@@ -618,26 +617,26 @@ TEST_F(DecomposeStridedArrayTest, PrivateNestedStridedArray) {
ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("a", b.ty.type_name("ARR_B"),
b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.array(b.ty.type_name("ARR_A"), 3, 16),
b.IndexAccessor( //
b.MemberAccessor("s", "a"), //
3))),
b.Decl(b.Const("c", b.ty.type_name("ARR_A"),
b.IndexAccessor( //
b.IndexAccessor( //
b.MemberAccessor("s", "a"), //
3),
2))),
b.Decl(b.Const("d", b.ty.f32(),
b.IndexAccessor( //
b.IndexAccessor( //
b.IndexAccessor( //
b.MemberAccessor("s", "a"), //
3),
2),
1))),
b.Decl(b.Let("a", b.ty.type_name("ARR_B"),
b.MemberAccessor("s", "a"))),
b.Decl(b.Let("b", b.ty.array(b.ty.type_name("ARR_A"), 3, 16),
b.IndexAccessor( //
b.MemberAccessor("s", "a"), //
3))),
b.Decl(b.Let("c", b.ty.type_name("ARR_A"),
b.IndexAccessor( //
b.IndexAccessor( //
b.MemberAccessor("s", "a"), //
3),
2))),
b.Decl(b.Let("d", b.ty.f32(),
b.IndexAccessor( //
b.IndexAccessor( //
b.IndexAccessor( //
b.MemberAccessor("s", "a"), //
3),
2),
1))),
b.Assign(b.MemberAccessor("s", "a"),
b.Construct(b.ty.type_name("ARR_B"))),
b.Assign(b.IndexAccessor( //

View File

@@ -79,15 +79,14 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) {
});
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
b.GroupAndBinding(0, 0));
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
auto* expect = R"(
struct S {
@@ -142,8 +141,8 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) {
b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("x", b.ty.vec2<f32>(),
b.IndexAccessor(b.MemberAccessor("s", "m"), 1))),
b.Decl(b.Let("x", b.ty.vec2<f32>(),
b.IndexAccessor(b.MemberAccessor("s", "m"), 1))),
},
{
b.Stage(ast::PipelineStage::kCompute),
@@ -197,15 +196,14 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) {
});
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
b.GroupAndBinding(0, 0));
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
auto* expect = R"(
struct S {
@@ -255,15 +253,14 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) {
});
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
auto* expect = R"(
struct S {
@@ -318,8 +315,8 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) {
ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Const("x", b.ty.vec2<f32>(),
b.IndexAccessor(b.MemberAccessor("s", "m"), 1))),
b.Decl(b.Let("x", b.ty.vec2<f32>(),
b.IndexAccessor(b.MemberAccessor("s", "m"), 1))),
},
{
b.Stage(ast::PipelineStage::kCompute),
@@ -501,13 +498,12 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) {
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(
b.Const("a", nullptr, b.AddressOf(b.MemberAccessor("s", "m")))),
b.Decl(b.Const("b", nullptr,
b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
b.Decl(b.Const("x", nullptr, b.Deref("b"))),
b.Decl(b.Const("y", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
b.Decl(b.Const("z", nullptr, b.IndexAccessor("x", 1))),
b.Decl(b.Let("a", nullptr, b.AddressOf(b.MemberAccessor("s", "m")))),
b.Decl(b.Let("b", nullptr,
b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
b.Decl(b.Let("x", nullptr, b.Deref("b"))),
b.Decl(b.Let("y", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
b.Decl(b.Let("z", nullptr, b.IndexAccessor("x", 1))),
b.Assign(b.Deref("b"), b.mat2x2<f32>(b.vec2<f32>(1.0f, 2.0f),
b.vec2<f32>(3.0f, 4.0f))),
b.Assign(b.IndexAccessor(b.Deref("b"), 1), b.vec2<f32>(5.0f, 6.0f)),
@@ -575,15 +571,14 @@ TEST_F(DecomposeStridedMatrixTest, ReadPrivateMatrix) {
}),
});
b.Global("s", b.ty.Of(S), ast::StorageClass::kPrivate);
b.Func(
"f", {}, b.ty.void_(),
{
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
b.Func("f", {}, b.ty.void_(),
{
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
},
{
b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1),
});
auto* expect = R"(
struct S {

View File

@@ -83,7 +83,7 @@ class State {
auto hoist_pointer_to = [&](const ast::Expression* expr) {
auto name = b.Sym();
auto* ptr = b.AddressOf(ctx.Clone(expr));
auto* decl = b.Decl(b.Const(name, nullptr, ptr));
auto* decl = b.Decl(b.Let(name, nullptr, ptr));
hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl);
return name;
};
@@ -91,7 +91,7 @@ class State {
// Helper function to hoist `expr` to a let declaration.
auto hoist_expr_to_let = [&](const ast::Expression* expr) {
auto name = b.Sym();
auto* decl = b.Decl(b.Const(name, nullptr, ctx.Clone(expr)));
auto* decl = b.Decl(b.Let(name, nullptr, ctx.Clone(expr)));
hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl);
return name;
};

View File

@@ -162,7 +162,7 @@ class LocalizeStructArrayAssignment::State {
// the value twice e.g. let tint_symbol = &(s.a1);
auto mem_access_ptr = b.Sym();
s.insert_before_stmts.push_back(
b.Decl(b.Const(mem_access_ptr, nullptr, b.AddressOf(mem_access))));
b.Decl(b.Let(mem_access_ptr, nullptr, b.AddressOf(mem_access))));
// Disable further transforms when cloning
TINT_SCOPED_ASSIGNMENT(s.process_nested_nodes, false);

View File

@@ -241,10 +241,10 @@ struct ModuleScopeVarToEntryPointParam::State {
auto* member_ptr = ctx.dst->AddressOf(ctx.dst->MemberAccessor(
ctx.dst->Deref(workgroup_param()), member));
auto* local_var =
ctx.dst->Const(new_var_symbol,
ctx.dst->ty.pointer(
store_type(), ast::StorageClass::kWorkgroup),
member_ptr);
ctx.dst->Let(new_var_symbol,
ctx.dst->ty.pointer(store_type(),
ast::StorageClass::kWorkgroup),
member_ptr);
ctx.InsertFront(func_ast->body->statements,
ctx.dst->Decl(local_var));
is_pointer = true;

View File

@@ -441,7 +441,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase {
[&](const ast::Expression* e) -> const ast::Expression* {
if (to_hoist.count(e)) {
auto name = b.Symbols().New();
auto* v = b.Const(name, nullptr, ctx.Clone(e));
auto* v = b.Let(name, nullptr, ctx.Clone(e));
auto* decl = b.Decl(v);
curr_stmts->push_back(decl);
return b.Expr(name);

View File

@@ -184,7 +184,7 @@ struct SimplifyPointers::State {
ctx.src->Symbols().NameFor(var->Declaration()->symbol) +
"_save");
auto* decl = ctx.dst->Decl(
ctx.dst->Const(saved_name, nullptr, ctx.Clone(idx_expr)));
ctx.dst->Let(saved_name, nullptr, ctx.Clone(idx_expr)));
saved.emplace_back(decl);
// Record the substitution of `idx_expr` to the saved variable
// with the symbol `saved_name`. This will be used by the

View File

@@ -211,7 +211,7 @@ class HoistToDeclBefore::State {
auto name = b.Symbols().New(decl_name);
// Construct the let/var that holds the hoisted expr
auto* v = as_const ? b.Const(name, nullptr, ctx.Clone(expr))
auto* v = as_const ? b.Let(name, nullptr, ctx.Clone(expr))
: b.Var(name, nullptr, ctx.Clone(expr));
auto* decl = b.Decl(v);

View File

@@ -310,7 +310,7 @@ struct State {
// let pulling_offset_n = <attribute_offset>
stmts.emplace_back(ctx.dst->Decl(
ctx.dst->Const(buffer_array_base, nullptr, attribute_offset)));
ctx.dst->Let(buffer_array_base, nullptr, attribute_offset)));
for (const VertexAttributeDescriptor& attribute_desc :
buffer_layout.attributes) {

View File

@@ -351,7 +351,7 @@ struct ZeroInitWorkgroupMemory::State {
ast::BinaryOp::kModulo, iteration(), b.Expr(index.modulo))
: iteration();
auto* div = (index.division != 1u) ? b.Div(mod, index.division) : mod;
auto* decl = b.Decl(b.Const(name, b.ty.u32(), div));
auto* decl = b.Decl(b.Let(name, b.ty.u32(), div));
stmts.emplace_back(decl);
}
return stmts;