src/share/vm/opto/regalloc.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 6876
710a3c8b516e
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "opto/regalloc.hpp"
aoqi@0 27
aoqi@0 28 static const int NodeRegsOverflowSize = 200;
aoqi@0 29
aoqi@0 30 void (*PhaseRegAlloc::_alloc_statistics[MAX_REG_ALLOCATORS])();
aoqi@0 31 int PhaseRegAlloc::_num_allocators = 0;
aoqi@0 32 #ifndef PRODUCT
aoqi@0 33 int PhaseRegAlloc::_total_framesize = 0;
aoqi@0 34 int PhaseRegAlloc::_max_framesize = 0;
aoqi@0 35 #endif
aoqi@0 36
aoqi@0 37 PhaseRegAlloc::PhaseRegAlloc( uint unique, PhaseCFG &cfg,
aoqi@0 38 Matcher &matcher,
aoqi@0 39 void (*pr_stats)() ):
aoqi@0 40 Phase(Register_Allocation), _cfg(cfg), _matcher(matcher),
aoqi@0 41 _node_oops(Thread::current()->resource_area()),
aoqi@0 42 _node_regs(0),
aoqi@0 43 _node_regs_max_index(0),
aoqi@0 44 _framesize(0xdeadbeef)
aoqi@0 45 {
aoqi@0 46 int i;
aoqi@0 47
aoqi@0 48 for (i=0; i < _num_allocators; i++) {
aoqi@0 49 if (_alloc_statistics[i] == pr_stats)
aoqi@0 50 return;
aoqi@0 51 }
aoqi@0 52 assert((_num_allocators + 1) < MAX_REG_ALLOCATORS, "too many register allocators");
aoqi@0 53 _alloc_statistics[_num_allocators++] = pr_stats;
aoqi@0 54 }
aoqi@0 55
aoqi@0 56
aoqi@0 57 //------------------------------reg2offset-------------------------------------
aoqi@0 58 int PhaseRegAlloc::reg2offset_unchecked( OptoReg::Name reg ) const {
aoqi@0 59 // Slots below _max_in_arg_stack_reg are offset by the entire frame.
aoqi@0 60 // Slots above _max_in_arg_stack_reg are frame_slots and are not offset.
aoqi@0 61 int slot = (reg < _matcher._new_SP)
aoqi@0 62 ? reg - OptoReg::stack0() + _framesize
aoqi@0 63 : reg - _matcher._new_SP;
aoqi@0 64 // Note: We use the direct formula (reg - SharedInfo::stack0) instead of
aoqi@0 65 // OptoReg::reg2stack(reg), in order to avoid asserts in the latter
aoqi@0 66 // function. This routine must remain unchecked, so that dump_frame()
aoqi@0 67 // can do its work undisturbed.
aoqi@0 68 // %%% not really clear why reg2stack would assert here
aoqi@0 69
aoqi@0 70 return slot*VMRegImpl::stack_slot_size;
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 int PhaseRegAlloc::reg2offset( OptoReg::Name reg ) const {
aoqi@0 74
aoqi@0 75 // Not allowed in the out-preserve area.
aoqi@0 76 // In-preserve area is allowed so Intel can fetch the return pc out.
aoqi@0 77 assert( reg < _matcher._old_SP ||
aoqi@0 78 (reg >= OptoReg::add(_matcher._old_SP,C->out_preserve_stack_slots()) &&
aoqi@0 79 reg < _matcher._in_arg_limit) ||
aoqi@0 80 reg >= OptoReg::add(_matcher._new_SP, C->out_preserve_stack_slots()) ||
aoqi@0 81 // Allow return_addr in the out-preserve area.
aoqi@0 82 reg == _matcher.return_addr(),
aoqi@0 83 "register allocated in a preserve area" );
aoqi@0 84 return reg2offset_unchecked( reg );
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 //------------------------------offset2reg-------------------------------------
aoqi@0 88 OptoReg::Name PhaseRegAlloc::offset2reg(int stk_offset) const {
aoqi@0 89 int slot = stk_offset / jintSize;
aoqi@0 90 int reg = (slot < (int) _framesize)
aoqi@0 91 ? slot + _matcher._new_SP
aoqi@0 92 : OptoReg::stack2reg(slot) - _framesize;
aoqi@0 93 assert(stk_offset == reg2offset((OptoReg::Name) reg),
aoqi@0 94 "offset2reg does not invert properly");
aoqi@0 95 return (OptoReg::Name) reg;
aoqi@0 96 }
aoqi@0 97
aoqi@0 98 //------------------------------set_oop----------------------------------------
aoqi@0 99 void PhaseRegAlloc::set_oop( const Node *n, bool is_an_oop ) {
aoqi@0 100 if( is_an_oop ) {
aoqi@0 101 _node_oops.set(n->_idx);
aoqi@0 102 }
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 //------------------------------is_oop-----------------------------------------
aoqi@0 106 bool PhaseRegAlloc::is_oop( const Node *n ) const {
aoqi@0 107 return _node_oops.test(n->_idx) != 0;
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 // Allocate _node_regs table with at least "size" elements
aoqi@0 111 void PhaseRegAlloc::alloc_node_regs(int size) {
aoqi@0 112 _node_regs_max_index = size + (size >> 1) + NodeRegsOverflowSize;
aoqi@0 113 _node_regs = NEW_RESOURCE_ARRAY( OptoRegPair, _node_regs_max_index );
aoqi@0 114 // We assume our caller will fill in all elements up to size-1, so
aoqi@0 115 // only the extra space we allocate is initialized here.
aoqi@0 116 for( uint i = size; i < _node_regs_max_index; ++i )
aoqi@0 117 _node_regs[i].set_bad();
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 #ifndef PRODUCT
aoqi@0 121 void
aoqi@0 122 PhaseRegAlloc::print_statistics() {
aoqi@0 123 tty->print_cr("Total frameslots = %d, Max frameslots = %d", _total_framesize, _max_framesize);
aoqi@0 124 int i;
aoqi@0 125
aoqi@0 126 for (i=0; i < _num_allocators; i++) {
aoqi@0 127 _alloc_statistics[i]();
aoqi@0 128 }
aoqi@0 129 }
aoqi@0 130 #endif

mercurial