src/hotspot/share/opto/regalloc.cpp
author thartmann
Tue, 22 Jan 2019 18:25:56 +0100
changeset 53429 1b292ae4eb50
parent 51333 f6641fcf7b7e
permissions -rw-r--r--
8217230: assert(t == t_no_spec) failure in NodeHash::check_no_speculative_types() Summary: Remove dead node from C2 IR. Reviewed-by: roland, neliasso
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: 15241
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
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "opto/regalloc.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
static const int NodeRegsOverflowSize = 200;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
void (*PhaseRegAlloc::_alloc_statistics[MAX_REG_ALLOCATORS])();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
int PhaseRegAlloc::_num_allocators = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
int PhaseRegAlloc::_total_framesize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
int PhaseRegAlloc::_max_framesize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
PhaseRegAlloc::PhaseRegAlloc( uint unique, PhaseCFG &cfg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                              Matcher &matcher,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                              void (*pr_stats)() ):
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    40
               Phase(Register_Allocation),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
               _node_regs(0),
15241
87d217c2d183 8005055: pass outputStream to more opto debug routines
kvn
parents: 7397
diff changeset
    42
               _node_regs_max_index(0),
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    43
               _node_oops(Thread::current()->resource_area()),
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    44
               _cfg(cfg),
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    45
               _framesize(0xdeadbeef),
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    46
               _matcher(matcher)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    for (i=0; i < _num_allocators; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
        if (_alloc_statistics[i] == pr_stats)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    assert((_num_allocators + 1) < MAX_REG_ALLOCATORS, "too many register allocators");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _alloc_statistics[_num_allocators++] = pr_stats;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//------------------------------reg2offset-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
int PhaseRegAlloc::reg2offset_unchecked( OptoReg::Name reg ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Slots below _max_in_arg_stack_reg are offset by the entire frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Slots above _max_in_arg_stack_reg are frame_slots and are not offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  int slot = (reg < _matcher._new_SP)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    ? reg - OptoReg::stack0() + _framesize
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    : reg - _matcher._new_SP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Note:  We use the direct formula (reg - SharedInfo::stack0) instead of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // OptoReg::reg2stack(reg), in order to avoid asserts in the latter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // function.  This routine must remain unchecked, so that dump_frame()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // can do its work undisturbed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // %%% not really clear why reg2stack would assert here
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  return slot*VMRegImpl::stack_slot_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
int PhaseRegAlloc::reg2offset( OptoReg::Name reg ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Not allowed in the out-preserve area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // In-preserve area is allowed so Intel can fetch the return pc out.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  assert( reg <  _matcher._old_SP ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
          (reg >= OptoReg::add(_matcher._old_SP,C->out_preserve_stack_slots()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
           reg <  _matcher._in_arg_limit) ||
22853
308672304981 8028767: PPC64: (part 121): smaller shared changes needed to build C2
goetz
parents: 15241
diff changeset
    82
          reg >=  OptoReg::add(_matcher._new_SP, C->out_preserve_stack_slots()) ||
308672304981 8028767: PPC64: (part 121): smaller shared changes needed to build C2
goetz
parents: 15241
diff changeset
    83
          // Allow return_addr in the out-preserve area.
308672304981 8028767: PPC64: (part 121): smaller shared changes needed to build C2
goetz
parents: 15241
diff changeset
    84
          reg == _matcher.return_addr(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
          "register allocated in a preserve area" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  return reg2offset_unchecked( reg );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
//------------------------------offset2reg-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
OptoReg::Name PhaseRegAlloc::offset2reg(int stk_offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int slot = stk_offset / jintSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  int reg = (slot < (int) _framesize)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    ? slot + _matcher._new_SP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    : OptoReg::stack2reg(slot) - _framesize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  assert(stk_offset == reg2offset((OptoReg::Name) reg),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
         "offset2reg does not invert properly");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  return (OptoReg::Name) reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
//------------------------------set_oop----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
void PhaseRegAlloc::set_oop( const Node *n, bool is_an_oop ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  if( is_an_oop ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    _node_oops.set(n->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
//------------------------------is_oop-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
bool PhaseRegAlloc::is_oop( const Node *n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  return _node_oops.test(n->_idx) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
// Allocate _node_regs table with at least "size" elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
void PhaseRegAlloc::alloc_node_regs(int size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  _node_regs_max_index = size + (size >> 1) + NodeRegsOverflowSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  _node_regs = NEW_RESOURCE_ARRAY( OptoRegPair, _node_regs_max_index );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // We assume our caller will fill in all elements up to size-1, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // only the extra space we allocate is initialized here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  for( uint i = size; i < _node_regs_max_index; ++i )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    _node_regs[i].set_bad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
PhaseRegAlloc::print_statistics() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  tty->print_cr("Total frameslots = %d, Max frameslots = %d", _total_framesize, _max_framesize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  for (i=0; i < _num_allocators; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    _alloc_statistics[i]();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
#endif