]> git.tdb.fi Git - libs/gl.git/commitdiff
Handle all constructs when inlining GLSL functions
authorMikko Rasa <tdb@tdb.fi>
Wed, 3 Mar 2021 11:02:55 +0000 (13:02 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 3 Mar 2021 15:28:53 +0000 (17:28 +0200)
We need to look for function calls inside conditional and iteration
statements too, and inline calls within condition expressions.

source/glsl/optimize.cpp
source/glsl/optimize.h

index 08455c8ac61412d71fb8cfbb684c857f6a883169..b7236feb6fafb4f7e0495b3b6e8260329f91b29b 100644 (file)
@@ -41,18 +41,21 @@ void InlineableFunctionLocator::visit(FunctionDeclaration &func)
        TraversingVisitor::visit(func);
 }
 
-void InlineableFunctionLocator::visit(Conditional &)
+void InlineableFunctionLocator::visit(Conditional &cond)
 {
+       TraversingVisitor::visit(cond);
        inlineable.erase(current_function);
 }
 
-void InlineableFunctionLocator::visit(Iteration &)
+void InlineableFunctionLocator::visit(Iteration &iter)
 {
+       TraversingVisitor::visit(iter);
        inlineable.erase(current_function);
 }
 
-void InlineableFunctionLocator::visit(Return &)
+void InlineableFunctionLocator::visit(Return &ret)
 {
+       TraversingVisitor::visit(ret);
        if(return_count)
                inlineable.erase(current_function);
        ++return_count;
@@ -274,6 +277,22 @@ void FunctionInliner::visit(FunctionDeclaration &func)
        TraversingVisitor::visit(func);
 }
 
+void FunctionInliner::visit(Conditional &cond)
+{
+       visit_and_inline(cond.condition);
+       cond.body.visit(*this);
+}
+
+void FunctionInliner::visit(Iteration &iter)
+{
+       SetForScope<Block *> set_block(current_block, &iter.body);
+       if(iter.init_statement)
+               iter.init_statement->visit(*this);
+       /* Skip the condition and loop expression parts because they're executed on
+       every iteration of the loop */
+       iter.body.visit(*this);
+}
+
 void FunctionInliner::visit(Return &ret)
 {
        if(ret.expression)
index 390dd64ea98f668639e6733447f29ac5895368f2..e74e6e0e812b3a3cdaf2f1b5286960fdc87487b2 100644 (file)
@@ -93,6 +93,8 @@ private:
        virtual void visit(ExpressionStatement &);
        virtual void visit(VariableDeclaration &);
        virtual void visit(FunctionDeclaration &);
+       virtual void visit(Conditional &);
+       virtual void visit(Iteration &);
        virtual void visit(Return &);
 };