hotspot/src/share/vm/opto/ifg.cpp
author thartmann
Mon, 04 Jul 2016 09:14:02 +0200
changeset 40044 4e8299073922
parent 37248 11a660dbbb8e
child 46630 75aa3e39d02c
permissions -rw-r--r--
8160651: StubRoutines::_dtan does not restore callee save register rbx Summary: Pop rbx before leaving stub. Reviewed-by: vlivanov, vdeshpande
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33065
diff changeset
     2
 * Copyright (c) 1998, 2016, 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: 4760
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4760
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: 4760
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "compiler/oopMap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/allocation.inline.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33065
diff changeset
    28
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/addnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/block.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/callnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "opto/cfgnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "opto/chaitin.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "opto/coalesce.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "opto/indexSet.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "opto/machnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "opto/memnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "opto/opcodes.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
PhaseIFG::PhaseIFG( Arena *arena ) : Phase(Interference_Graph), _arena(arena) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
void PhaseIFG::init( uint maxlrg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _maxlrg = maxlrg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _yanked = new (_arena) VectorSet(_arena);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _is_square = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // Make uninitialized adjacency lists
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _adjs = (IndexSet*)_arena->Amalloc(sizeof(IndexSet)*maxlrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Also make empty live range structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  _lrgs = (LRG *)_arena->Amalloc( maxlrg * sizeof(LRG) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  memset(_lrgs,0,sizeof(LRG)*maxlrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // Init all to empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  for( uint i = 0; i < maxlrg; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _adjs[i].initialize(maxlrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _lrgs[i].Set_All();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// Add edge between vertices a & b.  These are sorted (triangular matrix),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// then the smaller number is inserted in the larger numbered array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
int PhaseIFG::add_edge( uint a, uint b ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  lrgs(a).invalid_degree();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  lrgs(b).invalid_degree();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Sort a and b, so that a is bigger
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert( !_is_square, "only on triangular" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  if( a < b ) { uint tmp = a; a = b; b = tmp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  return _adjs[a].insert( b );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// Add an edge between 'a' and everything in the vector.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
void PhaseIFG::add_vector( uint a, IndexSet *vec ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // IFG is triangular, so do the inserts where 'a' < 'b'.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  assert( !_is_square, "only on triangular" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  IndexSet *adjs_a = &_adjs[a];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  if( !vec->count() ) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  IndexSetIterator elements(vec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  uint neighbor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  while ((neighbor = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    add_edge( a, neighbor );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// Is there an edge between a and b?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
int PhaseIFG::test_edge( uint a, uint b ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Sort a and b, so that a is larger
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  assert( !_is_square, "only on triangular" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  if( a < b ) { uint tmp = a; a = b; b = tmp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  return _adjs[a].member(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// Convert triangular matrix to square matrix
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
void PhaseIFG::SquareUp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  assert( !_is_square, "only on triangular" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Simple transpose
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  for( uint i = 0; i < _maxlrg; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    IndexSetIterator elements(&_adjs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    uint datum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    while ((datum = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      _adjs[datum].insert( i );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _is_square = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
// Compute effective degree in bulk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
void PhaseIFG::Compute_Effective_Degree() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  assert( _is_square, "only on square" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  for( uint i = 0; i < _maxlrg; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    lrgs(i).set_degree(effective_degree(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
int PhaseIFG::test_edge_sq( uint a, uint b ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  assert( _is_square, "only on square" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Swap, so that 'a' has the lesser count.  Then binary search is on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // the smaller of a's list and b's list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  if( neighbor_cnt(a) > neighbor_cnt(b) ) { uint tmp = a; a = b; b = tmp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  //return _adjs[a].unordered_member(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  return _adjs[a].member(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// Union edges of B into A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
void PhaseIFG::Union( uint a, uint b ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  assert( _is_square, "only on square" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  IndexSet *A = &_adjs[a];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  IndexSetIterator b_elements(&_adjs[b]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  uint datum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  while ((datum = b_elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if(A->insert(datum)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      _adjs[datum].insert(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      lrgs(a).invalid_degree();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      lrgs(datum).invalid_degree();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
// Yank a Node and all connected edges from the IFG.  Return a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
// list of neighbors (edges) yanked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
IndexSet *PhaseIFG::remove_node( uint a ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  assert( _is_square, "only on square" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  assert( !_yanked->test(a), "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  _yanked->set(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // I remove the LRG from all neighbors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  IndexSetIterator elements(&_adjs[a]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  LRG &lrg_a = lrgs(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  uint datum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  while ((datum = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    _adjs[datum].remove(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    lrgs(datum).inc_degree( -lrg_a.compute_degree(lrgs(datum)) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  return neighbors(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
// Re-insert a yanked Node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
void PhaseIFG::re_insert( uint a ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  assert( _is_square, "only on square" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert( _yanked->test(a), "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  (*_yanked) >>= a;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  IndexSetIterator elements(&_adjs[a]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  uint datum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  while ((datum = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    _adjs[datum].insert(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    lrgs(datum).invalid_degree();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// Compute the degree between 2 live ranges.  If both live ranges are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
// aligned-adjacent powers-of-2 then we use the MAX size.  If either is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// mis-aligned (or for Fat-Projections, not-adjacent) then we have to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// MULTIPLY the sizes.  Inspect Brigg's thesis on register pairs to see why
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// this is so.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
int LRG::compute_degree( LRG &l ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  int tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  int num_regs = _num_regs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  int nregs = l.num_regs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  tmp =  (_fat_proj || l._fat_proj)     // either is a fat-proj?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    ? (num_regs * nregs)                // then use product
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    : MAX2(num_regs,nregs);             // else use max
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  return tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
// Compute effective degree for this live range.  If both live ranges are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
// aligned-adjacent powers-of-2 then we use the MAX size.  If either is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
// mis-aligned (or for Fat-Projections, not-adjacent) then we have to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
// MULTIPLY the sizes.  Inspect Brigg's thesis on register pairs to see why
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// this is so.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
int PhaseIFG::effective_degree( uint lidx ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  int eff = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  int num_regs = lrgs(lidx).num_regs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  int fat_proj = lrgs(lidx)._fat_proj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  IndexSet *s = neighbors(lidx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  IndexSetIterator elements(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  uint nidx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  while((nidx = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    LRG &lrgn = lrgs(nidx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    int nregs = lrgn.num_regs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    eff += (fat_proj || lrgn._fat_proj) // either is a fat-proj?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      ? (num_regs * nregs)              // then use product
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      : MAX2(num_regs,nregs);           // else use max
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  return eff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
void PhaseIFG::dump() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  tty->print_cr("-- Interference Graph --%s--",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
                _is_square ? "square" : "triangular" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  if( _is_square ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    for( uint i = 0; i < _maxlrg; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      tty->print( (*_yanked)[i] ? "XX " : "  ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      tty->print("L%d: { ",i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
      IndexSetIterator elements(&_adjs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      uint datum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      while ((datum = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        tty->print("L%d ", datum);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      tty->print_cr("}");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // Triangular
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  for( uint i = 0; i < _maxlrg; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    uint j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    tty->print( (*_yanked)[i] ? "XX " : "  ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    tty->print("L%d: { ",i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    for( j = _maxlrg; j > i; j-- )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      if( test_edge(j - 1,i) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        tty->print("L%d ",j - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    tty->print("| ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    IndexSetIterator elements(&_adjs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    uint datum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    while ((datum = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      tty->print("L%d ", datum);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    tty->print("}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  tty->print("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
void PhaseIFG::stats() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  int *h_cnt = NEW_RESOURCE_ARRAY(int,_maxlrg*2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  memset( h_cnt, 0, sizeof(int)*_maxlrg*2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  uint i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  for( i = 0; i < _maxlrg; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    h_cnt[neighbor_cnt(i)]++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  tty->print_cr("--Histogram of counts--");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  for( i = 0; i < _maxlrg*2; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    if( h_cnt[i] )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      tty->print("%d/%d ",i,h_cnt[i]);
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23528
diff changeset
   260
  tty->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
void PhaseIFG::verify( const PhaseChaitin *pc ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // IFG is square, sorted and no need for Find
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  for( uint i = 0; i < _maxlrg; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    assert(!((*_yanked)[i]) || !neighbor_cnt(i), "Is removed completely" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    IndexSet *set = &_adjs[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    IndexSetIterator elements(set);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    uint idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    uint last = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    while ((idx = elements.next()) != 0) {
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   272
      assert(idx != i, "Must have empty diagonal");
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   273
      assert(pc->_lrg_map.find_const(idx) == idx, "Must not need Find");
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   274
      assert(_adjs[idx].member(i), "IFG not square");
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   275
      assert(!(*_yanked)[idx], "No yanked neighbors");
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   276
      assert(last < idx, "not sorted increasing");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      last = idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    }
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   279
    assert(!lrgs(i)._degree_valid || effective_degree(i) == lrgs(i).degree(), "degree is valid but wrong");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   284
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   285
 * Interfere this register with everything currently live.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   286
 * Check for interference by checking overlap of regmasks.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   287
 * Only interfere if acceptable register masks overlap.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   288
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   289
void PhaseChaitin::interfere_with_live(uint lid, IndexSet* liveout) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   290
  LRG& lrg = lrgs(lid);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   291
  const RegMask& rm = lrg.mask();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  IndexSetIterator elements(liveout);
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   293
  uint interfering_lid = elements.next();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   294
  while (interfering_lid != 0) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   295
    LRG& interfering_lrg = lrgs(interfering_lid);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   296
    if (rm.overlap(interfering_lrg.mask())) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   297
      _ifg->add_edge(lid, interfering_lid);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   298
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   299
    interfering_lid = elements.next();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   300
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
// Actually build the interference graph.  Uses virtual registers only, no
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
// physical register masks.  This allows me to be very aggressive when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
// coalescing copies.  Some of this aggressiveness will have to be undone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
// later, but I'd rather get all the copies I can now (since unremoved copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
// at this point can end up in bad places).  Copies I re-insert later I have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
// more opportunity to insert them in low-frequency locations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
void PhaseChaitin::build_ifg_virtual( ) {
26913
9ad70cd32368 8058968: Compiler time traces should be improved
shade
parents: 24424
diff changeset
   310
  Compile::TracePhase tp("buildIFG_virt", &timers[_t_buildIFGvirtual]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  // For all blocks (in any order) do...
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   313
  for (uint i = 0; i < _cfg.number_of_blocks(); i++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   314
    Block* block = _cfg.get_block(i);
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   315
    IndexSet* liveout = _live->live(block);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    // The IFG is built by a single reverse pass over each basic block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    // Starting with the known live-out set, we remove things that get
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    // defined and add things that become live (essentially executing one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    // pass of a standard LIVE analysis). Just before a Node defines a value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    // (and removes it from the live-ness set) that value is certainly live.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    // The defined value interferes with everything currently live.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    // value is then removed from the live-ness set and it's inputs are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    // added to the live-ness set.
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   325
    for (uint j = block->end_idx() + 1; j > 1; j--) {
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   326
      Node* n = block->get_node(j - 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
      // Get value being defined
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   329
      uint r = _lrg_map.live_range_id(n);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      // Some special values do not allocate
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   332
      if (r) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
        // Remove from live-out set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
        liveout->remove(r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
        // Copies do not define a new value and so do not interfere.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
        // Remove the copies source from the liveout set before interfering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
        uint idx = n->is_Copy();
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   340
        if (idx != 0) {
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   341
          liveout->remove(_lrg_map.live_range_id(n->in(idx)));
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   342
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
        // Interfere with everything live
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   345
        interfere_with_live(r, liveout);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      // Make all inputs live
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   349
      if (!n->is_Phi()) {      // Phi function uses come from prior block
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   350
        for(uint k = 1; k < n->req(); k++) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   351
          liveout->insert(_lrg_map.live_range_id(n->in(k)));
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   352
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      // 2-address instructions always have the defined value live
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      // on entry to the instruction, even though it is being defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      // by the instruction.  We pretend a virtual copy sits just prior
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      // to the instruction and kills the src-def'd register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      // In other words, for 2-address instructions the defined value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      // interferes with all inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      uint idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      if( n->is_Mach() && (idx = n->as_Mach()->two_adr()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
        const MachNode *mach = n->as_Mach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
        // Sometimes my 2-address ADDs are commuted in a bad way.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
        // We generally want the USE-DEF register to refer to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
        // loop-varying quantity, to avoid a copy.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
        uint op = mach->ideal_Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
        // Check that mach->num_opnds() == 3 to ensure instruction is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
        // not subsuming constants, effectively excludes addI_cin_imm
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
        // Can NOT swap for instructions like addI_cin_imm since it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
        // is adding zero to yhi + carry and the second ideal-input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
        // points to the result of adding low-halves.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
        // Checking req() and num_opnds() does NOT distinguish addI_cout from addI_cout_imm
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
        if( (op == Op_AddI && mach->req() == 3 && mach->num_opnds() == 3) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
            n->in(1)->bottom_type()->base() == Type::Int &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
            // See if the ADD is involved in a tight data loop the wrong way
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
            n->in(2)->is_Phi() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
            n->in(2)->in(2) == n ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
          Node *tmp = n->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
          n->set_req( 1, n->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
          n->set_req( 2, tmp );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
        // Defined value interferes with all inputs
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   384
        uint lidx = _lrg_map.live_range_id(n->in(idx));
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   385
        for (uint k = 1; k < n->req(); k++) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   386
          uint kidx = _lrg_map.live_range_id(n->in(k));
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   387
          if (kidx != lidx) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   388
            _ifg->add_edge(r, kidx);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 16618
diff changeset
   389
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    } // End of forall instructions in block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  } // End of forall blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   396
#ifdef ASSERT
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   397
uint PhaseChaitin::count_int_pressure(IndexSet* liveout) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  IndexSetIterator elements(liveout);
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   399
  uint lidx = elements.next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  uint cnt = 0;
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   401
  while (lidx != 0) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   402
    LRG& lrg = lrgs(lidx);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   403
    if (lrg.mask_is_nonempty_and_up() &&
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   404
        !lrg.is_float_or_vector() &&
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   405
        lrg.mask().overlap(*Matcher::idealreg2regmask[Op_RegI])) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   406
      cnt += lrg.reg_pressure();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   407
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   408
    lidx = elements.next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  return cnt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   413
uint PhaseChaitin::count_float_pressure(IndexSet* liveout) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  IndexSetIterator elements(liveout);
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   415
  uint lidx = elements.next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  uint cnt = 0;
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   417
  while (lidx != 0) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   418
    LRG& lrg = lrgs(lidx);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   419
    if (lrg.mask_is_nonempty_and_up() && lrg.is_float_or_vector()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   420
      cnt += lrg.reg_pressure();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   421
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   422
    lidx = elements.next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  return cnt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
}
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   426
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   428
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   429
 * Adjust register pressure down by 1.  Capture last hi-to-low transition,
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   430
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   431
void PhaseChaitin::lower_pressure(Block* b, uint location, LRG& lrg, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   432
  if (lrg.mask_is_nonempty_and_up()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   433
    if (lrg.is_float_or_vector()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   434
      float_pressure.lower(lrg, location);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   435
    } else {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   436
      // Do not count the SP and flag registers
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   437
      const RegMask& r = lrg.mask();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   438
      if (r.overlap(*Matcher::idealreg2regmask[Op_RegI])) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   439
        int_pressure.lower(lrg, location);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      }
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   441
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   442
  }
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   443
  if (_scheduling_info_generated == false) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   444
    assert(int_pressure.current_pressure() == count_int_pressure(liveout), "the int pressure is incorrect");
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   445
    assert(float_pressure.current_pressure() == count_float_pressure(liveout), "the float pressure is incorrect");
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   446
  }
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   447
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   448
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   449
/* Go to the first non-phi index in a block */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   450
static uint first_nonphi_index(Block* b) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   451
  uint i;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   452
  uint end_idx = b->end_idx();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   453
  for (i = 1; i < end_idx; i++) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   454
    Node* n = b->get_node(i);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   455
    if (!n->is_Phi()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   456
      break;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   457
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   458
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   459
  return i;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   460
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   461
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   462
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   463
 * Spills could be inserted before a CreateEx node which should be the first
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   464
 * instruction in a block after Phi nodes. If so, move the CreateEx node up.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   465
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   466
static void move_exception_node_up(Block* b, uint first_inst, uint last_inst) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   467
  for (uint i = first_inst; i < last_inst; i++) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   468
    Node* ex = b->get_node(i);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   469
    if (ex->is_SpillCopy()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   470
      continue;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   471
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   472
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   473
    if (i > first_inst &&
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   474
        ex->is_Mach() && ex->as_Mach()->ideal_Opcode() == Op_CreateEx) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   475
      b->remove_node(i);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   476
      b->insert_node(ex, first_inst);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   477
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   478
    // Stop once a CreateEx or any other node is found
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   479
    break;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   480
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   481
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   482
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   483
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   484
 * When new live ranges are live, we raise the register pressure
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   485
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   486
void PhaseChaitin::raise_pressure(Block* b, LRG& lrg, Pressure& int_pressure, Pressure& float_pressure) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   487
  if (lrg.mask_is_nonempty_and_up()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   488
    if (lrg.is_float_or_vector()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   489
      float_pressure.raise(lrg);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   490
    } else {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   491
      // Do not count the SP and flag registers
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   492
      const RegMask& rm = lrg.mask();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   493
      if (rm.overlap(*Matcher::idealreg2regmask[Op_RegI])) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   494
        int_pressure.raise(lrg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   500
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   501
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   502
 * Computes the initial register pressure of a block, looking at all live
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   503
 * ranges in the liveout. The register pressure is computed for both float
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   504
 * and int/pointer registers.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   505
 * Live ranges in the liveout are presumed live for the whole block.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   506
 * We add the cost for the whole block to the area of the live ranges initially.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   507
 * If a live range gets killed in the block, we'll subtract the unused part of
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   508
 * the block from the area.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   509
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   510
void PhaseChaitin::compute_initial_block_pressure(Block* b, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure, double cost) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   511
  IndexSetIterator elements(liveout);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   512
  uint lid = elements.next();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   513
  while (lid != 0) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   514
    LRG& lrg = lrgs(lid);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   515
    lrg._area += cost;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   516
    raise_pressure(b, lrg, int_pressure, float_pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   517
    lid = elements.next();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   518
  }
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   519
  assert(int_pressure.current_pressure() == count_int_pressure(liveout), "the int pressure is incorrect");
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   520
  assert(float_pressure.current_pressure() == count_float_pressure(liveout), "the float pressure is incorrect");
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   521
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   523
/*
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   524
* Computes the entry register pressure of a block, looking at all live
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   525
* ranges in the livein. The register pressure is computed for both float
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   526
* and int/pointer registers.
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   527
*/
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   528
void PhaseChaitin::compute_entry_block_pressure(Block* b) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   529
  IndexSet* livein = _live->livein(b);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   530
  IndexSetIterator elements(livein);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   531
  uint lid = elements.next();
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   532
  while (lid != 0) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   533
    LRG& lrg = lrgs(lid);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   534
    raise_pressure(b, lrg, _sched_int_pressure, _sched_float_pressure);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   535
    lid = elements.next();
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   536
  }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   537
  // Now check phis for locally defined inputs
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   538
  for (uint j = 0; j < b->number_of_nodes(); j++) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   539
    Node* n = b->get_node(j);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   540
    if (n->is_Phi()) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   541
      for (uint k = 1; k < n->req(); k++) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   542
        Node* phi_in = n->in(k);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   543
        // Because we are talking about phis, raise register pressure once for each
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   544
        // instance of a phi to account for a single value
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   545
        if (_cfg.get_block_for_node(phi_in) == b) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   546
          LRG& lrg = lrgs(phi_in->_idx);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   547
          raise_pressure(b, lrg, _sched_int_pressure, _sched_float_pressure);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   548
          break;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   549
        }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   550
      }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   551
    }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   552
  }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   553
  _sched_int_pressure.set_start_pressure(_sched_int_pressure.current_pressure());
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   554
  _sched_float_pressure.set_start_pressure(_sched_float_pressure.current_pressure());
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   555
}
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   556
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   557
/*
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   558
* Computes the exit register pressure of a block, looking at all live
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   559
* ranges in the liveout. The register pressure is computed for both float
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   560
* and int/pointer registers.
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   561
*/
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   562
void PhaseChaitin::compute_exit_block_pressure(Block* b) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   563
  IndexSet* livein = _live->live(b);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   564
  IndexSetIterator elements(livein);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   565
  _sched_int_pressure.set_current_pressure(0);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   566
  _sched_float_pressure.set_current_pressure(0);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   567
  uint lid = elements.next();
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   568
  while (lid != 0) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   569
    LRG& lrg = lrgs(lid);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   570
    raise_pressure(b, lrg, _sched_int_pressure, _sched_float_pressure);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   571
    lid = elements.next();
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   572
  }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   573
}
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   574
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   575
/*
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   576
 * Remove dead node if it's not used.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   577
 * We only remove projection nodes if the node "defining" the projection is
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   578
 * dead, for example on x86, if we have a dead Add node we remove its
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   579
 * RFLAGS node.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   580
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   581
bool PhaseChaitin::remove_node_if_not_used(Block* b, uint location, Node* n, uint lid, IndexSet* liveout) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   582
  Node* def = n->in(0);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   583
  if (!n->is_Proj() ||
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   584
      (_lrg_map.live_range_id(def) && !liveout->member(_lrg_map.live_range_id(def)))) {
27704
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   585
    if (n->is_MachProj()) {
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   586
      // Don't remove KILL projections if their "defining" nodes have
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   587
      // memory effects (have SCMemProj projection node) -
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   588
      // they are not dead even when their result is not used.
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   589
      // For example, compareAndSwapL (and other CAS) and EncodeISOArray nodes.
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   590
      // The method add_input_to_liveout() keeps such nodes alive (put them on liveout list)
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   591
      // when it sees SCMemProj node in a block. Unfortunately SCMemProj node could be placed
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   592
      // in block in such order that KILL MachProj nodes are processed first.
28643
a665e19ca007 8066312: Add new Node* Node::find_out(int opc) method.
zmajo
parents: 27704
diff changeset
   593
      if (def->has_out_with(Op_SCMemProj)) {
a665e19ca007 8066312: Add new Node* Node::find_out(int opc) method.
zmajo
parents: 27704
diff changeset
   594
        return false;
27704
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   595
      }
88c9f3b507ff 8065618: C2 RA incorrectly removes kill projections
kvn
parents: 26913
diff changeset
   596
    }
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   597
    b->remove_node(location);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   598
    LRG& lrg = lrgs(lid);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   599
    if (lrg._def == n) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   600
      lrg._def = 0;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   601
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   602
    n->disconnect_inputs(NULL, C);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   603
    _cfg.unmap_node_from_block(n);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   604
    n->replace_by(C->top());
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   605
    return true;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   606
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   607
  return false;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   608
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   609
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   610
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   611
 * When encountering a fat projection, we might go from a low to high to low
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   612
 * (since the fat proj only lives at this instruction) going backwards in the
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   613
 * block. If we find a low to high transition, we record it.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   614
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   615
void PhaseChaitin::check_for_high_pressure_transition_at_fatproj(uint& block_reg_pressure, uint location, LRG& lrg, Pressure& pressure, const int op_regtype) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   616
  RegMask mask_tmp = lrg.mask();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   617
  mask_tmp.AND(*Matcher::idealreg2regmask[op_regtype]);
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   618
  pressure.check_pressure_at_fatproj(location, mask_tmp);
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   619
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   621
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   622
 * Insure high score for immediate-use spill copies so they get a color.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   623
 * All single-use MachSpillCopy(s) that immediately precede their
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   624
 * use must color early.  If a longer live range steals their
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   625
 * color, the spill copy will split and may push another spill copy
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   626
 * further away resulting in an infinite spill-split-retry cycle.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   627
 * Assigning a zero area results in a high score() and a good
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   628
 * location in the simplify list.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   629
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   630
void PhaseChaitin::assign_high_score_to_immediate_copies(Block* b, Node* n, LRG& lrg, uint next_inst, uint last_inst) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   631
  if (n->is_SpillCopy() &&
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   632
      lrg.is_singledef() && // A multi defined live range can still split
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   633
      n->outcnt() == 1 &&   // and use must be in this block
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   634
      _cfg.get_block_for_node(n->unique_out()) == b) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   635
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   636
    Node* single_use = n->unique_out();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   637
    assert(b->find_node(single_use) >= next_inst, "Use must be later in block");
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   638
    // Use can be earlier in block if it is a Phi, but then I should be a MultiDef
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   639
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   640
    // Find first non SpillCopy 'm' that follows the current instruction
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   641
    // (current_inst - 1) is index for current instruction 'n'
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   642
    Node* m = n;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   643
    for (uint i = next_inst; i <= last_inst && m->is_SpillCopy(); ++i) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   644
      m = b->get_node(i);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   645
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   646
    if (m == single_use) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   647
      lrg._area = 0.0;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   648
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   649
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   650
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   651
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   652
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   653
 * Copies do not define a new value and so do not interfere.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   654
 * Remove the copies source from the liveout set before interfering.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   655
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   656
void PhaseChaitin::remove_interference_from_copy(Block* b, uint location, uint lid_copy, IndexSet* liveout, double cost, Pressure& int_pressure, Pressure& float_pressure) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   657
  if (liveout->remove(lid_copy)) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   658
    LRG& lrg_copy = lrgs(lid_copy);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   659
    lrg_copy._area -= cost;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   660
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   661
    // Lower register pressure since copy and definition can share the same register
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   662
    lower_pressure(b, location, lrg_copy, liveout, int_pressure, float_pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   663
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   664
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   665
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   666
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   667
 * The defined value must go in a particular register. Remove that register from
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   668
 * all conflicting parties and avoid the interference.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   669
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   670
void PhaseChaitin::remove_bound_register_from_interfering_live_ranges(LRG& lrg, IndexSet* liveout, uint& must_spill) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   671
  // Check for common case
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   672
  const RegMask& rm = lrg.mask();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   673
  int r_size = lrg.num_regs();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   674
  // Smear odd bits
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   675
  IndexSetIterator elements(liveout);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   676
  uint l = elements.next();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   677
  while (l != 0) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   678
    LRG& interfering_lrg = lrgs(l);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   679
    // If 'l' must spill already, do not further hack his bits.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   680
    // He'll get some interferences and be forced to spill later.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   681
    if (interfering_lrg._must_spill) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   682
      l = elements.next();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   683
      continue;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   684
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   685
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   686
    // Remove bound register(s) from 'l's choices
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   687
    RegMask old = interfering_lrg.mask();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   688
    uint old_size = interfering_lrg.mask_size();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   689
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   690
    // Remove the bits from LRG 'rm' from LRG 'l' so 'l' no
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   691
    // longer interferes with 'rm'.  If 'l' requires aligned
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   692
    // adjacent pairs, subtract out bit pairs.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   693
    assert(!interfering_lrg._is_vector || !interfering_lrg._fat_proj, "sanity");
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   694
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   695
    if (interfering_lrg.num_regs() > 1 && !interfering_lrg._fat_proj) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   696
      RegMask r2mask = rm;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   697
      // Leave only aligned set of bits.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   698
      r2mask.smear_to_sets(interfering_lrg.num_regs());
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   699
      // It includes vector case.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   700
      interfering_lrg.SUBTRACT(r2mask);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   701
      interfering_lrg.compute_set_mask_size();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   702
    } else if (r_size != 1) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   703
      // fat proj
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   704
      interfering_lrg.SUBTRACT(rm);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   705
      interfering_lrg.compute_set_mask_size();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   706
    } else {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   707
      // Common case: size 1 bound removal
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   708
      OptoReg::Name r_reg = rm.find_first_elem();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   709
      if (interfering_lrg.mask().Member(r_reg)) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   710
        interfering_lrg.Remove(r_reg);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   711
        interfering_lrg.set_mask_size(interfering_lrg.mask().is_AllStack() ? LRG::AllStack_size : old_size - 1);
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   712
      }
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   713
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   715
    // If 'l' goes completely dry, it must spill.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   716
    if (interfering_lrg.not_free()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   717
      // Give 'l' some kind of reasonable mask, so it picks up
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   718
      // interferences (and will spill later).
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   719
      interfering_lrg.set_mask(old);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   720
      interfering_lrg.set_mask_size(old_size);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   721
      must_spill++;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   722
      interfering_lrg._must_spill = 1;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   723
      interfering_lrg.set_reg(OptoReg::Name(LRG::SPILL_REG));
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   724
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   725
    l = elements.next();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   726
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   727
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   728
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   729
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   730
 * Start loop at 1 (skip control edge) for most Nodes. SCMemProj's might be the
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   731
 * sole use of a StoreLConditional. While StoreLConditionals set memory (the
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   732
 * SCMemProj use) they also def flags; if that flag def is unused the allocator
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   733
 * sees a flag-setting instruction with no use of the flags and assumes it's
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   734
 * dead.  This keeps the (useless) flag-setting behavior alive while also
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   735
 * keeping the (useful) memory update effect.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   736
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   737
void PhaseChaitin::add_input_to_liveout(Block* b, Node* n, IndexSet* liveout, double cost, Pressure& int_pressure, Pressure& float_pressure) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   738
  JVMState* jvms = n->jvms();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   739
  uint debug_start = jvms ? jvms->debug_start() : 999999;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   740
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   741
  for (uint k = ((n->Opcode() == Op_SCMemProj) ? 0:1); k < n->req(); k++) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   742
    Node* def = n->in(k);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   743
    uint lid = _lrg_map.live_range_id(def);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   744
    if (!lid) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   745
      continue;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   746
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   747
    LRG& lrg = lrgs(lid);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   748
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   749
    // No use-side cost for spilling debug info
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   750
    if (k < debug_start) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   751
      // A USE costs twice block frequency (once for the Load, once
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   752
      // for a Load-delay).  Rematerialized uses only cost once.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   753
      lrg._cost += (def->rematerialize() ? b->_freq : (b->_freq * 2));
2030
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 1412
diff changeset
   754
    }
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 1412
diff changeset
   755
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   756
    if (liveout->insert(lid)) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   757
      // Newly live things assumed live from here to top of block
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   758
      lrg._area += cost;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   759
      raise_pressure(b, lrg, int_pressure, float_pressure);
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   760
      assert(int_pressure.current_pressure() == count_int_pressure(liveout), "the int pressure is incorrect");
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   761
      assert(float_pressure.current_pressure() == count_float_pressure(liveout), "the float pressure is incorrect");
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   762
    }
22915
231c85af5482 8033260: assert(lrg._area >= 0.0) failed: negative spill area
adlertz
parents: 22912
diff changeset
   763
    assert(lrg._area >= 0.0, "negative spill area" );
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   764
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   765
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   766
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   767
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   768
 * If we run off the top of the block with high pressure just record that the
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   769
 * whole block is high pressure. (Even though we might have a transition
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   770
 * later down in the block)
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   771
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   772
void PhaseChaitin::check_for_high_pressure_block(Pressure& pressure) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   773
  // current pressure now means the pressure before the first instruction in the block
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   774
  // (since we have stepped through all instructions backwards)
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   775
  if (pressure.current_pressure() > pressure.high_pressure_limit()) {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   776
    pressure.set_high_pressure_index_to_block_start();
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   777
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   778
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   779
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   780
/*
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   781
 * Compute high pressure indice; avoid landing in the middle of projnodes
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   782
 * and set the high pressure index for the block
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   783
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   784
void PhaseChaitin::adjust_high_pressure_index(Block* b, uint& block_hrp_index, Pressure& pressure) {
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   785
  uint i = pressure.high_pressure_index();
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   786
  if (i < b->number_of_nodes() && i < b->end_idx() + 1) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   787
    Node* cur = b->get_node(i);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   788
    while (cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   789
      cur = b->get_node(--i);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   790
    }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   791
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   792
  block_hrp_index = i;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   793
}
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   794
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   795
void PhaseChaitin::print_pressure_info(Pressure& pressure, const char *str) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   796
  if (str != NULL) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   797
    tty->print_cr("#  *** %s ***", str);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   798
  }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   799
  tty->print_cr("#     start pressure is = %d", pressure.start_pressure());
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   800
  tty->print_cr("#     max pressure is = %d", pressure.final_pressure());
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   801
  tty->print_cr("#     end pressure is = %d", pressure.current_pressure());
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   802
  tty->print_cr("#");
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   803
}
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 28643
diff changeset
   804
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   805
/* Build an interference graph:
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   806
 *   That is, if 2 live ranges are simultaneously alive but in their acceptable
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   807
 *   register sets do not overlap, then they do not interfere. The IFG is built
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   808
 *   by a single reverse pass over each basic block. Starting with the known
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   809
 *   live-out set, we remove things that get defined and add things that become
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   810
 *   live (essentially executing one pass of a standard LIVE analysis). Just
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   811
 *   before a Node defines a value (and removes it from the live-ness set) that
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   812
 *   value is certainly live. The defined value interferes with everything
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   813
 *   currently live. The value is then removed from the live-ness set and it's
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   814
 *   inputs are added to the live-ness set.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   815
 * Compute register pressure for each block:
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   816
 *   We store the biggest register pressure for each block and also the first
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   817
 *   low to high register pressure transition within the block (if any).
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   818
 */
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   819
uint PhaseChaitin::build_ifg_physical( ResourceArea *a ) {
26913
9ad70cd32368 8058968: Compiler time traces should be improved
shade
parents: 24424
diff changeset
   820
  Compile::TracePhase tp("buildIFG", &timers[_t_buildIFGphysical]);
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   821
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   822
  uint must_spill = 0;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   823
  for (uint i = 0; i < _cfg.number_of_blocks(); i++) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   824
    Block* block = _cfg.get_block(i);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   825
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   826
    // Clone (rather than smash in place) the liveout info, so it is alive
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   827
    // for the "collect_gc_info" phase later.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   828
    IndexSet liveout(_live->live(block));
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   829
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   830
    uint first_inst = first_nonphi_index(block);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   831
    uint last_inst = block->end_idx();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   832
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   833
    move_exception_node_up(block, first_inst, last_inst);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   834
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   835
    Pressure int_pressure(last_inst + 1, INTPRESSURE);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   836
    Pressure float_pressure(last_inst + 1, FLOATPRESSURE);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   837
    block->_reg_pressure = 0;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   838
    block->_freg_pressure = 0;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   839
2030
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 1412
diff changeset
   840
    int inst_count = last_inst - first_inst;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   841
    double cost = (inst_count <= 0) ? 0.0 : block->_freq * double(inst_count);
22915
231c85af5482 8033260: assert(lrg._area >= 0.0) failed: negative spill area
adlertz
parents: 22912
diff changeset
   842
    assert(cost >= 0.0, "negative spill cost" );
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   843
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   844
    compute_initial_block_pressure(block, &liveout, int_pressure, float_pressure, cost);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   846
    for (uint location = last_inst; location > 0; location--) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   847
      Node* n = block->get_node(location);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   848
      uint lid = _lrg_map.live_range_id(n);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   850
      if(lid) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   851
        LRG& lrg = lrgs(lid);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
        // A DEF normally costs block frequency; rematerialized values are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
        // removed from the DEF sight, so LOWER costs here.
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   855
        lrg._cost += n->rematerialize() ? 0 : block->_freq;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   857
        if (!liveout.member(lid) && n->Opcode() != Op_SafePoint) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   858
          if (remove_node_if_not_used(block, location, n, lid, &liveout)) {
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   859
            float_pressure.lower_high_pressure_index();
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   860
            int_pressure.lower_high_pressure_index();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
            continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
          }
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   863
          if (lrg._fat_proj) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   864
            check_for_high_pressure_transition_at_fatproj(block->_reg_pressure, location, lrg, int_pressure, Op_RegI);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   865
            check_for_high_pressure_transition_at_fatproj(block->_freg_pressure, location, lrg, float_pressure, Op_RegD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
          }
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   867
        } else {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   868
          // A live range ends at its definition, remove the remaining area.
22915
231c85af5482 8033260: assert(lrg._area >= 0.0) failed: negative spill area
adlertz
parents: 22912
diff changeset
   869
          // If the cost is +Inf (which might happen in extreme cases), the lrg area will also be +Inf,
231c85af5482 8033260: assert(lrg._area >= 0.0) failed: negative spill area
adlertz
parents: 22912
diff changeset
   870
          // and +Inf - +Inf = NaN. So let's not do that subtraction.
231c85af5482 8033260: assert(lrg._area >= 0.0) failed: negative spill area
adlertz
parents: 22912
diff changeset
   871
          if (g_isfinite(cost)) {
231c85af5482 8033260: assert(lrg._area >= 0.0) failed: negative spill area
adlertz
parents: 22912
diff changeset
   872
            lrg._area -= cost;
231c85af5482 8033260: assert(lrg._area >= 0.0) failed: negative spill area
adlertz
parents: 22912
diff changeset
   873
          }
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   874
          assert(lrg._area >= 0.0, "negative spill area" );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   876
          assign_high_score_to_immediate_copies(block, n, lrg, location + 1, last_inst);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   878
          if (liveout.remove(lid)) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   879
            lower_pressure(block, location, lrg, &liveout, int_pressure, float_pressure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
          }
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   881
          uint copy_idx = n->is_Copy();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   882
          if (copy_idx) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   883
            uint lid_copy = _lrg_map.live_range_id(n->in(copy_idx));
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   884
            remove_interference_from_copy(block, location, lid_copy, &liveout, cost, int_pressure, float_pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   885
          }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   886
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   888
        // Since rematerializable DEFs are not bound but the live range is,
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   889
        // some uses must be bound. If we spill live range 'r', it can
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   890
        // rematerialize at each use site according to its bindings.
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   891
        if (lrg.is_bound() && !n->rematerialize() && lrg.mask().is_NotEmpty()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   892
          remove_bound_register_from_interfering_live_ranges(lrg, &liveout, must_spill);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   893
        }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   894
        interfere_with_live(lid, &liveout);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   895
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
1401
e5fdc8521d1f 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 1057
diff changeset
   897
      // Area remaining in the block
e5fdc8521d1f 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 1057
diff changeset
   898
      inst_count--;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   899
      cost = (inst_count <= 0) ? 0.0 : block->_freq * double(inst_count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   901
      if (!n->is_Phi()) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   902
        add_input_to_liveout(block, n, &liveout, cost, int_pressure, float_pressure);
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   903
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   906
    check_for_high_pressure_block(int_pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   907
    check_for_high_pressure_block(float_pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   908
    adjust_high_pressure_index(block, block->_ihrp_index, int_pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   909
    adjust_high_pressure_index(block, block->_fhrp_index, float_pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   910
    // set the final_pressure as the register pressure for the block
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   911
    block->_reg_pressure = int_pressure.final_pressure();
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   912
    block->_freg_pressure = float_pressure.final_pressure();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    // Gather Register Pressure Statistics
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   916
    if (PrintOptoStatistics) {
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   917
      if (block->_reg_pressure > int_pressure.high_pressure_limit() || block->_freg_pressure > float_pressure.high_pressure_limit()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
        _high_pressure++;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   919
      } else {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
        _low_pressure++;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   921
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
#endif
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   924
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  return must_spill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
}