annotate src/share/vm/opto/regalloc.cpp @ 17795:a9becfeecd1b

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