From: Mikko Rasa Date: Sat, 12 Nov 2016 00:04:14 +0000 (+0200) Subject: Return back to first stage after some optimization happens X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=96881e56ececfa3f4b0707dc168c687b35d249a0;p=libs%2Fgl.git Return back to first stage after some optimization happens Unused variable removal can propagate towards earlier stages so those have to be checked again. --- diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 79031e41..934416c2 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -55,8 +55,13 @@ void ProgramCompiler::process() { for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) generate(*i); - for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) - optimize(*i); + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ) + { + if(optimize(*i)) + i = module->stages.begin(); + else + ++i; + } } void ProgramCompiler::generate(Stage &stage) @@ -69,20 +74,16 @@ void ProgramCompiler::generate(Stage &stage) apply(stage); } -void ProgramCompiler::optimize(Stage &stage) +bool ProgramCompiler::optimize(Stage &stage) { - while(1) - { - UnusedVariableLocator unused_locator; - unused_locator.apply(stage); + UnusedVariableLocator unused_locator; + unused_locator.apply(stage); - NodeRemover remover; - remover.to_remove = unused_locator.unused_nodes; - remover.apply(stage); + NodeRemover remover; + remover.to_remove = unused_locator.unused_nodes; + remover.apply(stage); - if(!remover.n_removed) - break; - } + return remover.n_removed; } void ProgramCompiler::inject_block(Block &target, const Block &source) diff --git a/source/programcompiler.h b/source/programcompiler.h index 3b63c5e9..34b64b55 100644 --- a/source/programcompiler.h +++ b/source/programcompiler.h @@ -139,7 +139,7 @@ public: private: void process(); void generate(ProgramSyntax::Stage &); - void optimize(ProgramSyntax::Stage &); + bool optimize(ProgramSyntax::Stage &); static void inject_block(ProgramSyntax::Block &, const ProgramSyntax::Block &); template static void apply(ProgramSyntax::Stage &);