# HG changeset patch # User Max Brister # Date 1340149719 18000 # Node ID 90a7a2af2cd5fa978835b70ff2d11c46a156a970 # Parent 903a5ee2cdde36df2fe7205da94ce042641aa9aa Keep track of variables after SSA construction * src/pt-jit.cc (jit_instruction::do_construct_ssa): New function. (jit_convert::do_construct_ssa): Use instruction::construct_ssa. (jit_convert::convert_llvm::visit): Stash llvm value for jit_assign. * src/pt-jit.h (jit_instruction::construct_ssa, jit_assign_base::short_print, jit_assign::infer, jit_phi::construct_ssa): New function. (jit_convert::do_construct_ssa): New declaration. (jit_assign_base::jit_assign_base): Change number of arguments. (jit_assign::jit_assign): Do not keep track of dest in arguments. (jit_assign::print): Print correct SSA form. diff -r 903a5ee2cdde -r 90a7a2af2cd5 src/pt-jit.cc --- a/src/pt-jit.cc Tue Jun 19 13:10:10 2012 -0500 +++ b/src/pt-jit.cc Tue Jun 19 18:48:39 2012 -0500 @@ -1046,6 +1046,18 @@ return os << "#" << mid; } +void +jit_instruction::do_construct_ssa (size_t start, size_t end) +{ + for (size_t i = start; i < end; ++i) + { + jit_value *arg = argument (i); + jit_variable *var = dynamic_cast (arg); + if (var) + stash_argument (i, var->top ()); + } +} + // -------------------- jit_block -------------------- void jit_block::replace_with (jit_value *value) @@ -1800,9 +1812,7 @@ void jit_convert::visit_identifier (tree_identifier& ti) { - const jit_function& fn = jit_typeinfo::grab (); - jit_value *decl = get_variable (ti.name ()); - result = block->append (create (fn, decl)); + result = get_variable (ti.name ()); } void @@ -2264,18 +2274,7 @@ for (jit_block::iterator iter = block.begin (); iter != block.end (); ++iter) { jit_instruction *instr = *iter; - if (! isa (instr)) - { - for (size_t i = isa (instr); i < instr->argument_count (); - ++i) - { - jit_value *arg = instr->argument (i); - jit_variable *var = dynamic_cast (arg); - if (var) - instr->stash_argument (i, var->top ()); - } - } - + instr->construct_ssa (); instr->push_variable (); } @@ -2679,8 +2678,10 @@ } void -jit_convert::convert_llvm::visit (jit_assign&) -{} +jit_convert::convert_llvm::visit (jit_assign& assign) +{ + assign.stash_llvm (assign.src ()->to_llvm ()); +} void jit_convert::convert_llvm::visit (jit_argument&) diff -r 903a5ee2cdde -r 90a7a2af2cd5 src/pt-jit.h --- a/src/pt-jit.h Tue Jun 19 13:10:10 2012 -0500 +++ b/src/pt-jit.h Tue Jun 19 18:48:39 2012 -0500 @@ -52,7 +52,8 @@ // For loops are compiled again! // if, elseif, and else statements compile again! // break and continue now work! -// Additionally, make check passes using jit. +// +// NOTE: Matrix access is currently broken! // // The octave low level IR is a linear IR, it works by converting everything to // calls to jit_functions. This turns expressions like c = a + b into @@ -1001,6 +1002,11 @@ virtual void pop_variable (void) {} + virtual void construct_ssa (void) + { + do_construct_ssa (0, argument_count ()); + } + virtual bool infer (void) { return false; } void remove (void); @@ -1025,6 +1031,10 @@ size_t id (void) const { return mid; } protected: + + // Do SSA replacement on arguments in [start, end) + void do_construct_ssa (size_t start, size_t end); + std::vector already_infered; private: static size_t next_id (bool reset = false) @@ -1467,8 +1477,8 @@ jit_assign_base (jit_variable *adest, size_t npred) : jit_instruction (npred), mdest (adest) {} - jit_assign_base (jit_variable *adest, jit_value *arg0, jit_value *arg1) - : jit_instruction (arg0, arg1), mdest (adest) {} + jit_assign_base (jit_variable *adest, jit_value *arg0) + : jit_instruction (arg0), mdest (adest) {} jit_variable *dest (void) const { return mdest; } @@ -1481,6 +1491,15 @@ { mdest->pop (); } + + virtual std::ostream& short_print (std::ostream& os) const + { + if (type ()) + jit_print (os, type ()) << ": "; + + dest ()->short_print (os); + return os << "#" << id (); + } private: jit_variable *mdest; }; @@ -1490,26 +1509,31 @@ { public: jit_assign (jit_variable *adest, jit_value *asrc) - : jit_assign_base (adest, adest, asrc) {} + : jit_assign_base (adest, asrc) {} jit_instruction *src (void) const { - return static_cast (argument (1)); + return static_cast (argument (0)); } - virtual void push_variable (void) + virtual bool infer (void) { - dest ()->push (src ()); + jit_type *stype = src ()->type (); + if (stype != type()) + { + stash_type (stype); + return true; + } + + return false; } virtual std::ostream& print (std::ostream& os, size_t indent = 0) const { - return print_indent (os, indent) << *dest () << " = " << *src (); + return print_indent (os, indent) << *this << " = " << *src (); } JIT_VALUE_ACCEPT; -private: - jit_variable *mdest; }; class @@ -1543,6 +1567,8 @@ return inc->branch_llvm (parent ()); } + virtual void construct_ssa (void) {} + virtual bool infer (void); virtual std::ostream& print (std::ostream& os, size_t indent = 0) const @@ -1570,15 +1596,6 @@ return os; } - virtual std::ostream& short_print (std::ostream& os) const - { - if (type ()) - jit_print (os, type ()) << ": "; - - dest ()->short_print (os); - return os << "#" << id (); - } - JIT_VALUE_ACCEPT; private: std::vector mincomming;