{
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)
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)
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 &);