X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=8a888e15bec7c11e019b172570e758a06f46963b;hb=0388083;hp=85f11780baf45a8b77401aecccee255215a0bb2f;hpb=a204b5fac497e2ffbc6791f0f7de9d9d12c16d52;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 85f11780..8a888e15 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -43,10 +43,12 @@ private: FunctionDeclaration *source_func; Block *target_block; std::map variable_map; - bool remap_names; + std::string remap_prefix; + unsigned remap_names; bool deps_only; RefPtr r_inlined_statement; std::set dependencies; + std::set referenced_names; std::string r_result_name; public: @@ -55,8 +57,6 @@ public: const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList::iterator &, FunctionDeclaration &); private: - std::string create_unused_name(const std::string &, bool); - virtual void visit(VariableReference &); virtual void visit(InterfaceBlockReference &); virtual void visit(FunctionCall &); @@ -83,19 +83,11 @@ public: bool apply(Stage &); private: - void visit_and_inline(RefPtr &); - + virtual void visit(RefPtr &); virtual void visit(Block &); - virtual void visit(UnaryExpression &); - virtual void visit(BinaryExpression &); - virtual void visit(MemberAccess &); virtual void visit(FunctionCall &); - virtual void visit(ExpressionStatement &); - virtual void visit(VariableDeclaration &); virtual void visit(FunctionDeclaration &); - virtual void visit(Conditional &); virtual void visit(Iteration &); - virtual void visit(Return &); }; /** Inlines variables into expressions. Variables with trivial values (those @@ -109,16 +101,13 @@ 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; ExpressionInfo(); }; - std::map expressions; + std::map expressions; ExpressionInfo *r_ref_info; bool r_any_inlined; bool r_trivial; @@ -133,19 +122,19 @@ public: bool apply(Stage &); private: - void visit_and_record(RefPtr &, const Operator *, bool); - void inline_expression(Expression &, RefPtr &, const Operator *, const Operator *, bool); + void inline_expression(Expression &, RefPtr &); virtual void visit(Block &); + virtual void visit(RefPtr &); virtual void visit(VariableReference &); virtual void visit(MemberAccess &); + virtual void visit(Swizzle &); 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(Conditional &); virtual void visit(Iteration &); - virtual void visit(Return &); }; /** Removes conditional statements and loops where the condition can be @@ -175,10 +164,17 @@ public: bool apply(Stage &); 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 &); virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); + virtual void visit(InterfaceBlock &); + virtual void visit(FunctionDeclaration &); }; /** Removes variable declarations with no references to them. Assignment @@ -186,26 +182,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 { - bool local; - std::vector assignments; - bool conditionally_assigned; + InterfaceBlock *interface_block; + std::vector assignments; + bool initialized; + bool output; bool referenced; - VariableInfo(); + VariableInfo(): interface_block(0), initialized(false), output(false), referenced(false) { } }; - typedef std::map BlockVariableMap; + typedef std::map BlockVariableMap; - std::set unused_nodes; - std::map aggregates; - Node *aggregate; - std::vector variables; + Stage *stage; + BlockVariableMap variables; + std::list assignments; + InterfaceBlock *interface_block; Assignment *r_assignment; bool assignment_target; - bool r_assign_to_subfield; bool r_side_effects; + std::set unused_nodes; public: UnusedVariableRemover(); @@ -213,21 +219,21 @@ public: bool apply(Stage &); private: + void referenced(const Assignment::Target &, Node &); virtual void visit(VariableReference &); virtual void visit(InterfaceBlockReference &); - virtual void visit(MemberAccess &); virtual void visit(UnaryExpression &); virtual void visit(BinaryExpression &); virtual void visit(Assignment &); - void record_assignment(VariableDeclaration &, Node &, bool); - void clear_assignments(VariableInfo &, bool); virtual void visit(FunctionCall &); + void record_assignment(const Assignment::Target &, Node &); virtual void visit(ExpressionStatement &); - virtual void visit(StructDeclaration &); + // 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 &); };