1 /* 2 * Copyright 2021 Google LLC. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SKSL_TRANSFORM 9 #define SKSL_TRANSFORM 10 11 #include <memory> 12 #include <vector> 13 14 namespace SkSL { 15 16 class Context; 17 struct Program; 18 class ProgramElement; 19 class ProgramUsage; 20 class Statement; 21 enum class ProgramKind : int8_t; 22 23 namespace Transform { 24 25 void FindAndDeclareBuiltinVariables(const Context& context, ProgramKind programKind, 26 std::vector<const ProgramElement*>& sharedElements); 27 28 /** 29 * Eliminates statements in a block which cannot be reached; for example, a statement 30 * immediately after a `return` or `continue` can safely be eliminated. 31 */ 32 void EliminateUnreachableCode(Program& program, ProgramUsage* usage = nullptr); 33 34 /** 35 * Eliminates functions in a program which are never called. Returns true if any changes were made. 36 */ 37 bool EliminateDeadFunctions(Program& program, ProgramUsage* usage); 38 39 /** 40 * Eliminates variables in a program which are never read or written (past their initializer). 41 * Preserves side effects from initializers, if any. Returns true if any changes were made. 42 */ 43 bool EliminateDeadLocalVariables(Program& program, ProgramUsage* usage); 44 bool EliminateDeadGlobalVariables(Program& program, ProgramUsage* usage); 45 46 } // namespace Transform 47 } // namespace SkSL 48 49 #endif 50