]> git.tdb.fi Git - libs/gl.git/commitdiff
Cleanup ExpressionInliner
authorMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 19:29:40 +0000 (21:29 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 19:29:40 +0000 (21:29 +0200)
source/glsl/optimize.cpp
source/glsl/optimize.h

index 0d18b76c311b98c3ab7fbae14eea36cb1f80ba42..220017971a2f75001cb6e30faeb4a4fecc2b9fa9 100644 (file)
@@ -289,33 +289,6 @@ bool ExpressionInliner::apply(Stage &s)
        return r_any_inlined;
 }
 
-void ExpressionInliner::visit_and_record(RefPtr<Expression> &ptr)
-{
-       r_ref_info = 0;
-       ptr->visit(*this);
-       if(r_ref_info && r_ref_info->expression && r_ref_info->available)
-       {
-               if(iteration_body && !r_ref_info->trivial)
-               {
-                       /* Don't inline non-trivial expressions which were assigned outside
-                       an iteration statement.  The iteration may run multiple times, which
-                       would cause the expression to also be evaluated multiple times. */
-                       Block *i = r_ref_info->assign_scope;
-                       for(; (i && i!=iteration_body); i=i->parent) ;
-                       if(!i)
-                               return;
-               }
-
-               if(r_ref_info->trivial)
-                       inline_expression(*r_ref_info->expression, ptr);
-               else
-                       /* Record the inline point for a non-trivial expression but don't
-                       inline it yet.  It might turn out it shouldn't be inlined after all. */
-                       r_ref_info->inline_point = &ptr;
-       }
-       r_ref_info = 0;
-}
-
 void ExpressionInliner::inline_expression(Expression &expr, RefPtr<Expression> &ptr)
 {
        ptr = expr.clone();
@@ -348,7 +321,30 @@ void ExpressionInliner::visit(Block &block)
 
 void ExpressionInliner::visit(RefPtr<Expression> &expr)
 {
-       visit_and_record(expr);
+       r_ref_info = 0;
+       expr->visit(*this);
+       if(r_ref_info && r_ref_info->expression && r_ref_info->available)
+       {
+               if(iteration_body && !r_ref_info->trivial)
+               {
+                       /* Don't inline non-trivial expressions which were assigned outside
+                       an iteration statement.  The iteration may run multiple times, which
+                       would cause the expression to also be evaluated multiple times. */
+                       Block *i = r_ref_info->assign_scope;
+                       for(; (i && i!=iteration_body); i=i->parent) ;
+                       if(!i)
+                               return;
+               }
+
+               if(r_ref_info->trivial)
+                       inline_expression(*r_ref_info->expression, expr);
+               else
+                       /* Record the inline point for a non-trivial expression but don't
+                       inline it yet.  It might turn out it shouldn't be inlined after all. */
+                       r_ref_info->inline_point = &expr;
+       }
+       r_oper = expr->oper;
+       r_ref_info = 0;
 }
 
 void ExpressionInliner::visit(VariableReference &var)
@@ -373,34 +369,30 @@ void ExpressionInliner::visit(VariableReference &var)
 
 void ExpressionInliner::visit(MemberAccess &memacc)
 {
-       visit_and_record(memacc.left);
-       r_oper = memacc.oper;
+       visit(memacc.left);
        r_trivial = false;
 }
 
 void ExpressionInliner::visit(Swizzle &swizzle)
 {
-       visit_and_record(swizzle.left);
-       r_oper = swizzle.oper;
+       visit(swizzle.left);
        r_trivial = false;
 }
 
 void ExpressionInliner::visit(UnaryExpression &unary)
 {
        SetFlag set_target(mutating, mutating || unary.oper->token[1]=='+' || unary.oper->token[1]=='-');
-       visit_and_record(unary.expression);
-       r_oper = unary.oper;
+       visit(unary.expression);
        r_trivial = false;
 }
 
 void ExpressionInliner::visit(BinaryExpression &binary)
 {
-       visit_and_record(binary.left);
+       visit(binary.left);
        {
                SetFlag clear_target(mutating, false);
-               visit_and_record(binary.right);
+               visit(binary.right);
        }
-       r_oper = binary.oper;
        r_trivial = false;
 }
 
@@ -408,10 +400,10 @@ void ExpressionInliner::visit(Assignment &assign)
 {
        {
                SetFlag set_target(mutating);
-               visit_and_record(assign.left);
+               visit(assign.left);
        }
        r_oper = 0;
-       visit_and_record(assign.right);
+       visit(assign.right);
 
        map<Assignment::Target, ExpressionInfo>::iterator i = expressions.find(assign.target);
        if(i!=expressions.end())
@@ -424,23 +416,20 @@ void ExpressionInliner::visit(Assignment &assign)
                i->second.available = true;
        }
 
-       r_oper = assign.oper;
        r_trivial = false;
 }
 
 void ExpressionInliner::visit(TernaryExpression &ternary)
 {
-       visit_and_record(ternary.condition);
-       visit_and_record(ternary.true_expr);
-       visit_and_record(ternary.false_expr);
-       r_oper = ternary.oper;
+       visit(ternary.condition);
+       visit(ternary.true_expr);
+       visit(ternary.false_expr);
        r_trivial = false;
 }
 
 void ExpressionInliner::visit(FunctionCall &call)
 {
        TraversingVisitor::visit(call);
-       r_oper = 0;
        r_trivial = false;
 }
 
index ca22c9d8259fdf198c0c63cc5221361ee010c8a6..fa75e6d7e867cdbb9f18f4a8bd0896e89f33f663 100644 (file)
@@ -122,7 +122,6 @@ public:
        bool apply(Stage &);
 
 private:
-       void visit_and_record(RefPtr<Expression> &);
        void inline_expression(Expression &, RefPtr<Expression> &);
        virtual void visit(Block &);
        virtual void visit(RefPtr<Expression> &);