ir_function_inlining: Re-add the "s/return/retval =/" functionality.
authorEric Anholt <eric@anholt.net>
Thu, 24 Jun 2010 15:59:57 +0000 (08:59 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 24 Jun 2010 20:32:35 +0000 (13:32 -0700)
I ripped it out with the cloning changes yesterday, and should have
tested and noticed that there were now returns all over.

ir_function_inlining.cpp
ir_hierarchical_visitor.cpp
ir_hierarchical_visitor.h

index effb01c8f68dbdf53ecdbb3684f27eb5fd9ae66e..d74de650e0ac2184ef6d7ae8a5e60d1851360c2e 100644 (file)
@@ -91,6 +91,26 @@ do_function_inlining(exec_list *instructions)
    return v.progress;
 }
 
+static void
+replace_return_with_assignment(ir_instruction *ir, void *data)
+{
+   ir_variable *retval = (ir_variable *)data;
+   ir_return *ret = ir->as_return();
+
+   if (ret) {
+      if (ret->value) {
+        ir_rvalue *lhs = new ir_dereference_variable(retval);
+        ret->insert_before(new ir_assignment(lhs, ret->value, NULL));
+        ret->remove();
+      } else {
+        /* un-valued return has to be the last return, or we shouldn't
+         * have reached here. (see can_inline()).
+         */
+        assert(!ret->next->is_tail_sentinal());
+      }
+   }
+}
+
 ir_rvalue *
 ir_call::generate_inline(ir_instruction *next_ir)
 {
@@ -145,8 +165,10 @@ ir_call::generate_inline(ir_instruction *next_ir)
    /* Generate the inlined body of the function. */
    foreach_iter(exec_list_iterator, iter, callee->body) {
       ir_instruction *ir = (ir_instruction *)iter.get();
+      ir_instruction *new_ir = ir->clone(ht);
 
-      next_ir->insert_before(ir->clone(ht));
+      next_ir->insert_before(new_ir);
+      visit_tree(new_ir, replace_return_with_assignment, retval);
    }
 
    /* Copy back the value of any 'out' parameters from the function body
index 63ce8784adbbf7bdcdc13b20f4b38d188290b9ec..0d520b127f287500a7974a94668774bd46fa5677 100644 (file)
@@ -268,3 +268,17 @@ ir_hierarchical_visitor::run(exec_list *instructions)
         break;
    }
 }
+
+
+void
+visit_tree(ir_instruction *ir,
+          void (*callback)(class ir_instruction *ir, void *data),
+          void *data)
+{
+   ir_hierarchical_visitor v;
+
+   v.callback = callback;
+   v.data = data;
+
+   ir->accept(&v);
+}
index e741155e19f344ed3995d2c171d0578dc1fc39e0..8b9e49dab13b707a0c1ad55f251687876446eddf 100644 (file)
@@ -139,7 +139,6 @@ public:
     */
    void run(struct exec_list *instructions);
 
-protected:
    /**
     * Callback function that is invoked on entry to each node visited.
     *
@@ -156,4 +155,8 @@ protected:
    void *data;
 };
 
+void visit_tree(ir_instruction *ir,
+               void (*callback)(class ir_instruction *ir, void *data),
+               void *data);
+
 #endif /* IR_HIERARCHICAL_VISITOR_H */