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