changeset 14962:90a7a2af2cd5

Keep track of variables after SSA construction * src/pt-jit.cc (jit_instruction::do_construct_ssa): New function. (jit_convert::do_construct_ssa): Use instruction::construct_ssa. (jit_convert::convert_llvm::visit): Stash llvm value for jit_assign. * src/pt-jit.h (jit_instruction::construct_ssa, jit_assign_base::short_print, jit_assign::infer, jit_phi::construct_ssa): New function. (jit_convert::do_construct_ssa): New declaration. (jit_assign_base::jit_assign_base): Change number of arguments. (jit_assign::jit_assign): Do not keep track of dest in arguments. (jit_assign::print): Print correct SSA form.
author Max Brister <max@2bass.com>
date Tue, 19 Jun 2012 18:48:39 -0500
parents 903a5ee2cdde
children 709f50069722
files src/pt-jit.cc src/pt-jit.h
diffstat 2 files changed, 54 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/pt-jit.cc	Tue Jun 19 13:10:10 2012 -0500
+++ b/src/pt-jit.cc	Tue Jun 19 18:48:39 2012 -0500
@@ -1046,6 +1046,18 @@
   return os << "#" << mid;
 }
 
+void
+jit_instruction::do_construct_ssa (size_t start, size_t end)
+{
+  for (size_t i = start; i < end; ++i)
+    {
+      jit_value *arg = argument (i);
+      jit_variable *var = dynamic_cast<jit_variable *> (arg);
+      if (var)
+        stash_argument (i, var->top ());
+    }
+}
+
 // -------------------- jit_block --------------------
 void
 jit_block::replace_with (jit_value *value)
@@ -1800,9 +1812,7 @@
 void
 jit_convert::visit_identifier (tree_identifier& ti)
 {
-  const jit_function& fn = jit_typeinfo::grab ();
-  jit_value *decl = get_variable (ti.name ());
-  result = block->append (create<jit_call> (fn, decl));
+  result = get_variable (ti.name ());
 }
 
 void
@@ -2264,18 +2274,7 @@
   for (jit_block::iterator iter = block.begin (); iter != block.end (); ++iter)
     {
       jit_instruction *instr = *iter;
-      if (! isa<jit_phi> (instr))
-        {
-          for (size_t i = isa<jit_assign> (instr); i < instr->argument_count ();
-               ++i)
-            {
-              jit_value *arg = instr->argument (i);
-              jit_variable *var = dynamic_cast<jit_variable *> (arg);
-              if (var)
-                instr->stash_argument (i, var->top ());
-            }
-        }
-
+      instr->construct_ssa ();
       instr->push_variable ();
     }
 
@@ -2679,8 +2678,10 @@
 }
 
 void
-jit_convert::convert_llvm::visit (jit_assign&)
-{}
+jit_convert::convert_llvm::visit (jit_assign& assign)
+{
+  assign.stash_llvm (assign.src ()->to_llvm ());
+}
 
 void
 jit_convert::convert_llvm::visit (jit_argument&)
--- a/src/pt-jit.h	Tue Jun 19 13:10:10 2012 -0500
+++ b/src/pt-jit.h	Tue Jun 19 18:48:39 2012 -0500
@@ -52,7 +52,8 @@
 // For loops are compiled again!
 // if, elseif, and else statements compile again!
 // break and continue now work!
-// Additionally, make check passes using jit.
+//
+// NOTE: Matrix access is currently broken!
 //
 // The octave low level IR is a linear IR, it works by converting everything to
 // calls to jit_functions. This turns expressions like c = a + b into
@@ -1001,6 +1002,11 @@
 
   virtual void pop_variable (void) {}
 
+  virtual void construct_ssa (void)
+  {
+    do_construct_ssa (0, argument_count ());
+  }
+
   virtual bool infer (void) { return false; }
 
   void remove (void);
@@ -1025,6 +1031,10 @@
 
   size_t id (void) const { return mid; }
 protected:
+
+  // Do SSA replacement on arguments in [start, end)
+  void do_construct_ssa (size_t start, size_t end);
+
   std::vector<jit_type *> already_infered;
 private:
   static size_t next_id (bool reset = false)
@@ -1467,8 +1477,8 @@
   jit_assign_base (jit_variable *adest, size_t npred) : jit_instruction (npred),
                                                         mdest (adest) {}
 
-  jit_assign_base (jit_variable *adest, jit_value *arg0, jit_value *arg1)
-    : jit_instruction (arg0, arg1), mdest (adest) {}
+  jit_assign_base (jit_variable *adest, jit_value *arg0)
+    : jit_instruction (arg0), mdest (adest) {}
 
   jit_variable *dest (void) const { return mdest; }
 
@@ -1481,6 +1491,15 @@
   {
     mdest->pop ();
   }
+
+  virtual std::ostream& short_print (std::ostream& os) const
+  {
+    if (type ())
+      jit_print (os, type ()) << ": ";
+
+    dest ()->short_print (os);
+    return os << "#" << id ();
+  }
 private:
   jit_variable *mdest;
 };
@@ -1490,26 +1509,31 @@
 {
 public:
   jit_assign (jit_variable *adest, jit_value *asrc)
-    : jit_assign_base (adest, adest, asrc) {}
+    : jit_assign_base (adest, asrc) {}
 
   jit_instruction *src (void) const
   {
-    return static_cast<jit_instruction *> (argument (1));
+    return static_cast<jit_instruction *> (argument (0));
   }
 
-  virtual void push_variable (void)
+  virtual bool infer (void)
   {
-    dest ()->push (src ());
+    jit_type *stype = src ()->type ();
+    if (stype != type())
+      {
+        stash_type (stype);
+        return true;
+      }
+
+    return false;
   }
 
   virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
   {
-    return print_indent (os, indent) << *dest () << " = " << *src ();
+    return print_indent (os, indent) << *this << " = " << *src ();
   }
 
   JIT_VALUE_ACCEPT;
-private:
-  jit_variable *mdest;
 };
 
 class
@@ -1543,6 +1567,8 @@
     return inc->branch_llvm (parent ());
   }
 
+  virtual void construct_ssa (void) {}
+
   virtual bool infer (void);
 
   virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
@@ -1570,15 +1596,6 @@
     return os;
   }
 
-  virtual std::ostream& short_print (std::ostream& os) const
-  {
-    if (type ())
-      jit_print (os, type ()) << ": ";
-
-    dest ()->short_print (os);
-    return os << "#" << id ();
-  }
-
   JIT_VALUE_ACCEPT;
 private:
   std::vector<jit_phi_incomming> mincomming;