comparison 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
comparison
equal deleted inserted replaced
15022:e47b4e8c2714 15023:75d1bc2fd6d2
89 89
90 // initialize the worklist to instructions derived from constants 90 // initialize the worklist to instructions derived from constants
91 for (std::list<jit_value *>::iterator iter = constants.begin (); 91 for (std::list<jit_value *>::iterator iter = constants.begin ();
92 iter != constants.end (); ++iter) 92 iter != constants.end (); ++iter)
93 append_users (*iter); 93 append_users (*iter);
94
95 // the entry block terminator may be a regular branch statement
96 if (entry_block->terminator ())
97 push_worklist (entry_block->terminator ());
94 98
95 // FIXME: Describe algorithm here 99 // FIXME: Describe algorithm here
96 while (worklist.size ()) 100 while (worklist.size ())
97 { 101 {
98 jit_instruction *next = worklist.front (); 102 jit_instruction *next = worklist.front ();
1457 tree_jit::~tree_jit (void) 1461 tree_jit::~tree_jit (void)
1458 {} 1462 {}
1459 1463
1460 bool 1464 bool
1461 tree_jit::execute (tree_simple_for_command& cmd) 1465 tree_jit::execute (tree_simple_for_command& cmd)
1466 {
1467 if (! initialize ())
1468 return false;
1469
1470 jit_info *info = cmd.get_info ();
1471 if (! info || ! info->match ())
1472 {
1473 delete info;
1474 info = new jit_info (*this, cmd);
1475 cmd.stash_info (info);
1476 }
1477
1478 return info->execute ();
1479 }
1480
1481 bool
1482 tree_jit::execute (tree_while_command& cmd)
1462 { 1483 {
1463 if (! initialize ()) 1484 if (! initialize ())
1464 return false; 1485 return false;
1465 1486
1466 jit_info *info = cmd.get_info (); 1487 jit_info *info = cmd.get_info ();
1706 1727
1707 %!test 1728 %!test
1708 %! test_set = gen_test (10000); 1729 %! test_set = gen_test (10000);
1709 %! assert (all (vectorized (test_set, 3) == loopy (test_set, 3))); 1730 %! assert (all (vectorized (test_set, 3) == loopy (test_set, 3)));
1710 1731
1732 %!test
1733 %! niter = 1001;
1734 %! i = 0;
1735 %! while (i < niter)
1736 %! i = i + 1;
1737 %! endwhile
1738 %! assert (i == niter);
1739
1711 */ 1740 */