/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*
* 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.
*
*/
#include "precompiled.hpp"
#include "memory/allocation.inline.hpp"
#include "opto/chaitin.hpp"
#include "opto/compile.hpp"
#include "opto/indexSet.hpp"
#include "opto/regmask.hpp"
// This file defines the IndexSet class, a set of sparse integer indices.
// This data structure is used by the compiler in its liveness analysis and
// during register allocation. It also defines an iterator for this class.
//-------------------------------- Initializations ------------------------------
#ifdef ASSERT
// Initialize statistics counters
// Per set, or all sets operation tracing
#endif
// What is the first set bit in a 5 bit integer?
0, 0, 1, 0,
2, 0, 1, 0,
3, 0, 1, 0,
2, 0, 1, 0,
4, 0, 1, 0,
2, 0, 1, 0,
3, 0, 1, 0,
2, 0, 1, 0
};
// What is the second set bit in a 5 bit integer?
5, 5, 5, 1,
5, 2, 2, 1,
5, 3, 3, 1,
3, 2, 2, 1,
5, 4, 4, 1,
4, 2, 2, 1,
4, 3, 3, 1,
3, 2, 2, 1
};
// I tried implementing the IndexSetIterator with a window_size of 8 and
// didn't seem to get a noticeable speedup. I am leaving in the tables
// in case we want to switch back.
/*const byte IndexSetIterator::_first_bit[256] = {
8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
5, 0, 1, 0, 2, 0, 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, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
8, 7, 7, 1, 7, 2, 2, 1, 7, 3, 3, 1, 3, 2, 2, 1,
7, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
7, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
7, 6, 6, 1, 6, 2, 2, 1, 6, 3, 3, 1, 3, 2, 2, 1,
6, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
6, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1
};*/
//---------------------------- IndexSet::populate_free_list() -----------------------------
// Populate the free BitBlock list with a batch of BitBlocks. The BitBlocks
// are 32 bit aligned.
bitblock_alloc_chunk_size + 32);
// Align the pointer to a 32 bit boundary.
// Add the new blocks to the free list.
for (int i = 0; i < bitblock_alloc_chunk_size; i++) {
free = new_blocks;
new_blocks++;
}
#ifdef ASSERT
if (CollectIndexSetStatistics) {
}
#endif
}
//---------------------------- IndexSet::alloc_block() ------------------------
// Allocate a BitBlock from the free list. If the free list is empty,
// prime it.
#ifdef ASSERT
if (CollectIndexSetStatistics) {
}
#endif
}
return block;
}
//---------------------------- IndexSet::alloc_block_containing() -------------
// Allocate a new BitBlock and put it into the position in the _blocks array
// corresponding to element.
return block;
}
//---------------------------- IndexSet::free_block() -------------------------
// Add a BitBlock to the free list.
set_block(i,&_empty_block);
}
//------------------------------lrg_union--------------------------------------
// Compute the union of all elements of one and two which interfere with
// the RegMask mask. If the degree of the union becomes exceeds
// fail_degree, the union bails out. The underlying set is cleared before
// the union is performed.
const uint fail_degree,
#ifdef ASSERT
check_watch("union destination");
#endif
// Compute the degree of the combined live-range. The combined
// live-range has the union of the original live-ranges' neighbors set as
// well as the neighbors of all intermediate copies, minus those neighbors
// that can not use the intersected allowed-register-set.
// Copy the larger set. Insert the smaller set into the larger.
}
clear();
// Used to compute degree of register-only interferences. Infinite-stack
// neighbors do not alter colorability, as they can always color to some
// other color. (A variant of the Briggs assertion)
// Load up the combined interference set with the neighbors of one
} else {
// !!!!! Danger! No update to reg_degree despite having a neighbor.
// A variant of the Briggs assertion.
}
}
}
// Add neighbors of two as well
} else {
// !!!!! Danger! No update to reg_degree despite having a neighbor.
// A variant of the Briggs assertion.
}
}
}
}
return reg_degree;
}
//---------------------------- IndexSet() -----------------------------
// A deep copy constructor. This is used when you need a scratch copy of this set.
#ifdef ASSERT
#endif
if (_max_blocks <= preallocated_block_list_size) {
} else {
_blocks =
}
for (uint i = 0; i < _max_blocks; i++) {
if (block == &_empty_block) {
set_block(i, &_empty_block);
} else {
}
}
}
//---------------------------- IndexSet::initialize() -----------------------------
// Prepare an IndexSet for use.
#ifdef ASSERT
#endif
_count = 0;
if (_max_blocks <= preallocated_block_list_size) {
} else {
}
for (uint i = 0; i < _max_blocks; i++) {
set_block(i, &_empty_block);
}
}
//---------------------------- IndexSet::initialize()------------------------------
// Prepare an IndexSet for use. If it needs to allocate its _blocks array, it does
// so from the Arena passed as a parameter. BitBlock allocation is still done from
// the static Arena which was set with reset_memory().
#ifdef ASSERT
#endif // ASSERT
_count = 0;
if (_max_blocks <= preallocated_block_list_size) {
} else {
}
for (uint i = 0; i < _max_blocks; i++) {
set_block(i, &_empty_block);
}
}
//---------------------------- IndexSet::swap() -----------------------------
// Exchange two IndexSets.
#ifdef ASSERT
#endif
for (uint i = 0; i < _max_blocks; i++) {
}
}
//---------------------------- IndexSet::dump() -----------------------------
// Print this set. Used for debugging.
#ifndef PRODUCT
IndexSetIterator elements(this);
uint i;
}
}
#endif
#ifdef ASSERT
//---------------------------- IndexSet::tally_iteration_statistics() -----------------------------
for (uint i = 0; i < _max_blocks; i++) {
if (_blocks[i] != &_empty_block) {
} else {
}
}
}
//---------------------------- IndexSet::print_statistics() -----------------------------
// Print statistics about IndexSet usage.
}
//---------------------------- IndexSet::verify() -----------------------------
// Expensive test of IndexSet sanity. Ensure that the count agrees with the
// number of bits in the blocks. Make sure the iterator is seeing all elements
// of the set. Meant for use during development.
uint i;
for (i = 1; i < _max_elements; i++) {
if (member(i)) {
count++;
}
}
IndexSetIterator elements(this);
count = 0;
count++;
}
}
#endif
//---------------------------- IndexSetIterator() -----------------------------
// Create an iterator for a set. If empty blocks are detected when iterating
// over the set, these blocks are replaced.
#ifdef ASSERT
if (CollectIndexSetStatistics) {
}
#endif
_current = 0;
_next_block = 1;
_max_blocks = 1;
// We don't need the following values when we iterate over an empty set.
// The commented out code is left here to document that the omission
// is intentional.
//
//_value = 0;
//_words = NULL;
//_blocks = NULL;
//_set = NULL;
} else {
_current = 0;
_value = 0;
_next_block = 0;
}
}
//---------------------------- IndexSetIterator(const) -----------------------------
// Iterate over a constant IndexSet.
#ifdef ASSERT
if (CollectIndexSetStatistics) {
}
// We don't call check_watch from here to avoid bad recursion.
// set->check_watch("traversed const", set->count());
#endif
_current = 0;
_next_block = 1;
_max_blocks = 1;
// We don't need the following values when we iterate over an empty set.
// The commented out code is left here to document that the omission
// is intentional.
//
//_value = 0;
//_words = NULL;
//_blocks = NULL;
//_set = NULL;
} else {
_current = 0;
_value = 0;
_next_block = 0;
}
}
//---------------------------- List16Iterator::advance_and_next() -----------------------------
// Advance to the next non-empty word in the set being iterated over. Return the next element
// if there is one. If we are done, return 0. This method is called from the next() method
// when it gets done with a word.
// See if there is another non-empty word in the current block.
// Found a non-empty word.
return next();
}
}
// We ran out of words in the current block. Advance to next non-empty block.
// Found a non-empty block.
// Found a non-empty word.
return next();
}
}
// All of the words in the block were empty. Replace
// the block with the empty block.
if (_set) {
}
}
}
// These assignments make redundant calls to next on a finished iterator
// faster. Probably not necessary.
// No more words.
return 0;
}