Improve comments for Analysis::IsSelfAssignment.

Change-Id: I34353769f4c65bdfa7205d460671a78f3463a5f2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/378317
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2021-03-02 09:57:28 -05:00 committed by Skia Commit-Bot
parent 036ba86489
commit 786d42c6da
2 changed files with 5 additions and 7 deletions

View File

@ -562,16 +562,15 @@ bool Analysis::IsTrivialExpression(const Expression& expr) {
IsTrivialExpression(*expr.as<IndexExpression>().base()));
}
/**
* Returns true if both expression trees are the same. The left side is expected to be an lvalue.
* This only needs to check for trees that can plausibly terminate in a variable, so some basic
* candidates like `FloatLiteral` are missing.
*/
bool Analysis::IsSelfAssignment(const Expression& left, const Expression& right) {
if (left.kind() != right.kind() || left.type() != right.type()) {
return false;
}
// This isn't a fully exhaustive list of expressions that could be involved in a self-
// assignment, particularly when arrays are involved; for instance, `x[y+1] = x[y+1]` isn't
// detected because we don't look at BinaryExpressions. Since this is intended to be used for
// optimization purposes, handling the common cases is sufficient.
switch (left.kind()) {
case Expression::Kind::kIntLiteral:
return left.as<IntLiteral>().value() == right.as<IntLiteral>().value();

View File

@ -89,8 +89,7 @@ struct Analysis {
static bool IsTrivialExpression(const Expression& expr);
// Returns true if both expression trees are the same. The left side is expected to be an
// lvalue. This only needs to check for trees that can plausibly terminate in a variable, so
// some basic candidates like `FloatLiteral` are missing.
// lvalue. Intended for use by the optimizer; won't necessarily catch complex cases.
static bool IsSelfAssignment(const Expression& left, const Expression& right);
// Is 'expr' a constant-expression, as defined by GLSL 1.0, section 5.10? A constant expression