hotspot/src/share/vm/opto/regalloc.hpp
author iveresov
Thu, 22 Jan 2015 11:25:23 -0800
changeset 28723 0a36120cb225
parent 22234 da823d78ad65
permissions -rw-r--r--
8071302: assert(!_reg_node[reg_lo] || edge_from_to(_reg_node[reg_lo], def)) failed: after block local Summary: Add merge nodes to node to block mapping Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 17013
diff changeset
     2
 * Copyright (c) 2000, 2013, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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: 5547
diff changeset
    25
#ifndef SHARE_VM_OPTO_REGALLOC_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_OPTO_REGALLOC_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "code/vmreg.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/block.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/matcher.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/phase.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class Node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
class Matcher;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class PhaseCFG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
#define  MAX_REG_ALLOCATORS   10
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//------------------------------PhaseRegAlloc------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// Abstract register allocator
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
class PhaseRegAlloc : public Phase {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 7397
diff changeset
    42
  friend class VMStructs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  static void (*_alloc_statistics[MAX_REG_ALLOCATORS])();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static int _num_allocators;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  OptoRegPair  *_node_regs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  uint         _node_regs_max_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  VectorSet    _node_oops;         // Mapping from node indices to oopiness
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  void alloc_node_regs(int size);  // allocate _node_regs table with at least "size" elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  PhaseRegAlloc( uint unique, PhaseCFG &cfg, Matcher &matcher,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                 void (*pr_stats)());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  PhaseCFG &_cfg;               // Control flow graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  uint _framesize;              // Size of frame in stack-slots. not counting preserve area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  OptoReg::Name _max_reg;       // Past largest register seen
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  Matcher &_matcher;            // Convert Ideal to MachNodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  uint node_regs_max_index() const { return _node_regs_max_index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Get the register associated with the Node
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  OptoReg::Name get_reg_first( const Node *n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    return _node_regs[n->_idx].first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  OptoReg::Name get_reg_second( const Node *n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    return _node_regs[n->_idx].second();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // Do all the real work of allocate
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  virtual void Register_Allocate() = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // notify the register allocator that "node" is a new reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // to the value produced by "old_node"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  virtual void add_reference( const Node *node, const Node *old_node) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // Set the register associated with a new Node
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  void set_bad( uint idx ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    _node_regs[idx].set_bad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  void set1( uint idx, OptoReg::Name reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    _node_regs[idx].set1(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  void set2( uint idx, OptoReg::Name reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    _node_regs[idx].set2(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  void set_pair( uint idx, OptoReg::Name hi, OptoReg::Name lo ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    _node_regs[idx].set_pair(hi, lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  void set_ptr( uint idx, OptoReg::Name reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    _node_regs[idx].set_ptr(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Set and query if a node produces an oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  void set_oop( const Node *n, bool );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  bool is_oop( const Node *n ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Convert a register number to a stack offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  int reg2offset          ( OptoReg::Name reg ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  int reg2offset_unchecked( OptoReg::Name reg ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // Convert a stack offset to a register number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  OptoReg::Name offset2reg( int stk_offset ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // Get the register encoding associated with the Node
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 10547
diff changeset
   116
  int get_encode(const Node *n) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    OptoReg::Name first = _node_regs[n->_idx].first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    OptoReg::Name second = _node_regs[n->_idx].second();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    assert( !OptoReg::is_valid(second) || second == first+1, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    assert(OptoReg::is_reg(first), "out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    return Matcher::_regEncode[first];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static int _total_framesize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  static int _max_framesize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  virtual void dump_frame() const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  virtual char *dump_register( const Node *n, char *buf  ) const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  static void print_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   134
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   135
#endif // SHARE_VM_OPTO_REGALLOC_HPP