Tue, 09 Mar 2010 20:16:19 +0100
6919934: JSR 292 needs to support x86 C1
Summary: This implements JSR 292 support for C1 x86.
Reviewed-by: never, jrose, kvn
duke@435 | 1 | /* |
xdono@905 | 2 | * Copyright 1999-2008 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 |
never@894 | 136 | void do_StoreField (StoreField* x) { |
never@894 | 137 | if (!x->is_initialized()) { |
never@894 | 138 | kill_memory(); |
never@894 | 139 | } else { |
never@894 | 140 | kill_field(x->field()); |
never@894 | 141 | } |
never@894 | 142 | } |
never@894 | 143 | void do_StoreIndexed (StoreIndexed* x) { kill_array(x->type()); } |
never@894 | 144 | void do_MonitorEnter (MonitorEnter* x) { kill_memory(); } |
never@894 | 145 | void do_MonitorExit (MonitorExit* x) { kill_memory(); } |
never@894 | 146 | void do_Invoke (Invoke* x) { kill_memory(); } |
never@894 | 147 | void do_UnsafePutRaw (UnsafePutRaw* x) { kill_memory(); } |
never@894 | 148 | void do_UnsafePutObject(UnsafePutObject* x) { kill_memory(); } |
never@894 | 149 | void do_Intrinsic (Intrinsic* x) { if (!x->preserves_state()) kill_memory(); } |
duke@435 | 150 | |
never@894 | 151 | void do_Phi (Phi* x) { /* nothing to do */ } |
never@894 | 152 | void do_Local (Local* x) { /* nothing to do */ } |
never@894 | 153 | void do_Constant (Constant* x) { /* nothing to do */ } |
never@894 | 154 | void do_LoadField (LoadField* x) { |
never@894 | 155 | if (!x->is_initialized()) { |
never@894 | 156 | kill_memory(); |
never@894 | 157 | } |
never@894 | 158 | } |
never@894 | 159 | void do_ArrayLength (ArrayLength* x) { /* nothing to do */ } |
never@894 | 160 | void do_LoadIndexed (LoadIndexed* x) { /* nothing to do */ } |
never@894 | 161 | void do_NegateOp (NegateOp* x) { /* nothing to do */ } |
never@894 | 162 | void do_ArithmeticOp (ArithmeticOp* x) { /* nothing to do */ } |
never@894 | 163 | void do_ShiftOp (ShiftOp* x) { /* nothing to do */ } |
never@894 | 164 | void do_LogicOp (LogicOp* x) { /* nothing to do */ } |
never@894 | 165 | void do_CompareOp (CompareOp* x) { /* nothing to do */ } |
never@894 | 166 | void do_IfOp (IfOp* x) { /* nothing to do */ } |
never@894 | 167 | void do_Convert (Convert* x) { /* nothing to do */ } |
never@894 | 168 | void do_NullCheck (NullCheck* x) { /* nothing to do */ } |
never@894 | 169 | void do_NewInstance (NewInstance* x) { /* nothing to do */ } |
never@894 | 170 | void do_NewTypeArray (NewTypeArray* x) { /* nothing to do */ } |
never@894 | 171 | void do_NewObjectArray (NewObjectArray* x) { /* nothing to do */ } |
never@894 | 172 | void do_NewMultiArray (NewMultiArray* x) { /* nothing to do */ } |
never@894 | 173 | void do_CheckCast (CheckCast* x) { /* nothing to do */ } |
never@894 | 174 | void do_InstanceOf (InstanceOf* x) { /* nothing to do */ } |
never@894 | 175 | void do_BlockBegin (BlockBegin* x) { /* nothing to do */ } |
never@894 | 176 | void do_Goto (Goto* x) { /* nothing to do */ } |
never@894 | 177 | void do_If (If* x) { /* nothing to do */ } |
never@894 | 178 | void do_IfInstanceOf (IfInstanceOf* x) { /* nothing to do */ } |
never@894 | 179 | void do_TableSwitch (TableSwitch* x) { /* nothing to do */ } |
never@894 | 180 | void do_LookupSwitch (LookupSwitch* x) { /* nothing to do */ } |
never@894 | 181 | void do_Return (Return* x) { /* nothing to do */ } |
never@894 | 182 | void do_Throw (Throw* x) { /* nothing to do */ } |
never@894 | 183 | void do_Base (Base* x) { /* nothing to do */ } |
never@894 | 184 | void do_OsrEntry (OsrEntry* x) { /* nothing to do */ } |
never@894 | 185 | void do_ExceptionObject(ExceptionObject* x) { /* nothing to do */ } |
never@894 | 186 | void do_RoundFP (RoundFP* x) { /* nothing to do */ } |
never@894 | 187 | void do_UnsafeGetRaw (UnsafeGetRaw* x) { /* nothing to do */ } |
never@894 | 188 | void do_UnsafeGetObject(UnsafeGetObject* x) { /* nothing to do */ } |
never@894 | 189 | void do_UnsafePrefetchRead (UnsafePrefetchRead* x) { /* nothing to do */ } |
never@894 | 190 | void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) { /* nothing to do */ } |
never@894 | 191 | void do_ProfileCall (ProfileCall* x) { /* nothing to do */ } |
never@894 | 192 | void do_ProfileCounter (ProfileCounter* x) { /* nothing to do */ } |
never@894 | 193 | }; |
never@894 | 194 | |
never@894 | 195 | |
never@894 | 196 | class ValueNumberingEffects: public ValueNumberingVisitor { |
never@894 | 197 | private: |
never@894 | 198 | ValueMap* _map; |
never@894 | 199 | |
never@894 | 200 | public: |
never@894 | 201 | // implementation for abstract methods of ValueNumberingVisitor |
never@894 | 202 | void kill_memory() { _map->kill_memory(); } |
never@894 | 203 | void kill_field(ciField* field) { _map->kill_field(field); } |
never@894 | 204 | void kill_array(ValueType* type) { _map->kill_array(type); } |
never@894 | 205 | |
never@894 | 206 | ValueNumberingEffects(ValueMap* map): _map(map) {} |
duke@435 | 207 | }; |
duke@435 | 208 | |
duke@435 | 209 | |
duke@435 | 210 | class GlobalValueNumbering: public ValueNumberingVisitor { |
duke@435 | 211 | private: |
duke@435 | 212 | ValueMap* _current_map; // value map of current block |
duke@435 | 213 | ValueMapArray _value_maps; // list of value maps for all blocks |
duke@435 | 214 | |
duke@435 | 215 | public: |
duke@435 | 216 | // accessors |
duke@435 | 217 | ValueMap* current_map() { return _current_map; } |
duke@435 | 218 | ValueMap* value_map_of(BlockBegin* block) { return _value_maps.at(block->linear_scan_number()); } |
duke@435 | 219 | 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 | 220 | |
duke@435 | 221 | // implementation for abstract methods of ValueNumberingVisitor |
duke@435 | 222 | void kill_memory() { current_map()->kill_memory(); } |
duke@435 | 223 | void kill_field(ciField* field) { current_map()->kill_field(field); } |
duke@435 | 224 | void kill_array(ValueType* type) { current_map()->kill_array(type); } |
duke@435 | 225 | |
duke@435 | 226 | // main entry point that performs global value numbering |
duke@435 | 227 | GlobalValueNumbering(IR* ir); |
duke@435 | 228 | }; |