Move Constructor generation and type-coercion out of IRGenerator.
The IRGenerator's `convertConstructor` and `coerce` were tied at the
hip--coercion can create a constructor, and creating a constructor can
cause type-coercion. This CL migrates IRGenerator::coerce to
Type::coerceExpression, and migrates IRGenerator::convertConstructor to
Constructor::Make.
Most constructor creation should go through Constructor::Make instead of
make_unique<Constructor> for best results. There are exceptions to this
rule:
- during the Compiler's `optimize` phase, we hold raw pointers to
unique_ptrs of existing expression trees, and are manually tracking
variable usage counts, so adjusting the IR tree should be done with
extreme care. Continue to use make_unique here to avoid any "surprise
improvements."
- the Rehydrator is attempting to recreate an IR tree exactly as it used
to be and doesn't want additional optimization or fixups
There are still Constructor-related optimizations in simplifyExpression
which are not yet implemented in Constructor::Make. These are migrated
to Constructor::Make at http://review.skia.org/371482
Change-Id: I0f3876f932835fc2e347ae95414bc490085f120c
Bug: skia:11342
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/370876
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLConstantFolder.cpp b/src/sksl/SkSLConstantFolder.cpp
index 7d05ffd..fc86d90 100644
--- a/src/sksl/SkSLConstantFolder.cpp
+++ b/src/sksl/SkSLConstantFolder.cpp
@@ -91,7 +91,7 @@
}
// Handle floating-point arithmetic: + - * /
- const auto vectorComponentwiseFold = [&](auto foldFn) -> std::unique_ptr<Constructor> {
+ const auto vectorComponentwiseFold = [&](auto foldFn) -> std::unique_ptr<Expression> {
const Type& componentType = type.componentType();
ExpressionArray args;
args.reserve_back(type.columns());
@@ -99,7 +99,7 @@
U value = foldFn(left.getVecComponent<T>(i), right.getVecComponent<T>(i));
args.push_back(std::make_unique<Literal<T>>(left.fOffset, value, &componentType));
}
- return std::make_unique<Constructor>(left.fOffset, &type, std::move(args));
+ return Constructor::Make(context, left.fOffset, type, std::move(args));
};
switch (op.kind()) {
@@ -119,7 +119,7 @@
// Use a Constructor to splat the scalar expression across a vector.
ExpressionArray arg;
arg.push_back(scalar.clone());
- return Constructor{scalar.fOffset, &type, std::move(arg)};
+ return Constructor{scalar.fOffset, type, std::move(arg)};
}
bool ConstantFolder::GetConstantInt(const Expression& value, SKSL_INT* out) {