X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=92353a77ee1748c651d8d6f35ab266d6a429593c;hb=3bc34893905a2df622894aadcb6669f27f186772;hp=6d8a6194e7e9f5d2076fa81938a75aff421e39c2;hpb=83186c4a01ada8bfb0199c4396c0aaa64631577f;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 6d8a6194..92353a77 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -116,22 +116,32 @@ Variables which are only referenced once are also inlined. */ class ExpressionInliner: private TraversingVisitor { private: + struct ExpressionUse + { + RefPtr *reference; + Block *ref_scope; + bool blocked; + + ExpressionUse(): reference(0), ref_scope(0), blocked(false) { } + }; + struct ExpressionInfo { - Expression *expression; + Assignment::Target target; + RefPtr expression; Block *assign_scope; - RefPtr *inline_point; + std::vector uses; bool trivial; - bool available; - ExpressionInfo(): expression(0), assign_scope(0), inline_point(0), trivial(false), available(true) { } + ExpressionInfo(): expression(0), assign_scope(0), trivial(false) { } }; - std::map expressions; + std::list expressions; + std::map assignments; ExpressionInfo *r_ref_info; - bool r_any_inlined; bool r_trivial; - bool mutating; + bool access_read; + bool access_write; bool iteration_init; Block *iteration_body; const Operator *r_oper; @@ -142,8 +152,6 @@ public: bool apply(Stage &); private: - void inline_expression(Expression &, RefPtr &); - virtual void visit(Block &); virtual void visit(RefPtr &); virtual void visit(VariableReference &); virtual void visit(MemberAccess &); @@ -202,7 +210,8 @@ private: }; /** Removes conditional statements and loops where the condition can be -determined as constant at compile time. */ +determined as constant at compile time. Also removes such statements where +the body is empty and the condition has no side effects. */ class ConstantConditionEliminator: private TraversingVisitor { private: @@ -216,6 +225,7 @@ private: NodeList::iterator insert_point; std::set nodes_to_remove; RefPtr r_ternary_result; + bool r_external_side_effects; public: void apply(Stage &); @@ -225,7 +235,10 @@ private: virtual void visit(Block &); virtual void visit(RefPtr &); + virtual void visit(UnaryExpression &); + virtual void visit(Assignment &); virtual void visit(TernaryExpression &); + virtual void visit(FunctionCall &); virtual void visit(Conditional &); virtual void visit(Iteration &); };