Mercurial > hg > octave-terminal
changeset 15334:8125773322d4
Error on undefined an unused variables in JIT
* jit-typeinfo.cc (jit_typeinfo::jit_typeinfo): Support grab_fn for all types
except any and remove copy_fn initialization.
* jit-typeinfo.h (jit_typeinfo::copy): Removed function.
* pt-jit.cc (jit_convert::visit_identifier): Grab identifier on visit.
(jit_convert::visit_index_expression): Update resolve signature.
(jit_convert::resolve): Change parameters.
(jit_convert::do_assign): Update resolve call.
(jit_convert_llvm::visit): Remove now dead case.
* pt-jit.h (jit_convert::resolve): Change resolve signature.
author | Max Brister <max@2bass.com> |
---|---|
date | Sat, 08 Sep 2012 17:20:05 -0600 |
parents | 7d2eb4a01798 |
children | 5187c3ea5a68 |
files | libinterp/interp-core/jit-typeinfo.cc libinterp/interp-core/jit-typeinfo.h libinterp/interp-core/pt-jit.cc libinterp/interp-core/pt-jit.h |
diffstat | 4 files changed, 47 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/interp-core/jit-typeinfo.cc +++ b/libinterp/interp-core/jit-typeinfo.cc @@ -1123,19 +1123,19 @@ binary_ops[op].add_overload (fn); } - // grab any - fn = create_function (jit_convention::external, "octave_jit_grab_any", any, - any); - fn.add_mapping (engine, &octave_jit_grab_any); - grab_fn.add_overload (fn); - grab_fn.stash_name ("grab"); - // grab matrix fn = create_function (jit_convention::external, "octave_jit_grab_matrix", matrix, matrix); fn.add_mapping (engine, &octave_jit_grab_matrix); grab_fn.add_overload (fn); + grab_fn.add_overload (create_identity (scalar)); + grab_fn.add_overload (create_identity (scalar_ptr)); + grab_fn.add_overload (create_identity (any_ptr)); + grab_fn.add_overload (create_identity (boolean)); + grab_fn.add_overload (create_identity (complex)); + grab_fn.add_overload (create_identity (index)); + // release any fn = create_function (jit_convention::external, "octave_jit_release_any", 0, any); @@ -1149,10 +1149,6 @@ fn.add_mapping (engine, &octave_jit_release_matrix); release_fn.add_overload (fn); - // copy - copy_fn.stash_name ("copy"); - copy_fn.add_overload (create_identity (scalar)); - // now for binary scalar operations add_binary_op (scalar, octave_value::op_add, llvm::Instruction::FAdd); add_binary_op (scalar, octave_value::op_sub, llvm::Instruction::FSub); @@ -1836,6 +1832,9 @@ casts.resize (next_id + 1); jit_function any_id = create_identity (any); + jit_function grab_any = create_function (jit_convention::external, + "octave_jit_grab_any", any, any); + grab_any.add_mapping (engine, &octave_jit_grab_any); jit_function release_any = get_release (any); std::vector<jit_type *> args; args.resize (1); @@ -1846,6 +1845,7 @@ jit_type *btype = iter->second; args[0] = btype; + grab_fn.add_overload (jit_function (grab_any, btype, args)); release_fn.add_overload (jit_function (release_any, 0, args)); casts[any->type_id ()].add_overload (jit_function (any_id, any, args));
--- a/libinterp/interp-core/jit-typeinfo.h +++ b/libinterp/interp-core/jit-typeinfo.h @@ -498,11 +498,6 @@ return instance->release_fn.overload (type); } - static const jit_operation& copy (void) - { - return instance->copy_fn; - } - static const jit_operation& print_value (void) { return instance->print_fn; @@ -756,7 +751,6 @@ std::vector<jit_operation> unary_ops; jit_operation grab_fn; jit_operation release_fn; - jit_operation copy_fn; jit_operation print_fn; jit_operation for_init_fn; jit_operation for_check_fn;
--- a/libinterp/interp-core/pt-jit.cc +++ b/libinterp/interp-core/pt-jit.cc @@ -359,7 +359,12 @@ result = block->append (factory.create<jit_magic_end> (end_context)); } else - result = get_variable (ti.name ()); + { + jit_variable *var = get_variable (ti.name ()); + jit_instruction *instr; + instr = factory.create<jit_call> (&jit_typeinfo::grab, var); + result = block->append (instr); + } } void @@ -458,7 +463,7 @@ void jit_convert::visit_index_expression (tree_index_expression& exp) { - result = resolve (jit_typeinfo::paren_subsref (), exp); + result = resolve (exp); } void @@ -532,7 +537,7 @@ if (etype == octave_value::op_incr || etype == octave_value::op_decr) { - jit_value *ret = create_checked (&jit_typeinfo::copy, operandv); + jit_value *ret = create_checked (&jit_typeinfo::grab, operandv); do_assign (operand, result); result = ret; } @@ -772,8 +777,8 @@ } jit_instruction * -jit_convert::resolve (const jit_operation& fres, tree_index_expression& exp, - jit_value *extra_arg) +jit_convert::resolve (tree_index_expression& exp, jit_value *extra_arg, + bool lhs) { std::string type = exp.type_tags (); if (! (type.size () == 1 && type[0] == '(')) @@ -781,7 +786,8 @@ std::list<tree_argument_list *> args = exp.arg_lists (); if (args.size () != 1) - throw jit_fail_exception ("Bad number of arguments in tree_index_expression"); + throw jit_fail_exception ("Bad number of arguments in " + "tree_index_expression"); tree_argument_list *arg_list = args.front (); if (! arg_list) @@ -791,7 +797,16 @@ throw jit_fail_exception ("Empty arg_list"); tree_expression *tree_object = exp.expression (); - jit_value *object = visit (tree_object); + jit_value *object; + if (lhs) + { + tree_identifier *id = dynamic_cast<tree_identifier *> (tree_object); + if (! id) + throw jit_fail_exception ("expected identifier"); + object = get_variable (id->name ()); + } + else + object = visit (tree_object); size_t narg = arg_list->size (); tree_argument_list::iterator iter = arg_list->begin (); @@ -813,6 +828,9 @@ if (extra_arg) call_args[call_args.size () - 1] = extra_arg; + const jit_operation& fres = lhs ? jit_typeinfo::paren_subsasgn () + : jit_typeinfo::paren_subsref (); + return create_checked (fres, call_args); } @@ -827,8 +845,7 @@ else if (tree_index_expression *idx = dynamic_cast<tree_index_expression *> (exp)) { - jit_value *new_object = resolve (jit_typeinfo::paren_subsasgn (), *idx, - rhs); + jit_value *new_object = resolve (*idx, rhs, true); do_assign (idx->expression (), new_object, true); // FIXME: Will not work for values that must be release/grabed @@ -1122,13 +1139,6 @@ if (assign.artificial ()) return; - if (isa<jit_assign_base> (new_value)) - { - const jit_function& ol = jit_typeinfo::get_grab (new_value->type ()); - if (ol.valid ()) - assign.stash_llvm (ol.call (builder, new_value)); - } - jit_value *overwrite = assign.overwrite (); if (isa<jit_assign_base> (overwrite)) { @@ -2108,4 +2118,12 @@ %! endwhile %! assert (b, a(1)); +%!function test_undef () +%! for i=1:1e7 +%! XXX; +%! endfor +%!endfunction + +%!error <undefined near> (test_undef); + */
--- a/libinterp/interp-core/pt-jit.h +++ b/libinterp/interp-core/pt-jit.h @@ -206,9 +206,8 @@ std::string next_name (const char *prefix, size_t& count, bool inc); - jit_instruction *resolve (const jit_operation& fres, - tree_index_expression& exp, - jit_value *extra_arg = 0); + jit_instruction *resolve (tree_index_expression& exp, + jit_value *extra_arg = 0, bool lhs = false); jit_value *do_assign (tree_expression *exp, jit_value *rhs, bool artificial = false);