X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=92353a77ee1748c651d8d6f35ab266d6a429593c;hb=c39bb707ff8678d0675538994dc05182e61da193;hp=a714a97a1b45ce49cf78a5c0fd4c69d2a4b6a661;hpb=188b3b2bf686aada8772475aabf899a0420cbd0f;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index a714a97a..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 &); @@ -181,6 +189,10 @@ private: static bool evaluate_relation(const char *, T, T); template static T evaluate_arithmetic(char, T, T); + template + static T evaluate_int_special_op(char, T, T); + template + void convert_to_result(const Variant &); void set_result(const Variant &, bool = false); virtual void visit(RefPtr &); @@ -198,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: @@ -212,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 &); @@ -221,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 &); }; @@ -275,6 +292,7 @@ private: Node *node; Assignment::Target target; std::vector used_by; + unsigned in_loop; AssignmentInfo(): node(0) { } }; @@ -301,6 +319,8 @@ private: bool r_side_effects; bool in_struct; bool composite_reference; + unsigned in_loop; + std::vector loop_ext_refs; Assignment::Target r_reference; std::set unused_nodes;