0N/A/*
4319N/A * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_OPTO_REGMASK_HPP
1879N/A#define SHARE_VM_OPTO_REGMASK_HPP
1879N/A
1879N/A#include "code/vmreg.hpp"
1879N/A#include "libadt/port.hpp"
1879N/A#include "opto/optoreg.hpp"
1879N/A#ifdef TARGET_ARCH_MODEL_x86_32
1879N/A# include "adfiles/adGlobals_x86_32.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_x86_64
1879N/A# include "adfiles/adGlobals_x86_64.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_sparc
1879N/A# include "adfiles/adGlobals_sparc.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_zero
1879N/A# include "adfiles/adGlobals_zero.hpp"
1879N/A#endif
2073N/A#ifdef TARGET_ARCH_MODEL_arm
2073N/A# include "adfiles/adGlobals_arm.hpp"
2073N/A#endif
2073N/A#ifdef TARGET_ARCH_MODEL_ppc
2073N/A# include "adfiles/adGlobals_ppc.hpp"
2073N/A#endif
1879N/A
0N/A// Some fun naming (textual) substitutions:
0N/A//
0N/A// RegMask::get_low_elem() ==> RegMask::find_first_elem()
0N/A// RegMask::Special ==> RegMask::Empty
0N/A// RegMask::_flags ==> RegMask::is_AllStack()
0N/A// RegMask::operator<<=() ==> RegMask::Insert()
0N/A// RegMask::operator>>=() ==> RegMask::Remove()
0N/A// RegMask::Union() ==> RegMask::OR
0N/A// RegMask::Inter() ==> RegMask::AND
0N/A//
0N/A// OptoRegister::RegName ==> OptoReg::Name
0N/A//
0N/A// OptoReg::stack0() ==> _last_Mach_Reg or ZERO in core version
0N/A//
0N/A// numregs in chaitin ==> proper degree in chaitin
0N/A
0N/A//-------------Non-zero bit search methods used by RegMask---------------------
0N/A// Find lowest 1, or return 32 if empty
0N/Aint find_lowest_bit( uint32 mask );
0N/A// Find highest 1, or return 32 if empty
0N/Aint find_hihghest_bit( uint32 mask );
0N/A
0N/A//------------------------------RegMask----------------------------------------
0N/A// The ADL file describes how to print the machine-specific registers, as well
0N/A// as any notion of register classes. We provide a register mask, which is
0N/A// just a collection of Register numbers.
0N/A
0N/A// The ADLC defines 2 macros, RM_SIZE and FORALL_BODY.
0N/A// RM_SIZE is the size of a register mask in words.
0N/A// FORALL_BODY replicates a BODY macro once per word in the register mask.
0N/A// The usage is somewhat clumsy and limited to the regmask.[h,c]pp files.
0N/A// However, it means the ADLC can redefine the unroll macro and all loops
0N/A// over register masks will be unrolled by the correct amount.
0N/A
0N/Aclass RegMask VALUE_OBJ_CLASS_SPEC {
0N/A union {
0N/A double _dummy_force_double_alignment[RM_SIZE>>1];
0N/A // Array of Register Mask bits. This array is large enough to cover
0N/A // all the machine registers and all parameters that need to be passed
0N/A // on the stack (stack registers) up to some interesting limit. Methods
0N/A // that need more parameters will NOT be compiled. On Intel, the limit
0N/A // is something like 90+ parameters.
0N/A int _A[RM_SIZE];
0N/A };
0N/A
0N/A enum {
0N/A _WordBits = BitsPerInt,
0N/A _LogWordBits = LogBitsPerInt,
0N/A _RM_SIZE = RM_SIZE // local constant, imported, then hidden by #undef
0N/A };
0N/A
0N/Apublic:
0N/A enum { CHUNK_SIZE = RM_SIZE*_WordBits };
0N/A
0N/A // SlotsPerLong is 2, since slots are 32 bits and longs are 64 bits.
0N/A // Also, consider the maximum alignment size for a normally allocated
0N/A // value. Since we allocate register pairs but not register quads (at
0N/A // present), this alignment is SlotsPerLong (== 2). A normally
0N/A // aligned allocated register is either a single register, or a pair
0N/A // of adjacent registers, the lower-numbered being even.
0N/A // See also is_aligned_Pairs() below, and the padding added before
0N/A // Matcher::_new_SP to keep allocated pairs aligned properly.
0N/A // If we ever go to quad-word allocations, SlotsPerQuad will become
0N/A // the controlling alignment constraint. Note that this alignment
0N/A // requirement is internal to the allocator, and independent of any
0N/A // particular platform.
3845N/A enum { SlotsPerLong = 2,
3845N/A SlotsPerVecS = 1,
3845N/A SlotsPerVecD = 2,
3845N/A SlotsPerVecX = 4,
3845N/A SlotsPerVecY = 8 };
0N/A
0N/A // A constructor only used by the ADLC output. All mask fields are filled
0N/A // in directly. Calls to this look something like RM(1,2,3,4);
0N/A RegMask(
0N/A# define BODY(I) int a##I,
0N/A FORALL_BODY
0N/A# undef BODY
0N/A int dummy = 0 ) {
0N/A# define BODY(I) _A[I] = a##I;
0N/A FORALL_BODY
0N/A# undef BODY
0N/A }
0N/A
0N/A // Handy copying constructor
0N/A RegMask( RegMask *rm ) {
0N/A# define BODY(I) _A[I] = rm->_A[I];
0N/A FORALL_BODY
0N/A# undef BODY
0N/A }
0N/A
0N/A // Construct an empty mask
0N/A RegMask( ) { Clear(); }
0N/A
0N/A // Construct a mask with a single bit
0N/A RegMask( OptoReg::Name reg ) { Clear(); Insert(reg); }
0N/A
0N/A // Check for register being in mask
0N/A int Member( OptoReg::Name reg ) const {
0N/A assert( reg < CHUNK_SIZE, "" );
0N/A return _A[reg>>_LogWordBits] & (1<<(reg&(_WordBits-1)));
0N/A }
0N/A
0N/A // The last bit in the register mask indicates that the mask should repeat
0N/A // indefinitely with ONE bits. Returns TRUE if mask is infinite or
0N/A // unbounded in size. Returns FALSE if mask is finite size.
0N/A int is_AllStack() const { return _A[RM_SIZE-1] >> (_WordBits-1); }
0N/A
0N/A // Work around an -xO3 optimization problme in WS6U1. The old way:
0N/A // void set_AllStack() { _A[RM_SIZE-1] |= (1<<(_WordBits-1)); }
0N/A // will cause _A[RM_SIZE-1] to be clobbered, not updated when set_AllStack()
0N/A // follows an Insert() loop, like the one found in init_spill_mask(). Using
0N/A // Insert() instead works because the index into _A in computed instead of
0N/A // constant. See bug 4665841.
0N/A void set_AllStack() { Insert(OptoReg::Name(CHUNK_SIZE-1)); }
0N/A
0N/A // Test for being a not-empty mask.
0N/A int is_NotEmpty( ) const {
0N/A int tmp = 0;
0N/A# define BODY(I) tmp |= _A[I];
0N/A FORALL_BODY
0N/A# undef BODY
0N/A return tmp;
0N/A }
0N/A
0N/A // Find lowest-numbered register from mask, or BAD if mask is empty.
0N/A OptoReg::Name find_first_elem() const {
0N/A int base, bits;
0N/A# define BODY(I) if( (bits = _A[I]) != 0 ) base = I<<_LogWordBits; else
0N/A FORALL_BODY
0N/A# undef BODY
0N/A { base = OptoReg::Bad; bits = 1<<0; }
0N/A return OptoReg::Name(base + find_lowest_bit(bits));
0N/A }
0N/A // Get highest-numbered register from mask, or BAD if mask is empty.
0N/A OptoReg::Name find_last_elem() const {
0N/A int base, bits;
0N/A# define BODY(I) if( (bits = _A[RM_SIZE-1-I]) != 0 ) base = (RM_SIZE-1-I)<<_LogWordBits; else
0N/A FORALL_BODY
0N/A# undef BODY
0N/A { base = OptoReg::Bad; bits = 1<<0; }
0N/A return OptoReg::Name(base + find_hihghest_bit(bits));
0N/A }
0N/A
0N/A // Find the lowest-numbered register pair in the mask. Return the
0N/A // HIGHEST register number in the pair, or BAD if no pairs.
0N/A // Assert that the mask contains only bit pairs.
0N/A OptoReg::Name find_first_pair() const;
0N/A
0N/A // Clear out partial bits; leave only aligned adjacent bit pairs.
3845N/A void clear_to_pairs();
0N/A // Smear out partial bits; leave only aligned adjacent bit pairs.
3845N/A void smear_to_pairs();
0N/A // Verify that the mask contains only aligned adjacent bit pairs
3845N/A void verify_pairs() const { assert( is_aligned_pairs(), "mask is not aligned, adjacent pairs" ); }
0N/A // Test that the mask contains only aligned adjacent bit pairs
3845N/A bool is_aligned_pairs() const;
0N/A
0N/A // mask is a pair of misaligned registers
3845N/A bool is_misaligned_pair() const { return Size()==2 && !is_aligned_pairs(); }
0N/A // Test for single register
0N/A int is_bound1() const;
0N/A // Test for a single adjacent pair
3845N/A int is_bound_pair() const;
3845N/A // Test for a single adjacent set of ideal register's size.
3845N/A int is_bound(uint ireg) const {
3845N/A if (is_vector(ireg)) {
3845N/A if (is_bound_set(num_registers(ireg)))
3845N/A return true;
3845N/A } else if (is_bound1() || is_bound_pair()) {
3845N/A return true;
3845N/A }
3845N/A return false;
3845N/A }
3845N/A
3845N/A // Find the lowest-numbered register set in the mask. Return the
3845N/A // HIGHEST register number in the set, or BAD if no sets.
3845N/A // Assert that the mask contains only bit sets.
4319N/A OptoReg::Name find_first_set(const int size) const;
3845N/A
3845N/A // Clear out partial bits; leave only aligned adjacent bit sets of size.
4319N/A void clear_to_sets(const int size);
3845N/A // Smear out partial bits to aligned adjacent bit sets.
4319N/A void smear_to_sets(const int size);
3845N/A // Verify that the mask contains only aligned adjacent bit sets
3845N/A void verify_sets(int size) const { assert(is_aligned_sets(size), "mask is not aligned, adjacent sets"); }
3845N/A // Test that the mask contains only aligned adjacent bit sets
4319N/A bool is_aligned_sets(const int size) const;
3845N/A
3845N/A // mask is a set of misaligned registers
3845N/A bool is_misaligned_set(int size) const { return (int)Size()==size && !is_aligned_sets(size);}
3845N/A
3845N/A // Test for a single adjacent set
4319N/A int is_bound_set(const int size) const;
3845N/A
3845N/A static bool is_vector(uint ireg);
3845N/A static int num_registers(uint ireg);
0N/A
0N/A // Fast overlap test. Non-zero if any registers in common.
0N/A int overlap( const RegMask &rm ) const {
0N/A return
0N/A# define BODY(I) (_A[I] & rm._A[I]) |
0N/A FORALL_BODY
0N/A# undef BODY
0N/A 0 ;
0N/A }
0N/A
0N/A // Special test for register pressure based splitting
0N/A // UP means register only, Register plus stack, or stack only is DOWN
0N/A bool is_UP() const;
0N/A
0N/A // Clear a register mask
0N/A void Clear( ) {
0N/A# define BODY(I) _A[I] = 0;
0N/A FORALL_BODY
0N/A# undef BODY
0N/A }
0N/A
0N/A // Fill a register mask with 1's
0N/A void Set_All( ) {
0N/A# define BODY(I) _A[I] = -1;
0N/A FORALL_BODY
0N/A# undef BODY
0N/A }
0N/A
0N/A // Insert register into mask
0N/A void Insert( OptoReg::Name reg ) {
0N/A assert( reg < CHUNK_SIZE, "" );
0N/A _A[reg>>_LogWordBits] |= (1<<(reg&(_WordBits-1)));
0N/A }
0N/A
0N/A // Remove register from mask
0N/A void Remove( OptoReg::Name reg ) {
0N/A assert( reg < CHUNK_SIZE, "" );
0N/A _A[reg>>_LogWordBits] &= ~(1<<(reg&(_WordBits-1)));
0N/A }
0N/A
0N/A // OR 'rm' into 'this'
0N/A void OR( const RegMask &rm ) {
0N/A# define BODY(I) this->_A[I] |= rm._A[I];
0N/A FORALL_BODY
0N/A# undef BODY
0N/A }
0N/A
0N/A // AND 'rm' into 'this'
0N/A void AND( const RegMask &rm ) {
0N/A# define BODY(I) this->_A[I] &= rm._A[I];
0N/A FORALL_BODY
0N/A# undef BODY
0N/A }
0N/A
0N/A // Subtract 'rm' from 'this'
0N/A void SUBTRACT( const RegMask &rm ) {
0N/A# define BODY(I) _A[I] &= ~rm._A[I];
0N/A FORALL_BODY
0N/A# undef BODY
0N/A }
0N/A
0N/A // Compute size of register mask: number of bits
0N/A uint Size() const;
0N/A
0N/A#ifndef PRODUCT
0N/A void print() const { dump(); }
4312N/A void dump(outputStream *st = tty) const; // Print a mask
0N/A#endif
0N/A
0N/A static const RegMask Empty; // Common empty mask
0N/A
0N/A static bool can_represent(OptoReg::Name reg) {
0N/A // NOTE: -1 in computation reflects the usage of the last
3845N/A // bit of the regmask as an infinite stack flag and
3845N/A // -7 is to keep mask aligned for largest value (VecY).
0N/A return (int)reg < (int)(CHUNK_SIZE-1);
0N/A }
3845N/A static bool can_represent_arg(OptoReg::Name reg) {
3845N/A // NOTE: -SlotsPerVecY in computation reflects the need
3845N/A // to keep mask aligned for largest value (VecY).
3845N/A return (int)reg < (int)(CHUNK_SIZE-SlotsPerVecY);
3845N/A }
0N/A};
0N/A
0N/A// Do not use this constant directly in client code!
0N/A#undef RM_SIZE
1879N/A
1879N/A#endif // SHARE_VM_OPTO_REGMASK_HPP