forked from google/skia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
const
modifier to variables during inlineStatement.
During the inlining pass, we know the ProgramUsage for every variable. When the inliner is about to emit a var-declaration like `float PI = 3.14;`, we can check the ProgramUsage to see if we ever assign to PI elsewhere in the code. If we don't, we can emit `const float PI = 3.14;` instead. This small change gives the constant folder many, many more opportunities to do its job. (See the attached bug for more information.) Change-Id: I2481bd7fbcf360a56b746800d29816c2ba7f2e5b Bug: skia:13544 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/559401 Reviewed-by: Brian Osman <[email protected]> Auto-Submit: John Stiles <[email protected]> Commit-Queue: John Stiles <[email protected]>
- Loading branch information
1 parent
80723ae
commit 78b7d53
Showing
27 changed files
with
312 additions
and
542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#include "include/private/SkSLModifiers.h" | ||
#include "src/sksl/SkSLContext.h" | ||
#include "src/sksl/SkSLModifiersPool.h" | ||
#include "src/sksl/ir/SkSLExpression.h" | ||
#include "src/sksl/ir/SkSLProgram.h" | ||
#include "src/sksl/ir/SkSLVariable.h" | ||
#include "src/sksl/transform/SkSLTransform.h" | ||
|
||
namespace SkSL { | ||
|
||
const Modifiers* Transform::AddConstToVarModifiers(const Context& context, | ||
const Variable& var, | ||
const Expression* initialValue, | ||
const ProgramUsage* usage) { | ||
// If the variable is already marked as `const`, keep our existing modifiers. | ||
const Modifiers* modifiers = &var.modifiers(); | ||
if (modifiers->fFlags & Modifiers::kConst_Flag) { | ||
return modifiers; | ||
} | ||
// If the variable doesn't have a compile-time-constant initial value, we can't `const` it. | ||
if (!initialValue || !initialValue->isCompileTimeConstant()) { | ||
return modifiers; | ||
} | ||
// This only works for variables that are written-to a single time. | ||
ProgramUsage::VariableCounts counts = usage->get(var); | ||
if (counts.fWrite != 1) { | ||
return modifiers; | ||
} | ||
// Add `const` to our variable's modifiers, making it eligible for constant-folding. | ||
Modifiers constModifiers = *modifiers; | ||
constModifiers.fFlags |= Modifiers::kConst_Flag; | ||
return context.fModifiersPool->add(constModifiers); | ||
} | ||
|
||
} // namespace SkSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
|
||
out vec4 sk_FragColor; | ||
vec4 main() { | ||
vec2 _1_reusedName = vec2(1.0, 2.0); | ||
vec2 _2_reusedName = _1_reusedName - 1.0; | ||
const vec2 _2_reusedName = vec2(0.0, 1.0); | ||
return _2_reusedName.xyxy; | ||
} |
Oops, something went wrong.