src/hotspot/share/c1/c1_Optimizer.cpp
author mdoerr
Tue, 12 Nov 2019 16:13:16 +0100
changeset 59032 ad05ed6f2a77
parent 58273 08a5148e7c4e
permissions -rw-r--r--
8233820: Test crashed with assert(phi->operand_count() != 1 || phi->subst() != phi) failed: missed trivial simplification Summary: Verification code needs to skip illegal phi functions. Reviewed-by: thartmann, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 53806
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    26
#include "c1/c1_Canonicalizer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    27
#include "c1/c1_Optimizer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    28
#include "c1/c1_ValueMap.hpp"
46502
116a09d8f142 8180755: Remove use of bitMap.inline.hpp include from instanceKlass.hpp and c1_ValueSet.hpp
tschatzl
parents: 38033
diff changeset
    29
#include "c1/c1_ValueSet.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    30
#include "c1/c1_ValueStack.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 28954
diff changeset
    31
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    32
#include "utilities/bitMap.inline.hpp"
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    33
#include "compiler/compileLog.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
    35
typedef GrowableArray<ValueSet*> ValueSetList;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
Optimizer::Optimizer(IR* ir) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert(ir->is_valid(), "IR must be valid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _ir = ir;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
class CE_Eliminator: public BlockClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  IR* _hir;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  int _cee_count;                                // the number of CEs successfully eliminated
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    46
  int _ifop_count;                               // the number of IfOps successfully simplified
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  int _has_substitution;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
 public:
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    50
  CE_Eliminator(IR* hir) : _hir(hir), _cee_count(0), _ifop_count(0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    _has_substitution = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    _hir->iterate_preorder(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if (_has_substitution) {
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    54
      // substituted some ifops/phis, so resolve the substitution
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      SubstitutionResolver sr(_hir);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    57
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    58
    CompileLog* log = _hir->compilation()->log();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    59
    if (log != NULL)
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    60
      log->set_context("optimize name='cee'");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    62
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    63
  ~CE_Eliminator() {
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    64
    CompileLog* log = _hir->compilation()->log();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    65
    if (log != NULL)
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    66
      log->clear_context(); // skip marker if nothing was printed
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    67
  }
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
    68
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  int cee_count() const                          { return _cee_count; }
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    70
  int ifop_count() const                         { return _ifop_count; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void adjust_exception_edges(BlockBegin* block, BlockBegin* sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    int e = sux->number_of_exception_handlers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    for (int i = 0; i < e; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      BlockBegin* xhandler = sux->exception_handler_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      block->add_exception_handler(xhandler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      assert(xhandler->is_predecessor(sux), "missing predecessor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      if (sux->number_of_preds() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
        // sux is disconnected from graph so disconnect from exception handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
        xhandler->remove_predecessor(sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      if (!xhandler->is_predecessor(block)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
        xhandler->add_predecessor(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    89
  virtual void block_do(BlockBegin* block);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    90
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    91
 private:
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    92
  Value make_ifop(Value x, Instruction::Condition cond, Value y, Value tval, Value fval);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    93
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    95
void CE_Eliminator::block_do(BlockBegin* block) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    96
  // 1) find conditional expression
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    97
  // check if block ends with an If
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    98
  If* if_ = block->end()->as_If();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
    99
  if (if_ == NULL) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   101
  // check if If works on int or object types
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   102
  // (we cannot handle If's working on long, float or doubles yet,
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   103
  // since IfOp doesn't support them - these If's show up if cmp
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   104
  // operations followed by If's are eliminated)
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   105
  ValueType* if_type = if_->x()->type();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   106
  if (!if_type->is_int() && !if_type->is_object()) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   108
  BlockBegin* t_block = if_->tsux();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   109
  BlockBegin* f_block = if_->fsux();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   110
  Instruction* t_cur = t_block->next();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   111
  Instruction* f_cur = f_block->next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   113
  // one Constant may be present between BlockBegin and BlockEnd
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   114
  Value t_const = NULL;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   115
  Value f_const = NULL;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   116
  if (t_cur->as_Constant() != NULL && !t_cur->can_trap()) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   117
    t_const = t_cur;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   118
    t_cur = t_cur->next();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   119
  }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   120
  if (f_cur->as_Constant() != NULL && !f_cur->can_trap()) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   121
    f_const = f_cur;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   122
    f_cur = f_cur->next();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   123
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   125
  // check if both branches end with a goto
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   126
  Goto* t_goto = t_cur->as_Goto();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   127
  if (t_goto == NULL) return;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   128
  Goto* f_goto = f_cur->as_Goto();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   129
  if (f_goto == NULL) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   131
  // check if both gotos merge into the same block
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   132
  BlockBegin* sux = t_goto->default_sux();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   133
  if (sux != f_goto->default_sux()) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   135
  // check if at least one word was pushed on sux_state
11425
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   136
  // inlining depths must match
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   137
  ValueStack* if_state = if_->state();
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   138
  ValueStack* sux_state = sux->state();
11432
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   139
  if (if_state->scope()->level() > sux_state->scope()->level()) {
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   140
    while (sux_state->scope() != if_state->scope()) {
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   141
      if_state = if_state->caller_state();
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   142
      assert(if_state != NULL, "states do not match up");
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   143
    }
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   144
  } else if (if_state->scope()->level() < sux_state->scope()->level()) {
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   145
    while (sux_state->scope() != if_state->scope()) {
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   146
      sux_state = sux_state->caller_state();
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   147
      assert(sux_state != NULL, "states do not match up");
c731e8d846ce 7123108: C1: assert(if_state != NULL) failed: states do not match up
roland
parents: 11425
diff changeset
   148
    }
11425
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   149
  }
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   150
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   151
  if (sux_state->stack_size() <= if_state->stack_size()) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   153
  // check if phi function is present at end of successor stack and that
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   154
  // only this phi was pushed on the stack
11425
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   155
  Value sux_phi = sux_state->stack_at(if_state->stack_size());
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   156
  if (sux_phi == NULL || sux_phi->as_Phi() == NULL || sux_phi->as_Phi()->block() != sux) return;
11425
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   157
  if (sux_phi->type()->size() != sux_state->stack_size() - if_state->stack_size()) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   159
  // get the values that were pushed in the true- and false-branch
11425
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   160
  Value t_value = t_goto->state()->stack_at(if_state->stack_size());
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   161
  Value f_value = f_goto->state()->stack_at(if_state->stack_size());
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   162
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   163
  // backend does not support floats
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   164
  assert(t_value->type()->base() == f_value->type()->base(), "incompatible types");
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   165
  if (t_value->type()->is_float_kind()) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   167
  // check that successor has no other phi functions but sux_phi
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   168
  // this can happen when t_block or f_block contained additonal stores to local variables
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   169
  // that are no longer represented by explicit instructions
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   170
  for_each_phi_fun(sux, phi,
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   171
                   if (phi != sux_phi) return;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   172
                   );
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   173
  // true and false blocks can't have phis
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   174
  for_each_phi_fun(t_block, phi, return; );
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   175
  for_each_phi_fun(f_block, phi, return; );
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   176
53806
3bd474c23ee4 8218721: C1's CEE optimization produces safepoint poll with invalid debug information
thartmann
parents: 51333
diff changeset
   177
  // Only replace safepoint gotos if state_before information is available (if is a safepoint)
3bd474c23ee4 8218721: C1's CEE optimization produces safepoint poll with invalid debug information
thartmann
parents: 51333
diff changeset
   178
  bool is_safepoint = if_->is_safepoint();
3bd474c23ee4 8218721: C1's CEE optimization produces safepoint poll with invalid debug information
thartmann
parents: 51333
diff changeset
   179
  if (!is_safepoint && (t_goto->is_safepoint() || f_goto->is_safepoint())) {
3bd474c23ee4 8218721: C1's CEE optimization produces safepoint poll with invalid debug information
thartmann
parents: 51333
diff changeset
   180
    return;
3bd474c23ee4 8218721: C1's CEE optimization produces safepoint poll with invalid debug information
thartmann
parents: 51333
diff changeset
   181
  }
3bd474c23ee4 8218721: C1's CEE optimization produces safepoint poll with invalid debug information
thartmann
parents: 51333
diff changeset
   182
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   183
  // 2) substitute conditional expression
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   184
  //    with an IfOp followed by a Goto
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   185
  // cut if_ away and get node before
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 13974
diff changeset
   186
  Instruction* cur_end = if_->prev();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   188
  // append constants of true- and false-block if necessary
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   189
  // clone constants because original block must not be destroyed
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   190
  assert((t_value != f_const && f_value != t_const) || t_const == f_const, "mismatch");
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   191
  if (t_value == t_const) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   192
    t_value = new Constant(t_const->type());
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   193
    NOT_PRODUCT(t_value->set_printable_bci(if_->printable_bci()));
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   194
    cur_end = cur_end->set_next(t_value);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   195
  }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   196
  if (f_value == f_const) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   197
    f_value = new Constant(f_const->type());
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   198
    NOT_PRODUCT(f_value->set_printable_bci(if_->printable_bci()));
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   199
    cur_end = cur_end->set_next(f_value);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   200
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   202
  Value result = make_ifop(if_->x(), if_->cond(), if_->y(), t_value, f_value);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   203
  assert(result != NULL, "make_ifop must return a non-null instruction");
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   204
  if (!result->is_linked() && result->can_be_linked()) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   205
    NOT_PRODUCT(result->set_printable_bci(if_->printable_bci()));
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   206
    cur_end = cur_end->set_next(result);
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   207
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   209
  // append Goto to successor
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 13974
diff changeset
   210
  ValueStack* state_before = if_->state_before();
53806
3bd474c23ee4 8218721: C1's CEE optimization produces safepoint poll with invalid debug information
thartmann
parents: 51333
diff changeset
   211
  Goto* goto_ = new Goto(sux, state_before, is_safepoint);
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   212
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   213
  // prepare state for Goto
11425
fd1547049bec 7114106: C1: assert(goto_state->is_same(sux_state)) failed: states must match now
roland
parents: 10015
diff changeset
   214
  ValueStack* goto_state = if_state;
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   215
  goto_state = goto_state->copy(ValueStack::StateAfter, goto_state->bci());
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   216
  goto_state->push(result->type(), result);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   217
  assert(goto_state->is_same(sux_state), "states must match now");
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   218
  goto_->set_state(goto_state);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   219
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   220
  cur_end = cur_end->set_next(goto_, goto_state->bci());
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   221
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   222
  // Adjust control flow graph
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   223
  BlockBegin::disconnect_edge(block, t_block);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   224
  BlockBegin::disconnect_edge(block, f_block);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   225
  if (t_block->number_of_preds() == 0) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   226
    BlockBegin::disconnect_edge(t_block, sux);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   227
  }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   228
  adjust_exception_edges(block, t_block);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   229
  if (f_block->number_of_preds() == 0) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   230
    BlockBegin::disconnect_edge(f_block, sux);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   231
  }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   232
  adjust_exception_edges(block, f_block);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   233
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   234
  // update block end
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   235
  block->set_end(goto_);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   236
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   237
  // substitute the phi if possible
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   238
  if (sux_phi->as_Phi()->operand_count() == 1) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   239
    assert(sux_phi->as_Phi()->operand_at(0) == result, "screwed up phi");
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   240
    sux_phi->set_subst(result);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   241
    _has_substitution = true;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   242
  }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   243
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   244
  // 3) successfully eliminated a conditional expression
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   245
  _cee_count++;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   246
  if (PrintCEE) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   247
    tty->print_cr("%d. CEE in B%d (B%d B%d)", cee_count(), block->block_id(), t_block->block_id(), f_block->block_id());
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   248
    tty->print_cr("%d. IfOp in B%d", ifop_count(), block->block_id());
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   249
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   251
  _hir->verify();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   252
}
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   253
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   254
Value CE_Eliminator::make_ifop(Value x, Instruction::Condition cond, Value y, Value tval, Value fval) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   255
  if (!OptimizeIfOps) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   256
    return new IfOp(x, cond, y, tval, fval);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   257
  }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   258
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   259
  tval = tval->subst();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   260
  fval = fval->subst();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   261
  if (tval == fval) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   262
    _ifop_count++;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   263
    return tval;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   264
  }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   265
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   266
  x = x->subst();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   267
  y = y->subst();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   268
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   269
  Constant* y_const = y->as_Constant();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   270
  if (y_const != NULL) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   271
    IfOp* x_ifop = x->as_IfOp();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   272
    if (x_ifop != NULL) {                 // x is an ifop, y is a constant
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   273
      Constant* x_tval_const = x_ifop->tval()->subst()->as_Constant();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   274
      Constant* x_fval_const = x_ifop->fval()->subst()->as_Constant();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   276
      if (x_tval_const != NULL && x_fval_const != NULL) {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   277
        Instruction::Condition x_ifop_cond = x_ifop->cond();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   278
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   279
        Constant::CompareResult t_compare_res = x_tval_const->compare(cond, y_const);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   280
        Constant::CompareResult f_compare_res = x_fval_const->compare(cond, y_const);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   281
9629
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   282
        // not_comparable here is a valid return in case we're comparing unloaded oop constants
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   283
        if (t_compare_res != Constant::not_comparable && f_compare_res != Constant::not_comparable) {
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   284
          Value new_tval = t_compare_res == Constant::cond_true ? tval : fval;
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   285
          Value new_fval = f_compare_res == Constant::cond_true ? tval : fval;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
9629
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   287
          _ifop_count++;
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   288
          if (new_tval == new_fval) {
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   289
            return new_tval;
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   290
          } else {
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   291
            return new IfOp(x_ifop->x(), x_ifop_cond, x_ifop->y(), new_tval, new_fval);
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   292
          }
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   293
        }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   294
      }
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   295
    } else {
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   296
      Constant* x_const = x->as_Constant();
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   297
      if (x_const != NULL) {         // x and y are constants
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   298
        Constant::CompareResult x_compare_res = x_const->compare(cond, y_const);
9629
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   299
        // not_comparable here is a valid return in case we're comparing unloaded oop constants
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   300
        if (x_compare_res != Constant::not_comparable) {
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   301
          _ifop_count++;
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   302
          return x_compare_res == Constant::cond_true ? tval : fval;
1f4dc6af5ad8 7042153: guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
iveresov
parents: 9102
diff changeset
   303
        }
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   304
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   307
  return new IfOp(x, cond, y, tval, fval);
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   308
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
void Optimizer::eliminate_conditional_expressions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  // find conditional expressions & replace them with IfOps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  CE_Eliminator ce(ir());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
class BlockMerger: public BlockClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  IR* _hir;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  int _merge_count;              // the number of block pairs successfully merged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  BlockMerger(IR* hir)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  : _hir(hir)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  , _merge_count(0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    _hir->iterate_preorder(this);
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   326
    CompileLog* log = _hir->compilation()->log();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   327
    if (log != NULL)
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   328
      log->set_context("optimize name='eliminate_blocks'");
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   329
  }
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   330
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   331
  ~BlockMerger() {
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   332
    CompileLog* log = _hir->compilation()->log();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   333
    if (log != NULL)
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   334
      log->clear_context(); // skip marker if nothing was printed
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  bool try_merge(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    BlockEnd* end = block->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    if (end->as_Goto() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      assert(end->number_of_sux() == 1, "end must have exactly one successor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
      // Note: It would be sufficient to check for the number of successors (= 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      //       in order to decide if this block can be merged potentially. That
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      //       would then also include switch statements w/ only a default case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      //       However, in that case we would need to make sure the switch tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      //       expression is executed if it can produce observable side effects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      //       We should probably have the canonicalizer simplifying such switch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      //       statements and then we are sure we don't miss these merge opportunities
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      //       here (was bug - gri 7/7/99).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      BlockBegin* sux = end->default_sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
      if (sux->number_of_preds() == 1 && !sux->is_entry_block() && !end->is_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
        // merge the two blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
        // verify that state at the end of block and at the beginning of sux are equal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
        // no phi functions must be present at beginning of sux
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
        ValueStack* sux_state = sux->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
        ValueStack* end_state = end->state();
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   358
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   359
        assert(end_state->scope() == sux_state->scope(), "scopes must match");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        assert(end_state->stack_size() == sux_state->stack_size(), "stack not equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
        assert(end_state->locals_size() == sux_state->locals_size(), "locals not equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
        int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
        Value sux_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
        for_each_stack_value(sux_state, index, sux_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
          assert(sux_value == end_state->stack_at(index), "stack not equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
        for_each_local_value(sux_state, index, sux_value) {
59032
ad05ed6f2a77 8233820: Test crashed with assert(phi->operand_count() != 1 || phi->subst() != phi) failed: missed trivial simplification
mdoerr
parents: 58273
diff changeset
   369
          Phi* sux_phi = sux_value->as_Phi();
ad05ed6f2a77 8233820: Test crashed with assert(phi->operand_count() != 1 || phi->subst() != phi) failed: missed trivial simplification
mdoerr
parents: 58273
diff changeset
   370
          if (sux_phi != NULL && sux_phi->is_illegal()) continue;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
          assert(sux_value == end_state->local_at(index), "locals not equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
        assert(sux_state->caller_state() == end_state->caller_state(), "caller not equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
        // find instruction before end & append first instruction of sux block
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 13974
diff changeset
   377
        Instruction* prev = end->prev();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
        Instruction* next = sux->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
        assert(prev->as_BlockEnd() == NULL, "must not be a BlockEnd");
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   380
        prev->set_next(next);
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 13974
diff changeset
   381
        prev->fixup_block_pointers();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
        sux->disconnect_from_graph();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
        block->set_end(sux->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
        // add exception handlers of deleted block, if any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
        for (int k = 0; k < sux->number_of_exception_handlers(); k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
          BlockBegin* xhandler = sux->exception_handler_at(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
          block->add_exception_handler(xhandler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
          // also substitute predecessor of exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
          assert(xhandler->is_predecessor(sux), "missing predecessor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
          xhandler->remove_predecessor(sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
          if (!xhandler->is_predecessor(block)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
            xhandler->add_predecessor(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
        // debugging output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
        _merge_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
        if (PrintBlockElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
          tty->print_cr("%d. merged B%d & B%d (stack size = %d)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
                        _merge_count, block->block_id(), sux->block_id(), sux->state()->stack_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
        _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
        If* if_ = block->end()->as_If();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
        if (if_) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
          IfOp* ifop    = if_->x()->as_IfOp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
          Constant* con = if_->y()->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
          bool swapped = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
          if (!con || !ifop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
            ifop = if_->y()->as_IfOp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
            con  = if_->x()->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
            swapped = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
          if (con && ifop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
            Constant* tval = ifop->tval()->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
            Constant* fval = ifop->fval()->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
            if (tval && fval) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
              // Find the instruction before if_, starting with ifop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
              // When if_ and ifop are not in the same block, prev
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
              // becomes NULL In such (rare) cases it is not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
              // profitable to perform the optimization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
              Value prev = ifop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
              while (prev != NULL && prev->next() != if_) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
                prev = prev->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
              if (prev != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
                Instruction::Condition cond = if_->cond();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
                BlockBegin* tsux = if_->tsux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
                BlockBegin* fsux = if_->fsux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
                if (swapped) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
                  cond = Instruction::mirror(cond);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                BlockBegin* tblock = tval->compare(cond, con, tsux, fsux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
                BlockBegin* fblock = fval->compare(cond, con, tsux, fsux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
                if (tblock != fblock && !if_->is_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
                  If* newif = new If(ifop->x(), ifop->cond(), false, ifop->y(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
                                     tblock, fblock, if_->state_before(), if_->is_safepoint());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
                  newif->set_state(if_->state()->copy());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
                  assert(prev->next() == if_, "must be guaranteed by above search");
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   445
                  NOT_PRODUCT(newif->set_printable_bci(if_->printable_bci()));
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   446
                  prev->set_next(newif);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
                  block->set_end(newif);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
                  _merge_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
                  if (PrintBlockElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
                    tty->print_cr("%d. replaced If and IfOp at end of B%d with single If", _merge_count, block->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
                  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  virtual void block_do(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    // repeat since the same block may merge again
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    while (try_merge(block)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
void Optimizer::eliminate_blocks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  // merge blocks if possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  BlockMerger bm(ir());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
class NullCheckEliminator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
class NullCheckVisitor: public InstructionVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  NullCheckEliminator* _nce;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  NullCheckEliminator* nce() { return _nce; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  NullCheckVisitor() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  void set_eliminator(NullCheckEliminator* nce) { _nce = nce; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  void do_Phi            (Phi*             x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  void do_Local          (Local*           x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  void do_Constant       (Constant*        x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  void do_LoadField      (LoadField*       x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  void do_StoreField     (StoreField*      x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  void do_ArrayLength    (ArrayLength*     x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  void do_LoadIndexed    (LoadIndexed*     x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  void do_StoreIndexed   (StoreIndexed*    x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  void do_NegateOp       (NegateOp*        x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  void do_ArithmeticOp   (ArithmeticOp*    x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  void do_ShiftOp        (ShiftOp*         x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  void do_LogicOp        (LogicOp*         x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  void do_CompareOp      (CompareOp*       x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  void do_IfOp           (IfOp*            x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  void do_Convert        (Convert*         x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  void do_NullCheck      (NullCheck*       x);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11886
diff changeset
   510
  void do_TypeCast       (TypeCast*        x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  void do_Invoke         (Invoke*          x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  void do_NewInstance    (NewInstance*     x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  void do_NewTypeArray   (NewTypeArray*    x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  void do_NewObjectArray (NewObjectArray*  x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  void do_NewMultiArray  (NewMultiArray*   x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  void do_CheckCast      (CheckCast*       x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  void do_InstanceOf     (InstanceOf*      x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  void do_MonitorEnter   (MonitorEnter*    x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  void do_MonitorExit    (MonitorExit*     x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  void do_Intrinsic      (Intrinsic*       x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  void do_BlockBegin     (BlockBegin*      x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  void do_Goto           (Goto*            x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  void do_If             (If*              x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  void do_IfInstanceOf   (IfInstanceOf*    x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  void do_TableSwitch    (TableSwitch*     x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  void do_LookupSwitch   (LookupSwitch*    x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  void do_Return         (Return*          x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  void do_Throw          (Throw*           x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  void do_Base           (Base*            x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  void do_OsrEntry       (OsrEntry*        x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  void do_ExceptionObject(ExceptionObject* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  void do_RoundFP        (RoundFP*         x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  void do_UnsafeGetRaw   (UnsafeGetRaw*    x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  void do_UnsafePutRaw   (UnsafePutRaw*    x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  void do_UnsafeGetObject(UnsafeGetObject* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  void do_UnsafePutObject(UnsafePutObject* x);
13886
8d82c4dfa722 7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()
roland
parents: 13391
diff changeset
   537
  void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  void do_ProfileCall    (ProfileCall*     x);
20709
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
   539
  void do_ProfileReturnType (ProfileReturnType*  x);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5707
diff changeset
   540
  void do_ProfileInvoke  (ProfileInvoke*   x);
8065
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7397
diff changeset
   541
  void do_RuntimeCall    (RuntimeCall*     x);
11886
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11432
diff changeset
   542
  void do_MemBar         (MemBar*          x);
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 13974
diff changeset
   543
  void do_RangeCheckPredicate(RangeCheckPredicate* x);
17011
def8879c5b81 8011648: C1: optimized build is broken after 7153771
roland
parents: 16611
diff changeset
   544
#ifdef ASSERT
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 13974
diff changeset
   545
  void do_Assert         (Assert*          x);
17011
def8879c5b81 8011648: C1: optimized build is broken after 7153771
roland
parents: 16611
diff changeset
   546
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
// Because of a static contained within (for the purpose of iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
// over instructions), it is only valid to have one of these active at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
// a time
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   553
class NullCheckEliminator: public ValueVisitor {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  Optimizer*        _opt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  ValueSet*         _visitable_instructions;        // Visit each instruction only once per basic block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  BlockList*        _work_list;                   // Basic blocks to visit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  bool visitable(Value x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    assert(_visitable_instructions != NULL, "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
    return _visitable_instructions->contains(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  void mark_visited(Value x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    assert(_visitable_instructions != NULL, "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    _visitable_instructions->remove(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  void mark_visitable(Value x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
    assert(_visitable_instructions != NULL, "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    _visitable_instructions->put(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  void clear_visitable_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    assert(_visitable_instructions != NULL, "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    _visitable_instructions->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  ValueSet*         _set;                         // current state, propagated to subsequent BlockBegins
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  ValueSetList      _block_states;                // BlockBegin null-check states for all processed blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  NullCheckVisitor  _visitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  NullCheck*        _last_explicit_null_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  bool set_contains(Value x)                      { assert(_set != NULL, "check"); return _set->contains(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  void set_put     (Value x)                      { assert(_set != NULL, "check"); _set->put(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  void set_remove  (Value x)                      { assert(_set != NULL, "check"); _set->remove(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  BlockList* work_list()                          { return _work_list; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  void iterate_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  void iterate_one(BlockBegin* block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  ValueSet* state()                               { return _set; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  void      set_state_from (ValueSet* state)      { _set->set_from(state); }
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
   593
  ValueSet* state_for      (BlockBegin* block)    { return _block_states.at(block->block_id()); }
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
   594
  void      set_state_for  (BlockBegin* block, ValueSet* stack) { _block_states.at_put(block->block_id(), stack); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  // Returns true if caused a change in the block's state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  bool      merge_state_for(BlockBegin* block,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
                            ValueSet*   incoming_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  // constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  NullCheckEliminator(Optimizer* opt)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    : _opt(opt)
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
   603
    , _work_list(new BlockList())
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    , _set(new ValueSet())
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
   605
    , _block_states(BlockBegin::number_of_blocks(), BlockBegin::number_of_blocks(), NULL)
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
   606
    , _last_explicit_null_check(NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    _visitable_instructions = new ValueSet();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    _visitor.set_eliminator(this);
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   609
    CompileLog* log = _opt->ir()->compilation()->log();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   610
    if (log != NULL)
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   611
      log->set_context("optimize name='null_check_elimination'");
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   612
  }
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   613
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   614
  ~NullCheckEliminator() {
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   615
    CompileLog* log = _opt->ir()->compilation()->log();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   616
    if (log != NULL)
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13886
diff changeset
   617
      log->clear_context(); // skip marker if nothing was printed
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  Optimizer*  opt()                               { return _opt; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  IR*         ir ()                               { return opt()->ir(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  // Process a graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  void iterate(BlockBegin* root);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   626
  void visit(Value* f);
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   627
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  // In some situations (like NullCheck(x); getfield(x)) the debug
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  // information from the explicit NullCheck can be used to populate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  // the getfield, even if the two instructions are in different
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  // scopes; this allows implicit null checks to be used but the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  // correct exception information to be generated. We must clear the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  // last-traversed NullCheck when we reach a potentially-exception-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  // throwing instruction, as well as in some other cases.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  void        set_last_explicit_null_check(NullCheck* check) { _last_explicit_null_check = check; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  NullCheck*  last_explicit_null_check()                     { return _last_explicit_null_check; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  Value       last_explicit_null_check_obj()                 { return (_last_explicit_null_check
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
                                                                         ? _last_explicit_null_check->obj()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
                                                                         : NULL); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  NullCheck*  consume_last_explicit_null_check() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    _last_explicit_null_check->unpin(Instruction::PinExplicitNullCheck);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    _last_explicit_null_check->set_can_trap(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    return _last_explicit_null_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  void        clear_last_explicit_null_check()               { _last_explicit_null_check = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  // Handlers for relevant instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  // (separated out from NullCheckVisitor for clarity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  // The basic contract is that these must leave the instruction in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  // the desired state; must not assume anything about the state of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  // the instruction. We make multiple passes over some basic blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  // and the last pass is the only one whose result is valid.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  void handle_AccessField     (AccessField* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  void handle_ArrayLength     (ArrayLength* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  void handle_LoadIndexed     (LoadIndexed* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  void handle_StoreIndexed    (StoreIndexed* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  void handle_NullCheck       (NullCheck* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  void handle_Invoke          (Invoke* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  void handle_NewInstance     (NewInstance* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  void handle_NewArray        (NewArray* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  void handle_AccessMonitor   (AccessMonitor* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  void handle_Intrinsic       (Intrinsic* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  void handle_ExceptionObject (ExceptionObject* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  void handle_Phi             (Phi* x);
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
   666
  void handle_ProfileCall     (ProfileCall* x);
20709
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
   667
  void handle_ProfileReturnType (ProfileReturnType* x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
// NEEDS_CLEANUP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
// There may be other instructions which need to clear the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
// explicit null check. Anything across which we can not hoist the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
// debug information for a NullCheck instruction must clear it. It
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
// might be safer to pattern match "NullCheck ; {AccessField,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
// ArrayLength, LoadIndexed}" but it is more easily structured this way.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
// Should test to see performance hit of clearing it for all handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
// with empty bodies below. If it is negligible then we should leave
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
// that in for safety, otherwise should think more about it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
void NullCheckVisitor::do_Phi            (Phi*             x) { nce()->handle_Phi(x);      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
void NullCheckVisitor::do_Local          (Local*           x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
void NullCheckVisitor::do_Constant       (Constant*        x) { /* FIXME: handle object constants */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
void NullCheckVisitor::do_LoadField      (LoadField*       x) { nce()->handle_AccessField(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
void NullCheckVisitor::do_StoreField     (StoreField*      x) { nce()->handle_AccessField(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
void NullCheckVisitor::do_ArrayLength    (ArrayLength*     x) { nce()->handle_ArrayLength(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
void NullCheckVisitor::do_LoadIndexed    (LoadIndexed*     x) { nce()->handle_LoadIndexed(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
void NullCheckVisitor::do_StoreIndexed   (StoreIndexed*    x) { nce()->handle_StoreIndexed(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
void NullCheckVisitor::do_NegateOp       (NegateOp*        x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
void NullCheckVisitor::do_ArithmeticOp   (ArithmeticOp*    x) { if (x->can_trap()) nce()->clear_last_explicit_null_check(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
void NullCheckVisitor::do_ShiftOp        (ShiftOp*         x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
void NullCheckVisitor::do_LogicOp        (LogicOp*         x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
void NullCheckVisitor::do_CompareOp      (CompareOp*       x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
void NullCheckVisitor::do_IfOp           (IfOp*            x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
void NullCheckVisitor::do_Convert        (Convert*         x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
void NullCheckVisitor::do_NullCheck      (NullCheck*       x) { nce()->handle_NullCheck(x); }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11886
diff changeset
   696
void NullCheckVisitor::do_TypeCast       (TypeCast*        x) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
void NullCheckVisitor::do_Invoke         (Invoke*          x) { nce()->handle_Invoke(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
void NullCheckVisitor::do_NewInstance    (NewInstance*     x) { nce()->handle_NewInstance(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
void NullCheckVisitor::do_NewTypeArray   (NewTypeArray*    x) { nce()->handle_NewArray(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
void NullCheckVisitor::do_NewObjectArray (NewObjectArray*  x) { nce()->handle_NewArray(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
void NullCheckVisitor::do_NewMultiArray  (NewMultiArray*   x) { nce()->handle_NewArray(x); }
10015
ddfb84d0d0c1 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents: 9629
diff changeset
   702
void NullCheckVisitor::do_CheckCast      (CheckCast*       x) { nce()->clear_last_explicit_null_check(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
void NullCheckVisitor::do_InstanceOf     (InstanceOf*      x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
void NullCheckVisitor::do_MonitorEnter   (MonitorEnter*    x) { nce()->handle_AccessMonitor(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
void NullCheckVisitor::do_MonitorExit    (MonitorExit*     x) { nce()->handle_AccessMonitor(x); }
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8065
diff changeset
   706
void NullCheckVisitor::do_Intrinsic      (Intrinsic*       x) { nce()->handle_Intrinsic(x);     }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
void NullCheckVisitor::do_BlockBegin     (BlockBegin*      x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
void NullCheckVisitor::do_Goto           (Goto*            x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
void NullCheckVisitor::do_If             (If*              x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
void NullCheckVisitor::do_IfInstanceOf   (IfInstanceOf*    x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
void NullCheckVisitor::do_TableSwitch    (TableSwitch*     x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
void NullCheckVisitor::do_LookupSwitch   (LookupSwitch*    x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
void NullCheckVisitor::do_Return         (Return*          x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
void NullCheckVisitor::do_Throw          (Throw*           x) { nce()->clear_last_explicit_null_check(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
void NullCheckVisitor::do_Base           (Base*            x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
void NullCheckVisitor::do_OsrEntry       (OsrEntry*        x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
void NullCheckVisitor::do_ExceptionObject(ExceptionObject* x) { nce()->handle_ExceptionObject(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
void NullCheckVisitor::do_RoundFP        (RoundFP*         x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
void NullCheckVisitor::do_UnsafeGetRaw   (UnsafeGetRaw*    x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
void NullCheckVisitor::do_UnsafePutRaw   (UnsafePutRaw*    x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
void NullCheckVisitor::do_UnsafeGetObject(UnsafeGetObject* x) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
void NullCheckVisitor::do_UnsafePutObject(UnsafePutObject* x) {}
13886
8d82c4dfa722 7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()
roland
parents: 13391
diff changeset
   723
void NullCheckVisitor::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {}
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
   724
void NullCheckVisitor::do_ProfileCall    (ProfileCall*     x) { nce()->clear_last_explicit_null_check();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
   725
                                                                nce()->handle_ProfileCall(x); }
20709
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
   726
void NullCheckVisitor::do_ProfileReturnType (ProfileReturnType* x) { nce()->handle_ProfileReturnType(x); }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5707
diff changeset
   727
void NullCheckVisitor::do_ProfileInvoke  (ProfileInvoke*   x) {}
8065
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7397
diff changeset
   728
void NullCheckVisitor::do_RuntimeCall    (RuntimeCall*     x) {}
11886
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11432
diff changeset
   729
void NullCheckVisitor::do_MemBar         (MemBar*          x) {}
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 13974
diff changeset
   730
void NullCheckVisitor::do_RangeCheckPredicate(RangeCheckPredicate* x) {}
17011
def8879c5b81 8011648: C1: optimized build is broken after 7153771
roland
parents: 16611
diff changeset
   731
#ifdef ASSERT
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 13974
diff changeset
   732
void NullCheckVisitor::do_Assert         (Assert*          x) {}
17011
def8879c5b81 8011648: C1: optimized build is broken after 7153771
roland
parents: 16611
diff changeset
   733
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   735
void NullCheckEliminator::visit(Value* p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  assert(*p != NULL, "should not find NULL instructions");
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   737
  if (visitable(*p)) {
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   738
    mark_visited(*p);
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   739
    (*p)->visit(&_visitor);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
bool NullCheckEliminator::merge_state_for(BlockBegin* block, ValueSet* incoming_state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  ValueSet* state = state_for(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  if (state == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
    state = incoming_state->copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    set_state_for(block, state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    bool changed = state->set_intersect(incoming_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
    if (PrintNullCheckElimination && changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
      tty->print_cr("Block %d's null check state changed", block->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    return changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
void NullCheckEliminator::iterate_all() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  while (work_list()->length() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    iterate_one(work_list()->pop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
void NullCheckEliminator::iterate_one(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  clear_visitable_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  // clear out an old explicit null checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  set_last_explicit_null_check(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    tty->print_cr(" ...iterating block %d in null check elimination for %s::%s%s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
                  block->block_id(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
                  ir()->method()->holder()->name()->as_utf8(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
                  ir()->method()->name()->as_utf8(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
                  ir()->method()->signature()->as_symbol()->as_utf8());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  // Create new state if none present (only happens at root)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  if (state_for(block) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
    ValueSet* tmp_state = new ValueSet();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
    set_state_for(block, tmp_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    // Initial state is that local 0 (receiver) is non-null for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    // non-static methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    ValueStack* stack  = block->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    IRScope*    scope  = stack->scope();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    ciMethod*   method = scope->method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
    if (!method->is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
      Local* local0 = stack->local_at(0)->as_Local();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
      assert(local0 != NULL, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
      assert(local0->type() == objectType, "invalid type of receiver");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
      if (local0 != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
        // Local 0 is used in this scope
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
        tmp_state->put(local0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
        if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
          tty->print_cr("Local 0 (value %d) proven non-null upon entry", local0->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  // Must copy block's state to avoid mutating it during iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  // through the block -- otherwise "not-null" states can accidentally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  // propagate "up" through the block during processing of backward
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  // branches and algorithm is incorrect (and does not converge)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  set_state_from(state_for(block));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  // allow visiting of Phis belonging to this block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  for_each_phi_fun(block, phi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
                   mark_visitable(phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
                   );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  BlockEnd* e = block->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  assert(e != NULL, "incomplete graph");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  // Propagate the state before this block into the exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  // handlers.  They aren't true successors since we aren't guaranteed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  // to execute the whole block before executing them.  Also putting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  // them on first seems to help reduce the amount of iteration to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  // reach a fixed point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  for (i = 0; i < block->number_of_exception_handlers(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    BlockBegin* next = block->exception_handler_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    if (merge_state_for(next, state())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
      if (!work_list()->contains(next)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
        work_list()->push(next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  // Iterate through block, updating state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  for (Instruction* instr = block; instr != NULL; instr = instr->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    // Mark instructions in this block as visitable as they are seen
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    // in the instruction list.  This keeps the iteration from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    // visiting instructions which are references in other blocks or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    // visiting instructions more than once.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    mark_visitable(instr);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   839
    if (instr->is_pinned() || instr->can_trap() || (instr->as_NullCheck() != NULL)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      mark_visited(instr);
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   841
      instr->input_values_do(this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
      instr->visit(&_visitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  // Propagate state to successors if necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  for (i = 0; i < e->number_of_sux(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    BlockBegin* next = e->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    if (merge_state_for(next, state())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
      if (!work_list()->contains(next)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
        work_list()->push(next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
void NullCheckEliminator::iterate(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  work_list()->push(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  iterate_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
void NullCheckEliminator::handle_AccessField(AccessField* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  if (x->is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    if (x->as_LoadField() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
      // If the field is a non-null static final object field (as is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
      // often the case for sun.misc.Unsafe), put this LoadField into
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
      // the non-null map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      ciField* field = x->field();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
      if (field->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
        ciConstant field_val = field->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
        BasicType field_type = field_val.basic_type();
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 53806
diff changeset
   873
        if (is_reference_type(field_type)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
          ciObject* obj_val = field_val.as_object();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
          if (!obj_val->is_null_object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
            if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
              tty->print_cr("AccessField %d proven non-null by static final non-null oop check",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
                            x->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
            set_put(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
    // Be conservative
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  Value obj = x->obj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  if (set_contains(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
    // Value is non-null => update AccessField
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
    if (last_explicit_null_check_obj() == obj && !x->needs_patching()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
      x->set_explicit_null_check(consume_last_explicit_null_check());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
      x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
      if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
        tty->print_cr("Folded NullCheck %d into AccessField %d's null check for value %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
                      x->explicit_null_check()->id(), x->id(), obj->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
      x->set_explicit_null_check(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
      x->set_needs_null_check(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
      if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
        tty->print_cr("Eliminated AccessField %d's null check for value %d", x->id(), obj->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    set_put(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      tty->print_cr("AccessField %d of value %d proves value to be non-null", x->id(), obj->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    // Ensure previous passes do not cause wrong state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
    x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
    x->set_explicit_null_check(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
  clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
void NullCheckEliminator::handle_ArrayLength(ArrayLength* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  Value array = x->array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  if (set_contains(array)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
    // Value is non-null => update AccessArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
    if (last_explicit_null_check_obj() == array) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
      x->set_explicit_null_check(consume_last_explicit_null_check());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
      x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
      if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
        tty->print_cr("Folded NullCheck %d into ArrayLength %d's null check for value %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
                      x->explicit_null_check()->id(), x->id(), array->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
      x->set_explicit_null_check(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
      x->set_needs_null_check(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
      if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
        tty->print_cr("Eliminated ArrayLength %d's null check for value %d", x->id(), array->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    set_put(array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
      tty->print_cr("ArrayLength %d of value %d proves value to be non-null", x->id(), array->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
    // Ensure previous passes do not cause wrong state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
    x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
    x->set_explicit_null_check(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
void NullCheckEliminator::handle_LoadIndexed(LoadIndexed* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  Value array = x->array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  if (set_contains(array)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    // Value is non-null => update AccessArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    if (last_explicit_null_check_obj() == array) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
      x->set_explicit_null_check(consume_last_explicit_null_check());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
      x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
      if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
        tty->print_cr("Folded NullCheck %d into LoadIndexed %d's null check for value %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
                      x->explicit_null_check()->id(), x->id(), array->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
      x->set_explicit_null_check(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
      x->set_needs_null_check(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
      if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
        tty->print_cr("Eliminated LoadIndexed %d's null check for value %d", x->id(), array->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    set_put(array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
      tty->print_cr("LoadIndexed %d of value %d proves value to be non-null", x->id(), array->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    // Ensure previous passes do not cause wrong state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
    x->set_explicit_null_check(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
void NullCheckEliminator::handle_StoreIndexed(StoreIndexed* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  Value array = x->array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  if (set_contains(array)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    // Value is non-null => update AccessArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
      tty->print_cr("Eliminated StoreIndexed %d's null check for value %d", x->id(), array->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    x->set_needs_null_check(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    set_put(array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
      tty->print_cr("StoreIndexed %d of value %d proves value to be non-null", x->id(), array->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    // Ensure previous passes do not cause wrong state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
void NullCheckEliminator::handle_NullCheck(NullCheck* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
  Value obj = x->obj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
  if (set_contains(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    // Already proven to be non-null => this NullCheck is useless
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
      tty->print_cr("Eliminated NullCheck %d for value %d", x->id(), obj->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    // Don't unpin since that may shrink obj's live range and make it unavailable for debug info.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
    // The code generator won't emit LIR for a NullCheck that cannot trap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    x->set_can_trap(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
    // May be null => add to map and set last explicit NullCheck
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
    x->set_can_trap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    // make sure it's pinned if it can trap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
    x->pin(Instruction::PinExplicitNullCheck);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
    set_put(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
    set_last_explicit_null_check(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
      tty->print_cr("NullCheck %d of value %d proves value to be non-null", x->id(), obj->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
void NullCheckEliminator::handle_Invoke(Invoke* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  if (!x->has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    // Be conservative
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
    clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  Value recv = x->receiver();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  if (!set_contains(recv)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    set_put(recv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
      tty->print_cr("Invoke %d of value %d proves value to be non-null", x->id(), recv->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
void NullCheckEliminator::handle_NewInstance(NewInstance* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
  set_put(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
  if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    tty->print_cr("NewInstance %d is non-null", x->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
void NullCheckEliminator::handle_NewArray(NewArray* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  set_put(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
  if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
    tty->print_cr("NewArray %d is non-null", x->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
void NullCheckEliminator::handle_ExceptionObject(ExceptionObject* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  set_put(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
    tty->print_cr("ExceptionObject %d is non-null", x->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
void NullCheckEliminator::handle_AccessMonitor(AccessMonitor* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
  Value obj = x->obj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  if (set_contains(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
    // Value is non-null => update AccessMonitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
      tty->print_cr("Eliminated AccessMonitor %d's null check for value %d", x->id(), obj->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    x->set_needs_null_check(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
    set_put(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
      tty->print_cr("AccessMonitor %d of value %d proves value to be non-null", x->id(), obj->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    // Ensure previous passes do not cause wrong state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
    x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
void NullCheckEliminator::handle_Intrinsic(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  if (!x->has_receiver()) {
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8065
diff changeset
  1090
    if (x->id() == vmIntrinsics::_arraycopy) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8065
diff changeset
  1091
      for (int i = 0; i < x->number_of_arguments(); i++) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8065
diff changeset
  1092
        x->set_arg_needs_null_check(i, !set_contains(x->argument_at(i)));
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8065
diff changeset
  1093
      }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8065
diff changeset
  1094
    }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8065
diff changeset
  1095
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
    // Be conservative
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  Value recv = x->receiver();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
  if (set_contains(recv)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    // Value is non-null => update Intrinsic
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
      tty->print_cr("Eliminated Intrinsic %d's null check for value %d", x->id(), recv->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
    x->set_needs_null_check(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
    set_put(recv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
      tty->print_cr("Intrinsic %d of value %d proves value to be non-null", x->id(), recv->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
    // Ensure previous passes do not cause wrong state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
    x->set_needs_null_check(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
  clear_last_explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
void NullCheckEliminator::handle_Phi(Phi* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
  bool all_non_null = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
  if (x->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
    all_non_null = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    for (i = 0; i < x->operand_count(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
      Value input = x->operand_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
      if (!set_contains(input)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
        all_non_null = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
  if (all_non_null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
    // Value is non-null => update Phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
      tty->print_cr("Eliminated Phi %d's null check for phifun because all inputs are non-null", x->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
    x->set_needs_null_check(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
  } else if (set_contains(x)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
    set_remove(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
  1145
void NullCheckEliminator::handle_ProfileCall(ProfileCall* x) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
  1146
  for (int i = 0; i < x->nb_profiled_args(); i++) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
  1147
    x->set_arg_needs_null_check(i, !set_contains(x->profiled_arg_at(i)));
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
  1148
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
  1149
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
20709
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  1151
void NullCheckEliminator::handle_ProfileReturnType(ProfileReturnType* x) {
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  1152
  x->set_needs_null_check(!set_contains(x->ret()));
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  1153
}
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  1154
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
void Optimizer::eliminate_null_checks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  NullCheckEliminator nce(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
  if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
    tty->print_cr("Starting null check elimination for method %s::%s%s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
                  ir()->method()->holder()->name()->as_utf8(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
                  ir()->method()->name()->as_utf8(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
                  ir()->method()->signature()->as_symbol()->as_utf8());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
  // Apply to graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  nce.iterate(ir()->start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
  // walk over the graph looking for exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
  // handlers and iterate over them as well
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
  int nblocks = BlockBegin::number_of_blocks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
  BlockList blocks(nblocks);
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
  1174
  boolArray visited_block(nblocks, nblocks, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
  blocks.push(ir()->start());
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
  1177
  visited_block.at_put(ir()->start()->block_id(), true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
  for (int i = 0; i < blocks.length(); i++) {
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
  1179
    BlockBegin* b = blocks.at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
    // exception handlers need to be treated as additional roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
    for (int e = b->number_of_exception_handlers(); e-- > 0; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
      BlockBegin* excp = b->exception_handler_at(e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
      int id = excp->block_id();
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
  1184
      if (!visited_block.at(id)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
        blocks.push(excp);
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
  1186
        visited_block.at_put(id, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
        nce.iterate(excp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
    // traverse successors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    BlockEnd *end = b->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
    for (int s = end->number_of_sux(); s-- > 0; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
      BlockBegin* next = end->sux_at(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
      int id = next->block_id();
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
  1195
      if (!visited_block.at(id)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
        blocks.push(next);
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 28954
diff changeset
  1197
        visited_block.at_put(id, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  if (PrintNullCheckElimination) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    tty->print_cr("Done with null check elimination for method %s::%s%s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
                  ir()->method()->holder()->name()->as_utf8(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
                  ir()->method()->name()->as_utf8(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
                  ir()->method()->signature()->as_symbol()->as_utf8());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
}