40 SkSpan<std::unique_ptr<ProgramElement>> elements,
50 bool visitExpressionPtr(std::unique_ptr<Expression>& expr)
override {
55 if (fDeadVariables.contains(assignedVar->variable())) {
57 fUsage->remove(expr.get());
58 expr = std::move(
binary.right());
59 fUsage->add(expr.get());
63 fAssignmentWasEliminated =
true;
68 return this->visitExpressionPtr(expr);
75 return INHERITED::visitExpressionPtr(expr);
78 bool visitStatementPtr(std::unique_ptr<Statement>& stmt)
override {
85 if (CanEliminate(var, *
counts)) {
86 fDeadVariables.add(var);
87 if (var->initialValue()) {
91 fUsage->remove(stmt.get());
93 fUsage->add(stmt.get());
96 fUsage->remove(stmt.get());
104 return this->visitStatementPtr(stmt);
108 bool result = INHERITED::visitStatementPtr(stmt);
112 if (fAssignmentWasEliminated) {
113 fAssignmentWasEliminated =
false;
118 fUsage->remove(&exprStmt);
131 bool fMadeChanges =
false;
135 bool fAssignmentWasEliminated =
false;
140 DeadLocalVariableEliminator visitor{context,
usage};
142 for (
auto& [var,
counts] :
usage->fVariableCounts) {
143 if (DeadLocalVariableEliminator::CanEliminate(var,
counts)) {
146 for (std::unique_ptr<ProgramElement>& pe : elements) {
148 visitor.visitProgramElement(*pe);
155 return visitor.fMadeChanges;
165 return program.
fConfig->fSettings.fRemoveDeadVariables
#define INHERITED(method,...)
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
static std::unique_ptr< Statement > Make(const Context &context, std::unique_ptr< Expression > expr)
const std::unique_ptr< Expression > & expression() const
static std::unique_ptr< Statement > Make()
virtual bool visitProgramElement(typename T::ProgramElement &programElement)
std::unique_ptr< Expression > & value()
const Variable * variable() const
bool HasSideEffects(const Expression &expr)
static bool eliminate_dead_local_variables(const Context &context, SkSpan< std::unique_ptr< ProgramElement > > elements, 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)
std::vector< std::unique_ptr< ProgramElement > > fElements
std::vector< std::unique_ptr< ProgramElement > > fOwnedElements
std::shared_ptr< Context > fContext
std::unique_ptr< ProgramUsage > fUsage
std::unique_ptr< ProgramConfig > fConfig