hotspot/src/share/vm/opto/loopUnswitch.cpp
author goetz
Mon, 02 Nov 2015 15:52:37 +0100
changeset 34194 213af0859e7e
parent 34174 4db2fb26dc49
child 37287 c2660335bf81
permissions -rw-r--r--
8141137: C2 fails rematerializing nodes using flag registers. Summary: Don't rem. if input stretches several live ranges. If rem., don't add SpillCopy on RegFlags edge. Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13895
diff changeset
     2
 * Copyright (c) 2006, 2012, 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"
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents: 14623
diff changeset
    28
#include "opto/convertnode.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/loopnode.hpp"
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents: 14623
diff changeset
    30
#include "opto/opaquenode.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/rootnode.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//================= Loop Unswitching =====================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// orig:                       transformed:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//                               if (invariant-test) then
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
    37
//  predicate                      predicate
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//  loop                           loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//    stmt1                          stmt1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//    if (invariant-test) then       stmt2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//      stmt2                        stmt4
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//    else                         endloop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//      stmt3                    else
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
    44
//    endif                        predicate [clone]
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
    45
//    stmt4                        loop [clone]
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
    46
//  endloop                          stmt1 [clone]
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
    47
//                                   stmt3
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//                                   stmt4 [clone]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//                                 endloop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//                               endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// Note: the "else" clause may be empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//------------------------------policy_unswitching-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// Return TRUE or FALSE if the loop should be unswitched
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// (ie. clone loop with an invariant test that does not exit the loop)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
bool IdealLoopTree::policy_unswitching( PhaseIdealLoop *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  if( !LoopUnswitching ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
355
22d39d357cca 6684385: Loop unswitching crashes without LoopNode
rasbold
parents: 1
diff changeset
    61
  if (!_head->is_Loop()) {
22d39d357cca 6684385: Loop unswitching crashes without LoopNode
rasbold
parents: 1
diff changeset
    62
    return false;
22d39d357cca 6684385: Loop unswitching crashes without LoopNode
rasbold
parents: 1
diff changeset
    63
  }
31772
718fc367468d 8129920: Vectorized loop unrolling
kvn
parents: 27707
diff changeset
    64
718fc367468d 8129920: Vectorized loop unrolling
kvn
parents: 27707
diff changeset
    65
  // check for vectorized loops, any unswitching was already applied
718fc367468d 8129920: Vectorized loop unrolling
kvn
parents: 27707
diff changeset
    66
  if (_head->is_CountedLoop() && _head->as_CountedLoop()->do_unroll_only()) {
718fc367468d 8129920: Vectorized loop unrolling
kvn
parents: 27707
diff changeset
    67
    return false;
718fc367468d 8129920: Vectorized loop unrolling
kvn
parents: 27707
diff changeset
    68
  }
718fc367468d 8129920: Vectorized loop unrolling
kvn
parents: 27707
diff changeset
    69
27707
f7d26e5b8b5d 8058148: MaxNodeLimit and LiveNodeCountInliningCutoff
vlivanov
parents: 24923
diff changeset
    70
  int nodes_left = phase->C->max_node_limit() - phase->C->live_nodes();
f7d26e5b8b5d 8058148: MaxNodeLimit and LiveNodeCountInliningCutoff
vlivanov
parents: 24923
diff changeset
    71
  if ((int)(2 * _body.size()) > nodes_left) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    return false; // Too speculative if running low on nodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  LoopNode* head = _head->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  if (head->unswitch_count() + 1 > head->unswitch_max()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  return phase->find_unswitching_candidate(this) != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
//------------------------------find_unswitching_candidate-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// Find candidate "if" for unswitching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
IfNode* PhaseIdealLoop::find_unswitching_candidate(const IdealLoopTree *loop) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Find first invariant test that doesn't exit the loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  LoopNode *head = loop->_head->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  IfNode* unswitch_iff = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  Node* n = head->in(LoopNode::LoopBackControl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  while (n != head) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    Node* n_dom = idom(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (n->is_Region()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      if (n_dom->is_If()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        IfNode* iff = n_dom->as_If();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        if (iff->in(1)->is_Bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
          BoolNode* bol = iff->in(1)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
          if (bol->in(1)->is_Cmp()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
            // If condition is invariant and not a loop exit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
            // then found reason to unswitch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
            if (loop->is_invariant(bol) && !loop->is_loop_exit(iff)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
              unswitch_iff = iff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    n = n_dom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  return unswitch_iff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
//------------------------------do_unswitching-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
// Clone loop with an invariant test (that does not exit) and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// insert a clone of the test that selects which version to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// execute.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
void PhaseIdealLoop::do_unswitching (IdealLoopTree *loop, Node_List &old_new) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Find first invariant test that doesn't exit the loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  LoopNode *head = loop->_head->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  IfNode* unswitch_iff = find_unswitching_candidate((const IdealLoopTree *)loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  assert(unswitch_iff != NULL, "should be at least one");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
8732
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   123
#ifndef PRODUCT
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   124
  if (TraceLoopOpts) {
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   125
    tty->print("Unswitch   %d ", head->unswitch_count()+1);
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   126
    loop->dump_head();
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   127
  }
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   128
#endif
16fc1c68714b 7008866: Missing loop predicate for loop with multiple entries
kvn
parents: 7397
diff changeset
   129
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Need to revert back to normal loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  if (head->is_CountedLoop() && !head->as_CountedLoop()->is_normal_loop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    head->as_CountedLoop()->set_normal_loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 33166
diff changeset
   135
  ProjNode* proj_true = create_slow_version_of_loop(loop, old_new, unswitch_iff->Opcode());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   137
#ifdef ASSERT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   138
  Node* uniqc = proj_true->unique_ctrl_out();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   139
  Node* entry = head->in(LoopNode::EntryControl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   140
  Node* predicate = find_predicate(entry);
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9124
diff changeset
   141
  if (predicate != NULL && LoopLimitCheck && UseLoopPredicate) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9124
diff changeset
   142
    // We may have two predicates, find first.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9124
diff changeset
   143
    entry = find_predicate(entry->in(0)->in(0));
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9124
diff changeset
   144
    if (entry != NULL) predicate = entry;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9124
diff changeset
   145
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   146
  if (predicate != NULL) predicate = predicate->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   147
  assert(proj_true->is_IfTrue() &&
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   148
         (predicate == NULL && uniqc == head ||
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   149
          predicate != NULL && uniqc == predicate), "by construction");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   150
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // Increment unswitch count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  LoopNode* head_clone = old_new[head->_idx]->as_Loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  int nct = head->unswitch_count() + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  head->set_unswitch_count(nct);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  head_clone->set_unswitch_count(nct);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // Add test to new "if" outside of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  IfNode* invar_iff   = proj_true->in(0)->as_If();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  Node* invar_iff_c   = invar_iff->in(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  BoolNode* bol       = unswitch_iff->in(1)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  invar_iff->set_req(1, bol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  invar_iff->_prob    = unswitch_iff->_prob;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  ProjNode* proj_false = invar_iff->proj_out(0)->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 781
diff changeset
   166
  // Hoist invariant casts out of each loop to the appropriate
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // control projection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  Node_List worklist;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  for (DUIterator_Fast imax, i = unswitch_iff->fast_outs(imax); i < imax; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    ProjNode* proj= unswitch_iff->fast_out(i)->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    // Copy to a worklist for easier manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    for (DUIterator_Fast jmax, j = proj->fast_outs(jmax); j < jmax; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      Node* use = proj->fast_out(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      if (use->Opcode() == Op_CheckCastPP && loop->is_invariant(use->in(1))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
        worklist.push(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    ProjNode* invar_proj = invar_iff->proj_out(proj->_con)->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    while (worklist.size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      Node* use = worklist.pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      Node* nuse = use->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      nuse->set_req(0, invar_proj);
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10258
diff changeset
   185
      _igvn.replace_input_of(use, 1, nuse);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      register_new_node(nuse, invar_proj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      // Same for the clone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      Node* use_clone = old_new[use->_idx];
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10258
diff changeset
   189
      _igvn.replace_input_of(use_clone, 1, nuse);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // Hardwire the control paths in the loops into if(true) and if(false)
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10258
diff changeset
   194
  _igvn.rehash_node_delayed(unswitch_iff);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  short_circuit_if(unswitch_iff, proj_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  IfNode* unswitch_iff_clone = old_new[unswitch_iff->_idx]->as_If();
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10258
diff changeset
   198
  _igvn.rehash_node_delayed(unswitch_iff_clone);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  short_circuit_if(unswitch_iff_clone, proj_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // Reoptimize loops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  loop->record_for_igvn();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  for(int i = loop->_body.size() - 1; i >= 0 ; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    Node *n = loop->_body[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    Node *n_clone = old_new[n->_idx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    _igvn._worklist.push(n_clone);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  if (TraceLoopUnswitching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    tty->print_cr("Loop unswitching orig: %d @ %d  new: %d @ %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
                  head->_idx,                unswitch_iff->_idx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
                  old_new[head->_idx]->_idx, unswitch_iff_clone->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  C->set_major_progress();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
//-------------------------create_slow_version_of_loop------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
// Create a slow version of the loop by cloning the loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
// and inserting an if to select fast-slow versions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
// Return control projection of the entry to the fast version.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
ProjNode* PhaseIdealLoop::create_slow_version_of_loop(IdealLoopTree *loop,
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 33166
diff changeset
   225
                                                      Node_List &old_new,
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 33166
diff changeset
   226
                                                      int opcode) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  LoopNode* head  = loop->_head->as_Loop();
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9124
diff changeset
   228
  bool counted_loop = head->is_CountedLoop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  Node*     entry = head->in(LoopNode::EntryControl);
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10258
diff changeset
   230
  _igvn.rehash_node_delayed(entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  IdealLoopTree* outer_loop = loop->_parent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  Node *cont      = _igvn.intcon(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  set_ctrl(cont, C->root());
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   235
  Node* opq       = new Opaque1Node(C, cont);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  register_node(opq, outer_loop, entry, dom_depth(entry));
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   237
  Node *bol       = new Conv2BNode(opq);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  register_node(bol, outer_loop, entry, dom_depth(entry));
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 33166
diff changeset
   239
  IfNode* iff = (opcode == Op_RangeCheck) ? new RangeCheckNode(entry, bol, PROB_MAX, COUNT_UNKNOWN) :
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 33166
diff changeset
   240
    new IfNode(entry, bol, PROB_MAX, COUNT_UNKNOWN);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  register_node(iff, outer_loop, entry, dom_depth(entry));
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   242
  ProjNode* iffast = new IfTrueNode(iff);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  register_node(iffast, outer_loop, iff, dom_depth(iff));
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   244
  ProjNode* ifslow = new IfFalseNode(iff);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  register_node(ifslow, outer_loop, iff, dom_depth(iff));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // Clone the loop body.  The clone becomes the fast loop.  The
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   248
  // original pre-header will (illegally) have 3 control users
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   249
  // (old & new loops & new if).
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  clone_loop(loop, old_new, dom_depth(head), iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  assert(old_new[head->_idx]->is_Loop(), "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // Fast (true) control
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9124
diff changeset
   254
  Node* iffast_pred = clone_loop_predicates(entry, iffast, !counted_loop);
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10258
diff changeset
   255
  _igvn.replace_input_of(head, LoopNode::EntryControl, iffast_pred);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   256
  set_idom(head, iffast_pred, dom_depth(head));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // Slow (false) control
10258
10c77b8c8d3e 7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents: 9446
diff changeset
   259
  Node* ifslow_pred = clone_loop_predicates(entry, ifslow, !counted_loop);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  LoopNode* slow_head = old_new[head->_idx]->as_Loop();
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10258
diff changeset
   261
  _igvn.replace_input_of(slow_head, LoopNode::EntryControl, ifslow_pred);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents: 8732
diff changeset
   262
  set_idom(slow_head, ifslow_pred, dom_depth(slow_head));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  recompute_dom_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  return iffast;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
}
33166
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   268
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   269
LoopNode* PhaseIdealLoop::create_reserve_version_of_loop(IdealLoopTree *loop, CountedLoopReserveKit* lk) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   270
  Node_List old_new;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   271
  LoopNode* head  = loop->_head->as_Loop();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   272
  bool counted_loop = head->is_CountedLoop();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   273
  Node*     entry = head->in(LoopNode::EntryControl);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   274
  _igvn.rehash_node_delayed(entry);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   275
  IdealLoopTree* outer_loop = loop->_parent;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   276
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   277
  ConINode* const_1 = _igvn.intcon(1);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   278
  set_ctrl(const_1, C->root());
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   279
  IfNode* iff = new IfNode(entry, const_1, PROB_MAX, COUNT_UNKNOWN);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   280
  register_node(iff, outer_loop, entry, dom_depth(entry));
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   281
  ProjNode* iffast = new IfTrueNode(iff);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   282
  register_node(iffast, outer_loop, iff, dom_depth(iff));
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   283
  ProjNode* ifslow = new IfFalseNode(iff);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   284
  register_node(ifslow, outer_loop, iff, dom_depth(iff));
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   285
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   286
  // Clone the loop body.  The clone becomes the fast loop.  The
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   287
  // original pre-header will (illegally) have 3 control users
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   288
  // (old & new loops & new if).
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   289
  clone_loop(loop, old_new, dom_depth(head), iff);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   290
  assert(old_new[head->_idx]->is_Loop(), "" );
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   291
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   292
  LoopNode* slow_head = old_new[head->_idx]->as_Loop();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   293
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   294
#ifndef PRODUCT
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   295
  if (TraceLoopOpts) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   296
    tty->print_cr("PhaseIdealLoop::create_reserve_version_of_loop:");
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   297
    tty->print("\t iff = %d, ", iff->_idx); iff->dump();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   298
    tty->print("\t iffast = %d, ", iffast->_idx); iffast->dump();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   299
    tty->print("\t ifslow = %d, ", ifslow->_idx); ifslow->dump();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   300
    tty->print("\t before replace_input_of: head = %d, ", head->_idx); head->dump();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   301
    tty->print("\t before replace_input_of: slow_head = %d, ", slow_head->_idx); slow_head->dump();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   302
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   303
#endif
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   304
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   305
  // Fast (true) control
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   306
  _igvn.replace_input_of(head, LoopNode::EntryControl, iffast);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   307
  // Slow (false) control
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   308
  _igvn.replace_input_of(slow_head, LoopNode::EntryControl, ifslow);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   309
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   310
  recompute_dom_depth();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   311
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   312
  lk->set_iff(iff);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   313
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   314
#ifndef PRODUCT
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   315
  if (TraceLoopOpts ) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   316
    tty->print("\t after  replace_input_of: head = %d, ", head->_idx); head->dump();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   317
    tty->print("\t after  replace_input_of: slow_head = %d, ", slow_head->_idx); slow_head->dump();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   318
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   319
#endif
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   320
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   321
  return slow_head->as_Loop();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   322
}
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   323
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   324
CountedLoopReserveKit::CountedLoopReserveKit(PhaseIdealLoop* phase, IdealLoopTree *loop, bool active = true) :
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   325
  _phase(phase),
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   326
  _lpt(loop),
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   327
  _lp(NULL),
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   328
  _iff(NULL),
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   329
  _lp_reserved(NULL),
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   330
  _has_reserved(false),
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   331
  _use_new(false),
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   332
  _active(active)
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   333
  {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   334
    create_reserve();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   335
  };
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   336
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   337
CountedLoopReserveKit::~CountedLoopReserveKit() {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   338
  if (!_active) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   339
    return;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   340
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   341
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   342
  if (_has_reserved && !_use_new) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   343
    // intcon(0)->iff-node reverts CF to the reserved copy
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   344
    ConINode* const_0 = _phase->_igvn.intcon(0);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   345
    _phase->set_ctrl(const_0, _phase->C->root());
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   346
    _iff->set_req(1, const_0);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   347
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   348
    #ifndef PRODUCT
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   349
      if (TraceLoopOpts) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   350
        tty->print_cr("CountedLoopReserveKit::~CountedLoopReserveKit()");
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   351
        tty->print("\t discard loop %d and revert to the reserved loop clone %d: ", _lp->_idx, _lp_reserved->_idx);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   352
        _lp_reserved->dump();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   353
      }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   354
    #endif
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   355
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   356
}
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   357
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   358
bool CountedLoopReserveKit::create_reserve() {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   359
  if (!_active) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   360
    return false;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   361
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   362
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   363
  if(!_lpt->_head->is_CountedLoop()) {
34174
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   364
    if (TraceLoopOpts) {
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   365
      tty->print_cr("CountedLoopReserveKit::create_reserve: %d not counted loop", _lpt->_head->_idx);
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   366
    }
33166
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   367
    return false;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   368
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   369
  CountedLoopNode *cl = _lpt->_head->as_CountedLoop();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   370
  if (!cl->is_valid_counted_loop()) {
34174
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   371
    if (TraceLoopOpts) {
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   372
      tty->print_cr("CountedLoopReserveKit::create_reserve: %d not valid counted loop", cl->_idx);
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   373
    }
33166
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   374
    return false; // skip malformed counted loop
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   375
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   376
  if (!cl->is_main_loop()) {
34174
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   377
    if (TraceLoopOpts) {
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   378
      tty->print_cr("CountedLoopReserveKit::create_reserve: %d not main loop", cl->_idx);
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 34164
diff changeset
   379
    }
33166
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   380
    return false; // skip normal, pre, and post loops
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   381
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   382
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   383
  _lp = _lpt->_head->as_Loop();
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   384
  _lp_reserved = _phase->create_reserve_version_of_loop(_lpt, this);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   385
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   386
  if (!_lp_reserved->is_CountedLoop()) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   387
    return false;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   388
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   389
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   390
  Node* ifslow_pred = _lp_reserved->as_CountedLoop()->in(LoopNode::EntryControl);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   391
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   392
  if (!ifslow_pred->is_IfFalse()) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   393
    return false;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   394
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   395
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   396
  Node* iff = ifslow_pred->in(0);
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   397
  if (!iff->is_If() || iff != _iff) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   398
    return false;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   399
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   400
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   401
  if (iff->in(1)->Opcode() != Op_ConI) {
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   402
    return false;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   403
  }
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   404
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   405
  return _has_reserved = true;
81352250770f 8136725: Provide utility for creation a counted loop reserve copy (clone)
iveresov
parents: 31772
diff changeset
   406
}