Module: Mesa
Branch: master
Commit: 01a851c296347d8e9d2166b3c83eab97404c0670
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=01a851c296347d8e9d2166b3c83eab97404c0670

Author: Paul Berry <[email protected]>
Date:   Wed Aug  3 16:16:59 2011 -0700

glsl: When linking, emit functions at the tail of the final linked program.

When link_functions.cpp adds a new function to the final linked
program, it needs to add it after any global variable declarations
that the function refers to, otherwise the IR will be invalid (because
variable declarations must occur before variable accesses).  The
easiest way to do that is to have the linker emit functions to the
tail of the final linked program.

The linker used to emit functions to the head of the final linked
program, in an effort to keep callees sorted before their callers.
However, this was not reliable: it didn't work for functions declared
or defined in the same compilation unit as main, for diamond-shaped
patterns in the call graph, or for some obscure cases involving
overloaded functions.  And no code currently relies on this sort
order.

No Piglit regressions with i965 Ironlake.

Reviewed-by: Kenneth Graunke <[email protected]>

---

 src/glsl/link_functions.cpp |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/glsl/link_functions.cpp b/src/glsl/link_functions.cpp
index d40f771..acee327 100644
--- a/src/glsl/link_functions.cpp
+++ b/src/glsl/link_functions.cpp
@@ -104,10 +104,12 @@ public:
       if (f == NULL) {
         f = new(linked) ir_function(name);
 
-        /* Add the new function to the linked IR.
+        /* Add the new function to the linked IR.  Put it at the end
+          * so that it comes after any global variable declarations
+          * that it refers to.
          */
         linked->symbols->add_function(f);
-        linked->ir->push_head(f);
+        linked->ir->push_tail(f);
       }
 
       ir_function_signature *linked_sig =

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to