src/hotspot/share/opto/chaitin.hpp
author phedlin
Wed, 23 Oct 2019 12:51:53 +0200
changeset 58816 77148b8bb7a1
parent 54021 6347ffe2c3c7
permissions -rw-r--r--
8231565: More node budget asserts in fuzzed tests. Reviewed-by: neliasso, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51333
diff changeset
     2
 * Copyright (c) 1997, 2019, 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: 3678
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3678
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: 3678
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51333
diff changeset
    25
#ifndef SHARE_OPTO_CHAITIN_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51333
diff changeset
    26
#define SHARE_OPTO_CHAITIN_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "code/vmreg.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/connode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/live.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "opto/matcher.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "opto/phase.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "opto/regalloc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "opto/regmask.hpp"
22914
0712db174bbb 8032656: Tag the MachSpillCopies with purpose information
adlertz
parents: 22912
diff changeset
    36
#include "opto/machnode.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
class Matcher;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class PhaseCFG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
class PhaseLive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
class PhaseRegAlloc;
53468
d927fc999582 8217716: Remove dead code in PhaseChaitin
redestad
parents: 53244
diff changeset
    42
class PhaseChaitin;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
#define OPTO_DEBUG_SPLIT_FREQ  BLOCK_FREQUENCY(0.001)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
#define OPTO_LRG_HIGH_FREQ     BLOCK_FREQUENCY(0.25)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//------------------------------LRG--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Live-RanGe structure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
class LRG : public ResourceObj {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10542
diff changeset
    50
  friend class VMStructs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
public:
20704
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    52
  static const uint AllStack_size = 0xFFFFF; // This mask size is used to tell that the mask of this LRG supports stack positions
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  enum { SPILL_REG=29999 };     // Register number of a spilled LRG
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  double _cost;                 // 2 for loads/1 for stores times block freq
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  double _area;                 // Sum of all simultaneously live values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  double score() const;         // Compute score from cost and area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  double _maxfreq;              // Maximum frequency of any def or use
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  Node *_def;                   // Check for multi-def live ranges
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  GrowableArray<Node*>* _defs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  uint _risk_bias;              // Index of LRG which we want to avoid color
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  uint _copy_bias;              // Index of LRG which we want to share color
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  uint _next;                   // Index of next LRG in linked list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  uint _prev;                   // Index of prev LRG in linked list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  uint _reg;                    // Chosen register; undefined if mask is plural
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Return chosen register for this LRG.  Error if the LRG is not bound to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // a single register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  OptoReg::Name reg() const { return OptoReg::Name(_reg); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  void set_reg( OptoReg::Name r ) { _reg = r; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  uint _eff_degree;             // Effective degree: Sum of neighbors _num_regs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
public:
20704
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    81
  int degree() const { assert( _degree_valid , "" ); return _eff_degree; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Degree starts not valid and any change to the IFG neighbor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // set makes it not valid.
20704
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    84
  void set_degree( uint degree ) {
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    85
    _eff_degree = degree;
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    86
    debug_only(_degree_valid = 1;)
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    87
    assert(!_mask.is_AllStack() || (_mask.is_AllStack() && lo_degree()), "_eff_degree can't be bigger than AllStack_size - _num_regs if the mask supports stack registers");
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    88
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Made a change that hammered degree
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  void invalid_degree() { debug_only(_degree_valid=0;) }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Incrementally modify degree.  If it was correct, it should remain correct
20704
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    92
  void inc_degree( uint mod ) {
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    93
    _eff_degree += mod;
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    94
    assert(!_mask.is_AllStack() || (_mask.is_AllStack() && lo_degree()), "_eff_degree can't be bigger than AllStack_size - _num_regs if the mask supports stack registers");
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
    95
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Compute the degree between 2 live ranges
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  int compute_degree( LRG &l ) const;
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
    98
  bool mask_is_nonempty_and_up() const {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
    99
    return mask().is_UP() && mask_size();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   100
  }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   101
  bool is_float_or_vector() const {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   102
    return _is_float || _is_vector;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   103
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  RegMask _mask;                // Allowed registers for this LRG
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  uint _mask_size;              // cache of _mask.Size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
public:
20704
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
   109
  int compute_mask_size() const { return _mask.is_AllStack() ? AllStack_size : _mask.Size(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  void set_mask_size( int size ) {
20704
b689a120e974 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 20007
diff changeset
   111
    assert((size == (int)AllStack_size) || (size == (int)_mask.Size()), "");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    _mask_size = size;
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   113
#ifdef ASSERT
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   114
    _msize_valid=1;
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   115
    if (_is_vector) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   116
      assert(!_fat_proj, "sanity");
54021
6347ffe2c3c7 8220159: Optimize various RegMask operations by introducing watermarks
redestad
parents: 53468
diff changeset
   117
      assert(_mask.is_aligned_sets(_num_regs), "mask is not aligned, adjacent sets");
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   118
    } else if (_num_regs == 2 && !_fat_proj) {
54021
6347ffe2c3c7 8220159: Optimize various RegMask operations by introducing watermarks
redestad
parents: 53468
diff changeset
   119
      assert(_mask.is_aligned_pairs(), "mask is not aligned, adjacent pairs");
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   120
    }
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   121
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  void compute_set_mask_size() { set_mask_size(compute_mask_size()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  int mask_size() const { assert( _msize_valid, "mask size not valid" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
                          return _mask_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Get the last mask size computed, even if it does not match the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // count of bits in the current mask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  int get_invalid_mask_size() const { return _mask_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  const RegMask &mask() const { return _mask; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  void set_mask( const RegMask &rm ) { _mask = rm; debug_only(_msize_valid=0;)}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  void AND( const RegMask &rm ) { _mask.AND(rm); debug_only(_msize_valid=0;)}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  void SUBTRACT( const RegMask &rm ) { _mask.SUBTRACT(rm); debug_only(_msize_valid=0;)}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void Clear()   { _mask.Clear()  ; debug_only(_msize_valid=1); _mask_size = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  void Set_All() { _mask.Set_All(); debug_only(_msize_valid=1); _mask_size = RegMask::CHUNK_SIZE; }
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   135
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  void Insert( OptoReg::Name reg ) { _mask.Insert(reg);  debug_only(_msize_valid=0;) }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  void Remove( OptoReg::Name reg ) { _mask.Remove(reg);  debug_only(_msize_valid=0;) }
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   138
  void clear_to_sets()  { _mask.clear_to_sets(_num_regs); debug_only(_msize_valid=0;) }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // Number of registers this live range uses when it colors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
private:
30624
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 28648
diff changeset
   142
  uint16_t _num_regs;           // 2 for Longs and Doubles, 1 for all else
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
                                // except _num_regs is kill count for fat_proj
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  int num_regs() const { return _num_regs; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  void set_num_regs( int reg ) { assert( _num_regs == reg || !_num_regs, "" ); _num_regs = reg; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // Number of physical registers this live range uses when it colors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Architecture and register-set dependent
30624
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 28648
diff changeset
   151
  uint16_t _reg_pressure;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  void set_reg_pressure(int i)  { _reg_pressure = i; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  int      reg_pressure() const { return _reg_pressure; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // How much 'wiggle room' does this live range have?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // How many color choices can it make (scaled by _num_regs)?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  int degrees_of_freedom() const { return mask_size() - _num_regs; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Bound LRGs have ZERO degrees of freedom.  We also count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // must_spill as bound.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  bool is_bound  () const { return _is_bound; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // Negative degrees-of-freedom; even with no neighbors this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // live range must spill.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  bool not_free() const { return degrees_of_freedom() <  0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // Is this live range of "low-degree"?  Trivially colorable?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  bool lo_degree () const { return degree() <= degrees_of_freedom(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Is this live range just barely "low-degree"?  Trivially colorable?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  bool just_lo_degree () const { return degree() == degrees_of_freedom(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  uint   _is_oop:1,             // Live-range holds an oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
         _is_float:1,           // True if in float registers
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   172
         _is_vector:1,          // True if in vector registers
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
         _was_spilled1:1,       // True if prior spilling on def
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
         _was_spilled2:1,       // True if twice prior spilling on def
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
         _is_bound:1,           // live range starts life with no
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                                // degrees of freedom.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
         _direct_conflict:1,    // True if def and use registers in conflict
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
         _must_spill:1,         // live range has lost all degrees of freedom
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    // If _fat_proj is set, live range does NOT require aligned, adjacent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // registers and has NO interferences.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    // If _fat_proj is clear, live range requires num_regs() to be a power of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    // 2, and it requires registers to form an aligned, adjacent set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
         _fat_proj:1,           //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
         _was_lo:1,             // Was lo-degree prior to coalesce
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
         _msize_valid:1,        // _mask_size cache valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
         _degree_valid:1,       // _degree cache valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
         _has_copy:1,           // Adjacent to some copy instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
         _at_risk:1;            // Simplify says this guy is at risk to spill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // Alive if non-zero, dead if zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  bool alive() const { return _def != NULL; }
1057
44220ef9a775 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 670
diff changeset
   193
  bool is_multidef() const { return _def == NodeSentinel; }
44220ef9a775 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 670
diff changeset
   194
  bool is_singledef() const { return _def != NodeSentinel; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  void dump( ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
//------------------------------IFG--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
//                         InterFerence Graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
// An undirected graph implementation.  Created with a fixed number of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
// vertices.  Edges can be added & tested.  Vertices can be removed, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// added back later with all edges intact.  Can add edges between one vertex
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// and a list of other vertices.  Can union vertices (and their edges)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// together.  The IFG needs to be really really fast, and also fairly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// abstract!  It needs abstraction so I can fiddle with the implementation to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// get even more speed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
class PhaseIFG : public Phase {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10542
diff changeset
   211
  friend class VMStructs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // Current implementation: a triangular adjacency list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // Array of adjacency-lists, indexed by live-range number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  IndexSet *_adjs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Assertion bit for proper use of Squaring
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  bool _is_square;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // Live range structure goes here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  LRG *_lrgs;                   // Array of LRG structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // Largest live-range number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  uint _maxlrg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  Arena *_arena;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // Keep track of inserted and deleted Nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  VectorSet *_yanked;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  PhaseIFG( Arena *arena );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  void init( uint maxlrg );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  // Add edge between a and b.  Returns true if actually addded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  int add_edge( uint a, uint b );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // Test for edge existance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  int test_edge( uint a, uint b ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  // Square-up matrix for faster Union
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  void SquareUp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // Return number of LRG neighbors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  uint neighbor_cnt( uint a ) const { return _adjs[a].count(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  // Union edges of b into a on Squared-up matrix
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  void Union( uint a, uint b );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // Test for edge in Squared-up matrix
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  int test_edge_sq( uint a, uint b ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // Yank a Node and all connected edges from the IFG.  Be prepared to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // re-insert the yanked Node in reverse order of yanking.  Return a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // list of neighbors (edges) yanked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  IndexSet *remove_node( uint a );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  // Reinsert a yanked Node
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  void re_insert( uint a );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // Return set of neighbors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  IndexSet *neighbors( uint a ) const { return &_adjs[a]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  // Dump the IFG
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  void dump() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  void stats() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  void verify( const PhaseChaitin * ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  //--------------- Live Range Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  LRG &lrgs(uint idx) const { assert(idx < _maxlrg, "oob"); return _lrgs[idx]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  // Compute and set effective degree.  Might be folded into SquareUp().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  void Compute_Effective_Degree();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  // Compute effective degree as the sum of neighbors' _sizes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  int effective_degree( uint lidx ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   276
// The LiveRangeMap class is responsible for storing node to live range id mapping.
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   277
// Each node is mapped to a live range id (a virtual register). Nodes that are
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   278
// not considered for register allocation are given live range id 0.
49373
47b5652f2928 8199283: Remove ValueObj class for allocation subclassing for compiler code
coleenp
parents: 47216
diff changeset
   279
class LiveRangeMap {
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   280
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   281
private:
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   282
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   283
  uint _max_lrg_id;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   284
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   285
  // Union-find map.  Declared as a short for speed.
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   286
  // Indexed by live-range number, it returns the compacted live-range number
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   287
  LRG_List _uf_map;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   288
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   289
  // Map from Nodes to live ranges
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   290
  LRG_List _names;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   291
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   292
  // Straight out of Tarjan's union-find algorithm
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   293
  uint find_compress(const Node *node) {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   294
    uint lrg_id = find_compress(_names.at(node->_idx));
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   295
    _names.at_put(node->_idx, lrg_id);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   296
    return lrg_id;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   297
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   298
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   299
  uint find_compress(uint lrg);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   300
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   301
public:
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   302
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   303
  const LRG_List& names() {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   304
    return _names;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   305
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   306
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   307
  uint max_lrg_id() const {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   308
    return _max_lrg_id;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   309
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   310
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   311
  void set_max_lrg_id(uint max_lrg_id) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   312
    _max_lrg_id = max_lrg_id;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   313
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   314
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   315
  uint size() const {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   316
    return _names.length();
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   317
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   318
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   319
  uint live_range_id(uint idx) const {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   320
    return _names.at(idx);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   321
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   322
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   323
  uint live_range_id(const Node *node) const {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   324
    return _names.at(node->_idx);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   325
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   326
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   327
  uint uf_live_range_id(uint lrg_id) const {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   328
    return _uf_map.at(lrg_id);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   329
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   331
  void map(uint idx, uint lrg_id) {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   332
    _names.at_put(idx, lrg_id);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   333
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   334
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   335
  void uf_map(uint dst_lrg_id, uint src_lrg_id) {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   336
    _uf_map.at_put(dst_lrg_id, src_lrg_id);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   337
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   338
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   339
  void extend(uint idx, uint lrg_id) {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   340
    _names.at_put_grow(idx, lrg_id);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   341
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   342
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   343
  void uf_extend(uint dst_lrg_id, uint src_lrg_id) {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   344
    _uf_map.at_put_grow(dst_lrg_id, src_lrg_id);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   345
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   346
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   347
  LiveRangeMap(Arena* arena, uint unique)
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 49373
diff changeset
   348
  :  _max_lrg_id(0)
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   349
  , _uf_map(arena, unique, unique, 0)
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 49373
diff changeset
   350
  , _names(arena, unique, unique, 0) {}
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   351
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   352
  uint find_id( const Node *n ) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   353
    uint retval = live_range_id(n);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   354
    assert(retval == find(n),"Invalid node to lidx mapping");
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   355
    return retval;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   356
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   357
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   358
  // Reset the Union-Find map to identity
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   359
  void reset_uf_map(uint max_lrg_id);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   360
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   361
  // Make all Nodes map directly to their final live range; no need for
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   362
  // the Union-Find mapping after this call.
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   363
  void compress_uf_map_for_nodes();
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   364
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   365
  uint find(uint lidx) {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   366
    uint uf_lidx = _uf_map.at(lidx);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   367
    return (uf_lidx == lidx) ? uf_lidx : find_compress(lidx);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   368
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   369
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   370
  // Convert a Node into a Live Range Index - a lidx
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   371
  uint find(const Node *node) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   372
    uint lidx = live_range_id(node);
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   373
    uint uf_lidx = _uf_map.at(lidx);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   374
    return (uf_lidx == lidx) ? uf_lidx : find_compress(node);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   375
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   376
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   377
  // Like Find above, but no path compress, so bad asymptotic behavior
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   378
  uint find_const(uint lrg) const;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   379
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   380
  // Like Find above, but no path compress, so bad asymptotic behavior
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   381
  uint find_const(const Node *node) const {
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   382
    if(node->_idx >= (uint)_names.length()) {
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   383
      return 0; // not mapped, usual for debug dump
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   384
    }
20007
b67e71448544 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 19334
diff changeset
   385
    return find_const(_names.at(node->_idx));
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   386
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   387
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
//------------------------------Chaitin----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
// Briggs-Chaitin style allocation, mostly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
class PhaseChaitin : public PhaseRegAlloc {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10542
diff changeset
   392
  friend class VMStructs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  int _trip_cnt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  int _alternate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  PhaseLive *_live;             // Liveness, used in the interference graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  PhaseIFG *_ifg;               // Interference graph (for original chunk)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  VectorSet _spilled_once;      // Nodes that have been spilled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  VectorSet _spilled_twice;     // Nodes that have been spilled twice
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // Combine the Live Range Indices for these 2 Nodes into a single live
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  // range.  Future requests for any Node in either live range will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  // return the live range index for the combined live range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  void Union( const Node *src, const Node *dst );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  void new_lrg( const Node *x, uint lrg );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // Compact live ranges, removing unused ones.  Return new maxlrg.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  void compact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  uint _lo_degree;              // Head of lo-degree LRGs list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  uint _lo_stk_degree;          // Head of lo-stk-degree LRGs list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  uint _hi_degree;              // Head of hi-degree LRGs list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  uint _simplified;             // Linked list head of simplified LRGs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // Helper functions for Split()
22914
0712db174bbb 8032656: Tag the MachSpillCopies with purpose information
adlertz
parents: 22912
diff changeset
   418
  uint split_DEF(Node *def, Block *b, int loc, uint max, Node **Reachblock, Node **debug_defs, GrowableArray<uint> splits, int slidx );
0712db174bbb 8032656: Tag the MachSpillCopies with purpose information
adlertz
parents: 22912
diff changeset
   419
  uint split_USE(MachSpillCopyNode::SpillType spill_type, Node *def, Block *b, Node *use, uint useidx, uint max, bool def_down, bool cisc_sp, GrowableArray<uint> splits, int slidx );
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   420
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   421
  //------------------------------clone_projs------------------------------------
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   422
  // After cloning some rematerialized instruction, clone any MachProj's that
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   423
  // follow it.  Example: Intel zero is XOR, kills flags.  Sparc FP constants
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   424
  // use G3 as an address temp.
19334
3aa9ca404965 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 17013
diff changeset
   425
  int clone_projs(Block* b, uint idx, Node* orig, Node* copy, uint& max_lrg_id);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   426
19334
3aa9ca404965 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 17013
diff changeset
   427
  int clone_projs(Block* b, uint idx, Node* orig, Node* copy, LiveRangeMap& lrg_map) {
3aa9ca404965 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 17013
diff changeset
   428
    uint max_lrg_id = lrg_map.max_lrg_id();
3aa9ca404965 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 17013
diff changeset
   429
    int found_projs = clone_projs(b, idx, orig, copy, max_lrg_id);
3aa9ca404965 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 17013
diff changeset
   430
    if (found_projs > 0) {
3aa9ca404965 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 17013
diff changeset
   431
      // max_lrg_id is updated during call above
3aa9ca404965 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 17013
diff changeset
   432
      lrg_map.set_max_lrg_id(max_lrg_id);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   433
    }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   434
    return found_projs;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   435
  }
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   436
1057
44220ef9a775 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 670
diff changeset
   437
  Node *split_Rematerialize(Node *def, Block *b, uint insidx, uint &maxlrg, GrowableArray<uint> splits,
44220ef9a775 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 670
diff changeset
   438
                            int slidx, uint *lrg2reach, Node **Reachblock, bool walkThru);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  // True if lidx is used before any real register is def'd in the block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  bool prompt_use( Block *b, uint lidx );
22914
0712db174bbb 8032656: Tag the MachSpillCopies with purpose information
adlertz
parents: 22912
diff changeset
   441
  Node *get_spillcopy_wide(MachSpillCopyNode::SpillType spill_type, Node *def, Node *use, uint uidx );
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 2030
diff changeset
   442
  // Insert the spill at chosen location.  Skip over any intervening Proj's or
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  // Phis.  Skip over a CatchNode and projs, inserting in the fall-through block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  // instead.  Update high-pressure indices.  Create a new live range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  void insert_proj( Block *b, uint i, Node *spill, uint maxlrg );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  bool is_high_pressure( Block *b, LRG *lrg, uint insidx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  uint _oldphi;                 // Node index which separates pre-allocation nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  Block **_blks;                // Array of blocks sorted by frequency for coalescing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
2340
cb47f8209cd8 6810845: Performance regression in mpegaudio on x64
kvn
parents: 2154
diff changeset
   453
  float _high_frequency_lrg;    // Frequency at which LRG will be spilled for debug info
cb47f8209cd8 6810845: Performance regression in mpegaudio on x64
kvn
parents: 2154
diff changeset
   454
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  bool _trace_spilling;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
public:
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   460
  PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher, bool track_liveout_pressure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  ~PhaseChaitin() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 15944
diff changeset
   463
  LiveRangeMap _lrg_map;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   465
  LRG &lrgs(uint idx) const { return _ifg->lrgs(idx); }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   466
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  // Do all the real work of allocate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  void Register_Allocate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
2340
cb47f8209cd8 6810845: Performance regression in mpegaudio on x64
kvn
parents: 2154
diff changeset
   470
  float high_frequency_lrg() const { return _high_frequency_lrg; }
cb47f8209cd8 6810845: Performance regression in mpegaudio on x64
kvn
parents: 2154
diff changeset
   471
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   472
  // Used when scheduling info generated, not in general register allocation
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   473
  bool _scheduling_info_generated;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   474
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   475
  void set_ifg(PhaseIFG &ifg) { _ifg = &ifg;  }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   476
  void set_live(PhaseLive &live) { _live = &live; }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   477
  PhaseLive* get_live() { return _live; }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   478
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   479
  // Populate the live range maps with ssa info for scheduling
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   480
  void mark_ssa();
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   481
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  bool trace_spilling() const { return _trace_spilling; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  // De-SSA the world.  Assign registers to Nodes.  Use the same register for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  // all inputs to a PhiNode, effectively coalescing live ranges.  Insert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  // copies as needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  void de_ssa();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  // Add edge between reg and everything in the vector.
53468
d927fc999582 8217716: Remove dead code in PhaseChaitin
redestad
parents: 53244
diff changeset
   493
  // Use the RegMask information to trim the set of interferences.  Return the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  // count of edges added.
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   495
  void interfere_with_live(uint lid, IndexSet* liveout);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   496
#ifdef ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  // Count register pressure for asserts
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   498
  uint count_int_pressure(IndexSet* liveout);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   499
  uint count_float_pressure(IndexSet* liveout);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   500
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  // Build the interference graph using virtual registers only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  // Used for aggressive coalescing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  void build_ifg_virtual( );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   506
  // used when computing the register pressure for each block in the CFG. This
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   507
  // is done during IFG creation.
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   508
  class Pressure {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   509
      // keeps track of the register pressure at the current
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   510
      // instruction (used when stepping backwards in the block)
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   511
      uint _current_pressure;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   512
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   513
      // keeps track of the instruction index of the first low to high register pressure
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   514
      // transition (starting from the top) in the block
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   515
      // if high_pressure_index == 0 then the whole block is high pressure
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   516
      // if high_pressure_index = b.end_idx() + 1 then the whole block is low pressure
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   517
      uint _high_pressure_index;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   518
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   519
      // stores the highest pressure we find
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   520
      uint _final_pressure;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   521
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   522
      // number of live ranges that constitute high register pressure
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   523
      uint _high_pressure_limit;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   524
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   525
      // initial pressure observed
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   526
      uint _start_pressure;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   527
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   528
    public:
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   529
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   530
      // lower the register pressure and look for a low to high pressure
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   531
      // transition
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   532
      void lower(LRG& lrg, uint& location) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   533
        _current_pressure -= lrg.reg_pressure();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   534
        if (_current_pressure == _high_pressure_limit) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   535
          _high_pressure_index = location;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   536
        }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   537
      }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   538
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   539
      // raise the pressure and store the pressure if it's the biggest
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   540
      // pressure so far
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   541
      void raise(LRG &lrg) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   542
        _current_pressure += lrg.reg_pressure();
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   543
        if (_current_pressure > _final_pressure) {
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   544
          _final_pressure = _current_pressure;
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   545
        }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   546
      }
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   547
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   548
      void init(int limit) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   549
        _current_pressure = 0;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   550
        _high_pressure_index = 0;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   551
        _final_pressure = 0;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   552
        _high_pressure_limit = limit;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   553
        _start_pressure = 0;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   554
      }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   555
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   556
      uint high_pressure_index() const {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   557
        return _high_pressure_index;
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   558
      }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   559
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   560
      uint final_pressure() const {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   561
        return _final_pressure;
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   562
      }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   563
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   564
      uint start_pressure() const {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   565
        return _start_pressure;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   566
      }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   567
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   568
      uint current_pressure() const {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   569
        return _current_pressure;
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   570
      }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   571
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   572
      uint high_pressure_limit() const {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   573
        return _high_pressure_limit;
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   574
      }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   575
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   576
      void lower_high_pressure_index() {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   577
        _high_pressure_index--;
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   578
      }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   579
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   580
      void set_high_pressure_index_to_block_start() {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   581
        _high_pressure_index = 0;
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   582
      }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   583
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   584
      void set_start_pressure(int value) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   585
        _start_pressure = value;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   586
        _final_pressure = value;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   587
      }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   588
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   589
      void set_current_pressure(int value) {
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   590
        _current_pressure = value;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   591
      }
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   592
22912
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   593
      void check_pressure_at_fatproj(uint fatproj_location, RegMask& fatproj_mask) {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   594
        // this pressure is only valid at this instruction, i.e. we don't need to lower
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   595
        // the register pressure since the fat proj was never live before (going backwards)
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   596
        uint new_pressure = current_pressure() + fatproj_mask.Size();
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   597
        if (new_pressure > final_pressure()) {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   598
          _final_pressure = new_pressure;
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   599
        }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   600
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   601
        // if we were at a low pressure and now and the fat proj is at high pressure, record the fat proj location
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   602
        // as coming from a low to high (to low again)
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   603
        if (current_pressure() <= high_pressure_limit() && new_pressure > high_pressure_limit()) {
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   604
          _high_pressure_index = fatproj_location;
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   605
        }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   606
      }
a8c042dca573 8032894: Remove dead code in Pressure::lower
adlertz
parents: 22804
diff changeset
   607
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   608
      Pressure(uint high_pressure_index, uint high_pressure_limit)
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   609
        : _current_pressure(0)
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   610
        , _high_pressure_index(high_pressure_index)
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   611
        , _final_pressure(0)
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   612
        , _high_pressure_limit(high_pressure_limit)
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   613
        , _start_pressure(0) {}
22804
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
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   616
  void 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
   617
  void 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
   618
  void 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
   619
  bool 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
   620
  void 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
   621
  void 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
   622
  void 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
   623
  void check_for_high_pressure_block(Pressure& pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   624
  void adjust_high_pressure_index(Block* b, uint& hrp_index, Pressure& pressure);
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   625
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  // Build the interference graph using physical registers when available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  // That is, if 2 live ranges are simultaneously alive but in their
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  // acceptable register sets do not overlap, then they do not interfere.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  uint build_ifg_physical( ResourceArea *a );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   631
public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  // Gather LiveRanGe information, including register masks and base pointer/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  // derived pointer relationships.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  void gather_lrg_masks( bool mod_cisc_masks );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
33065
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   636
  // user visible pressure variables for scheduling
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   637
  Pressure _sched_int_pressure;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   638
  Pressure _sched_float_pressure;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   639
  Pressure _scratch_int_pressure;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   640
  Pressure _scratch_float_pressure;
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   641
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   642
  // Pressure functions for user context
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   643
  void lower_pressure(Block* b, uint location, LRG& lrg, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   644
  void raise_pressure(Block* b, LRG& lrg, Pressure& int_pressure, Pressure& float_pressure);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   645
  void compute_entry_block_pressure(Block* b);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   646
  void compute_exit_block_pressure(Block* b);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   647
  void print_pressure_info(Pressure& pressure, const char *str);
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   648
55892792936f 8134802: LCM register pressure scheduling
mcberg
parents: 30624
diff changeset
   649
private:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  // Force the bases of derived pointers to be alive at GC points.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  bool stretch_base_pointer_live_ranges( ResourceArea *a );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  // Helper to stretch above; recursively discover the base Node for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  // a given derived Node.  Easy for AddP-related machine nodes, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  // needs to be recursive for derived Phis.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  Node *find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  // Set the was-lo-degree bit.  Conservative coalescing should not change the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  // colorability of the graph.  If any live range was of low-degree before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  // coalescing, it should Simplify.  This call sets the was-lo-degree bit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  void set_was_low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  // Init LRG caching of degree, numregs.  Init lo_degree list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  void cache_lrg_info( );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  // Simplify the IFG by removing LRGs of low degree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  void Simplify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  // Select colors by re-inserting edges into the IFG.
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 2030
diff changeset
   669
  // Return TRUE if any spills occurred.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  uint Select( );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  // Helper function for select which allows biased coloring
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  OptoReg::Name choose_color( LRG &lrg, int chunk );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  // Helper function which implements biasing heuristic
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  OptoReg::Name bias_color( LRG &lrg, int chunk );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  // Split uncolorable live ranges
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  // Return new number of live ranges
13520
a1ba7784ef54 7148109: C2 compiler consumes too much heap resources
kvn
parents: 13104
diff changeset
   678
  uint Split(uint maxlrg, ResourceArea* split_arena);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  // Set the 'spilled_once' or 'spilled_twice' flag on a node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  void set_was_spilled( Node *n );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  // Convert ideal spill-nodes into machine loads & stores
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  // Set C->failing when fixup spills could not complete, node limit exceeded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  void fixup_spills();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  // Post-Allocation peephole copy removal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  void post_allocate_copy_removal();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  Node *skip_copies( Node *c );
3678
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   690
  // Replace the old node with the current live version of that value
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   691
  // and yank the old value if it's dead.
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   692
  int replace_and_yank_if_dead( Node *old, OptoReg::Name nreg,
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   693
      Block *current_block, Node_List& value, Node_List& regnd ) {
3678
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   694
    Node* v = regnd[nreg];
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   695
    assert(v->outcnt() != 0, "no dead values");
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   696
    old->replace_by(v);
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   697
    return yank_if_dead(old, current_block, &value, &regnd);
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   698
  }
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2340
diff changeset
   699
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10547
diff changeset
   700
  int yank_if_dead( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) {
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10547
diff changeset
   701
    return yank_if_dead_recurse(old, old, current_block, value, regnd);
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10547
diff changeset
   702
  }
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10547
diff changeset
   703
  int yank_if_dead_recurse(Node *old, Node *orig_old, Block *current_block,
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   704
      Node_List *value, Node_List *regnd);
10542
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7441
diff changeset
   705
  int yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  int elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List &regnd, bool can_change_regs );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  int use_prior_register( Node *copy, uint idx, Node *def, Block *current_block, Node_List &value, Node_List &regnd );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  bool may_be_copy_of_callee( Node *def ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  // If nreg already contains the same constant as val then eliminate it
243
79b67a7a584a 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 1
diff changeset
   711
  bool eliminate_copy_of_constant(Node* val, Node* n,
22804
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   712
      Block *current_block, Node_List& value, Node_List &regnd,
401135897b65 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 22234
diff changeset
   713
      OptoReg::Name nreg, OptoReg::Name nreg2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  // Extend the node to LRG mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  void add_reference( const Node *node, const Node *old_node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
28648
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   717
  // Record the first use of a def in the block for a register.
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   718
  class RegDefUse {
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   719
    Node* _def;
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   720
    Node* _first_use;
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   721
  public:
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   722
    RegDefUse() : _def(NULL), _first_use(NULL) { }
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   723
    Node* def() const       { return _def;       }
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   724
    Node* first_use() const { return _first_use; }
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   725
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   726
    void update(Node* def, Node* use) {
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   727
      if (_def != def) {
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   728
        _def = def;
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   729
        _first_use = use;
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   730
      }
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   731
    }
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   732
    void clear() {
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   733
      _def = NULL;
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   734
      _first_use = NULL;
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   735
    }
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   736
  };
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   737
  typedef GrowableArray<RegDefUse> RegToDefUseMap;
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   738
  int possibly_merge_multidef(Node *n, uint k, Block *block, RegToDefUseMap& reg2defuse);
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   739
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   740
  // Merge nodes that are a part of a multidef lrg and produce the same value within a block.
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   741
  void merge_multidefs();
102bdbb42723 8068881: SIGBUS in C2 compiled method weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory$SimulatedWsdlDefinitions.<init>
iveresov
parents: 24425
diff changeset
   742
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  static int _final_loads, _final_stores, _final_copies, _final_memoves;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  static double _final_load_cost, _final_store_cost, _final_copy_cost, _final_memove_cost;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  static int _conserv_coalesce, _conserv_coalesce_pair;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  static int _conserv_coalesce_trie, _conserv_coalesce_quad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  static int _post_alloc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  static int _lost_opp_pp_coalesce, _lost_opp_cflow_coalesce;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  static int _used_cisc_instructions, _unused_cisc_instructions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  static int _allocator_attempts, _allocator_successes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  static uint _high_pressure, _low_pressure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  void dump() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  void dump( const Node *n ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  void dump( const Block * b ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  void dump_degree_lists() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  void dump_simplified() const;
7441
47ea904dba6a 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 7397
diff changeset
   762
  void dump_lrg( uint lidx, bool defs_only) const;
47ea904dba6a 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 7397
diff changeset
   763
  void dump_lrg( uint lidx) const {
47ea904dba6a 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 7397
diff changeset
   764
    // dump defs and uses by default
47ea904dba6a 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 7397
diff changeset
   765
    dump_lrg(lidx, false);
47ea904dba6a 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 7397
diff changeset
   766
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  void dump_bb( uint pre_order ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  // Verify that base pointers and derived pointers are still sane
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  void verify_base_ptrs( ResourceArea *a ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
2030
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 1057
diff changeset
   772
  void verify( ResourceArea *a, bool verify_ifg = false ) const;
39d55e4534b4 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 1057
diff changeset
   773
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  void dump_for_spill_split_recycle() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  void dump_frame() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  char *dump_register( const Node *n, char *buf  ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  static void print_chaitin_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  friend class PhaseCoalesce;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  friend class PhaseAggressiveCoalesce;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  friend class PhaseConservativeCoalesce;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   786
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51333
diff changeset
   787
#endif // SHARE_OPTO_CHAITIN_HPP