src/share/vm/c1/c1_ValueMap.hpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 894
3a86a8dcf27c
permissions
-rw-r--r--

Initial load

duke@435 1 /*
duke@435 2 * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class ValueMapEntry: public CompilationResourceObj {
duke@435 26 private:
duke@435 27 intx _hash;
duke@435 28 Value _value;
duke@435 29 int _nesting;
duke@435 30 ValueMapEntry* _next;
duke@435 31
duke@435 32 public:
duke@435 33 ValueMapEntry(intx hash, Value value, int nesting, ValueMapEntry* next)
duke@435 34 : _hash(hash)
duke@435 35 , _value(value)
duke@435 36 , _nesting(nesting)
duke@435 37 , _next(next)
duke@435 38 {
duke@435 39 }
duke@435 40
duke@435 41 intx hash() { return _hash; }
duke@435 42 Value value() { return _value; }
duke@435 43 int nesting() { return _nesting; }
duke@435 44 ValueMapEntry* next() { return _next; }
duke@435 45
duke@435 46 void set_next(ValueMapEntry* next) { _next = next; }
duke@435 47 };
duke@435 48
duke@435 49 define_array(ValueMapEntryArray, ValueMapEntry*)
duke@435 50 define_stack(ValueMapEntryList, ValueMapEntryArray)
duke@435 51
duke@435 52 // ValueMap implements nested hash tables for value numbering. It
duke@435 53 // maintains a set _killed_values which represents the instructions
duke@435 54 // which have been killed so far and an array of linked lists of
duke@435 55 // ValueMapEntries names _entries. Each ValueMapEntry has a nesting
duke@435 56 // which indicates what ValueMap nesting it belongs to. Higher
duke@435 57 // nesting values are always before lower values in the linked list.
duke@435 58 // This allows cloning of parent ValueMaps by simply copying the heads
duke@435 59 // of the list. _entry_count represents the number of reachable
duke@435 60 // entries in the ValueMap. A ValueMap is only allowed to mutate
duke@435 61 // ValueMapEntries with the same nesting level. Adding or removing
duke@435 62 // entries at the current nesting level requires updating
duke@435 63 // _entry_count. Elements in the parent's list that get killed can be
duke@435 64 // skipped if they are at the head of the list by simply moving to the
duke@435 65 // next element in the list and decrementing _entry_count.
duke@435 66
duke@435 67 class ValueMap: public CompilationResourceObj {
duke@435 68 private:
duke@435 69 int _nesting;
duke@435 70 ValueMapEntryArray _entries;
duke@435 71 ValueSet _killed_values;
duke@435 72 int _entry_count;
duke@435 73
duke@435 74 int nesting() { return _nesting; }
duke@435 75 bool is_local_value_numbering() { return _nesting == 0; }
duke@435 76 bool is_global_value_numbering() { return _nesting > 0; }
duke@435 77
duke@435 78 int entry_count() { return _entry_count; }
duke@435 79 int size() { return _entries.length(); }
duke@435 80 ValueMapEntry* entry_at(int i) { return _entries.at(i); }
duke@435 81
duke@435 82 // calculates the index of a hash value in a hash table of size n
duke@435 83 int entry_index(intx hash, int n) { return (unsigned int)hash % n; }
duke@435 84
duke@435 85 // if entry_count > size_threshold, the size of the hash table is increased
duke@435 86 int size_threshold() { return size(); }
duke@435 87
duke@435 88 // management of the killed-bitset for global value numbering
duke@435 89 void kill_value(Value v) { if (is_global_value_numbering()) _killed_values.put(v); }
duke@435 90 bool is_killed(Value v) { if (is_global_value_numbering()) return _killed_values.contains(v); else return false; }
duke@435 91
duke@435 92 // helper functions
duke@435 93 void increase_table_size();
duke@435 94
duke@435 95 #ifndef PRODUCT
duke@435 96 static int _number_of_finds;
duke@435 97 static int _number_of_hits;
duke@435 98 static int _number_of_kills;
duke@435 99 #endif // PRODUCT
duke@435 100
duke@435 101 public:
duke@435 102 // creation
duke@435 103 ValueMap(); // empty value map
duke@435 104 ValueMap(ValueMap* old); // value map with increased nesting
duke@435 105
duke@435 106 // manipulation
duke@435 107 Value find_insert(Value x);
duke@435 108
duke@435 109 void kill_memory();
duke@435 110 void kill_field(ciField* field);
duke@435 111 void kill_array(ValueType* type);
duke@435 112 void kill_exception();
duke@435 113 void kill_map(ValueMap* map);
duke@435 114 void kill_all();
duke@435 115
duke@435 116 #ifndef PRODUCT
duke@435 117 // debugging/printing
duke@435 118 void print();
duke@435 119
duke@435 120 static void reset_statistics();
duke@435 121 static void print_statistics();
duke@435 122 #endif
duke@435 123 };
duke@435 124
duke@435 125 define_array(ValueMapArray, ValueMap*)
duke@435 126
duke@435 127
duke@435 128 class ValueNumberingVisitor: public InstructionVisitor {
duke@435 129 protected:
duke@435 130 // called by visitor functions for instructions that kill values
duke@435 131 virtual void kill_memory() = 0;
duke@435 132 virtual void kill_field(ciField* field) = 0;
duke@435 133 virtual void kill_array(ValueType* type) = 0;
duke@435 134
duke@435 135 // visitor functions
duke@435 136 void do_StoreField (StoreField* x) { kill_field(x->field()); };
duke@435 137 void do_StoreIndexed (StoreIndexed* x) { kill_array(x->type()); };
duke@435 138 void do_MonitorEnter (MonitorEnter* x) { kill_memory(); };
duke@435 139 void do_MonitorExit (MonitorExit* x) { kill_memory(); };
duke@435 140 void do_Invoke (Invoke* x) { kill_memory(); };
duke@435 141 void do_UnsafePutRaw (UnsafePutRaw* x) { kill_memory(); };
duke@435 142 void do_UnsafePutObject(UnsafePutObject* x) { kill_memory(); };
duke@435 143 void do_Intrinsic (Intrinsic* x) { if (!x->preserves_state()) kill_memory(); };
duke@435 144
duke@435 145 void do_Phi (Phi* x) { /* nothing to do */ };
duke@435 146 void do_Local (Local* x) { /* nothing to do */ };
duke@435 147 void do_Constant (Constant* x) { /* nothing to do */ };
duke@435 148 void do_LoadField (LoadField* x) { /* nothing to do */ };
duke@435 149 void do_ArrayLength (ArrayLength* x) { /* nothing to do */ };
duke@435 150 void do_LoadIndexed (LoadIndexed* x) { /* nothing to do */ };
duke@435 151 void do_NegateOp (NegateOp* x) { /* nothing to do */ };
duke@435 152 void do_ArithmeticOp (ArithmeticOp* x) { /* nothing to do */ };
duke@435 153 void do_ShiftOp (ShiftOp* x) { /* nothing to do */ };
duke@435 154 void do_LogicOp (LogicOp* x) { /* nothing to do */ };
duke@435 155 void do_CompareOp (CompareOp* x) { /* nothing to do */ };
duke@435 156 void do_IfOp (IfOp* x) { /* nothing to do */ };
duke@435 157 void do_Convert (Convert* x) { /* nothing to do */ };
duke@435 158 void do_NullCheck (NullCheck* x) { /* nothing to do */ };
duke@435 159 void do_NewInstance (NewInstance* x) { /* nothing to do */ };
duke@435 160 void do_NewTypeArray (NewTypeArray* x) { /* nothing to do */ };
duke@435 161 void do_NewObjectArray (NewObjectArray* x) { /* nothing to do */ };
duke@435 162 void do_NewMultiArray (NewMultiArray* x) { /* nothing to do */ };
duke@435 163 void do_CheckCast (CheckCast* x) { /* nothing to do */ };
duke@435 164 void do_InstanceOf (InstanceOf* x) { /* nothing to do */ };
duke@435 165 void do_BlockBegin (BlockBegin* x) { /* nothing to do */ };
duke@435 166 void do_Goto (Goto* x) { /* nothing to do */ };
duke@435 167 void do_If (If* x) { /* nothing to do */ };
duke@435 168 void do_IfInstanceOf (IfInstanceOf* x) { /* nothing to do */ };
duke@435 169 void do_TableSwitch (TableSwitch* x) { /* nothing to do */ };
duke@435 170 void do_LookupSwitch (LookupSwitch* x) { /* nothing to do */ };
duke@435 171 void do_Return (Return* x) { /* nothing to do */ };
duke@435 172 void do_Throw (Throw* x) { /* nothing to do */ };
duke@435 173 void do_Base (Base* x) { /* nothing to do */ };
duke@435 174 void do_OsrEntry (OsrEntry* x) { /* nothing to do */ };
duke@435 175 void do_ExceptionObject(ExceptionObject* x) { /* nothing to do */ };
duke@435 176 void do_RoundFP (RoundFP* x) { /* nothing to do */ };
duke@435 177 void do_UnsafeGetRaw (UnsafeGetRaw* x) { /* nothing to do */ };
duke@435 178 void do_UnsafeGetObject(UnsafeGetObject* x) { /* nothing to do */ };
duke@435 179 void do_UnsafePrefetchRead (UnsafePrefetchRead* x) { /* nothing to do */ };
duke@435 180 void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) { /* nothing to do */ };
duke@435 181 void do_ProfileCall (ProfileCall* x) { /* nothing to do */ };
duke@435 182 void do_ProfileCounter (ProfileCounter* x) { /* nothing to do */ };
duke@435 183 };
duke@435 184
duke@435 185
duke@435 186 class GlobalValueNumbering: public ValueNumberingVisitor {
duke@435 187 private:
duke@435 188 ValueMap* _current_map; // value map of current block
duke@435 189 ValueMapArray _value_maps; // list of value maps for all blocks
duke@435 190
duke@435 191 public:
duke@435 192 // accessors
duke@435 193 ValueMap* current_map() { return _current_map; }
duke@435 194 ValueMap* value_map_of(BlockBegin* block) { return _value_maps.at(block->linear_scan_number()); }
duke@435 195 void set_value_map_of(BlockBegin* block, ValueMap* map) { assert(value_map_of(block) == NULL, ""); _value_maps.at_put(block->linear_scan_number(), map); }
duke@435 196
duke@435 197 // implementation for abstract methods of ValueNumberingVisitor
duke@435 198 void kill_memory() { current_map()->kill_memory(); }
duke@435 199 void kill_field(ciField* field) { current_map()->kill_field(field); }
duke@435 200 void kill_array(ValueType* type) { current_map()->kill_array(type); }
duke@435 201
duke@435 202 // main entry point that performs global value numbering
duke@435 203 GlobalValueNumbering(IR* ir);
duke@435 204 };

mercurial