annotate src/share/vm/opto/postaloc.cpp @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents 89e0543e1737
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 948
diff changeset
2 * Copyright (c) 1998, 2009, 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: 948
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 948
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: 948
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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_postaloc.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // see if this register kind does not requires two registers
a61af66fc99e Initial load
duke
parents:
diff changeset
29 static bool is_single_register(uint x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
31 return (x != Op_RegD && x != Op_RegL && x != Op_RegP);
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
33 return (x != Op_RegD && x != Op_RegL);
a61af66fc99e Initial load
duke
parents:
diff changeset
34 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
35 }
a61af66fc99e Initial load
duke
parents:
diff changeset
36
400
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
37 //---------------------------may_be_copy_of_callee-----------------------------
0
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // Check to see if we can possibly be a copy of a callee-save value.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 bool PhaseChaitin::may_be_copy_of_callee( Node *def ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Short circuit if there are no callee save registers
a61af66fc99e Initial load
duke
parents:
diff changeset
41 if (_matcher.number_of_saved_registers() == 0) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Expect only a spill-down and reload on exit for callee-save spills.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Chains of copies cannot be deep.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // 5008997 - This is wishful thinking. Register allocator seems to
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // be splitting live ranges for callee save registers to such
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // an extent that in large methods the chains can be very long
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // (50+). The conservative answer is to return true if we don't
605
98cb887364d3 6810672: Comment typos
twisti
parents: 400
diff changeset
49 // know as this prevents optimizations from occurring.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 const int limit = 60;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 for( i=0; i < limit; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if( def->is_Proj() && def->in(0)->is_Start() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
55 _matcher.is_save_on_entry(lrgs(n2lidx(def)).reg()) )
a61af66fc99e Initial load
duke
parents:
diff changeset
56 return true; // Direct use of callee-save proj
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if( def->is_Copy() ) // Copies carry value through
a61af66fc99e Initial load
duke
parents:
diff changeset
58 def = def->in(def->is_Copy());
a61af66fc99e Initial load
duke
parents:
diff changeset
59 else if( def->is_Phi() ) // Phis can merge it from any direction
a61af66fc99e Initial load
duke
parents:
diff changeset
60 def = def->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 else
a61af66fc99e Initial load
duke
parents:
diff changeset
62 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 guarantee(def != NULL, "must not resurrect dead copy");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // If we reached the end and didn't find a callee save proj
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // then this may be a callee save proj so we return true
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // as the conservative answer. If we didn't reach then end
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // we must have discovered that it was not a callee save
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // else we would have returned.
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return i == limit;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 //------------------------------yank_if_dead-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // Removed an edge from 'old'. Yank if dead. Return adjustment counts to
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // iterators in the current block.
a61af66fc99e Initial load
duke
parents:
diff changeset
78 int PhaseChaitin::yank_if_dead( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 int blk_adjust=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 while (old->outcnt() == 0 && old != C->top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 Block *oldb = _cfg._bbs[old->_idx];
a61af66fc99e Initial load
duke
parents:
diff changeset
82 oldb->find_remove(old);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // Count 1 if deleting an instruction from the current block
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if( oldb == current_block ) blk_adjust++;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _cfg._bbs.map(old->_idx,NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 OptoReg::Name old_reg = lrgs(n2lidx(old)).reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if( regnd && (*regnd)[old_reg]==old ) { // Instruction is currently available?
a61af66fc99e Initial load
duke
parents:
diff changeset
88 value->map(old_reg,NULL); // Yank from value/regnd maps
a61af66fc99e Initial load
duke
parents:
diff changeset
89 regnd->map(old_reg,NULL); // This register's value is now unknown
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
91 assert(old->req() <= 2, "can't handle more inputs");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92 Node *tmp = old->req() > 1 ? old->in(1) : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 old->disconnect_inputs(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if( !tmp ) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 old = tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return blk_adjust;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 //------------------------------use_prior_register-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Use the prior value instead of the current value, in an effort to make
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // the current value go dead. Return block iterator adjustment, in case
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // we yank some instructions from this block.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 int PhaseChaitin::use_prior_register( Node *n, uint idx, Node *def, Block *current_block, Node_List &value, Node_List &regnd ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // No effect?
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if( def == n->in(idx) ) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Def is currently dead and can be removed? Do not resurrect
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if( def->outcnt() == 0 ) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Not every pair of physical registers are assignment compatible,
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // e.g. on sparc floating point registers are not assignable to integer
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // registers.
a61af66fc99e Initial load
duke
parents:
diff changeset
113 const LRG &def_lrg = lrgs(n2lidx(def));
a61af66fc99e Initial load
duke
parents:
diff changeset
114 OptoReg::Name def_reg = def_lrg.reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
115 const RegMask &use_mask = n->in_RegMask(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 bool can_use = ( RegMask::can_represent(def_reg) ? (use_mask.Member(def_reg) != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
117 : (use_mask.is_AllStack() != 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Check for a copy to or from a misaligned pair.
a61af66fc99e Initial load
duke
parents:
diff changeset
119 can_use = can_use && !use_mask.is_misaligned_Pair() && !def_lrg.mask().is_misaligned_Pair();
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (!can_use)
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Capture the old def in case it goes dead...
a61af66fc99e Initial load
duke
parents:
diff changeset
125 Node *old = n->in(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Save-on-call copies can only be elided if the entire copy chain can go
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // away, lest we get the same callee-save value alive in 2 locations at
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // once. We check for the obvious trivial case here. Although it can
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // sometimes be elided with cooperation outside our scope, here we will just
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // miss the opportunity. :-(
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if( may_be_copy_of_callee(def) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if( old->outcnt() > 1 ) return 0; // We're the not last user
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int idx = old->is_Copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 assert( idx, "chain of copies being removed" );
a61af66fc99e Initial load
duke
parents:
diff changeset
136 Node *old2 = old->in(idx); // Chain of copies
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if( old2->outcnt() > 1 ) return 0; // old is not the last user
a61af66fc99e Initial load
duke
parents:
diff changeset
138 int idx2 = old2->is_Copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if( !idx2 ) return 0; // Not a chain of 2 copies
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if( def != old2->in(idx2) ) return 0; // Chain of exactly 2 copies
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Use the new def
a61af66fc99e Initial load
duke
parents:
diff changeset
144 n->set_req(idx,def);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 _post_alloc++;
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // Is old def now dead? We successfully yanked a copy?
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return yank_if_dead(old,current_block,&value,&regnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 //------------------------------skip_copies------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // Skip through any number of copies (that don't mod oop-i-ness)
a61af66fc99e Initial load
duke
parents:
diff changeset
154 Node *PhaseChaitin::skip_copies( Node *c ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 int idx = c->is_Copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 uint is_oop = lrgs(n2lidx(c))._is_oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 while (idx != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 guarantee(c->in(idx) != NULL, "must not resurrect dead copy");
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (lrgs(n2lidx(c->in(idx)))._is_oop != is_oop)
a61af66fc99e Initial load
duke
parents:
diff changeset
160 break; // casting copy, not the same value
a61af66fc99e Initial load
duke
parents:
diff changeset
161 c = c->in(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 idx = c->is_Copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return c;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 //------------------------------elide_copy-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Remove (bypass) copies along Node n, edge k.
a61af66fc99e Initial load
duke
parents:
diff changeset
169 int PhaseChaitin::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
170 int blk_adjust = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 uint nk_idx = n2lidx(n->in(k));
a61af66fc99e Initial load
duke
parents:
diff changeset
173 OptoReg::Name nk_reg = lrgs(nk_idx ).reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Remove obvious same-register copies
a61af66fc99e Initial load
duke
parents:
diff changeset
176 Node *x = n->in(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 int idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 while( (idx=x->is_Copy()) != 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 Node *copy = x->in(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 guarantee(copy != NULL, "must not resurrect dead copy");
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if( lrgs(n2lidx(copy)).reg() != nk_reg ) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 blk_adjust += use_prior_register(n,k,copy,current_block,value,regnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if( n->in(k) != copy ) break; // Failed for some cutout?
a61af66fc99e Initial load
duke
parents:
diff changeset
184 x = copy; // Progress, try again
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Phis and 2-address instructions cannot change registers so easily - their
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // outputs must match their input.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 if( !can_change_regs )
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return blk_adjust; // Only check stupid copies!
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Loop backedges won't have a value-mapping yet
a61af66fc99e Initial load
duke
parents:
diff changeset
193 if( &value == NULL ) return blk_adjust;
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // Skip through all copies to the _value_ being used. Do not change from
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // int to pointer. This attempts to jump through a chain of copies, where
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // intermediate copies might be illegal, i.e., value is stored down to stack
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // then reloaded BUT survives in a register the whole way.
a61af66fc99e Initial load
duke
parents:
diff changeset
199 Node *val = skip_copies(n->in(k));
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if( val == x ) return blk_adjust; // No progress?
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 bool single = is_single_register(val->ideal_reg());
a61af66fc99e Initial load
duke
parents:
diff changeset
204 uint val_idx = n2lidx(val);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 OptoReg::Name val_reg = lrgs(val_idx).reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // See if it happens to already be in the correct register!
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // (either Phi's direct register, or the common case of the name
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // never-clobbered original-def register)
a61af66fc99e Initial load
duke
parents:
diff changeset
210 if( value[val_reg] == val &&
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // Doubles check both halves
a61af66fc99e Initial load
duke
parents:
diff changeset
212 ( single || value[val_reg-1] == val ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 blk_adjust += use_prior_register(n,k,regnd[val_reg],current_block,value,regnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 if( n->in(k) == regnd[val_reg] ) // Success! Quit trying
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return blk_adjust;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // See if we can skip the copy by changing registers. Don't change from
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // using a register to using the stack unless we know we can remove a
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // copy-load. Otherwise we might end up making a pile of Intel cisc-spill
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // ops reading from memory instead of just loading once and using the
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // register.
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // Also handle duplicate copies here.
a61af66fc99e Initial load
duke
parents:
diff changeset
225 const Type *t = val->is_Con() ? val->bottom_type() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // Scan all registers to see if this value is around already
a61af66fc99e Initial load
duke
parents:
diff changeset
228 for( uint reg = 0; reg < (uint)_max_reg; reg++ ) {
400
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
229 if (reg == (uint)nk_reg) {
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
230 // Found ourselves so check if there is only one user of this
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
231 // copy and keep on searching for a better copy if so.
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
232 bool ignore_self = true;
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
233 x = n->in(k);
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
234 DUIterator_Fast imax, i = x->fast_outs(imax);
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
235 Node* first = x->fast_out(i); i++;
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
236 while (i < imax && ignore_self) {
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
237 Node* use = x->fast_out(i); i++;
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
238 if (use != first) ignore_self = false;
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
239 }
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
240 if (ignore_self) continue;
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
241 }
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 196
diff changeset
242
0
a61af66fc99e Initial load
duke
parents:
diff changeset
243 Node *vv = value[reg];
a61af66fc99e Initial load
duke
parents:
diff changeset
244 if( !single ) { // Doubles check for aligned-adjacent pair
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if( (reg&1)==0 ) continue; // Wrong half of a pair
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if( vv != value[reg-1] ) continue; // Not a complete pair
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 if( vv == val || // Got a direct hit?
a61af66fc99e Initial load
duke
parents:
diff changeset
249 (t && vv && vv->bottom_type() == t && vv->is_Mach() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
250 vv->as_Mach()->rule() == val->as_Mach()->rule()) ) { // Or same constant?
a61af66fc99e Initial load
duke
parents:
diff changeset
251 assert( !n->is_Phi(), "cannot change registers at a Phi so easily" );
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if( OptoReg::is_stack(nk_reg) || // CISC-loading from stack OR
a61af66fc99e Initial load
duke
parents:
diff changeset
253 OptoReg::is_reg(reg) || // turning into a register use OR
a61af66fc99e Initial load
duke
parents:
diff changeset
254 regnd[reg]->outcnt()==1 ) { // last use of a spill-load turns into a CISC use
a61af66fc99e Initial load
duke
parents:
diff changeset
255 blk_adjust += use_prior_register(n,k,regnd[reg],current_block,value,regnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 if( n->in(k) == regnd[reg] ) // Success! Quit trying
a61af66fc99e Initial load
duke
parents:
diff changeset
257 return blk_adjust;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 } // End of if not degrading to a stack
a61af66fc99e Initial load
duke
parents:
diff changeset
259 } // End of if found value in another register
a61af66fc99e Initial load
duke
parents:
diff changeset
260 } // End of scan all machine registers
a61af66fc99e Initial load
duke
parents:
diff changeset
261 return blk_adjust;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 //
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // Check if nreg already contains the constant value val. Normal copy
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // elimination doesn't doesn't work on constants because multiple
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // nodes can represent the same constant so the type and rule of the
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // MachNode must be checked to ensure equivalence.
a61af66fc99e Initial load
duke
parents:
diff changeset
270 //
70
b683f557224b 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 0
diff changeset
271 bool PhaseChaitin::eliminate_copy_of_constant(Node* val, Node* n,
b683f557224b 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 0
diff changeset
272 Block *current_block,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
273 Node_List& value, Node_List& regnd,
a61af66fc99e Initial load
duke
parents:
diff changeset
274 OptoReg::Name nreg, OptoReg::Name nreg2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if (value[nreg] != val && val->is_Con() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
276 value[nreg] != NULL && value[nreg]->is_Con() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
277 (nreg2 == OptoReg::Bad || value[nreg] == value[nreg2]) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
278 value[nreg]->bottom_type() == val->bottom_type() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
279 value[nreg]->as_Mach()->rule() == val->as_Mach()->rule()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // This code assumes that two MachNodes representing constants
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // which have the same rule and the same bottom type will produce
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // identical effects into a register. This seems like it must be
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // objectively true unless there are hidden inputs to the nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // but if that were to change this code would need to updated.
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Since they are equivalent the second one if redundant and can
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // be removed.
a61af66fc99e Initial load
duke
parents:
diff changeset
287 //
70
b683f557224b 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 0
diff changeset
288 // n will be replaced with the old value but n might have
0
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // kills projections associated with it so remove them now so that
605
98cb887364d3 6810672: Comment typos
twisti
parents: 400
diff changeset
290 // yank_if_dead will be able to eliminate the copy once the uses
0
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // have been transferred to the old[value].
70
b683f557224b 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 0
diff changeset
292 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
b683f557224b 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 0
diff changeset
293 Node* use = n->fast_out(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if (use->is_Proj() && use->outcnt() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // Kill projections have no users and one input
a61af66fc99e Initial load
duke
parents:
diff changeset
296 use->set_req(0, C->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
297 yank_if_dead(use, current_block, &value, &regnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 --i; --imax;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 _post_alloc++;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 //------------------------------post_allocate_copy_removal---------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // Post-Allocation peephole copy removal. We do this in 1 pass over the
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // basic blocks. We maintain a mapping of registers to Nodes (an array of
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // Nodes indexed by machine register or stack slot number). NULL means that a
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // register is not mapped to any Node. We can (want to have!) have several
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // registers map to the same Node. We walk forward over the instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // updating the mapping as we go. At merge points we force a NULL if we have
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // to merge 2 different Nodes into the same register. Phi functions will give
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // us a new Node if there is a proper value merging. Since the blocks are
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // arranged in some RPO, we will visit all parent blocks before visiting any
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // successor blocks (except at loops).
a61af66fc99e Initial load
duke
parents:
diff changeset
319 //
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // If we find a Copy we look to see if the Copy's source register is a stack
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // slot and that value has already been loaded into some machine register; if
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // so we use machine register directly. This turns a Load into a reg-reg
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // Move. We also look for reloads of identical constants.
a61af66fc99e Initial load
duke
parents:
diff changeset
324 //
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // When we see a use from a reg-reg Copy, we will attempt to use the copy's
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // source directly and make the copy go dead.
a61af66fc99e Initial load
duke
parents:
diff changeset
327 void PhaseChaitin::post_allocate_copy_removal() {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 NOT_PRODUCT( Compile::TracePhase t3("postAllocCopyRemoval", &_t_postAllocCopyRemoval, TimeCompiler); )
a61af66fc99e Initial load
duke
parents:
diff changeset
329 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // Need a mapping from basic block Node_Lists. We need a Node_List to
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // map from register number to value-producing Node.
a61af66fc99e Initial load
duke
parents:
diff changeset
333 Node_List **blk2value = NEW_RESOURCE_ARRAY( Node_List *, _cfg._num_blocks+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 memset( blk2value, 0, sizeof(Node_List*)*(_cfg._num_blocks+1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // Need a mapping from basic block Node_Lists. We need a Node_List to
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // map from register number to register-defining Node.
a61af66fc99e Initial load
duke
parents:
diff changeset
337 Node_List **blk2regnd = NEW_RESOURCE_ARRAY( Node_List *, _cfg._num_blocks+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
338 memset( blk2regnd, 0, sizeof(Node_List*)*(_cfg._num_blocks+1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // We keep unused Node_Lists on a free_list to avoid wasting
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
342 GrowableArray<Node_List*> free_list = GrowableArray<Node_List*>(16);
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // For all blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
345 for( uint i = 0; i < _cfg._num_blocks; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 uint j;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 Block *b = _cfg._blocks[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // Count of Phis in block
a61af66fc99e Initial load
duke
parents:
diff changeset
350 uint phi_dex;
a61af66fc99e Initial load
duke
parents:
diff changeset
351 for( phi_dex = 1; phi_dex < b->_nodes.size(); phi_dex++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 Node *phi = b->_nodes[phi_dex];
a61af66fc99e Initial load
duke
parents:
diff changeset
353 if( !phi->is_Phi() )
a61af66fc99e Initial load
duke
parents:
diff changeset
354 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // If any predecessor has not been visited, we do not know the state
a61af66fc99e Initial load
duke
parents:
diff changeset
358 // of registers at the start. Check for this, while updating copies
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // along Phi input edges
a61af66fc99e Initial load
duke
parents:
diff changeset
360 bool missing_some_inputs = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 Block *freed = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
362 for( j = 1; j < b->num_preds(); j++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 Block *pb = _cfg._bbs[b->pred(j)->_idx];
a61af66fc99e Initial load
duke
parents:
diff changeset
364 // Remove copies along phi edges
a61af66fc99e Initial load
duke
parents:
diff changeset
365 for( uint k=1; k<phi_dex; k++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
366 elide_copy( b->_nodes[k], j, b, *blk2value[pb->_pre_order], *blk2regnd[pb->_pre_order], false );
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if( blk2value[pb->_pre_order] ) { // Have a mapping on this edge?
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // See if this predecessor's mappings have been used by everybody
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // who wants them. If so, free 'em.
a61af66fc99e Initial load
duke
parents:
diff changeset
370 uint k;
a61af66fc99e Initial load
duke
parents:
diff changeset
371 for( k=0; k<pb->_num_succs; k++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
372 Block *pbsucc = pb->_succs[k];
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if( !blk2value[pbsucc->_pre_order] && pbsucc != b )
a61af66fc99e Initial load
duke
parents:
diff changeset
374 break; // Found a future user
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
376 if( k >= pb->_num_succs ) { // No more uses, free!
a61af66fc99e Initial load
duke
parents:
diff changeset
377 freed = pb; // Record last block freed
a61af66fc99e Initial load
duke
parents:
diff changeset
378 free_list.push(blk2value[pb->_pre_order]);
a61af66fc99e Initial load
duke
parents:
diff changeset
379 free_list.push(blk2regnd[pb->_pre_order]);
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381 } else { // This block has unvisited (loopback) inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
382 missing_some_inputs = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387 // Extract Node_List mappings. If 'freed' is non-zero, we just popped
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // 'freed's blocks off the list
a61af66fc99e Initial load
duke
parents:
diff changeset
389 Node_List &regnd = *(free_list.is_empty() ? new Node_List() : free_list.pop());
a61af66fc99e Initial load
duke
parents:
diff changeset
390 Node_List &value = *(free_list.is_empty() ? new Node_List() : free_list.pop());
a61af66fc99e Initial load
duke
parents:
diff changeset
391 assert( !freed || blk2value[freed->_pre_order] == &value, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
392 value.map(_max_reg,NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
393 regnd.map(_max_reg,NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 // Set mappings as OUR mappings
a61af66fc99e Initial load
duke
parents:
diff changeset
395 blk2value[b->_pre_order] = &value;
a61af66fc99e Initial load
duke
parents:
diff changeset
396 blk2regnd[b->_pre_order] = &regnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // Initialize value & regnd for this block
a61af66fc99e Initial load
duke
parents:
diff changeset
399 if( missing_some_inputs ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 // Some predecessor has not yet been visited; zap map to empty
a61af66fc99e Initial load
duke
parents:
diff changeset
401 for( uint k = 0; k < (uint)_max_reg; k++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 value.map(k,NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
403 regnd.map(k,NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 if( !freed ) { // Didn't get a freebie prior block
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // Must clone some data
a61af66fc99e Initial load
duke
parents:
diff changeset
408 freed = _cfg._bbs[b->pred(1)->_idx];
a61af66fc99e Initial load
duke
parents:
diff changeset
409 Node_List &f_value = *blk2value[freed->_pre_order];
a61af66fc99e Initial load
duke
parents:
diff changeset
410 Node_List &f_regnd = *blk2regnd[freed->_pre_order];
a61af66fc99e Initial load
duke
parents:
diff changeset
411 for( uint k = 0; k < (uint)_max_reg; k++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 value.map(k,f_value[k]);
a61af66fc99e Initial load
duke
parents:
diff changeset
413 regnd.map(k,f_regnd[k]);
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416 // Merge all inputs together, setting to NULL any conflicts.
a61af66fc99e Initial load
duke
parents:
diff changeset
417 for( j = 1; j < b->num_preds(); j++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 Block *pb = _cfg._bbs[b->pred(j)->_idx];
a61af66fc99e Initial load
duke
parents:
diff changeset
419 if( pb == freed ) continue; // Did self already via freelist
a61af66fc99e Initial load
duke
parents:
diff changeset
420 Node_List &p_regnd = *blk2regnd[pb->_pre_order];
a61af66fc99e Initial load
duke
parents:
diff changeset
421 for( uint k = 0; k < (uint)_max_reg; k++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if( regnd[k] != p_regnd[k] ) { // Conflict on reaching defs?
a61af66fc99e Initial load
duke
parents:
diff changeset
423 value.map(k,NULL); // Then no value handy
a61af66fc99e Initial load
duke
parents:
diff changeset
424 regnd.map(k,NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 // For all Phi's
a61af66fc99e Initial load
duke
parents:
diff changeset
431 for( j = 1; j < phi_dex; j++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 uint k;
a61af66fc99e Initial load
duke
parents:
diff changeset
433 Node *phi = b->_nodes[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
434 uint pidx = n2lidx(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
435 OptoReg::Name preg = lrgs(n2lidx(phi)).reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // Remove copies remaining on edges. Check for junk phi.
a61af66fc99e Initial load
duke
parents:
diff changeset
438 Node *u = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
439 for( k=1; k<phi->req(); k++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 Node *x = phi->in(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
441 if( phi != x && u != x ) // Found a different input
a61af66fc99e Initial load
duke
parents:
diff changeset
442 u = u ? NodeSentinel : x; // Capture unique input, or NodeSentinel for 2nd input
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444 if( u != NodeSentinel ) { // Junk Phi. Remove
a61af66fc99e Initial load
duke
parents:
diff changeset
445 b->_nodes.remove(j--); phi_dex--;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 _cfg._bbs.map(phi->_idx,NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
447 phi->replace_by(u);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 phi->disconnect_inputs(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
449 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // Note that if value[pidx] exists, then we merged no new values here
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // and the phi is useless. This can happen even with the above phi
a61af66fc99e Initial load
duke
parents:
diff changeset
453 // removal for complex flows. I cannot keep the better known value here
a61af66fc99e Initial load
duke
parents:
diff changeset
454 // because locally the phi appears to define a new merged value. If I
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // keep the better value then a copy of the phi, being unable to use the
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // global flow analysis, can't "peek through" the phi to the original
a61af66fc99e Initial load
duke
parents:
diff changeset
457 // reaching value and so will act like it's defining a new value. This
a61af66fc99e Initial load
duke
parents:
diff changeset
458 // can lead to situations where some uses are from the old and some from
a61af66fc99e Initial load
duke
parents:
diff changeset
459 // the new values. Not illegal by itself but throws the over-strong
a61af66fc99e Initial load
duke
parents:
diff changeset
460 // assert in scheduling.
a61af66fc99e Initial load
duke
parents:
diff changeset
461 if( pidx ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 value.map(preg,phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
463 regnd.map(preg,phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 OptoReg::Name preg_lo = OptoReg::add(preg,-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
465 if( !is_single_register(phi->ideal_reg()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 value.map(preg_lo,phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
467 regnd.map(preg_lo,phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
a61af66fc99e Initial load
duke
parents:
diff changeset
470 }
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // For all remaining instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
473 for( j = phi_dex; j < b->_nodes.size(); j++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
474 Node *n = b->_nodes[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 if( n->outcnt() == 0 && // Dead?
a61af66fc99e Initial load
duke
parents:
diff changeset
477 n != C->top() && // (ignore TOP, it has no du info)
a61af66fc99e Initial load
duke
parents:
diff changeset
478 !n->is_Proj() ) { // fat-proj kills
a61af66fc99e Initial load
duke
parents:
diff changeset
479 j -= yank_if_dead(n,b,&value,&regnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
480 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // Improve reaching-def info. Occasionally post-alloc's liveness gives
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // up (at loop backedges, because we aren't doing a full flow pass).
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // The presence of a live use essentially asserts that the use's def is
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // alive and well at the use (or else the allocator fubar'd). Take
a61af66fc99e Initial load
duke
parents:
diff changeset
487 // advantage of this info to set a reaching def for the use-reg.
a61af66fc99e Initial load
duke
parents:
diff changeset
488 uint k;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 for( k = 1; k < n->req(); k++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
490 Node *def = n->in(k); // n->in(k) is a USE; def is the DEF for this USE
a61af66fc99e Initial load
duke
parents:
diff changeset
491 guarantee(def != NULL, "no disconnected nodes at this point");
a61af66fc99e Initial load
duke
parents:
diff changeset
492 uint useidx = n2lidx(def); // useidx is the live range index for this USE
a61af66fc99e Initial load
duke
parents:
diff changeset
493
a61af66fc99e Initial load
duke
parents:
diff changeset
494 if( useidx ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
495 OptoReg::Name ureg = lrgs(useidx).reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
496 if( !value[ureg] ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
497 int idx; // Skip occasional useless copy
a61af66fc99e Initial load
duke
parents:
diff changeset
498 while( (idx=def->is_Copy()) != 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
499 def->in(idx) != NULL && // NULL should not happen
a61af66fc99e Initial load
duke
parents:
diff changeset
500 ureg == lrgs(n2lidx(def->in(idx))).reg() )
a61af66fc99e Initial load
duke
parents:
diff changeset
501 def = def->in(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
502 Node *valdef = skip_copies(def); // tighten up val through non-useless copies
a61af66fc99e Initial load
duke
parents:
diff changeset
503 value.map(ureg,valdef); // record improved reaching-def info
a61af66fc99e Initial load
duke
parents:
diff changeset
504 regnd.map(ureg, def);
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // Record other half of doubles
a61af66fc99e Initial load
duke
parents:
diff changeset
506 OptoReg::Name ureg_lo = OptoReg::add(ureg,-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if( !is_single_register(def->ideal_reg()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
508 ( !RegMask::can_represent(ureg_lo) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
509 lrgs(useidx).mask().Member(ureg_lo) ) && // Nearly always adjacent
a61af66fc99e Initial load
duke
parents:
diff changeset
510 !value[ureg_lo] ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
511 value.map(ureg_lo,valdef); // record improved reaching-def info
a61af66fc99e Initial load
duke
parents:
diff changeset
512 regnd.map(ureg_lo, def);
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 const uint two_adr = n->is_Mach() ? n->as_Mach()->two_adr() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520 // Remove copies along input edges
a61af66fc99e Initial load
duke
parents:
diff changeset
521 for( k = 1; k < n->req(); k++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
522 j -= elide_copy( n, k, b, value, regnd, two_adr!=k );
a61af66fc99e Initial load
duke
parents:
diff changeset
523
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // Unallocated Nodes define no registers
a61af66fc99e Initial load
duke
parents:
diff changeset
525 uint lidx = n2lidx(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
526 if( !lidx ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
527
a61af66fc99e Initial load
duke
parents:
diff changeset
528 // Update the register defined by this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
529 OptoReg::Name nreg = lrgs(lidx).reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // Skip through all copies to the _value_ being defined.
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // Do not change from int to pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
532 Node *val = skip_copies(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
533
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
534 // Clear out a dead definition before starting so that the
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
535 // elimination code doesn't have to guard against it. The
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
536 // definition could in fact be a kill projection with a count of
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
537 // 0 which is safe but since those are uninteresting for copy
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
538 // elimination just delete them as well.
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
539 if (regnd[nreg] != NULL && regnd[nreg]->outcnt() == 0) {
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
540 regnd.map(nreg, NULL);
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
541 value.map(nreg, NULL);
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
542 }
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
543
0
a61af66fc99e Initial load
duke
parents:
diff changeset
544 uint n_ideal_reg = n->ideal_reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
545 if( is_single_register(n_ideal_reg) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // If Node 'n' does not change the value mapped by the register,
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // then 'n' is a useless copy. Do not update the register->node
a61af66fc99e Initial load
duke
parents:
diff changeset
548 // mapping so 'n' will go dead.
a61af66fc99e Initial load
duke
parents:
diff changeset
549 if( value[nreg] != val ) {
70
b683f557224b 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 0
diff changeset
550 if (eliminate_copy_of_constant(val, n, b, value, regnd, nreg, OptoReg::Bad)) {
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
551 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
552 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 // Update the mapping: record new Node defined by the register
a61af66fc99e Initial load
duke
parents:
diff changeset
554 regnd.map(nreg,n);
a61af66fc99e Initial load
duke
parents:
diff changeset
555 // Update mapping for defined *value*, which is the defined
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // Node after skipping all copies.
a61af66fc99e Initial load
duke
parents:
diff changeset
557 value.map(nreg,val);
a61af66fc99e Initial load
duke
parents:
diff changeset
558 }
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
559 } else if( !may_be_copy_of_callee(n) ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
560 assert( n->is_Copy(), "" );
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
561 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
563 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 // If the value occupies a register pair, record same info
a61af66fc99e Initial load
duke
parents:
diff changeset
565 // in both registers.
a61af66fc99e Initial load
duke
parents:
diff changeset
566 OptoReg::Name nreg_lo = OptoReg::add(nreg,-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
567 if( RegMask::can_represent(nreg_lo) && // Either a spill slot, or
a61af66fc99e Initial load
duke
parents:
diff changeset
568 !lrgs(lidx).mask().Member(nreg_lo) ) { // Nearly always adjacent
a61af66fc99e Initial load
duke
parents:
diff changeset
569 // Sparc occasionally has non-adjacent pairs.
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // Find the actual other value
a61af66fc99e Initial load
duke
parents:
diff changeset
571 RegMask tmp = lrgs(lidx).mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
572 tmp.Remove(nreg);
a61af66fc99e Initial load
duke
parents:
diff changeset
573 nreg_lo = tmp.find_first_elem();
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575 if( value[nreg] != val || value[nreg_lo] != val ) {
70
b683f557224b 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 0
diff changeset
576 if (eliminate_copy_of_constant(val, n, b, value, regnd, nreg, nreg_lo)) {
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
577 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
578 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
579 regnd.map(nreg , n );
a61af66fc99e Initial load
duke
parents:
diff changeset
580 regnd.map(nreg_lo, n );
a61af66fc99e Initial load
duke
parents:
diff changeset
581 value.map(nreg ,val);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 value.map(nreg_lo,val);
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
584 } else if( !may_be_copy_of_callee(n) ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
585 assert( n->is_Copy(), "" );
923
a70508bb21c3 6862863: C2 compiler fails in elide_copy()
never
parents: 605
diff changeset
586 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
587 }
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 // Fat projections kill many registers
a61af66fc99e Initial load
duke
parents:
diff changeset
591 if( n_ideal_reg == MachProjNode::fat_proj ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
592 RegMask rm = n->out_RegMask();
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // wow, what an expensive iterator...
a61af66fc99e Initial load
duke
parents:
diff changeset
594 nreg = rm.find_first_elem();
a61af66fc99e Initial load
duke
parents:
diff changeset
595 while( OptoReg::is_valid(nreg)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 rm.Remove(nreg);
a61af66fc99e Initial load
duke
parents:
diff changeset
597 value.map(nreg,n);
a61af66fc99e Initial load
duke
parents:
diff changeset
598 regnd.map(nreg,n);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 nreg = rm.find_first_elem();
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 } // End of for all instructions in the block
a61af66fc99e Initial load
duke
parents:
diff changeset
604
a61af66fc99e Initial load
duke
parents:
diff changeset
605 } // End for all blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
606 }