2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2019-01-10 15:13:51 -05:00
|
|
|
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_OPTO_REGMASK_HPP
|
|
|
|
#define SHARE_OPTO_REGMASK_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#include "code/vmreg.hpp"
|
|
|
|
#include "opto/optoreg.hpp"
|
2019-01-28 23:00:31 +01:00
|
|
|
#include "utilities/count_leading_zeros.hpp"
|
2019-01-23 17:25:25 +01:00
|
|
|
#include "utilities/count_trailing_zeros.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
//-------------Non-zero bit search methods used by RegMask---------------------
|
2019-01-23 17:25:25 +01:00
|
|
|
// Find lowest 1, undefined if empty/0
|
|
|
|
static int find_lowest_bit(uint32_t mask) {
|
|
|
|
return count_trailing_zeros(mask);
|
|
|
|
}
|
2019-01-28 23:00:31 +01:00
|
|
|
// Find highest 1, undefined if empty/0
|
|
|
|
static int find_highest_bit(uint32_t mask) {
|
|
|
|
return count_leading_zeros(mask) ^ 31;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
//------------------------------RegMask----------------------------------------
|
|
|
|
// The ADL file describes how to print the machine-specific registers, as well
|
|
|
|
// as any notion of register classes. We provide a register mask, which is
|
|
|
|
// just a collection of Register numbers.
|
|
|
|
|
|
|
|
// The ADLC defines 2 macros, RM_SIZE and FORALL_BODY.
|
|
|
|
// RM_SIZE is the size of a register mask in words.
|
|
|
|
// FORALL_BODY replicates a BODY macro once per word in the register mask.
|
|
|
|
// The usage is somewhat clumsy and limited to the regmask.[h,c]pp files.
|
|
|
|
// However, it means the ADLC can redefine the unroll macro and all loops
|
|
|
|
// over register masks will be unrolled by the correct amount.
|
|
|
|
|
2018-03-09 20:01:38 -05:00
|
|
|
class RegMask {
|
2007-12-01 00:00:00 +00:00
|
|
|
union {
|
|
|
|
double _dummy_force_double_alignment[RM_SIZE>>1];
|
|
|
|
// Array of Register Mask bits. This array is large enough to cover
|
|
|
|
// all the machine registers and all parameters that need to be passed
|
|
|
|
// on the stack (stack registers) up to some interesting limit. Methods
|
|
|
|
// that need more parameters will NOT be compiled. On Intel, the limit
|
|
|
|
// is something like 90+ parameters.
|
|
|
|
int _A[RM_SIZE];
|
|
|
|
};
|
2019-03-05 16:39:18 +01:00
|
|
|
// The low and high water marks represents the lowest and highest word
|
|
|
|
// that might contain set register mask bits, respectively. We guarantee
|
|
|
|
// that there are no bits in words outside this range, but any word at
|
|
|
|
// and between the two marks can still be 0.
|
|
|
|
int _lwm;
|
|
|
|
int _hwm;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
_WordBits = BitsPerInt,
|
|
|
|
_LogWordBits = LogBitsPerInt,
|
|
|
|
_RM_SIZE = RM_SIZE // local constant, imported, then hidden by #undef
|
|
|
|
};
|
|
|
|
|
2019-03-05 16:39:18 +01:00
|
|
|
public:
|
2007-12-01 00:00:00 +00:00
|
|
|
enum { CHUNK_SIZE = RM_SIZE*_WordBits };
|
|
|
|
|
|
|
|
// SlotsPerLong is 2, since slots are 32 bits and longs are 64 bits.
|
|
|
|
// Also, consider the maximum alignment size for a normally allocated
|
|
|
|
// value. Since we allocate register pairs but not register quads (at
|
|
|
|
// present), this alignment is SlotsPerLong (== 2). A normally
|
|
|
|
// aligned allocated register is either a single register, or a pair
|
|
|
|
// of adjacent registers, the lower-numbered being even.
|
|
|
|
// See also is_aligned_Pairs() below, and the padding added before
|
|
|
|
// Matcher::_new_SP to keep allocated pairs aligned properly.
|
|
|
|
// If we ever go to quad-word allocations, SlotsPerQuad will become
|
|
|
|
// the controlling alignment constraint. Note that this alignment
|
|
|
|
// requirement is internal to the allocator, and independent of any
|
|
|
|
// particular platform.
|
2012-06-15 01:25:19 -07:00
|
|
|
enum { SlotsPerLong = 2,
|
|
|
|
SlotsPerVecS = 1,
|
|
|
|
SlotsPerVecD = 2,
|
|
|
|
SlotsPerVecX = 4,
|
2015-05-08 11:49:20 -07:00
|
|
|
SlotsPerVecY = 8,
|
|
|
|
SlotsPerVecZ = 16 };
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// A constructor only used by the ADLC output. All mask fields are filled
|
|
|
|
// in directly. Calls to this look something like RM(1,2,3,4);
|
|
|
|
RegMask(
|
|
|
|
# define BODY(I) int a##I,
|
|
|
|
FORALL_BODY
|
|
|
|
# undef BODY
|
2019-03-05 16:39:18 +01:00
|
|
|
int dummy = 0) {
|
2007-12-01 00:00:00 +00:00
|
|
|
# define BODY(I) _A[I] = a##I;
|
|
|
|
FORALL_BODY
|
|
|
|
# undef BODY
|
2019-03-05 16:39:18 +01:00
|
|
|
_lwm = 0;
|
|
|
|
_hwm = RM_SIZE - 1;
|
|
|
|
while (_hwm > 0 && _A[_hwm] == 0) _hwm--;
|
|
|
|
while ((_lwm < _hwm) && _A[_lwm] == 0) _lwm++;
|
|
|
|
assert(valid_watermarks(), "post-condition");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handy copying constructor
|
2019-03-05 16:39:18 +01:00
|
|
|
RegMask(RegMask *rm) {
|
|
|
|
_hwm = rm->_hwm;
|
|
|
|
_lwm = rm->_lwm;
|
|
|
|
for (int i = 0; i < RM_SIZE; i++) {
|
|
|
|
_A[i] = rm->_A[i];
|
|
|
|
}
|
|
|
|
assert(valid_watermarks(), "post-condition");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Construct an empty mask
|
2019-03-05 16:39:18 +01:00
|
|
|
RegMask() {
|
|
|
|
Clear();
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Construct a mask with a single bit
|
2019-03-05 16:39:18 +01:00
|
|
|
RegMask(OptoReg::Name reg) {
|
|
|
|
Clear();
|
|
|
|
Insert(reg);
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Check for register being in mask
|
2019-03-05 16:39:18 +01:00
|
|
|
int Member(OptoReg::Name reg) const {
|
|
|
|
assert(reg < CHUNK_SIZE, "");
|
2007-12-01 00:00:00 +00:00
|
|
|
return _A[reg>>_LogWordBits] & (1<<(reg&(_WordBits-1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The last bit in the register mask indicates that the mask should repeat
|
|
|
|
// indefinitely with ONE bits. Returns TRUE if mask is infinite or
|
|
|
|
// unbounded in size. Returns FALSE if mask is finite size.
|
|
|
|
int is_AllStack() const { return _A[RM_SIZE-1] >> (_WordBits-1); }
|
|
|
|
|
|
|
|
// Work around an -xO3 optimization problme in WS6U1. The old way:
|
|
|
|
// void set_AllStack() { _A[RM_SIZE-1] |= (1<<(_WordBits-1)); }
|
|
|
|
// will cause _A[RM_SIZE-1] to be clobbered, not updated when set_AllStack()
|
|
|
|
// follows an Insert() loop, like the one found in init_spill_mask(). Using
|
|
|
|
// Insert() instead works because the index into _A in computed instead of
|
|
|
|
// constant. See bug 4665841.
|
|
|
|
void set_AllStack() { Insert(OptoReg::Name(CHUNK_SIZE-1)); }
|
|
|
|
|
|
|
|
// Test for being a not-empty mask.
|
2019-03-05 16:39:18 +01:00
|
|
|
int is_NotEmpty() const {
|
|
|
|
assert(valid_watermarks(), "sanity");
|
2007-12-01 00:00:00 +00:00
|
|
|
int tmp = 0;
|
2019-03-05 16:39:18 +01:00
|
|
|
for (int i = _lwm; i <= _hwm; i++) {
|
|
|
|
tmp |= _A[i];
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find lowest-numbered register from mask, or BAD if mask is empty.
|
|
|
|
OptoReg::Name find_first_elem() const {
|
2019-03-05 16:39:18 +01:00
|
|
|
assert(valid_watermarks(), "sanity");
|
|
|
|
for (int i = _lwm; i <= _hwm; i++) {
|
|
|
|
int bits = _A[i];
|
|
|
|
if (bits) {
|
|
|
|
return OptoReg::Name((i<<_LogWordBits) + find_lowest_bit(bits));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OptoReg::Name(OptoReg::Bad);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2019-03-05 16:39:18 +01:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Get highest-numbered register from mask, or BAD if mask is empty.
|
|
|
|
OptoReg::Name find_last_elem() const {
|
2019-03-05 16:39:18 +01:00
|
|
|
assert(valid_watermarks(), "sanity");
|
|
|
|
for (int i = _hwm; i >= _lwm; i--) {
|
|
|
|
int bits = _A[i];
|
|
|
|
if (bits) {
|
|
|
|
return OptoReg::Name((i<<_LogWordBits) + find_highest_bit(bits));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OptoReg::Name(OptoReg::Bad);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear out partial bits; leave only aligned adjacent bit pairs.
|
2012-06-15 01:25:19 -07:00
|
|
|
void clear_to_pairs();
|
2019-03-05 16:39:18 +01:00
|
|
|
|
|
|
|
#ifdef ASSERT
|
|
|
|
// Verify watermarks are sane, i.e., within bounds and that no
|
|
|
|
// register words below or above the watermarks have bits set.
|
|
|
|
bool valid_watermarks() const {
|
|
|
|
assert(_hwm >= 0 && _hwm < RM_SIZE, "_hwm out of range: %d", _hwm);
|
|
|
|
assert(_lwm >= 0 && _lwm < RM_SIZE, "_lwm out of range: %d", _lwm);
|
|
|
|
for (int i = 0; i < _lwm; i++) {
|
|
|
|
assert(_A[i] == 0, "_lwm too high: %d regs at: %d", _lwm, i);
|
|
|
|
}
|
|
|
|
for (int i = _hwm + 1; i < RM_SIZE; i++) {
|
|
|
|
assert(_A[i] == 0, "_hwm too low: %d regs at: %d", _hwm, i);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // !ASSERT
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Test that the mask contains only aligned adjacent bit pairs
|
2012-06-15 01:25:19 -07:00
|
|
|
bool is_aligned_pairs() const;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// mask is a pair of misaligned registers
|
2019-03-05 16:39:18 +01:00
|
|
|
bool is_misaligned_pair() const;
|
2007-12-01 00:00:00 +00:00
|
|
|
// Test for single register
|
2019-03-05 16:39:18 +01:00
|
|
|
bool is_bound1() const;
|
2007-12-01 00:00:00 +00:00
|
|
|
// Test for a single adjacent pair
|
2019-03-05 16:39:18 +01:00
|
|
|
bool is_bound_pair() const;
|
2012-06-15 01:25:19 -07:00
|
|
|
// Test for a single adjacent set of ideal register's size.
|
2019-03-05 16:39:18 +01:00
|
|
|
bool is_bound(uint ireg) const;
|
2012-06-15 01:25:19 -07:00
|
|
|
|
|
|
|
// Find the lowest-numbered register set in the mask. Return the
|
|
|
|
// HIGHEST register number in the set, or BAD if no sets.
|
|
|
|
// Assert that the mask contains only bit sets.
|
2013-02-09 12:55:09 -08:00
|
|
|
OptoReg::Name find_first_set(const int size) const;
|
2012-06-15 01:25:19 -07:00
|
|
|
|
|
|
|
// Clear out partial bits; leave only aligned adjacent bit sets of size.
|
2013-02-09 12:55:09 -08:00
|
|
|
void clear_to_sets(const int size);
|
2012-06-15 01:25:19 -07:00
|
|
|
// Smear out partial bits to aligned adjacent bit sets.
|
2013-02-09 12:55:09 -08:00
|
|
|
void smear_to_sets(const int size);
|
2012-06-15 01:25:19 -07:00
|
|
|
// Test that the mask contains only aligned adjacent bit sets
|
2013-02-09 12:55:09 -08:00
|
|
|
bool is_aligned_sets(const int size) const;
|
2012-06-15 01:25:19 -07:00
|
|
|
|
|
|
|
// Test for a single adjacent set
|
2013-02-09 12:55:09 -08:00
|
|
|
int is_bound_set(const int size) const;
|
2012-06-15 01:25:19 -07:00
|
|
|
|
|
|
|
static bool is_vector(uint ireg);
|
|
|
|
static int num_registers(uint ireg);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Fast overlap test. Non-zero if any registers in common.
|
2019-03-05 16:39:18 +01:00
|
|
|
int overlap(const RegMask &rm) const {
|
|
|
|
assert(valid_watermarks() && rm.valid_watermarks(), "sanity");
|
|
|
|
int hwm = MIN2(_hwm, rm._hwm);
|
|
|
|
int lwm = MAX2(_lwm, rm._lwm);
|
|
|
|
int result = 0;
|
|
|
|
for (int i = lwm; i <= hwm; i++) {
|
|
|
|
result |= _A[i] & rm._A[i];
|
|
|
|
}
|
|
|
|
return result;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Special test for register pressure based splitting
|
|
|
|
// UP means register only, Register plus stack, or stack only is DOWN
|
|
|
|
bool is_UP() const;
|
|
|
|
|
|
|
|
// Clear a register mask
|
2019-03-05 16:39:18 +01:00
|
|
|
void Clear() {
|
|
|
|
_lwm = RM_SIZE - 1;
|
|
|
|
_hwm = 0;
|
|
|
|
memset(_A, 0, sizeof(int)*RM_SIZE);
|
|
|
|
assert(valid_watermarks(), "sanity");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fill a register mask with 1's
|
2019-03-05 16:39:18 +01:00
|
|
|
void Set_All() {
|
|
|
|
_lwm = 0;
|
|
|
|
_hwm = RM_SIZE - 1;
|
|
|
|
memset(_A, 0xFF, sizeof(int)*RM_SIZE);
|
|
|
|
assert(valid_watermarks(), "sanity");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Insert register into mask
|
2019-03-05 16:39:18 +01:00
|
|
|
void Insert(OptoReg::Name reg) {
|
|
|
|
assert(reg < CHUNK_SIZE, "sanity");
|
|
|
|
assert(valid_watermarks(), "pre-condition");
|
|
|
|
int index = reg>>_LogWordBits;
|
|
|
|
if (index > _hwm) _hwm = index;
|
|
|
|
if (index < _lwm) _lwm = index;
|
|
|
|
_A[index] |= (1<<(reg&(_WordBits-1)));
|
|
|
|
assert(valid_watermarks(), "post-condition");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove register from mask
|
2019-03-05 16:39:18 +01:00
|
|
|
void Remove(OptoReg::Name reg) {
|
|
|
|
assert(reg < CHUNK_SIZE, "");
|
2007-12-01 00:00:00 +00:00
|
|
|
_A[reg>>_LogWordBits] &= ~(1<<(reg&(_WordBits-1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// OR 'rm' into 'this'
|
2019-03-05 16:39:18 +01:00
|
|
|
void OR(const RegMask &rm) {
|
|
|
|
assert(valid_watermarks() && rm.valid_watermarks(), "sanity");
|
|
|
|
// OR widens the live range
|
|
|
|
if (_lwm > rm._lwm) _lwm = rm._lwm;
|
|
|
|
if (_hwm < rm._hwm) _hwm = rm._hwm;
|
|
|
|
for (int i = _lwm; i <= _hwm; i++) {
|
|
|
|
_A[i] |= rm._A[i];
|
|
|
|
}
|
|
|
|
assert(valid_watermarks(), "sanity");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AND 'rm' into 'this'
|
2019-03-05 16:39:18 +01:00
|
|
|
void AND(const RegMask &rm) {
|
|
|
|
assert(valid_watermarks() && rm.valid_watermarks(), "sanity");
|
|
|
|
// Do not evaluate words outside the current watermark range, as they are
|
|
|
|
// already zero and an &= would not change that
|
|
|
|
for (int i = _lwm; i <= _hwm; i++) {
|
|
|
|
_A[i] &= rm._A[i];
|
|
|
|
}
|
|
|
|
// Narrow the watermarks if &rm spans a narrower range.
|
|
|
|
// Update after to ensure non-overlapping words are zeroed out.
|
|
|
|
if (_lwm < rm._lwm) _lwm = rm._lwm;
|
|
|
|
if (_hwm > rm._hwm) _hwm = rm._hwm;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Subtract 'rm' from 'this'
|
2019-03-05 16:39:18 +01:00
|
|
|
void SUBTRACT(const RegMask &rm) {
|
|
|
|
assert(valid_watermarks() && rm.valid_watermarks(), "sanity");
|
|
|
|
int hwm = MIN2(_hwm, rm._hwm);
|
|
|
|
int lwm = MAX2(_lwm, rm._lwm);
|
|
|
|
for (int i = lwm; i <= hwm; i++) {
|
|
|
|
_A[i] &= ~rm._A[i];
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute size of register mask: number of bits
|
|
|
|
uint Size() const;
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
void print() const { dump(); }
|
2013-01-22 11:31:25 -08:00
|
|
|
void dump(outputStream *st = tty) const; // Print a mask
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static const RegMask Empty; // Common empty mask
|
|
|
|
|
|
|
|
static bool can_represent(OptoReg::Name reg) {
|
|
|
|
// NOTE: -1 in computation reflects the usage of the last
|
2012-06-15 01:25:19 -07:00
|
|
|
// bit of the regmask as an infinite stack flag and
|
2015-05-08 11:49:20 -07:00
|
|
|
// -7 is to keep mask aligned for largest value (VecZ).
|
2007-12-01 00:00:00 +00:00
|
|
|
return (int)reg < (int)(CHUNK_SIZE-1);
|
|
|
|
}
|
2012-06-15 01:25:19 -07:00
|
|
|
static bool can_represent_arg(OptoReg::Name reg) {
|
2015-05-08 11:49:20 -07:00
|
|
|
// NOTE: -SlotsPerVecZ in computation reflects the need
|
|
|
|
// to keep mask aligned for largest value (VecZ).
|
|
|
|
return (int)reg < (int)(CHUNK_SIZE-SlotsPerVecZ);
|
2012-06-15 01:25:19 -07:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Do not use this constant directly in client code!
|
|
|
|
#undef RM_SIZE
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_OPTO_REGMASK_HPP
|