X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=4c57eaea94844192b29d3a12c9862d754af6dc2c;hb=d9d7ab44d5f88c4537906e77c49db06d6bdc099c;hp=1262823f53ead86c058734fc0d62841b70f7dea3;hpb=5e4204ecaf54f49b63587ef5cd669a1b3838e0e9;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 1262823f..4c57eaea 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -9,9 +9,25 @@ namespace Msp { namespace GL { namespace SL { +/** Assigns values to specialization constants, turning them into normal +constants. */ +class ConstantSpecializer: private TraversingVisitor +{ +private: + const std::map *values; + +public: + ConstantSpecializer(); + + void apply(Stage &, const std::map &); + +private: + virtual void visit(VariableDeclaration &); +}; + /** Finds functions which are candidates for inlining. Currently this means -functions which have no parameters, contain no more than one return statement, -and are only called once. */ +functions which have no flow control statements, no more than one return +statement, and are only called once. */ class InlineableFunctionLocator: private TraversingVisitor { private: @@ -39,12 +55,17 @@ dependencies of the inlined statements to appear before the target function. */ class InlineContentInjector: private TraversingVisitor { private: + enum Pass + { + DEPENDS, + REFERENCED, + INLINE, + RENAME + }; + FunctionDeclaration *source_func; - Block *target_block; - std::map variable_map; - std::string remap_prefix; - unsigned remap_names; - bool deps_only; + Block staging_block; + Pass pass; RefPtr r_inlined_statement; std::set dependencies; std::set referenced_names; @@ -53,7 +74,7 @@ private: public: InlineContentInjector(); - const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList::iterator &, FunctionDeclaration &); + const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList::iterator &, FunctionCall &); private: virtual void visit(VariableReference &); @@ -75,6 +96,7 @@ private: NodeList::iterator insert_point; RefPtr r_inline_result; bool r_any_inlined; + bool r_inlined_here; public: FunctionInliner(); @@ -191,6 +213,7 @@ private: NodeList::iterator insert_point; std::set nodes_to_remove; + RefPtr r_ternary_result; public: void apply(Stage &); @@ -199,6 +222,8 @@ private: ConstantStatus check_constant_condition(const Expression &); virtual void visit(Block &); + virtual void visit(RefPtr &); + virtual void visit(TernaryExpression &); virtual void visit(Conditional &); virtual void visit(Iteration &); };