coalesce.hpp revision 4514:8373c19be854
1/* 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 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#ifndef SHARE_VM_OPTO_COALESCE_HPP 26#define SHARE_VM_OPTO_COALESCE_HPP 27 28#include "opto/phase.hpp" 29 30class LoopTree; 31class LRG; 32class LRG_List; 33class Matcher; 34class PhaseIFG; 35class PhaseCFG; 36 37//------------------------------PhaseCoalesce---------------------------------- 38class PhaseCoalesce : public Phase { 39protected: 40 PhaseChaitin &_phc; 41 42public: 43 // Coalesce copies 44 PhaseCoalesce(PhaseChaitin &phc) 45 : Phase(Coalesce) 46 , _phc(phc) {} 47 48 virtual void verify() = 0; 49 50 // Coalesce copies 51 void coalesce_driver(); 52 53 // Coalesce copies in this block 54 virtual void coalesce(Block *b) = 0; 55 56 // Attempt to coalesce live ranges defined by these 2 57 void combine_these_two(Node *n1, Node *n2); 58 59 LRG &lrgs(uint lidx) { return _phc.lrgs(lidx); } 60#ifndef PRODUCT 61 // Dump internally name 62 void dump(Node *n) const; 63 // Dump whole shebang 64 void dump() const; 65#endif 66}; 67 68//------------------------------PhaseAggressiveCoalesce------------------------ 69// Aggressively, pessimistic coalesce copies. Aggressive means ignore graph 70// colorability; perhaps coalescing to the point of forcing a spill. 71// Pessimistic means we cannot coalesce if 2 live ranges interfere. This 72// implies we do not hit a fixed point right away. 73class PhaseAggressiveCoalesce : public PhaseCoalesce { 74 uint _unique; 75public: 76 // Coalesce copies 77 PhaseAggressiveCoalesce( PhaseChaitin &chaitin ) : PhaseCoalesce(chaitin) {} 78 79 virtual void verify() { }; 80 81 // Aggressively coalesce copies in this block 82 virtual void coalesce( Block *b ); 83 84 // Where I fail to coalesce, manifest virtual copies as the Real Thing 85 void insert_copies( Matcher &matcher ); 86 87 // Copy insertion needs some smarts in case live ranges overlap 88 void insert_copy_with_overlap( Block *b, Node *copy, uint dst_name, uint src_name ); 89}; 90 91 92//------------------------------PhaseConservativeCoalesce---------------------- 93// Conservatively, pessimistic coalesce copies. Conservative means do not 94// coalesce if the resultant live range will be uncolorable. Pessimistic 95// means we cannot coalesce if 2 live ranges interfere. This implies we do 96// not hit a fixed point right away. 97class PhaseConservativeCoalesce : public PhaseCoalesce { 98 IndexSet _ulr; // Union live range interferences 99public: 100 // Coalesce copies 101 PhaseConservativeCoalesce( PhaseChaitin &chaitin ); 102 103 virtual void verify(); 104 105 // Conservatively coalesce copies in this block 106 virtual void coalesce( Block *b ); 107 108 // Coalesce this chain of copies away 109 bool copy_copy( Node *dst_copy, Node *src_copy, Block *b, uint bindex ); 110 111 void union_helper( Node *lr1_node, Node *lr2_node, uint lr1, uint lr2, Node *src_def, Node *dst_copy, Node *src_copy, Block *b, uint bindex ); 112 113 uint compute_separating_interferences(Node *dst_copy, Node *src_copy, Block *b, uint bindex, RegMask &rm, uint rm_size, uint reg_degree, uint lr1, uint lr2); 114 115 void update_ifg(uint lr1, uint lr2, IndexSet *n_lr1, IndexSet *n_lr2); 116}; 117 118#endif // SHARE_VM_OPTO_COALESCE_HPP 119