hotspot/src/share/vm/opto/loopUnswitch.cpp
author trims
Tue, 05 Apr 2011 14:12:31 -0700
changeset 8921 14bfe81f2a9d
parent 8732 16fc1c68714b
child 9124 f60dee480d49
permissions -rw-r--r--
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass Summary: Update the copyright to be 2010 on all changed files in OpenJDK Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8732
diff changeset
     2
 * Copyright (c) 2006, 2011, 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: 2131
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
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: 2131
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: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "opto/connode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "opto/loopnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/rootnode.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//================= Loop Unswitching =====================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// orig:                       transformed:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//                               if (invariant-test) then
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//  loop                           loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//    stmt1                          stmt1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//    if (invariant-test) then       stmt2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//      stmt2                        stmt4
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//    else                         endloop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//      stmt3                    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//    endif                        loop [clone]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//    stmt4                          stmt1 [clone]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//  endloop                          stmt3
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//                                   stmt4 [clone]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//                                 endloop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//                               endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Note: the "else" clause may be empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//------------------------------policy_unswitching-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// Return TRUE or FALSE if the loop should be unswitched
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// (ie. clone loop with an invariant test that does not exit the loop)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
bool IdealLoopTree::policy_unswitching( PhaseIdealLoop *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  if( !LoopUnswitching ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
355
22d39d357cca 6684385: Loop unswitching crashes without LoopNode
rasbold
parents: 1
diff changeset
    57
  if (!_head->is_Loop()) {
22d39d357cca 6684385: Loop unswitching crashes without LoopNode
rasbold
parents: 1
diff changeset
    58
    return false;
22d39d357cca 6684385: Loop unswitching crashes without LoopNode
rasbold
parents: 1
diff changeset
    59
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  uint nodes_left = MaxNodeLimit - phase->C->unique();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  if (2 * _body.size() > nodes_left) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    return false; // Too speculative if running low on nodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  LoopNode* head = _head->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  if (head->unswitch_count() + 1 > head->unswitch_max()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  return phase->find_unswitching_candidate(this) != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
//------------------------------find_unswitching_candidate-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
// Find candidate "if" for unswitching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
IfNode* PhaseIdealLoop::find_unswitching_candidate(const IdealLoopTree *loop) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // Find first invariant test that doesn't exit the loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  LoopNode *head = loop->_head->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  IfNode* unswitch_iff = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  Node* n = head->in(LoopNode::LoopBackControl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  while (n != head) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    Node* n_dom = idom(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    if (n->is_Region()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      if (n_dom->is_If()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
        IfNode* iff = n_dom->as_If();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
        if (iff->in(1)->is_Bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
          BoolNode* bol = iff->in(1)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
          if (bol->in(1)->is_Cmp()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
            // If condition is invariant and not a loop exit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
            // then found reason to unswitch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
            if (loop->is_invariant(bol) && !loop->is_loop_exit(iff)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
              unswitch_iff = iff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    n = n_dom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  return unswitch_iff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
//------------------------------do_unswitching-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// Clone loop with an invariant test (that does not exit) and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// insert a clone of the test that selects which version to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
// execute.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
void PhaseIdealLoop::do_unswitching (IdealLoopTree *loop, Node_List &old_new) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // Find first invariant test that doesn't exit the loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  LoopNode *head = loop->_head->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  IfNode* unswitch_iff = find_unswitching_candidate((const IdealLoopTree *)loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  assert(unswitch_iff != NULL, "should be at least one");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
8732
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   113
#ifndef PRODUCT
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   114
  if (TraceLoopOpts) {
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   115
    tty->print("Unswitch   %d ", head->unswitch_count()+1);
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   116
    loop->dump_head();
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   117
  }
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   118
#endif
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   119
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // Need to revert back to normal loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  if (head->is_CountedLoop() && !head->as_CountedLoop()->is_normal_loop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    head->as_CountedLoop()->set_normal_loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  ProjNode* proj_true = create_slow_version_of_loop(loop, old_new);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  assert(proj_true->is_IfTrue() && proj_true->unique_ctrl_out() == head, "by construction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // Increment unswitch count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  LoopNode* head_clone = old_new[head->_idx]->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  int nct = head->unswitch_count() + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  head->set_unswitch_count(nct);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  head_clone->set_unswitch_count(nct);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // Add test to new "if" outside of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  IfNode* invar_iff   = proj_true->in(0)->as_If();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  Node* invar_iff_c   = invar_iff->in(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  BoolNode* bol       = unswitch_iff->in(1)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  invar_iff->set_req(1, bol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  invar_iff->_prob    = unswitch_iff->_prob;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  ProjNode* proj_false = invar_iff->proj_out(0)->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 781
diff changeset
   144
  // Hoist invariant casts out of each loop to the appropriate
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // control projection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  Node_List worklist;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  for (DUIterator_Fast imax, i = unswitch_iff->fast_outs(imax); i < imax; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    ProjNode* proj= unswitch_iff->fast_out(i)->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    // Copy to a worklist for easier manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    for (DUIterator_Fast jmax, j = proj->fast_outs(jmax); j < jmax; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      Node* use = proj->fast_out(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      if (use->Opcode() == Op_CheckCastPP && loop->is_invariant(use->in(1))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        worklist.push(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    ProjNode* invar_proj = invar_iff->proj_out(proj->_con)->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    while (worklist.size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      Node* use = worklist.pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      Node* nuse = use->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      nuse->set_req(0, invar_proj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      _igvn.hash_delete(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      use->set_req(1, nuse);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      _igvn._worklist.push(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      register_new_node(nuse, invar_proj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      // Same for the clone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      Node* use_clone = old_new[use->_idx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      _igvn.hash_delete(use_clone);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      use_clone->set_req(1, nuse);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      _igvn._worklist.push(use_clone);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Hardwire the control paths in the loops into if(true) and if(false)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  _igvn.hash_delete(unswitch_iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  short_circuit_if(unswitch_iff, proj_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  _igvn._worklist.push(unswitch_iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  IfNode* unswitch_iff_clone = old_new[unswitch_iff->_idx]->as_If();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  _igvn.hash_delete(unswitch_iff_clone);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  short_circuit_if(unswitch_iff_clone, proj_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  _igvn._worklist.push(unswitch_iff_clone);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // Reoptimize loops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  loop->record_for_igvn();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  for(int i = loop->_body.size() - 1; i >= 0 ; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    Node *n = loop->_body[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    Node *n_clone = old_new[n->_idx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    _igvn._worklist.push(n_clone);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  if (TraceLoopUnswitching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    tty->print_cr("Loop unswitching orig: %d @ %d  new: %d @ %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                  head->_idx,                unswitch_iff->_idx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
                  old_new[head->_idx]->_idx, unswitch_iff_clone->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  C->set_major_progress();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
//-------------------------create_slow_version_of_loop------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// Create a slow version of the loop by cloning the loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// and inserting an if to select fast-slow versions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// Return control projection of the entry to the fast version.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
ProjNode* PhaseIdealLoop::create_slow_version_of_loop(IdealLoopTree *loop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
                                                      Node_List &old_new) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  LoopNode* head  = loop->_head->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  Node*     entry = head->in(LoopNode::EntryControl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  _igvn.hash_delete(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  _igvn._worklist.push(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  IdealLoopTree* outer_loop = loop->_parent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  Node *cont      = _igvn.intcon(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  set_ctrl(cont, C->root());
762
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 355
diff changeset
   218
  Node* opq       = new (C, 2) Opaque1Node(C, cont);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  register_node(opq, outer_loop, entry, dom_depth(entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  Node *bol       = new (C, 2) Conv2BNode(opq);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  register_node(bol, outer_loop, entry, dom_depth(entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  IfNode* iff = new (C, 2) IfNode(entry, bol, PROB_MAX, COUNT_UNKNOWN);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  register_node(iff, outer_loop, entry, dom_depth(entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  ProjNode* iffast = new (C, 1) IfTrueNode(iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  register_node(iffast, outer_loop, iff, dom_depth(iff));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  ProjNode* ifslow = new (C, 1) IfFalseNode(iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  register_node(ifslow, outer_loop, iff, dom_depth(iff));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // Clone the loop body.  The clone becomes the fast loop.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // original pre-header will (illegally) have 2 control users (old & new loops).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  clone_loop(loop, old_new, dom_depth(head), iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  assert(old_new[head->_idx]->is_Loop(), "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // Fast (true) control
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  _igvn.hash_delete(head);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  head->set_req(LoopNode::EntryControl, iffast);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  set_idom(head, iffast, dom_depth(head));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  _igvn._worklist.push(head);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // Slow (false) control
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  LoopNode* slow_head = old_new[head->_idx]->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  _igvn.hash_delete(slow_head);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  slow_head->set_req(LoopNode::EntryControl, ifslow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  set_idom(slow_head, ifslow, dom_depth(slow_head));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  _igvn._worklist.push(slow_head);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  recompute_dom_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  return iffast;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}