hotspot/src/share/vm/opto/regalloc.hpp
author bobv
Wed, 02 Feb 2011 11:35:26 -0500
changeset 8107 78e5bd944384
parent 7397 5b173b4ca846
child 10547 ea4a2ec31ae2
permissions -rw-r--r--
7016023: Enable building ARM and PPC from src/closed repository Reviewed-by: dholmes, bdelsart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2000, 2010, 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 {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static void (*_alloc_statistics[MAX_REG_ALLOCATORS])();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  static int _num_allocators;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  OptoRegPair  *_node_regs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  uint         _node_regs_max_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  VectorSet    _node_oops;         // Mapping from node indices to oopiness
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  void alloc_node_regs(int size);  // allocate _node_regs table with at least "size" elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  PhaseRegAlloc( uint unique, PhaseCFG &cfg, Matcher &matcher,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                 void (*pr_stats)());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  PhaseCFG &_cfg;               // Control flow graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  uint _framesize;              // Size of frame in stack-slots. not counting preserve area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  OptoReg::Name _max_reg;       // Past largest register seen
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  Matcher &_matcher;            // Convert Ideal to MachNodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  uint node_regs_max_index() const { return _node_regs_max_index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Get the register associated with the Node
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  OptoReg::Name get_reg_first( const Node *n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    return _node_regs[n->_idx].first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  OptoReg::Name get_reg_second( const Node *n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    debug_only( if( n->_idx >= _node_regs_max_index ) n->dump(); );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    return _node_regs[n->_idx].second();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Do all the real work of allocate
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  virtual void Register_Allocate() = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // notify the register allocator that "node" is a new reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // to the value produced by "old_node"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  virtual void add_reference( const Node *node, const Node *old_node) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Set the register associated with a new Node
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  void set_bad( uint idx ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _node_regs[idx].set_bad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  void set1( uint idx, OptoReg::Name reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    _node_regs[idx].set1(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  void set2( uint idx, OptoReg::Name reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    _node_regs[idx].set2(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  void set_pair( uint idx, OptoReg::Name hi, OptoReg::Name lo ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    _node_regs[idx].set_pair(hi, lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  void set_ptr( uint idx, OptoReg::Name reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    assert( idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    _node_regs[idx].set_ptr(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // Set and query if a node produces an oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  void set_oop( const Node *n, bool );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  bool is_oop( const Node *n ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // Convert a register number to a stack offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  int reg2offset          ( OptoReg::Name reg ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  int reg2offset_unchecked( OptoReg::Name reg ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Convert a stack offset to a register number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  OptoReg::Name offset2reg( int stk_offset ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Get the register encoding associated with the Node
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  int get_encode( const Node *n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    assert( n->_idx < _node_regs_max_index, "Exceeded _node_regs array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    OptoReg::Name first = _node_regs[n->_idx].first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    OptoReg::Name second = _node_regs[n->_idx].second();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    assert( !OptoReg::is_valid(second) || second == first+1, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    assert(OptoReg::is_reg(first), "out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return Matcher::_regEncode[first];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // Platform dependent hook for actions prior to allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  void  pd_preallocate_hook();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Platform dependent hook for verification after allocation.  Will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // only get called when compiling with asserts.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  void  pd_postallocate_verify_hook();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  static int _total_framesize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  static int _max_framesize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  virtual void dump_frame() const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  virtual char *dump_register( const Node *n, char *buf  ) const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static void print_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   142
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   143
#endif // SHARE_VM_OPTO_REGALLOC_HPP