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:
Antonio Maiorano
2022-12-07 13:29:58 +00:00
committed by Dawn LUCI CQ
parent 6198bea2ac
commit 4c8f5a1ac2
34 changed files with 255 additions and 307 deletions

View File

@@ -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) {

View File

@@ -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

View File

@@ -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),

View File

@@ -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,
},
};