diff src/interp-core/jit-ir.cc @ 15182:a7a56b436de2

Factor out jit_block_list and jit_factory from jit_convert * jit-ir.cc (jit_factory, jit_block_list): New class. (jit_block::maybe_split): Use jit_factory and jit_block_list instead of jit_convert. (jit_magic_end::context::context): Use jit_factory instead of jit_convert. * jit-ir.h (jit_factory, jit_block_list): New class. (jit_block::maybe_split): Use jit_block_list and jit_factory. (jit_magic_end::context::context) Use jit_factory. * pt-jit.cc (jit_convert): Use jit_factory and jit_block_list instead of internal methods. (jit_convert::append): Removed method. (jit_convert::create_checked_impl): Merg in jit_convert::create_check. (jit_convert::insert_before, jit_convert;:insert_after, jit_convert::~jit_convert, jit_convert::append): Remove method. (jit_convert_llvm::convert): Use jit_block_list. * pt-jit.h (jit_convert::~jit_convert, jit_convert::append): Remove declaration. (jit_convert::create, jit_convert::insert_before, jit_convert::insert_after, jit_convert::track_value): Remove method. (jit_convert_llvm::convert): Use jit_block_list.
author Max Brister <max@2bass.com>
date Wed, 15 Aug 2012 23:30:02 -0500
parents 7a19e8275d41
children ed4f4fb78586
line wrap: on
line diff
--- a/src/interp-core/jit-ir.cc	Wed Aug 15 22:36:59 2012 -0500
+++ b/src/interp-core/jit-ir.cc	Wed Aug 15 23:30:02 2012 -0500
@@ -36,7 +36,57 @@
 #include <llvm/Instructions.h>
 
 #include "error.h"
-#include "pt-jit.h"
+
+// -------------------- jit_factory --------------------
+jit_factory::~jit_factory (void)
+{
+  for (value_list::iterator iter = all_values.begin ();
+       iter != all_values.end (); ++iter)
+    delete *iter;
+}
+
+void
+jit_factory::track_value (jit_value *value)
+{
+  if (value->type ())
+    mconstants.push_back (value);
+  all_values.push_back (value);
+}
+
+// -------------------- jit_block_list --------------------
+void
+jit_block_list::insert_after (iterator iter, jit_block *ablock)
+{
+  ++iter;
+  insert_before (iter, ablock);
+}
+
+void
+jit_block_list::insert_after (jit_block *loc, jit_block *ablock)
+{
+  insert_after (loc->location (), ablock);
+}
+
+void
+jit_block_list::insert_before (iterator iter, jit_block *ablock)
+{
+  iter = mlist.insert (iter, ablock);
+  ablock->stash_location (iter);
+}
+
+void
+jit_block_list::insert_before (jit_block *loc, jit_block *ablock)
+{
+  insert_before (loc->location (), ablock);
+}
+
+void
+jit_block_list::push_back (jit_block *b)
+{
+  mlist.push_back (b);
+  iterator iter = mlist.end ();
+  b->stash_location (--iter);
+}
 
 // -------------------- jit_use --------------------
 jit_block *
@@ -396,19 +446,20 @@
 }
 
 jit_block *
-jit_block::maybe_split (jit_convert& convert, jit_block *asuccessor)
+jit_block::maybe_split (jit_factory& factory, jit_block_list& blocks,
+                        jit_block *asuccessor)
 {
   if (successor_count () > 1)
     {
       jit_terminator *term = terminator ();
       size_t idx = term->successor_index (asuccessor);
-      jit_block *split = convert.create<jit_block> ("phi_split", mvisit_count);
+      jit_block *split = factory.create<jit_block> ("phi_split", mvisit_count);
 
       // place after this to ensure define before use in the blocks list
-      convert.insert_after (this, split);
+      blocks.insert_after (this, split);
 
       term->stash_argument (idx, split);
-      jit_branch *br = split->append (convert.create<jit_branch> (asuccessor));
+      jit_branch *br = split->append (factory.create<jit_branch> (asuccessor));
       replace_in_phi (asuccessor, split);
 
       if (alive ())
@@ -596,10 +647,10 @@
 }
 
 // -------------------- jit_magic_end --------------------
-jit_magic_end::context::context (jit_convert& convert, jit_value *avalue,
+jit_magic_end::context::context (jit_factory& factory, jit_value *avalue,
                                  size_t aindex, size_t acount)
-  : value (avalue), index (convert.create<jit_const_index> (aindex)),
-    count (convert.create<jit_const_index> (acount))
+  : value (avalue), index (factory.create<jit_const_index> (aindex)),
+    count (factory.create<jit_const_index> (acount))
 {}
 
 jit_magic_end::jit_magic_end (const std::vector<context>& full_context)