37class ReturnsInputAlphaVisitor :
public ProgramVisitor {
39 ReturnsInputAlphaVisitor(
const ProgramUsage& u) : fUsage(u) {}
41 bool visitProgramElement(
const ProgramElement& pe)
override {
42 const FunctionDeclaration& decl = pe.as<FunctionDefinition>().declaration();
46 if (parameters.
size() != 1 ||
47 parameters[0]->type().columns() != 4 ||
48 !parameters[0]->type().componentType().isFloat()) {
52 fInputVar = parameters[0];
56 ProgramUsage::VariableCounts
counts = fUsage.get(*fInputVar);
64 bool isInputVar(
const Expression& expr) {
65 return expr.is<VariableReference>() && expr.as<VariableReference>().variable() == fInputVar;
68 bool isInputSwizzleEndingWithAlpha(
const Expression& expr) {
69 if (!expr.is<Swizzle>()) {
72 const Swizzle& swizzle = expr.as<Swizzle>();
73 return this->isInputVar(*swizzle.base()) && swizzle.components().back() == 3;
76 bool returnsInputAlpha(
const Expression& expr) {
77 if (this->isInputVar(expr)) {
81 if (expr.is<Swizzle>()) {
83 return this->isInputSwizzleEndingWithAlpha(expr);
85 if (expr.is<ConstructorSplat>() || expr.is<ConstructorCompound>()) {
87 const AnyConstructor& ctor = expr.asAnyConstructor();
88 return this->returnsInputAlpha(*ctor.argumentSpan().back());
90 if (expr.is<ConstructorCompoundCast>()) {
92 const Expression& arg = *expr.as<ConstructorCompoundCast>().argument();
93 return arg.type().componentType().isFloat() && this->returnsInputAlpha(arg);
95 if (expr.is<TernaryExpression>()) {
97 const TernaryExpression& ternary = expr.as<TernaryExpression>();
98 return this->returnsInputAlpha(*ternary.ifTrue()) &&
99 this->returnsInputAlpha(*ternary.ifFalse());
105 bool visitStatement(
const Statement&
s)
override {
106 if (
s.is<ReturnStatement>()) {
107 return !this->returnsInputAlpha(*
s.as<ReturnStatement>().expression());
112 bool visitExpression(
const Expression&
e)
override {
118 const ProgramUsage& fUsage;
119 const Variable* fInputVar =
nullptr;
127 ReturnsInputAlphaVisitor visitor{
usage};
128 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)