annotate src/share/vm/opto/chaitin.hpp @ 14498:04e7587c97dc

8032656: Tag the MachSpillCopies with purpose information Summary: Subclassed the MachSpillCopyNode with different subnodes for different spill purposes to enhance debugging / visualization Reviewed-by: kvn, roland
author adlertz
date Tue, 25 Feb 2014 14:09:02 +0100
parents 99fc8c086679
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
14223
de6a9e811145 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 12877
diff changeset
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 923
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 923
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 923
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_OPTO_CHAITIN_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_OPTO_CHAITIN_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "code/vmreg.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "libadt/port.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "opto/connode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "opto/live.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "opto/matcher.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "opto/phase.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #include "opto/regalloc.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 #include "opto/regmask.hpp"
14498
04e7587c97dc 8032656: Tag the MachSpillCopies with purpose information
adlertz
parents: 14496
diff changeset
37 #include "opto/machnode.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39 class LoopTree;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 class Matcher;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class PhaseCFG;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 class PhaseLive;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 class PhaseRegAlloc;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 class PhaseChaitin;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 #define OPTO_DEBUG_SPLIT_FREQ BLOCK_FREQUENCY(0.001)
a61af66fc99e Initial load
duke
parents:
diff changeset
47 #define OPTO_LRG_HIGH_FREQ BLOCK_FREQUENCY(0.25)
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 //------------------------------LRG--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Live-RanGe structure.
a61af66fc99e Initial load
duke
parents:
diff changeset
51 class LRG : public ResourceObj {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3934
diff changeset
52 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public:
12877
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
54 static const uint AllStack_size = 0xFFFFF; // This mask size is used to tell that the mask of this LRG supports stack positions
0
a61af66fc99e Initial load
duke
parents:
diff changeset
55 enum { SPILL_REG=29999 }; // Register number of a spilled LRG
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 double _cost; // 2 for loads/1 for stores times block freq
a61af66fc99e Initial load
duke
parents:
diff changeset
58 double _area; // Sum of all simultaneously live values
a61af66fc99e Initial load
duke
parents:
diff changeset
59 double score() const; // Compute score from cost and area
a61af66fc99e Initial load
duke
parents:
diff changeset
60 double _maxfreq; // Maximum frequency of any def or use
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 Node *_def; // Check for multi-def live ranges
a61af66fc99e Initial load
duke
parents:
diff changeset
63 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
64 GrowableArray<Node*>* _defs;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 uint _risk_bias; // Index of LRG which we want to avoid color
a61af66fc99e Initial load
duke
parents:
diff changeset
68 uint _copy_bias; // Index of LRG which we want to share color
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 uint _next; // Index of next LRG in linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
71 uint _prev; // Index of prev LRG in linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
73 uint _reg; // Chosen register; undefined if mask is plural
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Return chosen register for this LRG. Error if the LRG is not bound to
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // a single register.
a61af66fc99e Initial load
duke
parents:
diff changeset
77 OptoReg::Name reg() const { return OptoReg::Name(_reg); }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 void set_reg( OptoReg::Name r ) { _reg = r; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
81 uint _eff_degree; // Effective degree: Sum of neighbors _num_regs
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public:
12877
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
83 int degree() const { assert( _degree_valid , "" ); return _eff_degree; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Degree starts not valid and any change to the IFG neighbor
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // set makes it not valid.
12877
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
86 void set_degree( uint degree ) {
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
87 _eff_degree = degree;
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
88 debug_only(_degree_valid = 1;)
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
89 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");
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
90 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Made a change that hammered degree
a61af66fc99e Initial load
duke
parents:
diff changeset
92 void invalid_degree() { debug_only(_degree_valid=0;) }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Incrementally modify degree. If it was correct, it should remain correct
12877
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
94 void inc_degree( uint mod ) {
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
95 _eff_degree += mod;
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
96 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");
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
97 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // Compute the degree between 2 live ranges
a61af66fc99e Initial load
duke
parents:
diff changeset
99 int compute_degree( LRG &l ) const;
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
100 bool mask_is_nonempty_and_up() const {
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
101 return mask().is_UP() && mask_size();
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
102 }
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
103 bool is_float_or_vector() const {
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
104 return _is_float || _is_vector;
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
105 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
108 RegMask _mask; // Allowed registers for this LRG
a61af66fc99e Initial load
duke
parents:
diff changeset
109 uint _mask_size; // cache of _mask.Size();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public:
12877
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
111 int compute_mask_size() const { return _mask.is_AllStack() ? AllStack_size : _mask.Size(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void set_mask_size( int size ) {
12877
d8a449d2f5b2 8011415: CTW on Sparc: assert(lrg.lo_degree()) failed:
adlertz
parents: 12254
diff changeset
113 assert((size == (int)AllStack_size) || (size == (int)_mask.Size()), "");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
114 _mask_size = size;
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
115 #ifdef ASSERT
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
116 _msize_valid=1;
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
117 if (_is_vector) {
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
118 assert(!_fat_proj, "sanity");
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
119 _mask.verify_sets(_num_regs);
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
120 } else if (_num_regs == 2 && !_fat_proj) {
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
121 _mask.verify_pairs();
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
122 }
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
123 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 void compute_set_mask_size() { set_mask_size(compute_mask_size()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 int mask_size() const { assert( _msize_valid, "mask size not valid" );
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return _mask_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Get the last mask size computed, even if it does not match the
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // count of bits in the current mask.
a61af66fc99e Initial load
duke
parents:
diff changeset
130 int get_invalid_mask_size() const { return _mask_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 const RegMask &mask() const { return _mask; }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 void set_mask( const RegMask &rm ) { _mask = rm; debug_only(_msize_valid=0;)}
a61af66fc99e Initial load
duke
parents:
diff changeset
133 void AND( const RegMask &rm ) { _mask.AND(rm); debug_only(_msize_valid=0;)}
a61af66fc99e Initial load
duke
parents:
diff changeset
134 void SUBTRACT( const RegMask &rm ) { _mask.SUBTRACT(rm); debug_only(_msize_valid=0;)}
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void Clear() { _mask.Clear() ; debug_only(_msize_valid=1); _mask_size = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void Set_All() { _mask.Set_All(); debug_only(_msize_valid=1); _mask_size = RegMask::CHUNK_SIZE; }
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
137
0
a61af66fc99e Initial load
duke
parents:
diff changeset
138 void Insert( OptoReg::Name reg ) { _mask.Insert(reg); debug_only(_msize_valid=0;) }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 void Remove( OptoReg::Name reg ) { _mask.Remove(reg); debug_only(_msize_valid=0;) }
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
140 void clear_to_pairs() { _mask.clear_to_pairs(); debug_only(_msize_valid=0;) }
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
141 void clear_to_sets() { _mask.clear_to_sets(_num_regs); debug_only(_msize_valid=0;) }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Number of registers this live range uses when it colors
a61af66fc99e Initial load
duke
parents:
diff changeset
144 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
145 uint8 _num_regs; // 2 for Longs and Doubles, 1 for all else
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // except _num_regs is kill count for fat_proj
a61af66fc99e Initial load
duke
parents:
diff changeset
147 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
148 int num_regs() const { return _num_regs; }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 void set_num_regs( int reg ) { assert( _num_regs == reg || !_num_regs, "" ); _num_regs = reg; }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Number of physical registers this live range uses when it colors
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // Architecture and register-set dependent
a61af66fc99e Initial load
duke
parents:
diff changeset
154 uint8 _reg_pressure;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
156 void set_reg_pressure(int i) { _reg_pressure = i; }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 int reg_pressure() const { return _reg_pressure; }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // How much 'wiggle room' does this live range have?
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // How many color choices can it make (scaled by _num_regs)?
a61af66fc99e Initial load
duke
parents:
diff changeset
161 int degrees_of_freedom() const { return mask_size() - _num_regs; }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Bound LRGs have ZERO degrees of freedom. We also count
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // must_spill as bound.
a61af66fc99e Initial load
duke
parents:
diff changeset
164 bool is_bound () const { return _is_bound; }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Negative degrees-of-freedom; even with no neighbors this
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // live range must spill.
a61af66fc99e Initial load
duke
parents:
diff changeset
167 bool not_free() const { return degrees_of_freedom() < 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Is this live range of "low-degree"? Trivially colorable?
a61af66fc99e Initial load
duke
parents:
diff changeset
169 bool lo_degree () const { return degree() <= degrees_of_freedom(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Is this live range just barely "low-degree"? Trivially colorable?
a61af66fc99e Initial load
duke
parents:
diff changeset
171 bool just_lo_degree () const { return degree() == degrees_of_freedom(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 uint _is_oop:1, // Live-range holds an oop
a61af66fc99e Initial load
duke
parents:
diff changeset
174 _is_float:1, // True if in float registers
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4776
diff changeset
175 _is_vector:1, // True if in vector registers
0
a61af66fc99e Initial load
duke
parents:
diff changeset
176 _was_spilled1:1, // True if prior spilling on def
a61af66fc99e Initial load
duke
parents:
diff changeset
177 _was_spilled2:1, // True if twice prior spilling on def
a61af66fc99e Initial load
duke
parents:
diff changeset
178 _is_bound:1, // live range starts life with no
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // degrees of freedom.
a61af66fc99e Initial load
duke
parents:
diff changeset
180 _direct_conflict:1, // True if def and use registers in conflict
a61af66fc99e Initial load
duke
parents:
diff changeset
181 _must_spill:1, // live range has lost all degrees of freedom
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // If _fat_proj is set, live range does NOT require aligned, adjacent
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // registers and has NO interferences.
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // If _fat_proj is clear, live range requires num_regs() to be a power of
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // 2, and it requires registers to form an aligned, adjacent set.
a61af66fc99e Initial load
duke
parents:
diff changeset
186 _fat_proj:1, //
a61af66fc99e Initial load
duke
parents:
diff changeset
187 _was_lo:1, // Was lo-degree prior to coalesce
a61af66fc99e Initial load
duke
parents:
diff changeset
188 _msize_valid:1, // _mask_size cache valid
a61af66fc99e Initial load
duke
parents:
diff changeset
189 _degree_valid:1, // _degree cache valid
a61af66fc99e Initial load
duke
parents:
diff changeset
190 _has_copy:1, // Adjacent to some copy instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
191 _at_risk:1; // Simplify says this guy is at risk to spill
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // Alive if non-zero, dead if zero
a61af66fc99e Initial load
duke
parents:
diff changeset
195 bool alive() const { return _def != NULL; }
295
ea18057223c4 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 196
diff changeset
196 bool is_multidef() const { return _def == NodeSentinel; }
ea18057223c4 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 196
diff changeset
197 bool is_singledef() const { return _def != NodeSentinel; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
200 void dump( ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
202 };
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 //------------------------------IFG--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // InterFerence Graph
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // An undirected graph implementation. Created with a fixed number of
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // vertices. Edges can be added & tested. Vertices can be removed, then
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // added back later with all edges intact. Can add edges between one vertex
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // and a list of other vertices. Can union vertices (and their edges)
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // together. The IFG needs to be really really fast, and also fairly
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // abstract! It needs abstraction so I can fiddle with the implementation to
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // get even more speed.
a61af66fc99e Initial load
duke
parents:
diff changeset
213 class PhaseIFG : public Phase {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3934
diff changeset
214 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Current implementation: a triangular adjacency list.
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // Array of adjacency-lists, indexed by live-range number
a61af66fc99e Initial load
duke
parents:
diff changeset
218 IndexSet *_adjs;
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // Assertion bit for proper use of Squaring
a61af66fc99e Initial load
duke
parents:
diff changeset
221 bool _is_square;
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // Live range structure goes here
a61af66fc99e Initial load
duke
parents:
diff changeset
224 LRG *_lrgs; // Array of LRG structures
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // Largest live-range number
a61af66fc99e Initial load
duke
parents:
diff changeset
228 uint _maxlrg;
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 Arena *_arena;
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // Keep track of inserted and deleted Nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
233 VectorSet *_yanked;
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 PhaseIFG( Arena *arena );
a61af66fc99e Initial load
duke
parents:
diff changeset
236 void init( uint maxlrg );
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // Add edge between a and b. Returns true if actually addded.
a61af66fc99e Initial load
duke
parents:
diff changeset
239 int add_edge( uint a, uint b );
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // Add edge between a and everything in the vector
a61af66fc99e Initial load
duke
parents:
diff changeset
242 void add_vector( uint a, IndexSet *vec );
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // Test for edge existance
a61af66fc99e Initial load
duke
parents:
diff changeset
245 int test_edge( uint a, uint b ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // Square-up matrix for faster Union
a61af66fc99e Initial load
duke
parents:
diff changeset
248 void SquareUp();
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // Return number of LRG neighbors
a61af66fc99e Initial load
duke
parents:
diff changeset
251 uint neighbor_cnt( uint a ) const { return _adjs[a].count(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // Union edges of b into a on Squared-up matrix
a61af66fc99e Initial load
duke
parents:
diff changeset
253 void Union( uint a, uint b );
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // Test for edge in Squared-up matrix
a61af66fc99e Initial load
duke
parents:
diff changeset
255 int test_edge_sq( uint a, uint b ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // Yank a Node and all connected edges from the IFG. Be prepared to
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // re-insert the yanked Node in reverse order of yanking. Return a
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // list of neighbors (edges) yanked.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 IndexSet *remove_node( uint a );
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // Reinsert a yanked Node
a61af66fc99e Initial load
duke
parents:
diff changeset
261 void re_insert( uint a );
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // Return set of neighbors
a61af66fc99e Initial load
duke
parents:
diff changeset
263 IndexSet *neighbors( uint a ) const { return &_adjs[a]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // Dump the IFG
a61af66fc99e Initial load
duke
parents:
diff changeset
267 void dump() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 void stats() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 void verify( const PhaseChaitin * ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 //--------------- Live Range Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
273 LRG &lrgs(uint idx) const { assert(idx < _maxlrg, "oob"); return _lrgs[idx]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // Compute and set effective degree. Might be folded into SquareUp().
a61af66fc99e Initial load
duke
parents:
diff changeset
276 void Compute_Effective_Degree();
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // Compute effective degree as the sum of neighbors' _sizes.
a61af66fc99e Initial load
duke
parents:
diff changeset
279 int effective_degree( uint lidx ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 };
a61af66fc99e Initial load
duke
parents:
diff changeset
281
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
282 // The LiveRangeMap class is responsible for storing node to live range id mapping.
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
283 // Each node is mapped to a live range id (a virtual register). Nodes that are
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
284 // not considered for register allocation are given live range id 0.
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
285 class LiveRangeMap VALUE_OBJ_CLASS_SPEC {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
286
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
287 private:
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
288
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
289 uint _max_lrg_id;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
290
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
291 // Union-find map. Declared as a short for speed.
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
292 // Indexed by live-range number, it returns the compacted live-range number
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
293 LRG_List _uf_map;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
294
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
295 // Map from Nodes to live ranges
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
296 LRG_List _names;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
297
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
298 // Straight out of Tarjan's union-find algorithm
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
299 uint find_compress(const Node *node) {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
300 uint lrg_id = find_compress(_names.at(node->_idx));
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
301 _names.at_put(node->_idx, lrg_id);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
302 return lrg_id;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
303 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
304
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
305 uint find_compress(uint lrg);
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
306
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
307 public:
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
308
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
309 const LRG_List& names() {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
310 return _names;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
311 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
312
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
313 uint max_lrg_id() const {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
314 return _max_lrg_id;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
315 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
316
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
317 void set_max_lrg_id(uint max_lrg_id) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
318 _max_lrg_id = max_lrg_id;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
319 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
320
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
321 uint size() const {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
322 return _names.length();
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
323 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
324
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
325 uint live_range_id(uint idx) const {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
326 return _names.at(idx);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
327 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
328
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
329 uint live_range_id(const Node *node) const {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
330 return _names.at(node->_idx);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
331 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
332
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
333 uint uf_live_range_id(uint lrg_id) const {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
334 return _uf_map.at(lrg_id);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
335 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
336
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
337 void map(uint idx, uint lrg_id) {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
338 _names.at_put(idx, lrg_id);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
339 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
340
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
341 void uf_map(uint dst_lrg_id, uint src_lrg_id) {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
342 _uf_map.at_put(dst_lrg_id, src_lrg_id);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
343 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
344
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
345 void extend(uint idx, uint lrg_id) {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
346 _names.at_put_grow(idx, lrg_id);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
347 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
348
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
349 void uf_extend(uint dst_lrg_id, uint src_lrg_id) {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
350 _uf_map.at_put_grow(dst_lrg_id, src_lrg_id);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
351 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
352
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
353 LiveRangeMap(Arena* arena, uint unique)
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
354 : _names(arena, unique, unique, 0)
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
355 , _uf_map(arena, unique, unique, 0)
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
356 , _max_lrg_id(0) {}
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
357
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
358 uint find_id( const Node *n ) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
359 uint retval = live_range_id(n);
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
360 assert(retval == find(n),"Invalid node to lidx mapping");
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
361 return retval;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
362 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
363
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
364 // Reset the Union-Find map to identity
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
365 void reset_uf_map(uint max_lrg_id);
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
366
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
367 // Make all Nodes map directly to their final live range; no need for
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
368 // the Union-Find mapping after this call.
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
369 void compress_uf_map_for_nodes();
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
370
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
371 uint find(uint lidx) {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
372 uint uf_lidx = _uf_map.at(lidx);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
373 return (uf_lidx == lidx) ? uf_lidx : find_compress(lidx);
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
374 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
375
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
376 // Convert a Node into a Live Range Index - a lidx
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
377 uint find(const Node *node) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
378 uint lidx = live_range_id(node);
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
379 uint uf_lidx = _uf_map.at(lidx);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
380 return (uf_lidx == lidx) ? uf_lidx : find_compress(node);
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
381 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
382
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
383 // Like Find above, but no path compress, so bad asymptotic behavior
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
384 uint find_const(uint lrg) const;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
385
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
386 // Like Find above, but no path compress, so bad asymptotic behavior
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
387 uint find_const(const Node *node) const {
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
388 if(node->_idx >= (uint)_names.length()) {
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
389 return 0; // not mapped, usual for debug dump
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
390 }
12254
8c83625e3a53 8024646: Remove LRG_List container, replace it with GrowableArray
adlertz
parents: 12075
diff changeset
391 return find_const(_names.at(node->_idx));
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
392 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
393 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 //------------------------------Chaitin----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // Briggs-Chaitin style allocation, mostly.
a61af66fc99e Initial load
duke
parents:
diff changeset
397 class PhaseChaitin : public PhaseRegAlloc {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3934
diff changeset
398 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
399
a61af66fc99e Initial load
duke
parents:
diff changeset
400 int _trip_cnt;
a61af66fc99e Initial load
duke
parents:
diff changeset
401 int _alternate;
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 LRG &lrgs(uint idx) const { return _ifg->lrgs(idx); }
a61af66fc99e Initial load
duke
parents:
diff changeset
404 PhaseLive *_live; // Liveness, used in the interference graph
a61af66fc99e Initial load
duke
parents:
diff changeset
405 PhaseIFG *_ifg; // Interference graph (for original chunk)
a61af66fc99e Initial load
duke
parents:
diff changeset
406 Node_List **_lrg_nodes; // Array of node; lists for lrgs which spill
a61af66fc99e Initial load
duke
parents:
diff changeset
407 VectorSet _spilled_once; // Nodes that have been spilled
a61af66fc99e Initial load
duke
parents:
diff changeset
408 VectorSet _spilled_twice; // Nodes that have been spilled twice
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // Combine the Live Range Indices for these 2 Nodes into a single live
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // range. Future requests for any Node in either live range will
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // return the live range index for the combined live range.
a61af66fc99e Initial load
duke
parents:
diff changeset
413 void Union( const Node *src, const Node *dst );
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 void new_lrg( const Node *x, uint lrg );
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // Compact live ranges, removing unused ones. Return new maxlrg.
a61af66fc99e Initial load
duke
parents:
diff changeset
418 void compact();
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 uint _lo_degree; // Head of lo-degree LRGs list
a61af66fc99e Initial load
duke
parents:
diff changeset
421 uint _lo_stk_degree; // Head of lo-stk-degree LRGs list
a61af66fc99e Initial load
duke
parents:
diff changeset
422 uint _hi_degree; // Head of hi-degree LRGs list
a61af66fc99e Initial load
duke
parents:
diff changeset
423 uint _simplified; // Linked list head of simplified LRGs
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 // Helper functions for Split()
14498
04e7587c97dc 8032656: Tag the MachSpillCopies with purpose information
adlertz
parents: 14496
diff changeset
426 uint split_DEF(Node *def, Block *b, int loc, uint max, Node **Reachblock, Node **debug_defs, GrowableArray<uint> splits, int slidx );
04e7587c97dc 8032656: Tag the MachSpillCopies with purpose information
adlertz
parents: 14496
diff changeset
427 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 );
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
428
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
429 //------------------------------clone_projs------------------------------------
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
430 // After cloning some rematerialized instruction, clone any MachProj's that
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
431 // follow it. Example: Intel zero is XOR, kills flags. Sparc FP constants
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
432 // use G3 as an address temp.
12075
4b2838704fd5 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 10111
diff changeset
433 int clone_projs(Block* b, uint idx, Node* orig, Node* copy, uint& max_lrg_id);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
434
12075
4b2838704fd5 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 10111
diff changeset
435 int clone_projs(Block* b, uint idx, Node* orig, Node* copy, LiveRangeMap& lrg_map) {
4b2838704fd5 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 10111
diff changeset
436 uint max_lrg_id = lrg_map.max_lrg_id();
4b2838704fd5 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 10111
diff changeset
437 int found_projs = clone_projs(b, idx, orig, copy, max_lrg_id);
4b2838704fd5 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 10111
diff changeset
438 if (found_projs > 0) {
4b2838704fd5 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 10111
diff changeset
439 // max_lrg_id is updated during call above
4b2838704fd5 8021898: Broken JIT compiler optimization for loop unswitching
kvn
parents: 10111
diff changeset
440 lrg_map.set_max_lrg_id(max_lrg_id);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
441 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
442 return found_projs;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
443 }
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
444
295
ea18057223c4 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 196
diff changeset
445 Node *split_Rematerialize(Node *def, Block *b, uint insidx, uint &maxlrg, GrowableArray<uint> splits,
ea18057223c4 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 196
diff changeset
446 int slidx, uint *lrg2reach, Node **Reachblock, bool walkThru);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // True if lidx is used before any real register is def'd in the block
a61af66fc99e Initial load
duke
parents:
diff changeset
448 bool prompt_use( Block *b, uint lidx );
14498
04e7587c97dc 8032656: Tag the MachSpillCopies with purpose information
adlertz
parents: 14496
diff changeset
449 Node *get_spillcopy_wide(MachSpillCopyNode::SpillType spill_type, Node *def, Node *use, uint uidx );
605
98cb887364d3 6810672: Comment typos
twisti
parents: 566
diff changeset
450 // Insert the spill at chosen location. Skip over any intervening Proj's or
0
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // Phis. Skip over a CatchNode and projs, inserting in the fall-through block
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // instead. Update high-pressure indices. Create a new live range.
a61af66fc99e Initial load
duke
parents:
diff changeset
453 void insert_proj( Block *b, uint i, Node *spill, uint maxlrg );
a61af66fc99e Initial load
duke
parents:
diff changeset
454
a61af66fc99e Initial load
duke
parents:
diff changeset
455 bool is_high_pressure( Block *b, LRG *lrg, uint insidx );
a61af66fc99e Initial load
duke
parents:
diff changeset
456
a61af66fc99e Initial load
duke
parents:
diff changeset
457 uint _oldphi; // Node index which separates pre-allocation nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 Block **_blks; // Array of blocks sorted by frequency for coalescing
a61af66fc99e Initial load
duke
parents:
diff changeset
460
673
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
461 float _high_frequency_lrg; // Frequency at which LRG will be spilled for debug info
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
462
0
a61af66fc99e Initial load
duke
parents:
diff changeset
463 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
464 bool _trace_spilling;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
468 PhaseChaitin( uint unique, PhaseCFG &cfg, Matcher &matcher );
a61af66fc99e Initial load
duke
parents:
diff changeset
469 ~PhaseChaitin() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
470
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8728
diff changeset
471 LiveRangeMap _lrg_map;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 // Do all the real work of allocate
a61af66fc99e Initial load
duke
parents:
diff changeset
474 void Register_Allocate();
a61af66fc99e Initial load
duke
parents:
diff changeset
475
673
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
476 float high_frequency_lrg() const { return _high_frequency_lrg; }
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
477
0
a61af66fc99e Initial load
duke
parents:
diff changeset
478 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
479 bool trace_spilling() const { return _trace_spilling; }
a61af66fc99e Initial load
duke
parents:
diff changeset
480 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // De-SSA the world. Assign registers to Nodes. Use the same register for
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // all inputs to a PhiNode, effectively coalescing live ranges. Insert
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // copies as needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
486 void de_ssa();
a61af66fc99e Initial load
duke
parents:
diff changeset
487
a61af66fc99e Initial load
duke
parents:
diff changeset
488 // Add edge between reg and everything in the vector.
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // Same as _ifg->add_vector(reg,live) EXCEPT use the RegMask
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // information to trim the set of interferences. Return the
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // count of edges added.
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
492 void interfere_with_live(uint lid, IndexSet* liveout);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
493 #ifdef ASSERT
0
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // Count register pressure for asserts
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
495 uint count_int_pressure(IndexSet* liveout);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
496 uint count_float_pressure(IndexSet* liveout);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
497 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // Build the interference graph using virtual registers only.
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // Used for aggressive coalescing.
a61af66fc99e Initial load
duke
parents:
diff changeset
501 void build_ifg_virtual( );
a61af66fc99e Initial load
duke
parents:
diff changeset
502
14496
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
503 // used when computing the register pressure for each block in the CFG. This
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
504 // is done during IFG creation.
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
505 class Pressure {
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
506 // keeps track of the register pressure at the current
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
507 // instruction (used when stepping backwards in the block)
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
508 uint _current_pressure;
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
509
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
510 // keeps track of the instruction index of the first low to high register pressure
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
511 // transition (starting from the top) in the block
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
512 // if high_pressure_index == 0 then the whole block is high pressure
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
513 // if high_pressure_index = b.end_idx() + 1 then the whole block is low pressure
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
514 uint _high_pressure_index;
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
515
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
516 // stores the highest pressure we find
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
517 uint _final_pressure;
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
518
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
519 // number of live ranges that constitute high register pressure
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
520 const uint _high_pressure_limit;
14496
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
521 public:
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
522
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
523 // lower the register pressure and look for a low to high pressure
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
524 // transition
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
525 void lower(LRG& lrg, uint& location) {
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
526 _current_pressure -= lrg.reg_pressure();
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
527 if (_current_pressure == _high_pressure_limit) {
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
528 _high_pressure_index = location;
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
529 }
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
530 }
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
531
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
532 // raise the pressure and store the pressure if it's the biggest
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
533 // pressure so far
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
534 void raise(LRG &lrg) {
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
535 _current_pressure += lrg.reg_pressure();
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
536 if (_current_pressure > _final_pressure) {
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
537 _final_pressure = _current_pressure;
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
538 }
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
539 }
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
540
14496
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
541 uint high_pressure_index() const {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
542 return _high_pressure_index;
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
543 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
544
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
545 uint final_pressure() const {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
546 return _final_pressure;
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
547 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
548
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
549 uint current_pressure() const {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
550 return _current_pressure;
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
551 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
552
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
553 uint high_pressure_limit() const {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
554 return _high_pressure_limit;
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
555 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
556
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
557 void lower_high_pressure_index() {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
558 _high_pressure_index--;
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
559 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
560
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
561 void set_high_pressure_index_to_block_start() {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
562 _high_pressure_index = 0;
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
563 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
564
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
565 void check_pressure_at_fatproj(uint fatproj_location, RegMask& fatproj_mask) {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
566 // this pressure is only valid at this instruction, i.e. we don't need to lower
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
567 // the register pressure since the fat proj was never live before (going backwards)
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
568 uint new_pressure = current_pressure() + fatproj_mask.Size();
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
569 if (new_pressure > final_pressure()) {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
570 _final_pressure = new_pressure;
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
571 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
572
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
573 // if we were at a low pressure and now and the fat proj is at high pressure, record the fat proj location
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
574 // as coming from a low to high (to low again)
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
575 if (current_pressure() <= high_pressure_limit() && new_pressure > high_pressure_limit()) {
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
576 _high_pressure_index = fatproj_location;
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
577 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
578 }
99fc8c086679 8032894: Remove dead code in Pressure::lower
adlertz
parents: 14388
diff changeset
579
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
580 Pressure(uint high_pressure_index, uint high_pressure_limit)
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
581 : _current_pressure(0)
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
582 , _high_pressure_index(high_pressure_index)
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
583 , _high_pressure_limit(high_pressure_limit)
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
584 , _final_pressure(0) {}
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
585 };
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
586
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
587 void lower_pressure(Block* b, uint location, LRG& lrg, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
588 void raise_pressure(Block* b, LRG& lrg, Pressure& int_pressure, Pressure& float_pressure);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
589 void check_for_high_pressure_transition_at_fatproj(uint& block_reg_pressure, uint location, LRG& lrg, Pressure& pressure, const int op_regtype);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
590 void add_input_to_liveout(Block* b, Node* n, IndexSet* liveout, double cost, Pressure& int_pressure, Pressure& float_pressure);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
591 void compute_initial_block_pressure(Block* b, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure, double cost);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
592 bool remove_node_if_not_used(Block* b, uint location, Node* n, uint lid, IndexSet* liveout);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
593 void assign_high_score_to_immediate_copies(Block* b, Node* n, LRG& lrg, uint next_inst, uint last_inst);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
594 void remove_interference_from_copy(Block* b, uint location, uint lid_copy, IndexSet* liveout, double cost, Pressure& int_pressure, Pressure& float_pressure);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
595 void remove_bound_register_from_interfering_live_ranges(LRG& lrg, IndexSet* liveout, uint& must_spill);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
596 void check_for_high_pressure_block(Pressure& pressure);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
597 void adjust_high_pressure_index(Block* b, uint& hrp_index, Pressure& pressure);
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
598
0
a61af66fc99e Initial load
duke
parents:
diff changeset
599 // Build the interference graph using physical registers when available.
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // That is, if 2 live ranges are simultaneously alive but in their
a61af66fc99e Initial load
duke
parents:
diff changeset
601 // acceptable register sets do not overlap, then they do not interfere.
a61af66fc99e Initial load
duke
parents:
diff changeset
602 uint build_ifg_physical( ResourceArea *a );
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604 // Gather LiveRanGe information, including register masks and base pointer/
a61af66fc99e Initial load
duke
parents:
diff changeset
605 // derived pointer relationships.
a61af66fc99e Initial load
duke
parents:
diff changeset
606 void gather_lrg_masks( bool mod_cisc_masks );
a61af66fc99e Initial load
duke
parents:
diff changeset
607
a61af66fc99e Initial load
duke
parents:
diff changeset
608 // Force the bases of derived pointers to be alive at GC points.
a61af66fc99e Initial load
duke
parents:
diff changeset
609 bool stretch_base_pointer_live_ranges( ResourceArea *a );
a61af66fc99e Initial load
duke
parents:
diff changeset
610 // Helper to stretch above; recursively discover the base Node for
a61af66fc99e Initial load
duke
parents:
diff changeset
611 // a given derived Node. Easy for AddP-related machine nodes, but
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // needs to be recursive for derived Phis.
a61af66fc99e Initial load
duke
parents:
diff changeset
613 Node *find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg );
a61af66fc99e Initial load
duke
parents:
diff changeset
614
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // Set the was-lo-degree bit. Conservative coalescing should not change the
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // colorability of the graph. If any live range was of low-degree before
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // coalescing, it should Simplify. This call sets the was-lo-degree bit.
a61af66fc99e Initial load
duke
parents:
diff changeset
618 void set_was_low();
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 // Split live-ranges that must spill due to register conflicts (as opposed
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // to capacity spills). Typically these are things def'd in a register
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // and used on the stack or vice-versa.
a61af66fc99e Initial load
duke
parents:
diff changeset
623 void pre_spill();
a61af66fc99e Initial load
duke
parents:
diff changeset
624
a61af66fc99e Initial load
duke
parents:
diff changeset
625 // Init LRG caching of degree, numregs. Init lo_degree list.
a61af66fc99e Initial load
duke
parents:
diff changeset
626 void cache_lrg_info( );
a61af66fc99e Initial load
duke
parents:
diff changeset
627
a61af66fc99e Initial load
duke
parents:
diff changeset
628 // Simplify the IFG by removing LRGs of low degree with no copies
a61af66fc99e Initial load
duke
parents:
diff changeset
629 void Pre_Simplify();
a61af66fc99e Initial load
duke
parents:
diff changeset
630
a61af66fc99e Initial load
duke
parents:
diff changeset
631 // Simplify the IFG by removing LRGs of low degree
a61af66fc99e Initial load
duke
parents:
diff changeset
632 void Simplify();
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 // Select colors by re-inserting edges into the IFG.
605
98cb887364d3 6810672: Comment typos
twisti
parents: 566
diff changeset
635 // Return TRUE if any spills occurred.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
636 uint Select( );
a61af66fc99e Initial load
duke
parents:
diff changeset
637 // Helper function for select which allows biased coloring
a61af66fc99e Initial load
duke
parents:
diff changeset
638 OptoReg::Name choose_color( LRG &lrg, int chunk );
a61af66fc99e Initial load
duke
parents:
diff changeset
639 // Helper function which implements biasing heuristic
a61af66fc99e Initial load
duke
parents:
diff changeset
640 OptoReg::Name bias_color( LRG &lrg, int chunk );
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // Split uncolorable live ranges
a61af66fc99e Initial load
duke
parents:
diff changeset
643 // Return new number of live ranges
6632
a1c7f6472621 7148109: C2 compiler consumes too much heap resources
kvn
parents: 6179
diff changeset
644 uint Split(uint maxlrg, ResourceArea* split_arena);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
645
a61af66fc99e Initial load
duke
parents:
diff changeset
646 // Copy 'was_spilled'-edness from one Node to another.
a61af66fc99e Initial load
duke
parents:
diff changeset
647 void copy_was_spilled( Node *src, Node *dst );
a61af66fc99e Initial load
duke
parents:
diff changeset
648 // Set the 'spilled_once' or 'spilled_twice' flag on a node.
a61af66fc99e Initial load
duke
parents:
diff changeset
649 void set_was_spilled( Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
650
a61af66fc99e Initial load
duke
parents:
diff changeset
651 // Convert ideal spill-nodes into machine loads & stores
a61af66fc99e Initial load
duke
parents:
diff changeset
652 // Set C->failing when fixup spills could not complete, node limit exceeded.
a61af66fc99e Initial load
duke
parents:
diff changeset
653 void fixup_spills();
a61af66fc99e Initial load
duke
parents:
diff changeset
654
a61af66fc99e Initial load
duke
parents:
diff changeset
655 // Post-Allocation peephole copy removal
a61af66fc99e Initial load
duke
parents:
diff changeset
656 void post_allocate_copy_removal();
a61af66fc99e Initial load
duke
parents:
diff changeset
657 Node *skip_copies( Node *c );
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
658 // Replace the old node with the current live version of that value
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
659 // and yank the old value if it's dead.
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
660 int replace_and_yank_if_dead( Node *old, OptoReg::Name nreg,
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
661 Block *current_block, Node_List& value, Node_List& regnd ) {
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
662 Node* v = regnd[nreg];
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
663 assert(v->outcnt() != 0, "no dead values");
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
664 old->replace_by(v);
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
665 return yank_if_dead(old, current_block, &value, &regnd);
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
666 }
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 673
diff changeset
667
4776
5da7201222d5 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 3939
diff changeset
668 int yank_if_dead( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) {
5da7201222d5 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 3939
diff changeset
669 return yank_if_dead_recurse(old, old, current_block, value, regnd);
5da7201222d5 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 3939
diff changeset
670 }
5da7201222d5 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 3939
diff changeset
671 int yank_if_dead_recurse(Node *old, Node *orig_old, Block *current_block,
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
672 Node_List *value, Node_List *regnd);
3934
8f47d8870d9a 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 2016
diff changeset
673 int yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
674 int elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List &regnd, bool can_change_regs );
a61af66fc99e Initial load
duke
parents:
diff changeset
675 int use_prior_register( Node *copy, uint idx, Node *def, Block *current_block, Node_List &value, Node_List &regnd );
a61af66fc99e Initial load
duke
parents:
diff changeset
676 bool may_be_copy_of_callee( Node *def ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
677
a61af66fc99e Initial load
duke
parents:
diff changeset
678 // If nreg already contains the same constant as val then eliminate it
70
b683f557224b 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 0
diff changeset
679 bool eliminate_copy_of_constant(Node* val, Node* n,
14388
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
680 Block *current_block, Node_List& value, Node_List &regnd,
c84312468f5c 8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical
adlertz
parents: 14223
diff changeset
681 OptoReg::Name nreg, OptoReg::Name nreg2);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
682 // Extend the node to LRG mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
683 void add_reference( const Node *node, const Node *old_node);
a61af66fc99e Initial load
duke
parents:
diff changeset
684
a61af66fc99e Initial load
duke
parents:
diff changeset
685 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
686
a61af66fc99e Initial load
duke
parents:
diff changeset
687 static int _final_loads, _final_stores, _final_copies, _final_memoves;
a61af66fc99e Initial load
duke
parents:
diff changeset
688 static double _final_load_cost, _final_store_cost, _final_copy_cost, _final_memove_cost;
a61af66fc99e Initial load
duke
parents:
diff changeset
689 static int _conserv_coalesce, _conserv_coalesce_pair;
a61af66fc99e Initial load
duke
parents:
diff changeset
690 static int _conserv_coalesce_trie, _conserv_coalesce_quad;
a61af66fc99e Initial load
duke
parents:
diff changeset
691 static int _post_alloc;
a61af66fc99e Initial load
duke
parents:
diff changeset
692 static int _lost_opp_pp_coalesce, _lost_opp_cflow_coalesce;
a61af66fc99e Initial load
duke
parents:
diff changeset
693 static int _used_cisc_instructions, _unused_cisc_instructions;
a61af66fc99e Initial load
duke
parents:
diff changeset
694 static int _allocator_attempts, _allocator_successes;
a61af66fc99e Initial load
duke
parents:
diff changeset
695
a61af66fc99e Initial load
duke
parents:
diff changeset
696 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
697 static uint _high_pressure, _low_pressure;
a61af66fc99e Initial load
duke
parents:
diff changeset
698
a61af66fc99e Initial load
duke
parents:
diff changeset
699 void dump() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
700 void dump( const Node *n ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
701 void dump( const Block * b ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
702 void dump_degree_lists() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
703 void dump_simplified() const;
2016
361783318e7e 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 1972
diff changeset
704 void dump_lrg( uint lidx, bool defs_only) const;
361783318e7e 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 1972
diff changeset
705 void dump_lrg( uint lidx) const {
361783318e7e 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 1972
diff changeset
706 // dump defs and uses by default
361783318e7e 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 1972
diff changeset
707 dump_lrg(lidx, false);
361783318e7e 7004940: CTW: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG
never
parents: 1972
diff changeset
708 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
709 void dump_bb( uint pre_order ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
710
a61af66fc99e Initial load
duke
parents:
diff changeset
711 // Verify that base pointers and derived pointers are still sane
a61af66fc99e Initial load
duke
parents:
diff changeset
712 void verify_base_ptrs( ResourceArea *a ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
713
566
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 295
diff changeset
714 void verify( ResourceArea *a, bool verify_ifg = false ) const;
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 295
diff changeset
715
0
a61af66fc99e Initial load
duke
parents:
diff changeset
716 void dump_for_spill_split_recycle() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
719 void dump_frame() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
720 char *dump_register( const Node *n, char *buf ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
721 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
722 static void print_chaitin_statistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
723 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
724 friend class PhaseCoalesce;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 friend class PhaseAggressiveCoalesce;
a61af66fc99e Initial load
duke
parents:
diff changeset
726 friend class PhaseConservativeCoalesce;
a61af66fc99e Initial load
duke
parents:
diff changeset
727 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
728
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
729 #endif // SHARE_VM_OPTO_CHAITIN_HPP