hotspot/src/share/vm/opto/replacednodes.cpp
author vlivanov
Mon, 14 Jul 2014 03:29:42 -0700
changeset 25645 0bcfdc697031
parent 24946 24b68ccf3fc4
child 37248 11a660dbbb8e
permissions -rw-r--r--
8048703: ReplacedNodes dumps it's content to tty Reviewed-by: roland, iveresov, drchase
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24946
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     1
/*
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     4
 *
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     8
 *
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    13
 * accompanied this code).
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    14
 *
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    18
 *
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    21
 * questions.
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    22
 *
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    23
 */
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    24
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    25
#include "precompiled.hpp"
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    26
#include "opto/cfgnode.hpp"
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    27
#include "opto/phaseX.hpp"
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    28
#include "opto/replacednodes.hpp"
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    29
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    30
void ReplacedNodes::allocate_if_necessary() {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    31
  if (_replaced_nodes == NULL) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    32
    _replaced_nodes = new GrowableArray<ReplacedNode>();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    33
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    34
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    35
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    36
bool ReplacedNodes::is_empty() const {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    37
  return _replaced_nodes == NULL || _replaced_nodes->length() == 0;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    38
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    39
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    40
bool ReplacedNodes::has_node(const ReplacedNode& r) const {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    41
  return _replaced_nodes->find(r) != -1;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    42
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    43
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    44
bool ReplacedNodes::has_target_node(Node* n) const {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    45
  for (int i = 0; i < _replaced_nodes->length(); i++) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    46
    if (_replaced_nodes->at(i).improved() == n) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    47
      return true;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    48
    }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    49
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    50
  return false;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    51
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    52
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    53
// Record replaced node if not seen before
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    54
void ReplacedNodes::record(Node* initial, Node* improved) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    55
  allocate_if_necessary();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    56
  ReplacedNode r(initial, improved);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    57
  if (!has_node(r)) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    58
    _replaced_nodes->push(r);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    59
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    60
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    61
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    62
// Copy replaced nodes from one map to another. idx is used to
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    63
// identify nodes that are too new to be of interest in the target
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    64
// node list.
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    65
void ReplacedNodes::transfer_from(const ReplacedNodes& other, uint idx) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    66
  if (other.is_empty()) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    67
    return;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    68
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    69
  allocate_if_necessary();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    70
  for (int i = 0; i < other._replaced_nodes->length(); i++) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    71
    ReplacedNode replaced = other._replaced_nodes->at(i);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    72
    // Only transfer the nodes that can actually be useful
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    73
    if (!has_node(replaced) && (replaced.initial()->_idx < idx || has_target_node(replaced.initial()))) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    74
      _replaced_nodes->push(replaced);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    75
    }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    76
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    77
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    78
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    79
void ReplacedNodes::clone() {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    80
  if (_replaced_nodes != NULL) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    81
    GrowableArray<ReplacedNode>* replaced_nodes_clone = new GrowableArray<ReplacedNode>();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    82
    replaced_nodes_clone->appendAll(_replaced_nodes);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    83
    _replaced_nodes = replaced_nodes_clone;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    84
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    85
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    86
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    87
void ReplacedNodes::reset() {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    88
  if (_replaced_nodes != NULL) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    89
    _replaced_nodes->clear();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    90
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    91
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    92
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    93
// Perfom node replacement (used when returning to caller)
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    94
void ReplacedNodes::apply(Node* n) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    95
  if (is_empty()) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    96
    return;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    97
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    98
  for (int i = 0; i < _replaced_nodes->length(); i++) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
    99
    ReplacedNode replaced = _replaced_nodes->at(i);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   100
    n->replace_edge(replaced.initial(), replaced.improved());
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   101
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   102
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   103
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   104
static void enqueue_use(Node* n, Node* use, Unique_Node_List& work) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   105
  if (use->is_Phi()) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   106
    Node* r = use->in(0);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   107
    assert(r->is_Region(), "Phi should have Region");
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   108
    for (uint i = 1; i < use->req(); i++) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   109
      if (use->in(i) == n) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   110
        work.push(r->in(i));
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   111
      }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   112
    }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   113
  } else {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   114
    work.push(use);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   115
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   116
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   117
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   118
// Perfom node replacement following late inlining
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   119
void ReplacedNodes::apply(Compile* C, Node* ctl) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   120
  // ctl is the control on exit of the method that was late inlined
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   121
  if (is_empty()) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   122
    return;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   123
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   124
  for (int i = 0; i < _replaced_nodes->length(); i++) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   125
    ReplacedNode replaced = _replaced_nodes->at(i);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   126
    Node* initial = replaced.initial();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   127
    Node* improved = replaced.improved();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   128
    assert (ctl != NULL && !ctl->is_top(), "replaced node should have actual control");
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   129
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   130
    ResourceMark rm;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   131
    Unique_Node_List work;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   132
    // Go over all the uses of the node that is considered for replacement...
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   133
    for (DUIterator j = initial->outs(); initial->has_out(j); j++) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   134
      Node* use = initial->out(j);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   135
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   136
      if (use == improved || use->outcnt() == 0) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   137
        continue;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   138
      }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   139
      work.clear();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   140
      enqueue_use(initial, use, work);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   141
      bool replace = true;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   142
      // Check that this use is dominated by ctl. Go ahead with the
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   143
      // replacement if it is.
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   144
      while (work.size() != 0 && replace) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   145
        Node* n = work.pop();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   146
        if (use->outcnt() == 0) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   147
          continue;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   148
        }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   149
        if (n->is_CFG() || (n->in(0) != NULL && !n->in(0)->is_top())) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   150
          int depth = 0;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   151
          Node *m = n;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   152
          if (!n->is_CFG()) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   153
            n = n->in(0);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   154
          }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   155
          assert(n->is_CFG(), "should be CFG now");
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   156
          while(n != ctl) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   157
            n = IfNode::up_one_dom(n);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   158
            depth++;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   159
            // limit search depth
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   160
            if (depth >= 100 || n == NULL) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   161
              replace = false;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   162
              break;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   163
            }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   164
          }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   165
        } else {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   166
          for (DUIterator k = n->outs(); n->has_out(k); k++) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   167
            enqueue_use(n, n->out(k), work);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   168
          }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   169
        }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   170
      }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   171
      if (replace) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   172
        bool is_in_table = C->initial_gvn()->hash_delete(use);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   173
        int replaced = use->replace_edge(initial, improved);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   174
        if (is_in_table) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   175
          C->initial_gvn()->hash_find_insert(use);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   176
        }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   177
        C->record_for_igvn(use);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   178
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   179
        assert(replaced > 0, "inconsistent");
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   180
        --j;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   181
      }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   182
    }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   183
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   184
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   185
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   186
void ReplacedNodes::dump(outputStream *st) const {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   187
  if (!is_empty()) {
25645
0bcfdc697031 8048703: ReplacedNodes dumps it's content to tty
vlivanov
parents: 24946
diff changeset
   188
    st->print("replaced nodes: ");
24946
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   189
    for (int i = 0; i < _replaced_nodes->length(); i++) {
25645
0bcfdc697031 8048703: ReplacedNodes dumps it's content to tty
vlivanov
parents: 24946
diff changeset
   190
      st->print("%d->%d", _replaced_nodes->at(i).initial()->_idx, _replaced_nodes->at(i).improved()->_idx);
24946
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   191
      if (i < _replaced_nodes->length()-1) {
25645
0bcfdc697031 8048703: ReplacedNodes dumps it's content to tty
vlivanov
parents: 24946
diff changeset
   192
        st->print(",");
24946
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   193
      }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   194
    }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   195
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   196
}
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   197
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   198
// Merge 2 list of replaced node at a point where control flow paths merge
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   199
void ReplacedNodes::merge_with(const ReplacedNodes& other) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   200
  if (is_empty()) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   201
    return;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   202
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   203
  if (other.is_empty()) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   204
    reset();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   205
    return;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   206
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   207
  int shift = 0;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   208
  int len = _replaced_nodes->length();
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   209
  for (int i = 0; i < len; i++) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   210
    if (!other.has_node(_replaced_nodes->at(i))) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   211
      shift++;
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   212
    } else if (shift > 0) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   213
      _replaced_nodes->at_put(i-shift, _replaced_nodes->at(i));
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   214
    }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   215
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   216
  if (shift > 0) {
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   217
    _replaced_nodes->trunc_to(len - shift);
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   218
  }
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents:
diff changeset
   219
}