From 6bf6963198aa977146449467b3d363b6da8ee169 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Fri, 8 Jan 2021 14:10:22 -0500 Subject: [PATCH] Remove context argument from short_circuit_boolean. Now that BoolLiterals can be constructed with a Type*, there's no need to pass the context through. Change-Id: Ic2003aa03f5c2428e73e81c95eb12c862700554a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/352025 Auto-Submit: John Stiles Reviewed-by: Brian Osman Commit-Queue: John Stiles --- src/sksl/SkSLIRGenerator.cpp | 37 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 2c5db5e8df..13f024da40 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -1771,29 +1771,30 @@ static bool determine_binary_type(const Context& context, return false; } -static std::unique_ptr short_circuit_boolean(const Context& context, - const Expression& left, +static std::unique_ptr short_circuit_boolean(const Expression& left, Token::Kind op, const Expression& right) { - SkASSERT(left.kind() == Expression::Kind::kBoolLiteral); + SkASSERT(left.is()); bool leftVal = left.as().value(); + if (op == Token::Kind::TK_LOGICALAND) { // (true && expr) -> (expr) and (false && expr) -> (false) return leftVal ? right.clone() - : std::unique_ptr(new BoolLiteral(context, left.fOffset, false)); - } else if (op == Token::Kind::TK_LOGICALOR) { - // (true || expr) -> (true) and (false || expr) -> (expr) - return leftVal ? std::unique_ptr(new BoolLiteral(context, left.fOffset, true)) - : right.clone(); - } else if (op == Token::Kind::TK_LOGICALXOR) { - // (true ^^ expr) -> !(expr) and (false ^^ expr) -> (expr) - return leftVal ? std::unique_ptr(new PrefixExpression( - Token::Kind::TK_LOGICALNOT, - right.clone())) - : right.clone(); - } else { - return nullptr; + : std::make_unique(left.fOffset, /*value=*/false, &left.type()); } + if (op == Token::Kind::TK_LOGICALOR) { + // (true || expr) -> (true) and (false || expr) -> (expr) + return leftVal ? std::make_unique(left.fOffset, /*value=*/true, &left.type()) + : right.clone(); + } + if (op == Token::Kind::TK_LOGICALXOR) { + // (true ^^ expr) -> !(expr) and (false ^^ expr) -> (expr) + return leftVal ? std::make_unique(Token::Kind::TK_LOGICALNOT, + right.clone()) + : right.clone(); + } + + return nullptr; } template @@ -1861,11 +1862,11 @@ std::unique_ptr IRGenerator::constantFold(const Expression& left, // If the left side is a constant boolean literal, the right side does not need to be constant // for short circuit optimizations to allow the constant to be folded. if (left.is() && !right.isCompileTimeConstant()) { - return short_circuit_boolean(fContext, left, op, right); + return short_circuit_boolean(left, op, right); } else if (right.is() && !left.isCompileTimeConstant()) { // There aren't side effects in SkSL within expressions, so (left OP right) is equivalent to // (right OP left) for short-circuit optimizations - return short_circuit_boolean(fContext, right, op, left); + return short_circuit_boolean(right, op, left); } // Other than the short-circuit cases above, constant folding requires both sides to be constant