![]() |
Flutter Engine
The Flutter Engine
|
ModifierFlags SkSL::Transform::AddConstToVarModifiers | ( | const Variable & | var, |
const Expression * | initialValue, | ||
const ProgramUsage * | usage | ||
) |
Checks to see if it would be safe to add const
to the modifier flags of a variable. If so, returns the modifiers with const
applied; if not, returns the existing modifiers as-is. Adding const
allows the inliner to fold away more values and generate tighter code.
Definition at line 19 of file SkSLAddConstToVarModifiers.cpp.
bool SkSL::Transform::EliminateDeadFunctions | ( | const Context & | context, |
Module & | module, | ||
ProgramUsage * | usage | ||
) |
Eliminates functions in a program which are never called. Returns true if any changes were made.
Definition at line 63 of file SkSLEliminateDeadFunctions.cpp.
bool SkSL::Transform::EliminateDeadFunctions | ( | Program & | program | ) |
Definition at line 38 of file SkSLEliminateDeadFunctions.cpp.
bool SkSL::Transform::EliminateDeadGlobalVariables | ( | const Context & | context, |
Module & | module, | ||
ProgramUsage * | usage, | ||
bool | onlyPrivateGlobals | ||
) |
Definition at line 45 of file SkSLEliminateDeadGlobalVariables.cpp.
bool SkSL::Transform::EliminateDeadGlobalVariables | ( | Program & | program | ) |
Definition at line 65 of file SkSLEliminateDeadGlobalVariables.cpp.
bool SkSL::Transform::EliminateDeadLocalVariables | ( | const Context & | context, |
Module & | module, | ||
ProgramUsage * | usage | ||
) |
Eliminates variables in a program which are never read or written (past their initializer). Preserves side effects from initializers, if any. Returns true if any changes were made.
Definition at line 158 of file SkSLEliminateDeadLocalVariables.cpp.
bool SkSL::Transform::EliminateDeadLocalVariables | ( | Program & | program | ) |
Definition at line 164 of file SkSLEliminateDeadLocalVariables.cpp.
void SkSL::Transform::EliminateEmptyStatements | ( | Module & | module | ) |
Eliminates empty statements in a module (Nops, or blocks holding only Nops). Not implemented for Programs because Nops are harmless, but they waste space in long-lived module IR.
Definition at line 63 of file SkSLEliminateEmptyStatements.cpp.
void SkSL::Transform::EliminateUnnecessaryBraces | ( | Module & | module | ) |
Eliminates unnecessary braces in a module (e.g., single-statement child blocks). Not implemented for Programs because extra braces are harmless, but they waste space in long-lived module IR.
Definition at line 107 of file SkSLEliminateUnnecessaryBraces.cpp.
void SkSL::Transform::EliminateUnreachableCode | ( | Module & | module, |
ProgramUsage * | usage | ||
) |
Eliminates statements in a block which cannot be reached; for example, a statement immediately after a return
or continue
can safely be eliminated.
Definition at line 208 of file SkSLEliminateUnreachableCode.cpp.
void SkSL::Transform::EliminateUnreachableCode | ( | Program & | program | ) |
Definition at line 212 of file SkSLEliminateUnreachableCode.cpp.
void SkSL::Transform::FindAndDeclareBuiltinFunctions | ( | Program & | program | ) |
Copies built-in functions from modules into the program. Relies on ProgramUsage to determine which functions are necessary.
Definition at line 31 of file SkSLFindAndDeclareBuiltinFunctions.cpp.
void SkSL::Transform::FindAndDeclareBuiltinStructs | ( | Program & | program | ) |
Copies built-in structs from modules into the program. Relies on ProgramUsage to determine which structs are necessary.
Definition at line 60 of file SkSLFindAndDeclareBuiltinStructs.cpp.
void SkSL::Transform::FindAndDeclareBuiltinVariables | ( | Program & | program | ) |
Scans the finished program for built-in variables like sk_FragColor
and adds them to the program's shared elements.
Definition at line 127 of file SkSLFindAndDeclareBuiltinVariables.cpp.
std::unique_ptr< Statement > SkSL::Transform::HoistSwitchVarDeclarationsAtTopLevel | ( | const Context & | context, |
std::unique_ptr< SwitchStatement > | stmt | ||
) |
Looks for variables inside of the top-level of a switch body, such as:
switch (x) { case 1: int i; // i
is at top-level case 2: float f = 5.0; // f
is at top-level, and has an initial-value assignment case 3: { bool b; } // b
is not at top-level; it has an additional scope }
If any top-level variables are found, a scoped block is created around the switch, and the variable declarations are moved out of the switch body and into the outer scope. (Variables with additional scoping are left as-is.) Then, we replace the declarations with assignment statements:
{ int i; float f; switch (a) { case 1: // i
is declared above and does not need initialization case 2: f = 5.0; // f
is declared above and initialized here case 3: { bool b; } // b
is left as-is because it has a block-scope } }
This doesn't change the meaning or correctness of the code. If the switch needs to be rewriten (e.g. due to the restrictions of ES2 or WGSL), this transformation prevents scoping issues with variables falling out of scope between switch-cases when we fall through.
If there are no variables at the top-level, the switch statement is returned as-is.
Definition at line 36 of file SkSLHoistSwitchVarDeclarationsAtTopLevel.cpp.
void SkSL::Transform::RenamePrivateSymbols | ( | Context & | context, |
Module & | module, | ||
ProgramUsage * | usage, | ||
ProgramKind | kind | ||
) |
Renames private functions and function-local variables to minimize code size.
Definition at line 58 of file SkSLRenamePrivateSymbols.cpp.
void SkSL::Transform::ReplaceConstVarsWithLiterals | ( | Module & | module, |
ProgramUsage * | usage | ||
) |
Replaces constant variables in a program with their equivalent values.
Definition at line 32 of file SkSLReplaceConstVarsWithLiterals.cpp.
std::unique_ptr< Expression > SkSL::Transform::RewriteIndexedSwizzle | ( | const Context & | context, |
const IndexExpression & | swizzle | ||
) |
Rewrites indexed swizzles of the form myVec.zyx[i]
by replacing the swizzle with a lookup into a constant vector. e.g., the above expression would be rewritten as myVec[vec3(2, 1, 0)[i]]
. This roughly matches glslang's handling of the code.
Definition at line 22 of file SkSLRewriteIndexedSwizzle.cpp.