annotate src/share/vm/opto/ifg.cpp @ 10408:836a62f43af9

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 19 Jun 2013 10:45:56 +0200
parents 8373c19be854
children d1034bd8cefc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
2 * Copyright (c) 1998, 2012, 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: 1212
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1212
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: 1212
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 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "compiler/oopMap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "opto/addnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "opto/block.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "opto/callnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "opto/cfgnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "opto/chaitin.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "opto/coalesce.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "opto/connode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #include "opto/indexSet.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 #include "opto/machnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 #include "opto/memnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 #include "opto/opcodes.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
41 //------------------------------IFG--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
42 PhaseIFG::PhaseIFG( Arena *arena ) : Phase(Interference_Graph), _arena(arena) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //------------------------------init-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
46 void PhaseIFG::init( uint maxlrg ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 _maxlrg = maxlrg;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 _yanked = new (_arena) VectorSet(_arena);
a61af66fc99e Initial load
duke
parents:
diff changeset
49 _is_square = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Make uninitialized adjacency lists
a61af66fc99e Initial load
duke
parents:
diff changeset
51 _adjs = (IndexSet*)_arena->Amalloc(sizeof(IndexSet)*maxlrg);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Also make empty live range structures
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _lrgs = (LRG *)_arena->Amalloc( maxlrg * sizeof(LRG) );
a61af66fc99e Initial load
duke
parents:
diff changeset
54 memset(_lrgs,0,sizeof(LRG)*maxlrg);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Init all to empty
a61af66fc99e Initial load
duke
parents:
diff changeset
56 for( uint i = 0; i < maxlrg; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 _adjs[i].initialize(maxlrg);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _lrgs[i].Set_All();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 //------------------------------add--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Add edge between vertices a & b. These are sorted (triangular matrix),
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // then the smaller number is inserted in the larger numbered array.
a61af66fc99e Initial load
duke
parents:
diff changeset
65 int PhaseIFG::add_edge( uint a, uint b ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 lrgs(a).invalid_degree();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 lrgs(b).invalid_degree();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // Sort a and b, so that a is bigger
a61af66fc99e Initial load
duke
parents:
diff changeset
69 assert( !_is_square, "only on triangular" );
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if( a < b ) { uint tmp = a; a = b; b = tmp; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return _adjs[a].insert( b );
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 //------------------------------add_vector-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Add an edge between 'a' and everything in the vector.
a61af66fc99e Initial load
duke
parents:
diff changeset
76 void PhaseIFG::add_vector( uint a, IndexSet *vec ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // IFG is triangular, so do the inserts where 'a' < 'b'.
a61af66fc99e Initial load
duke
parents:
diff changeset
78 assert( !_is_square, "only on triangular" );
a61af66fc99e Initial load
duke
parents:
diff changeset
79 IndexSet *adjs_a = &_adjs[a];
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if( !vec->count() ) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 IndexSetIterator elements(vec);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 uint neighbor;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 while ((neighbor = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 add_edge( a, neighbor );
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 //------------------------------test-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Is there an edge between a and b?
a61af66fc99e Initial load
duke
parents:
diff changeset
91 int PhaseIFG::test_edge( uint a, uint b ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Sort a and b, so that a is larger
a61af66fc99e Initial load
duke
parents:
diff changeset
93 assert( !_is_square, "only on triangular" );
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if( a < b ) { uint tmp = a; a = b; b = tmp; }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return _adjs[a].member(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 //------------------------------SquareUp---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Convert triangular matrix to square matrix
a61af66fc99e Initial load
duke
parents:
diff changeset
100 void PhaseIFG::SquareUp() {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 assert( !_is_square, "only on triangular" );
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Simple transpose
a61af66fc99e Initial load
duke
parents:
diff changeset
104 for( uint i = 0; i < _maxlrg; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 IndexSetIterator elements(&_adjs[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 uint datum;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 while ((datum = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 _adjs[datum].insert( i );
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 _is_square = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 //------------------------------Compute_Effective_Degree-----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Compute effective degree in bulk
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void PhaseIFG::Compute_Effective_Degree() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 assert( _is_square, "only on square" );
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 for( uint i = 0; i < _maxlrg; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
120 lrgs(i).set_degree(effective_degree(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 //------------------------------test_edge_sq-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
124 int PhaseIFG::test_edge_sq( uint a, uint b ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 assert( _is_square, "only on square" );
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Swap, so that 'a' has the lesser count. Then binary search is on
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // the smaller of a's list and b's list.
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if( neighbor_cnt(a) > neighbor_cnt(b) ) { uint tmp = a; a = b; b = tmp; }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 //return _adjs[a].unordered_member(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return _adjs[a].member(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 //------------------------------Union------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Union edges of B into A
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void PhaseIFG::Union( uint a, uint b ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 assert( _is_square, "only on square" );
a61af66fc99e Initial load
duke
parents:
diff changeset
137 IndexSet *A = &_adjs[a];
a61af66fc99e Initial load
duke
parents:
diff changeset
138 IndexSetIterator b_elements(&_adjs[b]);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 uint datum;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 while ((datum = b_elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if(A->insert(datum)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 _adjs[datum].insert(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 lrgs(a).invalid_degree();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 lrgs(datum).invalid_degree();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 //------------------------------remove_node------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Yank a Node and all connected edges from the IFG. Return a
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // list of neighbors (edges) yanked.
a61af66fc99e Initial load
duke
parents:
diff changeset
152 IndexSet *PhaseIFG::remove_node( uint a ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert( _is_square, "only on square" );
a61af66fc99e Initial load
duke
parents:
diff changeset
154 assert( !_yanked->test(a), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
155 _yanked->set(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // I remove the LRG from all neighbors.
a61af66fc99e Initial load
duke
parents:
diff changeset
158 IndexSetIterator elements(&_adjs[a]);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 LRG &lrg_a = lrgs(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 uint datum;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 while ((datum = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 _adjs[datum].remove(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 lrgs(datum).inc_degree( -lrg_a.compute_degree(lrgs(datum)) );
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return neighbors(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 //------------------------------re_insert--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Re-insert a yanked Node.
a61af66fc99e Initial load
duke
parents:
diff changeset
170 void PhaseIFG::re_insert( uint a ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 assert( _is_square, "only on square" );
a61af66fc99e Initial load
duke
parents:
diff changeset
172 assert( _yanked->test(a), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
173 (*_yanked) >>= a;
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 IndexSetIterator elements(&_adjs[a]);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 uint datum;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 while ((datum = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 _adjs[datum].insert(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 lrgs(datum).invalid_degree();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 //------------------------------compute_degree---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // Compute the degree between 2 live ranges. If both live ranges are
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // aligned-adjacent powers-of-2 then we use the MAX size. If either is
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // mis-aligned (or for Fat-Projections, not-adjacent) then we have to
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // MULTIPLY the sizes. Inspect Brigg's thesis on register pairs to see why
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // this is so.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 int LRG::compute_degree( LRG &l ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 int tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 int num_regs = _num_regs;
a61af66fc99e Initial load
duke
parents:
diff changeset
192 int nregs = l.num_regs();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 tmp = (_fat_proj || l._fat_proj) // either is a fat-proj?
a61af66fc99e Initial load
duke
parents:
diff changeset
194 ? (num_regs * nregs) // then use product
a61af66fc99e Initial load
duke
parents:
diff changeset
195 : MAX2(num_regs,nregs); // else use max
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 //------------------------------effective_degree-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // Compute effective degree for this live range. If both live ranges are
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // aligned-adjacent powers-of-2 then we use the MAX size. If either is
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // mis-aligned (or for Fat-Projections, not-adjacent) then we have to
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // MULTIPLY the sizes. Inspect Brigg's thesis on register pairs to see why
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // this is so.
a61af66fc99e Initial load
duke
parents:
diff changeset
205 int PhaseIFG::effective_degree( uint lidx ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 int eff = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
207 int num_regs = lrgs(lidx).num_regs();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 int fat_proj = lrgs(lidx)._fat_proj;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 IndexSet *s = neighbors(lidx);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 IndexSetIterator elements(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 uint nidx;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 while((nidx = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 LRG &lrgn = lrgs(nidx);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 int nregs = lrgn.num_regs();
a61af66fc99e Initial load
duke
parents:
diff changeset
215 eff += (fat_proj || lrgn._fat_proj) // either is a fat-proj?
a61af66fc99e Initial load
duke
parents:
diff changeset
216 ? (num_regs * nregs) // then use product
a61af66fc99e Initial load
duke
parents:
diff changeset
217 : MAX2(num_regs,nregs); // else use max
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return eff;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
224 //------------------------------dump-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
225 void PhaseIFG::dump() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 tty->print_cr("-- Interference Graph --%s--",
a61af66fc99e Initial load
duke
parents:
diff changeset
227 _is_square ? "square" : "triangular" );
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if( _is_square ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 for( uint i = 0; i < _maxlrg; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 tty->print( (*_yanked)[i] ? "XX " : " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
231 tty->print("L%d: { ",i);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 IndexSetIterator elements(&_adjs[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 uint datum;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 while ((datum = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 tty->print("L%d ", datum);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 tty->print_cr("}");
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // Triangular
a61af66fc99e Initial load
duke
parents:
diff changeset
244 for( uint i = 0; i < _maxlrg; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 uint j;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 tty->print( (*_yanked)[i] ? "XX " : " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
247 tty->print("L%d: { ",i);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 for( j = _maxlrg; j > i; j-- )
a61af66fc99e Initial load
duke
parents:
diff changeset
249 if( test_edge(j - 1,i) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 tty->print("L%d ",j - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 tty->print("| ");
a61af66fc99e Initial load
duke
parents:
diff changeset
253 IndexSetIterator elements(&_adjs[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
254 uint datum;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 while ((datum = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 tty->print("L%d ", datum);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 tty->print("}\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 tty->print("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 //------------------------------stats------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
264 void PhaseIFG::stats() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
266 int *h_cnt = NEW_RESOURCE_ARRAY(int,_maxlrg*2);
a61af66fc99e Initial load
duke
parents:
diff changeset
267 memset( h_cnt, 0, sizeof(int)*_maxlrg*2 );
a61af66fc99e Initial load
duke
parents:
diff changeset
268 uint i;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 for( i = 0; i < _maxlrg; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 h_cnt[neighbor_cnt(i)]++;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 tty->print_cr("--Histogram of counts--");
a61af66fc99e Initial load
duke
parents:
diff changeset
273 for( i = 0; i < _maxlrg*2; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if( h_cnt[i] )
a61af66fc99e Initial load
duke
parents:
diff changeset
275 tty->print("%d/%d ",i,h_cnt[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 tty->print_cr("");
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 //------------------------------verify-----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
280 void PhaseIFG::verify( const PhaseChaitin *pc ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // IFG is square, sorted and no need for Find
a61af66fc99e Initial load
duke
parents:
diff changeset
282 for( uint i = 0; i < _maxlrg; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 assert(!((*_yanked)[i]) || !neighbor_cnt(i), "Is removed completely" );
a61af66fc99e Initial load
duke
parents:
diff changeset
284 IndexSet *set = &_adjs[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
285 IndexSetIterator elements(set);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 uint idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 uint last = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 while ((idx = elements.next()) != 0) {
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
289 assert(idx != i, "Must have empty diagonal");
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
290 assert(pc->_lrg_map.find_const(idx) == idx, "Must not need Find");
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
291 assert(_adjs[idx].member(i), "IFG not square");
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
292 assert(!(*_yanked)[idx], "No yanked neighbors");
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
293 assert(last < idx, "not sorted increasing");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
294 last = idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
296 assert(!lrgs(i)._degree_valid || effective_degree(i) == lrgs(i).degree(), "degree is valid but wrong");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 //------------------------------interfere_with_live----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // Interfere this register with everything currently live. Use the RegMasks
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // to trim the set of possible interferences. Return a count of register-only
605
98cb887364d3 6810672: Comment typos
twisti
parents: 566
diff changeset
304 // interferences as an estimate of register pressure.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
305 void PhaseChaitin::interfere_with_live( uint r, IndexSet *liveout ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 uint retval = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // Interfere with everything live.
a61af66fc99e Initial load
duke
parents:
diff changeset
308 const RegMask &rm = lrgs(r).mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // Check for interference by checking overlap of regmasks.
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // Only interfere if acceptable register masks overlap.
a61af66fc99e Initial load
duke
parents:
diff changeset
311 IndexSetIterator elements(liveout);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 uint l;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 while( (l = elements.next()) != 0 )
a61af66fc99e Initial load
duke
parents:
diff changeset
314 if( rm.overlap( lrgs(l).mask() ) )
a61af66fc99e Initial load
duke
parents:
diff changeset
315 _ifg->add_edge( r, l );
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 //------------------------------build_ifg_virtual------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
319 // Actually build the interference graph. Uses virtual registers only, no
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // physical register masks. This allows me to be very aggressive when
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // coalescing copies. Some of this aggressiveness will have to be undone
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // later, but I'd rather get all the copies I can now (since unremoved copies
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // at this point can end up in bad places). Copies I re-insert later I have
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // more opportunity to insert them in low-frequency locations.
a61af66fc99e Initial load
duke
parents:
diff changeset
325 void PhaseChaitin::build_ifg_virtual( ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // For all blocks (in any order) do...
a61af66fc99e Initial load
duke
parents:
diff changeset
328 for( uint i=0; i<_cfg._num_blocks; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 Block *b = _cfg._blocks[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
330 IndexSet *liveout = _live->live(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // The IFG is built by a single reverse pass over each basic block.
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Starting with the known live-out set, we remove things that get
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // defined and add things that become live (essentially executing one
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // pass of a standard LIVE analysis). Just before a Node defines a value
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // (and removes it from the live-ness set) that value is certainly live.
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // The defined value interferes with everything currently live. The
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // value is then removed from the live-ness set and it's inputs are
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // added to the live-ness set.
a61af66fc99e Initial load
duke
parents:
diff changeset
340 for( uint j = b->end_idx() + 1; j > 1; j-- ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 Node *n = b->_nodes[j-1];
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // Get value being defined
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
344 uint r = _lrg_map.live_range_id(n);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // Some special values do not allocate
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
347 if (r) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // Remove from live-out set
a61af66fc99e Initial load
duke
parents:
diff changeset
350 liveout->remove(r);
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 // Copies do not define a new value and so do not interfere.
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // Remove the copies source from the liveout set before interfering.
a61af66fc99e Initial load
duke
parents:
diff changeset
354 uint idx = n->is_Copy();
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
355 if (idx) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
356 liveout->remove(_lrg_map.live_range_id(n->in(idx)));
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
357 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // Interfere with everything live
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
360 interfere_with_live(r, liveout);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 // Make all inputs live
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
364 if (!n->is_Phi()) { // Phi function uses come from prior block
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
365 for(uint k = 1; k < n->req(); k++) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
366 liveout->insert(_lrg_map.live_range_id(n->in(k)));
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
367 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // 2-address instructions always have the defined value live
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // on entry to the instruction, even though it is being defined
a61af66fc99e Initial load
duke
parents:
diff changeset
372 // by the instruction. We pretend a virtual copy sits just prior
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // to the instruction and kills the src-def'd register.
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // In other words, for 2-address instructions the defined value
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // interferes with all inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
376 uint idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 if( n->is_Mach() && (idx = n->as_Mach()->two_adr()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 const MachNode *mach = n->as_Mach();
a61af66fc99e Initial load
duke
parents:
diff changeset
379 // Sometimes my 2-address ADDs are commuted in a bad way.
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // We generally want the USE-DEF register to refer to the
a61af66fc99e Initial load
duke
parents:
diff changeset
381 // loop-varying quantity, to avoid a copy.
a61af66fc99e Initial load
duke
parents:
diff changeset
382 uint op = mach->ideal_Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // Check that mach->num_opnds() == 3 to ensure instruction is
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // not subsuming constants, effectively excludes addI_cin_imm
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // Can NOT swap for instructions like addI_cin_imm since it
a61af66fc99e Initial load
duke
parents:
diff changeset
386 // is adding zero to yhi + carry and the second ideal-input
a61af66fc99e Initial load
duke
parents:
diff changeset
387 // points to the result of adding low-halves.
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // Checking req() and num_opnds() does NOT distinguish addI_cout from addI_cout_imm
a61af66fc99e Initial load
duke
parents:
diff changeset
389 if( (op == Op_AddI && mach->req() == 3 && mach->num_opnds() == 3) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
390 n->in(1)->bottom_type()->base() == Type::Int &&
a61af66fc99e Initial load
duke
parents:
diff changeset
391 // See if the ADD is involved in a tight data loop the wrong way
a61af66fc99e Initial load
duke
parents:
diff changeset
392 n->in(2)->is_Phi() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
393 n->in(2)->in(2) == n ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 Node *tmp = n->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 n->set_req( 1, n->in(2) );
a61af66fc99e Initial load
duke
parents:
diff changeset
396 n->set_req( 2, tmp );
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // Defined value interferes with all inputs
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
399 uint lidx = _lrg_map.live_range_id(n->in(idx));
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
400 for (uint k = 1; k < n->req(); k++) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
401 uint kidx = _lrg_map.live_range_id(n->in(k));
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
402 if (kidx != lidx) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
403 _ifg->add_edge(r, kidx);
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
404 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407 } // End of forall instructions in block
a61af66fc99e Initial load
duke
parents:
diff changeset
408 } // End of forall blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 //------------------------------count_int_pressure-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
412 uint PhaseChaitin::count_int_pressure( IndexSet *liveout ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 IndexSetIterator elements(liveout);
a61af66fc99e Initial load
duke
parents:
diff changeset
414 uint lidx;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 uint cnt = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 while ((lidx = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 if( lrgs(lidx).mask().is_UP() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
418 lrgs(lidx).mask_size() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
419 !lrgs(lidx)._is_float &&
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
420 !lrgs(lidx)._is_vector &&
0
a61af66fc99e Initial load
duke
parents:
diff changeset
421 lrgs(lidx).mask().overlap(*Matcher::idealreg2regmask[Op_RegI]) )
a61af66fc99e Initial load
duke
parents:
diff changeset
422 cnt += lrgs(lidx).reg_pressure();
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424 return cnt;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426
a61af66fc99e Initial load
duke
parents:
diff changeset
427 //------------------------------count_float_pressure---------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
428 uint PhaseChaitin::count_float_pressure( IndexSet *liveout ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
429 IndexSetIterator elements(liveout);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 uint lidx;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 uint cnt = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
432 while ((lidx = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 if( lrgs(lidx).mask().is_UP() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
434 lrgs(lidx).mask_size() &&
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
435 (lrgs(lidx)._is_float || lrgs(lidx)._is_vector))
0
a61af66fc99e Initial load
duke
parents:
diff changeset
436 cnt += lrgs(lidx).reg_pressure();
a61af66fc99e Initial load
duke
parents:
diff changeset
437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
438 return cnt;
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440
a61af66fc99e Initial load
duke
parents:
diff changeset
441 //------------------------------lower_pressure---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
442 // Adjust register pressure down by 1. Capture last hi-to-low transition,
a61af66fc99e Initial load
duke
parents:
diff changeset
443 static void lower_pressure( LRG *lrg, uint where, Block *b, uint *pressure, uint *hrp_index ) {
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
444 if (lrg->mask().is_UP() && lrg->mask_size()) {
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
445 if (lrg->_is_float || lrg->_is_vector) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
446 pressure[1] -= lrg->reg_pressure();
a61af66fc99e Initial load
duke
parents:
diff changeset
447 if( pressure[1] == (uint)FLOATPRESSURE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
448 hrp_index[1] = where;
8867
b808febcad9a 8010281: Remove code that is never executed
neliasso
parents: 7196
diff changeset
449 if( pressure[1] > b->_freg_pressure )
b808febcad9a 8010281: Remove code that is never executed
neliasso
parents: 7196
diff changeset
450 b->_freg_pressure = pressure[1]+1;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452 } else if( lrg->mask().overlap(*Matcher::idealreg2regmask[Op_RegI]) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 pressure[0] -= lrg->reg_pressure();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 if( pressure[0] == (uint)INTPRESSURE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 hrp_index[0] = where;
8867
b808febcad9a 8010281: Remove code that is never executed
neliasso
parents: 7196
diff changeset
456 if( pressure[0] > b->_reg_pressure )
b808febcad9a 8010281: Remove code that is never executed
neliasso
parents: 7196
diff changeset
457 b->_reg_pressure = pressure[0]+1;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 //------------------------------build_ifg_physical-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
464 // Build the interference graph using physical registers when available.
a61af66fc99e Initial load
duke
parents:
diff changeset
465 // That is, if 2 live ranges are simultaneously alive but in their acceptable
a61af66fc99e Initial load
duke
parents:
diff changeset
466 // register sets do not overlap, then they do not interfere.
a61af66fc99e Initial load
duke
parents:
diff changeset
467 uint PhaseChaitin::build_ifg_physical( ResourceArea *a ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 NOT_PRODUCT( Compile::TracePhase t3("buildIFG", &_t_buildIFGphysical, TimeCompiler); )
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 uint spill_reg = LRG::SPILL_REG;
a61af66fc99e Initial load
duke
parents:
diff changeset
471 uint must_spill = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 // For all blocks (in any order) do...
a61af66fc99e Initial load
duke
parents:
diff changeset
474 for( uint i = 0; i < _cfg._num_blocks; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 Block *b = _cfg._blocks[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // Clone (rather than smash in place) the liveout info, so it is alive
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // for the "collect_gc_info" phase later.
a61af66fc99e Initial load
duke
parents:
diff changeset
478 IndexSet liveout(_live->live(b));
a61af66fc99e Initial load
duke
parents:
diff changeset
479 uint last_inst = b->end_idx();
566
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
480 // Compute first nonphi node index
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
481 uint first_inst;
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
482 for( first_inst = 1; first_inst < last_inst; first_inst++ )
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
483 if( !b->_nodes[first_inst]->is_Phi() )
0
a61af66fc99e Initial load
duke
parents:
diff changeset
484 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
485
566
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
486 // Spills could be inserted before CreateEx node which should be
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
487 // first instruction in block after Phis. Move CreateEx up.
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
488 for( uint insidx = first_inst; insidx < last_inst; insidx++ ) {
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
489 Node *ex = b->_nodes[insidx];
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
490 if( ex->is_SpillCopy() ) continue;
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
491 if( insidx > first_inst && ex->is_Mach() &&
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
492 ex->as_Mach()->ideal_Opcode() == Op_CreateEx ) {
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
493 // If the CreateEx isn't above all the MachSpillCopies
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
494 // then move it to the top.
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
495 b->_nodes.remove(insidx);
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
496 b->_nodes.insert(first_inst, ex);
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
497 }
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
498 // Stop once a CreateEx or any other node is found
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
499 break;
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
500 }
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
501
0
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // Reset block's register pressure values for each ifg construction
a61af66fc99e Initial load
duke
parents:
diff changeset
503 uint pressure[2], hrp_index[2];
a61af66fc99e Initial load
duke
parents:
diff changeset
504 pressure[0] = pressure[1] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
505 hrp_index[0] = hrp_index[1] = last_inst+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 b->_reg_pressure = b->_freg_pressure = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
507 // Liveout things are presumed live for the whole block. We accumulate
a61af66fc99e Initial load
duke
parents:
diff changeset
508 // 'area' accordingly. If they get killed in the block, we'll subtract
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // the unused part of the block from the area.
566
91263420e1c6 6791852: assert(b->_nodes[insidx] == n,"got insidx set incorrectly")
kvn
parents: 380
diff changeset
510 int inst_count = last_inst - first_inst;
369
5f85534046c2 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 295
diff changeset
511 double cost = (inst_count <= 0) ? 0.0 : b->_freq * double(inst_count);
5f85534046c2 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 295
diff changeset
512 assert(!(cost < 0.0), "negative spill cost" );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
513 IndexSetIterator elements(&liveout);
a61af66fc99e Initial load
duke
parents:
diff changeset
514 uint lidx;
a61af66fc99e Initial load
duke
parents:
diff changeset
515 while ((lidx = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 LRG &lrg = lrgs(lidx);
a61af66fc99e Initial load
duke
parents:
diff changeset
517 lrg._area += cost;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // Compute initial register pressure
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
519 if (lrg.mask().is_UP() && lrg.mask_size()) {
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
520 if (lrg._is_float || lrg._is_vector) { // Count float pressure
0
a61af66fc99e Initial load
duke
parents:
diff changeset
521 pressure[1] += lrg.reg_pressure();
a61af66fc99e Initial load
duke
parents:
diff changeset
522 if( pressure[1] > b->_freg_pressure )
a61af66fc99e Initial load
duke
parents:
diff changeset
523 b->_freg_pressure = pressure[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // Count int pressure, but do not count the SP, flags
a61af66fc99e Initial load
duke
parents:
diff changeset
525 } else if( lrgs(lidx).mask().overlap(*Matcher::idealreg2regmask[Op_RegI]) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 pressure[0] += lrg.reg_pressure();
a61af66fc99e Initial load
duke
parents:
diff changeset
527 if( pressure[0] > b->_reg_pressure )
a61af66fc99e Initial load
duke
parents:
diff changeset
528 b->_reg_pressure = pressure[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 assert( pressure[0] == count_int_pressure (&liveout), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
533 assert( pressure[1] == count_float_pressure(&liveout), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
534
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // The IFG is built by a single reverse pass over each basic block.
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // Starting with the known live-out set, we remove things that get
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // defined and add things that become live (essentially executing one
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // pass of a standard LIVE analysis). Just before a Node defines a value
a61af66fc99e Initial load
duke
parents:
diff changeset
539 // (and removes it from the live-ness set) that value is certainly live.
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // The defined value interferes with everything currently live. The
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // value is then removed from the live-ness set and it's inputs are added
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // to the live-ness set.
a61af66fc99e Initial load
duke
parents:
diff changeset
543 uint j;
a61af66fc99e Initial load
duke
parents:
diff changeset
544 for( j = last_inst + 1; j > 1; j-- ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 Node *n = b->_nodes[j - 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // Get value being defined
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
548 uint r = _lrg_map.live_range_id(n);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
549
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // Some special values do not allocate
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
551 if(r) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
552 // A DEF normally costs block frequency; rematerialized values are
a61af66fc99e Initial load
duke
parents:
diff changeset
553 // removed from the DEF sight, so LOWER costs here.
a61af66fc99e Initial load
duke
parents:
diff changeset
554 lrgs(r)._cost += n->rematerialize() ? 0 : b->_freq;
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // If it is not live, then this instruction is dead. Probably caused
a61af66fc99e Initial load
duke
parents:
diff changeset
557 // by spilling and rematerialization. Who cares why, yank this baby.
a61af66fc99e Initial load
duke
parents:
diff changeset
558 if( !liveout.member(r) && n->Opcode() != Op_SafePoint ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
559 Node *def = n->in(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
560 if( !n->is_Proj() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
561 // Could also be a flags-projection of a dead ADD or such.
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
562 (_lrg_map.live_range_id(def) && !liveout.member(_lrg_map.live_range_id(def)))) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
563 b->_nodes.remove(j - 1);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
564 if (lrgs(r)._def == n) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
565 lrgs(r)._def = 0;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
566 }
7196
2aff40cb4703 7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents: 6179
diff changeset
567 n->disconnect_inputs(NULL, C);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
568 _cfg._bbs.map(n->_idx,NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
569 n->replace_by(C->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // Since yanking a Node from block, high pressure moves up one
a61af66fc99e Initial load
duke
parents:
diff changeset
571 hrp_index[0]--;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 hrp_index[1]--;
a61af66fc99e Initial load
duke
parents:
diff changeset
573 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 // Fat-projections kill many registers which cannot be used to
a61af66fc99e Initial load
duke
parents:
diff changeset
577 // hold live ranges.
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
578 if (lrgs(r)._fat_proj) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
579 // Count the int-only registers
a61af66fc99e Initial load
duke
parents:
diff changeset
580 RegMask itmp = lrgs(r).mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
581 itmp.AND(*Matcher::idealreg2regmask[Op_RegI]);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 int iregs = itmp.Size();
a61af66fc99e Initial load
duke
parents:
diff changeset
583 if( pressure[0]+iregs > b->_reg_pressure )
a61af66fc99e Initial load
duke
parents:
diff changeset
584 b->_reg_pressure = pressure[0]+iregs;
a61af66fc99e Initial load
duke
parents:
diff changeset
585 if( pressure[0] <= (uint)INTPRESSURE &&
a61af66fc99e Initial load
duke
parents:
diff changeset
586 pressure[0]+iregs > (uint)INTPRESSURE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
587 hrp_index[0] = j-1;
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589 // Count the float-only registers
a61af66fc99e Initial load
duke
parents:
diff changeset
590 RegMask ftmp = lrgs(r).mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
591 ftmp.AND(*Matcher::idealreg2regmask[Op_RegD]);
a61af66fc99e Initial load
duke
parents:
diff changeset
592 int fregs = ftmp.Size();
a61af66fc99e Initial load
duke
parents:
diff changeset
593 if( pressure[1]+fregs > b->_freg_pressure )
a61af66fc99e Initial load
duke
parents:
diff changeset
594 b->_freg_pressure = pressure[1]+fregs;
a61af66fc99e Initial load
duke
parents:
diff changeset
595 if( pressure[1] <= (uint)FLOATPRESSURE &&
a61af66fc99e Initial load
duke
parents:
diff changeset
596 pressure[1]+fregs > (uint)FLOATPRESSURE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
597 hrp_index[1] = j-1;
a61af66fc99e Initial load
duke
parents:
diff changeset
598 }
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600
a61af66fc99e Initial load
duke
parents:
diff changeset
601 } else { // Else it is live
a61af66fc99e Initial load
duke
parents:
diff changeset
602 // A DEF also ends 'area' partway through the block.
a61af66fc99e Initial load
duke
parents:
diff changeset
603 lrgs(r)._area -= cost;
369
5f85534046c2 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 295
diff changeset
604 assert(!(lrgs(r)._area < 0.0), "negative spill area" );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 // Insure high score for immediate-use spill copies so they get a color
a61af66fc99e Initial load
duke
parents:
diff changeset
607 if( n->is_SpillCopy()
295
ea18057223c4 6732194: Data corruption dependent on -server/-client/-Xbatch
never
parents: 0
diff changeset
608 && lrgs(r).is_singledef() // MultiDef live range can still split
0
a61af66fc99e Initial load
duke
parents:
diff changeset
609 && n->outcnt() == 1 // and use must be in this block
a61af66fc99e Initial load
duke
parents:
diff changeset
610 && _cfg._bbs[n->unique_out()->_idx] == b ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 // All single-use MachSpillCopy(s) that immediately precede their
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // use must color early. If a longer live range steals their
a61af66fc99e Initial load
duke
parents:
diff changeset
613 // color, the spill copy will split and may push another spill copy
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // further away resulting in an infinite spill-split-retry cycle.
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // Assigning a zero area results in a high score() and a good
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // location in the simplify list.
a61af66fc99e Initial load
duke
parents:
diff changeset
617 //
a61af66fc99e Initial load
duke
parents:
diff changeset
618
a61af66fc99e Initial load
duke
parents:
diff changeset
619 Node *single_use = n->unique_out();
a61af66fc99e Initial load
duke
parents:
diff changeset
620 assert( b->find_node(single_use) >= j, "Use must be later in block");
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // Use can be earlier in block if it is a Phi, but then I should be a MultiDef
a61af66fc99e Initial load
duke
parents:
diff changeset
622
a61af66fc99e Initial load
duke
parents:
diff changeset
623 // Find first non SpillCopy 'm' that follows the current instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // (j - 1) is index for current instruction 'n'
a61af66fc99e Initial load
duke
parents:
diff changeset
625 Node *m = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
626 for( uint i = j; i <= last_inst && m->is_SpillCopy(); ++i ) { m = b->_nodes[i]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
627 if( m == single_use ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
628 lrgs(r)._area = 0.0;
a61af66fc99e Initial load
duke
parents:
diff changeset
629 }
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631
a61af66fc99e Initial load
duke
parents:
diff changeset
632 // Remove from live-out set
a61af66fc99e Initial load
duke
parents:
diff changeset
633 if( liveout.remove(r) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 // Adjust register pressure.
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // Capture last hi-to-lo pressure transition
a61af66fc99e Initial load
duke
parents:
diff changeset
636 lower_pressure( &lrgs(r), j-1, b, pressure, hrp_index );
a61af66fc99e Initial load
duke
parents:
diff changeset
637 assert( pressure[0] == count_int_pressure (&liveout), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
638 assert( pressure[1] == count_float_pressure(&liveout), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // Copies do not define a new value and so do not interfere.
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // Remove the copies source from the liveout set before interfering.
a61af66fc99e Initial load
duke
parents:
diff changeset
643 uint idx = n->is_Copy();
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
644 if (idx) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
645 uint x = _lrg_map.live_range_id(n->in(idx));
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
646 if (liveout.remove(x)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
647 lrgs(x)._area -= cost;
a61af66fc99e Initial load
duke
parents:
diff changeset
648 // Adjust register pressure.
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
649 lower_pressure(&lrgs(x), j-1, b, pressure, hrp_index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
650 assert( pressure[0] == count_int_pressure (&liveout), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
651 assert( pressure[1] == count_float_pressure(&liveout), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
653 }
a61af66fc99e Initial load
duke
parents:
diff changeset
654 } // End of if live or not
a61af66fc99e Initial load
duke
parents:
diff changeset
655
a61af66fc99e Initial load
duke
parents:
diff changeset
656 // Interfere with everything live. If the defined value must
a61af66fc99e Initial load
duke
parents:
diff changeset
657 // go in a particular register, just remove that register from
a61af66fc99e Initial load
duke
parents:
diff changeset
658 // all conflicting parties and avoid the interference.
a61af66fc99e Initial load
duke
parents:
diff changeset
659
a61af66fc99e Initial load
duke
parents:
diff changeset
660 // Make exclusions for rematerializable defs. Since rematerializable
a61af66fc99e Initial load
duke
parents:
diff changeset
661 // DEFs are not bound but the live range is, some uses must be bound.
a61af66fc99e Initial load
duke
parents:
diff changeset
662 // If we spill live range 'r', it can rematerialize at each use site
a61af66fc99e Initial load
duke
parents:
diff changeset
663 // according to its bindings.
a61af66fc99e Initial load
duke
parents:
diff changeset
664 const RegMask &rmask = lrgs(r).mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
665 if( lrgs(r).is_bound() && !(n->rematerialize()) && rmask.is_NotEmpty() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 // Check for common case
a61af66fc99e Initial load
duke
parents:
diff changeset
667 int r_size = lrgs(r).num_regs();
a61af66fc99e Initial load
duke
parents:
diff changeset
668 OptoReg::Name r_reg = (r_size == 1) ? rmask.find_first_elem() : OptoReg::Physical;
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
669 // Smear odd bits
0
a61af66fc99e Initial load
duke
parents:
diff changeset
670 IndexSetIterator elements(&liveout);
a61af66fc99e Initial load
duke
parents:
diff changeset
671 uint l;
a61af66fc99e Initial load
duke
parents:
diff changeset
672 while ((l = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
673 LRG &lrg = lrgs(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // If 'l' must spill already, do not further hack his bits.
a61af66fc99e Initial load
duke
parents:
diff changeset
675 // He'll get some interferences and be forced to spill later.
a61af66fc99e Initial load
duke
parents:
diff changeset
676 if( lrg._must_spill ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // Remove bound register(s) from 'l's choices
a61af66fc99e Initial load
duke
parents:
diff changeset
678 RegMask old = lrg.mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
679 uint old_size = lrg.mask_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
680 // Remove the bits from LRG 'r' from LRG 'l' so 'l' no
a61af66fc99e Initial load
duke
parents:
diff changeset
681 // longer interferes with 'r'. If 'l' requires aligned
a61af66fc99e Initial load
duke
parents:
diff changeset
682 // adjacent pairs, subtract out bit pairs.
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
683 assert(!lrg._is_vector || !lrg._fat_proj, "sanity");
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
684 if (lrg.num_regs() > 1 && !lrg._fat_proj) {
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
685 RegMask r2mask = rmask;
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
686 // Leave only aligned set of bits.
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
687 r2mask.smear_to_sets(lrg.num_regs());
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
688 // It includes vector case.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
689 lrg.SUBTRACT( r2mask );
a61af66fc99e Initial load
duke
parents:
diff changeset
690 lrg.compute_set_mask_size();
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
691 } else if( r_size != 1 ) { // fat proj
0
a61af66fc99e Initial load
duke
parents:
diff changeset
692 lrg.SUBTRACT( rmask );
a61af66fc99e Initial load
duke
parents:
diff changeset
693 lrg.compute_set_mask_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
694 } else { // Common case: size 1 bound removal
a61af66fc99e Initial load
duke
parents:
diff changeset
695 if( lrg.mask().Member(r_reg) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 lrg.Remove(r_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
697 lrg.set_mask_size(lrg.mask().is_AllStack() ? 65535:old_size-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
698 }
a61af66fc99e Initial load
duke
parents:
diff changeset
699 }
a61af66fc99e Initial load
duke
parents:
diff changeset
700 // If 'l' goes completely dry, it must spill.
a61af66fc99e Initial load
duke
parents:
diff changeset
701 if( lrg.not_free() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 // Give 'l' some kind of reasonable mask, so he picks up
a61af66fc99e Initial load
duke
parents:
diff changeset
703 // interferences (and will spill later).
a61af66fc99e Initial load
duke
parents:
diff changeset
704 lrg.set_mask( old );
a61af66fc99e Initial load
duke
parents:
diff changeset
705 lrg.set_mask_size(old_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
706 must_spill++;
a61af66fc99e Initial load
duke
parents:
diff changeset
707 lrg._must_spill = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
708 lrg.set_reg(OptoReg::Name(LRG::SPILL_REG));
a61af66fc99e Initial load
duke
parents:
diff changeset
709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
710 }
a61af66fc99e Initial load
duke
parents:
diff changeset
711 } // End of if bound
a61af66fc99e Initial load
duke
parents:
diff changeset
712
a61af66fc99e Initial load
duke
parents:
diff changeset
713 // Now interference with everything that is live and has
a61af66fc99e Initial load
duke
parents:
diff changeset
714 // compatible register sets.
a61af66fc99e Initial load
duke
parents:
diff changeset
715 interfere_with_live(r,&liveout);
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 } // End of if normal register-allocated value
a61af66fc99e Initial load
duke
parents:
diff changeset
718
369
5f85534046c2 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 295
diff changeset
719 // Area remaining in the block
5f85534046c2 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 295
diff changeset
720 inst_count--;
5f85534046c2 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 295
diff changeset
721 cost = (inst_count <= 0) ? 0.0 : b->_freq * double(inst_count);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
722
a61af66fc99e Initial load
duke
parents:
diff changeset
723 // Make all inputs live
a61af66fc99e Initial load
duke
parents:
diff changeset
724 if( !n->is_Phi() ) { // Phi function uses come from prior block
a61af66fc99e Initial load
duke
parents:
diff changeset
725 JVMState* jvms = n->jvms();
a61af66fc99e Initial load
duke
parents:
diff changeset
726 uint debug_start = jvms ? jvms->debug_start() : 999999;
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // Start loop at 1 (skip control edge) for most Nodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
728 // SCMemProj's might be the sole use of a StoreLConditional.
a61af66fc99e Initial load
duke
parents:
diff changeset
729 // While StoreLConditionals set memory (the SCMemProj use)
a61af66fc99e Initial load
duke
parents:
diff changeset
730 // they also def flags; if that flag def is unused the
a61af66fc99e Initial load
duke
parents:
diff changeset
731 // allocator sees a flag-setting instruction with no use of
a61af66fc99e Initial load
duke
parents:
diff changeset
732 // the flags and assumes it's dead. This keeps the (useless)
a61af66fc99e Initial load
duke
parents:
diff changeset
733 // flag-setting behavior alive while also keeping the (useful)
a61af66fc99e Initial load
duke
parents:
diff changeset
734 // memory update effect.
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
735 for (uint k = ((n->Opcode() == Op_SCMemProj) ? 0:1); k < n->req(); k++) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
736 Node *def = n->in(k);
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
737 uint x = _lrg_map.live_range_id(def);
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
738 if (!x) {
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
739 continue;
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
740 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
741 LRG &lrg = lrgs(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
742 // No use-side cost for spilling debug info
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
743 if (k < debug_start) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
744 // A USE costs twice block frequency (once for the Load, once
a61af66fc99e Initial load
duke
parents:
diff changeset
745 // for a Load-delay). Rematerialized uses only cost once.
a61af66fc99e Initial load
duke
parents:
diff changeset
746 lrg._cost += (def->rematerialize() ? b->_freq : (b->_freq + b->_freq));
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
747 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
748 // It is live now
10111
8373c19be854 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 8867
diff changeset
749 if (liveout.insert(x)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
750 // Newly live things assumed live from here to top of block
a61af66fc99e Initial load
duke
parents:
diff changeset
751 lrg._area += cost;
a61af66fc99e Initial load
duke
parents:
diff changeset
752 // Adjust register pressure
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
753 if (lrg.mask().is_UP() && lrg.mask_size()) {
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 1972
diff changeset
754 if (lrg._is_float || lrg._is_vector) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
755 pressure[1] += lrg.reg_pressure();
a61af66fc99e Initial load
duke
parents:
diff changeset
756 if( pressure[1] > b->_freg_pressure )
a61af66fc99e Initial load
duke
parents:
diff changeset
757 b->_freg_pressure = pressure[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
758 } else if( lrg.mask().overlap(*Matcher::idealreg2regmask[Op_RegI]) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
759 pressure[0] += lrg.reg_pressure();
a61af66fc99e Initial load
duke
parents:
diff changeset
760 if( pressure[0] > b->_reg_pressure )
a61af66fc99e Initial load
duke
parents:
diff changeset
761 b->_reg_pressure = pressure[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
762 }
a61af66fc99e Initial load
duke
parents:
diff changeset
763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
764 assert( pressure[0] == count_int_pressure (&liveout), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
765 assert( pressure[1] == count_float_pressure(&liveout), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
766 }
369
5f85534046c2 6750588: assert(lrg._area >= 0,"negative spill area") running NSK stmp0101 test
rasbold
parents: 295
diff changeset
767 assert(!(lrg._area < 0.0), "negative spill area" );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
768 }
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770 } // End of reverse pass over all instructions in block
a61af66fc99e Initial load
duke
parents:
diff changeset
771
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // If we run off the top of the block with high pressure and
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // never see a hi-to-low pressure transition, just record that
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // the whole block is high pressure.
a61af66fc99e Initial load
duke
parents:
diff changeset
775 if( pressure[0] > (uint)INTPRESSURE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 hrp_index[0] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
777 if( pressure[0] > b->_reg_pressure )
a61af66fc99e Initial load
duke
parents:
diff changeset
778 b->_reg_pressure = pressure[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
779 }
a61af66fc99e Initial load
duke
parents:
diff changeset
780 if( pressure[1] > (uint)FLOATPRESSURE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
781 hrp_index[1] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 if( pressure[1] > b->_freg_pressure )
a61af66fc99e Initial load
duke
parents:
diff changeset
783 b->_freg_pressure = pressure[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
784 }
a61af66fc99e Initial load
duke
parents:
diff changeset
785
a61af66fc99e Initial load
duke
parents:
diff changeset
786 // Compute high pressure indice; avoid landing in the middle of projnodes
a61af66fc99e Initial load
duke
parents:
diff changeset
787 j = hrp_index[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
788 if( j < b->_nodes.size() && j < b->end_idx()+1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
789 Node *cur = b->_nodes[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
790 while( cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
791 j--;
a61af66fc99e Initial load
duke
parents:
diff changeset
792 cur = b->_nodes[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
793 }
a61af66fc99e Initial load
duke
parents:
diff changeset
794 }
a61af66fc99e Initial load
duke
parents:
diff changeset
795 b->_ihrp_index = j;
a61af66fc99e Initial load
duke
parents:
diff changeset
796 j = hrp_index[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
797 if( j < b->_nodes.size() && j < b->end_idx()+1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
798 Node *cur = b->_nodes[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
799 while( cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
800 j--;
a61af66fc99e Initial load
duke
parents:
diff changeset
801 cur = b->_nodes[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
803 }
a61af66fc99e Initial load
duke
parents:
diff changeset
804 b->_fhrp_index = j;
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
807 // Gather Register Pressure Statistics
a61af66fc99e Initial load
duke
parents:
diff changeset
808 if( PrintOptoStatistics ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
809 if( b->_reg_pressure > (uint)INTPRESSURE || b->_freg_pressure > (uint)FLOATPRESSURE )
a61af66fc99e Initial load
duke
parents:
diff changeset
810 _high_pressure++;
a61af66fc99e Initial load
duke
parents:
diff changeset
811 else
a61af66fc99e Initial load
duke
parents:
diff changeset
812 _low_pressure++;
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
815 } // End of for all blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
816
a61af66fc99e Initial load
duke
parents:
diff changeset
817 return must_spill;
a61af66fc99e Initial load
duke
parents:
diff changeset
818 }