11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.inline.hpp"
27 #include "opto/block.hpp"
28 #include "opto/cfgnode.hpp"
29 #include "opto/chaitin.hpp"
30 #include "opto/coalesce.hpp"
31 #include "opto/connode.hpp"
32 #include "opto/indexSet.hpp"
33 #include "opto/machnode.hpp"
34 #include "opto/matcher.hpp"
35 #include "opto/regmask.hpp"
36
37 #ifndef PRODUCT
38 void PhaseCoalesce::dump(Node *n) const {
39 // Being a const function means I cannot use 'Find'
40 uint r = _phc._lrg_map.find(n);
41 tty->print("L%d/N%d ",r,n->_idx);
42 }
43
44 void PhaseCoalesce::dump() const {
45 // I know I have a block layout now, so I can print blocks in a loop
46 for( uint i=0; i<_phc._cfg.number_of_blocks(); i++ ) {
47 uint j;
48 Block* b = _phc._cfg.get_block(i);
49 // Print a nice block header
50 tty->print("B%d: ",b->_pre_order);
277 for (uint j = 1; j < cnt; j++) {
278 Node *m = n->in(j);
279 uint src_name = _phc._lrg_map.find(m);
280 if (src_name != phi_name) {
281 Block *pred = _phc._cfg.get_block_for_node(b->pred(j));
282 Node *copy;
283 assert(!m->is_Con() || m->is_Mach(), "all Con must be Mach");
284 // Rematerialize constants instead of copying them.
285 // We do this only for immediate constants, we avoid constant table loads
286 // because that will unsafely extend the live range of the constant table base.
287 if (m->is_Mach() && m->as_Mach()->is_Con() && !m->as_Mach()->is_MachConstant() &&
288 m->as_Mach()->rematerialize()) {
289 copy = m->clone();
290 // Insert the copy in the predecessor basic block
291 pred->add_inst(copy);
292 // Copy any flags as well
293 _phc.clone_projs(pred, pred->end_idx(), m, copy, _phc._lrg_map);
294 } else {
295 uint ireg = m->ideal_reg();
296 if (ireg == 0 || ireg == Op_RegFlags) {
297 assert(false, "attempted to spill a non-spillable item: %d: %s, ireg = %u, spill_type: %s",
298 m->_idx, m->Name(), ireg, MachSpillCopyNode::spill_type(MachSpillCopyNode::PhiInput));
299 C->record_method_not_compilable("attempted to spill a non-spillable item");
300 return;
301 }
302 const RegMask *rm = C->matcher()->idealreg2spillmask[ireg];
303 copy = new MachSpillCopyNode(MachSpillCopyNode::PhiInput, m, *rm, *rm);
304 // Find a good place to insert. Kinda tricky, use a subroutine
305 insert_copy_with_overlap(pred,copy,phi_name,src_name);
306 }
307 // Insert the copy in the use-def chain
308 n->set_req(j, copy);
309 _phc._cfg.map_node_to_block(copy, pred);
310 // Extend ("register allocate") the names array for the copy.
311 _phc._lrg_map.extend(copy->_idx, phi_name);
312 } // End of if Phi names do not match
313 } // End of for all inputs to Phi
314 } else { // End of if Phi
315
316 // Now check for 2-address instructions
317 uint idx;
318 if( n->is_Mach() && (idx=n->as_Mach()->two_adr()) ) {
319 // Get the chosen name for the Node
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.inline.hpp"
27 #include "opto/block.hpp"
28 #include "opto/cfgnode.hpp"
29 #include "opto/chaitin.hpp"
30 #include "opto/coalesce.hpp"
31 #include "opto/c2compiler.hpp"
32 #include "opto/connode.hpp"
33 #include "opto/indexSet.hpp"
34 #include "opto/machnode.hpp"
35 #include "opto/matcher.hpp"
36 #include "opto/regmask.hpp"
37
38 #ifndef PRODUCT
39 void PhaseCoalesce::dump(Node *n) const {
40 // Being a const function means I cannot use 'Find'
41 uint r = _phc._lrg_map.find(n);
42 tty->print("L%d/N%d ",r,n->_idx);
43 }
44
45 void PhaseCoalesce::dump() const {
46 // I know I have a block layout now, so I can print blocks in a loop
47 for( uint i=0; i<_phc._cfg.number_of_blocks(); i++ ) {
48 uint j;
49 Block* b = _phc._cfg.get_block(i);
50 // Print a nice block header
51 tty->print("B%d: ",b->_pre_order);
278 for (uint j = 1; j < cnt; j++) {
279 Node *m = n->in(j);
280 uint src_name = _phc._lrg_map.find(m);
281 if (src_name != phi_name) {
282 Block *pred = _phc._cfg.get_block_for_node(b->pred(j));
283 Node *copy;
284 assert(!m->is_Con() || m->is_Mach(), "all Con must be Mach");
285 // Rematerialize constants instead of copying them.
286 // We do this only for immediate constants, we avoid constant table loads
287 // because that will unsafely extend the live range of the constant table base.
288 if (m->is_Mach() && m->as_Mach()->is_Con() && !m->as_Mach()->is_MachConstant() &&
289 m->as_Mach()->rematerialize()) {
290 copy = m->clone();
291 // Insert the copy in the predecessor basic block
292 pred->add_inst(copy);
293 // Copy any flags as well
294 _phc.clone_projs(pred, pred->end_idx(), m, copy, _phc._lrg_map);
295 } else {
296 uint ireg = m->ideal_reg();
297 if (ireg == 0 || ireg == Op_RegFlags) {
298 if (C->subsume_loads() == true && !C->failing()) {
299 // Retry with subsume_loads == false
300 C->record_failure(C2Compiler::retry_no_subsuming_loads());
301 } else {
302 assert(false, "attempted to spill a non-spillable item: %d: %s, ireg = %u, spill_type: %s",
303 m->_idx, m->Name(), ireg, MachSpillCopyNode::spill_type(MachSpillCopyNode::PhiInput));
304 // Bailout without retry
305 C->record_method_not_compilable("attempted to spill a non-spillable item");
306 }
307 return;
308 }
309 const RegMask *rm = C->matcher()->idealreg2spillmask[ireg];
310 copy = new MachSpillCopyNode(MachSpillCopyNode::PhiInput, m, *rm, *rm);
311 // Find a good place to insert. Kinda tricky, use a subroutine
312 insert_copy_with_overlap(pred,copy,phi_name,src_name);
313 }
314 // Insert the copy in the use-def chain
315 n->set_req(j, copy);
316 _phc._cfg.map_node_to_block(copy, pred);
317 // Extend ("register allocate") the names array for the copy.
318 _phc._lrg_map.extend(copy->_idx, phi_name);
319 } // End of if Phi names do not match
320 } // End of for all inputs to Phi
321 } else { // End of if Phi
322
323 // Now check for 2-address instructions
324 uint idx;
325 if( n->is_Mach() && (idx=n->as_Mach()->two_adr()) ) {
326 // Get the chosen name for the Node
|