/*
* 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.
*
*/
#ifndef SHARE_VM_C1_C1_VALUEMAP_HPP
#define SHARE_VM_C1_C1_VALUEMAP_HPP
#include "c1/c1_Instruction.hpp"
#include "c1/c1_ValueSet.hpp"
#include "memory/allocation.hpp"
private:
int _nesting;
public:
{
}
};
// ValueMap implements nested hash tables for value numbering. It
// maintains a set _killed_values which represents the instructions
// which have been killed so far and an array of linked lists of
// ValueMapEntries names _entries. Each ValueMapEntry has a nesting
// which indicates what ValueMap nesting it belongs to. Higher
// nesting values are always before lower values in the linked list.
// This allows cloning of parent ValueMaps by simply copying the heads
// of the list. _entry_count represents the number of reachable
// entries in the ValueMap. A ValueMap is only allowed to mutate
// ValueMapEntries with the same nesting level. Adding or removing
// entries at the current nesting level requires updating
// _entry_count. Elements in the parent's list that get killed can be
// skipped if they are at the head of the list by simply moving to the
// next element in the list and decrementing _entry_count.
private:
int _nesting;
int _entry_count;
// calculates the index of a hash value in a hash table of size n
// if entry_count > size_threshold, the size of the hash table is increased
// management of the killed-bitset for global value numbering
bool is_killed(Value v) { if (is_global_value_numbering()) return _killed_values.contains(v); else return false; }
// helper functions
void increase_table_size();
#ifndef PRODUCT
static int _number_of_finds;
static int _number_of_hits;
static int _number_of_kills;
#endif // PRODUCT
public:
// creation
ValueMap(); // empty value map
// manipulation
void kill_memory();
void kill_exception();
void kill_all();
#ifndef PRODUCT
void print();
static void reset_statistics();
static void print_statistics();
#endif
};
protected:
// called by visitor functions for instructions that kill values
virtual void kill_memory() = 0;
// visitor functions
if (x->is_init_point() || // putstatic is an initialization point so treat it as a wide kill
// This is actually too strict and the JMM doesn't require
// this in all cases (e.g. load a; volatile store b; load a)
// but possible future optimizations might require this.
x->field()->is_volatile()) {
kill_memory();
} else {
}
}
if (x->is_init_point() || // getstatic is an initialization point so treat it as a wide kill
kill_memory();
}
}
};
private:
public:
// implementation for abstract methods of ValueNumberingVisitor
};
private:
public:
// accessors
void set_value_map_of(BlockBegin* block, ValueMap* map) { assert(value_map_of(block) == NULL, ""); _value_maps.at_put(block->linear_scan_number(), map); }
// implementation for abstract methods of ValueNumberingVisitor
void kill_field(ciField* field, bool all_offsets) { current_map()->kill_field(field, all_offsets); }
// main entry point that performs global value numbering
};
#endif // SHARE_VM_C1_C1_VALUEMAP_HPP