X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=e21dd98fd0fcbe63e578e3012cd072d108c5437d;hb=1ce5df9e70385c8758eec39589a148e63238b0a8;hp=7b90a2cd676b62a7693b3b8ccdedf94ce2888d8a;hpb=01c863144c51fd370c75233c5aa5b4add335f4a8;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 7b90a2cd..e21dd98f 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -27,7 +27,7 @@ private: /** Finds functions which are candidates for inlining. Currently this means functions which have no flow control statements, no more than one return -statement, and are only called once. */ +statement, and are either builtins or only called once. */ class InlineableFunctionLocator: private TraversingVisitor { private: @@ -39,7 +39,7 @@ private: public: InlineableFunctionLocator(); - const std::set &apply(Stage &s) { s.content.visit(*this); return inlineable; } + std::set apply(Stage &s) { s.content.visit(*this); return inlineable; } private: virtual void visit(FunctionCall &); @@ -57,7 +57,6 @@ class InlineContentInjector: private TraversingVisitor private: enum Pass { - DEPENDS, REFERENCED, INLINE, RENAME @@ -74,7 +73,7 @@ private: public: InlineContentInjector(); - const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList::iterator &, FunctionCall &); + std::string apply(Stage &, FunctionDeclaration &, Block &, const NodeList::iterator &, FunctionCall &); private: virtual void visit(VariableReference &); @@ -228,6 +227,26 @@ private: virtual void visit(Iteration &); }; +class UnreachableCodeRemover: private TraversingVisitor +{ +private: + bool reachable; + std::set unreachable_nodes; + +public: + UnreachableCodeRemover(); + + virtual bool apply(Stage &); + +private: + virtual void visit(Block &); + virtual void visit(FunctionDeclaration &); + virtual void visit(Conditional &); + virtual void visit(Iteration &); + virtual void visit(Return &) { reachable = false; } + virtual void visit(Jump &) { reachable = false; } +}; + /** Removes types which are not used anywhere. */ class UnusedTypeRemover: private TraversingVisitor { @@ -238,11 +257,7 @@ 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(RefPtr &); virtual void visit(BasicTypeDeclaration &); virtual void visit(ImageTypeDeclaration &); virtual void visit(StructDeclaration &); @@ -285,6 +300,8 @@ private: Assignment *r_assignment; bool assignment_target; bool r_side_effects; + bool composite_reference; + Assignment::Target r_reference; std::set unused_nodes; public: @@ -296,9 +313,13 @@ private: void referenced(const Assignment::Target &, Node &); virtual void visit(VariableReference &); virtual void visit(InterfaceBlockReference &); + void visit_composite(Expression &); + 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 &); void record_assignment(const Assignment::Target &, Node &); virtual void visit(ExpressionStatement &);