From: Mikko Rasa Date: Mon, 1 Mar 2021 14:19:09 +0000 (+0200) Subject: Clarify SL::Compiler::optimize return values by using an enum X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f7b29fcfe408965c9cba79095eb05c49eca4a98e;p=libs%2Fgl.git Clarify SL::Compiler::optimize return values by using an enum --- diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index c68b67bd..cedd25e7 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -76,9 +76,11 @@ void Compiler::compile(Mode mode) { for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) generate(*i, mode); - for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ) + unsigned n = 0; + for(list::iterator i=module->stages.begin(); (i!=module->stages.end() && n<10000); ++n) { - if(optimize(*i)) + OptimizeResult result = optimize(*i); + if(result==REDO_PREVIOUS) i = module->stages.begin(); else ++i; @@ -240,7 +242,7 @@ void Compiler::generate(Stage &stage, Mode mode) LegacyConverter().apply(stage, features); } -bool Compiler::optimize(Stage &stage) +Compiler::OptimizeResult Compiler::optimize(Stage &stage) { ConstantConditionEliminator().apply(stage); @@ -250,10 +252,10 @@ bool Compiler::optimize(Stage &stage) /* Removing variables or functions may cause things from the previous stage to become unused. */ - bool result = UnusedVariableRemover().apply(stage); - result |= UnusedFunctionRemover().apply(stage); + bool any_removed = UnusedVariableRemover().apply(stage); + any_removed |= UnusedFunctionRemover().apply(stage); - return result; + return any_removed ? REDO_PREVIOUS : NEXT_STAGE; } void Compiler::finalize(Stage &stage, Mode mode) diff --git a/source/glsl/compiler.h b/source/glsl/compiler.h index 1f3cbee4..64cbac4f 100644 --- a/source/glsl/compiler.h +++ b/source/glsl/compiler.h @@ -21,6 +21,12 @@ public: }; private: + enum OptimizeResult + { + NEXT_STAGE, + REDO_PREVIOUS + }; + Features features; Module *module; std::vector imported_names; @@ -102,9 +108,9 @@ private: variables. */ void generate(Stage &, Mode); - /** Applies optimizations to a stage. The return value indicates if the - preceding stage should be processed again. */ - bool optimize(Stage &); + /** Applies optimizations to a stage. The return value indicates which + stage should be optimized next. */ + OptimizeResult optimize(Stage &); /** Performs final adjustments on a stage after compilation. */ void finalize(Stage &, Mode);