comparison src/pt-jit.cc @ 15067:df4538e3b50b

ND scalar indexing in JIT. * src/jit-ir.cc (jit_magic_end::jit_magic_end): Use jit_magic_end::context. * src/jit-ir.h (jit_call::jit_call): New overload. (jit_magic_end::context): New class. (jit_magic_end::jit_magic_end): moved to src/jit-ir.cc. * src/jit-typeinfo.cc (octave_jit_paren_scalar): New function. (jit_typeinfo::jit_typeinfo): Generate ND scalar indexing. (jit_typeinfo::gen_subsref): New function. * src/jit-typeinfo.h (jit_typeinfo::gen_subsref): New declaration. * src/pt-jit.cc (jit_convert::visit_index_expression, jit_convert::do_assign): Update resolve call. (jit_convert::resolve): Resolve ND indices. * src/pt-jit.h (jit_convert::resolve): Change function signature.
author Max Brister <max@2bass.com>
date Tue, 31 Jul 2012 11:51:01 -0500
parents bc32288f4a42
children f57d7578c1a6
comparison
equal deleted inserted replaced
15066:6451a584305e 15067:df4538e3b50b
516 } 516 }
517 517
518 void 518 void
519 jit_convert::visit_index_expression (tree_index_expression& exp) 519 jit_convert::visit_index_expression (tree_index_expression& exp)
520 { 520 {
521 std::pair<jit_value *, jit_value *> res = resolve (exp); 521 result = resolve (jit_typeinfo::paren_subsref (), exp);
522 jit_value *object = res.first;
523 jit_value *index = res.second;
524
525 result = create_checked (jit_typeinfo::paren_subsref, object, index);
526 } 522 }
527 523
528 void 524 void
529 jit_convert::visit_matrix (tree_matrix&) 525 jit_convert::visit_matrix (tree_matrix&)
530 { 526 {
811 if (inc) 807 if (inc)
812 ++count; 808 ++count;
813 return ss.str (); 809 return ss.str ();
814 } 810 }
815 811
816 std::pair<jit_value *, jit_value *> 812 jit_instruction *
817 jit_convert::resolve (tree_index_expression& exp) 813 jit_convert::resolve (const jit_operation& fres, tree_index_expression& exp)
818 { 814 {
819 std::string type = exp.type_tags (); 815 std::string type = exp.type_tags ();
820 if (! (type.size () == 1 && type[0] == '(')) 816 if (! (type.size () == 1 && type[0] == '('))
821 throw jit_fail_exception ("Unsupported index operation"); 817 throw jit_fail_exception ("Unsupported index operation");
822 818
826 822
827 tree_argument_list *arg_list = args.front (); 823 tree_argument_list *arg_list = args.front ();
828 if (! arg_list) 824 if (! arg_list)
829 throw jit_fail_exception ("null argument list"); 825 throw jit_fail_exception ("null argument list");
830 826
831 if (arg_list->size () != 1) 827 if (arg_list->size () < 1)
832 throw jit_fail_exception ("Bad number of arguments in arg_list"); 828 throw jit_fail_exception ("Empty arg_list");
833 829
834 tree_expression *tree_object = exp.expression (); 830 tree_expression *tree_object = exp.expression ();
835 jit_value *object = visit (tree_object); 831 jit_value *object = visit (tree_object);
836 832
837 end_context.push_back (object); 833 size_t narg = arg_list->size ();
838 834 tree_argument_list::iterator iter = arg_list->begin ();
839 unwind_protect prot; 835 std::vector<jit_value *> call_args (narg + 1);
840 prot.add_method (&end_context, &std::vector<jit_value *>::pop_back); 836 call_args[0] = object;
841 837
842 tree_expression *arg0 = arg_list->front (); 838 for (size_t idx = 0; iter != arg_list->end (); ++idx, ++iter)
843 jit_value *index = visit (arg0); 839 {
844 840 unwind_protect prot;
845 return std::make_pair (object, index); 841 prot.add_method (&end_context,
842 &std::vector<jit_magic_end::context>::pop_back);
843 end_context.push_back (jit_magic_end::context (object, idx, narg));
844 call_args[idx + 1] = visit (*iter);
845 }
846
847 return create_checked (fres, call_args);
846 } 848 }
847 849
848 jit_value * 850 jit_value *
849 jit_convert::do_assign (tree_expression *exp, jit_value *rhs, bool artificial) 851 jit_convert::do_assign (tree_expression *exp, jit_value *rhs, bool artificial)
850 { 852 {
854 if (isa<tree_identifier> (exp)) 856 if (isa<tree_identifier> (exp))
855 return do_assign (exp->name (), rhs, exp->print_result (), artificial); 857 return do_assign (exp->name (), rhs, exp->print_result (), artificial);
856 else if (tree_index_expression *idx 858 else if (tree_index_expression *idx
857 = dynamic_cast<tree_index_expression *> (exp)) 859 = dynamic_cast<tree_index_expression *> (exp))
858 { 860 {
859 std::pair<jit_value *, jit_value *> res = resolve (*idx); 861 jit_value *new_object = resolve (jit_typeinfo::paren_subsasgn (), *idx);
860 jit_value *object = res.first;
861 jit_value *index = res.second;
862 jit_call *new_object = create<jit_call> (&jit_typeinfo::paren_subsasgn,
863 object, index, rhs);
864 block->append (new_object);
865 do_assign (idx->expression (), new_object, true); 862 do_assign (idx->expression (), new_object, true);
866 create_check (new_object);
867 863
868 // FIXME: Will not work for values that must be release/grabed 864 // FIXME: Will not work for values that must be release/grabed
869 return rhs; 865 return rhs;
870 } 866 }
871 else 867 else
1851 %! for i=1:niter 1847 %! for i=1:niter
1852 %! result = result + m(end); 1848 %! result = result + m(end);
1853 %! endfor 1849 %! endfor
1854 %! assert (result == m(end) * niter); 1850 %! assert (result == m(end) * niter);
1855 1851
1852 %!test
1853 %! ndim = 100;
1854 %! result = 0;
1855 %! m = zeros (ndim);
1856 %! m(:) = 1:ndim^2;
1857 %! i = 1;
1858 %! while (i <= ndim)
1859 %! for j = 1:ndim
1860 %! result = result + m(i, j);
1861 %! endfor
1862 %! i = i + 1;
1863 %! endwhile
1864 %! assert (result == sum (sum (m)));
1856 */ 1865 */