X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=ca22c9d8259fdf198c0c63cc5221361ee010c8a6;hb=bde40be11da83206f3d33a8225963d47a413662e;hp=26076452efe58776ac092a8ce6ad840f63345b14;hpb=2a9f8f3803e1b57e0e5325454266d4e701b38cc5;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 26076452..ca22c9d8 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -101,9 +101,6 @@ private: Expression *expression; Block *assign_scope; RefPtr *inline_point; - const Operator *inner_oper; - const Operator *outer_oper; - bool inline_on_rhs; bool trivial; bool available; @@ -125,8 +122,8 @@ public: bool apply(Stage &); private: - void visit_and_record(RefPtr &, const Operator *, bool); - void inline_expression(Expression &, RefPtr &, const Operator *, const Operator *, bool); + void visit_and_record(RefPtr &); + void inline_expression(Expression &, RefPtr &); virtual void visit(Block &); virtual void visit(RefPtr &); virtual void visit(VariableReference &); @@ -135,6 +132,7 @@ private: virtual void visit(UnaryExpression &); virtual void visit(BinaryExpression &); virtual void visit(Assignment &); + virtual void visit(TernaryExpression &); virtual void visit(FunctionCall &); virtual void visit(VariableDeclaration &); virtual void visit(Iteration &); @@ -170,6 +168,7 @@ private: virtual void visit(Literal &); virtual void visit(UnaryExpression &); virtual void visit(BinaryExpression &); + virtual void visit(TernaryExpression &); virtual void visit(FunctionCall &); virtual void visit(BasicTypeDeclaration &); virtual void visit(ImageTypeDeclaration &); @@ -184,27 +183,36 @@ statements where the result is not used are also removed. */ class UnusedVariableRemover: private TraversingVisitor { private: + struct AssignmentInfo + { + Node *node; + Assignment::Target target; + std::vector used_by; + + AssignmentInfo(): node(0) { } + }; + struct VariableInfo { - std::vector assignments; - bool local; + InterfaceBlock *interface_block; + std::vector assignments; + bool initialized; bool output; - bool conditionally_assigned; bool referenced; - InterfaceBlock *interface_block; - VariableInfo(); + VariableInfo(): interface_block(0), initialized(false), output(false), referenced(false) { } }; - typedef std::map BlockVariableMap; + typedef std::map BlockVariableMap; Stage *stage; - std::set unused_nodes; - std::vector variables; + BlockVariableMap variables; + std::list assignments; InterfaceBlock *interface_block; Assignment *r_assignment; bool assignment_target; bool r_side_effects; + std::set unused_nodes; public: UnusedVariableRemover(); @@ -212,22 +220,21 @@ public: bool apply(Stage &); private: - void reference_used(Statement &); + void referenced(const Assignment::Target &, Node &); virtual void visit(VariableReference &); virtual void visit(InterfaceBlockReference &); virtual void visit(UnaryExpression &); virtual void visit(BinaryExpression &); virtual void visit(Assignment &); - void record_assignment(const Assignment::Target &, Node &, bool); - void clear_assignments(VariableInfo &, bool); virtual void visit(FunctionCall &); + void record_assignment(const Assignment::Target &, Node &); virtual void visit(ExpressionStatement &); // Ignore structs because their members can't be accessed directly. virtual void visit(StructDeclaration &) { } virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); + void merge_variables(const BlockVariableMap &); virtual void visit(FunctionDeclaration &); - void merge_down_variables(); virtual void visit(Conditional &); virtual void visit(Iteration &); };