Tue, 08 Aug 2017 15:57:29 +0800
merge
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef SHARE_VM_OPTO_REGMASK_HPP
32 #define SHARE_VM_OPTO_REGMASK_HPP
34 #include "code/vmreg.hpp"
35 #include "libadt/port.hpp"
36 #include "opto/optoreg.hpp"
37 #ifdef TARGET_ARCH_MODEL_x86_32
38 # include "adfiles/adGlobals_x86_32.hpp"
39 #endif
40 #ifdef TARGET_ARCH_MODEL_x86_64
41 # include "adfiles/adGlobals_x86_64.hpp"
42 #endif
43 #ifdef TARGET_ARCH_MODEL_mips_64
44 # include "adfiles/adGlobals_mips_64.hpp"
45 #endif
46 #ifdef TARGET_ARCH_MODEL_sparc
47 # include "adfiles/adGlobals_sparc.hpp"
48 #endif
49 #ifdef TARGET_ARCH_MODEL_zero
50 # include "adfiles/adGlobals_zero.hpp"
51 #endif
52 #ifdef TARGET_ARCH_MODEL_arm
53 # include "adfiles/adGlobals_arm.hpp"
54 #endif
55 #ifdef TARGET_ARCH_MODEL_ppc_32
56 # include "adfiles/adGlobals_ppc_32.hpp"
57 #endif
58 #ifdef TARGET_ARCH_MODEL_ppc_64
59 # include "adfiles/adGlobals_ppc_64.hpp"
60 #endif
62 // Some fun naming (textual) substitutions:
63 //
64 // RegMask::get_low_elem() ==> RegMask::find_first_elem()
65 // RegMask::Special ==> RegMask::Empty
66 // RegMask::_flags ==> RegMask::is_AllStack()
67 // RegMask::operator<<=() ==> RegMask::Insert()
68 // RegMask::operator>>=() ==> RegMask::Remove()
69 // RegMask::Union() ==> RegMask::OR
70 // RegMask::Inter() ==> RegMask::AND
71 //
72 // OptoRegister::RegName ==> OptoReg::Name
73 //
74 // OptoReg::stack0() ==> _last_Mach_Reg or ZERO in core version
75 //
76 // numregs in chaitin ==> proper degree in chaitin
78 //-------------Non-zero bit search methods used by RegMask---------------------
79 // Find lowest 1, or return 32 if empty
80 int find_lowest_bit( uint32 mask );
81 // Find highest 1, or return 32 if empty
82 int find_hihghest_bit( uint32 mask );
84 //------------------------------RegMask----------------------------------------
85 // The ADL file describes how to print the machine-specific registers, as well
86 // as any notion of register classes. We provide a register mask, which is
87 // just a collection of Register numbers.
89 // The ADLC defines 2 macros, RM_SIZE and FORALL_BODY.
90 // RM_SIZE is the size of a register mask in words.
91 // FORALL_BODY replicates a BODY macro once per word in the register mask.
92 // The usage is somewhat clumsy and limited to the regmask.[h,c]pp files.
93 // However, it means the ADLC can redefine the unroll macro and all loops
94 // over register masks will be unrolled by the correct amount.
96 class RegMask VALUE_OBJ_CLASS_SPEC {
97 union {
98 double _dummy_force_double_alignment[RM_SIZE>>1];
99 // Array of Register Mask bits. This array is large enough to cover
100 // all the machine registers and all parameters that need to be passed
101 // on the stack (stack registers) up to some interesting limit. Methods
102 // that need more parameters will NOT be compiled. On Intel, the limit
103 // is something like 90+ parameters.
104 int _A[RM_SIZE];
105 };
107 enum {
108 _WordBits = BitsPerInt,
109 _LogWordBits = LogBitsPerInt,
110 _RM_SIZE = RM_SIZE // local constant, imported, then hidden by #undef
111 };
113 public:
114 enum { CHUNK_SIZE = RM_SIZE*_WordBits };
116 // SlotsPerLong is 2, since slots are 32 bits and longs are 64 bits.
117 // Also, consider the maximum alignment size for a normally allocated
118 // value. Since we allocate register pairs but not register quads (at
119 // present), this alignment is SlotsPerLong (== 2). A normally
120 // aligned allocated register is either a single register, or a pair
121 // of adjacent registers, the lower-numbered being even.
122 // See also is_aligned_Pairs() below, and the padding added before
123 // Matcher::_new_SP to keep allocated pairs aligned properly.
124 // If we ever go to quad-word allocations, SlotsPerQuad will become
125 // the controlling alignment constraint. Note that this alignment
126 // requirement is internal to the allocator, and independent of any
127 // particular platform.
128 enum { SlotsPerLong = 2,
129 SlotsPerVecS = 1,
130 SlotsPerVecD = 2,
131 SlotsPerVecX = 4,
132 SlotsPerVecY = 8 };
134 // A constructor only used by the ADLC output. All mask fields are filled
135 // in directly. Calls to this look something like RM(1,2,3,4);
136 RegMask(
137 # define BODY(I) int a##I,
138 FORALL_BODY
139 # undef BODY
140 int dummy = 0 ) {
141 # define BODY(I) _A[I] = a##I;
142 FORALL_BODY
143 # undef BODY
144 }
146 // Handy copying constructor
147 RegMask( RegMask *rm ) {
148 # define BODY(I) _A[I] = rm->_A[I];
149 FORALL_BODY
150 # undef BODY
151 }
153 // Construct an empty mask
154 RegMask( ) { Clear(); }
156 // Construct a mask with a single bit
157 RegMask( OptoReg::Name reg ) { Clear(); Insert(reg); }
159 // Check for register being in mask
160 int Member( OptoReg::Name reg ) const {
161 assert( reg < CHUNK_SIZE, "" );
162 return _A[reg>>_LogWordBits] & (1<<(reg&(_WordBits-1)));
163 }
165 // The last bit in the register mask indicates that the mask should repeat
166 // indefinitely with ONE bits. Returns TRUE if mask is infinite or
167 // unbounded in size. Returns FALSE if mask is finite size.
168 int is_AllStack() const { return _A[RM_SIZE-1] >> (_WordBits-1); }
170 // Work around an -xO3 optimization problme in WS6U1. The old way:
171 // void set_AllStack() { _A[RM_SIZE-1] |= (1<<(_WordBits-1)); }
172 // will cause _A[RM_SIZE-1] to be clobbered, not updated when set_AllStack()
173 // follows an Insert() loop, like the one found in init_spill_mask(). Using
174 // Insert() instead works because the index into _A in computed instead of
175 // constant. See bug 4665841.
176 void set_AllStack() { Insert(OptoReg::Name(CHUNK_SIZE-1)); }
178 // Test for being a not-empty mask.
179 int is_NotEmpty( ) const {
180 int tmp = 0;
181 # define BODY(I) tmp |= _A[I];
182 FORALL_BODY
183 # undef BODY
184 return tmp;
185 }
187 // Find lowest-numbered register from mask, or BAD if mask is empty.
188 OptoReg::Name find_first_elem() const {
189 int base, bits;
190 # define BODY(I) if( (bits = _A[I]) != 0 ) base = I<<_LogWordBits; else
191 FORALL_BODY
192 # undef BODY
193 { base = OptoReg::Bad; bits = 1<<0; }
194 return OptoReg::Name(base + find_lowest_bit(bits));
195 }
196 // Get highest-numbered register from mask, or BAD if mask is empty.
197 OptoReg::Name find_last_elem() const {
198 int base, bits;
199 # define BODY(I) if( (bits = _A[RM_SIZE-1-I]) != 0 ) base = (RM_SIZE-1-I)<<_LogWordBits; else
200 FORALL_BODY
201 # undef BODY
202 { base = OptoReg::Bad; bits = 1<<0; }
203 return OptoReg::Name(base + find_hihghest_bit(bits));
204 }
206 // Find the lowest-numbered register pair in the mask. Return the
207 // HIGHEST register number in the pair, or BAD if no pairs.
208 // Assert that the mask contains only bit pairs.
209 OptoReg::Name find_first_pair() const;
211 // Clear out partial bits; leave only aligned adjacent bit pairs.
212 void clear_to_pairs();
213 // Smear out partial bits; leave only aligned adjacent bit pairs.
214 void smear_to_pairs();
215 // Verify that the mask contains only aligned adjacent bit pairs
216 void verify_pairs() const { assert( is_aligned_pairs(), "mask is not aligned, adjacent pairs" ); }
217 // Test that the mask contains only aligned adjacent bit pairs
218 bool is_aligned_pairs() const;
220 // mask is a pair of misaligned registers
221 bool is_misaligned_pair() const { return Size()==2 && !is_aligned_pairs(); }
222 // Test for single register
223 int is_bound1() const;
224 // Test for a single adjacent pair
225 int is_bound_pair() const;
226 // Test for a single adjacent set of ideal register's size.
227 int is_bound(uint ireg) const {
228 if (is_vector(ireg)) {
229 if (is_bound_set(num_registers(ireg)))
230 return true;
231 } else if (is_bound1() || is_bound_pair()) {
232 return true;
233 }
234 return false;
235 }
237 // Find the lowest-numbered register set in the mask. Return the
238 // HIGHEST register number in the set, or BAD if no sets.
239 // Assert that the mask contains only bit sets.
240 OptoReg::Name find_first_set(const int size) const;
242 // Clear out partial bits; leave only aligned adjacent bit sets of size.
243 void clear_to_sets(const int size);
244 // Smear out partial bits to aligned adjacent bit sets.
245 void smear_to_sets(const int size);
246 // Verify that the mask contains only aligned adjacent bit sets
247 void verify_sets(int size) const { assert(is_aligned_sets(size), "mask is not aligned, adjacent sets"); }
248 // Test that the mask contains only aligned adjacent bit sets
249 bool is_aligned_sets(const int size) const;
251 // mask is a set of misaligned registers
252 bool is_misaligned_set(int size) const { return (int)Size()==size && !is_aligned_sets(size);}
254 // Test for a single adjacent set
255 int is_bound_set(const int size) const;
257 static bool is_vector(uint ireg);
258 static int num_registers(uint ireg);
260 // Fast overlap test. Non-zero if any registers in common.
261 int overlap( const RegMask &rm ) const {
262 return
263 # define BODY(I) (_A[I] & rm._A[I]) |
264 FORALL_BODY
265 # undef BODY
266 0 ;
267 }
269 // Special test for register pressure based splitting
270 // UP means register only, Register plus stack, or stack only is DOWN
271 bool is_UP() const;
273 // Clear a register mask
274 void Clear( ) {
275 # define BODY(I) _A[I] = 0;
276 FORALL_BODY
277 # undef BODY
278 }
280 // Fill a register mask with 1's
281 void Set_All( ) {
282 # define BODY(I) _A[I] = -1;
283 FORALL_BODY
284 # undef BODY
285 }
287 // Insert register into mask
288 void Insert( OptoReg::Name reg ) {
289 assert( reg < CHUNK_SIZE, "" );
290 _A[reg>>_LogWordBits] |= (1<<(reg&(_WordBits-1)));
291 }
293 // Remove register from mask
294 void Remove( OptoReg::Name reg ) {
295 assert( reg < CHUNK_SIZE, "" );
296 _A[reg>>_LogWordBits] &= ~(1<<(reg&(_WordBits-1)));
297 }
299 // OR 'rm' into 'this'
300 void OR( const RegMask &rm ) {
301 # define BODY(I) this->_A[I] |= rm._A[I];
302 FORALL_BODY
303 # undef BODY
304 }
306 // AND 'rm' into 'this'
307 void AND( const RegMask &rm ) {
308 # define BODY(I) this->_A[I] &= rm._A[I];
309 FORALL_BODY
310 # undef BODY
311 }
313 // Subtract 'rm' from 'this'
314 void SUBTRACT( const RegMask &rm ) {
315 # define BODY(I) _A[I] &= ~rm._A[I];
316 FORALL_BODY
317 # undef BODY
318 }
320 // Compute size of register mask: number of bits
321 uint Size() const;
323 #ifndef PRODUCT
324 void print() const { dump(); }
325 void dump(outputStream *st = tty) const; // Print a mask
326 #endif
328 static const RegMask Empty; // Common empty mask
330 static bool can_represent(OptoReg::Name reg) {
331 // NOTE: -1 in computation reflects the usage of the last
332 // bit of the regmask as an infinite stack flag and
333 // -7 is to keep mask aligned for largest value (VecY).
334 return (int)reg < (int)(CHUNK_SIZE-1);
335 }
336 static bool can_represent_arg(OptoReg::Name reg) {
337 // NOTE: -SlotsPerVecY in computation reflects the need
338 // to keep mask aligned for largest value (VecY).
339 return (int)reg < (int)(CHUNK_SIZE-SlotsPerVecY);
340 }
341 };
343 // Do not use this constant directly in client code!
344 #undef RM_SIZE
346 #endif // SHARE_VM_OPTO_REGMASK_HPP