Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLAddConstToVarModifiers.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 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
14
15namespace SkSL {
16
17class Expression;
18
20 const Expression* initialValue,
21 const ProgramUsage* usage) {
22 // If the variable is already marked as `const`, keep our existing modifiers.
24 if (flags.isConst()) {
25 return flags;
26 }
27 // If the variable doesn't have a compile-time-constant initial value, we can't `const` it.
28 if (!initialValue || !Analysis::IsCompileTimeConstant(*initialValue)) {
29 return flags;
30 }
31 // This only works for variables that are written-to a single time.
32 ProgramUsage::VariableCounts counts = usage->get(var);
33 if (counts.fWrite != 1) {
34 return flags;
35 }
36 // Add `const` to our variable's modifier flags, making it eligible for constant-folding.
38}
39
40} // namespace SkSL
ModifierFlags modifierFlags() const
FlutterSemanticsFlag flags
bool IsCompileTimeConstant(const Expression &expr)
ModifierFlags AddConstToVarModifiers(const Variable &var, const Expression *initialValue, const ProgramUsage *usage)
static void usage(char *argv0)