annotate src/share/vm/c1/c1_ValueMap.cpp @ 6842:b9a9ed0f8eeb

7197424: update copyright year to match last edit in jdk8 hotspot repository Summary: Update copyright year to 2012 for relevant files Reviewed-by: dholmes, coleenp
author mikael
date Tue, 09 Oct 2012 10:09:34 -0700
parents 0bfcb7a3e12d
children 46f6f063b272
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 6618
diff changeset
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "c1/c1_Canonicalizer.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "c1/c1_IR.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "c1/c1_ValueMap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "utilities/bitMap.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 int ValueMap::_number_of_finds = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 int ValueMap::_number_of_hits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 int ValueMap::_number_of_kills = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 #define TRACE_VALUE_NUMBERING(code) if (PrintValueNumbering) { code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 #define TRACE_VALUE_NUMBERING(code)
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 ValueMap::ValueMap()
a61af66fc99e Initial load
duke
parents:
diff changeset
48 : _nesting(0)
a61af66fc99e Initial load
duke
parents:
diff changeset
49 , _entries(ValueMapInitialSize, NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
50 , _killed_values()
a61af66fc99e Initial load
duke
parents:
diff changeset
51 , _entry_count(0)
a61af66fc99e Initial load
duke
parents:
diff changeset
52 {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 NOT_PRODUCT(reset_statistics());
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 ValueMap::ValueMap(ValueMap* old)
a61af66fc99e Initial load
duke
parents:
diff changeset
58 : _nesting(old->_nesting + 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
59 , _entries(old->_entries.length())
a61af66fc99e Initial load
duke
parents:
diff changeset
60 , _killed_values()
a61af66fc99e Initial load
duke
parents:
diff changeset
61 , _entry_count(old->_entry_count)
a61af66fc99e Initial load
duke
parents:
diff changeset
62 {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 for (int i = size() - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 _entries.at_put(i, old->entry_at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 _killed_values.set_from(&old->_killed_values);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 void ValueMap::increase_table_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 int old_size = size();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 int new_size = old_size * 2 + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 ValueMapEntryList worklist(8);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 ValueMapEntryArray new_entries(new_size, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 int new_entry_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 TRACE_VALUE_NUMBERING(tty->print_cr("increasing table size from %d to %d", old_size, new_size));
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 for (int i = old_size - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 ValueMapEntry* entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 for (entry = entry_at(i); entry != NULL; entry = entry->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (!is_killed(entry->value())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 worklist.push(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 while (!worklist.is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 entry = worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int new_index = entry_index(entry->hash(), new_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (entry->nesting() != nesting() && new_entries.at(new_index) != entry->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // changing entries with a lower nesting than the current nesting of the table
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // is not allowed because then the same entry is contained in multiple value maps.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // clone entry when next-pointer must be changed
a61af66fc99e Initial load
duke
parents:
diff changeset
96 entry = new ValueMapEntry(entry->hash(), entry->value(), entry->nesting(), NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 entry->set_next(new_entries.at(new_index));
a61af66fc99e Initial load
duke
parents:
diff changeset
99 new_entries.at_put(new_index, entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 new_entry_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 _entries = new_entries;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 _entry_count = new_entry_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 Value ValueMap::find_insert(Value x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 const intx hash = x->hash();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (hash != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // 0 hash means: exclude from value numbering
a61af66fc99e Initial load
duke
parents:
diff changeset
113 NOT_PRODUCT(_number_of_finds++);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 for (ValueMapEntry* entry = entry_at(entry_index(hash, size())); entry != NULL; entry = entry->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (entry->hash() == hash) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 Value f = entry->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (!is_killed(f) && f->is_equal(x)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 NOT_PRODUCT(_number_of_hits++);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 TRACE_VALUE_NUMBERING(tty->print_cr("Value Numbering: %s %c%d equal to %c%d (size %d, entries %d, nesting-diff %d)", x->name(), x->type()->tchar(), x->id(), f->type()->tchar(), f->id(), size(), entry_count(), nesting() - entry->nesting()));
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (entry->nesting() != nesting() && f->as_Constant() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // non-constant values of of another block must be pinned,
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // otherwise it is possible that they are not evaluated
a61af66fc99e Initial load
duke
parents:
diff changeset
126 f->pin(Instruction::PinGlobalValueNumbering);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
4871
f067b4e0e04b 7090976: Eclipse/CDT causes a JVM crash while indexing C++ code
roland
parents: 1972
diff changeset
128 assert(x->type()->tag() == f->type()->tag(), "should have same type");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return f;
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // x not found, so insert it
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (entry_count() >= size_threshold()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 increase_table_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 int idx = entry_index(hash, size());
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _entries.at_put(idx, new ValueMapEntry(hash, x, nesting(), entry_at(idx)));
a61af66fc99e Initial load
duke
parents:
diff changeset
142 _entry_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 TRACE_VALUE_NUMBERING(tty->print_cr("Value Numbering: insert %s %c%d (size %d, entries %d, nesting %d)", x->name(), x->type()->tchar(), x->id(), size(), entry_count(), nesting()));
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return x;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 #define GENERIC_KILL_VALUE(must_kill_implementation) \
a61af66fc99e Initial load
duke
parents:
diff changeset
152 NOT_PRODUCT(_number_of_kills++); \
a61af66fc99e Initial load
duke
parents:
diff changeset
153 \
a61af66fc99e Initial load
duke
parents:
diff changeset
154 for (int i = size() - 1; i >= 0; i--) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
155 ValueMapEntry* prev_entry = NULL; \
a61af66fc99e Initial load
duke
parents:
diff changeset
156 for (ValueMapEntry* entry = entry_at(i); entry != NULL; entry = entry->next()) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
157 Value value = entry->value(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
158 \
a61af66fc99e Initial load
duke
parents:
diff changeset
159 must_kill_implementation(must_kill, entry, value) \
a61af66fc99e Initial load
duke
parents:
diff changeset
160 \
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (must_kill) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
162 kill_value(value); \
a61af66fc99e Initial load
duke
parents:
diff changeset
163 \
a61af66fc99e Initial load
duke
parents:
diff changeset
164 if (prev_entry == NULL) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
165 _entries.at_put(i, entry->next()); \
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _entry_count--; \
a61af66fc99e Initial load
duke
parents:
diff changeset
167 } else if (prev_entry->nesting() == nesting()) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
168 prev_entry->set_next(entry->next()); \
a61af66fc99e Initial load
duke
parents:
diff changeset
169 _entry_count--; \
a61af66fc99e Initial load
duke
parents:
diff changeset
170 } else { \
a61af66fc99e Initial load
duke
parents:
diff changeset
171 prev_entry = entry; \
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
173 \
a61af66fc99e Initial load
duke
parents:
diff changeset
174 TRACE_VALUE_NUMBERING(tty->print_cr("Value Numbering: killed %s %c%d (size %d, entries %d, nesting-diff %d)", value->name(), value->type()->tchar(), value->id(), size(), entry_count(), nesting() - entry->nesting())); \
a61af66fc99e Initial load
duke
parents:
diff changeset
175 } else { \
a61af66fc99e Initial load
duke
parents:
diff changeset
176 prev_entry = entry; \
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
178 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
179 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 #define MUST_KILL_MEMORY(must_kill, entry, value) \
a61af66fc99e Initial load
duke
parents:
diff changeset
182 bool must_kill = value->as_LoadField() != NULL || value->as_LoadIndexed() != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 #define MUST_KILL_ARRAY(must_kill, entry, value) \
a61af66fc99e Initial load
duke
parents:
diff changeset
185 bool must_kill = value->as_LoadIndexed() != NULL \
a61af66fc99e Initial load
duke
parents:
diff changeset
186 && value->type()->tag() == type->tag();
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 #define MUST_KILL_FIELD(must_kill, entry, value) \
a61af66fc99e Initial load
duke
parents:
diff changeset
189 /* ciField's are not unique; must compare their contents */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
190 LoadField* lf = value->as_LoadField(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
191 bool must_kill = lf != NULL \
a61af66fc99e Initial load
duke
parents:
diff changeset
192 && lf->field()->holder() == field->holder() \
6618
0bfcb7a3e12d 7171824: assert(_offset >= 1) failed: illegal call to offset()
roland
parents: 4871
diff changeset
193 && (all_offsets || lf->field()->offset() == field->offset());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 #define MUST_KILL_EXCEPTION(must_kill, entry, value) \
a61af66fc99e Initial load
duke
parents:
diff changeset
196 assert(entry->nesting() < nesting(), "must not find bigger nesting than current"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
197 bool must_kill = (entry->nesting() == nesting() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 void ValueMap::kill_memory() {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 GENERIC_KILL_VALUE(MUST_KILL_MEMORY);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 void ValueMap::kill_array(ValueType* type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 GENERIC_KILL_VALUE(MUST_KILL_ARRAY);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
6618
0bfcb7a3e12d 7171824: assert(_offset >= 1) failed: illegal call to offset()
roland
parents: 4871
diff changeset
208 void ValueMap::kill_field(ciField* field, bool all_offsets) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
209 GENERIC_KILL_VALUE(MUST_KILL_FIELD);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 void ValueMap::kill_exception() {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 GENERIC_KILL_VALUE(MUST_KILL_EXCEPTION);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 void ValueMap::kill_map(ValueMap* map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 assert(is_global_value_numbering(), "only for global value numbering");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 _killed_values.set_union(&map->_killed_values);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 void ValueMap::kill_all() {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 assert(is_local_value_numbering(), "only for local value numbering");
a61af66fc99e Initial load
duke
parents:
diff changeset
224 for (int i = size() - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 _entries.at_put(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227 _entry_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 void ValueMap::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 tty->print_cr("(size %d, entries %d, nesting %d)", size(), entry_count(), nesting());
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 int entries = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 for (int i = 0; i < size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if (entry_at(i) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 tty->print(" %2d: ", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 for (ValueMapEntry* entry = entry_at(i); entry != NULL; entry = entry->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 Value value = entry->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
242 tty->print("%s %c%d (%s%d) -> ", value->name(), value->type()->tchar(), value->id(), is_killed(value) ? "x" : "", entry->nesting());
a61af66fc99e Initial load
duke
parents:
diff changeset
243 entries++;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 tty->print_cr("NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 _killed_values.print();
a61af66fc99e Initial load
duke
parents:
diff changeset
250 assert(entry_count() == entries, "entry_count incorrect");
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 void ValueMap::reset_statistics() {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 _number_of_finds = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 _number_of_hits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 _number_of_kills = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 void ValueMap::print_statistics() {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 float hit_rate = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 if (_number_of_finds != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 hit_rate = (float)_number_of_hits / _number_of_finds;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 tty->print_cr("finds:%3d hits:%3d kills:%3d hit rate: %1.4f", _number_of_finds, _number_of_hits, _number_of_kills, hit_rate);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 class ShortLoopOptimizer : public ValueNumberingVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
274 GlobalValueNumbering* _gvn;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 BlockList _loop_blocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
276 bool _too_complicated_loop;
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // simplified access to methods of GlobalValueNumbering
a61af66fc99e Initial load
duke
parents:
diff changeset
279 ValueMap* current_map() { return _gvn->current_map(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 ValueMap* value_map_of(BlockBegin* block) { return _gvn->value_map_of(block); }
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // implementation for abstract methods of ValueNumberingVisitor
6618
0bfcb7a3e12d 7171824: assert(_offset >= 1) failed: illegal call to offset()
roland
parents: 4871
diff changeset
283 void kill_memory() { _too_complicated_loop = true; }
0bfcb7a3e12d 7171824: assert(_offset >= 1) failed: illegal call to offset()
roland
parents: 4871
diff changeset
284 void kill_field(ciField* field, bool all_offsets) { current_map()->kill_field(field, all_offsets); };
0bfcb7a3e12d 7171824: assert(_offset >= 1) failed: illegal call to offset()
roland
parents: 4871
diff changeset
285 void kill_array(ValueType* type) { current_map()->kill_array(type); };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
288 ShortLoopOptimizer(GlobalValueNumbering* gvn)
a61af66fc99e Initial load
duke
parents:
diff changeset
289 : _gvn(gvn)
a61af66fc99e Initial load
duke
parents:
diff changeset
290 , _loop_blocks(ValueMapMaxLoopSize)
a61af66fc99e Initial load
duke
parents:
diff changeset
291 , _too_complicated_loop(false)
a61af66fc99e Initial load
duke
parents:
diff changeset
292 {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 bool process(BlockBegin* loop_header);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 };
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 bool ShortLoopOptimizer::process(BlockBegin* loop_header) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 TRACE_VALUE_NUMBERING(tty->print_cr("** loop header block"));
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 _too_complicated_loop = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
303 _loop_blocks.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
304 _loop_blocks.append(loop_header);
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 for (int i = 0; i < _loop_blocks.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
307 BlockBegin* block = _loop_blocks.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
308 TRACE_VALUE_NUMBERING(tty->print_cr("processing loop block B%d", block->block_id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if (block->is_set(BlockBegin::exception_entry_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // this would be too complicated
a61af66fc99e Initial load
duke
parents:
diff changeset
312 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // add predecessors to worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
316 for (int j = block->number_of_preds() - 1; j >= 0; j--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 BlockBegin* pred = block->pred_at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
318
a61af66fc99e Initial load
duke
parents:
diff changeset
319 ValueMap* pred_map = value_map_of(pred);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (pred_map != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 current_map()->kill_map(pred_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 } else if (!_loop_blocks.contains(pred)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (_loop_blocks.length() >= ValueMapMaxLoopSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 _loop_blocks.append(pred);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // use the instruction visitor for killing values
a61af66fc99e Initial load
duke
parents:
diff changeset
331 for (Value instr = block->next(); instr != NULL; instr = instr->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 instr->visit(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
333 if (_too_complicated_loop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 TRACE_VALUE_NUMBERING(tty->print_cr("** loop successfully optimized"));
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 GlobalValueNumbering::GlobalValueNumbering(IR* ir)
a61af66fc99e Initial load
duke
parents:
diff changeset
345 : _current_map(NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
346 , _value_maps(ir->linear_scan_order()->length(), NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
347 {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 TRACE_VALUE_NUMBERING(tty->print_cr("****** start of global value numbering"));
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 ShortLoopOptimizer short_loop_optimizer(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
351 int subst_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 BlockList* blocks = ir->linear_scan_order();
a61af66fc99e Initial load
duke
parents:
diff changeset
354 int num_blocks = blocks->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 BlockBegin* start_block = blocks->at(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 assert(start_block == ir->start() && start_block->number_of_preds() == 0 && start_block->dominator() == NULL, "must be start block");
a61af66fc99e Initial load
duke
parents:
diff changeset
358 assert(start_block->next()->as_Base() != NULL && start_block->next()->next() == NULL, "start block must not have instructions");
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // initial, empty value map with nesting 0
a61af66fc99e Initial load
duke
parents:
diff changeset
361 set_value_map_of(start_block, new ValueMap());
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 for (int i = 1; i < num_blocks; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 BlockBegin* block = blocks->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
365 TRACE_VALUE_NUMBERING(tty->print_cr("**** processing block B%d", block->block_id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 int num_preds = block->number_of_preds();
a61af66fc99e Initial load
duke
parents:
diff changeset
368 assert(num_preds > 0, "block must have predecessors");
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 BlockBegin* dominator = block->dominator();
a61af66fc99e Initial load
duke
parents:
diff changeset
371 assert(dominator != NULL, "dominator must exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
372 assert(value_map_of(dominator) != NULL, "value map of dominator must exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // create new value map with increased nesting
a61af66fc99e Initial load
duke
parents:
diff changeset
375 _current_map = new ValueMap(value_map_of(dominator));
a61af66fc99e Initial load
duke
parents:
diff changeset
376
a61af66fc99e Initial load
duke
parents:
diff changeset
377 if (num_preds == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 assert(dominator == block->pred_at(0), "dominator must be equal to predecessor");
a61af66fc99e Initial load
duke
parents:
diff changeset
379 // nothing to do here
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381 } else if (block->is_set(BlockBegin::linear_scan_loop_header_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 // block has incoming backward branches -> try to optimize short loops
a61af66fc99e Initial load
duke
parents:
diff changeset
383 if (!short_loop_optimizer.process(block)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // loop is too complicated, so kill all memory loads because there might be
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // stores to them in the loop
a61af66fc99e Initial load
duke
parents:
diff changeset
386 current_map()->kill_memory();
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388
a61af66fc99e Initial load
duke
parents:
diff changeset
389 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 // only incoming forward branches that are already processed
a61af66fc99e Initial load
duke
parents:
diff changeset
391 for (int j = 0; j < num_preds; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 BlockBegin* pred = block->pred_at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
393 ValueMap* pred_map = value_map_of(pred);
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 if (pred_map != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // propagate killed values of the predecessor to this block
a61af66fc99e Initial load
duke
parents:
diff changeset
397 current_map()->kill_map(value_map_of(pred));
a61af66fc99e Initial load
duke
parents:
diff changeset
398 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // kill all memory loads because predecessor not yet processed
a61af66fc99e Initial load
duke
parents:
diff changeset
400 // (this can happen with non-natural loops and OSR-compiles)
a61af66fc99e Initial load
duke
parents:
diff changeset
401 current_map()->kill_memory();
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 if (block->is_set(BlockBegin::exception_entry_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 current_map()->kill_exception();
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 TRACE_VALUE_NUMBERING(tty->print("value map before processing block: "); current_map()->print());
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // visit all instructions of this block
a61af66fc99e Initial load
duke
parents:
diff changeset
413 for (Value instr = block->next(); instr != NULL; instr = instr->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 assert(!instr->has_subst(), "substitution already set");
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 // check if instruction kills any values
a61af66fc99e Initial load
duke
parents:
diff changeset
417 instr->visit(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 if (instr->hash() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 Value f = current_map()->find_insert(instr);
a61af66fc99e Initial load
duke
parents:
diff changeset
421 if (f != instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 assert(!f->has_subst(), "can't have a substitution");
a61af66fc99e Initial load
duke
parents:
diff changeset
423 instr->set_subst(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
424 subst_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 // remember value map for successors
a61af66fc99e Initial load
duke
parents:
diff changeset
430 set_value_map_of(block, current_map());
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 if (subst_count != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 SubstitutionResolver resolver(ir);
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 TRACE_VALUE_NUMBERING(tty->print("****** end of global value numbering. "); ValueMap::print_statistics());
a61af66fc99e Initial load
duke
parents:
diff changeset
438 }