38class ReturnsInputAlphaVisitor :
public ProgramVisitor {
40 ReturnsInputAlphaVisitor(
const ProgramUsage& u) : fUsage(u) {}
42 bool visitProgramElement(
const ProgramElement& pe)
override {
43 const FunctionDeclaration& decl = pe.as<FunctionDefinition>().declaration();
47 if (parameters.
size() != 1 ||
48 parameters[0]->type().columns() != 4 ||
49 !parameters[0]->type().componentType().isFloat()) {
53 fInputVar = parameters[0];
57 ProgramUsage::VariableCounts
counts = fUsage.get(*fInputVar);
65 bool isInputVar(
const Expression& expr) {
66 return expr.is<VariableReference>() && expr.as<VariableReference>().variable() == fInputVar;
69 bool isInputSwizzleEndingWithAlpha(
const Expression& expr) {
70 if (!expr.is<Swizzle>()) {
73 const Swizzle& swizzle = expr.as<Swizzle>();
74 return this->isInputVar(*swizzle.base()) && swizzle.components().back() == 3;
77 bool returnsInputAlpha(
const Expression& expr) {
78 if (this->isInputVar(expr)) {
82 if (expr.is<Swizzle>()) {
84 return this->isInputSwizzleEndingWithAlpha(expr);
86 if (expr.is<ConstructorSplat>() || expr.is<ConstructorCompound>()) {
88 const AnyConstructor& ctor = expr.asAnyConstructor();
89 return this->returnsInputAlpha(*ctor.argumentSpan().back());
91 if (expr.is<ConstructorCompoundCast>()) {
93 const Expression& arg = *expr.as<ConstructorCompoundCast>().argument();
94 return arg.type().componentType().isFloat() && this->returnsInputAlpha(arg);
96 if (expr.is<TernaryExpression>()) {
98 const TernaryExpression& ternary = expr.as<TernaryExpression>();
99 return this->returnsInputAlpha(*ternary.ifTrue()) &&
100 this->returnsInputAlpha(*ternary.ifFalse());
106 bool visitStatement(
const Statement&
s)
override {
107 if (
s.is<ReturnStatement>()) {
108 return !this->returnsInputAlpha(*
s.as<ReturnStatement>().expression());
113 bool visitExpression(
const Expression& e)
override {
119 const ProgramUsage& fUsage;
120 const Variable* fInputVar =
nullptr;
128 ReturnsInputAlphaVisitor visitor{
usage};
129 return !visitor.visitProgramElement(
function);
#define INHERITED(method,...)
virtual bool visitStatement(typename T::Statement &statement)
virtual bool visitProgramElement(typename T::ProgramElement &programElement)
constexpr size_t size() const
Dart_NativeFunction function
bool ReturnsInputAlpha(const FunctionDefinition &function, const ProgramUsage &usage)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core counts
static void usage(char *argv0)