]> git.tdb.fi Git - libs/gl.git/commitdiff
Return back to first stage after some optimization happens
authorMikko Rasa <tdb@tdb.fi>
Sat, 12 Nov 2016 00:04:14 +0000 (02:04 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 12 Nov 2016 00:04:14 +0000 (02:04 +0200)
Unused variable removal can propagate towards earlier stages so those
have to be checked again.

source/programcompiler.cpp
source/programcompiler.h

index 79031e41eeda0cc970162d3632c31eaadd253ae5..934416c28684f250fa8c37b9d842f5f05c39b7a9 100644 (file)
@@ -55,8 +55,13 @@ void ProgramCompiler::process()
 {
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
                generate(*i);
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               optimize(*i);
+       for(list<Stage>::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<VariableRenamer>(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)
index 3b63c5e906bd257bdd568a6d89527e5fd2e01fb1..34b64b557ca29a9185dc2f5e2aacaa1420bbf325 100644 (file)
@@ -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<typename T>
        static void apply(ProgramSyntax::Stage &);