src/share/vm/c1/c1_ValueMap.hpp

Wed, 02 Feb 2011 11:35:26 -0500

author
bobv
date
Wed, 02 Feb 2011 11:35:26 -0500
changeset 2508
b92c45f2bc75
parent 2486
403dc4c1d7f5
child 2634
425688247f3d
permissions
-rw-r--r--

7016023: Enable building ARM and PPC from src/closed repository
Reviewed-by: dholmes, bdelsart

duke@435 1 /*
never@2486 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_C1_C1_VALUEMAP_HPP
stefank@2314 26 #define SHARE_VM_C1_C1_VALUEMAP_HPP
stefank@2314 27
stefank@2314 28 #include "c1/c1_Instruction.hpp"
stefank@2314 29 #include "c1/c1_ValueSet.hpp"
stefank@2314 30 #include "memory/allocation.hpp"
stefank@2314 31
duke@435 32 class ValueMapEntry: public CompilationResourceObj {
duke@435 33 private:
duke@435 34 intx _hash;
duke@435 35 Value _value;
duke@435 36 int _nesting;
duke@435 37 ValueMapEntry* _next;
duke@435 38
duke@435 39 public:
duke@435 40 ValueMapEntry(intx hash, Value value, int nesting, ValueMapEntry* next)
duke@435 41 : _hash(hash)
duke@435 42 , _value(value)
duke@435 43 , _nesting(nesting)
duke@435 44 , _next(next)
duke@435 45 {
duke@435 46 }
duke@435 47
duke@435 48 intx hash() { return _hash; }
duke@435 49 Value value() { return _value; }
duke@435 50 int nesting() { return _nesting; }
duke@435 51 ValueMapEntry* next() { return _next; }
duke@435 52
duke@435 53 void set_next(ValueMapEntry* next) { _next = next; }
duke@435 54 };
duke@435 55
duke@435 56 define_array(ValueMapEntryArray, ValueMapEntry*)
duke@435 57 define_stack(ValueMapEntryList, ValueMapEntryArray)
duke@435 58
duke@435 59 // ValueMap implements nested hash tables for value numbering. It
duke@435 60 // maintains a set _killed_values which represents the instructions
duke@435 61 // which have been killed so far and an array of linked lists of
duke@435 62 // ValueMapEntries names _entries. Each ValueMapEntry has a nesting
duke@435 63 // which indicates what ValueMap nesting it belongs to. Higher
duke@435 64 // nesting values are always before lower values in the linked list.
duke@435 65 // This allows cloning of parent ValueMaps by simply copying the heads
duke@435 66 // of the list. _entry_count represents the number of reachable
duke@435 67 // entries in the ValueMap. A ValueMap is only allowed to mutate
duke@435 68 // ValueMapEntries with the same nesting level. Adding or removing
duke@435 69 // entries at the current nesting level requires updating
duke@435 70 // _entry_count. Elements in the parent's list that get killed can be
duke@435 71 // skipped if they are at the head of the list by simply moving to the
duke@435 72 // next element in the list and decrementing _entry_count.
duke@435 73
duke@435 74 class ValueMap: public CompilationResourceObj {
duke@435 75 private:
duke@435 76 int _nesting;
duke@435 77 ValueMapEntryArray _entries;
duke@435 78 ValueSet _killed_values;
duke@435 79 int _entry_count;
duke@435 80
duke@435 81 int nesting() { return _nesting; }
duke@435 82 bool is_local_value_numbering() { return _nesting == 0; }
duke@435 83 bool is_global_value_numbering() { return _nesting > 0; }
duke@435 84
duke@435 85 int entry_count() { return _entry_count; }
duke@435 86 int size() { return _entries.length(); }
duke@435 87 ValueMapEntry* entry_at(int i) { return _entries.at(i); }
duke@435 88
duke@435 89 // calculates the index of a hash value in a hash table of size n
duke@435 90 int entry_index(intx hash, int n) { return (unsigned int)hash % n; }
duke@435 91
duke@435 92 // if entry_count > size_threshold, the size of the hash table is increased
duke@435 93 int size_threshold() { return size(); }
duke@435 94
duke@435 95 // management of the killed-bitset for global value numbering
duke@435 96 void kill_value(Value v) { if (is_global_value_numbering()) _killed_values.put(v); }
duke@435 97 bool is_killed(Value v) { if (is_global_value_numbering()) return _killed_values.contains(v); else return false; }
duke@435 98
duke@435 99 // helper functions
duke@435 100 void increase_table_size();
duke@435 101
duke@435 102 #ifndef PRODUCT
duke@435 103 static int _number_of_finds;
duke@435 104 static int _number_of_hits;
duke@435 105 static int _number_of_kills;
duke@435 106 #endif // PRODUCT
duke@435 107
duke@435 108 public:
duke@435 109 // creation
duke@435 110 ValueMap(); // empty value map
duke@435 111 ValueMap(ValueMap* old); // value map with increased nesting
duke@435 112
duke@435 113 // manipulation
duke@435 114 Value find_insert(Value x);
duke@435 115
duke@435 116 void kill_memory();
duke@435 117 void kill_field(ciField* field);
duke@435 118 void kill_array(ValueType* type);
duke@435 119 void kill_exception();
duke@435 120 void kill_map(ValueMap* map);
duke@435 121 void kill_all();
duke@435 122
duke@435 123 #ifndef PRODUCT
duke@435 124 // debugging/printing
duke@435 125 void print();
duke@435 126
duke@435 127 static void reset_statistics();
duke@435 128 static void print_statistics();
duke@435 129 #endif
duke@435 130 };
duke@435 131
duke@435 132 define_array(ValueMapArray, ValueMap*)
duke@435 133
duke@435 134
duke@435 135 class ValueNumberingVisitor: public InstructionVisitor {
duke@435 136 protected:
duke@435 137 // called by visitor functions for instructions that kill values
duke@435 138 virtual void kill_memory() = 0;
duke@435 139 virtual void kill_field(ciField* field) = 0;
duke@435 140 virtual void kill_array(ValueType* type) = 0;
duke@435 141
duke@435 142 // visitor functions
never@894 143 void do_StoreField (StoreField* x) {
never@894 144 if (!x->is_initialized()) {
never@894 145 kill_memory();
never@894 146 } else {
never@894 147 kill_field(x->field());
never@894 148 }
never@894 149 }
never@894 150 void do_StoreIndexed (StoreIndexed* x) { kill_array(x->type()); }
never@894 151 void do_MonitorEnter (MonitorEnter* x) { kill_memory(); }
never@894 152 void do_MonitorExit (MonitorExit* x) { kill_memory(); }
never@894 153 void do_Invoke (Invoke* x) { kill_memory(); }
never@894 154 void do_UnsafePutRaw (UnsafePutRaw* x) { kill_memory(); }
never@894 155 void do_UnsafePutObject(UnsafePutObject* x) { kill_memory(); }
never@894 156 void do_Intrinsic (Intrinsic* x) { if (!x->preserves_state()) kill_memory(); }
duke@435 157
never@894 158 void do_Phi (Phi* x) { /* nothing to do */ }
never@894 159 void do_Local (Local* x) { /* nothing to do */ }
never@894 160 void do_Constant (Constant* x) { /* nothing to do */ }
never@894 161 void do_LoadField (LoadField* x) {
never@894 162 if (!x->is_initialized()) {
never@894 163 kill_memory();
never@894 164 }
never@894 165 }
never@894 166 void do_ArrayLength (ArrayLength* x) { /* nothing to do */ }
never@894 167 void do_LoadIndexed (LoadIndexed* x) { /* nothing to do */ }
never@894 168 void do_NegateOp (NegateOp* x) { /* nothing to do */ }
never@894 169 void do_ArithmeticOp (ArithmeticOp* x) { /* nothing to do */ }
never@894 170 void do_ShiftOp (ShiftOp* x) { /* nothing to do */ }
never@894 171 void do_LogicOp (LogicOp* x) { /* nothing to do */ }
never@894 172 void do_CompareOp (CompareOp* x) { /* nothing to do */ }
never@894 173 void do_IfOp (IfOp* x) { /* nothing to do */ }
never@894 174 void do_Convert (Convert* x) { /* nothing to do */ }
never@894 175 void do_NullCheck (NullCheck* x) { /* nothing to do */ }
never@894 176 void do_NewInstance (NewInstance* x) { /* nothing to do */ }
never@894 177 void do_NewTypeArray (NewTypeArray* x) { /* nothing to do */ }
never@894 178 void do_NewObjectArray (NewObjectArray* x) { /* nothing to do */ }
never@894 179 void do_NewMultiArray (NewMultiArray* x) { /* nothing to do */ }
never@894 180 void do_CheckCast (CheckCast* x) { /* nothing to do */ }
never@894 181 void do_InstanceOf (InstanceOf* x) { /* nothing to do */ }
never@894 182 void do_BlockBegin (BlockBegin* x) { /* nothing to do */ }
never@894 183 void do_Goto (Goto* x) { /* nothing to do */ }
never@894 184 void do_If (If* x) { /* nothing to do */ }
never@894 185 void do_IfInstanceOf (IfInstanceOf* x) { /* nothing to do */ }
never@894 186 void do_TableSwitch (TableSwitch* x) { /* nothing to do */ }
never@894 187 void do_LookupSwitch (LookupSwitch* x) { /* nothing to do */ }
never@894 188 void do_Return (Return* x) { /* nothing to do */ }
never@894 189 void do_Throw (Throw* x) { /* nothing to do */ }
never@894 190 void do_Base (Base* x) { /* nothing to do */ }
never@894 191 void do_OsrEntry (OsrEntry* x) { /* nothing to do */ }
never@894 192 void do_ExceptionObject(ExceptionObject* x) { /* nothing to do */ }
never@894 193 void do_RoundFP (RoundFP* x) { /* nothing to do */ }
never@894 194 void do_UnsafeGetRaw (UnsafeGetRaw* x) { /* nothing to do */ }
never@894 195 void do_UnsafeGetObject(UnsafeGetObject* x) { /* nothing to do */ }
never@894 196 void do_UnsafePrefetchRead (UnsafePrefetchRead* x) { /* nothing to do */ }
never@894 197 void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) { /* nothing to do */ }
never@894 198 void do_ProfileCall (ProfileCall* x) { /* nothing to do */ }
never@2486 199 void do_ProfileInvoke (ProfileInvoke* x) { /* nothing to do */ };
never@2486 200 void do_RuntimeCall (RuntimeCall* x) { /* nothing to do */ };
never@894 201 };
never@894 202
never@894 203
never@894 204 class ValueNumberingEffects: public ValueNumberingVisitor {
never@894 205 private:
never@894 206 ValueMap* _map;
never@894 207
never@894 208 public:
never@894 209 // implementation for abstract methods of ValueNumberingVisitor
never@894 210 void kill_memory() { _map->kill_memory(); }
never@894 211 void kill_field(ciField* field) { _map->kill_field(field); }
never@894 212 void kill_array(ValueType* type) { _map->kill_array(type); }
never@894 213
never@894 214 ValueNumberingEffects(ValueMap* map): _map(map) {}
duke@435 215 };
duke@435 216
duke@435 217
duke@435 218 class GlobalValueNumbering: public ValueNumberingVisitor {
duke@435 219 private:
duke@435 220 ValueMap* _current_map; // value map of current block
duke@435 221 ValueMapArray _value_maps; // list of value maps for all blocks
duke@435 222
duke@435 223 public:
duke@435 224 // accessors
duke@435 225 ValueMap* current_map() { return _current_map; }
duke@435 226 ValueMap* value_map_of(BlockBegin* block) { return _value_maps.at(block->linear_scan_number()); }
duke@435 227 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 228
duke@435 229 // implementation for abstract methods of ValueNumberingVisitor
duke@435 230 void kill_memory() { current_map()->kill_memory(); }
duke@435 231 void kill_field(ciField* field) { current_map()->kill_field(field); }
duke@435 232 void kill_array(ValueType* type) { current_map()->kill_array(type); }
duke@435 233
duke@435 234 // main entry point that performs global value numbering
duke@435 235 GlobalValueNumbering(IR* ir);
duke@435 236 };
stefank@2314 237
stefank@2314 238 #endif // SHARE_VM_C1_C1_VALUEMAP_HPP

mercurial