]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.h
Add some documentation to the GLSL compiler
[libs/gl.git] / source / glsl / optimize.h
index ea772b3d841b1ef78171d99ebb9afef064a76dfd..ed016ca0b9ddd26dd5e8e871b25a0f15484e2881 100644 (file)
@@ -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<FunctionDeclaration *> &apply(Stage &s) { visit(s.content); return inlineable; }
+       const std::set<FunctionDeclaration *> &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<Statement>::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