src/share/vm/opto/regmask.cpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added MIPS 64-bit port.

     1 /*
     2  * Copyright (c) 1997, 2014, 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 #include "precompiled.hpp"
    32 #include "opto/compile.hpp"
    33 #include "opto/regmask.hpp"
    34 #ifdef TARGET_ARCH_MODEL_x86_32
    35 # include "adfiles/ad_x86_32.hpp"
    36 #endif
    37 #ifdef TARGET_ARCH_MODEL_x86_64
    38 # include "adfiles/ad_x86_64.hpp"
    39 #endif
    40 #ifdef TARGET_ARCH_MODEL_mips_64
    41 # include "adfiles/ad_mips_64.hpp"
    42 #endif
    43 #ifdef TARGET_ARCH_MODEL_sparc
    44 # include "adfiles/ad_sparc.hpp"
    45 #endif
    46 #ifdef TARGET_ARCH_MODEL_zero
    47 # include "adfiles/ad_zero.hpp"
    48 #endif
    49 #ifdef TARGET_ARCH_MODEL_arm
    50 # include "adfiles/ad_arm.hpp"
    51 #endif
    52 #ifdef TARGET_ARCH_MODEL_ppc_32
    53 # include "adfiles/ad_ppc_32.hpp"
    54 #endif
    55 #ifdef TARGET_ARCH_MODEL_ppc_64
    56 # include "adfiles/ad_ppc_64.hpp"
    57 #endif
    59 #define RM_SIZE _RM_SIZE /* a constant private to the class RegMask */
    61 //-------------Non-zero bit search methods used by RegMask---------------------
    62 // Find lowest 1, or return 32 if empty
    63 int find_lowest_bit( uint32 mask ) {
    64   int n = 0;
    65   if( (mask & 0xffff) == 0 ) {
    66     mask >>= 16;
    67     n += 16;
    68   }
    69   if( (mask & 0xff) == 0 ) {
    70     mask >>= 8;
    71     n += 8;
    72   }
    73   if( (mask & 0xf) == 0 ) {
    74     mask >>= 4;
    75     n += 4;
    76   }
    77   if( (mask & 0x3) == 0 ) {
    78     mask >>= 2;
    79     n += 2;
    80   }
    81   if( (mask & 0x1) == 0 ) {
    82     mask >>= 1;
    83      n += 1;
    84   }
    85   if( mask == 0 ) {
    86     n = 32;
    87   }
    88   return n;
    89 }
    91 // Find highest 1, or return 32 if empty
    92 int find_hihghest_bit( uint32 mask ) {
    93   int n = 0;
    94   if( mask > 0xffff ) {
    95     mask >>= 16;
    96     n += 16;
    97   }
    98   if( mask > 0xff ) {
    99     mask >>= 8;
   100     n += 8;
   101   }
   102   if( mask > 0xf ) {
   103     mask >>= 4;
   104     n += 4;
   105   }
   106   if( mask > 0x3 ) {
   107     mask >>= 2;
   108     n += 2;
   109   }
   110   if( mask > 0x1 ) {
   111     mask >>= 1;
   112     n += 1;
   113   }
   114   if( mask == 0 ) {
   115     n = 32;
   116   }
   117   return n;
   118 }
   120 //------------------------------dump-------------------------------------------
   122 #ifndef PRODUCT
   123 void OptoReg::dump(int r, outputStream *st) {
   124   switch (r) {
   125   case Special: st->print("r---"); break;
   126   case Bad:     st->print("rBAD"); break;
   127   default:
   128     if (r < _last_Mach_Reg) st->print("%s", Matcher::regName[r]);
   129     else st->print("rS%d",r);
   130     break;
   131   }
   132 }
   133 #endif
   136 //=============================================================================
   137 const RegMask RegMask::Empty(
   138 # define BODY(I) 0,
   139   FORALL_BODY
   140 # undef BODY
   141   0
   142 );
   144 //=============================================================================
   145 bool RegMask::is_vector(uint ireg) {
   146   return (ireg == Op_VecS || ireg == Op_VecD || ireg == Op_VecX || ireg == Op_VecY);
   147 }
   149 int RegMask::num_registers(uint ireg) {
   150     switch(ireg) {
   151       case Op_VecY:
   152         return 8;
   153       case Op_VecX:
   154         return 4;
   155       case Op_VecD:
   156       case Op_RegD:
   157       case Op_RegL:
   158 #ifdef _LP64
   159       case Op_RegP:
   160 #endif
   161         return 2;
   162     }
   163     // Op_VecS and the rest ideal registers.
   164     return 1;
   165 }
   167 //------------------------------find_first_pair--------------------------------
   168 // Find the lowest-numbered register pair in the mask.  Return the
   169 // HIGHEST register number in the pair, or BAD if no pairs.
   170 OptoReg::Name RegMask::find_first_pair() const {
   171   verify_pairs();
   172   for( int i = 0; i < RM_SIZE; i++ ) {
   173     if( _A[i] ) {               // Found some bits
   174       int bit = _A[i] & -_A[i]; // Extract low bit
   175       // Convert to bit number, return hi bit in pair
   176       return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+1);
   177     }
   178   }
   179   return OptoReg::Bad;
   180 }
   182 //------------------------------ClearToPairs-----------------------------------
   183 // Clear out partial bits; leave only bit pairs
   184 void RegMask::clear_to_pairs() {
   185   for( int i = 0; i < RM_SIZE; i++ ) {
   186     int bits = _A[i];
   187     bits &= ((bits & 0x55555555)<<1); // 1 hi-bit set for each pair
   188     bits |= (bits>>1);          // Smear 1 hi-bit into a pair
   189     _A[i] = bits;
   190   }
   191   verify_pairs();
   192 }
   194 //------------------------------SmearToPairs-----------------------------------
   195 // Smear out partial bits; leave only bit pairs
   196 void RegMask::smear_to_pairs() {
   197   for( int i = 0; i < RM_SIZE; i++ ) {
   198     int bits = _A[i];
   199     bits |= ((bits & 0x55555555)<<1); // Smear lo bit hi per pair
   200     bits |= ((bits & 0xAAAAAAAA)>>1); // Smear hi bit lo per pair
   201     _A[i] = bits;
   202   }
   203   verify_pairs();
   204 }
   206 //------------------------------is_aligned_pairs-------------------------------
   207 bool RegMask::is_aligned_pairs() const {
   208   // Assert that the register mask contains only bit pairs.
   209   for( int i = 0; i < RM_SIZE; i++ ) {
   210     int bits = _A[i];
   211     while( bits ) {             // Check bits for pairing
   212       int bit = bits & -bits;   // Extract low bit
   213       // Low bit is not odd means its mis-aligned.
   214       if( (bit & 0x55555555) == 0 ) return false;
   215       bits -= bit;              // Remove bit from mask
   216       // Check for aligned adjacent bit
   217       if( (bits & (bit<<1)) == 0 ) return false;
   218       bits -= (bit<<1);         // Remove other halve of pair
   219     }
   220   }
   221   return true;
   222 }
   224 //------------------------------is_bound1--------------------------------------
   225 // Return TRUE if the mask contains a single bit
   226 int RegMask::is_bound1() const {
   227   if( is_AllStack() ) return false;
   228   int bit = -1;                 // Set to hold the one bit allowed
   229   for( int i = 0; i < RM_SIZE; i++ ) {
   230     if( _A[i] ) {               // Found some bits
   231       if( bit != -1 ) return false; // Already had bits, so fail
   232       bit = _A[i] & -_A[i];     // Extract 1 bit from mask
   233       if( bit != _A[i] ) return false; // Found many bits, so fail
   234     }
   235   }
   236   // True for both the empty mask and for a single bit
   237   return true;
   238 }
   240 //------------------------------is_bound2--------------------------------------
   241 // Return TRUE if the mask contains an adjacent pair of bits and no other bits.
   242 int RegMask::is_bound_pair() const {
   243   if( is_AllStack() ) return false;
   245   int bit = -1;                 // Set to hold the one bit allowed
   246   for( int i = 0; i < RM_SIZE; i++ ) {
   247     if( _A[i] ) {               // Found some bits
   248       if( bit != -1 ) return false; // Already had bits, so fail
   249       bit = _A[i] & -(_A[i]);   // Extract 1 bit from mask
   250       if( (bit << 1) != 0 ) {   // Bit pair stays in same word?
   251         if( (bit | (bit<<1)) != _A[i] )
   252           return false;         // Require adjacent bit pair and no more bits
   253       } else {                  // Else its a split-pair case
   254         if( bit != _A[i] ) return false; // Found many bits, so fail
   255         i++;                    // Skip iteration forward
   256         if( i >= RM_SIZE || _A[i] != 1 )
   257           return false; // Require 1 lo bit in next word
   258       }
   259     }
   260   }
   261   // True for both the empty mask and for a bit pair
   262   return true;
   263 }
   265 static int low_bits[3] = { 0x55555555, 0x11111111, 0x01010101 };
   266 //------------------------------find_first_set---------------------------------
   267 // Find the lowest-numbered register set in the mask.  Return the
   268 // HIGHEST register number in the set, or BAD if no sets.
   269 // Works also for size 1.
   270 OptoReg::Name RegMask::find_first_set(const int size) const {
   271   verify_sets(size);
   272   for (int i = 0; i < RM_SIZE; i++) {
   273     if (_A[i]) {                // Found some bits
   274       int bit = _A[i] & -_A[i]; // Extract low bit
   275       // Convert to bit number, return hi bit in pair
   276       return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+(size-1));
   277     }
   278   }
   279   return OptoReg::Bad;
   280 }
   282 //------------------------------clear_to_sets----------------------------------
   283 // Clear out partial bits; leave only aligned adjacent bit pairs
   284 void RegMask::clear_to_sets(const int size) {
   285   if (size == 1) return;
   286   assert(2 <= size && size <= 8, "update low bits table");
   287   assert(is_power_of_2(size), "sanity");
   288   int low_bits_mask = low_bits[size>>2];
   289   for (int i = 0; i < RM_SIZE; i++) {
   290     int bits = _A[i];
   291     int sets = (bits & low_bits_mask);
   292     for (int j = 1; j < size; j++) {
   293       sets = (bits & (sets<<1)); // filter bits which produce whole sets
   294     }
   295     sets |= (sets>>1);           // Smear 1 hi-bit into a set
   296     if (size > 2) {
   297       sets |= (sets>>2);         // Smear 2 hi-bits into a set
   298       if (size > 4) {
   299         sets |= (sets>>4);       // Smear 4 hi-bits into a set
   300       }
   301     }
   302     _A[i] = sets;
   303   }
   304   verify_sets(size);
   305 }
   307 //------------------------------smear_to_sets----------------------------------
   308 // Smear out partial bits to aligned adjacent bit sets
   309 void RegMask::smear_to_sets(const int size) {
   310   if (size == 1) return;
   311   assert(2 <= size && size <= 8, "update low bits table");
   312   assert(is_power_of_2(size), "sanity");
   313   int low_bits_mask = low_bits[size>>2];
   314   for (int i = 0; i < RM_SIZE; i++) {
   315     int bits = _A[i];
   316     int sets = 0;
   317     for (int j = 0; j < size; j++) {
   318       sets |= (bits & low_bits_mask);  // collect partial bits
   319       bits  = bits>>1;
   320     }
   321     sets |= (sets<<1);           // Smear 1 lo-bit  into a set
   322     if (size > 2) {
   323       sets |= (sets<<2);         // Smear 2 lo-bits into a set
   324       if (size > 4) {
   325         sets |= (sets<<4);       // Smear 4 lo-bits into a set
   326       }
   327     }
   328     _A[i] = sets;
   329   }
   330   verify_sets(size);
   331 }
   333 //------------------------------is_aligned_set--------------------------------
   334 bool RegMask::is_aligned_sets(const int size) const {
   335   if (size == 1) return true;
   336   assert(2 <= size && size <= 8, "update low bits table");
   337   assert(is_power_of_2(size), "sanity");
   338   int low_bits_mask = low_bits[size>>2];
   339   // Assert that the register mask contains only bit sets.
   340   for (int i = 0; i < RM_SIZE; i++) {
   341     int bits = _A[i];
   342     while (bits) {              // Check bits for pairing
   343       int bit = bits & -bits;   // Extract low bit
   344       // Low bit is not odd means its mis-aligned.
   345       if ((bit & low_bits_mask) == 0) return false;
   346       // Do extra work since (bit << size) may overflow.
   347       int hi_bit = bit << (size-1); // high bit
   348       int set = hi_bit + ((hi_bit-1) & ~(bit-1));
   349       // Check for aligned adjacent bits in this set
   350       if ((bits & set) != set) return false;
   351       bits -= set;  // Remove this set
   352     }
   353   }
   354   return true;
   355 }
   357 //------------------------------is_bound_set-----------------------------------
   358 // Return TRUE if the mask contains one adjacent set of bits and no other bits.
   359 // Works also for size 1.
   360 int RegMask::is_bound_set(const int size) const {
   361   if( is_AllStack() ) return false;
   362   assert(1 <= size && size <= 8, "update low bits table");
   363   int bit = -1;                 // Set to hold the one bit allowed
   364   for (int i = 0; i < RM_SIZE; i++) {
   365     if (_A[i] ) {               // Found some bits
   366       if (bit != -1)
   367        return false;            // Already had bits, so fail
   368       bit = _A[i] & -_A[i];     // Extract low bit from mask
   369       int hi_bit = bit << (size-1); // high bit
   370       if (hi_bit != 0) {        // Bit set stays in same word?
   371         int set = hi_bit + ((hi_bit-1) & ~(bit-1));
   372         if (set != _A[i])
   373           return false;         // Require adjacent bit set and no more bits
   374       } else {                  // Else its a split-set case
   375         if (((-1) & ~(bit-1)) != _A[i])
   376           return false;         // Found many bits, so fail
   377         i++;                    // Skip iteration forward and check high part
   378         // The lower 24 bits should be 0 since it is split case and size <= 8.
   379         int set = bit>>24;
   380         set = set & -set; // Remove sign extension.
   381         set = (((set << size) - 1) >> 8);
   382         if (i >= RM_SIZE || _A[i] != set)
   383           return false; // Require expected low bits in next word
   384       }
   385     }
   386   }
   387   // True for both the empty mask and for a bit set
   388   return true;
   389 }
   391 //------------------------------is_UP------------------------------------------
   392 // UP means register only, Register plus stack, or stack only is DOWN
   393 bool RegMask::is_UP() const {
   394   // Quick common case check for DOWN (any stack slot is legal)
   395   if( is_AllStack() )
   396     return false;
   397   // Slower check for any stack bits set (also DOWN)
   398   if( overlap(Matcher::STACK_ONLY_mask) )
   399     return false;
   400   // Not DOWN, so must be UP
   401   return true;
   402 }
   404 //------------------------------Size-------------------------------------------
   405 // Compute size of register mask in bits
   406 uint RegMask::Size() const {
   407   extern uint8 bitsInByte[256];
   408   uint sum = 0;
   409   for( int i = 0; i < RM_SIZE; i++ )
   410     sum +=
   411       bitsInByte[(_A[i]>>24) & 0xff] +
   412       bitsInByte[(_A[i]>>16) & 0xff] +
   413       bitsInByte[(_A[i]>> 8) & 0xff] +
   414       bitsInByte[ _A[i]      & 0xff];
   415   return sum;
   416 }
   418 #ifndef PRODUCT
   419 //------------------------------print------------------------------------------
   420 void RegMask::dump(outputStream *st) const {
   421   st->print("[");
   422   RegMask rm = *this;           // Structure copy into local temp
   424   OptoReg::Name start = rm.find_first_elem(); // Get a register
   425   if (OptoReg::is_valid(start)) { // Check for empty mask
   426     rm.Remove(start);           // Yank from mask
   427     OptoReg::dump(start, st);   // Print register
   428     OptoReg::Name last = start;
   430     // Now I have printed an initial register.
   431     // Print adjacent registers as "rX-rZ" instead of "rX,rY,rZ".
   432     // Begin looping over the remaining registers.
   433     while (1) {                 //
   434       OptoReg::Name reg = rm.find_first_elem(); // Get a register
   435       if (!OptoReg::is_valid(reg))
   436         break;                  // Empty mask, end loop
   437       rm.Remove(reg);           // Yank from mask
   439       if (last+1 == reg) {      // See if they are adjacent
   440         // Adjacent registers just collect into long runs, no printing.
   441         last = reg;
   442       } else {                  // Ending some kind of run
   443         if (start == last) {    // 1-register run; no special printing
   444         } else if (start+1 == last) {
   445           st->print(",");       // 2-register run; print as "rX,rY"
   446           OptoReg::dump(last, st);
   447         } else {                // Multi-register run; print as "rX-rZ"
   448           st->print("-");
   449           OptoReg::dump(last, st);
   450         }
   451         st->print(",");         // Seperate start of new run
   452         start = last = reg;     // Start a new register run
   453         OptoReg::dump(start, st); // Print register
   454       } // End of if ending a register run or not
   455     } // End of while regmask not empty
   457     if (start == last) {        // 1-register run; no special printing
   458     } else if (start+1 == last) {
   459       st->print(",");           // 2-register run; print as "rX,rY"
   460       OptoReg::dump(last, st);
   461     } else {                    // Multi-register run; print as "rX-rZ"
   462       st->print("-");
   463       OptoReg::dump(last, st);
   464     }
   465     if (rm.is_AllStack()) st->print("...");
   466   }
   467   st->print("]");
   468 }
   469 #endif

mercurial