X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=inline;f=source%2Fglsl%2Foptimize.h;h=eae90399542d3130ba38e08c24d87f6f13a7ff50;hb=518f751d385b733adbf43fe4056403740709edec;hp=ed016ca0b9ddd26dd5e8e871b25a0f15484e2881;hpb=f7b29fcfe408965c9cba79095eb05c49eca4a98e;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index ed016ca0..eae90399 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -11,8 +11,7 @@ namespace GL { namespace SL { /** Finds functions which are candidates for inlining. Currently this means -functions which have no parameters, are only called once, and that call occurs -after the definition of the function. */ +functions which have no parameters and are only called once. */ class InlineableFunctionLocator: private TraversingVisitor { private: @@ -30,20 +29,39 @@ private: virtual void visit(FunctionDeclaration &); }; +/** Collects declarations referenced by a function. */ +class InlineDependencyCollector: private TraversingVisitor +{ +private: + std::set dependencies; + +public: + const std::set &apply(FunctionDeclaration &f) { f.visit(*this); return dependencies; } + +private: + virtual void visit(VariableReference &); + virtual void visit(InterfaceBlockReference &); + virtual void visit(FunctionCall &); + virtual void visit(VariableDeclaration &); +}; + /** Inlines functions. Internally uses InlineableFunctionLocator to find candidate functions. Only functions which consist of a single return statement are inlined. */ class FunctionInliner: private TraversingVisitor { private: + Stage *stage; std::set inlineable; + FunctionDeclaration *current_function; unsigned extract_result; RefPtr inline_result; + bool any_inlined; public: FunctionInliner(); - void apply(Stage &); + bool apply(Stage &); private: void visit_and_inline(RefPtr &); @@ -54,6 +72,7 @@ private: virtual void visit(MemberAccess &); virtual void visit(FunctionCall &); virtual void visit(VariableDeclaration &); + virtual void visit(FunctionDeclaration &); virtual void visit(Return &); };