glsl2: Perform initial bits of loop analysis during compilation
[mesa.git] / src / glsl / glsl_parser_extras.cpp
index d1bb1ae5ecce29763bbb0b00966252557a62e240..2d045ac9c7ab6b85ae58df4aadce73988c203124 100644 (file)
 
 extern "C" {
 #include <talloc.h>
-#include "main/mtypes.h"
+#include "main/core.h" /* for struct __GLcontextRec */
 }
 
 #include "ast.h"
 #include "glsl_parser_extras.h"
 #include "glsl_parser.h"
 #include "ir_optimization.h"
+#include "loop_analysis.h"
 
 _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct __GLcontextRec *ctx,
                                               GLenum target, void *mem_ctx)
@@ -739,5 +740,39 @@ do_common_optimization(exec_list *ir, bool linked)
    progress = do_swizzle_swizzle(ir) || progress;
    progress = do_noop_swizzle(ir) || progress;
 
+   loop_state *ls = analyze_loop_variables(ir);
+   progress = set_loop_controls(ir, ls) || progress;
+   delete ls;
+
    return progress;
 }
+
+extern "C" {
+
+/**
+ * To be called at GL teardown time, this frees compiler datastructures.
+ *
+ * After calling this, any previously compiled shaders and shader
+ * programs would be invalid.  So this should happen at approximately
+ * program exit.
+ */
+void
+_mesa_destroy_shader_compiler(void)
+{
+   _mesa_destroy_shader_compiler_caches();
+
+   _mesa_glsl_release_types();
+}
+
+/**
+ * Releases compiler caches to trade off performance for memory.
+ *
+ * Intended to be used with glReleaseShaderCompiler().
+ */
+void
+_mesa_destroy_shader_compiler_caches(void)
+{
+   _mesa_glsl_release_functions();
+}
+
+}