blob: 67fb647ebab0a3c4b94f023eba1f7f8432d06a64 [file] [log] [blame]
buzbee2502e002012-12-31 16:05:53 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_LOCAL_VALUE_NUMBERING_H_
18#define ART_COMPILER_DEX_LOCAL_VALUE_NUMBERING_H_
buzbee2502e002012-12-31 16:05:53 -080019
Ian Rogers700a4022014-05-19 16:49:03 -070020#include <memory>
21
Mathieu Chartierb666f482015-02-18 14:33:14 -080022#include "base/arena_object.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080023#include "base/logging.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080024#include "dex_instruction_utils.h"
Vladimir Marko95a05972014-05-30 10:01:32 +010025#include "global_value_numbering.h"
buzbee2502e002012-12-31 16:05:53 -080026
buzbee2502e002012-12-31 16:05:53 -080027namespace art {
28
Vladimir Markof59f18b2014-02-17 15:53:57 +000029class DexFile;
Vladimir Marko95a05972014-05-30 10:01:32 +010030
31// Enable/disable tracking values stored in the FILLED_NEW_ARRAY result.
32static constexpr bool kLocalValueNumberingEnableFilledNewArrayTracking = true;
buzbee2502e002012-12-31 16:05:53 -080033
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070034class LocalValueNumbering : public DeletableArenaObject<kArenaAllocMisc> {
Vladimir Marko95a05972014-05-30 10:01:32 +010035 private:
36 static constexpr uint16_t kNoValue = GlobalValueNumbering::kNoValue;
37
Vladimir Marko2ac01fc2014-05-22 12:09:08 +010038 public:
Vladimir Markob19955d2014-07-29 12:04:10 +010039 LocalValueNumbering(GlobalValueNumbering* gvn, BasicBlockId id, ScopedArenaAllocator* allocator);
Vladimir Marko95a05972014-05-30 10:01:32 +010040
41 BasicBlockId Id() const {
42 return id_;
43 }
44
45 bool Equals(const LocalValueNumbering& other) const;
46
Vladimir Marko95a05972014-05-30 10:01:32 +010047 bool IsValueNullChecked(uint16_t value_name) const {
48 return null_checked_.find(value_name) != null_checked_.end();
49 }
50
Razvan A Lupusorue0951142014-11-14 14:36:55 -080051 bool IsValueDivZeroChecked(uint16_t value_name) const {
52 return div_zero_checked_.find(value_name) != div_zero_checked_.end();
53 }
54
Vladimir Marko7a01dc22015-01-02 17:00:44 +000055 uint16_t GetSregValue(uint16_t s_reg) const {
Vladimir Markoa5e69e82015-04-24 19:03:51 +010056 DCHECK(!gvn_->GetMirGraph()->GetRegLocation(s_reg).wide);
Vladimir Marko7a01dc22015-01-02 17:00:44 +000057 return GetSregValueImpl(s_reg, &sreg_value_map_);
58 }
59
60 uint16_t GetSregValueWide(uint16_t s_reg) const {
Vladimir Markoa5e69e82015-04-24 19:03:51 +010061 DCHECK(gvn_->GetMirGraph()->GetRegLocation(s_reg).wide);
Vladimir Marko7a01dc22015-01-02 17:00:44 +000062 return GetSregValueImpl(s_reg, &sreg_wide_value_map_);
63 }
64
65 // Get the starting value number for a given dalvik register.
66 uint16_t GetStartingVregValueNumber(int v_reg) const {
67 return GetStartingVregValueNumberImpl(v_reg, false);
68 }
69
70 // Get the starting value number for a given wide dalvik register.
71 uint16_t GetStartingVregValueNumberWide(int v_reg) const {
72 return GetStartingVregValueNumberImpl(v_reg, true);
Vladimir Marko95a05972014-05-30 10:01:32 +010073 }
74
75 enum MergeType {
76 kNormalMerge,
77 kCatchMerge,
78 kReturnMerge, // RETURN or PHI+RETURN. Merge only sreg maps.
79 };
80
81 void MergeOne(const LocalValueNumbering& other, MergeType merge_type);
82 void Merge(MergeType merge_type); // Merge gvn_->merge_lvns_.
Vladimir Markoa4426cf2014-10-22 17:15:53 +010083 void PrepareEntryBlock();
Vladimir Marko2ac01fc2014-05-22 12:09:08 +010084
85 uint16_t GetValueNumber(MIR* mir);
86
Vladimir Markof59f18b2014-02-17 15:53:57 +000087 private:
Vladimir Marko95a05972014-05-30 10:01:32 +010088 // A set of value names.
89 typedef GlobalValueNumbering::ValueNameSet ValueNameSet;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +010090
Vladimir Marko95a05972014-05-30 10:01:32 +010091 // Key is s_reg, value is value name.
92 typedef ScopedArenaSafeMap<uint16_t, uint16_t> SregValueMap;
Vladimir Markof59f18b2014-02-17 15:53:57 +000093
Vladimir Marko7a01dc22015-01-02 17:00:44 +000094 uint16_t GetEndingVregValueNumberImpl(int v_reg, bool wide) const;
95 uint16_t GetStartingVregValueNumberImpl(int v_reg, bool wide) const;
96
97 uint16_t GetSregValueImpl(int s_reg, const SregValueMap* map) const {
98 uint16_t res = kNoValue;
99 auto lb = map->find(s_reg);
100 if (lb != map->end()) {
101 res = lb->second;
102 } else {
103 res = gvn_->FindValue(kNoValue, s_reg, kNoValue, kNoValue);
104 }
105 return res;
106 }
107
Vladimir Marko95a05972014-05-30 10:01:32 +0100108 void SetOperandValueImpl(uint16_t s_reg, uint16_t value, SregValueMap* map) {
109 DCHECK_EQ(map->count(s_reg), 0u) << PrettyMethod(gvn_->cu_->method_idx, *gvn_->cu_->dex_file)
110 << " LVN id: " << id_ << ", s_reg: " << s_reg;
111 map->Put(s_reg, value);
112 }
113
114 uint16_t GetOperandValueImpl(int s_reg, const SregValueMap* map) const {
115 uint16_t res = kNoValue;
116 auto lb = map->find(s_reg);
117 if (lb != map->end()) {
118 res = lb->second;
119 } else {
120 // Using the original value; s_reg refers to an input reg.
121 res = gvn_->LookupValue(kNoValue, s_reg, kNoValue, kNoValue);
Vladimir Markof59f18b2014-02-17 15:53:57 +0000122 }
Vladimir Marko95a05972014-05-30 10:01:32 +0100123 return res;
124 }
125
126 void SetOperandValue(uint16_t s_reg, uint16_t value) {
Vladimir Markoa4426cf2014-10-22 17:15:53 +0100127 DCHECK_EQ(sreg_wide_value_map_.count(s_reg), 0u);
Vladimir Markoa5e69e82015-04-24 19:03:51 +0100128 DCHECK(!gvn_->GetMirGraph()->GetRegLocation(s_reg).wide);
Vladimir Marko95a05972014-05-30 10:01:32 +0100129 SetOperandValueImpl(s_reg, value, &sreg_value_map_);
Andreas Gampec8ccf682014-09-29 20:07:43 -0700130 }
Vladimir Markof59f18b2014-02-17 15:53:57 +0000131
Vladimir Marko95a05972014-05-30 10:01:32 +0100132 uint16_t GetOperandValue(int s_reg) const {
Vladimir Markoa4426cf2014-10-22 17:15:53 +0100133 DCHECK_EQ(sreg_wide_value_map_.count(s_reg), 0u);
Vladimir Markoa5e69e82015-04-24 19:03:51 +0100134 DCHECK(!gvn_->GetMirGraph()->GetRegLocation(s_reg).wide);
Vladimir Marko95a05972014-05-30 10:01:32 +0100135 return GetOperandValueImpl(s_reg, &sreg_value_map_);
Andreas Gampec8ccf682014-09-29 20:07:43 -0700136 }
Vladimir Marko95a05972014-05-30 10:01:32 +0100137
138 void SetOperandValueWide(uint16_t s_reg, uint16_t value) {
Vladimir Markoa4426cf2014-10-22 17:15:53 +0100139 DCHECK_EQ(sreg_value_map_.count(s_reg), 0u);
Vladimir Markoa5e69e82015-04-24 19:03:51 +0100140 DCHECK(gvn_->GetMirGraph()->GetRegLocation(s_reg).wide);
141 DCHECK(!gvn_->GetMirGraph()->GetRegLocation(s_reg).high_word);
Vladimir Marko95a05972014-05-30 10:01:32 +0100142 SetOperandValueImpl(s_reg, value, &sreg_wide_value_map_);
Andreas Gampec8ccf682014-09-29 20:07:43 -0700143 }
Vladimir Marko95a05972014-05-30 10:01:32 +0100144
145 uint16_t GetOperandValueWide(int s_reg) const {
Vladimir Markoa4426cf2014-10-22 17:15:53 +0100146 DCHECK_EQ(sreg_value_map_.count(s_reg), 0u);
Vladimir Markoa5e69e82015-04-24 19:03:51 +0100147 DCHECK(gvn_->GetMirGraph()->GetRegLocation(s_reg).wide);
148 DCHECK(!gvn_->GetMirGraph()->GetRegLocation(s_reg).high_word);
Vladimir Marko95a05972014-05-30 10:01:32 +0100149 return GetOperandValueImpl(s_reg, &sreg_wide_value_map_);
Andreas Gampec8ccf682014-09-29 20:07:43 -0700150 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100151
152 struct RangeCheckKey {
153 uint16_t array;
154 uint16_t index;
Vladimir Marko95a05972014-05-30 10:01:32 +0100155
156 // NOTE: Can't define this at namespace scope for a private struct.
157 bool operator==(const RangeCheckKey& other) const {
158 return array == other.array && index == other.index;
159 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100160 };
161
162 struct RangeCheckKeyComparator {
163 bool operator()(const RangeCheckKey& lhs, const RangeCheckKey& rhs) const {
164 if (lhs.array != rhs.array) {
165 return lhs.array < rhs.array;
166 }
167 return lhs.index < rhs.index;
168 }
169 };
170
171 typedef ScopedArenaSet<RangeCheckKey, RangeCheckKeyComparator> RangeCheckSet;
172
Vladimir Marko95a05972014-05-30 10:01:32 +0100173 // Maps instance field "location" (derived from base, field_id and type) to value name.
174 typedef ScopedArenaSafeMap<uint16_t, uint16_t> IFieldLocToValueMap;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100175
Vladimir Marko95a05972014-05-30 10:01:32 +0100176 // Maps static field id to value name
177 typedef ScopedArenaSafeMap<uint16_t, uint16_t> SFieldToValueMap;
178
179 struct EscapedIFieldClobberKey {
180 uint16_t base; // Or array.
Vladimir Markof59f18b2014-02-17 15:53:57 +0000181 uint16_t type;
Vladimir Marko95a05972014-05-30 10:01:32 +0100182 uint16_t field_id; // None (kNoValue) for arrays and unresolved instance field stores.
183
184 // NOTE: Can't define this at namespace scope for a private struct.
185 bool operator==(const EscapedIFieldClobberKey& other) const {
186 return base == other.base && type == other.type && field_id == other.field_id;
187 }
Vladimir Markof59f18b2014-02-17 15:53:57 +0000188 };
189
Vladimir Marko95a05972014-05-30 10:01:32 +0100190 struct EscapedIFieldClobberKeyComparator {
191 bool operator()(const EscapedIFieldClobberKey& lhs, const EscapedIFieldClobberKey& rhs) const {
192 // Compare base first. This makes sequential iteration respect the order of base.
193 if (lhs.base != rhs.base) {
194 return lhs.base < rhs.base;
195 }
196 // Compare type second. This makes the type-clobber entries (field_id == kNoValue) last
197 // for given base and type and makes it easy to prune unnecessary entries when merging
198 // escaped_ifield_clobber_set_ from multiple LVNs.
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100199 if (lhs.type != rhs.type) {
200 return lhs.type < rhs.type;
Vladimir Markof59f18b2014-02-17 15:53:57 +0000201 }
Vladimir Marko95a05972014-05-30 10:01:32 +0100202 return lhs.field_id < rhs.field_id;
Vladimir Markof59f18b2014-02-17 15:53:57 +0000203 }
204 };
205
Vladimir Marko95a05972014-05-30 10:01:32 +0100206 typedef ScopedArenaSet<EscapedIFieldClobberKey, EscapedIFieldClobberKeyComparator>
207 EscapedIFieldClobberSet;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100208
Vladimir Marko95a05972014-05-30 10:01:32 +0100209 struct EscapedArrayClobberKey {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100210 uint16_t base;
211 uint16_t type;
Vladimir Marko95a05972014-05-30 10:01:32 +0100212
213 // NOTE: Can't define this at namespace scope for a private struct.
214 bool operator==(const EscapedArrayClobberKey& other) const {
215 return base == other.base && type == other.type;
216 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100217 };
218
Vladimir Marko95a05972014-05-30 10:01:32 +0100219 struct EscapedArrayClobberKeyComparator {
220 bool operator()(const EscapedArrayClobberKey& lhs, const EscapedArrayClobberKey& rhs) const {
221 // Compare base first. This makes sequential iteration respect the order of base.
222 if (lhs.base != rhs.base) {
223 return lhs.base < rhs.base;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100224 }
Vladimir Marko95a05972014-05-30 10:01:32 +0100225 return lhs.type < rhs.type;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100226 }
227 };
228
Vladimir Marko95a05972014-05-30 10:01:32 +0100229 // Clobber set for previously non-aliasing array refs that escaped.
230 typedef ScopedArenaSet<EscapedArrayClobberKey, EscapedArrayClobberKeyComparator>
231 EscapedArrayClobberSet;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100232
Vladimir Marko95a05972014-05-30 10:01:32 +0100233 // Known location values for an aliasing set. The set can be tied to one of:
234 // 1. Instance field. The locations are aliasing references used to access the field.
235 // 2. Non-aliasing array reference. The locations are indexes to the array.
236 // 3. Aliasing array type. The locations are (reference, index) pair ids assigned by GVN.
237 // In each case we keep track of the last stored value, if any, and the set of locations
238 // where it was stored. We also keep track of all values known for the current write state
239 // (load_value_map), which can be known either because they have been loaded since the last
240 // store or because they contained the last_stored_value before the store and thus could not
241 // have changed as a result.
242 struct AliasingValues {
Vladimir Markob19955d2014-07-29 12:04:10 +0100243 explicit AliasingValues(LocalValueNumbering* lvn)
Vladimir Marko95a05972014-05-30 10:01:32 +0100244 : memory_version_before_stores(kNoValue),
245 last_stored_value(kNoValue),
Vladimir Markob19955d2014-07-29 12:04:10 +0100246 store_loc_set(std::less<uint16_t>(), lvn->null_checked_.get_allocator()),
Vladimir Marko95a05972014-05-30 10:01:32 +0100247 last_load_memory_version(kNoValue),
Vladimir Markob19955d2014-07-29 12:04:10 +0100248 load_value_map(std::less<uint16_t>(), lvn->null_checked_.get_allocator()) {
buzbee2502e002012-12-31 16:05:53 -0800249 }
buzbee2502e002012-12-31 16:05:53 -0800250
Vladimir Marko95a05972014-05-30 10:01:32 +0100251 uint16_t memory_version_before_stores; // kNoValue if start version for the field.
252 uint16_t last_stored_value; // Last stored value name, kNoValue if none.
253 ValueNameSet store_loc_set; // Where was last_stored_value stored.
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100254
Vladimir Marko95a05972014-05-30 10:01:32 +0100255 // Maps refs (other than stored_to) to currently known values for this field other. On write,
256 // anything that differs from the written value is removed as it may be overwritten.
257 uint16_t last_load_memory_version; // kNoValue if not known.
258 ScopedArenaSafeMap<uint16_t, uint16_t> load_value_map;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100259
Vladimir Marko95a05972014-05-30 10:01:32 +0100260 // NOTE: Can't define this at namespace scope for a private struct.
261 bool operator==(const AliasingValues& other) const {
262 return memory_version_before_stores == other.memory_version_before_stores &&
263 last_load_memory_version == other.last_load_memory_version &&
264 last_stored_value == other.last_stored_value &&
265 store_loc_set == other.store_loc_set &&
266 load_value_map == other.load_value_map;
buzbee2502e002012-12-31 16:05:53 -0800267 }
268 };
269
Vladimir Marko95a05972014-05-30 10:01:32 +0100270 // Maps instance field id to AliasingValues, locations are object refs.
271 typedef ScopedArenaSafeMap<uint16_t, AliasingValues> AliasingIFieldValuesMap;
buzbee2502e002012-12-31 16:05:53 -0800272
Vladimir Marko95a05972014-05-30 10:01:32 +0100273 // Maps non-aliasing array reference to AliasingValues, locations are array indexes.
274 typedef ScopedArenaSafeMap<uint16_t, AliasingValues> NonAliasingArrayValuesMap;
buzbee2502e002012-12-31 16:05:53 -0800275
Vladimir Marko95a05972014-05-30 10:01:32 +0100276 // Maps aliasing array type to AliasingValues, locations are (array, index) pair ids.
277 typedef ScopedArenaSafeMap<uint16_t, AliasingValues> AliasingArrayValuesMap;
buzbee2502e002012-12-31 16:05:53 -0800278
Vladimir Marko95a05972014-05-30 10:01:32 +0100279 // Helper classes defining versions for updating and merging the AliasingValues maps above.
280 class AliasingIFieldVersions;
281 class NonAliasingArrayVersions;
282 class AliasingArrayVersions;
283
284 template <typename Map>
285 AliasingValues* GetAliasingValues(Map* map, const typename Map::key_type& key);
286
287 template <typename Versions, typename KeyType>
288 void UpdateAliasingValuesLoadVersion(const KeyType& key, AliasingValues* values);
289
290 template <typename Versions, typename Map>
291 static uint16_t AliasingValuesMergeGet(GlobalValueNumbering* gvn,
292 const LocalValueNumbering* lvn,
293 Map* map, const typename Map::key_type& key,
294 uint16_t location);
295
296 template <typename Versions, typename Map>
297 uint16_t HandleAliasingValuesGet(Map* map, const typename Map::key_type& key,
298 uint16_t location);
299
300 template <typename Versions, typename Map>
301 bool HandleAliasingValuesPut(Map* map, const typename Map::key_type& key,
302 uint16_t location, uint16_t value);
303
Vladimir Markob19955d2014-07-29 12:04:10 +0100304 template <typename K>
305 void CopyAliasingValuesMap(ScopedArenaSafeMap<K, AliasingValues>* dest,
306 const ScopedArenaSafeMap<K, AliasingValues>& src);
307
Vladimir Markof59f18b2014-02-17 15:53:57 +0000308 uint16_t MarkNonAliasingNonNull(MIR* mir);
Vladimir Marko95a05972014-05-30 10:01:32 +0100309 bool IsNonAliasing(uint16_t reg) const;
310 bool IsNonAliasingIField(uint16_t reg, uint16_t field_id, uint16_t type) const;
311 bool IsNonAliasingArray(uint16_t reg, uint16_t type) const;
Vladimir Markof59f18b2014-02-17 15:53:57 +0000312 void HandleNullCheck(MIR* mir, uint16_t reg);
313 void HandleRangeCheck(MIR* mir, uint16_t array, uint16_t index);
Razvan A Lupusorue0951142014-11-14 14:36:55 -0800314 void HandleDivZeroCheck(MIR* mir, uint16_t reg);
Vladimir Markof59f18b2014-02-17 15:53:57 +0000315 void HandlePutObject(MIR* mir);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100316 void HandleEscapingRef(uint16_t base);
Vladimir Markoa4426cf2014-10-22 17:15:53 +0100317 void HandleInvokeArgs(const MIR* mir, const LocalValueNumbering* mir_lvn);
Vladimir Marko95a05972014-05-30 10:01:32 +0100318 uint16_t HandlePhi(MIR* mir);
Vladimir Marko22c7f5b2015-02-18 17:52:39 +0000319 uint16_t HandleConst(MIR* mir, uint32_t value);
320 uint16_t HandleConstWide(MIR* mir, uint64_t value);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100321 uint16_t HandleAGet(MIR* mir, uint16_t opcode);
322 void HandleAPut(MIR* mir, uint16_t opcode);
323 uint16_t HandleIGet(MIR* mir, uint16_t opcode);
324 void HandleIPut(MIR* mir, uint16_t opcode);
325 uint16_t HandleSGet(MIR* mir, uint16_t opcode);
326 void HandleSPut(MIR* mir, uint16_t opcode);
Vladimir Marko95a05972014-05-30 10:01:32 +0100327 void RemoveSFieldsForType(uint16_t type);
Vladimir Markofa236452014-09-29 17:58:10 +0100328 void HandleInvokeOrClInitOrAcquireOp(MIR* mir);
Vladimir Markof59f18b2014-02-17 15:53:57 +0000329
Vladimir Marko95a05972014-05-30 10:01:32 +0100330 bool SameMemoryVersion(const LocalValueNumbering& other) const;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100331
Vladimir Marko95a05972014-05-30 10:01:32 +0100332 uint16_t NewMemoryVersion(uint16_t* new_version);
333 void MergeMemoryVersions(bool clobbered_catch);
334
335 void PruneNonAliasingRefsForCatch();
336
337 template <typename Set, Set LocalValueNumbering::* set_ptr>
338 void IntersectSets();
339
Vladimir Markob19955d2014-07-29 12:04:10 +0100340 void CopyLiveSregValues(SregValueMap* dest, const SregValueMap& src);
341
Vladimir Markoa5e69e82015-04-24 19:03:51 +0100342 // Intersect SSA reg value maps as sets, ignore dead regs.
Vladimir Markob19955d2014-07-29 12:04:10 +0100343 template <SregValueMap LocalValueNumbering::* map_ptr>
344 void IntersectSregValueMaps();
Vladimir Marko95a05972014-05-30 10:01:32 +0100345
346 // Intersect maps as sets. The value type must be equality-comparable.
347 template <typename Map>
348 static void InPlaceIntersectMaps(Map* work_map, const Map& other_map);
349
350 template <typename Set, Set LocalValueNumbering::*set_ptr, void (LocalValueNumbering::*MergeFn)(
351 const typename Set::value_type& entry, typename Set::iterator hint)>
352 void MergeSets();
353
354 void IntersectAliasingValueLocations(AliasingValues* work_values, const AliasingValues* values);
355
356 void MergeEscapedRefs(const ValueNameSet::value_type& entry, ValueNameSet::iterator hint);
357 void MergeEscapedIFieldTypeClobberSets(const EscapedIFieldClobberSet::value_type& entry,
358 EscapedIFieldClobberSet::iterator hint);
359 void MergeEscapedIFieldClobberSets(const EscapedIFieldClobberSet::value_type& entry,
360 EscapedIFieldClobberSet::iterator hint);
361 void MergeEscapedArrayClobberSets(const EscapedArrayClobberSet::value_type& entry,
362 EscapedArrayClobberSet::iterator hint);
Vladimir Marko95a05972014-05-30 10:01:32 +0100363 void MergeSFieldValues(const SFieldToValueMap::value_type& entry,
364 SFieldToValueMap::iterator hint);
365 void MergeNonAliasingIFieldValues(const IFieldLocToValueMap::value_type& entry,
366 IFieldLocToValueMap::iterator hint);
Vladimir Marko2d2365c2014-08-19 18:08:39 +0100367 void MergeNullChecked();
Razvan A Lupusorue0951142014-11-14 14:36:55 -0800368 void MergeDivZeroChecked();
Vladimir Marko95a05972014-05-30 10:01:32 +0100369
370 template <typename Map, Map LocalValueNumbering::*map_ptr, typename Versions>
371 void MergeAliasingValues(const typename Map::value_type& entry, typename Map::iterator hint);
372
373 GlobalValueNumbering* gvn_;
374
375 // We're using the block id as a 16-bit operand value for some lookups.
Andreas Gampe785d2f22014-11-03 22:57:30 -0800376 static_assert(sizeof(BasicBlockId) == sizeof(uint16_t), "BasicBlockId must be 16 bit");
Vladimir Marko95a05972014-05-30 10:01:32 +0100377 BasicBlockId id_;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100378
buzbee2502e002012-12-31 16:05:53 -0800379 SregValueMap sreg_value_map_;
380 SregValueMap sreg_wide_value_map_;
Vladimir Marko95a05972014-05-30 10:01:32 +0100381
382 SFieldToValueMap sfield_value_map_;
383 IFieldLocToValueMap non_aliasing_ifield_value_map_;
384 AliasingIFieldValuesMap aliasing_ifield_value_map_;
385 NonAliasingArrayValuesMap non_aliasing_array_value_map_;
386 AliasingArrayValuesMap aliasing_array_value_map_;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100387
388 // Data for dealing with memory clobbering and store/load aliasing.
Vladimir Markof59f18b2014-02-17 15:53:57 +0000389 uint16_t global_memory_version_;
Vladimir Marko321b9872014-11-24 16:33:51 +0000390 uint16_t unresolved_sfield_version_[kDexMemAccessTypeCount];
391 uint16_t unresolved_ifield_version_[kDexMemAccessTypeCount];
Vladimir Markof59f18b2014-02-17 15:53:57 +0000392 // Value names of references to objects that cannot be reached through a different value name.
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000393 ValueNameSet non_aliasing_refs_;
Vladimir Marko95a05972014-05-30 10:01:32 +0100394 // Previously non-aliasing refs that escaped but can still be used for non-aliasing AGET/IGET.
395 ValueNameSet escaped_refs_;
396 // Blacklists for cases where escaped_refs_ can't be used.
397 EscapedIFieldClobberSet escaped_ifield_clobber_set_;
398 EscapedArrayClobberSet escaped_array_clobber_set_;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100399
400 // Range check and null check elimination.
401 RangeCheckSet range_checked_;
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000402 ValueNameSet null_checked_;
Razvan A Lupusorue0951142014-11-14 14:36:55 -0800403 ValueNameSet div_zero_checked_;
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000404
Vladimir Marko95a05972014-05-30 10:01:32 +0100405 // Reuse one vector for all merges to avoid leaking too much memory on the ArenaStack.
Vladimir Marko7a01dc22015-01-02 17:00:44 +0000406 mutable ScopedArenaVector<uint16_t> merge_names_;
Vladimir Marko95a05972014-05-30 10:01:32 +0100407 // Map to identify when different locations merge the same values.
Vladimir Marko7a01dc22015-01-02 17:00:44 +0000408 ScopedArenaSafeMap<ScopedArenaVector<uint16_t>, uint16_t> merge_map_;
Vladimir Marko95a05972014-05-30 10:01:32 +0100409 // New memory version for merge, kNoValue if all memory versions matched.
410 uint16_t merge_new_memory_version_;
411
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000412 DISALLOW_COPY_AND_ASSIGN(LocalValueNumbering);
buzbee2502e002012-12-31 16:05:53 -0800413};
414
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700415} // namespace art
buzbee2502e002012-12-31 16:05:53 -0800416
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700417#endif // ART_COMPILER_DEX_LOCAL_VALUE_NUMBERING_H_