1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/regmask.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,460 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "opto/compile.hpp" 1.30 +#include "opto/regmask.hpp" 1.31 +#ifdef TARGET_ARCH_MODEL_x86_32 1.32 +# include "adfiles/ad_x86_32.hpp" 1.33 +#endif 1.34 +#ifdef TARGET_ARCH_MODEL_x86_64 1.35 +# include "adfiles/ad_x86_64.hpp" 1.36 +#endif 1.37 +#ifdef TARGET_ARCH_MODEL_sparc 1.38 +# include "adfiles/ad_sparc.hpp" 1.39 +#endif 1.40 +#ifdef TARGET_ARCH_MODEL_zero 1.41 +# include "adfiles/ad_zero.hpp" 1.42 +#endif 1.43 +#ifdef TARGET_ARCH_MODEL_arm 1.44 +# include "adfiles/ad_arm.hpp" 1.45 +#endif 1.46 +#ifdef TARGET_ARCH_MODEL_ppc_32 1.47 +# include "adfiles/ad_ppc_32.hpp" 1.48 +#endif 1.49 +#ifdef TARGET_ARCH_MODEL_ppc_64 1.50 +# include "adfiles/ad_ppc_64.hpp" 1.51 +#endif 1.52 + 1.53 +#define RM_SIZE _RM_SIZE /* a constant private to the class RegMask */ 1.54 + 1.55 +//-------------Non-zero bit search methods used by RegMask--------------------- 1.56 +// Find lowest 1, or return 32 if empty 1.57 +int find_lowest_bit( uint32 mask ) { 1.58 + int n = 0; 1.59 + if( (mask & 0xffff) == 0 ) { 1.60 + mask >>= 16; 1.61 + n += 16; 1.62 + } 1.63 + if( (mask & 0xff) == 0 ) { 1.64 + mask >>= 8; 1.65 + n += 8; 1.66 + } 1.67 + if( (mask & 0xf) == 0 ) { 1.68 + mask >>= 4; 1.69 + n += 4; 1.70 + } 1.71 + if( (mask & 0x3) == 0 ) { 1.72 + mask >>= 2; 1.73 + n += 2; 1.74 + } 1.75 + if( (mask & 0x1) == 0 ) { 1.76 + mask >>= 1; 1.77 + n += 1; 1.78 + } 1.79 + if( mask == 0 ) { 1.80 + n = 32; 1.81 + } 1.82 + return n; 1.83 +} 1.84 + 1.85 +// Find highest 1, or return 32 if empty 1.86 +int find_hihghest_bit( uint32 mask ) { 1.87 + int n = 0; 1.88 + if( mask > 0xffff ) { 1.89 + mask >>= 16; 1.90 + n += 16; 1.91 + } 1.92 + if( mask > 0xff ) { 1.93 + mask >>= 8; 1.94 + n += 8; 1.95 + } 1.96 + if( mask > 0xf ) { 1.97 + mask >>= 4; 1.98 + n += 4; 1.99 + } 1.100 + if( mask > 0x3 ) { 1.101 + mask >>= 2; 1.102 + n += 2; 1.103 + } 1.104 + if( mask > 0x1 ) { 1.105 + mask >>= 1; 1.106 + n += 1; 1.107 + } 1.108 + if( mask == 0 ) { 1.109 + n = 32; 1.110 + } 1.111 + return n; 1.112 +} 1.113 + 1.114 +//------------------------------dump------------------------------------------- 1.115 + 1.116 +#ifndef PRODUCT 1.117 +void OptoReg::dump(int r, outputStream *st) { 1.118 + switch (r) { 1.119 + case Special: st->print("r---"); break; 1.120 + case Bad: st->print("rBAD"); break; 1.121 + default: 1.122 + if (r < _last_Mach_Reg) st->print("%s", Matcher::regName[r]); 1.123 + else st->print("rS%d",r); 1.124 + break; 1.125 + } 1.126 +} 1.127 +#endif 1.128 + 1.129 + 1.130 +//============================================================================= 1.131 +const RegMask RegMask::Empty( 1.132 +# define BODY(I) 0, 1.133 + FORALL_BODY 1.134 +# undef BODY 1.135 + 0 1.136 +); 1.137 + 1.138 +//============================================================================= 1.139 +bool RegMask::is_vector(uint ireg) { 1.140 + return (ireg == Op_VecS || ireg == Op_VecD || ireg == Op_VecX || ireg == Op_VecY); 1.141 +} 1.142 + 1.143 +int RegMask::num_registers(uint ireg) { 1.144 + switch(ireg) { 1.145 + case Op_VecY: 1.146 + return 8; 1.147 + case Op_VecX: 1.148 + return 4; 1.149 + case Op_VecD: 1.150 + case Op_RegD: 1.151 + case Op_RegL: 1.152 +#ifdef _LP64 1.153 + case Op_RegP: 1.154 +#endif 1.155 + return 2; 1.156 + } 1.157 + // Op_VecS and the rest ideal registers. 1.158 + return 1; 1.159 +} 1.160 + 1.161 +//------------------------------find_first_pair-------------------------------- 1.162 +// Find the lowest-numbered register pair in the mask. Return the 1.163 +// HIGHEST register number in the pair, or BAD if no pairs. 1.164 +OptoReg::Name RegMask::find_first_pair() const { 1.165 + verify_pairs(); 1.166 + for( int i = 0; i < RM_SIZE; i++ ) { 1.167 + if( _A[i] ) { // Found some bits 1.168 + int bit = _A[i] & -_A[i]; // Extract low bit 1.169 + // Convert to bit number, return hi bit in pair 1.170 + return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+1); 1.171 + } 1.172 + } 1.173 + return OptoReg::Bad; 1.174 +} 1.175 + 1.176 +//------------------------------ClearToPairs----------------------------------- 1.177 +// Clear out partial bits; leave only bit pairs 1.178 +void RegMask::clear_to_pairs() { 1.179 + for( int i = 0; i < RM_SIZE; i++ ) { 1.180 + int bits = _A[i]; 1.181 + bits &= ((bits & 0x55555555)<<1); // 1 hi-bit set for each pair 1.182 + bits |= (bits>>1); // Smear 1 hi-bit into a pair 1.183 + _A[i] = bits; 1.184 + } 1.185 + verify_pairs(); 1.186 +} 1.187 + 1.188 +//------------------------------SmearToPairs----------------------------------- 1.189 +// Smear out partial bits; leave only bit pairs 1.190 +void RegMask::smear_to_pairs() { 1.191 + for( int i = 0; i < RM_SIZE; i++ ) { 1.192 + int bits = _A[i]; 1.193 + bits |= ((bits & 0x55555555)<<1); // Smear lo bit hi per pair 1.194 + bits |= ((bits & 0xAAAAAAAA)>>1); // Smear hi bit lo per pair 1.195 + _A[i] = bits; 1.196 + } 1.197 + verify_pairs(); 1.198 +} 1.199 + 1.200 +//------------------------------is_aligned_pairs------------------------------- 1.201 +bool RegMask::is_aligned_pairs() const { 1.202 + // Assert that the register mask contains only bit pairs. 1.203 + for( int i = 0; i < RM_SIZE; i++ ) { 1.204 + int bits = _A[i]; 1.205 + while( bits ) { // Check bits for pairing 1.206 + int bit = bits & -bits; // Extract low bit 1.207 + // Low bit is not odd means its mis-aligned. 1.208 + if( (bit & 0x55555555) == 0 ) return false; 1.209 + bits -= bit; // Remove bit from mask 1.210 + // Check for aligned adjacent bit 1.211 + if( (bits & (bit<<1)) == 0 ) return false; 1.212 + bits -= (bit<<1); // Remove other halve of pair 1.213 + } 1.214 + } 1.215 + return true; 1.216 +} 1.217 + 1.218 +//------------------------------is_bound1-------------------------------------- 1.219 +// Return TRUE if the mask contains a single bit 1.220 +int RegMask::is_bound1() const { 1.221 + if( is_AllStack() ) return false; 1.222 + int bit = -1; // Set to hold the one bit allowed 1.223 + for( int i = 0; i < RM_SIZE; i++ ) { 1.224 + if( _A[i] ) { // Found some bits 1.225 + if( bit != -1 ) return false; // Already had bits, so fail 1.226 + bit = _A[i] & -_A[i]; // Extract 1 bit from mask 1.227 + if( bit != _A[i] ) return false; // Found many bits, so fail 1.228 + } 1.229 + } 1.230 + // True for both the empty mask and for a single bit 1.231 + return true; 1.232 +} 1.233 + 1.234 +//------------------------------is_bound2-------------------------------------- 1.235 +// Return TRUE if the mask contains an adjacent pair of bits and no other bits. 1.236 +int RegMask::is_bound_pair() const { 1.237 + if( is_AllStack() ) return false; 1.238 + 1.239 + int bit = -1; // Set to hold the one bit allowed 1.240 + for( int i = 0; i < RM_SIZE; i++ ) { 1.241 + if( _A[i] ) { // Found some bits 1.242 + if( bit != -1 ) return false; // Already had bits, so fail 1.243 + bit = _A[i] & -(_A[i]); // Extract 1 bit from mask 1.244 + if( (bit << 1) != 0 ) { // Bit pair stays in same word? 1.245 + if( (bit | (bit<<1)) != _A[i] ) 1.246 + return false; // Require adjacent bit pair and no more bits 1.247 + } else { // Else its a split-pair case 1.248 + if( bit != _A[i] ) return false; // Found many bits, so fail 1.249 + i++; // Skip iteration forward 1.250 + if( i >= RM_SIZE || _A[i] != 1 ) 1.251 + return false; // Require 1 lo bit in next word 1.252 + } 1.253 + } 1.254 + } 1.255 + // True for both the empty mask and for a bit pair 1.256 + return true; 1.257 +} 1.258 + 1.259 +static int low_bits[3] = { 0x55555555, 0x11111111, 0x01010101 }; 1.260 +//------------------------------find_first_set--------------------------------- 1.261 +// Find the lowest-numbered register set in the mask. Return the 1.262 +// HIGHEST register number in the set, or BAD if no sets. 1.263 +// Works also for size 1. 1.264 +OptoReg::Name RegMask::find_first_set(const int size) const { 1.265 + verify_sets(size); 1.266 + for (int i = 0; i < RM_SIZE; i++) { 1.267 + if (_A[i]) { // Found some bits 1.268 + int bit = _A[i] & -_A[i]; // Extract low bit 1.269 + // Convert to bit number, return hi bit in pair 1.270 + return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+(size-1)); 1.271 + } 1.272 + } 1.273 + return OptoReg::Bad; 1.274 +} 1.275 + 1.276 +//------------------------------clear_to_sets---------------------------------- 1.277 +// Clear out partial bits; leave only aligned adjacent bit pairs 1.278 +void RegMask::clear_to_sets(const int size) { 1.279 + if (size == 1) return; 1.280 + assert(2 <= size && size <= 8, "update low bits table"); 1.281 + assert(is_power_of_2(size), "sanity"); 1.282 + int low_bits_mask = low_bits[size>>2]; 1.283 + for (int i = 0; i < RM_SIZE; i++) { 1.284 + int bits = _A[i]; 1.285 + int sets = (bits & low_bits_mask); 1.286 + for (int j = 1; j < size; j++) { 1.287 + sets = (bits & (sets<<1)); // filter bits which produce whole sets 1.288 + } 1.289 + sets |= (sets>>1); // Smear 1 hi-bit into a set 1.290 + if (size > 2) { 1.291 + sets |= (sets>>2); // Smear 2 hi-bits into a set 1.292 + if (size > 4) { 1.293 + sets |= (sets>>4); // Smear 4 hi-bits into a set 1.294 + } 1.295 + } 1.296 + _A[i] = sets; 1.297 + } 1.298 + verify_sets(size); 1.299 +} 1.300 + 1.301 +//------------------------------smear_to_sets---------------------------------- 1.302 +// Smear out partial bits to aligned adjacent bit sets 1.303 +void RegMask::smear_to_sets(const int size) { 1.304 + if (size == 1) return; 1.305 + assert(2 <= size && size <= 8, "update low bits table"); 1.306 + assert(is_power_of_2(size), "sanity"); 1.307 + int low_bits_mask = low_bits[size>>2]; 1.308 + for (int i = 0; i < RM_SIZE; i++) { 1.309 + int bits = _A[i]; 1.310 + int sets = 0; 1.311 + for (int j = 0; j < size; j++) { 1.312 + sets |= (bits & low_bits_mask); // collect partial bits 1.313 + bits = bits>>1; 1.314 + } 1.315 + sets |= (sets<<1); // Smear 1 lo-bit into a set 1.316 + if (size > 2) { 1.317 + sets |= (sets<<2); // Smear 2 lo-bits into a set 1.318 + if (size > 4) { 1.319 + sets |= (sets<<4); // Smear 4 lo-bits into a set 1.320 + } 1.321 + } 1.322 + _A[i] = sets; 1.323 + } 1.324 + verify_sets(size); 1.325 +} 1.326 + 1.327 +//------------------------------is_aligned_set-------------------------------- 1.328 +bool RegMask::is_aligned_sets(const int size) const { 1.329 + if (size == 1) return true; 1.330 + assert(2 <= size && size <= 8, "update low bits table"); 1.331 + assert(is_power_of_2(size), "sanity"); 1.332 + int low_bits_mask = low_bits[size>>2]; 1.333 + // Assert that the register mask contains only bit sets. 1.334 + for (int i = 0; i < RM_SIZE; i++) { 1.335 + int bits = _A[i]; 1.336 + while (bits) { // Check bits for pairing 1.337 + int bit = bits & -bits; // Extract low bit 1.338 + // Low bit is not odd means its mis-aligned. 1.339 + if ((bit & low_bits_mask) == 0) return false; 1.340 + // Do extra work since (bit << size) may overflow. 1.341 + int hi_bit = bit << (size-1); // high bit 1.342 + int set = hi_bit + ((hi_bit-1) & ~(bit-1)); 1.343 + // Check for aligned adjacent bits in this set 1.344 + if ((bits & set) != set) return false; 1.345 + bits -= set; // Remove this set 1.346 + } 1.347 + } 1.348 + return true; 1.349 +} 1.350 + 1.351 +//------------------------------is_bound_set----------------------------------- 1.352 +// Return TRUE if the mask contains one adjacent set of bits and no other bits. 1.353 +// Works also for size 1. 1.354 +int RegMask::is_bound_set(const int size) const { 1.355 + if( is_AllStack() ) return false; 1.356 + assert(1 <= size && size <= 8, "update low bits table"); 1.357 + int bit = -1; // Set to hold the one bit allowed 1.358 + for (int i = 0; i < RM_SIZE; i++) { 1.359 + if (_A[i] ) { // Found some bits 1.360 + if (bit != -1) 1.361 + return false; // Already had bits, so fail 1.362 + bit = _A[i] & -_A[i]; // Extract low bit from mask 1.363 + int hi_bit = bit << (size-1); // high bit 1.364 + if (hi_bit != 0) { // Bit set stays in same word? 1.365 + int set = hi_bit + ((hi_bit-1) & ~(bit-1)); 1.366 + if (set != _A[i]) 1.367 + return false; // Require adjacent bit set and no more bits 1.368 + } else { // Else its a split-set case 1.369 + if (((-1) & ~(bit-1)) != _A[i]) 1.370 + return false; // Found many bits, so fail 1.371 + i++; // Skip iteration forward and check high part 1.372 + // The lower 24 bits should be 0 since it is split case and size <= 8. 1.373 + int set = bit>>24; 1.374 + set = set & -set; // Remove sign extension. 1.375 + set = (((set << size) - 1) >> 8); 1.376 + if (i >= RM_SIZE || _A[i] != set) 1.377 + return false; // Require expected low bits in next word 1.378 + } 1.379 + } 1.380 + } 1.381 + // True for both the empty mask and for a bit set 1.382 + return true; 1.383 +} 1.384 + 1.385 +//------------------------------is_UP------------------------------------------ 1.386 +// UP means register only, Register plus stack, or stack only is DOWN 1.387 +bool RegMask::is_UP() const { 1.388 + // Quick common case check for DOWN (any stack slot is legal) 1.389 + if( is_AllStack() ) 1.390 + return false; 1.391 + // Slower check for any stack bits set (also DOWN) 1.392 + if( overlap(Matcher::STACK_ONLY_mask) ) 1.393 + return false; 1.394 + // Not DOWN, so must be UP 1.395 + return true; 1.396 +} 1.397 + 1.398 +//------------------------------Size------------------------------------------- 1.399 +// Compute size of register mask in bits 1.400 +uint RegMask::Size() const { 1.401 + extern uint8 bitsInByte[256]; 1.402 + uint sum = 0; 1.403 + for( int i = 0; i < RM_SIZE; i++ ) 1.404 + sum += 1.405 + bitsInByte[(_A[i]>>24) & 0xff] + 1.406 + bitsInByte[(_A[i]>>16) & 0xff] + 1.407 + bitsInByte[(_A[i]>> 8) & 0xff] + 1.408 + bitsInByte[ _A[i] & 0xff]; 1.409 + return sum; 1.410 +} 1.411 + 1.412 +#ifndef PRODUCT 1.413 +//------------------------------print------------------------------------------ 1.414 +void RegMask::dump(outputStream *st) const { 1.415 + st->print("["); 1.416 + RegMask rm = *this; // Structure copy into local temp 1.417 + 1.418 + OptoReg::Name start = rm.find_first_elem(); // Get a register 1.419 + if (OptoReg::is_valid(start)) { // Check for empty mask 1.420 + rm.Remove(start); // Yank from mask 1.421 + OptoReg::dump(start, st); // Print register 1.422 + OptoReg::Name last = start; 1.423 + 1.424 + // Now I have printed an initial register. 1.425 + // Print adjacent registers as "rX-rZ" instead of "rX,rY,rZ". 1.426 + // Begin looping over the remaining registers. 1.427 + while (1) { // 1.428 + OptoReg::Name reg = rm.find_first_elem(); // Get a register 1.429 + if (!OptoReg::is_valid(reg)) 1.430 + break; // Empty mask, end loop 1.431 + rm.Remove(reg); // Yank from mask 1.432 + 1.433 + if (last+1 == reg) { // See if they are adjacent 1.434 + // Adjacent registers just collect into long runs, no printing. 1.435 + last = reg; 1.436 + } else { // Ending some kind of run 1.437 + if (start == last) { // 1-register run; no special printing 1.438 + } else if (start+1 == last) { 1.439 + st->print(","); // 2-register run; print as "rX,rY" 1.440 + OptoReg::dump(last, st); 1.441 + } else { // Multi-register run; print as "rX-rZ" 1.442 + st->print("-"); 1.443 + OptoReg::dump(last, st); 1.444 + } 1.445 + st->print(","); // Seperate start of new run 1.446 + start = last = reg; // Start a new register run 1.447 + OptoReg::dump(start, st); // Print register 1.448 + } // End of if ending a register run or not 1.449 + } // End of while regmask not empty 1.450 + 1.451 + if (start == last) { // 1-register run; no special printing 1.452 + } else if (start+1 == last) { 1.453 + st->print(","); // 2-register run; print as "rX,rY" 1.454 + OptoReg::dump(last, st); 1.455 + } else { // Multi-register run; print as "rX-rZ" 1.456 + st->print("-"); 1.457 + OptoReg::dump(last, st); 1.458 + } 1.459 + if (rm.is_AllStack()) st->print("..."); 1.460 + } 1.461 + st->print("]"); 1.462 +} 1.463 +#endif