aoqi@0: /* aoqi@0: * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "c1/c1_ValueStack.hpp" aoqi@0: #include "c1/c1_RangeCheckElimination.hpp" aoqi@0: #include "c1/c1_IR.hpp" aoqi@0: #include "c1/c1_Canonicalizer.hpp" aoqi@0: #include "c1/c1_ValueMap.hpp" aoqi@0: #include "ci/ciMethodData.hpp" aoqi@0: #include "runtime/deoptimization.hpp" aoqi@0: aoqi@0: // Macros for the Trace and the Assertion flag aoqi@0: #ifdef ASSERT aoqi@0: #define TRACE_RANGE_CHECK_ELIMINATION(code) if (TraceRangeCheckElimination) { code; } aoqi@0: #define ASSERT_RANGE_CHECK_ELIMINATION(code) if (AssertRangeCheckElimination) { code; } aoqi@0: #define TRACE_OR_ASSERT_RANGE_CHECK_ELIMINATION(code) if (TraceRangeCheckElimination || AssertRangeCheckElimination) { code; } aoqi@0: #else aoqi@0: #define TRACE_RANGE_CHECK_ELIMINATION(code) aoqi@0: #define ASSERT_RANGE_CHECK_ELIMINATION(code) aoqi@0: #define TRACE_OR_ASSERT_RANGE_CHECK_ELIMINATION(code) aoqi@0: #endif aoqi@0: aoqi@0: // Entry point for the optimization aoqi@0: void RangeCheckElimination::eliminate(IR *ir) { aoqi@0: bool do_elimination = ir->compilation()->has_access_indexed(); aoqi@0: ASSERT_RANGE_CHECK_ELIMINATION(do_elimination = true); aoqi@0: if (do_elimination) { aoqi@0: RangeCheckEliminator rce(ir); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Constructor aoqi@0: RangeCheckEliminator::RangeCheckEliminator(IR *ir) : aoqi@0: _bounds(Instruction::number_of_instructions(), NULL), aoqi@0: _access_indexed_info(Instruction::number_of_instructions(), NULL) aoqi@0: { aoqi@0: _visitor.set_range_check_eliminator(this); aoqi@0: _ir = ir; aoqi@0: _number_of_instructions = Instruction::number_of_instructions(); aoqi@0: _optimistic = ir->compilation()->is_optimistic(); aoqi@0: aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->cr(); aoqi@0: tty->print_cr("Range check elimination"); aoqi@0: ir->method()->print_name(tty); aoqi@0: tty->cr(); aoqi@0: ); aoqi@0: aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->print_cr("optimistic=%d", (int)_optimistic); aoqi@0: ); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: // Verifies several conditions that must be true on the IR-input. Only used for debugging purposes. aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->print_cr("Verification of IR . . ."); aoqi@0: ); aoqi@0: Verification verification(ir); aoqi@0: #endif aoqi@0: aoqi@0: // Set process block flags aoqi@0: // Optimization so a blocks is only processed if it contains an access indexed instruction or if aoqi@0: // one of its children in the dominator tree contains an access indexed instruction. aoqi@0: set_process_block_flags(ir->start()); aoqi@0: aoqi@0: // Pass over instructions in the dominator tree aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->print_cr("Starting pass over dominator tree . . .") aoqi@0: ); aoqi@0: calc_bounds(ir->start(), NULL); aoqi@0: aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->print_cr("Finished!") aoqi@0: ); aoqi@0: } aoqi@0: aoqi@0: // Instruction specific work for some instructions aoqi@0: // Constant aoqi@0: void RangeCheckEliminator::Visitor::do_Constant(Constant *c) { aoqi@0: IntConstant *ic = c->type()->as_IntConstant(); aoqi@0: if (ic != NULL) { aoqi@0: int value = ic->value(); aoqi@0: _bound = new Bound(value, NULL, value, NULL); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // LogicOp aoqi@0: void RangeCheckEliminator::Visitor::do_LogicOp(LogicOp *lo) { aoqi@0: if (lo->type()->as_IntType() && lo->op() == Bytecodes::_iand && (lo->x()->as_Constant() || lo->y()->as_Constant())) { aoqi@0: int constant = 0; aoqi@0: Constant *c = lo->x()->as_Constant(); aoqi@0: if (c != NULL) { aoqi@0: constant = c->type()->as_IntConstant()->value(); aoqi@0: } else { aoqi@0: constant = lo->y()->as_Constant()->type()->as_IntConstant()->value(); aoqi@0: } aoqi@0: if (constant >= 0) { aoqi@0: _bound = new Bound(0, NULL, constant, NULL); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Phi aoqi@0: void RangeCheckEliminator::Visitor::do_Phi(Phi *phi) { aoqi@0: if (!phi->type()->as_IntType() && !phi->type()->as_ObjectType()) return; aoqi@0: aoqi@0: BlockBegin *block = phi->block(); aoqi@0: int op_count = phi->operand_count(); aoqi@0: bool has_upper = true; aoqi@0: bool has_lower = true; aoqi@0: assert(phi, "Phi must not be null"); aoqi@0: Bound *bound = NULL; aoqi@0: aoqi@0: // TODO: support more difficult phis aoqi@0: for (int i=0; ioperand_at(i); aoqi@0: aoqi@0: if (v == phi) continue; aoqi@0: aoqi@0: // Check if instruction is connected with phi itself aoqi@0: Op2 *op2 = v->as_Op2(); aoqi@0: if (op2 != NULL) { aoqi@0: Value x = op2->x(); aoqi@0: Value y = op2->y(); aoqi@0: if ((x == phi || y == phi)) { aoqi@0: Value other = x; aoqi@0: if (other == phi) { aoqi@0: other = y; aoqi@0: } aoqi@0: ArithmeticOp *ao = v->as_ArithmeticOp(); aoqi@0: if (ao != NULL && ao->op() == Bytecodes::_iadd) { aoqi@0: assert(ao->op() == Bytecodes::_iadd, "Has to be add!"); aoqi@0: if (ao->type()->as_IntType()) { aoqi@0: Constant *c = other->as_Constant(); aoqi@0: if (c != NULL) { aoqi@0: assert(c->type()->as_IntConstant(), "Constant has to be of type integer"); aoqi@0: int value = c->type()->as_IntConstant()->value(); aoqi@0: if (value == 1) { aoqi@0: has_upper = false; aoqi@0: } else if (value > 1) { aoqi@0: // Overflow not guaranteed aoqi@0: has_upper = false; aoqi@0: has_lower = false; aoqi@0: } else if (value < 0) { aoqi@0: has_lower = false; aoqi@0: } aoqi@0: continue; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // No connection -> new bound aoqi@0: Bound *v_bound = _rce->get_bound(v); aoqi@0: Bound *cur_bound; aoqi@0: int cur_constant = 0; aoqi@0: Value cur_value = v; aoqi@0: aoqi@0: if (v->type()->as_IntConstant()) { aoqi@0: cur_constant = v->type()->as_IntConstant()->value(); aoqi@0: cur_value = NULL; aoqi@0: } aoqi@0: if (!v_bound->has_upper() || !v_bound->has_lower()) { aoqi@0: cur_bound = new Bound(cur_constant, cur_value, cur_constant, cur_value); aoqi@0: } else { aoqi@0: cur_bound = v_bound; aoqi@0: } aoqi@0: if (cur_bound) { aoqi@0: if (!bound) { aoqi@0: bound = cur_bound->copy(); aoqi@0: } else { aoqi@0: bound->or_op(cur_bound); aoqi@0: } aoqi@0: } else { aoqi@0: // No bound! aoqi@0: bound = NULL; aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (bound) { aoqi@0: if (!has_upper) { aoqi@0: bound->remove_upper(); aoqi@0: } aoqi@0: if (!has_lower) { aoqi@0: bound->remove_lower(); aoqi@0: } aoqi@0: _bound = bound; aoqi@0: } else { aoqi@0: _bound = new Bound(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // ArithmeticOp aoqi@0: void RangeCheckEliminator::Visitor::do_ArithmeticOp(ArithmeticOp *ao) { aoqi@0: Value x = ao->x(); aoqi@0: Value y = ao->y(); aoqi@0: aoqi@0: if (ao->op() == Bytecodes::_irem) { aoqi@0: Bound* x_bound = _rce->get_bound(x); aoqi@0: Bound* y_bound = _rce->get_bound(y); aoqi@0: if (x_bound->lower() >= 0 && x_bound->lower_instr() == NULL && y->as_ArrayLength() != NULL) { aoqi@0: _bound = new Bound(0, NULL, -1, y); aoqi@0: } else { aoqi@0: _bound = new Bound(); aoqi@0: } aoqi@0: } else if (!x->as_Constant() || !y->as_Constant()) { aoqi@0: assert(!x->as_Constant() || !y->as_Constant(), "One of the operands must be non-constant!"); aoqi@0: if (((x->as_Constant() || y->as_Constant()) && (ao->op() == Bytecodes::_iadd)) || (y->as_Constant() && ao->op() == Bytecodes::_isub)) { aoqi@0: assert(ao->op() == Bytecodes::_iadd || ao->op() == Bytecodes::_isub, "Operand must be iadd or isub"); aoqi@0: aoqi@0: if (y->as_Constant()) { aoqi@0: Value tmp = x; aoqi@0: x = y; aoqi@0: y = tmp; aoqi@0: } aoqi@0: assert(x->as_Constant()->type()->as_IntConstant(), "Constant must be int constant!"); aoqi@0: aoqi@0: // Constant now in x aoqi@0: int const_value = x->as_Constant()->type()->as_IntConstant()->value(); aoqi@0: if (ao->op() == Bytecodes::_iadd || const_value != min_jint) { aoqi@0: if (ao->op() == Bytecodes::_isub) { aoqi@0: const_value = -const_value; aoqi@0: } aoqi@0: aoqi@0: Bound * bound = _rce->get_bound(y); aoqi@0: if (bound->has_upper() && bound->has_lower()) { aoqi@0: int new_lower = bound->lower() + const_value; aoqi@0: jlong new_lowerl = ((jlong)bound->lower()) + const_value; aoqi@0: int new_upper = bound->upper() + const_value; aoqi@0: jlong new_upperl = ((jlong)bound->upper()) + const_value; aoqi@0: aoqi@0: if (((jlong)new_lower) == new_lowerl && ((jlong)new_upper == new_upperl)) { aoqi@0: Bound *newBound = new Bound(new_lower, bound->lower_instr(), new_upper, bound->upper_instr()); aoqi@0: _bound = newBound; aoqi@0: } else { aoqi@0: // overflow aoqi@0: _bound = new Bound(); aoqi@0: } aoqi@0: } else { aoqi@0: _bound = new Bound(); aoqi@0: } aoqi@0: } else { aoqi@0: _bound = new Bound(); aoqi@0: } aoqi@0: } else { aoqi@0: Bound *bound = _rce->get_bound(x); aoqi@0: if (ao->op() == Bytecodes::_isub) { aoqi@0: if (bound->lower_instr() == y) { aoqi@0: _bound = new Bound(Instruction::geq, NULL, bound->lower()); aoqi@0: } else { aoqi@0: _bound = new Bound(); aoqi@0: } aoqi@0: } else { aoqi@0: _bound = new Bound(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // IfOp aoqi@0: void RangeCheckEliminator::Visitor::do_IfOp(IfOp *ifOp) aoqi@0: { aoqi@0: if (ifOp->tval()->type()->as_IntConstant() && ifOp->fval()->type()->as_IntConstant()) { aoqi@0: int min = ifOp->tval()->type()->as_IntConstant()->value(); aoqi@0: int max = ifOp->fval()->type()->as_IntConstant()->value(); aoqi@0: if (min > max) { aoqi@0: // min ^= max ^= min ^= max; aoqi@0: int tmp = min; aoqi@0: min = max; aoqi@0: max = tmp; aoqi@0: } aoqi@0: _bound = new Bound(min, NULL, max, NULL); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Get bound. Returns the current bound on Value v. Normally this is the topmost element on the bound stack. aoqi@0: RangeCheckEliminator::Bound *RangeCheckEliminator::get_bound(Value v) { aoqi@0: // Wrong type or NULL -> No bound aoqi@0: if (!v || (!v->type()->as_IntType() && !v->type()->as_ObjectType())) return NULL; aoqi@0: aoqi@0: if (!_bounds[v->id()]) { aoqi@0: // First (default) bound is calculated aoqi@0: // Create BoundStack aoqi@0: _bounds[v->id()] = new BoundStack(); aoqi@0: _visitor.clear_bound(); aoqi@0: Value visit_value = v; aoqi@0: visit_value->visit(&_visitor); aoqi@0: Bound *bound = _visitor.bound(); aoqi@0: if (bound) { aoqi@0: _bounds[v->id()]->push(bound); aoqi@0: } aoqi@0: if (_bounds[v->id()]->length() == 0) { aoqi@0: assert(!(v->as_Constant() && v->type()->as_IntConstant()), "constants not handled here"); aoqi@0: _bounds[v->id()]->push(new Bound()); aoqi@0: } aoqi@0: } else if (_bounds[v->id()]->length() == 0) { aoqi@0: // To avoid endless loops, bound is currently in calculation -> nothing known about it aoqi@0: return new Bound(); aoqi@0: } aoqi@0: aoqi@0: // Return bound aoqi@0: return _bounds[v->id()]->top(); aoqi@0: } aoqi@0: aoqi@0: // Update bound aoqi@0: void RangeCheckEliminator::update_bound(IntegerStack &pushed, Value v, Instruction::Condition cond, Value value, int constant) { aoqi@0: if (cond == Instruction::gtr) { aoqi@0: cond = Instruction::geq; aoqi@0: constant++; aoqi@0: } else if (cond == Instruction::lss) { aoqi@0: cond = Instruction::leq; aoqi@0: constant--; aoqi@0: } aoqi@0: Bound *bound = new Bound(cond, value, constant); aoqi@0: update_bound(pushed, v, bound); aoqi@0: } aoqi@0: aoqi@0: // Checks for loop invariance. Returns true if the instruction is outside of the loop which is identified by loop_header. aoqi@0: bool RangeCheckEliminator::loop_invariant(BlockBegin *loop_header, Instruction *instruction) { aoqi@0: assert(loop_header, "Loop header must not be null!"); aoqi@0: if (!instruction) return true; aoqi@0: return instruction->dominator_depth() < loop_header->dominator_depth(); aoqi@0: } aoqi@0: aoqi@0: // Update bound. Pushes a new bound onto the stack. Tries to do a conjunction with the current bound. aoqi@0: void RangeCheckEliminator::update_bound(IntegerStack &pushed, Value v, Bound *bound) { aoqi@0: if (v->as_Constant()) { aoqi@0: // No bound update for constants aoqi@0: return; aoqi@0: } aoqi@0: if (!_bounds[v->id()]) { aoqi@0: get_bound(v); aoqi@0: assert(_bounds[v->id()], "Now Stack must exist"); aoqi@0: } aoqi@0: Bound *top = NULL; aoqi@0: if (_bounds[v->id()]->length() > 0) { aoqi@0: top = _bounds[v->id()]->top(); aoqi@0: } aoqi@0: if (top) { aoqi@0: bound->and_op(top); aoqi@0: } aoqi@0: _bounds[v->id()]->push(bound); aoqi@0: pushed.append(v->id()); aoqi@0: } aoqi@0: aoqi@0: // Add instruction + idx for in block motion aoqi@0: void RangeCheckEliminator::add_access_indexed_info(InstructionList &indices, int idx, Value instruction, AccessIndexed *ai) { aoqi@0: int id = instruction->id(); aoqi@0: AccessIndexedInfo *aii = _access_indexed_info[id]; aoqi@0: if (aii == NULL) { aoqi@0: aii = new AccessIndexedInfo(); aoqi@0: _access_indexed_info[id] = aii; aoqi@0: indices.append(instruction); aoqi@0: aii->_min = idx; aoqi@0: aii->_max = idx; aoqi@0: aii->_list = new AccessIndexedList(); aoqi@0: } else if (idx >= aii->_min && idx <= aii->_max) { aoqi@0: remove_range_check(ai); aoqi@0: return; aoqi@0: } aoqi@0: aii->_min = MIN2(aii->_min, idx); aoqi@0: aii->_max = MAX2(aii->_max, idx); aoqi@0: aii->_list->append(ai); aoqi@0: } aoqi@0: aoqi@0: // In block motion. Tries to reorder checks in order to reduce some of them. aoqi@0: // Example: aoqi@0: // a[i] = 0; aoqi@0: // a[i+2] = 0; aoqi@0: // a[i+1] = 0; aoqi@0: // In this example the check for a[i+1] would be considered as unnecessary during the first iteration. aoqi@0: // After this i is only checked once for i >= 0 and i+2 < a.length before the first array access. If this aoqi@0: // check fails, deoptimization is called. aoqi@0: void RangeCheckEliminator::in_block_motion(BlockBegin *block, AccessIndexedList &accessIndexed, InstructionList &arrays) { aoqi@0: InstructionList indices; aoqi@0: aoqi@0: // Now iterate over all arrays aoqi@0: for (int i=0; iarray() != array || !ai->check_flag(Instruction::NeedsRangeCheckFlag)) continue; aoqi@0: aoqi@0: Value index = ai->index(); aoqi@0: Constant *c = index->as_Constant(); aoqi@0: if (c != NULL) { aoqi@0: int constant_value = c->type()->as_IntConstant()->value(); aoqi@0: if (constant_value >= 0) { aoqi@0: if (constant_value <= max_constant) { aoqi@0: // No range check needed for this aoqi@0: remove_range_check(ai); aoqi@0: } else { aoqi@0: max_constant = constant_value; aoqi@0: list_constant.append(ai); aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: int last_integer = 0; aoqi@0: Instruction *last_instruction = index; aoqi@0: int base = 0; aoqi@0: ArithmeticOp *ao = index->as_ArithmeticOp(); aoqi@0: aoqi@0: while (ao != NULL && (ao->x()->as_Constant() || ao->y()->as_Constant()) && (ao->op() == Bytecodes::_iadd || ao->op() == Bytecodes::_isub)) { aoqi@0: c = ao->y()->as_Constant(); aoqi@0: Instruction *other = ao->x(); aoqi@0: if (!c && ao->op() == Bytecodes::_iadd) { aoqi@0: c = ao->x()->as_Constant(); aoqi@0: other = ao->y(); aoqi@0: } aoqi@0: aoqi@0: if (c) { aoqi@0: int value = c->type()->as_IntConstant()->value(); aoqi@0: if (value != min_jint) { aoqi@0: if (ao->op() == Bytecodes::_isub) { aoqi@0: value = -value; aoqi@0: } aoqi@0: base += value; aoqi@0: last_integer = base; aoqi@0: last_instruction = other; aoqi@0: } aoqi@0: index = other; aoqi@0: } else { aoqi@0: break; aoqi@0: } aoqi@0: ao = index->as_ArithmeticOp(); aoqi@0: } aoqi@0: add_access_indexed_info(indices, last_integer, last_instruction, ai); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Iterate over all different indices aoqi@0: if (_optimistic) { aoqi@0: for (int i = 0; i < indices.length(); i++) { aoqi@0: Instruction *index_instruction = indices.at(i); aoqi@0: AccessIndexedInfo *info = _access_indexed_info[index_instruction->id()]; aoqi@0: assert(info != NULL, "Info must not be null"); aoqi@0: aoqi@0: // if idx < 0, max > 0, max + idx may fall between 0 and aoqi@0: // length-1 and if min < 0, min + idx may overflow and be >= aoqi@0: // 0. The predicate wouldn't trigger but some accesses could aoqi@0: // be with a negative index. This test guarantees that for the aoqi@0: // min and max value that are kept the predicate can't let aoqi@0: // some incorrect accesses happen. aoqi@0: bool range_cond = (info->_max < 0 || info->_max + min_jint <= info->_min); aoqi@0: aoqi@0: // Generate code only if more than 2 range checks can be eliminated because of that. aoqi@0: // 2 because at least 2 comparisons are done aoqi@0: if (info->_list->length() > 2 && range_cond) { aoqi@0: AccessIndexed *first = info->_list->at(0); aoqi@0: Instruction *insert_position = first->prev(); aoqi@0: assert(insert_position->next() == first, "prev was calculated"); aoqi@0: ValueStack *state = first->state_before(); aoqi@0: aoqi@0: // Load min Constant aoqi@0: Constant *min_constant = NULL; aoqi@0: if (info->_min != 0) { aoqi@0: min_constant = new Constant(new IntConstant(info->_min)); aoqi@0: NOT_PRODUCT(min_constant->set_printable_bci(first->printable_bci())); aoqi@0: insert_position = insert_position->insert_after(min_constant); aoqi@0: } aoqi@0: aoqi@0: // Load max Constant aoqi@0: Constant *max_constant = NULL; aoqi@0: if (info->_max != 0) { aoqi@0: max_constant = new Constant(new IntConstant(info->_max)); aoqi@0: NOT_PRODUCT(max_constant->set_printable_bci(first->printable_bci())); aoqi@0: insert_position = insert_position->insert_after(max_constant); aoqi@0: } aoqi@0: aoqi@0: // Load array length aoqi@0: Value length_instr = first->length(); aoqi@0: if (!length_instr) { aoqi@0: ArrayLength *length = new ArrayLength(array, first->state_before()->copy()); aoqi@0: length->set_exception_state(length->state_before()); aoqi@0: length->set_flag(Instruction::DeoptimizeOnException, true); aoqi@0: insert_position = insert_position->insert_after_same_bci(length); aoqi@0: length_instr = length; aoqi@0: } aoqi@0: aoqi@0: // Calculate lower bound aoqi@0: Instruction *lower_compare = index_instruction; aoqi@0: if (min_constant) { aoqi@0: ArithmeticOp *ao = new ArithmeticOp(Bytecodes::_iadd, min_constant, lower_compare, false, NULL); aoqi@0: insert_position = insert_position->insert_after_same_bci(ao); aoqi@0: lower_compare = ao; aoqi@0: } aoqi@0: aoqi@0: // Calculate upper bound aoqi@0: Instruction *upper_compare = index_instruction; aoqi@0: if (max_constant) { aoqi@0: ArithmeticOp *ao = new ArithmeticOp(Bytecodes::_iadd, max_constant, upper_compare, false, NULL); aoqi@0: insert_position = insert_position->insert_after_same_bci(ao); aoqi@0: upper_compare = ao; aoqi@0: } aoqi@0: aoqi@0: // Trick with unsigned compare is done aoqi@0: int bci = NOT_PRODUCT(first->printable_bci()) PRODUCT_ONLY(-1); aoqi@0: insert_position = predicate(upper_compare, Instruction::aeq, length_instr, state, insert_position, bci); aoqi@0: insert_position = predicate_cmp_with_const(lower_compare, Instruction::leq, -1, state, insert_position); aoqi@0: for (int j = 0; j_list->length(); j++) { aoqi@0: AccessIndexed *ai = info->_list->at(j); aoqi@0: remove_range_check(ai); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (list_constant.length() > 1) { aoqi@0: AccessIndexed *first = list_constant.at(0); aoqi@0: Instruction *insert_position = first->prev(); aoqi@0: ValueStack *state = first->state_before(); aoqi@0: // Load max Constant aoqi@0: Constant *constant = new Constant(new IntConstant(max_constant)); aoqi@0: NOT_PRODUCT(constant->set_printable_bci(first->printable_bci())); aoqi@0: insert_position = insert_position->insert_after(constant); aoqi@0: Instruction *compare_instr = constant; aoqi@0: Value length_instr = first->length(); aoqi@0: if (!length_instr) { aoqi@0: ArrayLength *length = new ArrayLength(array, state->copy()); aoqi@0: length->set_exception_state(length->state_before()); aoqi@0: length->set_flag(Instruction::DeoptimizeOnException, true); aoqi@0: insert_position = insert_position->insert_after_same_bci(length); aoqi@0: length_instr = length; aoqi@0: } aoqi@0: // Compare for greater or equal to array length aoqi@0: insert_position = predicate(compare_instr, Instruction::geq, length_instr, state, insert_position); aoqi@0: for (int j = 0; jid()] = NULL; aoqi@0: } aoqi@0: indices.clear(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool RangeCheckEliminator::set_process_block_flags(BlockBegin *block) { aoqi@0: Instruction *cur = block; aoqi@0: bool process = false; aoqi@0: aoqi@0: while (cur) { aoqi@0: process |= (cur->as_AccessIndexed() != NULL); aoqi@0: cur = cur->next(); aoqi@0: } aoqi@0: aoqi@0: BlockList *dominates = block->dominates(); aoqi@0: for (int i=0; ilength(); i++) { aoqi@0: BlockBegin *next = dominates->at(i); aoqi@0: process |= set_process_block_flags(next); aoqi@0: } aoqi@0: aoqi@0: if (!process) { aoqi@0: block->set(BlockBegin::donot_eliminate_range_checks); aoqi@0: } aoqi@0: return process; aoqi@0: } aoqi@0: aoqi@0: bool RangeCheckEliminator::is_ok_for_deoptimization(Instruction *insert_position, Instruction *array_instr, Instruction *length_instr, Instruction *lower_instr, int lower, Instruction *upper_instr, int upper) { aoqi@0: bool upper_check = true; aoqi@0: assert(lower_instr || lower >= 0, "If no lower_instr present, lower must be greater 0"); aoqi@0: assert(!lower_instr || lower_instr->dominator_depth() <= insert_position->dominator_depth(), "Dominator depth must be smaller"); aoqi@0: assert(!upper_instr || upper_instr->dominator_depth() <= insert_position->dominator_depth(), "Dominator depth must be smaller"); aoqi@0: assert(array_instr, "Array instruction must exist"); aoqi@0: assert(array_instr->dominator_depth() <= insert_position->dominator_depth(), "Dominator depth must be smaller"); aoqi@0: assert(!length_instr || length_instr->dominator_depth() <= insert_position->dominator_depth(), "Dominator depth must be smaller"); aoqi@0: aoqi@0: if (upper_instr && upper_instr->as_ArrayLength() && upper_instr->as_ArrayLength()->array() == array_instr) { aoqi@0: // static check aoqi@0: if (upper >= 0) return false; // would always trigger a deopt: aoqi@0: // array_length + x >= array_length, x >= 0 is always true aoqi@0: upper_check = false; aoqi@0: } aoqi@0: if (lower_instr && lower_instr->as_ArrayLength() && lower_instr->as_ArrayLength()->array() == array_instr) { aoqi@0: if (lower > 0) return false; aoqi@0: } aoqi@0: // No upper check required -> skip aoqi@0: if (upper_check && upper_instr && upper_instr->type()->as_ObjectType() && upper_instr == array_instr) { aoqi@0: // upper_instr is object means that the upper bound is the length aoqi@0: // of the upper_instr. aoqi@0: return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: Instruction* RangeCheckEliminator::insert_after(Instruction* insert_position, Instruction* instr, int bci) { aoqi@0: if (bci != -1) { aoqi@0: NOT_PRODUCT(instr->set_printable_bci(bci)); aoqi@0: return insert_position->insert_after(instr); aoqi@0: } else { aoqi@0: return insert_position->insert_after_same_bci(instr); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: Instruction* RangeCheckEliminator::predicate(Instruction* left, Instruction::Condition cond, Instruction* right, ValueStack* state, Instruction *insert_position, int bci) { aoqi@0: RangeCheckPredicate *deoptimize = new RangeCheckPredicate(left, cond, true, right, state->copy()); aoqi@0: return insert_after(insert_position, deoptimize, bci); aoqi@0: } aoqi@0: aoqi@0: Instruction* RangeCheckEliminator::predicate_cmp_with_const(Instruction* instr, Instruction::Condition cond, int constant, ValueStack* state, Instruction *insert_position, int bci) { aoqi@0: Constant *const_instr = new Constant(new IntConstant(constant)); aoqi@0: insert_position = insert_after(insert_position, const_instr, bci); aoqi@0: return predicate(instr, cond, const_instr, state, insert_position); aoqi@0: } aoqi@0: aoqi@0: Instruction* RangeCheckEliminator::predicate_add(Instruction* left, int left_const, Instruction::Condition cond, Instruction* right, ValueStack* state, Instruction *insert_position, int bci) { aoqi@0: Constant *constant = new Constant(new IntConstant(left_const)); aoqi@0: insert_position = insert_after(insert_position, constant, bci); aoqi@0: ArithmeticOp *ao = new ArithmeticOp(Bytecodes::_iadd, constant, left, false, NULL); aoqi@0: insert_position = insert_position->insert_after_same_bci(ao); aoqi@0: return predicate(ao, cond, right, state, insert_position); aoqi@0: } aoqi@0: aoqi@0: Instruction* RangeCheckEliminator::predicate_add_cmp_with_const(Instruction* left, int left_const, Instruction::Condition cond, int constant, ValueStack* state, Instruction *insert_position, int bci) { aoqi@0: Constant *const_instr = new Constant(new IntConstant(constant)); aoqi@0: insert_position = insert_after(insert_position, const_instr, bci); aoqi@0: return predicate_add(left, left_const, cond, const_instr, state, insert_position); aoqi@0: } aoqi@0: aoqi@0: // Insert deoptimization aoqi@0: void RangeCheckEliminator::insert_deoptimization(ValueStack *state, Instruction *insert_position, Instruction *array_instr, Instruction *length_instr, Instruction *lower_instr, int lower, Instruction *upper_instr, int upper, AccessIndexed *ai) { aoqi@0: assert(is_ok_for_deoptimization(insert_position, array_instr, length_instr, lower_instr, lower, upper_instr, upper), "should have been tested before"); aoqi@0: bool upper_check = !(upper_instr && upper_instr->as_ArrayLength() && upper_instr->as_ArrayLength()->array() == array_instr); aoqi@0: aoqi@0: int bci = NOT_PRODUCT(ai->printable_bci()) PRODUCT_ONLY(-1); aoqi@0: if (lower_instr) { aoqi@0: assert(!lower_instr->type()->as_ObjectType(), "Must not be object type"); aoqi@0: if (lower == 0) { aoqi@0: // Compare for less than 0 aoqi@0: insert_position = predicate_cmp_with_const(lower_instr, Instruction::lss, 0, state, insert_position, bci); aoqi@0: } else if (lower > 0) { aoqi@0: // Compare for smaller 0 aoqi@0: insert_position = predicate_add_cmp_with_const(lower_instr, lower, Instruction::lss, 0, state, insert_position, bci); aoqi@0: } else { aoqi@0: assert(lower < 0, ""); aoqi@0: // Add 1 aoqi@0: lower++; aoqi@0: lower = -lower; aoqi@0: // Compare for smaller or equal 0 aoqi@0: insert_position = predicate_cmp_with_const(lower_instr, Instruction::leq, lower, state, insert_position, bci); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // No upper check required -> skip aoqi@0: if (!upper_check) return; aoqi@0: aoqi@0: // We need to know length of array aoqi@0: if (!length_instr) { aoqi@0: // Load length if necessary aoqi@0: ArrayLength *length = new ArrayLength(array_instr, state->copy()); aoqi@0: NOT_PRODUCT(length->set_printable_bci(ai->printable_bci())); aoqi@0: length->set_exception_state(length->state_before()); aoqi@0: length->set_flag(Instruction::DeoptimizeOnException, true); aoqi@0: insert_position = insert_position->insert_after(length); aoqi@0: length_instr = length; aoqi@0: } aoqi@0: aoqi@0: if (!upper_instr) { aoqi@0: // Compare for geq array.length aoqi@0: insert_position = predicate_cmp_with_const(length_instr, Instruction::leq, upper, state, insert_position, bci); aoqi@0: } else { aoqi@0: if (upper_instr->type()->as_ObjectType()) { aoqi@0: assert(state, "must not be null"); aoqi@0: assert(upper_instr != array_instr, "should be"); aoqi@0: ArrayLength *length = new ArrayLength(upper_instr, state->copy()); aoqi@0: NOT_PRODUCT(length->set_printable_bci(ai->printable_bci())); aoqi@0: length->set_flag(Instruction::DeoptimizeOnException, true); aoqi@0: length->set_exception_state(length->state_before()); aoqi@0: insert_position = insert_position->insert_after(length); aoqi@0: upper_instr = length; aoqi@0: } aoqi@0: assert(upper_instr->type()->as_IntType(), "Must not be object type!"); aoqi@0: aoqi@0: if (upper == 0) { aoqi@0: // Compare for geq array.length aoqi@0: insert_position = predicate(upper_instr, Instruction::geq, length_instr, state, insert_position, bci); aoqi@0: } else if (upper < 0) { aoqi@0: // Compare for geq array.length aoqi@0: insert_position = predicate_add(upper_instr, upper, Instruction::geq, length_instr, state, insert_position, bci); aoqi@0: } else { aoqi@0: assert(upper > 0, ""); aoqi@0: upper = -upper; aoqi@0: // Compare for geq array.length aoqi@0: insert_position = predicate_add(length_instr, upper, Instruction::leq, upper_instr, state, insert_position, bci); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Add if condition aoqi@0: void RangeCheckEliminator::add_if_condition(IntegerStack &pushed, Value x, Value y, Instruction::Condition condition) { aoqi@0: if (y->as_Constant()) return; aoqi@0: aoqi@0: int const_value = 0; aoqi@0: Value instr_value = x; aoqi@0: Constant *c = x->as_Constant(); aoqi@0: ArithmeticOp *ao = x->as_ArithmeticOp(); aoqi@0: aoqi@0: if (c != NULL) { aoqi@0: const_value = c->type()->as_IntConstant()->value(); aoqi@0: instr_value = NULL; aoqi@0: } else if (ao != NULL && (!ao->x()->as_Constant() || !ao->y()->as_Constant()) && ((ao->op() == Bytecodes::_isub && ao->y()->as_Constant()) || ao->op() == Bytecodes::_iadd)) { aoqi@0: assert(!ao->x()->as_Constant() || !ao->y()->as_Constant(), "At least one operator must be non-constant!"); aoqi@0: assert(ao->op() == Bytecodes::_isub || ao->op() == Bytecodes::_iadd, "Operation has to be add or sub!"); aoqi@0: c = ao->x()->as_Constant(); aoqi@0: if (c != NULL) { aoqi@0: const_value = c->type()->as_IntConstant()->value(); aoqi@0: instr_value = ao->y(); aoqi@0: } else { aoqi@0: c = ao->y()->as_Constant(); aoqi@0: if (c != NULL) { aoqi@0: const_value = c->type()->as_IntConstant()->value(); aoqi@0: instr_value = ao->x(); aoqi@0: } aoqi@0: } aoqi@0: if (ao->op() == Bytecodes::_isub) { aoqi@0: assert(ao->y()->as_Constant(), "1 - x not supported, only x - 1 is valid!"); aoqi@0: if (const_value > min_jint) { aoqi@0: const_value = -const_value; aoqi@0: } else { aoqi@0: const_value = 0; aoqi@0: instr_value = x; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: update_bound(pushed, y, condition, instr_value, const_value); aoqi@0: } aoqi@0: aoqi@0: // Process If aoqi@0: void RangeCheckEliminator::process_if(IntegerStack &pushed, BlockBegin *block, If *cond) { aoqi@0: // Only if we are direct true / false successor and NOT both ! (even this may occur) aoqi@0: if ((cond->tsux() == block || cond->fsux() == block) && cond->tsux() != cond->fsux()) { aoqi@0: Instruction::Condition condition = cond->cond(); aoqi@0: if (cond->fsux() == block) { aoqi@0: condition = Instruction::negate(condition); aoqi@0: } aoqi@0: Value x = cond->x(); aoqi@0: Value y = cond->y(); aoqi@0: if (x->type()->as_IntType() && y->type()->as_IntType()) { aoqi@0: add_if_condition(pushed, y, x, condition); aoqi@0: add_if_condition(pushed, x, y, Instruction::mirror(condition)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Process access indexed aoqi@0: void RangeCheckEliminator::process_access_indexed(BlockBegin *loop_header, BlockBegin *block, AccessIndexed *ai) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2) aoqi@0: ); aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->print_cr("Access indexed: index=%d length=%d", ai->index()->id(), (ai->length() != NULL ? ai->length()->id() :-1 )) aoqi@0: ); aoqi@0: aoqi@0: if (ai->check_flag(Instruction::NeedsRangeCheckFlag)) { aoqi@0: Bound *index_bound = get_bound(ai->index()); aoqi@0: if (!index_bound->has_lower() || !index_bound->has_upper()) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Index instruction %d has no lower and/or no upper bound!", ai->index()->id()) aoqi@0: ); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: Bound *array_bound; aoqi@0: if (ai->length()) { aoqi@0: array_bound = get_bound(ai->length()); aoqi@0: } else { aoqi@0: array_bound = get_bound(ai->array()); aoqi@0: } aoqi@0: aoqi@0: if (in_array_bound(index_bound, ai->array()) || aoqi@0: (index_bound && array_bound && index_bound->is_smaller(array_bound) && !index_bound->lower_instr() && index_bound->lower() >= 0)) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Bounds check for instruction %d in block B%d can be fully eliminated!", ai->id(), ai->block()->block_id()) aoqi@0: ); aoqi@0: aoqi@0: remove_range_check(ai); aoqi@0: } else if (_optimistic && loop_header) { aoqi@0: assert(ai->array(), "Array must not be null!"); aoqi@0: assert(ai->index(), "Index must not be null!"); aoqi@0: aoqi@0: // Array instruction aoqi@0: Instruction *array_instr = ai->array(); aoqi@0: if (!loop_invariant(loop_header, array_instr)) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Array %d is not loop invariant to header B%d", ai->array()->id(), loop_header->block_id()) aoqi@0: ); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Lower instruction aoqi@0: Value index_instr = ai->index(); aoqi@0: Value lower_instr = index_bound->lower_instr(); aoqi@0: if (!loop_invariant(loop_header, lower_instr)) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Lower instruction %d not loop invariant!", lower_instr->id()) aoqi@0: ); aoqi@0: return; aoqi@0: } aoqi@0: if (!lower_instr && index_bound->lower() < 0) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Lower bound smaller than 0 (%d)!", index_bound->lower()) aoqi@0: ); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Upper instruction aoqi@0: Value upper_instr = index_bound->upper_instr(); aoqi@0: if (!loop_invariant(loop_header, upper_instr)) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Upper instruction %d not loop invariant!", upper_instr->id()) aoqi@0: ); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Length instruction aoqi@0: Value length_instr = ai->length(); aoqi@0: if (!loop_invariant(loop_header, length_instr)) { aoqi@0: // Generate length instruction yourself! aoqi@0: length_instr = NULL; aoqi@0: } aoqi@0: aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("LOOP INVARIANT access indexed %d found in block B%d!", ai->id(), ai->block()->block_id()) aoqi@0: ); aoqi@0: aoqi@0: BlockBegin *pred_block = loop_header->dominator(); aoqi@0: assert(pred_block != NULL, "Every loop header has a dominator!"); aoqi@0: BlockEnd *pred_block_end = pred_block->end(); aoqi@0: Instruction *insert_position = pred_block_end->prev(); aoqi@0: ValueStack *state = pred_block_end->state_before(); aoqi@0: if (pred_block_end->as_Goto() && state == NULL) state = pred_block_end->state(); aoqi@0: assert(state, "State must not be null"); aoqi@0: aoqi@0: // Add deoptimization to dominator of loop header aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Inserting deopt at bci %d in block B%d!", state->bci(), insert_position->block()->block_id()) aoqi@0: ); aoqi@0: aoqi@0: if (!is_ok_for_deoptimization(insert_position, array_instr, length_instr, lower_instr, index_bound->lower(), upper_instr, index_bound->upper())) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Could not eliminate because of static analysis!") aoqi@0: ); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: insert_deoptimization(state, insert_position, array_instr, length_instr, lower_instr, index_bound->lower(), upper_instr, index_bound->upper(), ai); aoqi@0: aoqi@0: // Finally remove the range check! aoqi@0: remove_range_check(ai); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void RangeCheckEliminator::remove_range_check(AccessIndexed *ai) { aoqi@0: ai->set_flag(Instruction::NeedsRangeCheckFlag, false); aoqi@0: // no range check, no need for the length instruction anymore aoqi@0: ai->clear_length(); aoqi@0: aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(ai->dominator_depth()*2); aoqi@0: tty->print_cr("Range check for instruction %d eliminated!", ai->id()); aoqi@0: ); aoqi@0: aoqi@0: ASSERT_RANGE_CHECK_ELIMINATION( aoqi@0: Value array_length = ai->length(); aoqi@0: if (!array_length) { aoqi@0: array_length = ai->array(); aoqi@0: assert(array_length->type()->as_ObjectType(), "Has to be object type!"); aoqi@0: } aoqi@0: int cur_constant = -1; aoqi@0: Value cur_value = array_length; aoqi@0: if (cur_value->type()->as_IntConstant()) { aoqi@0: cur_constant += cur_value->type()->as_IntConstant()->value(); aoqi@0: cur_value = NULL; aoqi@0: } aoqi@0: Bound *new_index_bound = new Bound(0, NULL, cur_constant, cur_value); aoqi@0: add_assertions(new_index_bound, ai->index(), ai); aoqi@0: ); aoqi@0: } aoqi@0: aoqi@0: // Calculate bounds for instruction in this block and children blocks in the dominator tree aoqi@0: void RangeCheckEliminator::calc_bounds(BlockBegin *block, BlockBegin *loop_header) { aoqi@0: // Ensures a valid loop_header aoqi@0: assert(!loop_header || loop_header->is_set(BlockBegin::linear_scan_loop_header_flag), "Loop header has to be real !"); aoqi@0: aoqi@0: // Tracing output aoqi@0: TRACE_RANGE_CHECK_ELIMINATION( aoqi@0: tty->fill_to(block->dominator_depth()*2); aoqi@0: tty->print_cr("Block B%d", block->block_id()); aoqi@0: ); aoqi@0: aoqi@0: // Pushed stack for conditions aoqi@0: IntegerStack pushed; aoqi@0: // Process If aoqi@0: BlockBegin *parent = block->dominator(); aoqi@0: if (parent != NULL) { aoqi@0: If *cond = parent->end()->as_If(); aoqi@0: if (cond != NULL) { aoqi@0: process_if(pushed, block, cond); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Interate over current block aoqi@0: InstructionList arrays; aoqi@0: AccessIndexedList accessIndexed; aoqi@0: Instruction *cur = block; aoqi@0: aoqi@0: while (cur) { aoqi@0: // Ensure cur wasn't inserted during the elimination aoqi@0: if (cur->id() < this->_bounds.length()) { aoqi@0: // Process only if it is an access indexed instruction aoqi@0: AccessIndexed *ai = cur->as_AccessIndexed(); aoqi@0: if (ai != NULL) { aoqi@0: process_access_indexed(loop_header, block, ai); aoqi@0: accessIndexed.append(ai); aoqi@0: if (!arrays.contains(ai->array())) { aoqi@0: arrays.append(ai->array()); aoqi@0: } aoqi@0: Bound *b = get_bound(ai->index()); aoqi@0: if (!b->lower_instr()) { aoqi@0: // Lower bound is constant aoqi@0: update_bound(pushed, ai->index(), Instruction::geq, NULL, 0); aoqi@0: } aoqi@0: if (!b->has_upper()) { aoqi@0: if (ai->length() && ai->length()->type()->as_IntConstant()) { aoqi@0: int value = ai->length()->type()->as_IntConstant()->value(); aoqi@0: update_bound(pushed, ai->index(), Instruction::lss, NULL, value); aoqi@0: } else { aoqi@0: // Has no upper bound aoqi@0: Instruction *instr = ai->length(); aoqi@0: if (instr != NULL) instr = ai->array(); aoqi@0: update_bound(pushed, ai->index(), Instruction::lss, instr, 0); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: cur = cur->next(); aoqi@0: } aoqi@0: aoqi@0: // Output current condition stack aoqi@0: TRACE_RANGE_CHECK_ELIMINATION(dump_condition_stack(block)); aoqi@0: aoqi@0: // Do in block motion of range checks aoqi@0: in_block_motion(block, accessIndexed, arrays); aoqi@0: aoqi@0: // Call all dominated blocks aoqi@0: for (int i=0; idominates()->length(); i++) { aoqi@0: BlockBegin *next = block->dominates()->at(i); aoqi@0: if (!next->is_set(BlockBegin::donot_eliminate_range_checks)) { aoqi@0: // if current block is a loop header and: aoqi@0: // - next block belongs to the same loop aoqi@0: // or aoqi@0: // - next block belongs to an inner loop aoqi@0: // then current block is the loop header for next block aoqi@0: if (block->is_set(BlockBegin::linear_scan_loop_header_flag) && (block->loop_index() == next->loop_index() || next->loop_depth() > block->loop_depth())) { aoqi@0: calc_bounds(next, block); aoqi@0: } else { aoqi@0: calc_bounds(next, loop_header); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Reset stack aoqi@0: for (int i=0; ipop(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: // Dump condition stack aoqi@0: void RangeCheckEliminator::dump_condition_stack(BlockBegin *block) { aoqi@0: for (int i=0; i<_ir->linear_scan_order()->length(); i++) { aoqi@0: BlockBegin *cur_block = _ir->linear_scan_order()->at(i); aoqi@0: Instruction *instr = cur_block; aoqi@0: for_each_phi_fun(cur_block, phi, aoqi@0: BoundStack *bound_stack = _bounds.at(phi->id()); aoqi@0: if (bound_stack && bound_stack->length() > 0) { aoqi@0: Bound *bound = bound_stack->top(); aoqi@0: if ((bound->has_lower() || bound->has_upper()) && (bound->lower_instr() != phi || bound->upper_instr() != phi || bound->lower() != 0 || bound->upper() != 0)) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION(tty->fill_to(2*block->dominator_depth()); aoqi@0: tty->print("i%d", phi->id()); aoqi@0: tty->print(": "); aoqi@0: bound->print(); aoqi@0: tty->cr(); aoqi@0: ); aoqi@0: } aoqi@0: }); aoqi@0: aoqi@0: while (!instr->as_BlockEnd()) { aoqi@0: if (instr->id() < _bounds.length()) { aoqi@0: BoundStack *bound_stack = _bounds.at(instr->id()); aoqi@0: if (bound_stack && bound_stack->length() > 0) { aoqi@0: Bound *bound = bound_stack->top(); aoqi@0: if ((bound->has_lower() || bound->has_upper()) && (bound->lower_instr() != instr || bound->upper_instr() != instr || bound->lower() != 0 || bound->upper() != 0)) { aoqi@0: TRACE_RANGE_CHECK_ELIMINATION(tty->fill_to(2*block->dominator_depth()); aoqi@0: tty->print("i%d", instr->id()); aoqi@0: tty->print(": "); aoqi@0: bound->print(); aoqi@0: tty->cr(); aoqi@0: ); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: instr = instr->next(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Verification or the IR aoqi@0: RangeCheckEliminator::Verification::Verification(IR *ir) : _used(BlockBegin::number_of_blocks(), false) { aoqi@0: this->_ir = ir; aoqi@0: ir->iterate_linear_scan_order(this); aoqi@0: } aoqi@0: aoqi@0: // Verify this block aoqi@0: void RangeCheckEliminator::Verification::block_do(BlockBegin *block) { aoqi@0: If *cond = block->end()->as_If(); aoqi@0: // Watch out: tsux and fsux can be the same! aoqi@0: if (block->number_of_sux() > 1) { aoqi@0: for (int i=0; inumber_of_sux(); i++) { aoqi@0: BlockBegin *sux = block->sux_at(i); aoqi@0: BlockBegin *pred = NULL; aoqi@0: for (int j=0; jnumber_of_preds(); j++) { aoqi@0: BlockBegin *cur = sux->pred_at(j); aoqi@0: assert(cur != NULL, "Predecessor must not be null"); aoqi@0: if (!pred) { aoqi@0: pred = cur; aoqi@0: } aoqi@0: assert(cur == pred, "Block must not have more than one predecessor if its predecessor has more than one successor"); aoqi@0: } aoqi@0: assert(sux->number_of_preds() >= 1, "Block must have at least one predecessor"); aoqi@0: assert(sux->pred_at(0) == block, "Wrong successor"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: BlockBegin *dominator = block->dominator(); aoqi@0: if (dominator) { aoqi@0: assert(block != _ir->start(), "Start block must not have a dominator!"); aoqi@0: assert(can_reach(dominator, block), "Dominator can't reach his block !"); aoqi@0: assert(can_reach(_ir->start(), dominator), "Dominator is unreachable !"); aoqi@0: assert(!can_reach(_ir->start(), block, dominator), "Wrong dominator ! Block can be reached anyway !"); aoqi@0: BlockList *all_blocks = _ir->linear_scan_order(); aoqi@0: for (int i=0; ilength(); i++) { aoqi@0: BlockBegin *cur = all_blocks->at(i); aoqi@0: if (cur != dominator && cur != block) { aoqi@0: assert(can_reach(dominator, block, cur), "There has to be another dominator!"); aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: assert(block == _ir->start(), "Only start block must not have a dominator"); aoqi@0: } aoqi@0: aoqi@0: if (block->is_set(BlockBegin::linear_scan_loop_header_flag)) { aoqi@0: int loop_index = block->loop_index(); aoqi@0: BlockList *all_blocks = _ir->linear_scan_order(); aoqi@0: assert(block->number_of_preds() >= 1, "Block must have at least one predecessor"); aoqi@0: assert(!block->is_set(BlockBegin::exception_entry_flag), "Loop header must not be exception handler!"); aoqi@0: // Sometimes, the backbranch comes from an exception handler. In aoqi@0: // this case, loop indexes/loop depths may not appear correct. aoqi@0: bool loop_through_xhandler = false; aoqi@0: for (int i = 0; i < block->number_of_exception_handlers(); i++) { aoqi@0: BlockBegin *xhandler = block->exception_handler_at(i); aoqi@0: for (int j = 0; j < block->number_of_preds(); j++) { aoqi@0: if (dominates(xhandler, block->pred_at(j)) || xhandler == block->pred_at(j)) { aoqi@0: loop_through_xhandler = true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: for (int i=0; inumber_of_sux(); i++) { aoqi@0: BlockBegin *sux = block->sux_at(i); aoqi@0: assert(sux->loop_depth() != block->loop_depth() || sux->loop_index() == block->loop_index() || loop_through_xhandler, "Loop index has to be same"); aoqi@0: assert(sux->loop_depth() == block->loop_depth() || sux->loop_index() != block->loop_index(), "Loop index has to be different"); aoqi@0: } aoqi@0: aoqi@0: for (int i=0; ilength(); i++) { aoqi@0: BlockBegin *cur = all_blocks->at(i); aoqi@0: if (cur->loop_index() == loop_index && cur != block) { aoqi@0: assert(dominates(block->dominator(), cur), "Dominator of loop header must dominate all loop blocks"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: Instruction *cur = block; aoqi@0: while (cur) { aoqi@0: assert(cur->block() == block, "Block begin has to be set correctly!"); aoqi@0: cur = cur->next(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Loop header must dominate all loop blocks aoqi@0: bool RangeCheckEliminator::Verification::dominates(BlockBegin *dominator, BlockBegin *block) { aoqi@0: BlockBegin *cur = block->dominator(); aoqi@0: while (cur && cur != dominator) { aoqi@0: cur = cur->dominator(); aoqi@0: } aoqi@0: return cur == dominator; aoqi@0: } aoqi@0: aoqi@0: // Try to reach Block end beginning in Block start and not using Block dont_use aoqi@0: bool RangeCheckEliminator::Verification::can_reach(BlockBegin *start, BlockBegin *end, BlockBegin *dont_use /* = NULL */) { aoqi@0: if (start == end) return start != dont_use; aoqi@0: // Simple BSF from start to end aoqi@0: // BlockBeginList _current; aoqi@0: for (int i=0; i<_used.length(); i++) { aoqi@0: _used[i] = false; aoqi@0: } aoqi@0: _current.truncate(0); aoqi@0: _successors.truncate(0); aoqi@0: if (start != dont_use) { aoqi@0: _current.push(start); aoqi@0: _used[start->block_id()] = true; aoqi@0: } aoqi@0: aoqi@0: // BlockBeginList _successors; aoqi@0: while (_current.length() > 0) { aoqi@0: BlockBegin *cur = _current.pop(); aoqi@0: // Add exception handlers to list aoqi@0: for (int i=0; inumber_of_exception_handlers(); i++) { aoqi@0: BlockBegin *xhandler = cur->exception_handler_at(i); aoqi@0: _successors.push(xhandler); aoqi@0: // Add exception handlers of _successors to list aoqi@0: for (int j=0; jnumber_of_exception_handlers(); j++) { aoqi@0: BlockBegin *sux_xhandler = xhandler->exception_handler_at(j); aoqi@0: _successors.push(sux_xhandler); aoqi@0: } aoqi@0: } aoqi@0: // Add normal _successors to list aoqi@0: for (int i=0; inumber_of_sux(); i++) { aoqi@0: BlockBegin *sux = cur->sux_at(i); aoqi@0: _successors.push(sux); aoqi@0: // Add exception handlers of _successors to list aoqi@0: for (int j=0; jnumber_of_exception_handlers(); j++) { aoqi@0: BlockBegin *xhandler = sux->exception_handler_at(j); aoqi@0: _successors.push(xhandler); aoqi@0: } aoqi@0: } aoqi@0: for (int i=0; i<_successors.length(); i++) { aoqi@0: BlockBegin *sux = _successors[i]; aoqi@0: assert(sux != NULL, "Successor must not be NULL!"); aoqi@0: if (sux == end) { aoqi@0: return true; aoqi@0: } aoqi@0: if (sux != dont_use && !_used[sux->block_id()]) { aoqi@0: _used[sux->block_id()] = true; aoqi@0: _current.push(sux); aoqi@0: } aoqi@0: } aoqi@0: _successors.truncate(0); aoqi@0: } aoqi@0: aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // Bound aoqi@0: RangeCheckEliminator::Bound::~Bound() { aoqi@0: } aoqi@0: aoqi@0: // Bound constructor aoqi@0: RangeCheckEliminator::Bound::Bound() { aoqi@0: init(); aoqi@0: this->_lower = min_jint; aoqi@0: this->_upper = max_jint; aoqi@0: this->_lower_instr = NULL; aoqi@0: this->_upper_instr = NULL; aoqi@0: } aoqi@0: aoqi@0: // Bound constructor aoqi@0: RangeCheckEliminator::Bound::Bound(int lower, Value lower_instr, int upper, Value upper_instr) { aoqi@0: init(); aoqi@0: assert(!lower_instr || !lower_instr->as_Constant() || !lower_instr->type()->as_IntConstant(), "Must not be constant!"); aoqi@0: assert(!upper_instr || !upper_instr->as_Constant() || !upper_instr->type()->as_IntConstant(), "Must not be constant!"); aoqi@0: this->_lower = lower; aoqi@0: this->_upper = upper; aoqi@0: this->_lower_instr = lower_instr; aoqi@0: this->_upper_instr = upper_instr; aoqi@0: } aoqi@0: aoqi@0: // Bound constructor aoqi@0: RangeCheckEliminator::Bound::Bound(Instruction::Condition cond, Value v, int constant) { aoqi@0: assert(!v || (v->type() && (v->type()->as_IntType() || v->type()->as_ObjectType())), "Type must be array or integer!"); aoqi@0: assert(!v || !v->as_Constant() || !v->type()->as_IntConstant(), "Must not be constant!"); aoqi@0: aoqi@0: init(); aoqi@0: if (cond == Instruction::eql) { aoqi@0: _lower = constant; aoqi@0: _lower_instr = v; aoqi@0: _upper = constant; aoqi@0: _upper_instr = v; aoqi@0: } else if (cond == Instruction::neq) { aoqi@0: _lower = min_jint; aoqi@0: _upper = max_jint; aoqi@0: _lower_instr = NULL; aoqi@0: _upper_instr = NULL; aoqi@0: if (v == NULL) { aoqi@0: if (constant == min_jint) { aoqi@0: _lower++; aoqi@0: } aoqi@0: if (constant == max_jint) { aoqi@0: _upper--; aoqi@0: } aoqi@0: } aoqi@0: } else if (cond == Instruction::geq) { aoqi@0: _lower = constant; aoqi@0: _lower_instr = v; aoqi@0: _upper = max_jint; aoqi@0: _upper_instr = NULL; aoqi@0: } else if (cond == Instruction::leq) { aoqi@0: _lower = min_jint; aoqi@0: _lower_instr = NULL; aoqi@0: _upper = constant; aoqi@0: _upper_instr = v; aoqi@0: } else { aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Set lower aoqi@0: void RangeCheckEliminator::Bound::set_lower(int value, Value v) { aoqi@0: assert(!v || !v->as_Constant() || !v->type()->as_IntConstant(), "Must not be constant!"); aoqi@0: this->_lower = value; aoqi@0: this->_lower_instr = v; aoqi@0: } aoqi@0: aoqi@0: // Set upper aoqi@0: void RangeCheckEliminator::Bound::set_upper(int value, Value v) { aoqi@0: assert(!v || !v->as_Constant() || !v->type()->as_IntConstant(), "Must not be constant!"); aoqi@0: this->_upper = value; aoqi@0: this->_upper_instr = v; aoqi@0: } aoqi@0: aoqi@0: // Add constant -> no overflow may occur aoqi@0: void RangeCheckEliminator::Bound::add_constant(int value) { aoqi@0: this->_lower += value; aoqi@0: this->_upper += value; aoqi@0: } aoqi@0: aoqi@0: // Init aoqi@0: void RangeCheckEliminator::Bound::init() { aoqi@0: } aoqi@0: aoqi@0: // or aoqi@0: void RangeCheckEliminator::Bound::or_op(Bound *b) { aoqi@0: // Watch out, bound is not guaranteed not to overflow! aoqi@0: // Update lower bound aoqi@0: if (_lower_instr != b->_lower_instr || (_lower_instr && _lower != b->_lower)) { aoqi@0: _lower_instr = NULL; aoqi@0: _lower = min_jint; aoqi@0: } else { aoqi@0: _lower = MIN2(_lower, b->_lower); aoqi@0: } aoqi@0: // Update upper bound aoqi@0: if (_upper_instr != b->_upper_instr || (_upper_instr && _upper != b->_upper)) { aoqi@0: _upper_instr = NULL; aoqi@0: _upper = max_jint; aoqi@0: } else { aoqi@0: _upper = MAX2(_upper, b->_upper); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // and aoqi@0: void RangeCheckEliminator::Bound::and_op(Bound *b) { aoqi@0: // Update lower bound aoqi@0: if (_lower_instr == b->_lower_instr) { aoqi@0: _lower = MAX2(_lower, b->_lower); aoqi@0: } aoqi@0: if (b->has_lower()) { aoqi@0: bool set = true; aoqi@0: if (_lower_instr != NULL && b->_lower_instr != NULL) { aoqi@0: set = (_lower_instr->dominator_depth() > b->_lower_instr->dominator_depth()); aoqi@0: } aoqi@0: if (set) { aoqi@0: _lower = b->_lower; aoqi@0: _lower_instr = b->_lower_instr; aoqi@0: } aoqi@0: } aoqi@0: // Update upper bound aoqi@0: if (_upper_instr == b->_upper_instr) { aoqi@0: _upper = MIN2(_upper, b->_upper); aoqi@0: } aoqi@0: if (b->has_upper()) { aoqi@0: bool set = true; aoqi@0: if (_upper_instr != NULL && b->_upper_instr != NULL) { aoqi@0: set = (_upper_instr->dominator_depth() > b->_upper_instr->dominator_depth()); aoqi@0: } aoqi@0: if (set) { aoqi@0: _upper = b->_upper; aoqi@0: _upper_instr = b->_upper_instr; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // has_upper aoqi@0: bool RangeCheckEliminator::Bound::has_upper() { aoqi@0: return _upper_instr != NULL || _upper < max_jint; aoqi@0: } aoqi@0: aoqi@0: // is_smaller aoqi@0: bool RangeCheckEliminator::Bound::is_smaller(Bound *b) { aoqi@0: if (b->_lower_instr != _upper_instr) { aoqi@0: return false; aoqi@0: } aoqi@0: return _upper < b->_lower; aoqi@0: } aoqi@0: aoqi@0: // has_lower aoqi@0: bool RangeCheckEliminator::Bound::has_lower() { aoqi@0: return _lower_instr != NULL || _lower > min_jint; aoqi@0: } aoqi@0: aoqi@0: // in_array_bound aoqi@0: bool RangeCheckEliminator::in_array_bound(Bound *bound, Value array){ aoqi@0: if (!bound) return false; aoqi@0: assert(array != NULL, "Must not be null!"); aoqi@0: assert(bound != NULL, "Must not be null!"); aoqi@0: if (bound->lower() >=0 && bound->lower_instr() == NULL && bound->upper() < 0 && bound->upper_instr() != NULL) { aoqi@0: ArrayLength *len = bound->upper_instr()->as_ArrayLength(); aoqi@0: if (bound->upper_instr() == array || (len != NULL && len->array() == array)) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // remove_lower aoqi@0: void RangeCheckEliminator::Bound::remove_lower() { aoqi@0: _lower = min_jint; aoqi@0: _lower_instr = NULL; aoqi@0: } aoqi@0: aoqi@0: // remove_upper aoqi@0: void RangeCheckEliminator::Bound::remove_upper() { aoqi@0: _upper = max_jint; aoqi@0: _upper_instr = NULL; aoqi@0: } aoqi@0: aoqi@0: // upper aoqi@0: int RangeCheckEliminator::Bound::upper() { aoqi@0: return _upper; aoqi@0: } aoqi@0: aoqi@0: // lower aoqi@0: int RangeCheckEliminator::Bound::lower() { aoqi@0: return _lower; aoqi@0: } aoqi@0: aoqi@0: // upper_instr aoqi@0: Value RangeCheckEliminator::Bound::upper_instr() { aoqi@0: return _upper_instr; aoqi@0: } aoqi@0: aoqi@0: // lower_instr aoqi@0: Value RangeCheckEliminator::Bound::lower_instr() { aoqi@0: return _lower_instr; aoqi@0: } aoqi@0: aoqi@0: // print aoqi@0: void RangeCheckEliminator::Bound::print() { aoqi@0: tty->print("%s", ""); aoqi@0: if (this->_lower_instr || this->_lower != min_jint) { aoqi@0: if (this->_lower_instr) { aoqi@0: tty->print("i%d", this->_lower_instr->id()); aoqi@0: if (this->_lower > 0) { aoqi@0: tty->print("+%d", _lower); aoqi@0: } aoqi@0: if (this->_lower < 0) { aoqi@0: tty->print("%d", _lower); aoqi@0: } aoqi@0: } else { aoqi@0: tty->print("%d", _lower); aoqi@0: } aoqi@0: tty->print(" <= "); aoqi@0: } aoqi@0: tty->print("x"); aoqi@0: if (this->_upper_instr || this->_upper != max_jint) { aoqi@0: tty->print(" <= "); aoqi@0: if (this->_upper_instr) { aoqi@0: tty->print("i%d", this->_upper_instr->id()); aoqi@0: if (this->_upper > 0) { aoqi@0: tty->print("+%d", _upper); aoqi@0: } aoqi@0: if (this->_upper < 0) { aoqi@0: tty->print("%d", _upper); aoqi@0: } aoqi@0: } else { aoqi@0: tty->print("%d", _upper); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Copy aoqi@0: RangeCheckEliminator::Bound *RangeCheckEliminator::Bound::copy() { aoqi@0: Bound *b = new Bound(); aoqi@0: b->_lower = _lower; aoqi@0: b->_lower_instr = _lower_instr; aoqi@0: b->_upper = _upper; aoqi@0: b->_upper_instr = _upper_instr; aoqi@0: return b; aoqi@0: } aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: // Add assertion aoqi@0: void RangeCheckEliminator::Bound::add_assertion(Instruction *instruction, Instruction *position, int i, Value instr, Instruction::Condition cond) { aoqi@0: Instruction *result = position; aoqi@0: Instruction *compare_with = NULL; aoqi@0: ValueStack *state = position->state_before(); aoqi@0: if (position->as_BlockEnd() && !position->as_Goto()) { aoqi@0: state = position->as_BlockEnd()->state_before(); aoqi@0: } aoqi@0: Instruction *instruction_before = position->prev(); aoqi@0: if (position->as_Return() && Compilation::current()->method()->is_synchronized() && instruction_before->as_MonitorExit()) { aoqi@0: instruction_before = instruction_before->prev(); aoqi@0: } aoqi@0: result = instruction_before; aoqi@0: // Load constant only if needed aoqi@0: Constant *constant = NULL; aoqi@0: if (i != 0 || !instr) { aoqi@0: constant = new Constant(new IntConstant(i)); aoqi@0: NOT_PRODUCT(constant->set_printable_bci(position->printable_bci())); aoqi@0: result = result->insert_after(constant); aoqi@0: compare_with = constant; aoqi@0: } aoqi@0: aoqi@0: if (instr) { aoqi@0: assert(instr->type()->as_ObjectType() || instr->type()->as_IntType(), "Type must be array or integer!"); aoqi@0: compare_with = instr; aoqi@0: // Load array length if necessary aoqi@0: Instruction *op = instr; aoqi@0: if (instr->type()->as_ObjectType()) { aoqi@0: assert(state, "must not be null"); aoqi@0: ArrayLength *length = new ArrayLength(instr, state->copy()); aoqi@0: NOT_PRODUCT(length->set_printable_bci(position->printable_bci())); aoqi@0: length->set_exception_state(length->state_before()); aoqi@0: result = result->insert_after(length); aoqi@0: op = length; aoqi@0: compare_with = length; aoqi@0: } aoqi@0: // Add operation only if necessary aoqi@0: if (constant) { aoqi@0: ArithmeticOp *ao = new ArithmeticOp(Bytecodes::_iadd, constant, op, false, NULL); aoqi@0: NOT_PRODUCT(ao->set_printable_bci(position->printable_bci())); aoqi@0: result = result->insert_after(ao); aoqi@0: compare_with = ao; aoqi@0: // TODO: Check that add operation does not overflow! aoqi@0: } aoqi@0: } aoqi@0: assert(compare_with != NULL, "You have to compare with something!"); aoqi@0: assert(instruction != NULL, "Instruction must not be null!"); aoqi@0: aoqi@0: if (instruction->type()->as_ObjectType()) { aoqi@0: // Load array length if necessary aoqi@0: Instruction *op = instruction; aoqi@0: assert(state, "must not be null"); aoqi@0: ArrayLength *length = new ArrayLength(instruction, state->copy()); aoqi@0: length->set_exception_state(length->state_before()); aoqi@0: NOT_PRODUCT(length->set_printable_bci(position->printable_bci())); aoqi@0: result = result->insert_after(length); aoqi@0: instruction = length; aoqi@0: } aoqi@0: aoqi@0: Assert *assert = new Assert(instruction, cond, false, compare_with); aoqi@0: NOT_PRODUCT(assert->set_printable_bci(position->printable_bci())); aoqi@0: result->insert_after(assert); aoqi@0: } aoqi@0: aoqi@0: // Add assertions aoqi@0: void RangeCheckEliminator::add_assertions(Bound *bound, Instruction *instruction, Instruction *position) { aoqi@0: // Add lower bound assertion aoqi@0: if (bound->has_lower()) { aoqi@0: bound->add_assertion(instruction, position, bound->lower(), bound->lower_instr(), Instruction::geq); aoqi@0: } aoqi@0: // Add upper bound assertion aoqi@0: if (bound->has_upper()) { aoqi@0: bound->add_assertion(instruction, position, bound->upper(), bound->upper_instr(), Instruction::leq); aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: