X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=ed016ca0b9ddd26dd5e8e871b25a0f15484e2881;hb=3f899b1fc2e04f4fe74c99ad3e8ebb900c257214;hp=ea772b3d841b1ef78171d99ebb9afef064a76dfd;hpb=ab5f2e6f1ddd35f8f117460530d76c0ba0c9bc87;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index ea772b3d..ed016ca0 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -10,6 +10,9 @@ namespace Msp { namespace GL { namespace SL { +/** Finds functions which are candidates for inlining. Currently this means +functions which have no parameters, are only called once, and that call occurs +after the definition of the function. */ class InlineableFunctionLocator: private TraversingVisitor { private: @@ -20,14 +23,16 @@ private: public: InlineableFunctionLocator(); - const std::set &apply(Stage &s) { visit(s.content); return inlineable; } + const std::set &apply(Stage &s) { s.content.visit(*this); return inlineable; } private: virtual void visit(FunctionCall &); virtual void visit(FunctionDeclaration &); - using TraversingVisitor::visit; }; +/** Inlines functions. Internally uses InlineableFunctionLocator to find +candidate functions. Only functions which consist of a single return statement +are inlined. */ class FunctionInliner: private TraversingVisitor { private: @@ -50,14 +55,13 @@ private: virtual void visit(FunctionCall &); virtual void visit(VariableDeclaration &); virtual void visit(Return &); - using TraversingVisitor::visit; }; +/** Removes conditional statements and loops where the condition can be +determined as constant at compile time. */ class ConstantConditionEliminator: private TraversingVisitor { private: - unsigned scope_level; - Block *current_block; bool record_only; ExpressionEvaluator::ValueMap variable_values; NodeList::iterator insert_point; @@ -75,9 +79,10 @@ private: virtual void visit(VariableDeclaration &); virtual void visit(Conditional &); virtual void visit(Iteration &); - using TraversingVisitor::visit; }; +/** Removes variable declarations with no references to them. Assignment +statements where the result is not used are also removed. */ class UnusedVariableRemover: private TraversingVisitor { private: @@ -100,7 +105,6 @@ private: Assignment *assignment; bool assignment_target; bool assign_to_subscript; - bool global_scope; public: UnusedVariableRemover(); @@ -109,6 +113,7 @@ public: private: virtual void visit(VariableReference &); + virtual void visit(InterfaceBlockReference &); virtual void visit(MemberAccess &); virtual void visit(BinaryExpression &); virtual void visit(Assignment &); @@ -122,9 +127,9 @@ private: void merge_down_variables(); virtual void visit(Conditional &); virtual void visit(Iteration &); - using TraversingVisitor::visit; }; +/** Removes function declarations with no references to them. */ class UnusedFunctionRemover: private TraversingVisitor { private: @@ -137,7 +142,6 @@ public: private: virtual void visit(FunctionCall &); virtual void visit(FunctionDeclaration &); - using TraversingVisitor::visit; }; } // namespace SL