comparison 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
comparison
equal deleted inserted replaced
15181:ed2b911a2fb3 15182:a7a56b436de2
34 34
35 #include <llvm/BasicBlock.h> 35 #include <llvm/BasicBlock.h>
36 #include <llvm/Instructions.h> 36 #include <llvm/Instructions.h>
37 37
38 #include "error.h" 38 #include "error.h"
39 #include "pt-jit.h" 39
40 // -------------------- jit_factory --------------------
41 jit_factory::~jit_factory (void)
42 {
43 for (value_list::iterator iter = all_values.begin ();
44 iter != all_values.end (); ++iter)
45 delete *iter;
46 }
47
48 void
49 jit_factory::track_value (jit_value *value)
50 {
51 if (value->type ())
52 mconstants.push_back (value);
53 all_values.push_back (value);
54 }
55
56 // -------------------- jit_block_list --------------------
57 void
58 jit_block_list::insert_after (iterator iter, jit_block *ablock)
59 {
60 ++iter;
61 insert_before (iter, ablock);
62 }
63
64 void
65 jit_block_list::insert_after (jit_block *loc, jit_block *ablock)
66 {
67 insert_after (loc->location (), ablock);
68 }
69
70 void
71 jit_block_list::insert_before (iterator iter, jit_block *ablock)
72 {
73 iter = mlist.insert (iter, ablock);
74 ablock->stash_location (iter);
75 }
76
77 void
78 jit_block_list::insert_before (jit_block *loc, jit_block *ablock)
79 {
80 insert_before (loc->location (), ablock);
81 }
82
83 void
84 jit_block_list::push_back (jit_block *b)
85 {
86 mlist.push_back (b);
87 iterator iter = mlist.end ();
88 b->stash_location (--iter);
89 }
40 90
41 // -------------------- jit_use -------------------- 91 // -------------------- jit_use --------------------
42 jit_block * 92 jit_block *
43 jit_use::user_parent (void) const 93 jit_use::user_parent (void) const
44 { 94 {
394 instr->pop_variable (); 444 instr->pop_variable ();
395 } 445 }
396 } 446 }
397 447
398 jit_block * 448 jit_block *
399 jit_block::maybe_split (jit_convert& convert, jit_block *asuccessor) 449 jit_block::maybe_split (jit_factory& factory, jit_block_list& blocks,
450 jit_block *asuccessor)
400 { 451 {
401 if (successor_count () > 1) 452 if (successor_count () > 1)
402 { 453 {
403 jit_terminator *term = terminator (); 454 jit_terminator *term = terminator ();
404 size_t idx = term->successor_index (asuccessor); 455 size_t idx = term->successor_index (asuccessor);
405 jit_block *split = convert.create<jit_block> ("phi_split", mvisit_count); 456 jit_block *split = factory.create<jit_block> ("phi_split", mvisit_count);
406 457
407 // place after this to ensure define before use in the blocks list 458 // place after this to ensure define before use in the blocks list
408 convert.insert_after (this, split); 459 blocks.insert_after (this, split);
409 460
410 term->stash_argument (idx, split); 461 term->stash_argument (idx, split);
411 jit_branch *br = split->append (convert.create<jit_branch> (asuccessor)); 462 jit_branch *br = split->append (factory.create<jit_branch> (asuccessor));
412 replace_in_phi (asuccessor, split); 463 replace_in_phi (asuccessor, split);
413 464
414 if (alive ()) 465 if (alive ())
415 { 466 {
416 split->mark_alive (); 467 split->mark_alive ();
594 645
595 return false; 646 return false;
596 } 647 }
597 648
598 // -------------------- jit_magic_end -------------------- 649 // -------------------- jit_magic_end --------------------
599 jit_magic_end::context::context (jit_convert& convert, jit_value *avalue, 650 jit_magic_end::context::context (jit_factory& factory, jit_value *avalue,
600 size_t aindex, size_t acount) 651 size_t aindex, size_t acount)
601 : value (avalue), index (convert.create<jit_const_index> (aindex)), 652 : value (avalue), index (factory.create<jit_const_index> (aindex)),
602 count (convert.create<jit_const_index> (acount)) 653 count (factory.create<jit_const_index> (acount))
603 {} 654 {}
604 655
605 jit_magic_end::jit_magic_end (const std::vector<context>& full_context) 656 jit_magic_end::jit_magic_end (const std::vector<context>& full_context)
606 : contexts (full_context) 657 : contexts (full_context)
607 { 658 {