Allow swizzle optimizations to apply to any 'trivial' ctor fields.

This allows swizzle removal to apply in more cases; in particular, we
can now optimize away extra swizzles caused by zero/one swizzle-
components quite effectively.

The "trivial expression" code was lifted from the inliner. Some subtle
changes in trivial-expression determination affect the inliner's results
in boring, non-meaningful ways. In particular, multi-argument
constructors containing all-constant values are now considered trivial,
whereas previously only single-argument constructors made the trivial-
ness cut. This allows the inliner to propagate some values that it
wouldn't have before.

Change-Id: I9a009b6803d9ac9595d65538252ba81c2b7166a7
Bug: skia:10954
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/336156
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp
index ba6fb7f..e339962 100644
--- a/src/sksl/SkSLInliner.cpp
+++ b/src/sksl/SkSLInliner.cpp
@@ -248,19 +248,6 @@
     return clone;
 }
 
-bool is_trivial_argument(const Expression& argument) {
-    return argument.is<VariableReference>() ||
-           (argument.is<Swizzle>() && is_trivial_argument(*argument.as<Swizzle>().base())) ||
-           (argument.is<FieldAccess>() &&
-            is_trivial_argument(*argument.as<FieldAccess>().base())) ||
-           (argument.is<Constructor>() &&
-            argument.as<Constructor>().arguments().size() == 1 &&
-            is_trivial_argument(*argument.as<Constructor>().arguments().front())) ||
-           (argument.is<IndexExpression>() &&
-            argument.as<IndexExpression>().index()->is<IntLiteral>() &&
-            is_trivial_argument(*argument.as<IndexExpression>().base()));
-}
-
 }  // namespace
 
 void Inliner::ensureScopedBlocks(Statement* inlinedBody, Statement* parentStmt) {
@@ -685,7 +672,7 @@
         bool isOutParam = param->modifiers().fFlags & Modifiers::kOut_Flag;
 
         // If this argument can be inlined trivially (e.g. a swizzle, or a constant array index)...
-        if (is_trivial_argument(*arguments[i])) {
+        if (Analysis::IsTrivialExpression(*arguments[i])) {
             // ... and it's an `out` param, or it isn't written to within the inline function...
             if (isOutParam || !Analysis::StatementWritesToVariable(*function.body(), *param)) {
                 // ... we don't need to copy it at all! We can just use the existing expression.