src/hotspot/share/opto/coalesce.cpp
author redestad
Thu, 14 Nov 2019 15:24:35 +0100
changeset 59081 95a99e617f28
parent 51521 76a51e26d0ac
permissions -rw-r--r--
8234003: Improve IndexSet iteration Reviewed-by: neliasso, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46378
4ccca1fdf627 8160748: Inconsistent types for ideal_reg
kbarrett
parents: 43482
diff changeset
     2
 * Copyright (c) 1997, 2017, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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: 6272
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    27
#include "opto/block.hpp"
51521
76a51e26d0ac 8209639: assert failure in coalesce.cpp: attempted to spill a non-spillable item
roland
parents: 47216
diff changeset
    28
#include "opto/c2compiler.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    29
#include "opto/cfgnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    30
#include "opto/chaitin.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    31
#include "opto/coalesce.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    32
#include "opto/connode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    33
#include "opto/indexSet.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    34
#include "opto/machnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    35
#include "opto/matcher.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6272
diff changeset
    36
#include "opto/regmask.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
#ifndef PRODUCT
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
    39
void PhaseCoalesce::dump(Node *n) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // Being a const function means I cannot use 'Find'
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
    41
  uint r = _phc._lrg_map.find(n);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  tty->print("L%d/N%d ",r,n->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
void PhaseCoalesce::dump() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // I know I have a block layout now, so I can print blocks in a loop
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
    47
  for( uint i=0; i<_phc._cfg.number_of_blocks(); i++ ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    uint j;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
    49
    Block* b = _phc._cfg.get_block(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    // Print a nice block header
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    tty->print("B%d: ",b->_pre_order);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    for( j=1; j<b->num_preds(); j++ )
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
    53
      tty->print("B%d ", _phc._cfg.get_block_for_node(b->pred(j))->_pre_order);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    tty->print("-> ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    for( j=0; j<b->_num_succs; j++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      tty->print("B%d ",b->_succs[j]->_pre_order);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    tty->print(" IDom: B%d/#%d\n", b->_idom ? b->_idom->_pre_order : 0, b->_dom_depth);
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
    58
    uint cnt = b->number_of_nodes();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    for( j=0; j<cnt; j++ ) {
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
    60
      Node *n = b->get_node(j);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      dump( n );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      tty->print("\t%s\t",n->Name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      // Dump the inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      uint k;                   // Exit value of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      for( k=0; k<n->req(); k++ ) // For all required inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        if( n->in(k) ) dump( n->in(k) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
        else tty->print("_ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      int any_prec = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      for( ; k<n->len(); k++ )          // For all precedence inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
        if( n->in(k) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
          if( !any_prec++ ) tty->print(" |");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
          dump( n->in(k) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      // Dump node-specific info
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      n->dump_spec(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      tty->print("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    tty->print("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// Combine the live ranges def'd by these 2 Nodes.  N2 is an input to N1.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
    87
void PhaseCoalesce::combine_these_two(Node *n1, Node *n2) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
    88
  uint lr1 = _phc._lrg_map.find(n1);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
    89
  uint lr2 = _phc._lrg_map.find(n2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  if( lr1 != lr2 &&             // Different live ranges already AND
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      !_phc._ifg->test_edge_sq( lr1, lr2 ) ) {  // Do not interfere
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    LRG *lrg1 = &_phc.lrgs(lr1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    LRG *lrg2 = &_phc.lrgs(lr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    // Not an oop->int cast; oop->oop, int->int, AND int->oop are OK.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    // Now, why is int->oop OK?  We end up declaring a raw-pointer as an oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    // and in general that's a bad thing.  However, int->oop conversions only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    // happen at GC points, so the lifetime of the misclassified raw-pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // is from the CheckCastPP (that converts it to an oop) backwards up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    // through a merge point and into the slow-path call, and around the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    // diamond up to the heap-top check and back down into the slow-path call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    // The misclassified raw pointer is NOT live across the slow-path call,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    // and so does not appear in any GC info, so the fact that it is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    // misclassified is OK.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    if( (lrg1->_is_oop || !lrg2->_is_oop) && // not an oop->int cast AND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        // Compatible final mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        lrg1->mask().overlap( lrg2->mask() ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      // Merge larger into smaller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      if( lr1 > lr2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        uint  tmp =  lr1;  lr1 =  lr2;  lr2 =  tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        Node   *n =   n1;   n1 =   n2;   n2 =    n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
        LRG *ltmp = lrg1; lrg1 = lrg2; lrg2 = ltmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      // Union lr2 into lr1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      _phc.Union( n1, n2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      if (lrg1->_maxfreq < lrg2->_maxfreq)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        lrg1->_maxfreq = lrg2->_maxfreq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      // Merge in the IFG
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      _phc._ifg->Union( lr1, lr2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      // Combine register restrictions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      lrg1->AND(lrg2->mask());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// Copy coalescing
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   128
void PhaseCoalesce::coalesce_driver() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Coalesce from high frequency to low
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   131
  for (uint i = 0; i < _phc._cfg.number_of_blocks(); i++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   132
    coalesce(_phc._blks[i]);
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   133
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
// I am inserting copies to come out of SSA form.  In the general case, I am
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
// doing a parallel renaming.  I'm in the Named world now, so I can't do a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
// general parallel renaming.  All the copies now use  "names" (live-ranges)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
// to carry values instead of the explicit use-def chains.  Suppose I need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
// insert 2 copies into the same block.  They copy L161->L128 and L128->L132.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
// If I insert them in the wrong order then L128 will get clobbered before it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
// can get used by the second copy.  This cannot happen in the SSA model;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
// direct use-def chains get me the right value.  It DOES happen in the named
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
// model so I have to handle the reordering of copies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
// In general, I need to topo-sort the placed copies to avoid conflicts.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// Its possible to have a closed cycle of copies (e.g., recirculating the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
// values around a loop).  In this case I need a temp to break the cycle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
void PhaseAggressiveCoalesce::insert_copy_with_overlap( Block *b, Node *copy, uint dst_name, uint src_name ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // Scan backwards for the locations of the last use of the dst_name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // I am about to clobber the dst_name, so the copy must be inserted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // after the last use.  Last use is really first-use on a backwards scan.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  uint i = b->end_idx()-1;
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   155
  while(1) {
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   156
    Node *n = b->get_node(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    // Check for end of virtual copies; this is also the end of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    // parallel renaming effort.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   159
    if (n->_idx < _unique) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   160
      break;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   161
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    uint idx = n->is_Copy();
10255
bab46e6f7661 7069452: Cleanup NodeFlags
kvn
parents: 7397
diff changeset
   163
    assert( idx || n->is_Con() || n->is_MachProj(), "Only copies during parallel renaming" );
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   164
    if (idx && _phc._lrg_map.find(n->in(idx)) == dst_name) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   165
      break;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   166
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    i--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  uint last_use_idx = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // Also search for any kill of src_name that exits the block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // Since the copy uses src_name, I have to come before any kill.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  uint kill_src_idx = b->end_idx();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // There can be only 1 kill that exits any block and that is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // the last kill.  Thus it is the first kill on a backwards scan.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  i = b->end_idx()-1;
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   177
  while (1) {
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   178
    Node *n = b->get_node(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    // Check for end of virtual copies; this is also the end of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // parallel renaming effort.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   181
    if (n->_idx < _unique) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   182
      break;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   183
    }
10255
bab46e6f7661 7069452: Cleanup NodeFlags
kvn
parents: 7397
diff changeset
   184
    assert( n->is_Copy() || n->is_Con() || n->is_MachProj(), "Only copies during parallel renaming" );
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   185
    if (_phc._lrg_map.find(n) == src_name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      kill_src_idx = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    i--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // Need a temp?  Last use of dst comes after the kill of src?
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   192
  if (last_use_idx >= kill_src_idx) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    // Need to break a cycle with a temp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    uint idx = copy->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    Node *tmp = copy->clone();
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   196
    uint max_lrg_id = _phc._lrg_map.max_lrg_id();
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   197
    _phc.new_lrg(tmp, max_lrg_id);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   198
    _phc._lrg_map.set_max_lrg_id(max_lrg_id + 1);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   199
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    // Insert new temp between copy and source
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    tmp ->set_req(idx,copy->in(idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    copy->set_req(idx,tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    // Save source in temp early, before source is killed
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   204
    b->insert_node(tmp, kill_src_idx);
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   205
    _phc._cfg.map_node_to_block(tmp, b);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    last_use_idx++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // Insert just after last use
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   210
  b->insert_node(copy, last_use_idx + 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // We do LRGs compressing and fix a liveout data only here since the other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // place in Split() is guarded by the assert which we never hit.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   216
  _phc._lrg_map.compress_uf_map_for_nodes();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Fix block's liveout data for compressed live ranges.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   218
  for (uint lrg = 1; lrg < _phc._lrg_map.max_lrg_id(); lrg++) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   219
    uint compressed_lrg = _phc._lrg_map.find(lrg);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   220
    if (lrg != compressed_lrg) {
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   221
      for (uint bidx = 0; bidx < _phc._cfg.number_of_blocks(); bidx++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   222
        IndexSet *liveout = _phc._live->live(_phc._cfg.get_block(bidx));
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   223
        if (liveout->member(lrg)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
          liveout->remove(lrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
          liveout->insert(compressed_lrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // All new nodes added are actual copies to replace virtual copies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // Nodes with index less than '_unique' are original, non-virtual Nodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  _unique = C->unique();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   235
  for (uint i = 0; i < _phc._cfg.number_of_blocks(); i++) {
18099
45973b036c3e 8014959: assert(Compile::current()->live_nodes() < (uint)MaxNodeLimit) failed: Live Node limit exceeded limit
drchase
parents: 17013
diff changeset
   236
    C->check_node_count(NodeLimitFudgeFactor, "out of nodes in coalesce");
45973b036c3e 8014959: assert(Compile::current()->live_nodes() < (uint)MaxNodeLimit) failed: Live Node limit exceeded limit
drchase
parents: 17013
diff changeset
   237
    if (C->failing()) return;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   238
    Block *b = _phc._cfg.get_block(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    uint cnt = b->num_preds();  // Number of inputs to the Phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   241
    for( uint l = 1; l<b->number_of_nodes(); l++ ) {
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   242
      Node *n = b->get_node(l);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      // Do not use removed-copies, use copied value instead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      uint ncnt = n->req();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      for( uint k = 1; k<ncnt; k++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
        Node *copy = n->in(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        uint cidx = copy->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        if( cidx ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
          Node *def = copy->in(cidx);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   251
          if (_phc._lrg_map.find(copy) == _phc._lrg_map.find(def)) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   252
            n->set_req(k, def);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   253
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      // Remove any explicit copies that get coalesced.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      uint cidx = n->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      if( cidx ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        Node *def = n->in(cidx);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   261
        if (_phc._lrg_map.find(n) == _phc._lrg_map.find(def)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
          n->replace_by(def);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
          n->set_req(cidx,NULL);
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   264
          b->remove_node(l);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
          l--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   270
      if (n->is_Phi()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
        // Get the chosen name for the Phi
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   272
        uint phi_name = _phc._lrg_map.find(n);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
        // Ignore the pre-allocated specials
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   274
        if (!phi_name) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   275
          continue;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   276
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
        // Check for mismatch inputs to Phi
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   278
        for (uint j = 1; j < cnt; j++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
          Node *m = n->in(j);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   280
          uint src_name = _phc._lrg_map.find(m);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   281
          if (src_name != phi_name) {
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   282
            Block *pred = _phc._cfg.get_block_for_node(b->pred(j));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
            Node *copy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
            assert(!m->is_Con() || m->is_Mach(), "all Con must be Mach");
27416
862162c5a8e0 8047383: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24923
diff changeset
   285
            // Rematerialize constants instead of copying them.
862162c5a8e0 8047383: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24923
diff changeset
   286
            // We do this only for immediate constants, we avoid constant table loads
862162c5a8e0 8047383: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24923
diff changeset
   287
            // because that will unsafely extend the live range of the constant table base.
862162c5a8e0 8047383: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24923
diff changeset
   288
            if (m->is_Mach() && m->as_Mach()->is_Con() && !m->as_Mach()->is_MachConstant() &&
862162c5a8e0 8047383: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24923
diff changeset
   289
                m->as_Mach()->rematerialize()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
              copy = m->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
              // Insert the copy in the predecessor basic block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
              pred->add_inst(copy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
              // Copy any flags as well
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   294
              _phc.clone_projs(pred, pred->end_idx(), m, copy, _phc._lrg_map);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
            } else {
46378
4ccca1fdf627 8160748: Inconsistent types for ideal_reg
kbarrett
parents: 43482
diff changeset
   296
              uint ireg = m->ideal_reg();
43482
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   297
              if (ireg == 0 || ireg == Op_RegFlags) {
51521
76a51e26d0ac 8209639: assert failure in coalesce.cpp: attempted to spill a non-spillable item
roland
parents: 47216
diff changeset
   298
                if (C->subsume_loads()) {
76a51e26d0ac 8209639: assert failure in coalesce.cpp: attempted to spill a non-spillable item
roland
parents: 47216
diff changeset
   299
                  C->record_failure(C2Compiler::retry_no_subsuming_loads());
76a51e26d0ac 8209639: assert failure in coalesce.cpp: attempted to spill a non-spillable item
roland
parents: 47216
diff changeset
   300
                } else {
76a51e26d0ac 8209639: assert failure in coalesce.cpp: attempted to spill a non-spillable item
roland
parents: 47216
diff changeset
   301
                  assert(false, "attempted to spill a non-spillable item: %d: %s, ireg = %u, spill_type: %s",
76a51e26d0ac 8209639: assert failure in coalesce.cpp: attempted to spill a non-spillable item
roland
parents: 47216
diff changeset
   302
                         m->_idx, m->Name(), ireg, MachSpillCopyNode::spill_type(MachSpillCopyNode::PhiInput));
76a51e26d0ac 8209639: assert failure in coalesce.cpp: attempted to spill a non-spillable item
roland
parents: 47216
diff changeset
   303
                  C->record_method_not_compilable("attempted to spill a non-spillable item");
76a51e26d0ac 8209639: assert failure in coalesce.cpp: attempted to spill a non-spillable item
roland
parents: 47216
diff changeset
   304
                }
43482
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   305
                return;
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   306
              }
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   307
              const RegMask *rm = C->matcher()->idealreg2spillmask[ireg];
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 22914
diff changeset
   308
              copy = new MachSpillCopyNode(MachSpillCopyNode::PhiInput, m, *rm, *rm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
              // Find a good place to insert.  Kinda tricky, use a subroutine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
              insert_copy_with_overlap(pred,copy,phi_name,src_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
            // Insert the copy in the use-def chain
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   313
            n->set_req(j, copy);
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   314
            _phc._cfg.map_node_to_block(copy, pred);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
            // Extend ("register allocate") the names array for the copy.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   316
            _phc._lrg_map.extend(copy->_idx, phi_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
          } // End of if Phi names do not match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
        } // End of for all inputs to Phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      } else { // End of if Phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
        // Now check for 2-address instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
        uint idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
        if( n->is_Mach() && (idx=n->as_Mach()->two_adr()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
          // Get the chosen name for the Node
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   325
          uint name = _phc._lrg_map.find(n);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   326
          assert (name, "no 2-address specials");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
          // Check for name mis-match on the 2-address input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
          Node *m = n->in(idx);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   329
          if (_phc._lrg_map.find(m) != name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
            Node *copy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
            assert(!m->is_Con() || m->is_Mach(), "all Con must be Mach");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
            // At this point it is unsafe to extend live ranges (6550579).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
            // Rematerialize only constants as we do for Phi above.
27416
862162c5a8e0 8047383: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24923
diff changeset
   334
            if (m->is_Mach() && m->as_Mach()->is_Con() && !m->as_Mach()->is_MachConstant() &&
862162c5a8e0 8047383: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24923
diff changeset
   335
                m->as_Mach()->rematerialize()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
              copy = m->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
              // Insert the copy in the basic block, just before us
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   338
              b->insert_node(copy, l++);
19334
3aa9ca404965 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 19330
diff changeset
   339
              l += _phc.clone_projs(b, l, m, copy, _phc._lrg_map);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
            } else {
46378
4ccca1fdf627 8160748: Inconsistent types for ideal_reg
kbarrett
parents: 43482
diff changeset
   341
              uint ireg = m->ideal_reg();
43482
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   342
              if (ireg == 0 || ireg == Op_RegFlags) {
46378
4ccca1fdf627 8160748: Inconsistent types for ideal_reg
kbarrett
parents: 43482
diff changeset
   343
                assert(false, "attempted to spill a non-spillable item: %d: %s, ireg = %u, spill_type: %s",
43482
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   344
                       m->_idx, m->Name(), ireg, MachSpillCopyNode::spill_type(MachSpillCopyNode::TwoAddress));
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   345
                C->record_method_not_compilable("attempted to spill a non-spillable item");
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   346
                return;
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   347
              }
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   348
              const RegMask *rm = C->matcher()->idealreg2spillmask[ireg];
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 22914
diff changeset
   349
              copy = new MachSpillCopyNode(MachSpillCopyNode::TwoAddress, m, *rm, *rm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
              // Insert the copy in the basic block, just before us
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   351
              b->insert_node(copy, l++);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
            // Insert the copy in the use-def chain
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   354
            n->set_req(idx, copy);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
            // Extend ("register allocate") the names array for the copy.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   356
            _phc._lrg_map.extend(copy->_idx, name);
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   357
            _phc._cfg.map_node_to_block(copy, b);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        } // End of is two-adr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
        // Insert a copy at a debug use for a lrg which has high frequency
19721
8ecbb2cdc965 8023988: Move local scheduling of nodes to the CFG creation and code motion phase (PhaseCFG)
adlertz
parents: 19717
diff changeset
   363
        if (b->_freq < OPTO_DEBUG_SPLIT_FREQ || _phc._cfg.is_uncommon(b)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
          // Walk the debug inputs to the node and check for lrg freq
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
          JVMState* jvms = n->jvms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
          uint debug_start = jvms ? jvms->debug_start() : 999999;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
          uint debug_end   = jvms ? jvms->debug_end()   : 999999;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
          for(uint inpidx = debug_start; inpidx < debug_end; inpidx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
            // Do not split monitors; they are only needed for debug table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
            // entries and need no code.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   371
            if (jvms->is_monitor_use(inpidx)) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   372
              continue;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   373
            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
            Node *inp = n->in(inpidx);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   375
            uint nidx = _phc._lrg_map.live_range_id(inp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
            LRG &lrg = lrgs(nidx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
            // If this lrg has a high frequency use/def
2340
cb47f8209cd8 6810845: Performance regression in mpegaudio on x64
kvn
parents: 2131
diff changeset
   379
            if( lrg._maxfreq >= _phc.high_frequency_lrg() ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
              // If the live range is also live out of this block (like it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
              // would be for a fast/slow idiom), the normal spill mechanism
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
              // does an excellent job.  If it is not live out of this block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
              // (like it would be for debug info to uncommon trap) splitting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
              // the live range now allows a better allocation in the high
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
              // frequency blocks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
              //   Build_IFG_virtual has converted the live sets to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
              // live-IN info, not live-OUT info.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
              uint k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
              for( k=0; k < b->_num_succs; k++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
                if( _phc._live->live(b->_succs[k])->member( nidx ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
                  break;      // Live in to some successor block?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
              if( k < b->_num_succs )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
                continue;     // Live out; do not pre-split
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
              // Split the lrg at this use
46378
4ccca1fdf627 8160748: Inconsistent types for ideal_reg
kbarrett
parents: 43482
diff changeset
   395
              uint ireg = inp->ideal_reg();
43482
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   396
              if (ireg == 0 || ireg == Op_RegFlags) {
46378
4ccca1fdf627 8160748: Inconsistent types for ideal_reg
kbarrett
parents: 43482
diff changeset
   397
                assert(false, "attempted to spill a non-spillable item: %d: %s, ireg = %u, spill_type: %s",
43482
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   398
                       inp->_idx, inp->Name(), ireg, MachSpillCopyNode::spill_type(MachSpillCopyNode::DebugUse));
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   399
                C->record_method_not_compilable("attempted to spill a non-spillable item");
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   400
                return;
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   401
              }
7417485c50f9 8172850: Anti-dependency on membar causes crash in register allocator due to invalid instruction scheduling
thartmann
parents: 27416
diff changeset
   402
              const RegMask *rm = C->matcher()->idealreg2spillmask[ireg];
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 22914
diff changeset
   403
              Node* copy = new MachSpillCopyNode(MachSpillCopyNode::DebugUse, inp, *rm, *rm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
              // Insert the copy in the use-def chain
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
              n->set_req(inpidx, copy );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
              // Insert the copy in the basic block, just before us
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   407
              b->insert_node(copy,  l++);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
              // Extend ("register allocate") the names array for the copy.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   409
              uint max_lrg_id = _phc._lrg_map.max_lrg_id();
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   410
              _phc.new_lrg(copy, max_lrg_id);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   411
              _phc._lrg_map.set_max_lrg_id(max_lrg_id + 1);
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   412
              _phc._cfg.map_node_to_block(copy, b);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
              //tty->print_cr("Split a debug use in Aggressive Coalesce");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
            }  // End of if high frequency use/def
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
          }  // End of for all debug inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
        }  // End of if low frequency safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
      } // End of if Phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    } // End of for all instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  } // End of for all blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   424
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
// Aggressive (but pessimistic) copy coalescing of a single block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
// The following coalesce pass represents a single round of aggressive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
// pessimistic coalesce.  "Aggressive" means no attempt to preserve
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
// colorability when coalescing.  This occasionally means more spills, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
// it also means fewer rounds of coalescing for better code - and that means
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
// faster compiles.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
// "Pessimistic" means we do not hit the fixed point in one pass (and we are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
// reaching for the least fixed point to boot).  This is typically solved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
// with a few more rounds of coalescing, but the compiler must run fast.  We
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
// could optimistically coalescing everything touching PhiNodes together
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
// into one big live range, then check for self-interference.  Everywhere
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
// the live range interferes with self it would have to be split.  Finding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
// the right split points can be done with some heuristics (based on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
// expected frequency of edges in the live range).  In short, it's a real
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
// research problem and the timeline is too short to allow such research.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
// Further thoughts: (1) build the LR in a pass, (2) find self-interference
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
// in another pass, (3) per each self-conflict, split, (4) split by finding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
// the low-cost cut (min-cut) of the LR, (5) edges in the LR are weighted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
// according to the GCM algorithm (or just exec freq on CFG edges).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
void PhaseAggressiveCoalesce::coalesce( Block *b ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  // Copies are still "virtual" - meaning we have not made them explicitly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  // copies.  Instead, Phi functions of successor blocks have mis-matched
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  // live-ranges.  If I fail to coalesce, I'll have to insert a copy to line
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  // up the live-ranges.  Check for Phis in successor blocks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  uint i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  for( i=0; i<b->_num_succs; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    Block *bs = b->_succs[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    // Find index of 'b' in 'bs' predecessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    uint j=1;
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   457
    while (_phc._cfg.get_block_for_node(bs->pred(j)) != b) {
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   458
      j++;
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   459
    }
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   460
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    // Visit all the Phis in successor block
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   462
    for( uint k = 1; k<bs->number_of_nodes(); k++ ) {
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   463
      Node *n = bs->get_node(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
      if( !n->is_Phi() ) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      combine_these_two( n, n->in(j) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  } // End of for all successor blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // Check _this_ block for 2-address instructions and copies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  uint cnt = b->end_idx();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  for( i = 1; i<cnt; i++ ) {
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   473
    Node *n = b->get_node(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    uint idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    // 2-address instructions have a virtual Copy matching their input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    // to their output
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   477
    if (n->is_Mach() && (idx = n->as_Mach()->two_adr())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
      MachNode *mach = n->as_Mach();
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   479
      combine_these_two(mach, mach->in(idx));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  } // End of for all instructions in block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   484
PhaseConservativeCoalesce::PhaseConservativeCoalesce(PhaseChaitin &chaitin) : PhaseCoalesce(chaitin) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   485
  _ulr.initialize(_phc._lrg_map.max_lrg_id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
void PhaseConservativeCoalesce::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  _phc.set_was_low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
void PhaseConservativeCoalesce::union_helper( Node *lr1_node, Node *lr2_node, uint lr1, uint lr2, Node *src_def, Node *dst_copy, Node *src_copy, Block *b, uint bindex ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  // Join live ranges.  Merge larger into smaller.  Union lr2 into lr1 in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  // union-find tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  _phc.Union( lr1_node, lr2_node );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  // Single-def live range ONLY if both live ranges are single-def.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  // If both are single def, then src_def powers one live range
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  // and def_copy powers the other.  After merging, src_def powers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  // the combined live range.
1057
44220ef9a775 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 1
diff changeset
   503
  lrgs(lr1)._def = (lrgs(lr1).is_multidef() ||
44220ef9a775 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 1
diff changeset
   504
                        lrgs(lr2).is_multidef() )
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    ? NodeSentinel : src_def;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  lrgs(lr2)._def = NULL;    // No def for lrg 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  lrgs(lr2).Clear();        // Force empty mask for LRG 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  //lrgs(lr2)._size = 0;      // Live-range 2 goes dead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  lrgs(lr1)._is_oop |= lrgs(lr2)._is_oop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  lrgs(lr2)._is_oop = 0;    // In particular, not an oop for GC info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  if (lrgs(lr1)._maxfreq < lrgs(lr2)._maxfreq)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    lrgs(lr1)._maxfreq = lrgs(lr2)._maxfreq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  // Copy original value instead.  Intermediate copies go dead, and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  // the dst_copy becomes useless.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  int didx = dst_copy->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  dst_copy->set_req( didx, src_def );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  // Add copy to free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  // _phc.free_spillcopy(b->_nodes[bindex]);
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   521
  assert( b->get_node(bindex) == dst_copy, "" );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  dst_copy->replace_by( dst_copy->in(didx) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  dst_copy->set_req( didx, NULL);
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   524
  b->remove_node(bindex);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  if( bindex < b->_ihrp_index ) b->_ihrp_index--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  if( bindex < b->_fhrp_index ) b->_fhrp_index--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  // Stretched lr1; add it to liveness of intermediate blocks
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   529
  Block *b2 = _phc._cfg.get_block_for_node(src_copy);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  while( b != b2 ) {
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   531
    b = _phc._cfg.get_block_for_node(b->pred(1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    _phc._live->live(b)->insert(lr1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
// Factored code from copy_copy that computes extra interferences from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
// lengthening a live range by double-coalescing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
uint PhaseConservativeCoalesce::compute_separating_interferences(Node *dst_copy, Node *src_copy, Block *b, uint bindex, RegMask &rm, uint reg_degree, uint rm_size, uint lr1, uint lr2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  assert(!lrgs(lr1)._fat_proj, "cannot coalesce fat_proj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  assert(!lrgs(lr2)._fat_proj, "cannot coalesce fat_proj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  Node *prev_copy = dst_copy->in(dst_copy->is_Copy());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  Block *b2 = b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  uint bindex2 = bindex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  while( 1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    // Find previous instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    bindex2--;                  // Chain backwards 1 instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    while( bindex2 == 0 ) {     // At block start, find prior block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
      assert( b2->num_preds() == 2, "cannot double coalesce across c-flow" );
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   550
      b2 = _phc._cfg.get_block_for_node(b2->pred(1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
      bindex2 = b2->end_idx()-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    // Get prior instruction
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   554
    assert(bindex2 < b2->number_of_nodes(), "index out of bounds");
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   555
    Node *x = b2->get_node(bindex2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    if( x == prev_copy ) {      // Previous copy in copy chain?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
      if( prev_copy == src_copy)// Found end of chain and all interferences
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
        break;                  // So break out of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
      // Else work back one in copy chain
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
      prev_copy = prev_copy->in(prev_copy->is_Copy());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    } else {                    // Else collect interferences
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   562
      uint lidx = _phc._lrg_map.find(x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
      // Found another def of live-range being stretched?
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   564
      if(lidx == lr1) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   565
        return max_juint;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   566
      }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   567
      if(lidx == lr2) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   568
        return max_juint;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   569
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
      // If we attempt to coalesce across a bound def
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      if( lrgs(lidx).is_bound() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
        // Do not let the coalesced LRG expect to get the bound color
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
        rm.SUBTRACT( lrgs(lidx).mask() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
        // Recompute rm_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
        rm_size = rm.Size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
        //if( rm._flags ) rm_size += 1000000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
        if( reg_degree >= rm_size ) return max_juint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
      if( rm.overlap(lrgs(lidx).mask()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
        // Insert lidx into union LRG; returns TRUE if actually inserted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
        if( _ulr.insert(lidx) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
          // Infinite-stack neighbors do not alter colorability, as they
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
          // can always color to some other color.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
          if( !lrgs(lidx).mask().is_AllStack() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
            // If this coalesce will make any new neighbor uncolorable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
            // do not coalesce.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
            if( lrgs(lidx).just_lo_degree() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
              return max_juint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
            // Bump our degree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
            if( ++reg_degree >= rm_size )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
              return max_juint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
          } // End of if not infinite-stack neighbor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
        } // End of if actually inserted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
      } // End of if live range overlaps
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1217
diff changeset
   596
    } // End of else collect interferences for 1 node
98f9cef66a34 6810672: Comment typos
twisti
parents: 1217
diff changeset
   597
  } // End of while forever, scan back for interferences
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  return reg_degree;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
void PhaseConservativeCoalesce::update_ifg(uint lr1, uint lr2, IndexSet *n_lr1, IndexSet *n_lr2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  // Some original neighbors of lr1 might have gone away
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  // because the constrained register mask prevented them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  // Remove lr1 from such neighbors.
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   605
  uint neighbor = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  LRG &lrg1 = lrgs(lr1);
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   607
  if (!n_lr1->is_empty()) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   608
    IndexSetIterator one(n_lr1);
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   609
    while ((neighbor = one.next()) != 0) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   610
      if (!_ulr.member(neighbor)) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   611
        if (_phc._ifg->neighbors(neighbor)->remove(lr1)) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   612
          lrgs(neighbor).inc_degree(-lrg1.compute_degree(lrgs(neighbor)));
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   613
        }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   614
      }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   615
    }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   616
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  // lr2 is now called (coalesced into) lr1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  // Remove lr2 from the IFG.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  LRG &lrg2 = lrgs(lr2);
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   622
  if (!n_lr2->is_empty()) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   623
    IndexSetIterator two(n_lr2);
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   624
    while ((neighbor = two.next()) != 0) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   625
      if (_phc._ifg->neighbors(neighbor)->remove(lr2)) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   626
        lrgs(neighbor).inc_degree(-lrg2.compute_degree(lrgs(neighbor)));
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   627
      }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   628
    }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   629
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  // Some neighbors of intermediate copies now interfere with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  // combined live range.
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   633
  if (!_ulr.is_empty()) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   634
    IndexSetIterator three(&_ulr);
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   635
    while ((neighbor = three.next()) != 0) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   636
      if (_phc._ifg->neighbors(neighbor)->insert(lr1)) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   637
        lrgs(neighbor).inc_degree(lrg1.compute_degree(lrgs(neighbor)));
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   638
      }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   639
    }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 51521
diff changeset
   640
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
static void record_bias( const PhaseIFG *ifg, int lr1, int lr2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  // Tag copy bias here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  if( !ifg->lrgs(lr1)._copy_bias )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    ifg->lrgs(lr1)._copy_bias = lr2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  if( !ifg->lrgs(lr2)._copy_bias )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    ifg->lrgs(lr2)._copy_bias = lr1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
// See if I can coalesce a series of multiple copies together.  I need the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
// final dest copy and the original src copy.  They can be the same Node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
// Compute the compatible register masks.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   654
bool PhaseConservativeCoalesce::copy_copy(Node *dst_copy, Node *src_copy, Block *b, uint bindex) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   656
  if (!dst_copy->is_SpillCopy()) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   657
    return false;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   658
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   659
  if (!src_copy->is_SpillCopy()) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   660
    return false;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   661
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  Node *src_def = src_copy->in(src_copy->is_Copy());
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   663
  uint lr1 = _phc._lrg_map.find(dst_copy);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   664
  uint lr2 = _phc._lrg_map.find(src_def);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  // Same live ranges already?
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   667
  if (lr1 == lr2) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   668
    return false;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   669
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  // Interfere?
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   672
  if (_phc._ifg->test_edge_sq(lr1, lr2)) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   673
    return false;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   674
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  // Not an oop->int cast; oop->oop, int->int, AND int->oop are OK.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   677
  if (!lrgs(lr1)._is_oop && lrgs(lr2)._is_oop) { // not an oop->int cast
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    return false;
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   679
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  // Coalescing between an aligned live range and a mis-aligned live range?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  // No, no!  Alignment changes how we count degree.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   683
  if (lrgs(lr1)._fat_proj != lrgs(lr2)._fat_proj) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
    return false;
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   685
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  // Sort; use smaller live-range number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  Node *lr1_node = dst_copy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  Node *lr2_node = src_def;
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10255
diff changeset
   690
  if (lr1 > lr2) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    uint tmp = lr1; lr1 = lr2; lr2 = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    lr1_node = src_def;  lr2_node = dst_copy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  // Check for compatibility of the 2 live ranges by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  // intersecting their allowed register sets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  RegMask rm = lrgs(lr1).mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  rm.AND(lrgs(lr2).mask());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  // Number of bits free
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  uint rm_size = rm.Size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
6272
94a20ad0e9de 6978249: spill between cpu and fpu registers when those moves are fast
never
parents: 5547
diff changeset
   702
  if (UseFPUForSpilling && rm.is_AllStack() ) {
94a20ad0e9de 6978249: spill between cpu and fpu registers when those moves are fast
never
parents: 5547
diff changeset
   703
    // Don't coalesce when frequency difference is large
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   704
    Block *dst_b = _phc._cfg.get_block_for_node(dst_copy);
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   705
    Block *src_def_b = _phc._cfg.get_block_for_node(src_def);
6272
94a20ad0e9de 6978249: spill between cpu and fpu registers when those moves are fast
never
parents: 5547
diff changeset
   706
    if (src_def_b->_freq > 10*dst_b->_freq )
94a20ad0e9de 6978249: spill between cpu and fpu registers when those moves are fast
never
parents: 5547
diff changeset
   707
      return false;
94a20ad0e9de 6978249: spill between cpu and fpu registers when those moves are fast
never
parents: 5547
diff changeset
   708
  }
94a20ad0e9de 6978249: spill between cpu and fpu registers when those moves are fast
never
parents: 5547
diff changeset
   709
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  // If we can use any stack slot, then effective size is infinite
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  if( rm.is_AllStack() ) rm_size += 1000000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  // Incompatible masks, no way to coalesce
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  if( rm_size == 0 ) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  // Another early bail-out test is when we are double-coalescing and the
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1217
diff changeset
   716
  // 2 copies are separated by some control flow.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  if( dst_copy != src_copy ) {
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   718
    Block *src_b = _phc._cfg.get_block_for_node(src_copy);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
    Block *b2 = b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    while( b2 != src_b ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
      if( b2->num_preds() > 2 ){// Found merge-point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
        _phc._lost_opp_cflow_coalesce++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
        // extra record_bias commented out because Chris believes it is not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
        // productive.  Since we can record only 1 bias, we want to choose one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
        // that stands a chance of working and this one probably does not.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
        //record_bias( _phc._lrgs, lr1, lr2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
        return false;           // To hard to find all interferences
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
      }
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   729
      b2 = _phc._cfg.get_block_for_node(b2->pred(1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  // Union the two interference sets together into '_ulr'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  uint reg_degree = _ulr.lrg_union( lr1, lr2, rm_size, _phc._ifg, rm );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  if( reg_degree >= rm_size ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    record_bias( _phc._ifg, lr1, lr2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  // Now I need to compute all the interferences between dst_copy and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  // src_copy.  I'm not willing visit the entire interference graph, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  // I limit my search to things in dst_copy's block or in a straight
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  // line of previous blocks.  I give up at merge points or when I get
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  // more interferences than my degree.  I can stop when I find src_copy.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  if( dst_copy != src_copy ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    reg_degree = compute_separating_interferences(dst_copy, src_copy, b, bindex, rm, rm_size, reg_degree, lr1, lr2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
    if( reg_degree == max_juint ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
      record_bias( _phc._ifg, lr1, lr2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  } // End of if dst_copy & src_copy are different
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  // ---- THE COMBINED LRG IS COLORABLE ----
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  // YEAH - Now coalesce this copy away
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  assert( lrgs(lr1).num_regs() == lrgs(lr2).num_regs(),   "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  IndexSet *n_lr1 = _phc._ifg->neighbors(lr1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  IndexSet *n_lr2 = _phc._ifg->neighbors(lr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  // Update the interference graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  update_ifg(lr1, lr2, n_lr1, n_lr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  _ulr.remove(lr1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  // Uncomment the following code to trace Coalescing in great detail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  //if (false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  //  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  //  tty->print_cr("#######################################");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  //  tty->print_cr("union %d and %d", lr1, lr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  //  n_lr1->dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  //  n_lr2->dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  //  tty->print_cr("resulting set is");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  //  _ulr.dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  //}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  // Replace n_lr1 with the new combined live range.  _ulr will use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  // n_lr1's old memory on the next iteration.  n_lr2 is cleared to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  // send its internal memory to the free list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  _ulr.swap(n_lr1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  _ulr.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  n_lr2->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  lrgs(lr1).set_degree( _phc._ifg->effective_degree(lr1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  lrgs(lr2).set_degree( 0 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  // Join live ranges.  Merge larger into smaller.  Union lr2 into lr1 in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  // union-find tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  union_helper( lr1_node, lr2_node, lr1, lr2, src_def, dst_copy, src_copy, b, bindex );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  // Combine register restrictions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  lrgs(lr1).set_mask(rm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  lrgs(lr1).compute_set_mask_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  lrgs(lr1)._cost += lrgs(lr2)._cost;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  lrgs(lr1)._area += lrgs(lr2)._area;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  // While its uncommon to successfully coalesce live ranges that started out
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  // being not-lo-degree, it can happen.  In any case the combined coalesced
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  // live range better Simplify nicely.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  lrgs(lr1)._was_lo = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  // kinda expensive to do all the time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  //tty->print_cr("warning: slow verify happening");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  //_phc._ifg->verify( &_phc );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
// Conservative (but pessimistic) copy coalescing of a single block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
void PhaseConservativeCoalesce::coalesce( Block *b ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  // Bail out on infrequent blocks
19721
8ecbb2cdc965 8023988: Move local scheduling of nodes to the CFG creation and code motion phase (PhaseCFG)
adlertz
parents: 19717
diff changeset
   813
  if (_phc._cfg.is_uncommon(b)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    return;
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 18099
diff changeset
   815
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  // Check this block for copies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  for( uint i = 1; i<b->end_idx(); i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
    // Check for actual copies on inputs.  Coalesce a copy into its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
    // input if use and copy's input are compatible.
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19334
diff changeset
   820
    Node *copy1 = b->get_node(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
    uint idx1 = copy1->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    if( !idx1 ) continue;       // Not a copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    if( copy_copy(copy1,copy1,b,i) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
      i--;                      // Retry, same location in block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
      PhaseChaitin::_conserv_coalesce++;  // Collect stats on success
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
}