diff src/pt-jit.cc @ 15023:75d1bc2fd6d2

Compile top level while loops in JIT. * src/pt-eval.cc (tree_evaluator::visit_while_command): Try compile while loops. * src/pt-jit.cc (jit_convert::jit_convert): Add first terminator to worklist. (tree_jit::execute): New overload. * src/pt-jit.h (tree_jit::execute): New overload. * src/pt-loop.cc (tree_while_command::~tree_while_command): Delete compiled. (tree_simple_for_command::~tree_simple_for_command): Only delete compiled if JIT is enabled. * src/pt-loop.h (tree_while_command::get_info, tree_while_command::stash_info): New function.
author Max Brister <max@2bass.com>
date Thu, 26 Jul 2012 12:17:56 -0500
parents 005cb78e1dd1
children 741d2dbcc117
line wrap: on
line diff
--- a/src/pt-jit.cc	Thu Jul 26 09:43:23 2012 -0700
+++ b/src/pt-jit.cc	Thu Jul 26 12:17:56 2012 -0500
@@ -92,6 +92,10 @@
        iter != constants.end (); ++iter)
     append_users (*iter);
 
+  // the entry block terminator may be a regular branch statement
+  if (entry_block->terminator ())
+    push_worklist (entry_block->terminator ());
+
   // FIXME: Describe algorithm here
   while (worklist.size ())
     {
@@ -1475,6 +1479,23 @@
 }
 
 bool
+tree_jit::execute (tree_while_command& cmd)
+{
+  if (! initialize ())
+    return false;
+
+  jit_info *info = cmd.get_info ();
+  if (! info || ! info->match ())
+    {
+      delete info;
+      info = new jit_info (*this, cmd);
+      cmd.stash_info (info);
+    }
+
+  return info->execute ();
+}
+
+bool
 tree_jit::initialize (void)
 {
   if (engine)
@@ -1708,4 +1729,12 @@
 %! test_set = gen_test (10000);
 %! assert (all (vectorized (test_set, 3) == loopy (test_set, 3)));
 
+%!test
+%! niter = 1001;
+%! i = 0;
+%! while (i < niter)
+%!   i = i + 1;
+%! endwhile
+%! assert (i == niter);
+
 */