mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
tint: const eval of logical AND and OR
Bug: tint:1581 Change-Id: I3921041613cb1c9fa3365d4cb1fc8c81bab92003 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113101 Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
6198bea2ac
commit
4c8f5a1ac2
@@ -51,7 +51,7 @@ enum extension {
|
||||
chromium_disable_uniformity_analysis
|
||||
// A Chromium-specific extension for push constants
|
||||
chromium_experimental_push_constant
|
||||
// A Chromium-specific extension that enables passing of uniform, storage and workgroup
|
||||
// A Chromium-specific extension that enables passing of uniform, storage and workgroup
|
||||
// address-spaced pointers as parameters, as well as pointers into sub-objects.
|
||||
chromium_experimental_full_ptr_parameters
|
||||
}
|
||||
@@ -969,8 +969,8 @@ init mat4x4<T: fa_f32_f16>(vec4<T>, vec4<T>, vec4<T>, vec4<T>) -> mat4x4<T>
|
||||
@const op | <T: ia_iu32>(T, T) -> T
|
||||
@const op | <T: ia_iu32, N: num> (vec<N, T>, vec<N, T>) -> vec<N, T>
|
||||
|
||||
op && (bool, bool) -> bool
|
||||
op || (bool, bool) -> bool
|
||||
@const op && (bool, bool) -> bool
|
||||
@const op || (bool, bool) -> bool
|
||||
|
||||
@const op == <T: scalar>(T, T) -> bool
|
||||
@const op == <T: scalar, N: num> (vec<N, T>, vec<N, T>) -> vec<N, bool>
|
||||
|
||||
@@ -1810,6 +1810,18 @@ ConstEval::Result ConstEval::OpGreaterThanEqual(const sem::Type* ty,
|
||||
return TransformElements(builder, ty, transform, args[0], args[1]);
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::OpLogicalAnd(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source) {
|
||||
return CreateElement(builder, source, ty, args[0]->As<bool>() && args[1]->As<bool>());
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::OpLogicalOr(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source) {
|
||||
return CreateElement(builder, source, ty, args[0]->As<bool>() || args[1]->As<bool>());
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::OpAnd(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source) {
|
||||
|
||||
@@ -346,6 +346,24 @@ class ConstEval {
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// Logical and operator '&&'
|
||||
/// @param ty the expression type
|
||||
/// @param args the input arguments
|
||||
/// @param source the source location
|
||||
/// @return the result value, or null if the value cannot be calculated
|
||||
Result OpLogicalAnd(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// Logical or operator '||'
|
||||
/// @param ty the expression type
|
||||
/// @param args the input arguments
|
||||
/// @param source the source location
|
||||
/// @return the result value, or null if the value cannot be calculated
|
||||
Result OpLogicalOr(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// Bitwise and operator '&'
|
||||
/// @param ty the expression type
|
||||
/// @param args the input arguments
|
||||
|
||||
@@ -749,6 +749,34 @@ INSTANTIATE_TEST_SUITE_P(LessThanEqual,
|
||||
OpGreaterThanCases<f32, false>(),
|
||||
OpGreaterThanCases<f16, false>()))));
|
||||
|
||||
static std::vector<Case> OpLogicalAndCases() {
|
||||
return {
|
||||
C(true, true, true),
|
||||
C(true, false, false),
|
||||
C(false, true, false),
|
||||
C(false, false, false),
|
||||
};
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(LogicalAnd,
|
||||
ResolverConstEvalBinaryOpTest,
|
||||
testing::Combine( //
|
||||
testing::Values(ast::BinaryOp::kLogicalAnd),
|
||||
testing::ValuesIn(OpLogicalAndCases())));
|
||||
|
||||
static std::vector<Case> OpLogicalOrCases() {
|
||||
return {
|
||||
C(true, true, true),
|
||||
C(true, false, true),
|
||||
C(false, true, true),
|
||||
C(false, false, false),
|
||||
};
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(LogicalOr,
|
||||
ResolverConstEvalBinaryOpTest,
|
||||
testing::Combine( //
|
||||
testing::Values(ast::BinaryOp::kLogicalOr),
|
||||
testing::ValuesIn(OpLogicalOrCases())));
|
||||
|
||||
static std::vector<Case> OpAndBoolCases() {
|
||||
return {
|
||||
C(true, true, true),
|
||||
|
||||
@@ -13918,7 +13918,7 @@ constexpr OverloadInfo kOverloads[] = {
|
||||
/* parameters */ &kParameters[746],
|
||||
/* return matcher indices */ &kMatcherIndices[35],
|
||||
/* flags */ OverloadFlags(OverloadFlag::kIsOperator, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
|
||||
/* const eval */ nullptr,
|
||||
/* const eval */ &ConstEval::OpLogicalAnd,
|
||||
},
|
||||
{
|
||||
/* [469] */
|
||||
@@ -13930,7 +13930,7 @@ constexpr OverloadInfo kOverloads[] = {
|
||||
/* parameters */ &kParameters[748],
|
||||
/* return matcher indices */ &kMatcherIndices[35],
|
||||
/* flags */ OverloadFlags(OverloadFlag::kIsOperator, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
|
||||
/* const eval */ nullptr,
|
||||
/* const eval */ &ConstEval::OpLogicalOr,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -212,14 +212,15 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleInit) {
|
||||
}
|
||||
|
||||
TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInit) {
|
||||
// for(var b = true && false; ; ) {
|
||||
// let t = true;
|
||||
// for(var b = t && false; ; ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
auto* f = For(Decl(Var("b", multi_stmt)), nullptr, nullptr, Block(Return()));
|
||||
WrapInFunction(f);
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -227,7 +228,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInit) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
@@ -263,16 +264,16 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleCond) {
|
||||
}
|
||||
|
||||
TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCond) {
|
||||
// for(; true && false; ) {
|
||||
// let t = true;
|
||||
// for(; t && false; ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
Func("a_statement", {}, ty.void_(), {});
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
auto* f = For(nullptr, multi_stmt, nullptr, Block(CallStmt(Call("a_statement"))));
|
||||
WrapInFunction(f);
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -281,7 +282,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCond) {
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
while (true) {
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
@@ -316,16 +317,17 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleCont) {
|
||||
}
|
||||
|
||||
TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCont) {
|
||||
// for(; ; i = true && false) {
|
||||
// let t = true;
|
||||
// for(; ; i = t && false) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
auto* v = Decl(Var("i", ty.bool_()));
|
||||
auto* f = For(nullptr, nullptr, Assign("i", multi_stmt), //
|
||||
Block(Return()));
|
||||
WrapInFunction(v, f);
|
||||
WrapInFunction(t, v, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -335,7 +337,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCont) {
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
while (true) {
|
||||
return;
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
@@ -367,20 +369,19 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleInitCondCont) {
|
||||
}
|
||||
|
||||
TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInitCondCont) {
|
||||
// for(var i = true && false; true && false; i = true && false) {
|
||||
// let t = true;
|
||||
// for(var i = t && false; t && false; i = t && false) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt_a =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* multi_stmt_b =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* multi_stmt_c =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt_a = LogicalAnd(t, false);
|
||||
auto* multi_stmt_b = LogicalAnd(t, false);
|
||||
auto* multi_stmt_c = LogicalAnd(t, false);
|
||||
|
||||
auto* f = For(Decl(Var("i", multi_stmt_a)), multi_stmt_b, Assign("i", multi_stmt_c), //
|
||||
Block(Return()));
|
||||
WrapInFunction(f);
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -388,19 +389,19 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInitCondCont) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
bool i = (tint_tmp);
|
||||
while (true) {
|
||||
bool tint_tmp_1 = true;
|
||||
bool tint_tmp_1 = t;
|
||||
if (tint_tmp_1) {
|
||||
tint_tmp_1 = false;
|
||||
}
|
||||
if (!((tint_tmp_1))) { break; }
|
||||
return;
|
||||
bool tint_tmp_2 = true;
|
||||
bool tint_tmp_2 = t;
|
||||
if (tint_tmp_2) {
|
||||
tint_tmp_2 = false;
|
||||
}
|
||||
@@ -449,16 +450,17 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_While_WithContinue) {
|
||||
}
|
||||
|
||||
TEST_F(GlslGeneratorImplTest_Loop, Emit_WhileWithMultiStmtCond) {
|
||||
// while(true && false) {
|
||||
// let t = true;
|
||||
// while(t && false) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
Func("a_statement", {}, ty.void_(), {});
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
auto* f = While(multi_stmt, Block(CallStmt(Call("a_statement"))));
|
||||
WrapInFunction(f);
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -466,7 +468,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_WhileWithMultiStmtCond) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while (true) {
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
|
||||
@@ -211,14 +211,15 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleInit) {
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInit) {
|
||||
// for(var b = true && false; ; ) {
|
||||
// let t = true;
|
||||
// for(var b = t && false; ; ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
auto* f = For(Decl(Var("b", multi_stmt)), nullptr, nullptr, Block(Return()));
|
||||
WrapInFunction(f);
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -226,7 +227,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInit) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
@@ -260,14 +261,16 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleCond) {
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCond) {
|
||||
// for(; true && false; ) {
|
||||
// let t = true;
|
||||
// for(; t && false; ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* f = For(nullptr, multi_stmt, nullptr, Block(Return()));
|
||||
WrapInFunction(f);
|
||||
Func("a_statement", {}, ty.void_(), {});
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
auto* f = For(nullptr, multi_stmt, nullptr, Block(CallStmt(Call("a_statement"))));
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -276,12 +279,12 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCond) {
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
while (true) {
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
if (!((tint_tmp))) { break; }
|
||||
return;
|
||||
a_statement();
|
||||
}
|
||||
}
|
||||
)");
|
||||
@@ -310,15 +313,17 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleCont) {
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCont) {
|
||||
// for(; ; i = true && false) {
|
||||
// let t = true;
|
||||
// for(; ; i = t && false) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
auto* v = Decl(Var("i", ty.bool_()));
|
||||
auto* f = For(nullptr, nullptr, Assign("i", multi_stmt), Block(Return()));
|
||||
WrapInFunction(v, f);
|
||||
auto* f = For(nullptr, nullptr, Assign("i", multi_stmt), //
|
||||
Block(Return()));
|
||||
WrapInFunction(t, v, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -328,7 +333,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCont) {
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
while (true) {
|
||||
return;
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
@@ -360,20 +365,19 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleInitCondCont) {
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInitCondCont) {
|
||||
// for(var i = true && false; true && false; i = true && false) {
|
||||
// let t = true;
|
||||
// for(var i = t && false; t && false; i = t && false) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt_a =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* multi_stmt_b =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* multi_stmt_c =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt_a = LogicalAnd(t, false);
|
||||
auto* multi_stmt_b = LogicalAnd(t, false);
|
||||
auto* multi_stmt_c = LogicalAnd(t, false);
|
||||
|
||||
auto* f =
|
||||
For(Decl(Var("i", multi_stmt_a)), multi_stmt_b, Assign("i", multi_stmt_c), Block(Return()));
|
||||
WrapInFunction(f);
|
||||
auto* f = For(Decl(Var("i", multi_stmt_a)), multi_stmt_b, Assign("i", multi_stmt_c), //
|
||||
Block(Return()));
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -381,19 +385,19 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInitCondCont) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
bool i = (tint_tmp);
|
||||
while (true) {
|
||||
bool tint_tmp_1 = true;
|
||||
bool tint_tmp_1 = t;
|
||||
if (tint_tmp_1) {
|
||||
tint_tmp_1 = false;
|
||||
}
|
||||
if (!((tint_tmp_1))) { break; }
|
||||
return;
|
||||
bool tint_tmp_2 = true;
|
||||
bool tint_tmp_2 = t;
|
||||
if (tint_tmp_2) {
|
||||
tint_tmp_2 = false;
|
||||
}
|
||||
@@ -442,14 +446,17 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_While_WithContinue) {
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Loop, Emit_WhileWithMultiStmtCond) {
|
||||
// while(true && false) {
|
||||
// let t = true;
|
||||
// while(t && false) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* f = While(multi_stmt, Block(Return()));
|
||||
WrapInFunction(f);
|
||||
Func("a_statement", {}, ty.void_(), {});
|
||||
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
auto* f = While(multi_stmt, Block(CallStmt(Call("a_statement"))));
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
@@ -457,12 +464,12 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_WhileWithMultiStmtCond) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while (true) {
|
||||
bool tint_tmp = true;
|
||||
bool tint_tmp = t;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
if (!((tint_tmp))) { break; }
|
||||
return;
|
||||
a_statement();
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
@@ -419,17 +419,18 @@ TEST_F(MslGeneratorImplTest, Emit_WhileWithMultiCond) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto* multi_stmt =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* multi_stmt = LogicalAnd(t, false);
|
||||
// create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(t), Expr(false));
|
||||
auto* f = While(multi_stmt, Block(Return()));
|
||||
WrapInFunction(f);
|
||||
WrapInFunction(t, f);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while((true && false)) {
|
||||
EXPECT_EQ(gen.result(), R"( while((t && false)) {
|
||||
return;
|
||||
}
|
||||
)");
|
||||
|
||||
@@ -1071,38 +1071,43 @@ TEST_F(BuilderTest, Binary_logicalOr_Nested_LogicalAnd) {
|
||||
// a || (b && c)
|
||||
// From: crbug.com/tint/355
|
||||
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* f = Let("f", Expr(false));
|
||||
|
||||
auto* logical_and_expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(t), Expr(f));
|
||||
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr(true), logical_and_expr);
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr(t), logical_and_expr);
|
||||
|
||||
WrapInFunction(expr);
|
||||
WrapInFunction(t, f, expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(t)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(f)) << b.error();
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantTrue %2
|
||||
%8 = OpConstantNull %2
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
|
||||
%2 = OpConstantTrue %1
|
||||
%3 = OpConstantNull %1
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(%1 = OpLabel
|
||||
OpSelectionMerge %4 None
|
||||
OpBranchConditional %3 %4 %5
|
||||
%5 = OpLabel
|
||||
OpSelectionMerge %6 None
|
||||
OpBranchConditional %3 %7 %6
|
||||
%7 = OpLabel
|
||||
OpBranch %6
|
||||
R"(%4 = OpLabel
|
||||
OpSelectionMerge %5 None
|
||||
OpBranchConditional %2 %5 %6
|
||||
%6 = OpLabel
|
||||
%9 = OpPhi %2 %3 %5 %8 %7
|
||||
OpBranch %4
|
||||
%4 = OpLabel
|
||||
%10 = OpPhi %2 %3 %1 %9 %6
|
||||
OpSelectionMerge %7 None
|
||||
OpBranchConditional %2 %8 %7
|
||||
%8 = OpLabel
|
||||
OpBranch %7
|
||||
%7 = OpLabel
|
||||
%9 = OpPhi %1 %2 %6 %3 %8
|
||||
OpBranch %5
|
||||
%5 = OpLabel
|
||||
%10 = OpPhi %1 %2 %4 %9 %7
|
||||
)");
|
||||
}
|
||||
|
||||
@@ -1111,38 +1116,43 @@ TEST_F(BuilderTest, Binary_logicalAnd_Nested_LogicalOr) {
|
||||
// a && (b || c)
|
||||
// From: crbug.com/tint/355
|
||||
|
||||
auto* t = Let("t", Expr(true));
|
||||
auto* f = Let("f", Expr(false));
|
||||
|
||||
auto* logical_or_expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr(true), Expr(false));
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr(t), Expr(f));
|
||||
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(true), logical_or_expr);
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr(t), logical_or_expr);
|
||||
|
||||
WrapInFunction(expr);
|
||||
WrapInFunction(t, f, expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(t)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(f)) << b.error();
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantTrue %2
|
||||
%8 = OpConstantNull %2
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
|
||||
%2 = OpConstantTrue %1
|
||||
%3 = OpConstantNull %1
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(%1 = OpLabel
|
||||
OpSelectionMerge %4 None
|
||||
OpBranchConditional %3 %5 %4
|
||||
%5 = OpLabel
|
||||
OpSelectionMerge %6 None
|
||||
OpBranchConditional %3 %6 %7
|
||||
%7 = OpLabel
|
||||
OpBranch %6
|
||||
R"(%4 = OpLabel
|
||||
OpSelectionMerge %5 None
|
||||
OpBranchConditional %2 %6 %5
|
||||
%6 = OpLabel
|
||||
%9 = OpPhi %2 %3 %5 %8 %7
|
||||
OpBranch %4
|
||||
%4 = OpLabel
|
||||
%10 = OpPhi %2 %3 %1 %9 %6
|
||||
OpSelectionMerge %7 None
|
||||
OpBranchConditional %2 %7 %8
|
||||
%8 = OpLabel
|
||||
OpBranch %7
|
||||
%7 = OpLabel
|
||||
%9 = OpPhi %1 %2 %6 %3 %8
|
||||
OpBranch %5
|
||||
%5 = OpLabel
|
||||
%10 = OpPhi %1 %2 %4 %9 %7
|
||||
)");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user