annotate src/share/vm/opto/block.hpp @ 12146:9758d9f36299

8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced Summary: declare all user-defined operator new()s within Hotspot code with the empty throw() exception specification Reviewed-by: coleenp, twisti, dholmes, hseigel, dcubed, kvn, ccheung Contributed-by: lois.foltan@oracle.com
author coleenp
date Thu, 29 Aug 2013 18:56:29 -0400
parents adb9a7d94cb5
children 650868c062a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 4820
diff changeset
2 * Copyright (c) 1997, 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: 844
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
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: 844
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: 1685
diff changeset
25 #ifndef SHARE_VM_OPTO_BLOCK_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
26 #define SHARE_VM_OPTO_BLOCK_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
28 #include "opto/multnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
29 #include "opto/node.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
30 #include "opto/phase.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
31
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Optimization - Graph Style
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 class Block;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 class CFGLoop;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 class MachCallNode;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 class Matcher;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 class RootNode;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 class VectorSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 struct Tarjan;
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 //------------------------------Block_Array------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Map dense integer indices to Blocks. Uses classic doubling-array trick.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Abstractly provides an infinite array of Block*'s, initialized to NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Note that the constructor just zeros things, and since I use Arena
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // allocation I do not need a destructor to reclaim storage.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 class Block_Array : public ResourceObj {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3851
diff changeset
48 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49 uint _size; // allocated size, as opposed to formal limit
a61af66fc99e Initial load
duke
parents:
diff changeset
50 debug_only(uint _limit;) // limit to formal domain
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
51 Arena *_arena; // Arena to allocate in
0
a61af66fc99e Initial load
duke
parents:
diff changeset
52 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
53 Block **_blocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 void grow( uint i ); // Grow array node to fit
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 Block_Array(Arena *a) : _arena(a), _size(OptoBlockListSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 debug_only(_limit=0);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _blocks = NEW_ARENA_ARRAY( a, Block *, OptoBlockListSize );
a61af66fc99e Initial load
duke
parents:
diff changeset
60 for( int i = 0; i < OptoBlockListSize; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _blocks[i] = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64 Block *lookup( uint i ) const // Lookup, or NULL for not mapped
a61af66fc99e Initial load
duke
parents:
diff changeset
65 { return (i<Max()) ? _blocks[i] : (Block*)NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 Block *operator[] ( uint i ) const // Lookup, or assert for not mapped
a61af66fc99e Initial load
duke
parents:
diff changeset
67 { assert( i < Max(), "oob" ); return _blocks[i]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // Extend the mapping: index i maps to Block *n.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 void map( uint i, Block *n ) { if( i>=Max() ) grow(i); _blocks[i] = n; }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 uint Max() const { debug_only(return _limit); return _size; }
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 class Block_List : public Block_Array {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3851
diff changeset
75 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
77 uint _cnt;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Block_List() : Block_Array(Thread::current()->resource_area()), _cnt(0) {}
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
79 void push( Block *b ) { map(_cnt++,b); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
80 Block *pop() { return _blocks[--_cnt]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 Block *rpop() { Block *b = _blocks[0]; _blocks[0]=_blocks[--_cnt]; return b;}
a61af66fc99e Initial load
duke
parents:
diff changeset
82 void remove( uint i );
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void insert( uint i, Block *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
84 uint size() const { return _cnt; }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 void reset() { _cnt = 0; }
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
86 void print();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
87 };
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 class CFGElement : public ResourceObj {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3851
diff changeset
91 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
93 float _freq; // Execution frequency (estimate)
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 CFGElement() : _freq(0.0f) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
96 virtual bool is_block() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 virtual bool is_loop() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 Block* as_Block() { assert(is_block(), "must be block"); return (Block*)this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 CFGLoop* as_CFGLoop() { assert(is_loop(), "must be loop"); return (CFGLoop*)this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 };
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 //------------------------------Block------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // This class defines a Basic Block.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Basic blocks are used during the output routines, and are not used during
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // any optimization pass. They are created late in the game.
a61af66fc99e Initial load
duke
parents:
diff changeset
106 class Block : public CFGElement {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3851
diff changeset
107 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Nodes in this block, in order
a61af66fc99e Initial load
duke
parents:
diff changeset
110 Node_List _nodes;
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // Basic blocks have a Node which defines Control for all Nodes pinned in
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // this block. This Node is a RegionNode. Exception-causing Nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // (division, subroutines) and Phi functions are always pinned. Later,
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // every Node will get pinned to some block.
a61af66fc99e Initial load
duke
parents:
diff changeset
116 Node *head() const { return _nodes[0]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // CAUTION: num_preds() is ONE based, so that predecessor numbers match
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // input edges to Regions and Phis.
a61af66fc99e Initial load
duke
parents:
diff changeset
120 uint num_preds() const { return head()->req(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 Node *pred(uint i) const { return head()->in(i); }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Array of successor blocks, same size as projs array
a61af66fc99e Initial load
duke
parents:
diff changeset
124 Block_Array _succs;
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Basic blocks have some number of Nodes which split control to all
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // following blocks. These Nodes are always Projections. The field in
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // the Projection and the block-ending Node determine which Block follows.
a61af66fc99e Initial load
duke
parents:
diff changeset
129 uint _num_succs;
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // Basic blocks also carry all sorts of good old fashioned DFS information
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // used to find loops, loop nesting depth, dominators, etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
133 uint _pre_order; // Pre-order DFS number
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Dominator tree
a61af66fc99e Initial load
duke
parents:
diff changeset
136 uint _dom_depth; // Depth in dominator tree for fast LCA
a61af66fc99e Initial load
duke
parents:
diff changeset
137 Block* _idom; // Immediate dominator block
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 CFGLoop *_loop; // Loop to which this block belongs
a61af66fc99e Initial load
duke
parents:
diff changeset
140 uint _rpo; // Number in reverse post order walk
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 virtual bool is_block() { return true; }
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
143 float succ_prob(uint i); // return probability of i'th successor
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
144 int num_fall_throughs(); // How many fall-through candidate this block has
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
145 void update_uncommon_branch(Block* un); // Lower branch prob to uncommon code
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
146 bool succ_fall_through(uint i); // Is successor "i" is a fall-through candidate
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
147 Block* lone_fall_through(); // Return lone fall-through Block or null
0
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 Block* dom_lca(Block* that); // Compute LCA in dominator tree.
a61af66fc99e Initial load
duke
parents:
diff changeset
150 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
151 bool dominates(Block* that) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 int dom_diff = this->_dom_depth - that->_dom_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (dom_diff > 0) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 for (; dom_diff < 0; dom_diff++) that = that->_idom;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return this == that;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Report the alignment required by this block. Must be a power of 2.
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // The previous block will insert nops to get this alignment.
a61af66fc99e Initial load
duke
parents:
diff changeset
161 uint code_alignment();
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
162 uint compute_loop_alignment();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // BLOCK_FREQUENCY is a sentinel to mark uses of constant block frequencies.
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // It is currently also used to scale such frequencies relative to
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // FreqCountInvocations relative to the old value of 1500.
a61af66fc99e Initial load
duke
parents:
diff changeset
167 #define BLOCK_FREQUENCY(f) ((f * (float) 1500) / FreqCountInvocations)
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Register Pressure (estimate) for Splitting heuristic
a61af66fc99e Initial load
duke
parents:
diff changeset
170 uint _reg_pressure;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 uint _ihrp_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 uint _freg_pressure;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 uint _fhrp_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Mark and visited bits for an LCA calculation in insert_anti_dependences.
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // Since they hold unique node indexes, they do not need reinitialization.
a61af66fc99e Initial load
duke
parents:
diff changeset
177 node_idx_t _raise_LCA_mark;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 void set_raise_LCA_mark(node_idx_t x) { _raise_LCA_mark = x; }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 node_idx_t raise_LCA_mark() const { return _raise_LCA_mark; }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 node_idx_t _raise_LCA_visited;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 void set_raise_LCA_visited(node_idx_t x) { _raise_LCA_visited = x; }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 node_idx_t raise_LCA_visited() const { return _raise_LCA_visited; }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // Estimated size in bytes of first instructions in a loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
185 uint _first_inst_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 uint first_inst_size() const { return _first_inst_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 void set_first_inst_size(uint s) { _first_inst_size = s; }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // Compute the size of first instructions in this block.
a61af66fc99e Initial load
duke
parents:
diff changeset
190 uint compute_first_inst_size(uint& sum_size, uint inst_cnt, PhaseRegAlloc* ra);
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Compute alignment padding if the block needs it.
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // Align a loop if loop's padding is less or equal to padding limit
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // or the size of first instructions in the loop > padding.
a61af66fc99e Initial load
duke
parents:
diff changeset
195 uint alignment_padding(int current_offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 int block_alignment = code_alignment();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 int max_pad = block_alignment-relocInfo::addr_unit();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if( max_pad > 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 assert(is_power_of_2(max_pad+relocInfo::addr_unit()), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
200 int current_alignment = current_offset & max_pad;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if( current_alignment != 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 uint padding = (block_alignment-current_alignment) & max_pad;
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
203 if( has_loop_alignment() &&
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
204 padding > (uint)MaxLoopPad &&
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
205 first_inst_size() <= padding ) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
206 return 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
208 return padding;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Connector blocks. Connector blocks are basic blocks devoid of
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // instructions, but may have relevant non-instruction Nodes, such as
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // Phis or MergeMems. Such blocks are discovered and marked during the
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // RemoveEmpty phase, and elided during Output.
a61af66fc99e Initial load
duke
parents:
diff changeset
218 bool _connector;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 void set_connector() { _connector = true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 bool is_connector() const { return _connector; };
a61af66fc99e Initial load
duke
parents:
diff changeset
221
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
222 // Loop_alignment will be set for blocks which are at the top of loops.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
223 // The block layout pass may rotate loops such that the loop head may not
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
224 // be the sequentially first block of the loop encountered in the linear
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
225 // list of blocks. If the layout pass is not run, loop alignment is set
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
226 // for each block which is the head of a loop.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
227 uint _loop_alignment;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
228 void set_loop_alignment(Block *loop_top) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
229 uint new_alignment = loop_top->compute_loop_alignment();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
230 if (new_alignment > _loop_alignment) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
231 _loop_alignment = new_alignment;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
232 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
233 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
234 uint loop_alignment() const { return _loop_alignment; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
235 bool has_loop_alignment() const { return loop_alignment() > 0; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
236
0
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // Create a new Block with given head Node.
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // Creates the (empty) predecessor arrays.
a61af66fc99e Initial load
duke
parents:
diff changeset
239 Block( Arena *a, Node *headnode )
a61af66fc99e Initial load
duke
parents:
diff changeset
240 : CFGElement(),
a61af66fc99e Initial load
duke
parents:
diff changeset
241 _nodes(a),
a61af66fc99e Initial load
duke
parents:
diff changeset
242 _succs(a),
a61af66fc99e Initial load
duke
parents:
diff changeset
243 _num_succs(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
244 _pre_order(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
245 _idom(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
246 _loop(NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
247 _reg_pressure(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
248 _ihrp_index(1),
a61af66fc99e Initial load
duke
parents:
diff changeset
249 _freg_pressure(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
250 _fhrp_index(1),
a61af66fc99e Initial load
duke
parents:
diff changeset
251 _raise_LCA_mark(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
252 _raise_LCA_visited(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
253 _first_inst_size(999999),
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
254 _connector(false),
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
255 _loop_alignment(0) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
256 _nodes.push(headnode);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // Index of 'end' Node
a61af66fc99e Initial load
duke
parents:
diff changeset
260 uint end_idx() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // %%%%% add a proj after every goto
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // so (last->is_block_proj() != last) always, then simplify this code
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // This will not give correct end_idx for block 0 when it only contains root.
a61af66fc99e Initial load
duke
parents:
diff changeset
264 int last_idx = _nodes.size() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 Node *last = _nodes[last_idx];
a61af66fc99e Initial load
duke
parents:
diff changeset
266 assert(last->is_block_proj() == last || last->is_block_proj() == _nodes[last_idx - _num_succs], "");
a61af66fc99e Initial load
duke
parents:
diff changeset
267 return (last->is_block_proj() == last) ? last_idx : (last_idx - _num_succs);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // Basic blocks have a Node which ends them. This Node determines which
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // basic block follows this one in the program flow. This Node is either an
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // IfNode, a GotoNode, a JmpNode, or a ReturnNode.
a61af66fc99e Initial load
duke
parents:
diff changeset
273 Node *end() const { return _nodes[end_idx()]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // Add an instruction to an existing block. It must go after the head
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // instruction and before the end instruction.
a61af66fc99e Initial load
duke
parents:
diff changeset
277 void add_inst( Node *n ) { _nodes.insert(end_idx(),n); }
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // Find node in block
a61af66fc99e Initial load
duke
parents:
diff changeset
279 uint find_node( const Node *n ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // Find and remove n from block list
a61af66fc99e Initial load
duke
parents:
diff changeset
281 void find_remove( const Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
282
4120
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 3939
diff changeset
283 // helper function that adds caller save registers to MachProjNode
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 3939
diff changeset
284 void add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Schedule a call next in the block
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
286 uint sched_call(Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_List &worklist, GrowableArray<int> &ready_cnt, MachCallNode *mcall, VectorSet &next_call);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // Perform basic-block local scheduling
4820
cf407b7d3d78 7116050: C2/ARM: memory stomping error with DivideMcTests
roland
parents: 4120
diff changeset
289 Node *select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &ready_cnt, VectorSet &next_call, uint sched_slot);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
290 void set_next_call( Node *n, VectorSet &next_call, PhaseCFG* cfg);
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
291 void needed_for_next_call(Node *this_call, VectorSet &next_call, PhaseCFG* cfg);
4820
cf407b7d3d78 7116050: C2/ARM: memory stomping error with DivideMcTests
roland
parents: 4120
diff changeset
292 bool schedule_local(PhaseCFG *cfg, Matcher &m, GrowableArray<int> &ready_cnt, VectorSet &next_call);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Cleanup if any code lands between a Call and his Catch
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
294 void call_catch_cleanup(PhaseCFG* cfg, Compile *C);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // Detect implicit-null-check opportunities. Basically, find NULL checks
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // with suitable memory ops nearby. Use the memory op to do the NULL check.
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // I can generate a memory op if there is not one nearby.
a61af66fc99e Initial load
duke
parents:
diff changeset
298 void implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowed_reasons);
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // Return the empty status of a block
a61af66fc99e Initial load
duke
parents:
diff changeset
301 enum { not_empty, empty_with_goto, completely_empty };
a61af66fc99e Initial load
duke
parents:
diff changeset
302 int is_Empty() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // Forward through connectors
a61af66fc99e Initial load
duke
parents:
diff changeset
305 Block* non_connector() {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 Block* s = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 while (s->is_connector()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 s = s->_succs[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return s;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
313 // Return true if b is a successor of this block
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
314 bool has_successor(Block* b) const {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
315 for (uint i = 0; i < _num_succs; i++ ) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
316 if (non_connector_successor(i) == b) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
317 return true;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
318 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
319 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
320 return false;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
321 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
322
0
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // Successor block, after forwarding through connectors
a61af66fc99e Initial load
duke
parents:
diff changeset
324 Block* non_connector_successor(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 return _succs[i]->non_connector();
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // Examine block's code shape to predict if it is not commonly executed.
a61af66fc99e Initial load
duke
parents:
diff changeset
329 bool has_uncommon_code() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // Use frequency calculations and code shape to predict if the block
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // is uncommon.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
333 bool is_uncommon(PhaseCFG* cfg) const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // Debugging print of basic block
3851
95134e034042 7063629: use cbcond in C2 generated code on T4
kvn
parents: 1972
diff changeset
337 void dump_bidx(const Block* orig, outputStream* st = tty) const;
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
338 void dump_pred(const PhaseCFG* cfg, Block* orig, outputStream* st = tty) const;
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
339 void dump_head(const PhaseCFG* cfg, outputStream* st = tty) const;
3851
95134e034042 7063629: use cbcond in C2 generated code on T4
kvn
parents: 1972
diff changeset
340 void dump() const;
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
341 void dump(const PhaseCFG* cfg) const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
342 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
343 };
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 //------------------------------PhaseCFG---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // Build an array of Basic Block pointers, one per Node.
a61af66fc99e Initial load
duke
parents:
diff changeset
348 class PhaseCFG : public Phase {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3851
diff changeset
349 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
350 private:
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
351
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
352 // Root of whole program
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
353 RootNode* _root;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
354
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
355 // The block containing the root node
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
356 Block* _root_block;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
357
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
358 // List of basic blocks that are created during CFG creation
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
359 Block_List _blocks;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
360
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
361 // Count of basic blocks
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
362 uint _number_of_blocks;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
363
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
364 // Arena for the blocks to be stored in
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
365 Arena* _block_arena;
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
366
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
367 // The matcher for this compilation
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
368 Matcher& _matcher;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
369
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
370 // Map nodes to owning basic block
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
371 Block_Array _node_to_block_mapping;
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
372
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
373 // Loop from the root
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
374 CFGLoop* _root_loop;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
375
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
376 // Outmost loop frequency
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
377 float _outer_loop_frequency;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
378
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
379 // Per node latency estimation, valid only during GCM
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
380 GrowableArray<uint>* _node_latency;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
381
0
a61af66fc99e Initial load
duke
parents:
diff changeset
382 // Build a proper looking cfg. Return count of basic blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
383 uint build_cfg();
a61af66fc99e Initial load
duke
parents:
diff changeset
384
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
385 // Build the dominator tree so that we know where we can move instructions
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
386 void build_dominator_tree();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
387
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
388 // Estimate block frequencies based on IfNode probabilities, so that we know where we want to move instructions
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
389 void estimate_block_frequency();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
390
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
391 // Global Code Motion. See Click's PLDI95 paper. Place Nodes in specific
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
392 // basic blocks; i.e. _node_to_block_mapping now maps _idx for all Nodes to some Block.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
393 // Move nodes to ensure correctness from GVN and also try to move nodes out of loops.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
394 void global_code_motion();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
395
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
396 // Schedule Nodes early in their basic blocks.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
397 bool schedule_early(VectorSet &visited, Node_List &roots);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
398
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
399 // For each node, find the latest block it can be scheduled into
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
400 // and then select the cheapest block between the latest and earliest
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
401 // block to place the node.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
402 void schedule_late(VectorSet &visited, Node_List &stack);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
403
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
404 // Compute the (backwards) latency of a node from a single use
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
405 int latency_from_use(Node *n, const Node *def, Node *use);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
406
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
407 // Compute the (backwards) latency of a node from the uses of this instruction
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
408 void partial_latency_of_defs(Node *n);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
409
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
410 // Compute the instruction global latency with a backwards walk
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
411 void compute_latencies_backwards(VectorSet &visited, Node_List &stack);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
412
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
413 // Pick a block between early and late that is a cheaper alternative
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
414 // to late. Helper for schedule_late.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
415 Block* hoist_to_cheaper_block(Block* LCA, Block* early, Node* self);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
416
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
417 // Perform a Depth First Search (DFS).
0
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // Setup 'vertex' as DFS to vertex mapping.
a61af66fc99e Initial load
duke
parents:
diff changeset
419 // Setup 'semi' as vertex to DFS mapping.
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // Set 'parent' to DFS parent.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
421 uint do_DFS(Tarjan* tarjan, uint rpo_counter);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // Helper function to insert a node into a block
a61af66fc99e Initial load
duke
parents:
diff changeset
424 void schedule_node_into_block( Node *n, Block *b );
a61af66fc99e Initial load
duke
parents:
diff changeset
425
604
ec59443af135 6811267: Fix for 6809798 broke linux build
kvn
parents: 601
diff changeset
426 void replace_block_proj_ctrl( Node *n );
601
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 470
diff changeset
427
0
a61af66fc99e Initial load
duke
parents:
diff changeset
428 // Set the basic block for pinned Nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
429 void schedule_pinned_nodes( VectorSet &visited );
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 // I'll need a few machine-specific GotoNodes. Clone from this one.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
432 // Used when building the CFG and creating end nodes for blocks.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
433 MachNode* _goto;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
434
a61af66fc99e Initial load
duke
parents:
diff changeset
435 Block* insert_anti_dependences(Block* LCA, Node* load, bool verify = false);
a61af66fc99e Initial load
duke
parents:
diff changeset
436 void verify_anti_dependences(Block* LCA, Node* load) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
437 assert(LCA == get_block_for_node(load), "should already be scheduled");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
438 insert_anti_dependences(LCA, load, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
441 bool move_to_next(Block* bx, uint b_index);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
442 void move_to_end(Block* bx, uint b_index);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
443
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
444 void insert_goto_at(uint block_no, uint succ_no);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
445
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
446 // Check for NeverBranch at block end. This needs to become a GOTO to the
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
447 // true target. NeverBranch are treated as a conditional branch that always
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
448 // goes the same direction for most of the optimizer and are used to give a
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
449 // fake exit path to infinite loops. At this late stage they need to turn
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
450 // into Goto's so that when you enter the infinite loop you indeed hang.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
451 void convert_NeverBranch_to_Goto(Block *b);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
452
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
453 CFGLoop* create_loop_tree();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
454
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
455 #ifndef PRODUCT
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
456 bool _trace_opto_pipelining; // tracing flag
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
457 #endif
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
458
0
a61af66fc99e Initial load
duke
parents:
diff changeset
459 public:
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
460 PhaseCFG(Arena* arena, RootNode* root, Matcher& matcher);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
461
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
462 void set_latency_for_node(Node* node, int latency) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
463 _node_latency->at_put_grow(node->_idx, latency);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
464 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
465
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
466 uint get_latency_for_node(Node* node) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
467 return _node_latency->at_grow(node->_idx);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
468 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
469
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
470 // Get the outer most frequency
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
471 float get_outer_loop_frequency() const {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
472 return _outer_loop_frequency;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
473 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
474
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
475 // Get the root node of the CFG
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
476 RootNode* get_root_node() const {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
477 return _root;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
478 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
479
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
480 // Get the block of the root node
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
481 Block* get_root_block() const {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
482 return _root_block;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
483 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
484
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
485 // Add a block at a position and moves the later ones one step
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
486 void add_block_at(uint pos, Block* block) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
487 _blocks.insert(pos, block);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
488 _number_of_blocks++;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
489 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
490
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
491 // Adds a block to the top of the block list
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
492 void add_block(Block* block) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
493 _blocks.push(block);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
494 _number_of_blocks++;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
495 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
496
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
497 // Clear the list of blocks
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
498 void clear_blocks() {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
499 _blocks.reset();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
500 _number_of_blocks = 0;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
501 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
502
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
503 // Get the block at position pos in _blocks
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
504 Block* get_block(uint pos) const {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
505 return _blocks[pos];
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
506 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
507
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
508 // Number of blocks
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
509 uint number_of_blocks() const {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
510 return _number_of_blocks;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
511 }
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
512
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
513 // set which block this node should reside in
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
514 void map_node_to_block(const Node* node, Block* block) {
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
515 _node_to_block_mapping.map(node->_idx, block);
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
516 }
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
517
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
518 // removes the mapping from a node to a block
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
519 void unmap_node_from_block(const Node* node) {
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
520 _node_to_block_mapping.map(node->_idx, NULL);
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
521 }
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
522
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
523 // get the block in which this node resides
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
524 Block* get_block_for_node(const Node* node) const {
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
525 return _node_to_block_mapping[node->_idx];
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
526 }
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
527
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
528 // does this node reside in a block; return true
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
529 bool has_block(const Node* node) const {
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
530 return (_node_to_block_mapping.lookup(node->_idx) != NULL);
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
531 }
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
532
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 673
diff changeset
533 #ifdef ASSERT
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 673
diff changeset
534 Unique_Node_List _raw_oops;
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 673
diff changeset
535 #endif
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 673
diff changeset
536
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
537 // Do global code motion by first building dominator tree and estimate block frequency
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
538 // Returns true on success
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
539 bool do_global_code_motion();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // Compute the (backwards) latency of a node from the uses
a61af66fc99e Initial load
duke
parents:
diff changeset
542 void latency_from_uses(Node *n);
a61af66fc99e Initial load
duke
parents:
diff changeset
543
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
544 // Set loop alignment
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
545 void set_loop_alignment();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
546
0
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // Remove empty basic blocks
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
548 void remove_empty_blocks();
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
549 void fixup_flow();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
550
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
551 // Insert a node into a block at index and map the node to the block
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
552 void insert(Block *b, uint idx, Node *n) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
553 b->_nodes.insert( idx, n );
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
554 map_node_to_block(n, b);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
556
a61af66fc99e Initial load
duke
parents:
diff changeset
557 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
558 bool trace_opto_pipelining() const { return _trace_opto_pipelining; }
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 // Debugging print of CFG
a61af66fc99e Initial load
duke
parents:
diff changeset
561 void dump( ) const; // CFG only
a61af66fc99e Initial load
duke
parents:
diff changeset
562 void _dump_cfg( const Node *end, VectorSet &visited ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 void verify() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
564 void dump_headers();
a61af66fc99e Initial load
duke
parents:
diff changeset
565 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
566 bool trace_opto_pipelining() const { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
567 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
568 };
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
571 //------------------------------UnionFind--------------------------------------
0
a61af66fc99e Initial load
duke
parents:
diff changeset
572 // Map Block indices to a block-index for a cfg-cover.
a61af66fc99e Initial load
duke
parents:
diff changeset
573 // Array lookup in the optimized case.
a61af66fc99e Initial load
duke
parents:
diff changeset
574 class UnionFind : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
575 uint _cnt, _max;
a61af66fc99e Initial load
duke
parents:
diff changeset
576 uint* _indices;
a61af66fc99e Initial load
duke
parents:
diff changeset
577 ReallocMark _nesting; // assertion check for reallocations
a61af66fc99e Initial load
duke
parents:
diff changeset
578 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
579 UnionFind( uint max );
a61af66fc99e Initial load
duke
parents:
diff changeset
580 void reset( uint max ); // Reset to identity map for [0..max]
a61af66fc99e Initial load
duke
parents:
diff changeset
581
a61af66fc99e Initial load
duke
parents:
diff changeset
582 uint lookup( uint nidx ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
583 return _indices[nidx];
a61af66fc99e Initial load
duke
parents:
diff changeset
584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
585 uint operator[] (uint nidx) const { return lookup(nidx); }
a61af66fc99e Initial load
duke
parents:
diff changeset
586
a61af66fc99e Initial load
duke
parents:
diff changeset
587 void map( uint from_idx, uint to_idx ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
588 assert( from_idx < _cnt, "oob" );
a61af66fc99e Initial load
duke
parents:
diff changeset
589 _indices[from_idx] = to_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
590 }
a61af66fc99e Initial load
duke
parents:
diff changeset
591 void extend( uint from_idx, uint to_idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
592
a61af66fc99e Initial load
duke
parents:
diff changeset
593 uint Size() const { return _cnt; }
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 uint Find( uint idx ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 assert( idx < 65536, "Must fit into uint");
a61af66fc99e Initial load
duke
parents:
diff changeset
597 uint uf_idx = lookup(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
598 return (uf_idx == idx) ? uf_idx : Find_compress(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600 uint Find_compress( uint idx );
a61af66fc99e Initial load
duke
parents:
diff changeset
601 uint Find_const( uint idx ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
602 void Union( uint idx1, uint idx2 );
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604 };
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 //----------------------------BlockProbPair---------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
607 // Ordered pair of Node*.
a61af66fc99e Initial load
duke
parents:
diff changeset
608 class BlockProbPair VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
610 Block* _target; // block target
a61af66fc99e Initial load
duke
parents:
diff changeset
611 float _prob; // probability of edge to block
a61af66fc99e Initial load
duke
parents:
diff changeset
612 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
613 BlockProbPair() : _target(NULL), _prob(0.0) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
614 BlockProbPair(Block* b, float p) : _target(b), _prob(p) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
615
a61af66fc99e Initial load
duke
parents:
diff changeset
616 Block* get_target() const { return _target; }
a61af66fc99e Initial load
duke
parents:
diff changeset
617 float get_prob() const { return _prob; }
a61af66fc99e Initial load
duke
parents:
diff changeset
618 };
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 //------------------------------CFGLoop-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
621 class CFGLoop : public CFGElement {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3851
diff changeset
622 friend class VMStructs;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
623 int _id;
a61af66fc99e Initial load
duke
parents:
diff changeset
624 int _depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
625 CFGLoop *_parent; // root of loop tree is the method level "pseudo" loop, it's parent is null
a61af66fc99e Initial load
duke
parents:
diff changeset
626 CFGLoop *_sibling; // null terminated list
a61af66fc99e Initial load
duke
parents:
diff changeset
627 CFGLoop *_child; // first child, use child's sibling to visit all immediately nested loops
a61af66fc99e Initial load
duke
parents:
diff changeset
628 GrowableArray<CFGElement*> _members; // list of members of loop
a61af66fc99e Initial load
duke
parents:
diff changeset
629 GrowableArray<BlockProbPair> _exits; // list of successor blocks and their probabilities
a61af66fc99e Initial load
duke
parents:
diff changeset
630 float _exit_prob; // probability any loop exit is taken on a single loop iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
631 void update_succ_freq(Block* b, float freq);
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
634 CFGLoop(int id) :
a61af66fc99e Initial load
duke
parents:
diff changeset
635 CFGElement(),
a61af66fc99e Initial load
duke
parents:
diff changeset
636 _id(id),
a61af66fc99e Initial load
duke
parents:
diff changeset
637 _depth(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
638 _parent(NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
639 _sibling(NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
640 _child(NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
641 _exit_prob(1.0f) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
642 CFGLoop* parent() { return _parent; }
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 7196
diff changeset
643 void push_pred(Block* blk, int i, Block_List& worklist, PhaseCFG* cfg);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
644 void add_member(CFGElement *s) { _members.push(s); }
a61af66fc99e Initial load
duke
parents:
diff changeset
645 void add_nested_loop(CFGLoop* cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
646 Block* head() {
a61af66fc99e Initial load
duke
parents:
diff changeset
647 assert(_members.at(0)->is_block(), "head must be a block");
a61af66fc99e Initial load
duke
parents:
diff changeset
648 Block* hd = _members.at(0)->as_Block();
a61af66fc99e Initial load
duke
parents:
diff changeset
649 assert(hd->_loop == this, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
650 assert(hd->head()->is_Loop(), "must begin with loop head node");
a61af66fc99e Initial load
duke
parents:
diff changeset
651 return hd;
a61af66fc99e Initial load
duke
parents:
diff changeset
652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
653 Block* backedge_block(); // Return the block on the backedge of the loop (else NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
654 void compute_loop_depth(int depth);
a61af66fc99e Initial load
duke
parents:
diff changeset
655 void compute_freq(); // compute frequency with loop assuming head freq 1.0f
a61af66fc99e Initial load
duke
parents:
diff changeset
656 void scale_freq(); // scale frequency by loop trip count (including outer loops)
673
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 605
diff changeset
657 float outer_loop_freq() const; // frequency of outer loop
0
a61af66fc99e Initial load
duke
parents:
diff changeset
658 bool in_loop_nest(Block* b);
a61af66fc99e Initial load
duke
parents:
diff changeset
659 float trip_count() const { return 1.0f / _exit_prob; }
a61af66fc99e Initial load
duke
parents:
diff changeset
660 virtual bool is_loop() { return true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
661 int id() { return _id; }
a61af66fc99e Initial load
duke
parents:
diff changeset
662
a61af66fc99e Initial load
duke
parents:
diff changeset
663 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
664 void dump( ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
665 void dump_tree() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
666 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
667 };
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
668
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
669
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
670 //----------------------------------CFGEdge------------------------------------
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
671 // A edge between two basic blocks that will be embodied by a branch or a
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
672 // fall-through.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
673 class CFGEdge : public ResourceObj {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3851
diff changeset
674 friend class VMStructs;
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
675 private:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
676 Block * _from; // Source basic block
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
677 Block * _to; // Destination basic block
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
678 float _freq; // Execution frequency (estimate)
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
679 int _state;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
680 bool _infrequent;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
681 int _from_pct;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
682 int _to_pct;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
683
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
684 // Private accessors
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
685 int from_pct() const { return _from_pct; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
686 int to_pct() const { return _to_pct; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
687 int from_infrequent() const { return from_pct() < BlockLayoutMinDiamondPercentage; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
688 int to_infrequent() const { return to_pct() < BlockLayoutMinDiamondPercentage; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
689
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
690 public:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
691 enum {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
692 open, // initial edge state; unprocessed
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
693 connected, // edge used to connect two traces together
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
694 interior // edge is interior to trace (could be backedge)
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
695 };
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
696
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
697 CFGEdge(Block *from, Block *to, float freq, int from_pct, int to_pct) :
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
698 _from(from), _to(to), _freq(freq),
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
699 _from_pct(from_pct), _to_pct(to_pct), _state(open) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
700 _infrequent = from_infrequent() || to_infrequent();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
701 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
702
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
703 float freq() const { return _freq; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
704 Block* from() const { return _from; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
705 Block* to () const { return _to; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
706 int infrequent() const { return _infrequent; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
707 int state() const { return _state; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
708
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
709 void set_state(int state) { _state = state; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
710
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
711 #ifndef PRODUCT
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
712 void dump( ) const;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
713 #endif
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
714 };
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
715
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
716
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
717 //-----------------------------------Trace-------------------------------------
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
718 // An ordered list of basic blocks.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
719 class Trace : public ResourceObj {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
720 private:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
721 uint _id; // Unique Trace id (derived from initial block)
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
722 Block ** _next_list; // Array mapping index to next block
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
723 Block ** _prev_list; // Array mapping index to previous block
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
724 Block * _first; // First block in the trace
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
725 Block * _last; // Last block in the trace
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
726
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
727 // Return the block that follows "b" in the trace.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
728 Block * next(Block *b) const { return _next_list[b->_pre_order]; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
729 void set_next(Block *b, Block *n) const { _next_list[b->_pre_order] = n; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
730
605
98cb887364d3 6810672: Comment typos
twisti
parents: 604
diff changeset
731 // Return the block that precedes "b" in the trace.
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
732 Block * prev(Block *b) const { return _prev_list[b->_pre_order]; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
733 void set_prev(Block *b, Block *p) const { _prev_list[b->_pre_order] = p; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
734
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
735 // We've discovered a loop in this trace. Reset last to be "b", and first as
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
736 // the block following "b
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
737 void break_loop_after(Block *b) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
738 _last = b;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
739 _first = next(b);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
740 set_prev(_first, NULL);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
741 set_next(_last, NULL);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
742 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
743
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
744 public:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
745
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
746 Trace(Block *b, Block **next_list, Block **prev_list) :
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
747 _first(b),
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
748 _last(b),
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
749 _next_list(next_list),
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
750 _prev_list(prev_list),
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
751 _id(b->_pre_order) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
752 set_next(b, NULL);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
753 set_prev(b, NULL);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
754 };
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
755
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
756 // Return the id number
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
757 uint id() const { return _id; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
758 void set_id(uint id) { _id = id; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
759
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
760 // Return the first block in the trace
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
761 Block * first_block() const { return _first; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
762
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
763 // Return the last block in the trace
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
764 Block * last_block() const { return _last; }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
765
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
766 // Insert a trace in the middle of this one after b
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
767 void insert_after(Block *b, Trace *tr) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
768 set_next(tr->last_block(), next(b));
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
769 if (next(b) != NULL) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
770 set_prev(next(b), tr->last_block());
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
771 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
772
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
773 set_next(b, tr->first_block());
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
774 set_prev(tr->first_block(), b);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
775
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
776 if (b == _last) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
777 _last = tr->last_block();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
778 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
779 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
780
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
781 void insert_before(Block *b, Trace *tr) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
782 Block *p = prev(b);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
783 assert(p != NULL, "use append instead");
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
784 insert_after(p, tr);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
785 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
786
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
787 // Append another trace to this one.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
788 void append(Trace *tr) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
789 insert_after(_last, tr);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
790 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
791
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
792 // Append a block at the end of this trace
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
793 void append(Block *b) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
794 set_next(_last, b);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
795 set_prev(b, _last);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
796 _last = b;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
797 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
798
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
799 // Adjust the the blocks in this trace
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
800 void fixup_blocks(PhaseCFG &cfg);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
801 bool backedge(CFGEdge *e);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
802
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
803 #ifndef PRODUCT
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
804 void dump( ) const;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
805 #endif
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
806 };
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
807
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
808 //------------------------------PhaseBlockLayout-------------------------------
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
809 // Rearrange blocks into some canonical order, based on edges and their frequencies
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
810 class PhaseBlockLayout : public Phase {
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3851
diff changeset
811 friend class VMStructs;
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
812 PhaseCFG &_cfg; // Control flow graph
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
813
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
814 GrowableArray<CFGEdge *> *edges;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
815 Trace **traces;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
816 Block **next;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
817 Block **prev;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
818 UnionFind *uf;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
819
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
820 // Given a block, find its encompassing Trace
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
821 Trace * trace(Block *b) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
822 return traces[uf->Find_compress(b->_pre_order)];
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
823 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
824 public:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
825 PhaseBlockLayout(PhaseCFG &cfg);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
826
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
827 void find_edges();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
828 void grow_traces();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
829 void merge_traces(bool loose_connections);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
830 void reorder_traces(int count);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
831 void union_traces(Trace* from, Trace* to);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 0
diff changeset
832 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
833
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
834 #endif // SHARE_VM_OPTO_BLOCK_HPP