]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.h
Support inlining GLSL functions with parameters
[libs/gl.git] / source / glsl / optimize.h
index 1262823f53ead86c058734fc0d62841b70f7dea3..6d4b1bcb5d2c2e5d883d7ab640390481c8c7e84e 100644 (file)
@@ -10,8 +10,8 @@ namespace GL {
 namespace SL {
 
 /** Finds functions which are candidates for inlining.  Currently this means
-functions which have no parameters, contain no more than one return statement,
-and are only called once. */
+functions which have no flow control statements, no more than one return
+statement, and are only called once. */
 class InlineableFunctionLocator: private TraversingVisitor
 {
 private:
@@ -39,12 +39,18 @@ dependencies of the inlined statements to appear before the target function. */
 class InlineContentInjector: private TraversingVisitor
 {
 private:
+       enum Pass
+       {
+               DEPENDS,
+               REFERENCED,
+               INLINE,
+               RENAME
+       };
+
        FunctionDeclaration *source_func;
-       Block *target_block;
-       std::map<std::string, VariableDeclaration *> variable_map;
+       Block staging_block;
        std::string remap_prefix;
-       unsigned remap_names;
-       bool deps_only;
+       Pass pass;
        RefPtr<Statement> r_inlined_statement;
        std::set<Node *> dependencies;
        std::set<std::string> referenced_names;
@@ -53,7 +59,7 @@ private:
 public:
        InlineContentInjector();
 
-       const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList<Statement>::iterator &, FunctionDeclaration &);
+       const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList<Statement>::iterator &, FunctionCall &);
 
 private:
        virtual void visit(VariableReference &);
@@ -75,6 +81,7 @@ private:
        NodeList<Statement>::iterator insert_point;
        RefPtr<Expression> r_inline_result;
        bool r_any_inlined;
+       bool r_inlined_here;
 
 public:
        FunctionInliner();
@@ -191,6 +198,7 @@ private:
 
        NodeList<Statement>::iterator insert_point;
        std::set<Node *> nodes_to_remove;
+       RefPtr<Expression> r_ternary_result;
 
 public:
        void apply(Stage &);
@@ -199,6 +207,8 @@ private:
        ConstantStatus check_constant_condition(const Expression &);
 
        virtual void visit(Block &);
+       virtual void visit(RefPtr<Expression> &);
+       virtual void visit(TernaryExpression &);
        virtual void visit(Conditional &);
        virtual void visit(Iteration &);
 };