X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=a714a97a1b45ce49cf78a5c0fd4c69d2a4b6a661;hb=188b3b2bf686aada8772475aabf899a0420cbd0f;hp=b7b39176a06e62490573cee96ec174fbcd276ad4;hpb=305b62cf4f7e2a4ca3cc56109003aed6bde61c25;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index b7b39176..a714a97a 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -175,7 +175,6 @@ public: bool apply(Stage &s) { s.content.visit(*this); return r_any_folded; } private: - static BasicTypeDeclaration::Kind get_value_kind(const Variant &); template static T evaluate_logical(char, T, T); template @@ -227,6 +226,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 { @@ -280,6 +299,7 @@ private: Assignment *r_assignment; bool assignment_target; bool r_side_effects; + bool in_struct; bool composite_reference; Assignment::Target r_reference; std::set unused_nodes; @@ -303,8 +323,7 @@ private: 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(StructDeclaration &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); void merge_variables(const BlockVariableMap &);