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