John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "src/sksl/SkSLConstantFolder.h" |
| 9 | |
| 10 | #include <limits> |
| 11 | |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 12 | #include "include/sksl/SkSLErrorReporter.h" |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 13 | #include "src/sksl/SkSLContext.h" |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 14 | #include "src/sksl/ir/SkSLBinaryExpression.h" |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 15 | #include "src/sksl/ir/SkSLConstructor.h" |
John Stiles | b0ce42d | 2021-04-09 10:39:42 -0400 | [diff] [blame] | 16 | #include "src/sksl/ir/SkSLConstructorCompound.h" |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 17 | #include "src/sksl/ir/SkSLConstructorSplat.h" |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 18 | #include "src/sksl/ir/SkSLExpression.h" |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 19 | #include "src/sksl/ir/SkSLLiteral.h" |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 20 | #include "src/sksl/ir/SkSLPrefixExpression.h" |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 21 | #include "src/sksl/ir/SkSLType.h" |
| 22 | #include "src/sksl/ir/SkSLVariable.h" |
| 23 | #include "src/sksl/ir/SkSLVariableReference.h" |
| 24 | |
| 25 | namespace SkSL { |
| 26 | |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 27 | static std::unique_ptr<Expression> eliminate_no_op_boolean(const Expression& left, |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 28 | Operator op, |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 29 | const Expression& right) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 30 | bool rightVal = right.as<Literal>().boolValue(); |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 31 | |
| 32 | // Detect no-op Boolean expressions and optimize them away. |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 33 | if ((op.kind() == Token::Kind::TK_LOGICALAND && rightVal) || // (expr && true) -> (expr) |
| 34 | (op.kind() == Token::Kind::TK_LOGICALOR && !rightVal) || // (expr || false) -> (expr) |
| 35 | (op.kind() == Token::Kind::TK_LOGICALXOR && !rightVal) || // (expr ^^ false) -> (expr) |
| 36 | (op.kind() == Token::Kind::TK_EQEQ && rightVal) || // (expr == true) -> (expr) |
| 37 | (op.kind() == Token::Kind::TK_NEQ && !rightVal)) { // (expr != false) -> (expr) |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 38 | |
| 39 | return left.clone(); |
| 40 | } |
| 41 | |
| 42 | return nullptr; |
| 43 | } |
| 44 | |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 45 | static std::unique_ptr<Expression> short_circuit_boolean(const Expression& left, |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 46 | Operator op, |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 47 | const Expression& right) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 48 | bool leftVal = left.as<Literal>().boolValue(); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 49 | |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 50 | // When the literal is on the left, we can sometimes eliminate the other expression entirely. |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 51 | if ((op.kind() == Token::Kind::TK_LOGICALAND && !leftVal) || // (false && expr) -> (false) |
| 52 | (op.kind() == Token::Kind::TK_LOGICALOR && leftVal)) { // (true || expr) -> (true) |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 53 | |
| 54 | return left.clone(); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 55 | } |
| 56 | |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 57 | // We can't eliminate the right-side expression via short-circuit, but we might still be able to |
| 58 | // simplify away a no-op expression. |
| 59 | return eliminate_no_op_boolean(right, op, left); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 60 | } |
| 61 | |
John Stiles | 878d8fb | 2021-08-24 11:33:27 -0400 | [diff] [blame] | 62 | static std::unique_ptr<Expression> simplify_vector_equality(const Context& context, |
| 63 | const Expression& left, |
| 64 | Operator op, |
| 65 | const Expression& right) { |
| 66 | if (op.kind() == Token::Kind::TK_EQEQ || op.kind() == Token::Kind::TK_NEQ) { |
| 67 | bool equality = (op.kind() == Token::Kind::TK_EQEQ); |
| 68 | |
| 69 | switch (left.compareConstant(right)) { |
| 70 | case Expression::ComparisonResult::kNotEqual: |
| 71 | equality = !equality; |
| 72 | [[fallthrough]]; |
| 73 | |
| 74 | case Expression::ComparisonResult::kEqual: |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 75 | return Literal::MakeBool(context, left.fOffset, equality); |
John Stiles | 878d8fb | 2021-08-24 11:33:27 -0400 | [diff] [blame] | 76 | |
| 77 | case Expression::ComparisonResult::kUnknown: |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | return nullptr; |
| 82 | } |
| 83 | |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 84 | static std::unique_ptr<Expression> simplify_vector(const Context& context, |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 85 | const Expression& left, |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 86 | Operator op, |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 87 | const Expression& right) { |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 88 | SkASSERT(left.type().isVector()); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 89 | SkASSERT(left.type() == right.type()); |
| 90 | const Type& type = left.type(); |
| 91 | |
John Stiles | 878d8fb | 2021-08-24 11:33:27 -0400 | [diff] [blame] | 92 | // Handle equality operations: == != |
| 93 | if (std::unique_ptr<Expression> result = simplify_vector_equality(context, left, op, right)) { |
| 94 | return result; |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | // Handle floating-point arithmetic: + - * / |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 98 | using FoldFn = double (*)(double, double); |
| 99 | FoldFn foldFn; |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 100 | switch (op.kind()) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 101 | case Token::Kind::TK_PLUS: foldFn = +[](double a, double b) { return a + b; }; break; |
| 102 | case Token::Kind::TK_MINUS: foldFn = +[](double a, double b) { return a - b; }; break; |
| 103 | case Token::Kind::TK_STAR: foldFn = +[](double a, double b) { return a * b; }; break; |
| 104 | case Token::Kind::TK_SLASH: foldFn = +[](double a, double b) { return a / b; }; break; |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 105 | default: |
| 106 | return nullptr; |
| 107 | } |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 108 | |
| 109 | const Type& componentType = type.componentType(); |
| 110 | ExpressionArray args; |
| 111 | args.reserve_back(type.columns()); |
| 112 | for (int i = 0; i < type.columns(); i++) { |
| 113 | double value = foldFn(left.getConstantSubexpression(i)->as<Literal>().value(), |
| 114 | right.getConstantSubexpression(i)->as<Literal>().value()); |
| 115 | args.push_back(Literal::Make(left.fOffset, value, &componentType)); |
| 116 | } |
| 117 | return ConstructorCompound::Make(context, left.fOffset, type, std::move(args)); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 118 | } |
| 119 | |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 120 | static std::unique_ptr<Expression> cast_expression(const Context& context, |
| 121 | const Expression& expr, |
| 122 | const Type& type) { |
| 123 | ExpressionArray ctorArgs; |
| 124 | ctorArgs.push_back(expr.clone()); |
| 125 | std::unique_ptr<Expression> ctor = Constructor::Convert(context, expr.fOffset, type, |
| 126 | std::move(ctorArgs)); |
| 127 | SkASSERT(ctor); |
| 128 | return ctor; |
| 129 | } |
| 130 | |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 131 | static ConstructorSplat splat_scalar(const Expression& scalar, const Type& type) { |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 132 | SkASSERT(type.isVector()); |
| 133 | SkASSERT(type.componentType() == scalar.type()); |
| 134 | |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 135 | // Use a constructor to splat the scalar expression across a vector. |
| 136 | return ConstructorSplat{scalar.fOffset, type, scalar.clone()}; |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 137 | } |
| 138 | |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 139 | bool ConstantFolder::GetConstantInt(const Expression& value, SKSL_INT* out) { |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 140 | const Expression* expr = GetConstantValueForVariable(value); |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 141 | if (!expr->isIntLiteral()) { |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 142 | return false; |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 143 | } |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 144 | *out = expr->as<Literal>().intValue(); |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 145 | return true; |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 146 | } |
| 147 | |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 148 | static bool is_constant_scalar_value(const Expression& inExpr, double match) { |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 149 | const Expression* expr = ConstantFolder::GetConstantValueForVariable(inExpr); |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 150 | return (expr->is<Literal>() && expr->as<Literal>().value() == match); |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 153 | static bool contains_constant_zero(const Expression& expr) { |
John Stiles | 55dc5c8 | 2021-08-19 18:15:49 -0400 | [diff] [blame] | 154 | int numSlots = expr.type().slotCount(); |
| 155 | for (int index = 0; index < numSlots; ++index) { |
| 156 | const Expression* subexpr = expr.getConstantSubexpression(index); |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 157 | if (subexpr && is_constant_scalar_value(*subexpr, 0.0)) { |
John Stiles | 55dc5c8 | 2021-08-19 18:15:49 -0400 | [diff] [blame] | 158 | return true; |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 159 | } |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 160 | } |
John Stiles | 55dc5c8 | 2021-08-19 18:15:49 -0400 | [diff] [blame] | 161 | return false; |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 162 | } |
| 163 | |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 164 | static bool is_constant_value(const Expression& expr, double value) { |
John Stiles | 55dc5c8 | 2021-08-19 18:15:49 -0400 | [diff] [blame] | 165 | int numSlots = expr.type().slotCount(); |
| 166 | for (int index = 0; index < numSlots; ++index) { |
| 167 | const Expression* subexpr = expr.getConstantSubexpression(index); |
| 168 | if (!subexpr || !is_constant_scalar_value(*subexpr, value)) { |
| 169 | return false; |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 170 | } |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 171 | } |
John Stiles | 55dc5c8 | 2021-08-19 18:15:49 -0400 | [diff] [blame] | 172 | return true; |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 173 | } |
| 174 | |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 175 | bool ConstantFolder::ErrorOnDivideByZero(const Context& context, int offset, Operator op, |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 176 | const Expression& right) { |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 177 | switch (op.kind()) { |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 178 | case Token::Kind::TK_SLASH: |
| 179 | case Token::Kind::TK_SLASHEQ: |
| 180 | case Token::Kind::TK_PERCENT: |
| 181 | case Token::Kind::TK_PERCENTEQ: |
| 182 | if (contains_constant_zero(right)) { |
Ethan Nicholas | 39f6da4 | 2021-08-23 13:10:07 -0400 | [diff] [blame] | 183 | context.fErrors->error(offset, "division by zero"); |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 184 | return true; |
| 185 | } |
| 186 | return false; |
| 187 | default: |
| 188 | return false; |
| 189 | } |
| 190 | } |
| 191 | |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 192 | const Expression* ConstantFolder::GetConstantValueForVariable(const Expression& inExpr) { |
| 193 | for (const Expression* expr = &inExpr;;) { |
| 194 | if (!expr->is<VariableReference>()) { |
| 195 | break; |
| 196 | } |
| 197 | const VariableReference& varRef = expr->as<VariableReference>(); |
| 198 | if (varRef.refKind() != VariableRefKind::kRead) { |
| 199 | break; |
| 200 | } |
| 201 | const Variable& var = *varRef.variable(); |
| 202 | if (!(var.modifiers().fFlags & Modifiers::kConst_Flag)) { |
| 203 | break; |
| 204 | } |
| 205 | expr = var.initialValue(); |
John Stiles | ca65f8f | 2021-03-29 17:14:39 -0400 | [diff] [blame] | 206 | if (!expr) { |
John Stiles | 3f37322 | 2021-08-23 13:52:17 -0400 | [diff] [blame] | 207 | // Function parameters can be const but won't have an initial value. |
John Stiles | ca65f8f | 2021-03-29 17:14:39 -0400 | [diff] [blame] | 208 | break; |
| 209 | } |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 210 | if (expr->isCompileTimeConstant()) { |
| 211 | return expr; |
| 212 | } |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 213 | } |
| 214 | // We didn't find a compile-time constant at the end. Return the expression as-is. |
| 215 | return &inExpr; |
| 216 | } |
| 217 | |
John Stiles | ffba524 | 2021-05-07 10:50:22 -0400 | [diff] [blame] | 218 | std::unique_ptr<Expression> ConstantFolder::MakeConstantValueForVariable( |
| 219 | std::unique_ptr<Expression> expr) { |
| 220 | const Expression* constantExpr = GetConstantValueForVariable(*expr); |
| 221 | if (constantExpr != expr.get()) { |
| 222 | expr = constantExpr->clone(); |
| 223 | } |
| 224 | return expr; |
| 225 | } |
| 226 | |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 227 | static std::unique_ptr<Expression> simplify_no_op_arithmetic(const Context& context, |
| 228 | const Expression& left, |
| 229 | Operator op, |
| 230 | const Expression& right, |
| 231 | const Type& resultType) { |
| 232 | switch (op.kind()) { |
| 233 | case Token::Kind::TK_PLUS: |
| 234 | if (is_constant_value(right, 0.0)) { // x + 0 |
| 235 | return cast_expression(context, left, resultType); |
| 236 | } |
| 237 | if (is_constant_value(left, 0.0)) { // 0 + x |
| 238 | return cast_expression(context, right, resultType); |
| 239 | } |
| 240 | break; |
| 241 | |
| 242 | case Token::Kind::TK_STAR: |
| 243 | if (is_constant_value(right, 1.0)) { // x * 1 |
| 244 | return cast_expression(context, left, resultType); |
| 245 | } |
| 246 | if (is_constant_value(left, 1.0)) { // 1 * x |
| 247 | return cast_expression(context, right, resultType); |
| 248 | } |
| 249 | if (is_constant_value(right, 0.0) && !left.hasSideEffects()) { // x * 0 |
| 250 | return cast_expression(context, right, resultType); |
| 251 | } |
| 252 | if (is_constant_value(left, 0.0) && !right.hasSideEffects()) { // 0 * x |
| 253 | return cast_expression(context, left, resultType); |
| 254 | } |
| 255 | break; |
| 256 | |
| 257 | case Token::Kind::TK_MINUS: |
| 258 | if (is_constant_value(right, 0.0)) { // x - 0 |
| 259 | return cast_expression(context, left, resultType); |
| 260 | } |
| 261 | if (is_constant_value(left, 0.0)) { // 0 - x (to `-x`) |
| 262 | return PrefixExpression::Make(context, Token::Kind::TK_MINUS, |
| 263 | cast_expression(context, right, resultType)); |
| 264 | } |
| 265 | break; |
| 266 | |
| 267 | case Token::Kind::TK_SLASH: |
| 268 | if (is_constant_value(right, 1.0)) { // x / 1 |
| 269 | return cast_expression(context, left, resultType); |
| 270 | } |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 271 | break; |
| 272 | |
| 273 | case Token::Kind::TK_PLUSEQ: |
| 274 | case Token::Kind::TK_MINUSEQ: |
| 275 | if (is_constant_value(right, 0.0)) { // x += 0, x -= 0 |
| 276 | std::unique_ptr<Expression> result = cast_expression(context, left, resultType); |
John Stiles | bb8cf58 | 2021-08-26 23:34:59 -0400 | [diff] [blame] | 277 | Analysis::UpdateVariableRefKind(result.get(), VariableRefKind::kRead); |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 278 | return result; |
| 279 | } |
| 280 | break; |
| 281 | |
| 282 | case Token::Kind::TK_STAREQ: |
| 283 | case Token::Kind::TK_SLASHEQ: |
| 284 | if (is_constant_value(right, 1.0)) { // x *= 1, x /= 1 |
| 285 | std::unique_ptr<Expression> result = cast_expression(context, left, resultType); |
John Stiles | bb8cf58 | 2021-08-26 23:34:59 -0400 | [diff] [blame] | 286 | Analysis::UpdateVariableRefKind(result.get(), VariableRefKind::kRead); |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 287 | return result; |
| 288 | } |
| 289 | break; |
| 290 | |
| 291 | default: |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | return nullptr; |
| 296 | } |
| 297 | |
John Stiles | afaddc9 | 2021-05-26 22:21:42 -0400 | [diff] [blame] | 298 | template <typename T> |
| 299 | static std::unique_ptr<Expression> fold_float_expression(int offset, |
| 300 | T result, |
| 301 | const Type* resultType) { |
| 302 | // If constant-folding this expression would generate a NaN/infinite result, leave it as-is. |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 303 | if constexpr (!std::is_same<T, bool>::value) { |
John Stiles | afaddc9 | 2021-05-26 22:21:42 -0400 | [diff] [blame] | 304 | if (!std::isfinite(result)) { |
| 305 | return nullptr; |
| 306 | } |
| 307 | } |
| 308 | |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 309 | return Literal::Make(offset, result, resultType); |
John Stiles | afaddc9 | 2021-05-26 22:21:42 -0400 | [diff] [blame] | 310 | } |
| 311 | |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 312 | template <typename T> |
| 313 | static std::unique_ptr<Expression> fold_int_expression(int offset, |
| 314 | T result, |
| 315 | const Type* resultType) { |
| 316 | // If constant-folding this expression would overflow the result type, leave it as-is. |
| 317 | if constexpr (!std::is_same<T, bool>::value) { |
| 318 | if (result < resultType->minimumValue() || result > resultType->maximumValue()) { |
| 319 | return nullptr; |
| 320 | } |
| 321 | } |
| 322 | |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 323 | return Literal::Make(offset, result, resultType); |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 324 | } |
| 325 | |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 326 | std::unique_ptr<Expression> ConstantFolder::Simplify(const Context& context, |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 327 | int offset, |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 328 | const Expression& leftExpr, |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 329 | Operator op, |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 330 | const Expression& rightExpr, |
| 331 | const Type& resultType) { |
John Stiles | be6cbf3 | 2021-03-09 20:15:17 -0500 | [diff] [blame] | 332 | // When optimization is enabled, replace constant variables with trivial initial-values. |
| 333 | const Expression* left; |
| 334 | const Expression* right; |
| 335 | if (context.fConfig->fSettings.fOptimize) { |
| 336 | left = GetConstantValueForVariable(leftExpr); |
| 337 | right = GetConstantValueForVariable(rightExpr); |
| 338 | } else { |
| 339 | left = &leftExpr; |
| 340 | right = &rightExpr; |
| 341 | } |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 342 | |
John Stiles | abc3b78 | 2021-02-05 10:07:19 -0500 | [diff] [blame] | 343 | // If this is the comma operator, the left side is evaluated but not otherwise used in any way. |
| 344 | // So if the left side has no side effects, it can just be eliminated entirely. |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 345 | if (op.kind() == Token::Kind::TK_COMMA && !left->hasSideEffects()) { |
| 346 | return right->clone(); |
John Stiles | abc3b78 | 2021-02-05 10:07:19 -0500 | [diff] [blame] | 347 | } |
| 348 | |
John Stiles | 95d0bad | 2021-03-01 17:02:28 -0500 | [diff] [blame] | 349 | // If this is the assignment operator, and both sides are the same trivial expression, this is |
| 350 | // self-assignment (i.e., `var = var`) and can be reduced to just a variable reference (`var`). |
| 351 | // This can happen when other parts of the assignment are optimized away. |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 352 | if (op.kind() == Token::Kind::TK_EQ && Analysis::IsSameExpressionTree(*left, *right)) { |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 353 | return right->clone(); |
John Stiles | 95d0bad | 2021-03-01 17:02:28 -0500 | [diff] [blame] | 354 | } |
| 355 | |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 356 | // Simplify the expression when both sides are constant Boolean literals. |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 357 | if (left->isBoolLiteral() && right->isBoolLiteral()) { |
| 358 | bool leftVal = left->as<Literal>().boolValue(); |
| 359 | bool rightVal = right->as<Literal>().boolValue(); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 360 | bool result; |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 361 | switch (op.kind()) { |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 362 | case Token::Kind::TK_LOGICALAND: result = leftVal && rightVal; break; |
| 363 | case Token::Kind::TK_LOGICALOR: result = leftVal || rightVal; break; |
| 364 | case Token::Kind::TK_LOGICALXOR: result = leftVal ^ rightVal; break; |
John Stiles | 26fdcbb | 2021-01-19 19:00:31 -0500 | [diff] [blame] | 365 | case Token::Kind::TK_EQEQ: result = leftVal == rightVal; break; |
| 366 | case Token::Kind::TK_NEQ: result = leftVal != rightVal; break; |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 367 | default: return nullptr; |
| 368 | } |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 369 | return Literal::MakeBool(context, offset, result); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 370 | } |
| 371 | |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 372 | // If the left side is a Boolean literal, apply short-circuit optimizations. |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 373 | if (left->isBoolLiteral()) { |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 374 | return short_circuit_boolean(*left, op, *right); |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | // If the right side is a Boolean literal... |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 378 | if (right->isBoolLiteral()) { |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 379 | // ... and the left side has no side effects... |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 380 | if (!left->hasSideEffects()) { |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 381 | // We can reverse the expressions and short-circuit optimizations are still valid. |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 382 | return short_circuit_boolean(*right, op, *left); |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | // We can't use short-circuiting, but we can still optimize away no-op Boolean expressions. |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 386 | return eliminate_no_op_boolean(*left, op, *right); |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 387 | } |
| 388 | |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 389 | if (op.kind() == Token::Kind::TK_EQEQ && Analysis::IsSameExpressionTree(*left, *right)) { |
| 390 | // With == comparison, if both sides are the same trivial expression, this is self- |
| 391 | // comparison and is always true. (We are not concerned with NaN.) |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 392 | return Literal::MakeBool(context, leftExpr.fOffset, /*value=*/true); |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | if (op.kind() == Token::Kind::TK_NEQ && Analysis::IsSameExpressionTree(*left, *right)) { |
| 396 | // With != comparison, if both sides are the same trivial expression, this is self- |
| 397 | // comparison and is always false. (We are not concerned with NaN.) |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 398 | return Literal::MakeBool(context, leftExpr.fOffset, /*value=*/false); |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 399 | } |
| 400 | |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 401 | if (ErrorOnDivideByZero(context, offset, op, *right)) { |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 402 | return nullptr; |
| 403 | } |
| 404 | |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 405 | // Optimize away no-op arithmetic like `x * 1`, `x *= 1`, `x + 0`, `x * 0`, `0 / x`, etc. |
| 406 | const Type& leftType = left->type(); |
| 407 | const Type& rightType = right->type(); |
| 408 | if ((leftType.isScalar() || leftType.isVector()) && |
| 409 | (rightType.isScalar() || rightType.isVector())) { |
| 410 | std::unique_ptr<Expression> expr = simplify_no_op_arithmetic(context, *left, op, *right, |
| 411 | resultType); |
| 412 | if (expr) { |
| 413 | return expr; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | // Other than the cases above, constant folding requires both sides to be constant. |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 418 | if (!left->isCompileTimeConstant() || !right->isCompileTimeConstant()) { |
John Stiles | 8a9da73 | 2021-01-20 14:32:33 -0500 | [diff] [blame] | 419 | return nullptr; |
| 420 | } |
| 421 | |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 422 | // Note that we expressly do not worry about precision and overflow here -- we use the maximum |
| 423 | // precision to calculate the results and hope the result makes sense. |
John Stiles | 9ce80f7 | 2021-03-11 22:35:19 -0500 | [diff] [blame] | 424 | // TODO(skia:10932): detect and handle integer overflow properly. |
Brian Osman | 21d2b6a | 2021-02-01 13:48:50 -0500 | [diff] [blame] | 425 | using SKSL_UINT = uint64_t; |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 426 | if (left->isIntLiteral() && right->isIntLiteral()) { |
| 427 | SKSL_INT leftVal = left->as<Literal>().intValue(); |
| 428 | SKSL_INT rightVal = right->as<Literal>().intValue(); |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 429 | |
| 430 | #define RESULT(Op) fold_int_expression(offset, \ |
| 431 | (SKSL_INT)(leftVal) Op (SKSL_INT)(rightVal), &resultType) |
| 432 | #define URESULT(Op) fold_int_expression(offset, \ |
| 433 | (SKSL_INT)((SKSL_UINT)(leftVal) Op (SKSL_UINT)(rightVal)), &resultType) |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 434 | switch (op.kind()) { |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 435 | case Token::Kind::TK_PLUS: return URESULT(+); |
| 436 | case Token::Kind::TK_MINUS: return URESULT(-); |
| 437 | case Token::Kind::TK_STAR: return URESULT(*); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 438 | case Token::Kind::TK_SLASH: |
| 439 | if (leftVal == std::numeric_limits<SKSL_INT>::min() && rightVal == -1) { |
Ethan Nicholas | 39f6da4 | 2021-08-23 13:10:07 -0400 | [diff] [blame] | 440 | context.fErrors->error(offset, "arithmetic overflow"); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 441 | return nullptr; |
| 442 | } |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 443 | return RESULT(/); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 444 | case Token::Kind::TK_PERCENT: |
| 445 | if (leftVal == std::numeric_limits<SKSL_INT>::min() && rightVal == -1) { |
Ethan Nicholas | 39f6da4 | 2021-08-23 13:10:07 -0400 | [diff] [blame] | 446 | context.fErrors->error(offset, "arithmetic overflow"); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 447 | return nullptr; |
| 448 | } |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 449 | return RESULT(%); |
| 450 | case Token::Kind::TK_BITWISEAND: return RESULT(&); |
| 451 | case Token::Kind::TK_BITWISEOR: return RESULT(|); |
| 452 | case Token::Kind::TK_BITWISEXOR: return RESULT(^); |
| 453 | case Token::Kind::TK_EQEQ: return RESULT(==); |
| 454 | case Token::Kind::TK_NEQ: return RESULT(!=); |
| 455 | case Token::Kind::TK_GT: return RESULT(>); |
| 456 | case Token::Kind::TK_GTEQ: return RESULT(>=); |
| 457 | case Token::Kind::TK_LT: return RESULT(<); |
| 458 | case Token::Kind::TK_LTEQ: return RESULT(<=); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 459 | case Token::Kind::TK_SHL: |
| 460 | if (rightVal >= 0 && rightVal <= 31) { |
Brian Osman | a7eb681 | 2021-02-01 11:43:05 -0500 | [diff] [blame] | 461 | // Left-shifting a negative (or really, any signed) value is undefined behavior |
| 462 | // in C++, but not GLSL. Do the shift on unsigned values, to avoid UBSAN. |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 463 | return URESULT(<<); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 464 | } |
Ethan Nicholas | 39f6da4 | 2021-08-23 13:10:07 -0400 | [diff] [blame] | 465 | context.fErrors->error(offset, "shift value out of range"); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 466 | return nullptr; |
| 467 | case Token::Kind::TK_SHR: |
| 468 | if (rightVal >= 0 && rightVal <= 31) { |
John Stiles | 3598129 | 2021-05-27 12:26:37 -0400 | [diff] [blame] | 469 | return RESULT(>>); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 470 | } |
Ethan Nicholas | 39f6da4 | 2021-08-23 13:10:07 -0400 | [diff] [blame] | 471 | context.fErrors->error(offset, "shift value out of range"); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 472 | return nullptr; |
| 473 | |
| 474 | default: |
| 475 | return nullptr; |
| 476 | } |
John Stiles | afaddc9 | 2021-05-26 22:21:42 -0400 | [diff] [blame] | 477 | #undef RESULT |
| 478 | #undef URESULT |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | // Perform constant folding on pairs of floating-point literals. |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 482 | if (left->isFloatLiteral() && right->isFloatLiteral()) { |
| 483 | SKSL_FLOAT leftVal = left->as<Literal>().floatValue(); |
| 484 | SKSL_FLOAT rightVal = right->as<Literal>().floatValue(); |
John Stiles | afaddc9 | 2021-05-26 22:21:42 -0400 | [diff] [blame] | 485 | |
| 486 | #define RESULT(Op) fold_float_expression(offset, leftVal Op rightVal, &resultType) |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 487 | switch (op.kind()) { |
John Stiles | afaddc9 | 2021-05-26 22:21:42 -0400 | [diff] [blame] | 488 | case Token::Kind::TK_PLUS: return RESULT(+); |
| 489 | case Token::Kind::TK_MINUS: return RESULT(-); |
| 490 | case Token::Kind::TK_STAR: return RESULT(*); |
| 491 | case Token::Kind::TK_SLASH: return RESULT(/); |
| 492 | case Token::Kind::TK_EQEQ: return RESULT(==); |
| 493 | case Token::Kind::TK_NEQ: return RESULT(!=); |
| 494 | case Token::Kind::TK_GT: return RESULT(>); |
| 495 | case Token::Kind::TK_GTEQ: return RESULT(>=); |
| 496 | case Token::Kind::TK_LT: return RESULT(<); |
| 497 | case Token::Kind::TK_LTEQ: return RESULT(<=); |
| 498 | default: return nullptr; |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 499 | } |
John Stiles | afaddc9 | 2021-05-26 22:21:42 -0400 | [diff] [blame] | 500 | #undef RESULT |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | // Perform constant folding on pairs of vectors. |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 504 | if (leftType.isVector() && leftType == rightType) { |
| 505 | if (leftType.componentType().isFloat()) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 506 | return simplify_vector(context, *left, op, *right); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 507 | } |
| 508 | if (leftType.componentType().isInteger()) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 509 | return simplify_vector(context, *left, op, *right); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 510 | } |
John Stiles | 878d8fb | 2021-08-24 11:33:27 -0400 | [diff] [blame] | 511 | if (leftType.componentType().isBoolean()) { |
| 512 | return simplify_vector_equality(context, *left, op, *right); |
| 513 | } |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 514 | return nullptr; |
| 515 | } |
| 516 | |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 517 | // Perform constant folding on vectors against scalars, e.g.: half4(2) + 2 |
| 518 | if (leftType.isVector() && leftType.componentType() == rightType) { |
| 519 | if (rightType.isFloat()) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 520 | return simplify_vector(context, *left, op, splat_scalar(*right, left->type())); |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 521 | } |
| 522 | if (rightType.isInteger()) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 523 | return simplify_vector(context, *left, op, splat_scalar(*right, left->type())); |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 524 | } |
John Stiles | 878d8fb | 2021-08-24 11:33:27 -0400 | [diff] [blame] | 525 | if (rightType.isBoolean()) { |
| 526 | return simplify_vector_equality(context, *left, op, |
| 527 | splat_scalar(*right, left->type())); |
| 528 | } |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 529 | return nullptr; |
| 530 | } |
| 531 | |
| 532 | // Perform constant folding on scalars against vectors, e.g.: 2 + half4(2) |
| 533 | if (rightType.isVector() && rightType.componentType() == leftType) { |
| 534 | if (leftType.isFloat()) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 535 | return simplify_vector(context, splat_scalar(*left, right->type()), op, *right); |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 536 | } |
| 537 | if (leftType.isInteger()) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 538 | return simplify_vector(context, splat_scalar(*left, right->type()), op, *right); |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 539 | } |
John Stiles | 878d8fb | 2021-08-24 11:33:27 -0400 | [diff] [blame] | 540 | if (leftType.isBoolean()) { |
| 541 | return simplify_vector_equality(context, splat_scalar(*left, right->type()), |
| 542 | op, *right); |
| 543 | } |
John Stiles | 508eba7 | 2021-01-11 13:07:47 -0500 | [diff] [blame] | 544 | return nullptr; |
| 545 | } |
| 546 | |
John Stiles | 22a5454 | 2021-03-31 11:33:48 -0400 | [diff] [blame] | 547 | // Perform constant folding on pairs of matrices or arrays. |
| 548 | if ((leftType.isMatrix() && rightType.isMatrix()) || |
| 549 | (leftType.isArray() && rightType.isArray())) { |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 550 | bool equality; |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 551 | switch (op.kind()) { |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 552 | case Token::Kind::TK_EQEQ: |
| 553 | equality = true; |
| 554 | break; |
| 555 | case Token::Kind::TK_NEQ: |
| 556 | equality = false; |
| 557 | break; |
| 558 | default: |
| 559 | return nullptr; |
| 560 | } |
| 561 | |
John Stiles | e80e169 | 2021-03-02 17:02:25 -0500 | [diff] [blame] | 562 | switch (left->compareConstant(*right)) { |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 563 | case Expression::ComparisonResult::kNotEqual: |
| 564 | equality = !equality; |
| 565 | [[fallthrough]]; |
| 566 | |
| 567 | case Expression::ComparisonResult::kEqual: |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame^] | 568 | return Literal::MakeBool(context, offset, equality); |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 569 | |
| 570 | case Expression::ComparisonResult::kUnknown: |
| 571 | return nullptr; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | // We aren't able to constant-fold. |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 576 | return nullptr; |
| 577 | } |
| 578 | |
| 579 | } // namespace SkSL |