X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=7d064056e48ceb6d72bb7d9a4b2e9d5099f2e401;hb=4737d137d0a1c7fed868c4adc7a3d7e00ba7681c;hp=1504acb224e27dd5290947e9700fa657750ba433;hpb=0ded10909240623e33712be80855827d440f3caf;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 1504acb2..7d064056 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: @@ -175,13 +175,16 @@ 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 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 &); @@ -227,6 +230,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 +303,9 @@ 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; public: @@ -291,14 +317,17 @@ 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 &); - // 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 &);