changeset 14944:c0a5ab3b9278

jit_const no longer inherits from jit_instruction
author Max Brister <max@2bass.com>
date Fri, 08 Jun 2012 15:30:07 -0500
parents 8efcaf5aa233
children 591aeec5c520
files src/pt-jit.cc src/pt-jit.h
diffstat 2 files changed, 35 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/pt-jit.cc	Fri Jun 08 13:35:40 2012 -0500
+++ b/src/pt-jit.cc	Fri Jun 08 15:30:07 2012 -0500
@@ -1226,7 +1226,7 @@
       arguments.push_back (std::make_pair (extract->name (), true));
 
   convert_llvm to_llvm;
-  function = to_llvm.convert (module, arguments, blocks);
+  function = to_llvm.convert (module, arguments, blocks, constants);
 
 #ifdef OCTAVE_JIT_DEBUG
   std::cout << "-------------------- llvm ir --------------------";
@@ -1289,18 +1289,15 @@
 jit_convert::visit_colon_expression (tree_colon_expression& expr)
 {
   // in the futher we need to add support for classes and deal with rvalues
-  jit_instruction *base = visit (expr.base ());
-  jit_instruction *limit = visit (expr.limit ());
-  jit_instruction *increment;
+  jit_value *base = visit (expr.base ());
+  jit_value *limit = visit (expr.limit ());
+  jit_value *increment;
   tree_expression *tinc = expr.increment ();
 
   if (tinc)
     increment = visit (tinc);
   else
-    {
-      increment = create<jit_const_scalar> (1);
-      block->append (increment);
-    }
+    increment = create<jit_const_scalar> (1);
 
   result = block->append (create<jit_call> (jit_typeinfo::make_range, base,
                                             limit, increment));
@@ -1411,9 +1408,7 @@
 
   block = check_block;
   const jit_function& add_fn = jit_typeinfo::binary_op (octave_value::op_add);
-  jit_instruction *one = create<jit_const_index> (1);
-  block->append (one);
-
+  jit_value *one = create<jit_const_index> (1);
   jit_call *iter_inc = create<jit_call> (add_fn, iterator, one);
   block->append (iter_inc);
   block->append (create<jit_assign> (iterator, iter_inc));
@@ -1528,9 +1523,9 @@
       if (! tic->is_else_clause ())
         {
           tree_expression *expr = tic->condition ();
-          jit_instruction *cond = visit (expr);
-          cond = create<jit_call> (&jit_typeinfo::logically_true, cond);
-          block->append (cond);
+          jit_value *cond = visit (expr);
+          jit_instruction *check = create<jit_call> (&jit_typeinfo::logically_true, cond);
+          block->append (check);
 
           jit_block *next = create<jit_block> (block->name () + "a");
           blocks.push_back (next);
@@ -1540,7 +1535,7 @@
           jit_block *body = create<jit_block> (i == 0 ? "if_body" : "ifelse_body");
           blocks.push_back (body);
 
-          jit_instruction *br = create<jit_cond_break> (cond, body,
+          jit_instruction *br = create<jit_cond_break> (check, body,
                                                         entry_blocks[i + 1]);
           block->append (br);
           block = body;
@@ -1615,8 +1610,6 @@
     }
   else
     fail ("Unknown constant");
-
-  block->append (result);
 }
 
 void
@@ -1660,7 +1653,7 @@
 {
   // resolve rhs
   tree_expression *rhs = tsa.right_hand_side ();
-  jit_instruction *rhsv = visit (rhs);
+  jit_value *rhsv = visit (rhs);
 
   // resolve lhs
   tree_expression *lhs = tsa.left_hand_side ();
@@ -1693,7 +1686,7 @@
       else
         do_bind_ans = (! expr->is_assignment_expression ());
 
-      jit_instruction *expr_result = visit (expr);
+      jit_value *expr_result = visit (expr);
 
       if (do_bind_ans)
         do_assign ("ans", expr_result, expr->print_result ());
@@ -1784,8 +1777,8 @@
   return vmap[vname] = var;
 }
 
-jit_instruction *
-jit_convert::do_assign (const std::string& lhs, jit_instruction *rhs,
+jit_value *
+jit_convert::do_assign (const std::string& lhs, jit_value *rhs,
                         bool print)
 {
   jit_variable *var = get_variable (lhs);
@@ -1798,16 +1791,16 @@
       block->append (create<jit_call> (print_fn, name, var));
     }
 
-  return rhs;
+  return var;
 }
 
-jit_instruction *
+jit_value *
 jit_convert::visit (tree& tee)
 {
   result = 0;
   tee.accept (*this);
 
-  jit_instruction *ret = result;
+  jit_value *ret = result;
   result = 0;
   return ret;
 }
@@ -1990,7 +1983,8 @@
 llvm::Function *
 jit_convert::convert_llvm::convert (llvm::Module *module,
                                     const std::vector<std::pair< std::string, bool> >& args,
-                                    const std::list<jit_block *>& blocks)
+                                    const std::list<jit_block *>& blocks,
+                                    const std::list<jit_value *>& constants)
 {
   jit_type *any = jit_typeinfo::get_any ();
 
@@ -2027,6 +2021,12 @@
       jit_block *first = *blocks.begin ();
       builder.CreateBr (first->to_llvm ());
 
+      // constants aren't in the IR, we visit those first
+      for (std::list<jit_value *>::const_iterator iter = constants.begin ();
+           iter != constants.end (); ++iter)
+        if (! isa<jit_instruction> (*iter))
+          visit (*iter);
+
       // convert all instructions
       for (biter = blocks.begin (); biter != blocks.end (); ++biter)
         visit (*biter);
--- a/src/pt-jit.h	Fri Jun 08 13:35:40 2012 -0500
+++ b/src/pt-jit.h	Fri Jun 08 15:30:07 2012 -0500
@@ -931,7 +931,7 @@
 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T,
           bool QUOTE>
 class
-jit_const : public jit_instruction
+jit_const : public jit_value
 {
 public:
   typedef PASS_T pass_t;
@@ -946,7 +946,7 @@
   virtual std::ostream& print (std::ostream& os, size_t indent) const
   {
     print_indent (os, indent);
-    short_print (os) << " = ";
+    jit_print (os, type ()) << ": ";
     if (QUOTE)
       os << "\"";
     os << mvalue;
@@ -1326,7 +1326,7 @@
 jit_assign : public jit_assign_base
 {
 public:
-  jit_assign (jit_variable *adest, jit_instruction *asrc)
+  jit_assign (jit_variable *adest, jit_value *asrc)
     : jit_assign_base (adest, adest, asrc) {}
 
   jit_instruction *src (void) const
@@ -1868,7 +1868,7 @@
   type_bound_vector bounds;
 
   // used instead of return values from visit_* functions
-  jit_instruction *result;
+  jit_value *result;
 
   jit_block *entry_block;
 
@@ -1893,12 +1893,12 @@
 
   jit_variable *get_variable (const std::string& vname);
 
-  jit_instruction *do_assign (const std::string& lhs, jit_instruction *rhs,
-                              bool print);
+  jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print);
+                        
 
-  jit_instruction *visit (tree *tee) { return visit (*tee); }
+  jit_value *visit (tree *tee) { return visit (*tee); }
 
-  jit_instruction *visit (tree& tee);
+  jit_value *visit (tree& tee);
 
   void append_users (jit_value *v)
   {
@@ -1967,7 +1967,8 @@
   public:
     llvm::Function *convert (llvm::Module *module,
                              const std::vector<std::pair<std::string, bool> >& args,
-                             const std::list<jit_block *>& blocks);
+                             const std::list<jit_block *>& blocks,
+                             const std::list<jit_value *>& constants);
 
 #define JIT_METH(clname)                        \
     virtual void visit (jit_ ## clname&);