blob: d5fd6feecfc750e1d314abd3afd80d0659cddc7e [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
buzbee311ca162013-02-28 15:56:43 -080017#include "local_value_numbering.h"
buzbee2502e002012-12-31 16:05:53 -080018
Vladimir Marko95a05972014-05-30 10:01:32 +010019#include "global_value_numbering.h"
Vladimir Markobe0e5462014-02-26 11:24:15 +000020#include "mir_field_info.h"
Vladimir Markof59f18b2014-02-17 15:53:57 +000021#include "mir_graph.h"
22
buzbee2502e002012-12-31 16:05:53 -080023namespace art {
24
Vladimir Marko2ac01fc2014-05-22 12:09:08 +010025namespace { // anonymous namespace
26
27// Operations used for value map keys instead of actual opcode.
Vladimir Marko95a05972014-05-30 10:01:32 +010028static constexpr uint16_t kInvokeMemoryVersionBumpOp = Instruction::INVOKE_VIRTUAL;
29static constexpr uint16_t kUnresolvedSFieldOp = Instruction::SGET;
30static constexpr uint16_t kResolvedSFieldOp = Instruction::SGET_WIDE;
31static constexpr uint16_t kUnresolvedIFieldOp = Instruction::IGET;
32static constexpr uint16_t kNonAliasingIFieldLocOp = Instruction::IGET_WIDE;
33static constexpr uint16_t kNonAliasingIFieldInitialOp = Instruction::IGET_OBJECT;
34static constexpr uint16_t kAliasingIFieldOp = Instruction::IGET_BOOLEAN;
35static constexpr uint16_t kAliasingIFieldStartVersionOp = Instruction::IGET_BYTE;
36static constexpr uint16_t kAliasingIFieldBumpVersionOp = Instruction::IGET_CHAR;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +010037static constexpr uint16_t kNonAliasingArrayOp = Instruction::AGET;
38static constexpr uint16_t kNonAliasingArrayStartVersionOp = Instruction::AGET_WIDE;
Vladimir Marko95a05972014-05-30 10:01:32 +010039static constexpr uint16_t kNonAliasingArrayBumpVersionOp = Instruction::AGET_OBJECT;
40static constexpr uint16_t kAliasingArrayOp = Instruction::AGET_BOOLEAN;
41static constexpr uint16_t kAliasingArrayStartVersionOp = Instruction::AGET_BYTE;
42static constexpr uint16_t kAliasingArrayBumpVersionOp = Instruction::AGET_CHAR;
43static constexpr uint16_t kMergeBlockMemoryVersionBumpOp = Instruction::INVOKE_VIRTUAL_RANGE;
44static constexpr uint16_t kMergeBlockAliasingIFieldVersionBumpOp = Instruction::IPUT;
45static constexpr uint16_t kMergeBlockAliasingIFieldMergeLocationOp = Instruction::IPUT_WIDE;
46static constexpr uint16_t kMergeBlockNonAliasingArrayVersionBumpOp = Instruction::APUT;
47static constexpr uint16_t kMergeBlockNonAliasingArrayMergeLocationOp = Instruction::APUT_WIDE;
48static constexpr uint16_t kMergeBlockAliasingArrayVersionBumpOp = Instruction::APUT_OBJECT;
49static constexpr uint16_t kMergeBlockAliasingArrayMergeLocationOp = Instruction::APUT_BOOLEAN;
50static constexpr uint16_t kMergeBlockNonAliasingIFieldVersionBumpOp = Instruction::APUT_BYTE;
51static constexpr uint16_t kMergeBlockSFieldVersionBumpOp = Instruction::APUT_CHAR;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +010052
53} // anonymous namespace
54
Vladimir Marko95a05972014-05-30 10:01:32 +010055class LocalValueNumbering::AliasingIFieldVersions {
56 public:
57 static uint16_t StartMemoryVersion(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
58 uint16_t field_id) {
59 uint16_t type = gvn->GetFieldType(field_id);
60 return gvn->LookupValue(kAliasingIFieldStartVersionOp, field_id,
61 lvn->global_memory_version_, lvn->unresolved_ifield_version_[type]);
62 }
63
64 static uint16_t BumpMemoryVersion(GlobalValueNumbering* gvn, uint16_t old_version,
65 uint16_t store_ref_set_id, uint16_t stored_value) {
66 return gvn->LookupValue(kAliasingIFieldBumpVersionOp, old_version,
67 store_ref_set_id, stored_value);
68 }
69
70 static uint16_t LookupGlobalValue(GlobalValueNumbering* gvn,
71 uint16_t field_id, uint16_t base, uint16_t memory_version) {
72 return gvn->LookupValue(kAliasingIFieldOp, field_id, base, memory_version);
73 }
74
75 static uint16_t LookupMergeValue(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
76 uint16_t field_id, uint16_t base) {
77 // If the base/field_id is non-aliasing in lvn, use the non-aliasing value.
78 uint16_t type = gvn->GetFieldType(field_id);
79 if (lvn->IsNonAliasingIField(base, field_id, type)) {
80 uint16_t loc = gvn->LookupValue(kNonAliasingIFieldLocOp, base, field_id, type);
81 auto lb = lvn->non_aliasing_ifield_value_map_.find(loc);
82 return (lb != lvn->non_aliasing_ifield_value_map_.end())
83 ? lb->second
84 : gvn->LookupValue(kNonAliasingIFieldInitialOp, loc, kNoValue, kNoValue);
85 }
86 return AliasingValuesMergeGet<AliasingIFieldVersions>(
87 gvn, lvn, &lvn->aliasing_ifield_value_map_, field_id, base);
88 }
89
90 static bool HasNewBaseVersion(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
91 uint16_t field_id) {
92 uint16_t type = gvn->GetFieldType(field_id);
93 return lvn->unresolved_ifield_version_[type] == lvn->merge_new_memory_version_ ||
94 lvn->global_memory_version_ == lvn->merge_new_memory_version_;
95 }
96
97 static uint16_t LookupMergeBlockValue(GlobalValueNumbering* gvn, uint16_t lvn_id,
98 uint16_t field_id) {
99 return gvn->LookupValue(kMergeBlockAliasingIFieldVersionBumpOp, field_id, kNoValue, lvn_id);
100 }
101
102 static uint16_t LookupMergeLocationValue(GlobalValueNumbering* gvn, uint16_t lvn_id,
103 uint16_t field_id, uint16_t base) {
104 return gvn->LookupValue(kMergeBlockAliasingIFieldMergeLocationOp, field_id, base, lvn_id);
105 }
106};
107
108class LocalValueNumbering::NonAliasingArrayVersions {
109 public:
110 static uint16_t StartMemoryVersion(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
111 uint16_t array) {
112 return gvn->LookupValue(kNonAliasingArrayStartVersionOp, array, kNoValue, kNoValue);
113 }
114
115 static uint16_t BumpMemoryVersion(GlobalValueNumbering* gvn, uint16_t old_version,
116 uint16_t store_ref_set_id, uint16_t stored_value) {
117 return gvn->LookupValue(kNonAliasingArrayBumpVersionOp, old_version,
118 store_ref_set_id, stored_value);
119 }
120
121 static uint16_t LookupGlobalValue(GlobalValueNumbering* gvn,
122 uint16_t array, uint16_t index, uint16_t memory_version) {
123 return gvn->LookupValue(kNonAliasingArrayOp, array, index, memory_version);
124 }
125
126 static uint16_t LookupMergeValue(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
127 uint16_t array, uint16_t index) {
128 return AliasingValuesMergeGet<NonAliasingArrayVersions>(
129 gvn, lvn, &lvn->non_aliasing_array_value_map_, array, index);
130 }
131
132 static bool HasNewBaseVersion(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
133 uint16_t array) {
134 return false; // Not affected by global_memory_version_.
135 }
136
137 static uint16_t LookupMergeBlockValue(GlobalValueNumbering* gvn, uint16_t lvn_id,
138 uint16_t array) {
139 return gvn->LookupValue(kMergeBlockNonAliasingArrayVersionBumpOp, array, kNoValue, lvn_id);
140 }
141
142 static uint16_t LookupMergeLocationValue(GlobalValueNumbering* gvn, uint16_t lvn_id,
143 uint16_t array, uint16_t index) {
144 return gvn->LookupValue(kMergeBlockNonAliasingArrayMergeLocationOp, array, index, lvn_id);
145 }
146};
147
148class LocalValueNumbering::AliasingArrayVersions {
149 public:
150 static uint16_t StartMemoryVersion(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
151 uint16_t type) {
152 return gvn->LookupValue(kAliasingArrayStartVersionOp, type, lvn->global_memory_version_,
153 kNoValue);
154 }
155
156 static uint16_t BumpMemoryVersion(GlobalValueNumbering* gvn, uint16_t old_version,
157 uint16_t store_ref_set_id, uint16_t stored_value) {
158 return gvn->LookupValue(kAliasingArrayBumpVersionOp, old_version,
159 store_ref_set_id, stored_value);
160 }
161
162 static uint16_t LookupGlobalValue(GlobalValueNumbering* gvn,
163 uint16_t type, uint16_t location, uint16_t memory_version) {
164 return gvn->LookupValue(kAliasingArrayOp, type, location, memory_version);
165 }
166
167 static uint16_t LookupMergeValue(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
168 uint16_t type, uint16_t location) {
169 // If the location is non-aliasing in lvn, use the non-aliasing value.
170 uint16_t array = gvn->GetArrayLocationBase(location);
171 if (lvn->IsNonAliasingArray(array, type)) {
172 uint16_t index = gvn->GetArrayLocationIndex(location);
173 return NonAliasingArrayVersions::LookupMergeValue(gvn, lvn, array, index);
174 }
175 return AliasingValuesMergeGet<AliasingArrayVersions>(
176 gvn, lvn, &lvn->aliasing_array_value_map_, type, location);
177 }
178
179 static bool HasNewBaseVersion(GlobalValueNumbering* gvn, const LocalValueNumbering* lvn,
180 uint16_t type) {
181 return lvn->global_memory_version_ == lvn->merge_new_memory_version_;
182 }
183
184 static uint16_t LookupMergeBlockValue(GlobalValueNumbering* gvn, uint16_t lvn_id,
185 uint16_t type) {
186 return gvn->LookupValue(kMergeBlockAliasingArrayVersionBumpOp, type, kNoValue, lvn_id);
187 }
188
189 static uint16_t LookupMergeLocationValue(GlobalValueNumbering* gvn, uint16_t lvn_id,
190 uint16_t type, uint16_t location) {
191 return gvn->LookupValue(kMergeBlockAliasingArrayMergeLocationOp, type, location, lvn_id);
192 }
193};
194
195template <typename Map>
196LocalValueNumbering::AliasingValues* LocalValueNumbering::GetAliasingValues(
197 Map* map, const typename Map::key_type& key) {
198 auto lb = map->lower_bound(key);
199 if (lb == map->end() || map->key_comp()(key, lb->first)) {
200 map->PutBefore(lb, key, AliasingValues(gvn_->allocator_));
201 // The new entry was inserted before lb.
202 DCHECK(lb != map->begin());
203 --lb;
204 DCHECK(!map->key_comp()(lb->first, key) && !map->key_comp()(key, lb->first));
205 }
206 return &lb->second;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100207}
208
Vladimir Marko95a05972014-05-30 10:01:32 +0100209template <typename Versions, typename KeyType>
210void LocalValueNumbering::UpdateAliasingValuesLoadVersion(const KeyType& key,
211 AliasingValues* values) {
212 if (values->last_load_memory_version == kNoValue) {
213 // Get the start version that accounts for aliasing with unresolved fields of the same
214 // type and make it unique for the field by including the field_id.
215 uint16_t memory_version = values->memory_version_before_stores;
216 if (memory_version == kNoValue) {
217 memory_version = Versions::StartMemoryVersion(gvn_, this, key);
218 }
219 if (!values->store_loc_set.empty()) {
220 uint16_t ref_set_id = gvn_->GetRefSetId(values->store_loc_set);
221 memory_version = Versions::BumpMemoryVersion(gvn_, memory_version, ref_set_id,
222 values->last_stored_value);
223 }
224 values->last_load_memory_version = memory_version;
Vladimir Markof59f18b2014-02-17 15:53:57 +0000225 }
Vladimir Marko95a05972014-05-30 10:01:32 +0100226}
227
228template <typename Versions, typename Map>
229uint16_t LocalValueNumbering::AliasingValuesMergeGet(GlobalValueNumbering* gvn,
230 const LocalValueNumbering* lvn,
231 Map* map, const typename Map::key_type& key,
232 uint16_t location) {
233 // Retrieve the value name that we would get from
234 // const_cast<LocalValueNumbering*>(lvn)->HandleAliasingValueGet(map. key, location)
235 // but don't modify the map.
236 uint16_t value_name;
237 auto it = map->find(key);
238 if (it == map->end()) {
239 uint16_t start_version = Versions::StartMemoryVersion(gvn, lvn, key);
240 value_name = Versions::LookupGlobalValue(gvn, key, location, start_version);
241 } else if (it->second.store_loc_set.count(location) != 0u) {
242 value_name = it->second.last_stored_value;
243 } else {
244 auto load_it = it->second.load_value_map.find(location);
245 if (load_it != it->second.load_value_map.end()) {
246 value_name = load_it->second;
247 } else {
248 value_name = Versions::LookupGlobalValue(gvn, key, location, it->second.last_load_memory_version);
249 }
250 }
251 return value_name;
252}
253
254template <typename Versions, typename Map>
255uint16_t LocalValueNumbering::HandleAliasingValuesGet(Map* map, const typename Map::key_type& key,
256 uint16_t location) {
257 // Retrieve the value name for IGET/SGET/AGET, update the map with new value if any.
258 uint16_t res;
259 AliasingValues* values = GetAliasingValues(map, key);
260 if (values->store_loc_set.count(location) != 0u) {
261 res = values->last_stored_value;
262 } else {
263 UpdateAliasingValuesLoadVersion<Versions>(key, values);
264 auto lb = values->load_value_map.lower_bound(location);
265 if (lb != values->load_value_map.end() && lb->first == location) {
266 res = lb->second;
267 } else {
268 res = Versions::LookupGlobalValue(gvn_, key, location, values->last_load_memory_version);
269 values->load_value_map.PutBefore(lb, location, res);
270 }
271 }
272 return res;
273}
274
275template <typename Versions, typename Map>
276bool LocalValueNumbering::HandleAliasingValuesPut(Map* map, const typename Map::key_type& key,
277 uint16_t location, uint16_t value) {
278 AliasingValues* values = GetAliasingValues(map, key);
279 auto load_values_it = values->load_value_map.find(location);
280 if (load_values_it != values->load_value_map.end() && load_values_it->second == value) {
281 // This insn can be eliminated, it stores the same value that's already in the field.
282 return false;
283 }
284 if (value == values->last_stored_value) {
285 auto store_loc_lb = values->store_loc_set.lower_bound(location);
286 if (store_loc_lb != values->store_loc_set.end() && *store_loc_lb == location) {
287 // This insn can be eliminated, it stores the same value that's already in the field.
288 return false;
289 }
290 values->store_loc_set.emplace_hint(store_loc_lb, location);
291 } else {
292 UpdateAliasingValuesLoadVersion<Versions>(key, values);
293 values->memory_version_before_stores = values->last_load_memory_version;
294 values->last_stored_value = value;
295 values->store_loc_set.clear();
296 values->store_loc_set.insert(location);
297 }
298 // Clear the last load memory version and remove all potentially overwritten values.
299 values->last_load_memory_version = kNoValue;
300 auto it = values->load_value_map.begin(), end = values->load_value_map.end();
301 while (it != end) {
302 if (it->second == value) {
303 ++it;
304 } else {
305 it = values->load_value_map.erase(it);
306 }
307 }
308 return true;
309}
310
311LocalValueNumbering::LocalValueNumbering(GlobalValueNumbering* gvn, uint16_t id)
312 : gvn_(gvn),
313 id_(id),
314 sreg_value_map_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
315 sreg_wide_value_map_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
316 sfield_value_map_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
317 non_aliasing_ifield_value_map_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
318 aliasing_ifield_value_map_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
319 non_aliasing_array_value_map_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
320 aliasing_array_value_map_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
321 global_memory_version_(0u),
322 non_aliasing_refs_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
323 escaped_refs_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
324 escaped_ifield_clobber_set_(EscapedIFieldClobberKeyComparator(), gvn->Allocator()->Adapter()),
325 escaped_array_clobber_set_(EscapedArrayClobberKeyComparator(), gvn->Allocator()->Adapter()),
326 range_checked_(RangeCheckKeyComparator() , gvn->Allocator()->Adapter()),
327 null_checked_(std::less<uint16_t>(), gvn->Allocator()->Adapter()),
328 merge_names_(gvn->Allocator()->Adapter()),
329 merge_map_(std::less<ScopedArenaVector<BasicBlockId>>(), gvn->Allocator()->Adapter()),
330 merge_new_memory_version_(kNoValue) {
331 std::fill_n(unresolved_sfield_version_, kFieldTypeCount, 0u);
332 std::fill_n(unresolved_ifield_version_, kFieldTypeCount, 0u);
333}
334
335bool LocalValueNumbering::Equals(const LocalValueNumbering& other) const {
336 DCHECK(gvn_ == other.gvn_);
337 // Compare the maps/sets and memory versions.
338 return sreg_value_map_ == other.sreg_value_map_ &&
339 sreg_wide_value_map_ == other.sreg_wide_value_map_ &&
340 sfield_value_map_ == other.sfield_value_map_ &&
341 non_aliasing_ifield_value_map_ == other.non_aliasing_ifield_value_map_ &&
342 aliasing_ifield_value_map_ == other.aliasing_ifield_value_map_ &&
343 non_aliasing_array_value_map_ == other.non_aliasing_array_value_map_ &&
344 aliasing_array_value_map_ == other.aliasing_array_value_map_ &&
345 SameMemoryVersion(other) &&
346 non_aliasing_refs_ == other.non_aliasing_refs_ &&
347 escaped_refs_ == other.escaped_refs_ &&
348 escaped_ifield_clobber_set_ == other.escaped_ifield_clobber_set_ &&
349 escaped_array_clobber_set_ == other.escaped_array_clobber_set_ &&
350 range_checked_ == other.range_checked_ &&
351 null_checked_ == other.null_checked_;
352}
353
354void LocalValueNumbering::MergeOne(const LocalValueNumbering& other, MergeType merge_type) {
355 sreg_value_map_ = other.sreg_value_map_;
356 sreg_wide_value_map_ = other.sreg_wide_value_map_;
357
358 if (merge_type == kReturnMerge) {
359 // RETURN or PHI+RETURN. We need only sreg value maps.
360 return;
361 }
362
363 non_aliasing_ifield_value_map_ = other.non_aliasing_ifield_value_map_;
364 non_aliasing_array_value_map_ = other.non_aliasing_array_value_map_;
365 non_aliasing_refs_ = other.non_aliasing_refs_;
366 range_checked_ = other.range_checked_;
367 null_checked_ = other.null_checked_;
368
369 if (merge_type == kCatchMerge) {
370 // Memory is clobbered. Use new memory version and don't merge aliasing locations.
371 global_memory_version_ = NewMemoryVersion(&merge_new_memory_version_);
372 std::fill_n(unresolved_sfield_version_, kFieldTypeCount, global_memory_version_);
373 std::fill_n(unresolved_ifield_version_, kFieldTypeCount, global_memory_version_);
374 PruneNonAliasingRefsForCatch();
375 return;
376 }
377
378 DCHECK(merge_type == kNormalMerge);
379 global_memory_version_ = other.global_memory_version_;
380 std::copy_n(other.unresolved_ifield_version_, kFieldTypeCount, unresolved_ifield_version_);
381 std::copy_n(other.unresolved_sfield_version_, kFieldTypeCount, unresolved_sfield_version_);
382 sfield_value_map_ = other.sfield_value_map_;
383 aliasing_ifield_value_map_ = other.aliasing_ifield_value_map_;
384 aliasing_array_value_map_ = other.aliasing_array_value_map_;
385 escaped_refs_ = other.escaped_refs_;
386 escaped_ifield_clobber_set_ = other.escaped_ifield_clobber_set_;
387 escaped_array_clobber_set_ = other.escaped_array_clobber_set_;
388}
389
390bool LocalValueNumbering::SameMemoryVersion(const LocalValueNumbering& other) const {
391 return
392 global_memory_version_ == other.global_memory_version_ &&
393 std::equal(unresolved_ifield_version_, unresolved_ifield_version_ + kFieldTypeCount,
394 other.unresolved_ifield_version_) &&
395 std::equal(unresolved_sfield_version_, unresolved_sfield_version_ + kFieldTypeCount,
396 other.unresolved_sfield_version_);
397}
398
399uint16_t LocalValueNumbering::NewMemoryVersion(uint16_t* new_version) {
400 if (*new_version == kNoValue) {
401 *new_version = gvn_->LookupValue(kMergeBlockMemoryVersionBumpOp, 0u, 0u, id_);
402 }
403 return *new_version;
404}
405
406void LocalValueNumbering::MergeMemoryVersions(bool clobbered_catch) {
407 DCHECK_GE(gvn_->merge_lvns_.size(), 2u);
408 const LocalValueNumbering* cmp = gvn_->merge_lvns_[0];
409 // Check if the global version has changed.
410 bool new_global_version = clobbered_catch;
411 if (!new_global_version) {
412 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
413 if (lvn->global_memory_version_ != cmp->global_memory_version_) {
414 // Use a new version for everything.
415 new_global_version = true;
416 break;
417 }
418 }
419 }
420 if (new_global_version) {
421 global_memory_version_ = NewMemoryVersion(&merge_new_memory_version_);
422 std::fill_n(unresolved_sfield_version_, kFieldTypeCount, merge_new_memory_version_);
423 std::fill_n(unresolved_ifield_version_, kFieldTypeCount, merge_new_memory_version_);
424 } else {
425 // Initialize with a copy of memory versions from the comparison LVN.
426 global_memory_version_ = cmp->global_memory_version_;
427 std::copy_n(cmp->unresolved_ifield_version_, kFieldTypeCount, unresolved_ifield_version_);
428 std::copy_n(cmp->unresolved_sfield_version_, kFieldTypeCount, unresolved_sfield_version_);
429 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
430 if (lvn == cmp) {
431 continue;
432 }
433 for (size_t i = 0; i != kFieldTypeCount; ++i) {
434 if (lvn->unresolved_ifield_version_[i] != cmp->unresolved_ifield_version_[i]) {
435 unresolved_ifield_version_[i] = NewMemoryVersion(&merge_new_memory_version_);
436 }
437 if (lvn->unresolved_sfield_version_[i] != cmp->unresolved_sfield_version_[i]) {
438 unresolved_sfield_version_[i] = NewMemoryVersion(&merge_new_memory_version_);
439 }
440 }
441 }
442 }
443}
444
445void LocalValueNumbering::PruneNonAliasingRefsForCatch() {
446 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
447 const BasicBlock* bb = gvn_->GetBasicBlock(lvn->Id());
448 DCHECK_EQ(bb->taken, kNullBlock);
449 DCHECK_NE(bb->fall_through, kNullBlock);
450 const BasicBlock* fall_through_bb = gvn_->GetBasicBlock(bb->fall_through);
451 const MIR* mir = fall_through_bb->first_mir_insn;
452 DCHECK(mir != nullptr);
453 // Only INVOKEs can leak and clobber non-aliasing references if they throw.
454 if ((Instruction::FlagsOf(mir->dalvikInsn.opcode) & Instruction::kInvoke) != 0) {
455 for (uint16_t i = 0u; i != mir->ssa_rep->num_uses; ++i) {
456 uint16_t value_name = lvn->GetOperandValue(mir->ssa_rep->uses[i]);
457 non_aliasing_refs_.erase(value_name);
458 }
459 }
460 }
461}
462
463
464template <typename Set, Set LocalValueNumbering::* set_ptr>
465void LocalValueNumbering::IntersectSets() {
466 DCHECK_GE(gvn_->merge_lvns_.size(), 2u);
467
468 // Find the LVN with the least entries in the set.
469 const LocalValueNumbering* least_entries_lvn = gvn_->merge_lvns_[0];
470 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
471 if ((lvn->*set_ptr).size() < (least_entries_lvn->*set_ptr).size()) {
472 least_entries_lvn = lvn;
473 }
474 }
475
476 // For each key check if it's in all the LVNs.
477 for (const auto& key : least_entries_lvn->*set_ptr) {
478 bool checked = true;
479 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
480 if (lvn != least_entries_lvn && (lvn->*set_ptr).count(key) == 0u) {
481 checked = false;
482 break;
483 }
484 }
485 if (checked) {
486 (this->*set_ptr).emplace_hint((this->*set_ptr).end(), key);
487 }
488 }
489}
490
491template <typename Map, Map LocalValueNumbering::* map_ptr>
492void LocalValueNumbering::IntersectMaps() {
493 DCHECK_GE(gvn_->merge_lvns_.size(), 2u);
494
495 // Find the LVN with the least entries in the set.
496 const LocalValueNumbering* least_entries_lvn = gvn_->merge_lvns_[0];
497 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
498 if ((lvn->*map_ptr).size() < (least_entries_lvn->*map_ptr).size()) {
499 least_entries_lvn = lvn;
500 }
501 }
502
503 // For each key check if it's in all the LVNs.
504 for (const auto& entry : least_entries_lvn->*map_ptr) {
505 bool checked = true;
506 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
507 if (lvn != least_entries_lvn) {
508 auto it = (lvn->*map_ptr).find(entry.first);
509 if (it == (lvn->*map_ptr).end() || !(it->second == entry.second)) {
510 checked = false;
511 break;
512 }
513 }
514 }
515 if (checked) {
516 (this->*map_ptr).PutBefore((this->*map_ptr).end(), entry.first, entry.second);
517 }
518 }
519}
520
521// Intersect maps as sets. The value type must be equality-comparable.
522template <typename Map>
523void LocalValueNumbering::InPlaceIntersectMaps(Map* work_map, const Map& other_map) {
524 auto work_it = work_map->begin(), work_end = work_map->end();
525 auto cmp = work_map->value_comp();
526 for (const auto& entry : other_map) {
527 while (work_it != work_end &&
528 (cmp(*work_it, entry) ||
529 (!cmp(entry, *work_it) && !(work_it->second == entry.second)))) {
530 work_it = work_map->erase(work_it);
531 }
532 }
533}
534
535template <typename Set, Set LocalValueNumbering::*set_ptr, void (LocalValueNumbering::*MergeFn)(
536 const typename Set::value_type& entry, typename Set::iterator hint)>
537void LocalValueNumbering::MergeSets() {
538 auto cmp = (this->*set_ptr).value_comp();
539 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
540 auto my_it = (this->*set_ptr).begin(), my_end = (this->*set_ptr).end();
541 for (const auto& entry : lvn->*set_ptr) {
542 while (my_it != my_end && cmp(*my_it, entry)) {
543 ++my_it;
544 }
545 if (my_it != my_end && !cmp(entry, *my_it)) {
546 // Already handled.
547 ++my_it;
548 } else {
549 // Merge values for this field_id.
550 (this->*MergeFn)(entry, my_it); // my_it remains valid across inserts to std::set/SafeMap.
551 }
552 }
553 }
554}
555
556void LocalValueNumbering::IntersectAliasingValueLocations(AliasingValues* work_values,
557 const AliasingValues* values) {
558 auto cmp = work_values->load_value_map.key_comp();
559 auto work_it = work_values->load_value_map.begin(), work_end = work_values->load_value_map.end();
560 auto store_it = values->store_loc_set.begin(), store_end = values->store_loc_set.end();
561 auto load_it = values->load_value_map.begin(), load_end = values->load_value_map.end();
562 while (store_it != store_end || load_it != load_end) {
563 uint16_t loc;
564 if (store_it != store_end && (load_it == load_end || *store_it < load_it->first)) {
565 loc = *store_it;
566 ++store_it;
567 } else {
568 loc = load_it->first;
569 ++load_it;
570 DCHECK(store_it == store_end || cmp(loc, *store_it));
571 }
572 while (work_it != work_end && cmp(work_it->first, loc)) {
573 work_it = work_values->load_value_map.erase(work_it);
574 }
575 if (work_it != work_end && !cmp(loc, work_it->first)) {
576 // The location matches, keep it.
577 ++work_it;
578 }
579 }
580 while (work_it != work_end) {
581 work_it = work_values->load_value_map.erase(work_it);
582 }
583}
584
585void LocalValueNumbering::MergeEscapedRefs(const ValueNameSet::value_type& entry,
586 ValueNameSet::iterator hint) {
587 // See if the ref is either escaped or non-aliasing in each predecessor.
588 bool is_escaped = true;
589 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
590 if (lvn->non_aliasing_refs_.count(entry) == 0u &&
591 lvn->escaped_refs_.count(entry) == 0u) {
592 is_escaped = false;
593 break;
594 }
595 }
596 if (is_escaped) {
597 escaped_refs_.emplace_hint(hint, entry);
598 }
599}
600
601void LocalValueNumbering::MergeEscapedIFieldTypeClobberSets(
602 const EscapedIFieldClobberSet::value_type& entry, EscapedIFieldClobberSet::iterator hint) {
603 // Insert only type-clobber entries (field_id == kNoValue) of escaped refs.
604 if (entry.field_id == kNoValue && escaped_refs_.count(entry.base) != 0u) {
605 escaped_ifield_clobber_set_.emplace_hint(hint, entry);
606 }
607}
608
609void LocalValueNumbering::MergeEscapedIFieldClobberSets(
610 const EscapedIFieldClobberSet::value_type& entry, EscapedIFieldClobberSet::iterator hint) {
611 // Insert only those entries of escaped refs that are not overridden by a type clobber.
612 if (!(hint == escaped_ifield_clobber_set_.end() &&
613 hint->base == entry.base && hint->type == entry.type) &&
614 escaped_refs_.count(entry.base) != 0u) {
615 escaped_ifield_clobber_set_.emplace_hint(hint, entry);
616 }
617}
618
619void LocalValueNumbering::MergeEscapedArrayClobberSets(
620 const EscapedArrayClobberSet::value_type& entry, EscapedArrayClobberSet::iterator hint) {
621 if (escaped_refs_.count(entry.base) != 0u) {
622 escaped_array_clobber_set_.emplace_hint(hint, entry);
623 }
624}
625
626void LocalValueNumbering::MergeNullChecked(const ValueNameSet::value_type& entry,
627 ValueNameSet::iterator hint) {
628 // Merge null_checked_ for this ref.
629 merge_names_.clear();
630 merge_names_.resize(gvn_->merge_lvns_.size(), entry);
631 if (gvn_->NullCheckedInAllPredecessors(merge_names_)) {
632 null_checked_.insert(hint, entry);
633 }
634}
635
636void LocalValueNumbering::MergeSFieldValues(const SFieldToValueMap::value_type& entry,
637 SFieldToValueMap::iterator hint) {
638 uint16_t field_id = entry.first;
639 merge_names_.clear();
640 uint16_t value_name = kNoValue;
641 bool same_values = true;
642 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
643 // Get the value name as in HandleSGet() but don't modify *lvn.
644 auto it = lvn->sfield_value_map_.find(field_id);
645 if (it != lvn->sfield_value_map_.end()) {
646 value_name = it->second;
647 } else {
648 uint16_t type = gvn_->GetFieldType(field_id);
649 value_name = gvn_->LookupValue(kResolvedSFieldOp, field_id,
650 lvn->unresolved_sfield_version_[type],
651 lvn->global_memory_version_);
652 }
653
654 same_values = same_values && (merge_names_.empty() || value_name == merge_names_.back());
655 merge_names_.push_back(value_name);
656 }
657 if (same_values) {
658 // value_name already contains the result.
659 } else {
660 auto lb = merge_map_.lower_bound(merge_names_);
661 if (lb != merge_map_.end() && !merge_map_.key_comp()(merge_names_, lb->first)) {
662 value_name = lb->second;
663 } else {
664 value_name = gvn_->LookupValue(kMergeBlockSFieldVersionBumpOp, field_id, id_, kNoValue);
665 merge_map_.PutBefore(lb, merge_names_, value_name);
666 if (gvn_->NullCheckedInAllPredecessors(merge_names_)) {
667 null_checked_.insert(value_name);
668 }
669 }
670 }
671 sfield_value_map_.PutBefore(hint, field_id, value_name);
672}
673
674void LocalValueNumbering::MergeNonAliasingIFieldValues(const IFieldLocToValueMap::value_type& entry,
675 IFieldLocToValueMap::iterator hint) {
676 uint16_t field_loc = entry.first;
677 merge_names_.clear();
678 uint16_t value_name = kNoValue;
679 bool same_values = true;
680 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
681 // Get the value name as in HandleIGet() but don't modify *lvn.
682 auto it = lvn->non_aliasing_ifield_value_map_.find(field_loc);
683 if (it != lvn->non_aliasing_ifield_value_map_.end()) {
684 value_name = it->second;
685 } else {
686 value_name = gvn_->LookupValue(kNonAliasingIFieldInitialOp, field_loc, kNoValue, kNoValue);
687 }
688
689 same_values = same_values && (merge_names_.empty() || value_name == merge_names_.back());
690 merge_names_.push_back(value_name);
691 }
692 if (same_values) {
693 // value_name already contains the result.
694 } else {
695 auto lb = merge_map_.lower_bound(merge_names_);
696 if (lb != merge_map_.end() && !merge_map_.key_comp()(merge_names_, lb->first)) {
697 value_name = lb->second;
698 } else {
699 value_name = gvn_->LookupValue(kMergeBlockNonAliasingIFieldVersionBumpOp, field_loc,
700 id_, kNoValue);
701 merge_map_.PutBefore(lb, merge_names_, value_name);
702 if (gvn_->NullCheckedInAllPredecessors(merge_names_)) {
703 null_checked_.insert(value_name);
704 }
705 }
706 }
707 non_aliasing_ifield_value_map_.PutBefore(hint, field_loc, value_name);
708}
709
710template <typename Map, Map LocalValueNumbering::*map_ptr, typename Versions>
711void LocalValueNumbering::MergeAliasingValues(const typename Map::value_type& entry,
712 typename Map::iterator hint) {
713 const typename Map::key_type& key = entry.first;
714
715 (this->*map_ptr).PutBefore(hint, key, AliasingValues(gvn_->allocator_));
716 DCHECK(hint != (this->*map_ptr).begin());
717 AliasingIFieldValuesMap::iterator it = hint;
718 --it;
719 DCHECK_EQ(it->first, key);
720 AliasingValues* my_values = &it->second;
721
722 const AliasingValues* cmp_values = nullptr;
723 bool same_version = !Versions::HasNewBaseVersion(gvn_, this, key);
724 uint16_t load_memory_version_for_same_version = kNoValue;
725 if (same_version) {
726 // Find the first non-null values.
727 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
728 auto it = (lvn->*map_ptr).find(key);
729 if (it != (lvn->*map_ptr).end()) {
730 cmp_values = &it->second;
731 break;
732 }
733 }
734 DCHECK(cmp_values != nullptr); // There must be at least one non-null values.
735
736 // Check if we have identical memory versions, i.e. the global memory version, unresolved
737 // field version and the values' memory_version_before_stores, last_stored_value
738 // and store_loc_set are identical.
739 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
740 auto it = (lvn->*map_ptr).find(key);
741 if (it == (lvn->*map_ptr).end()) {
742 if (cmp_values->memory_version_before_stores != kNoValue) {
743 same_version = false;
744 break;
745 }
746 } else if (cmp_values->last_stored_value != it->second.last_stored_value ||
747 cmp_values->memory_version_before_stores != it->second.memory_version_before_stores ||
748 cmp_values->store_loc_set != it->second.store_loc_set) {
749 same_version = false;
750 break;
751 } else if (it->second.last_load_memory_version != kNoValue) {
752 DCHECK(load_memory_version_for_same_version == kNoValue ||
753 load_memory_version_for_same_version == it->second.last_load_memory_version);
754 load_memory_version_for_same_version = it->second.last_load_memory_version;
755 }
756 }
757 }
758
759 if (same_version) {
760 // Copy the identical values.
761 my_values->memory_version_before_stores = cmp_values->memory_version_before_stores;
762 my_values->last_stored_value = cmp_values->last_stored_value;
763 my_values->store_loc_set = cmp_values->store_loc_set;
764 my_values->last_load_memory_version = load_memory_version_for_same_version;
765 // Merge load values seen in all incoming arcs (i.e. an intersection).
766 if (!cmp_values->load_value_map.empty()) {
767 my_values->load_value_map = cmp_values->load_value_map;
768 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
769 auto it = (lvn->*map_ptr).find(key);
770 if (it == (lvn->*map_ptr).end() || it->second.load_value_map.empty()) {
771 my_values->load_value_map.clear();
772 break;
773 }
774 InPlaceIntersectMaps(&my_values->load_value_map, it->second.load_value_map);
775 if (my_values->load_value_map.empty()) {
776 break;
777 }
778 }
779 }
780 } else {
781 // Bump version number for the merge.
782 my_values->memory_version_before_stores = my_values->last_load_memory_version =
783 Versions::LookupMergeBlockValue(gvn_, id_, key);
784
785 // Calculate the locations that have been either read from or written to in each incoming LVN.
786 bool first_lvn = true;
787 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
788 auto it = (lvn->*map_ptr).find(key);
789 if (it == (lvn->*map_ptr).end()) {
790 my_values->load_value_map.clear();
791 break;
792 }
793 if (first_lvn) {
794 first_lvn = false;
795 // Copy the first LVN's locations. Values will be overwritten later.
796 my_values->load_value_map = it->second.load_value_map;
797 for (uint16_t location : it->second.store_loc_set) {
798 my_values->load_value_map.Put(location, 0u);
799 }
800 } else {
801 IntersectAliasingValueLocations(my_values, &it->second);
802 }
803 }
804 // Calculate merged values for the intersection.
805 for (auto& load_value_entry : my_values->load_value_map) {
806 uint16_t location = load_value_entry.first;
807 bool same_values = true;
808 uint16_t value_name = kNoValue;
809 merge_names_.clear();
810 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
811 value_name = Versions::LookupMergeValue(gvn_, lvn, key, location);
812 same_values = same_values && (merge_names_.empty() || value_name == merge_names_.back());
813 merge_names_.push_back(value_name);
814 }
815 if (same_values) {
816 // value_name already contains the result.
817 } else {
818 auto lb = merge_map_.lower_bound(merge_names_);
819 if (lb != merge_map_.end() && !merge_map_.key_comp()(merge_names_, lb->first)) {
820 value_name = lb->second;
821 } else {
822 // NOTE: In addition to the key and id_ which don't change on an LVN recalculation
823 // during GVN, we also add location which can actually change on recalculation, so the
824 // value_name below may change. This could lead to an infinite loop if the location
825 // value name always changed when the refereced value name changes. However, given that
826 // we assign unique value names for other merges, such as Phis, such a dependency is
827 // not possible in a well-formed SSA graph.
828 value_name = Versions::LookupMergeLocationValue(gvn_, id_, key, location);
829 merge_map_.PutBefore(lb, merge_names_, value_name);
830 if (gvn_->NullCheckedInAllPredecessors(merge_names_)) {
831 null_checked_.insert(value_name);
832 }
833 }
834 }
835 load_value_entry.second = value_name;
836 }
837 }
838}
839
840void LocalValueNumbering::Merge(MergeType merge_type) {
841 DCHECK_GE(gvn_->merge_lvns_.size(), 2u);
842
843 IntersectMaps<SregValueMap, &LocalValueNumbering::sreg_value_map_>();
844 IntersectMaps<SregValueMap, &LocalValueNumbering::sreg_wide_value_map_>();
845 if (merge_type == kReturnMerge) {
846 // RETURN or PHI+RETURN. We need only sreg value maps.
847 return;
848 }
849
850 MergeMemoryVersions(merge_type == kCatchMerge);
851
852 // Merge non-aliasing maps/sets.
853 MergeSets<IFieldLocToValueMap, &LocalValueNumbering::non_aliasing_ifield_value_map_,
854 &LocalValueNumbering::MergeNonAliasingIFieldValues>();
855 MergeSets<NonAliasingArrayValuesMap, &LocalValueNumbering::non_aliasing_array_value_map_,
856 &LocalValueNumbering::MergeAliasingValues<
857 NonAliasingArrayValuesMap, &LocalValueNumbering::non_aliasing_array_value_map_,
858 NonAliasingArrayVersions>>();
859 IntersectSets<ValueNameSet, &LocalValueNumbering::non_aliasing_refs_>();
860
861 // We won't do anything complicated for range checks, just calculate the intersection.
862 IntersectSets<RangeCheckSet, &LocalValueNumbering::range_checked_>();
863
864 // Merge null_checked_. We may later insert more, such as merged object field values.
865 MergeSets<ValueNameSet, &LocalValueNumbering::null_checked_,
866 &LocalValueNumbering::MergeNullChecked>();
867
868 if (merge_type == kCatchMerge) {
869 // Memory is clobbered. New memory version already created, don't merge aliasing locations.
870 PruneNonAliasingRefsForCatch();
871 return;
872 }
873
874 DCHECK(merge_type == kNormalMerge);
875
876 // Merge escaped refs and clobber sets.
877 MergeSets<ValueNameSet, &LocalValueNumbering::escaped_refs_,
878 &LocalValueNumbering::MergeEscapedRefs>();
879 if (!escaped_refs_.empty()) {
880 MergeSets<EscapedIFieldClobberSet, &LocalValueNumbering::escaped_ifield_clobber_set_,
881 &LocalValueNumbering::MergeEscapedIFieldTypeClobberSets>();
882 MergeSets<EscapedIFieldClobberSet, &LocalValueNumbering::escaped_ifield_clobber_set_,
883 &LocalValueNumbering::MergeEscapedIFieldClobberSets>();
884 MergeSets<EscapedArrayClobberSet, &LocalValueNumbering::escaped_array_clobber_set_,
885 &LocalValueNumbering::MergeEscapedArrayClobberSets>();
886 }
887
888 MergeSets<SFieldToValueMap, &LocalValueNumbering::sfield_value_map_,
889 &LocalValueNumbering::MergeSFieldValues>();
890 MergeSets<AliasingIFieldValuesMap, &LocalValueNumbering::aliasing_ifield_value_map_,
891 &LocalValueNumbering::MergeAliasingValues<
892 AliasingIFieldValuesMap, &LocalValueNumbering::aliasing_ifield_value_map_,
893 AliasingIFieldVersions>>();
894 MergeSets<AliasingArrayValuesMap, &LocalValueNumbering::aliasing_array_value_map_,
895 &LocalValueNumbering::MergeAliasingValues<
896 AliasingArrayValuesMap, &LocalValueNumbering::aliasing_array_value_map_,
897 AliasingArrayVersions>>();
Vladimir Markof59f18b2014-02-17 15:53:57 +0000898}
899
Vladimir Markof59f18b2014-02-17 15:53:57 +0000900uint16_t LocalValueNumbering::MarkNonAliasingNonNull(MIR* mir) {
901 uint16_t res = GetOperandValue(mir->ssa_rep->defs[0]);
Vladimir Markof59f18b2014-02-17 15:53:57 +0000902 DCHECK(null_checked_.find(res) == null_checked_.end());
903 null_checked_.insert(res);
904 non_aliasing_refs_.insert(res);
905 return res;
906}
907
Vladimir Marko95a05972014-05-30 10:01:32 +0100908bool LocalValueNumbering::IsNonAliasing(uint16_t reg) const {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100909 return non_aliasing_refs_.find(reg) != non_aliasing_refs_.end();
Vladimir Markof59f18b2014-02-17 15:53:57 +0000910}
911
Vladimir Marko95a05972014-05-30 10:01:32 +0100912bool LocalValueNumbering::IsNonAliasingIField(uint16_t reg, uint16_t field_id,
913 uint16_t type) const {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100914 if (IsNonAliasing(reg)) {
915 return true;
916 }
Vladimir Marko95a05972014-05-30 10:01:32 +0100917 if (escaped_refs_.find(reg) == escaped_refs_.end()) {
918 return false;
919 }
920 // Check for IPUTs to unresolved fields.
921 EscapedIFieldClobberKey key1 = { reg, type, kNoValue };
922 if (escaped_ifield_clobber_set_.find(key1) != escaped_ifield_clobber_set_.end()) {
923 return false;
924 }
925 // Check for aliased IPUTs to the same field.
926 EscapedIFieldClobberKey key2 = { reg, type, field_id };
927 return escaped_ifield_clobber_set_.find(key2) == escaped_ifield_clobber_set_.end();
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100928}
929
Vladimir Marko95a05972014-05-30 10:01:32 +0100930bool LocalValueNumbering::IsNonAliasingArray(uint16_t reg, uint16_t type) const {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100931 if (IsNonAliasing(reg)) {
932 return true;
933 }
Vladimir Marko95a05972014-05-30 10:01:32 +0100934 if (escaped_refs_.count(reg) == 0u) {
935 return false;
936 }
937 // Check for aliased APUTs.
938 EscapedArrayClobberKey key = { reg, type };
939 return escaped_array_clobber_set_.find(key) == escaped_array_clobber_set_.end();
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100940}
941
Vladimir Markof59f18b2014-02-17 15:53:57 +0000942void LocalValueNumbering::HandleNullCheck(MIR* mir, uint16_t reg) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100943 auto lb = null_checked_.lower_bound(reg);
944 if (lb != null_checked_.end() && *lb == reg) {
Vladimir Marko95a05972014-05-30 10:01:32 +0100945 if (LIKELY(gvn_->CanModify())) {
946 if (gvn_->GetCompilationUnit()->verbose) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100947 LOG(INFO) << "Removing null check for 0x" << std::hex << mir->offset;
948 }
949 mir->optimization_flags |= MIR_IGNORE_NULL_CHECK;
Vladimir Markof59f18b2014-02-17 15:53:57 +0000950 }
Vladimir Markof59f18b2014-02-17 15:53:57 +0000951 } else {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100952 null_checked_.insert(lb, reg);
Vladimir Markof59f18b2014-02-17 15:53:57 +0000953 }
954}
955
956void LocalValueNumbering::HandleRangeCheck(MIR* mir, uint16_t array, uint16_t index) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100957 RangeCheckKey key = { array, index };
958 auto lb = range_checked_.lower_bound(key);
959 if (lb != range_checked_.end() && !RangeCheckKeyComparator()(key, *lb)) {
Vladimir Marko95a05972014-05-30 10:01:32 +0100960 if (LIKELY(gvn_->CanModify())) {
961 if (gvn_->GetCompilationUnit()->verbose) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100962 LOG(INFO) << "Removing range check for 0x" << std::hex << mir->offset;
963 }
964 mir->optimization_flags |= MIR_IGNORE_RANGE_CHECK;
Vladimir Markof59f18b2014-02-17 15:53:57 +0000965 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100966 } else {
967 // Mark range check completed.
968 range_checked_.insert(lb, key);
Vladimir Markof59f18b2014-02-17 15:53:57 +0000969 }
Vladimir Markof59f18b2014-02-17 15:53:57 +0000970}
971
972void LocalValueNumbering::HandlePutObject(MIR* mir) {
973 // If we're storing a non-aliasing reference, stop tracking it as non-aliasing now.
974 uint16_t base = GetOperandValue(mir->ssa_rep->uses[0]);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100975 HandleEscapingRef(base);
976}
977
978void LocalValueNumbering::HandleEscapingRef(uint16_t base) {
979 auto it = non_aliasing_refs_.find(base);
980 if (it != non_aliasing_refs_.end()) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100981 non_aliasing_refs_.erase(it);
Vladimir Marko95a05972014-05-30 10:01:32 +0100982 escaped_refs_.insert(base);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +0100983 }
984}
985
Vladimir Marko95a05972014-05-30 10:01:32 +0100986uint16_t LocalValueNumbering::HandlePhi(MIR* mir) {
987 if (gvn_->merge_lvns_.empty()) {
988 // Running LVN without a full GVN?
989 return kNoValue;
990 }
991 int16_t num_uses = mir->ssa_rep->num_uses;
992 int32_t* uses = mir->ssa_rep->uses;
993 // Try to find out if this is merging wide regs.
994 if (mir->ssa_rep->defs[0] != 0 &&
995 sreg_wide_value_map_.count(mir->ssa_rep->defs[0] - 1) != 0u) {
996 // This is the high part of a wide reg. Ignore the Phi.
997 return kNoValue;
998 }
999 bool wide = false;
1000 for (int16_t i = 0; i != num_uses; ++i) {
1001 if (sreg_wide_value_map_.count(uses[i]) != 0u) {
1002 wide = true;
1003 break;
1004 }
1005 }
1006 // Iterate over *merge_lvns_ and skip incoming sregs for BBs without associated LVN.
1007 uint16_t value_name = kNoValue;
1008 merge_names_.clear();
1009 BasicBlockId* incoming = mir->meta.phi_incoming;
1010 int16_t pos = 0;
1011 bool same_values = true;
1012 for (const LocalValueNumbering* lvn : gvn_->merge_lvns_) {
1013 DCHECK_LT(pos, mir->ssa_rep->num_uses);
1014 while (incoming[pos] != lvn->Id()) {
1015 ++pos;
1016 DCHECK_LT(pos, mir->ssa_rep->num_uses);
1017 }
1018 int s_reg = uses[pos];
1019 ++pos;
1020 value_name = wide ? lvn->GetOperandValueWide(s_reg) : lvn->GetOperandValue(s_reg);
1021
1022 same_values = same_values && (merge_names_.empty() || value_name == merge_names_.back());
1023 merge_names_.push_back(value_name);
1024 }
1025 if (same_values) {
1026 // value_name already contains the result.
1027 } else {
1028 auto lb = merge_map_.lower_bound(merge_names_);
1029 if (lb != merge_map_.end() && !merge_map_.key_comp()(merge_names_, lb->first)) {
1030 value_name = lb->second;
1031 } else {
1032 value_name = gvn_->LookupValue(kNoValue, mir->ssa_rep->defs[0], kNoValue, kNoValue);
1033 merge_map_.PutBefore(lb, merge_names_, value_name);
1034 if (!wide && gvn_->NullCheckedInAllPredecessors(merge_names_)) {
1035 null_checked_.insert(value_name);
1036 }
1037 }
1038 }
1039 if (wide) {
1040 SetOperandValueWide(mir->ssa_rep->defs[0], value_name);
1041 } else {
1042 SetOperandValue(mir->ssa_rep->defs[0], value_name);
1043 }
1044 return value_name;
1045}
1046
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001047uint16_t LocalValueNumbering::HandleAGet(MIR* mir, uint16_t opcode) {
1048 // uint16_t type = opcode - Instruction::AGET;
1049 uint16_t array = GetOperandValue(mir->ssa_rep->uses[0]);
1050 HandleNullCheck(mir, array);
1051 uint16_t index = GetOperandValue(mir->ssa_rep->uses[1]);
1052 HandleRangeCheck(mir, array, index);
1053 uint16_t type = opcode - Instruction::AGET;
1054 // Establish value number for loaded register.
1055 uint16_t res;
1056 if (IsNonAliasingArray(array, type)) {
Vladimir Marko95a05972014-05-30 10:01:32 +01001057 res = HandleAliasingValuesGet<NonAliasingArrayVersions>(&non_aliasing_array_value_map_,
1058 array, index);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001059 } else {
Vladimir Marko95a05972014-05-30 10:01:32 +01001060 uint16_t location = gvn_->GetArrayLocation(array, index);
1061 res = HandleAliasingValuesGet<AliasingArrayVersions>(&aliasing_array_value_map_,
1062 type, location);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001063 }
1064 if (opcode == Instruction::AGET_WIDE) {
1065 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1066 } else {
1067 SetOperandValue(mir->ssa_rep->defs[0], res);
1068 }
1069 return res;
1070}
1071
1072void LocalValueNumbering::HandleAPut(MIR* mir, uint16_t opcode) {
1073 int array_idx = (opcode == Instruction::APUT_WIDE) ? 2 : 1;
1074 int index_idx = array_idx + 1;
1075 uint16_t array = GetOperandValue(mir->ssa_rep->uses[array_idx]);
1076 HandleNullCheck(mir, array);
1077 uint16_t index = GetOperandValue(mir->ssa_rep->uses[index_idx]);
1078 HandleRangeCheck(mir, array, index);
1079
1080 uint16_t type = opcode - Instruction::APUT;
1081 uint16_t value = (opcode == Instruction::APUT_WIDE)
1082 ? GetOperandValueWide(mir->ssa_rep->uses[0])
1083 : GetOperandValue(mir->ssa_rep->uses[0]);
1084 if (IsNonAliasing(array)) {
Vladimir Marko95a05972014-05-30 10:01:32 +01001085 bool put_is_live = HandleAliasingValuesPut<NonAliasingArrayVersions>(
1086 &non_aliasing_array_value_map_, array, index, value);
1087 if (!put_is_live) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001088 // This APUT can be eliminated, it stores the same value that's already in the field.
1089 // TODO: Eliminate the APUT.
1090 return;
1091 }
Vladimir Marko95a05972014-05-30 10:01:32 +01001092 } else {
1093 uint16_t location = gvn_->GetArrayLocation(array, index);
1094 bool put_is_live = HandleAliasingValuesPut<AliasingArrayVersions>(
1095 &aliasing_array_value_map_, type, location, value);
1096 if (!put_is_live) {
1097 // This APUT can be eliminated, it stores the same value that's already in the field.
1098 // TODO: Eliminate the APUT.
1099 return;
1100 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001101
Vladimir Marko95a05972014-05-30 10:01:32 +01001102 // Clobber all escaped array refs for this type.
1103 for (uint16_t escaped_array : escaped_refs_) {
1104 EscapedArrayClobberKey clobber_key = { escaped_array, type };
1105 escaped_array_clobber_set_.insert(clobber_key);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001106 }
1107 }
1108}
1109
1110uint16_t LocalValueNumbering::HandleIGet(MIR* mir, uint16_t opcode) {
1111 uint16_t base = GetOperandValue(mir->ssa_rep->uses[0]);
1112 HandleNullCheck(mir, base);
Vladimir Marko95a05972014-05-30 10:01:32 +01001113 const MirFieldInfo& field_info = gvn_->GetMirGraph()->GetIFieldLoweringInfo(mir);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001114 uint16_t res;
1115 if (!field_info.IsResolved() || field_info.IsVolatile()) {
1116 // Volatile fields always get a new memory version; field id is irrelevant.
1117 // Unresolved fields may be volatile, so handle them as such to be safe.
1118 // Use result s_reg - will be unique.
Vladimir Marko95a05972014-05-30 10:01:32 +01001119 res = gvn_->LookupValue(kNoValue, mir->ssa_rep->defs[0], kNoValue, kNoValue);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001120 } else {
1121 uint16_t type = opcode - Instruction::IGET;
Vladimir Marko95a05972014-05-30 10:01:32 +01001122 uint16_t field_id = gvn_->GetFieldId(field_info, type);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001123 if (IsNonAliasingIField(base, field_id, type)) {
Vladimir Marko95a05972014-05-30 10:01:32 +01001124 uint16_t loc = gvn_->LookupValue(kNonAliasingIFieldLocOp, base, field_id, type);
1125 auto lb = non_aliasing_ifield_value_map_.lower_bound(loc);
1126 if (lb != non_aliasing_ifield_value_map_.end() && lb->first == loc) {
1127 res = lb->second;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001128 } else {
Vladimir Marko95a05972014-05-30 10:01:32 +01001129 res = gvn_->LookupValue(kNonAliasingIFieldInitialOp, loc, kNoValue, kNoValue);
1130 non_aliasing_ifield_value_map_.PutBefore(lb, loc, res);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001131 }
Vladimir Marko95a05972014-05-30 10:01:32 +01001132 } else {
1133 res = HandleAliasingValuesGet<AliasingIFieldVersions>(&aliasing_ifield_value_map_,
1134 field_id, base);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001135 }
1136 }
1137 if (opcode == Instruction::IGET_WIDE) {
1138 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1139 } else {
1140 SetOperandValue(mir->ssa_rep->defs[0], res);
1141 }
1142 return res;
1143}
1144
1145void LocalValueNumbering::HandleIPut(MIR* mir, uint16_t opcode) {
1146 uint16_t type = opcode - Instruction::IPUT;
1147 int base_reg = (opcode == Instruction::IPUT_WIDE) ? 2 : 1;
1148 uint16_t base = GetOperandValue(mir->ssa_rep->uses[base_reg]);
1149 HandleNullCheck(mir, base);
Vladimir Marko95a05972014-05-30 10:01:32 +01001150 const MirFieldInfo& field_info = gvn_->GetMirGraph()->GetIFieldLoweringInfo(mir);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001151 if (!field_info.IsResolved()) {
1152 // Unresolved fields always alias with everything of the same type.
1153 // Use mir->offset as modifier; without elaborate inlining, it will be unique.
1154 unresolved_ifield_version_[type] =
Vladimir Marko95a05972014-05-30 10:01:32 +01001155 gvn_->LookupValue(kUnresolvedIFieldOp, kNoValue, kNoValue, mir->offset);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001156
Vladimir Marko95a05972014-05-30 10:01:32 +01001157 // For simplicity, treat base as escaped now.
1158 HandleEscapingRef(base);
1159
1160 // Clobber all fields of escaped references of the same type.
1161 for (uint16_t escaped_ref : escaped_refs_) {
1162 EscapedIFieldClobberKey clobber_key = { escaped_ref, type, kNoValue };
1163 escaped_ifield_clobber_set_.insert(clobber_key);
1164 }
1165
1166 // Aliasing fields of the same type may have been overwritten.
1167 auto it = aliasing_ifield_value_map_.begin(), end = aliasing_ifield_value_map_.end();
1168 while (it != end) {
1169 if (gvn_->GetFieldType(it->first) != type) {
1170 ++it;
1171 } else {
1172 it = aliasing_ifield_value_map_.erase(it);
1173 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001174 }
1175 } else if (field_info.IsVolatile()) {
1176 // Nothing to do, resolved volatile fields always get a new memory version anyway and
1177 // can't alias with resolved non-volatile fields.
1178 } else {
Vladimir Marko95a05972014-05-30 10:01:32 +01001179 uint16_t field_id = gvn_->GetFieldId(field_info, type);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001180 uint16_t value = (opcode == Instruction::IPUT_WIDE)
1181 ? GetOperandValueWide(mir->ssa_rep->uses[0])
1182 : GetOperandValue(mir->ssa_rep->uses[0]);
1183 if (IsNonAliasing(base)) {
Vladimir Marko95a05972014-05-30 10:01:32 +01001184 uint16_t loc = gvn_->LookupValue(kNonAliasingIFieldLocOp, base, field_id, type);
1185 auto lb = non_aliasing_ifield_value_map_.lower_bound(loc);
1186 if (lb != non_aliasing_ifield_value_map_.end() && lb->first == loc) {
1187 if (lb->second == value) {
1188 // This IPUT can be eliminated, it stores the same value that's already in the field.
1189 // TODO: Eliminate the IPUT.
1190 return;
1191 }
1192 lb->second = value; // Overwrite.
1193 } else {
1194 non_aliasing_ifield_value_map_.PutBefore(lb, loc, value);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001195 }
Vladimir Marko95a05972014-05-30 10:01:32 +01001196 } else {
1197 bool put_is_live = HandleAliasingValuesPut<AliasingIFieldVersions>(
1198 &aliasing_ifield_value_map_, field_id, base, value);
1199 if (!put_is_live) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001200 // This IPUT can be eliminated, it stores the same value that's already in the field.
1201 // TODO: Eliminate the IPUT.
1202 return;
1203 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001204
Vladimir Marko95a05972014-05-30 10:01:32 +01001205 // Clobber all fields of escaped references for this field.
1206 for (uint16_t escaped_ref : escaped_refs_) {
1207 EscapedIFieldClobberKey clobber_key = { escaped_ref, type, field_id };
1208 escaped_ifield_clobber_set_.insert(clobber_key);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001209 }
1210 }
1211 }
1212}
1213
1214uint16_t LocalValueNumbering::HandleSGet(MIR* mir, uint16_t opcode) {
Vladimir Marko95a05972014-05-30 10:01:32 +01001215 const MirSFieldLoweringInfo& field_info = gvn_->GetMirGraph()->GetSFieldLoweringInfo(mir);
Vladimir Markof418f322014-07-09 14:45:36 +01001216 if (!field_info.IsInitialized() && (mir->optimization_flags & MIR_IGNORE_CLINIT_CHECK) == 0) {
1217 // Class initialization can call arbitrary functions, we need to wipe aliasing values.
1218 HandleInvokeOrClInit(mir);
1219 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001220 uint16_t res;
1221 if (!field_info.IsResolved() || field_info.IsVolatile()) {
1222 // Volatile fields always get a new memory version; field id is irrelevant.
1223 // Unresolved fields may be volatile, so handle them as such to be safe.
1224 // Use result s_reg - will be unique.
Vladimir Marko95a05972014-05-30 10:01:32 +01001225 res = gvn_->LookupValue(kNoValue, mir->ssa_rep->defs[0], kNoValue, kNoValue);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001226 } else {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001227 uint16_t type = opcode - Instruction::SGET;
Vladimir Marko95a05972014-05-30 10:01:32 +01001228 uint16_t field_id = gvn_->GetFieldId(field_info, type);
1229 auto lb = sfield_value_map_.lower_bound(field_id);
1230 if (lb != sfield_value_map_.end() && lb->first == field_id) {
1231 res = lb->second;
1232 } else {
1233 // Resolved non-volatile static fields can alias with non-resolved fields of the same type,
1234 // so we need to use unresolved_sfield_version_[type] in addition to global_memory_version_
1235 // to determine the version of the field.
1236 res = gvn_->LookupValue(kResolvedSFieldOp, field_id,
1237 unresolved_sfield_version_[type], global_memory_version_);
1238 sfield_value_map_.PutBefore(lb, field_id, res);
1239 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001240 }
1241 if (opcode == Instruction::SGET_WIDE) {
1242 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1243 } else {
1244 SetOperandValue(mir->ssa_rep->defs[0], res);
1245 }
1246 return res;
1247}
1248
1249void LocalValueNumbering::HandleSPut(MIR* mir, uint16_t opcode) {
Vladimir Marko95a05972014-05-30 10:01:32 +01001250 const MirSFieldLoweringInfo& field_info = gvn_->GetMirGraph()->GetSFieldLoweringInfo(mir);
Vladimir Markof418f322014-07-09 14:45:36 +01001251 if (!field_info.IsInitialized() && (mir->optimization_flags & MIR_IGNORE_CLINIT_CHECK) == 0) {
1252 // Class initialization can call arbitrary functions, we need to wipe aliasing values.
1253 HandleInvokeOrClInit(mir);
1254 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001255 uint16_t type = opcode - Instruction::SPUT;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001256 if (!field_info.IsResolved()) {
1257 // Unresolved fields always alias with everything of the same type.
1258 // Use mir->offset as modifier; without elaborate inlining, it will be unique.
1259 unresolved_sfield_version_[type] =
Vladimir Marko95a05972014-05-30 10:01:32 +01001260 gvn_->LookupValue(kUnresolvedSFieldOp, kNoValue, kNoValue, mir->offset);
1261 RemoveSFieldsForType(type);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001262 } else if (field_info.IsVolatile()) {
1263 // Nothing to do, resolved volatile fields always get a new memory version anyway and
1264 // can't alias with resolved non-volatile fields.
1265 } else {
Vladimir Marko95a05972014-05-30 10:01:32 +01001266 uint16_t field_id = gvn_->GetFieldId(field_info, type);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001267 uint16_t value = (opcode == Instruction::SPUT_WIDE)
1268 ? GetOperandValueWide(mir->ssa_rep->uses[0])
1269 : GetOperandValue(mir->ssa_rep->uses[0]);
1270 // Resolved non-volatile static fields can alias with non-resolved fields of the same type,
1271 // so we need to use unresolved_sfield_version_[type] in addition to global_memory_version_
1272 // to determine the version of the field.
Vladimir Marko95a05972014-05-30 10:01:32 +01001273 auto lb = sfield_value_map_.lower_bound(field_id);
1274 if (lb != sfield_value_map_.end() && lb->first == field_id) {
1275 if (lb->second == value) {
1276 // This SPUT can be eliminated, it stores the same value that's already in the field.
1277 // TODO: Eliminate the SPUT.
1278 return;
1279 }
1280 lb->second = value; // Overwrite.
1281 } else {
1282 sfield_value_map_.PutBefore(lb, field_id, value);
1283 }
1284 }
1285}
1286
1287void LocalValueNumbering::RemoveSFieldsForType(uint16_t type) {
1288 // Erase all static fields of this type from the sfield_value_map_.
1289 for (auto it = sfield_value_map_.begin(), end = sfield_value_map_.end(); it != end; ) {
1290 if (gvn_->GetFieldType(it->first) == type) {
1291 it = sfield_value_map_.erase(it);
1292 } else {
1293 ++it;
1294 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001295 }
Vladimir Markof59f18b2014-02-17 15:53:57 +00001296}
buzbee2502e002012-12-31 16:05:53 -08001297
Vladimir Markof418f322014-07-09 14:45:36 +01001298void LocalValueNumbering::HandleInvokeOrClInit(MIR* mir) {
1299 // Use mir->offset as modifier; without elaborate inlining, it will be unique.
Vladimir Marko95a05972014-05-30 10:01:32 +01001300 global_memory_version_ =
1301 gvn_->LookupValue(kInvokeMemoryVersionBumpOp, 0u, 0u, mir->offset);
1302 // All static fields and instance fields and array elements of aliasing references,
1303 // including escaped references, may have been modified.
1304 sfield_value_map_.clear();
1305 aliasing_ifield_value_map_.clear();
1306 aliasing_array_value_map_.clear();
1307 escaped_refs_.clear();
1308 escaped_ifield_clobber_set_.clear();
1309 escaped_array_clobber_set_.clear();
Vladimir Markof418f322014-07-09 14:45:36 +01001310}
1311
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001312uint16_t LocalValueNumbering::GetValueNumber(MIR* mir) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001313 uint16_t res = kNoValue;
buzbee2502e002012-12-31 16:05:53 -08001314 uint16_t opcode = mir->dalvikInsn.opcode;
1315 switch (opcode) {
1316 case Instruction::NOP:
1317 case Instruction::RETURN_VOID:
1318 case Instruction::RETURN:
1319 case Instruction::RETURN_OBJECT:
1320 case Instruction::RETURN_WIDE:
buzbee2502e002012-12-31 16:05:53 -08001321 case Instruction::GOTO:
1322 case Instruction::GOTO_16:
1323 case Instruction::GOTO_32:
1324 case Instruction::CHECK_CAST:
1325 case Instruction::THROW:
1326 case Instruction::FILL_ARRAY_DATA:
buzbee2502e002012-12-31 16:05:53 -08001327 case Instruction::PACKED_SWITCH:
1328 case Instruction::SPARSE_SWITCH:
1329 case Instruction::IF_EQ:
1330 case Instruction::IF_NE:
1331 case Instruction::IF_LT:
1332 case Instruction::IF_GE:
1333 case Instruction::IF_GT:
1334 case Instruction::IF_LE:
1335 case Instruction::IF_EQZ:
1336 case Instruction::IF_NEZ:
1337 case Instruction::IF_LTZ:
1338 case Instruction::IF_GEZ:
1339 case Instruction::IF_GTZ:
1340 case Instruction::IF_LEZ:
buzbee2502e002012-12-31 16:05:53 -08001341 case kMirOpFusedCmplFloat:
1342 case kMirOpFusedCmpgFloat:
1343 case kMirOpFusedCmplDouble:
1344 case kMirOpFusedCmpgDouble:
1345 case kMirOpFusedCmpLong:
1346 // Nothing defined - take no action.
1347 break;
1348
Vladimir Marko95a05972014-05-30 10:01:32 +01001349 case Instruction::MONITOR_ENTER:
1350 HandleNullCheck(mir, GetOperandValue(mir->ssa_rep->uses[0]));
1351 // NOTE: Keeping all aliasing values intact. Programs that rely on loads/stores of the
1352 // same non-volatile locations outside and inside a synchronized block being different
1353 // contain races that we cannot fix.
1354 break;
1355
1356 case Instruction::MONITOR_EXIT:
1357 HandleNullCheck(mir, GetOperandValue(mir->ssa_rep->uses[0]));
1358 // If we're running GVN and CanModify(), uneliminated null check indicates bytecode error.
1359 if ((gvn_->cu_->disable_opt & (1 << kGlobalValueNumbering)) == 0 && gvn_->CanModify() &&
1360 (mir->optimization_flags & MIR_IGNORE_NULL_CHECK) == 0) {
1361 LOG(WARNING) << "Bytecode error: MONITOR_EXIT is still null checked at 0x" << std::hex
1362 << mir->offset << " in " << PrettyMethod(gvn_->cu_->method_idx, *gvn_->cu_->dex_file);
1363 }
1364 break;
1365
Vladimir Markof59f18b2014-02-17 15:53:57 +00001366 case Instruction::FILLED_NEW_ARRAY:
1367 case Instruction::FILLED_NEW_ARRAY_RANGE:
1368 // Nothing defined but the result will be unique and non-null.
1369 if (mir->next != nullptr && mir->next->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) {
Vladimir Marko95a05972014-05-30 10:01:32 +01001370 uint16_t array = MarkNonAliasingNonNull(mir->next);
1371 // Do not SetOperandValue(), we'll do that when we process the MOVE_RESULT_OBJECT.
1372 if (kLocalValueNumberingEnableFilledNewArrayTracking && mir->ssa_rep->num_uses != 0u) {
1373 AliasingValues* values = GetAliasingValues(&non_aliasing_array_value_map_, array);
1374 // Clear the value if we got a merged version in a loop.
1375 *values = AliasingValues(gvn_->allocator_);
1376 for (size_t i = 0u, count = mir->ssa_rep->num_uses; i != count; ++i) {
1377 DCHECK_EQ(High16Bits(i), 0u);
1378 uint16_t index = gvn_->LookupValue(Instruction::CONST, i, 0u, 0);
1379 uint16_t value = GetOperandValue(mir->ssa_rep->uses[i]);
1380 values->load_value_map.Put(index, value);
1381 RangeCheckKey key = { array, index };
1382 range_checked_.insert(key);
1383 }
1384 }
Vladimir Markof59f18b2014-02-17 15:53:57 +00001385 // The MOVE_RESULT_OBJECT will be processed next and we'll return the value name then.
1386 }
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001387 // All args escaped (if references).
1388 for (size_t i = 0u, count = mir->ssa_rep->num_uses; i != count; ++i) {
1389 uint16_t reg = GetOperandValue(mir->ssa_rep->uses[i]);
1390 HandleEscapingRef(reg);
1391 }
Vladimir Markof59f18b2014-02-17 15:53:57 +00001392 break;
1393
1394 case Instruction::INVOKE_DIRECT:
1395 case Instruction::INVOKE_DIRECT_RANGE:
1396 case Instruction::INVOKE_VIRTUAL:
1397 case Instruction::INVOKE_VIRTUAL_RANGE:
1398 case Instruction::INVOKE_SUPER:
1399 case Instruction::INVOKE_SUPER_RANGE:
1400 case Instruction::INVOKE_INTERFACE:
1401 case Instruction::INVOKE_INTERFACE_RANGE: {
1402 // Nothing defined but handle the null check.
1403 uint16_t reg = GetOperandValue(mir->ssa_rep->uses[0]);
1404 HandleNullCheck(mir, reg);
1405 }
1406 // Intentional fall-through.
1407 case Instruction::INVOKE_STATIC:
1408 case Instruction::INVOKE_STATIC_RANGE:
Vladimir Marko9820b7c2014-01-02 16:40:37 +00001409 if ((mir->optimization_flags & MIR_INLINED) == 0) {
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001410 // Make ref args aliasing.
1411 for (size_t i = 0u, count = mir->ssa_rep->num_uses; i != count; ++i) {
1412 uint16_t reg = GetOperandValue(mir->ssa_rep->uses[i]);
1413 non_aliasing_refs_.erase(reg);
1414 }
Vladimir Markof418f322014-07-09 14:45:36 +01001415 HandleInvokeOrClInit(mir);
Vladimir Marko9820b7c2014-01-02 16:40:37 +00001416 }
Vladimir Markof59f18b2014-02-17 15:53:57 +00001417 break;
1418
buzbee2502e002012-12-31 16:05:53 -08001419 case Instruction::MOVE_RESULT:
1420 case Instruction::MOVE_RESULT_OBJECT:
1421 case Instruction::INSTANCE_OF:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001422 // 1 result, treat as unique each time, use result s_reg - will be unique.
1423 res = GetOperandValue(mir->ssa_rep->defs[0]);
1424 SetOperandValue(mir->ssa_rep->defs[0], res);
1425 break;
1426 case Instruction::MOVE_EXCEPTION:
buzbee2502e002012-12-31 16:05:53 -08001427 case Instruction::NEW_INSTANCE:
buzbee2502e002012-12-31 16:05:53 -08001428 case Instruction::CONST_CLASS:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001429 case Instruction::NEW_ARRAY:
Vladimir Markob3e527b2014-04-04 12:37:07 +01001430 // 1 result, treat as unique each time, use result s_reg - will be unique.
1431 res = MarkNonAliasingNonNull(mir);
Vladimir Marko95a05972014-05-30 10:01:32 +01001432 SetOperandValue(mir->ssa_rep->defs[0], res);
buzbee2502e002012-12-31 16:05:53 -08001433 break;
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001434 case Instruction::CONST_STRING:
1435 case Instruction::CONST_STRING_JUMBO:
1436 // These strings are internalized, so assign value based on the string pool index.
Vladimir Marko95a05972014-05-30 10:01:32 +01001437 res = gvn_->LookupValue(Instruction::CONST_STRING, Low16Bits(mir->dalvikInsn.vB),
1438 High16Bits(mir->dalvikInsn.vB), 0);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001439 SetOperandValue(mir->ssa_rep->defs[0], res);
1440 null_checked_.insert(res); // May already be there.
1441 // NOTE: Hacking the contents of an internalized string via reflection is possible
1442 // but the behavior is undefined. Therefore, we consider the string constant and
1443 // the reference non-aliasing.
1444 // TUNING: We could keep this property even if the reference "escapes".
1445 non_aliasing_refs_.insert(res); // May already be there.
1446 break;
Vladimir Markof59f18b2014-02-17 15:53:57 +00001447 case Instruction::MOVE_RESULT_WIDE:
Vladimir Markob3e527b2014-04-04 12:37:07 +01001448 // 1 wide result, treat as unique each time, use result s_reg - will be unique.
1449 res = GetOperandValueWide(mir->ssa_rep->defs[0]);
1450 SetOperandValueWide(mir->ssa_rep->defs[0], res);
buzbee2502e002012-12-31 16:05:53 -08001451 break;
1452
1453 case kMirOpPhi:
Vladimir Marko95a05972014-05-30 10:01:32 +01001454 res = HandlePhi(mir);
buzbee2502e002012-12-31 16:05:53 -08001455 break;
1456
1457 case Instruction::MOVE:
1458 case Instruction::MOVE_OBJECT:
1459 case Instruction::MOVE_16:
1460 case Instruction::MOVE_OBJECT_16:
1461 case Instruction::MOVE_FROM16:
1462 case Instruction::MOVE_OBJECT_FROM16:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001463 case kMirOpCopy:
1464 // Just copy value number of source to value number of result.
1465 res = GetOperandValue(mir->ssa_rep->uses[0]);
1466 SetOperandValue(mir->ssa_rep->defs[0], res);
buzbee2502e002012-12-31 16:05:53 -08001467 break;
1468
1469 case Instruction::MOVE_WIDE:
1470 case Instruction::MOVE_WIDE_16:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001471 case Instruction::MOVE_WIDE_FROM16:
1472 // Just copy value number of source to value number of result.
1473 res = GetOperandValueWide(mir->ssa_rep->uses[0]);
1474 SetOperandValueWide(mir->ssa_rep->defs[0], res);
buzbee2502e002012-12-31 16:05:53 -08001475 break;
1476
1477 case Instruction::CONST:
1478 case Instruction::CONST_4:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001479 case Instruction::CONST_16:
Vladimir Marko95a05972014-05-30 10:01:32 +01001480 res = gvn_->LookupValue(Instruction::CONST, Low16Bits(mir->dalvikInsn.vB),
1481 High16Bits(mir->dalvikInsn.vB), 0);
Vladimir Markof59f18b2014-02-17 15:53:57 +00001482 SetOperandValue(mir->ssa_rep->defs[0], res);
buzbee2502e002012-12-31 16:05:53 -08001483 break;
1484
Vladimir Markof59f18b2014-02-17 15:53:57 +00001485 case Instruction::CONST_HIGH16:
Vladimir Marko95a05972014-05-30 10:01:32 +01001486 res = gvn_->LookupValue(Instruction::CONST, 0, mir->dalvikInsn.vB, 0);
Vladimir Markof59f18b2014-02-17 15:53:57 +00001487 SetOperandValue(mir->ssa_rep->defs[0], res);
buzbee2502e002012-12-31 16:05:53 -08001488 break;
1489
1490 case Instruction::CONST_WIDE_16:
1491 case Instruction::CONST_WIDE_32: {
Vladimir Marko95a05972014-05-30 10:01:32 +01001492 uint16_t low_res = gvn_->LookupValue(Instruction::CONST, Low16Bits(mir->dalvikInsn.vB),
1493 High16Bits(mir->dalvikInsn.vB >> 16), 1);
buzbee2502e002012-12-31 16:05:53 -08001494 uint16_t high_res;
1495 if (mir->dalvikInsn.vB & 0x80000000) {
Vladimir Marko95a05972014-05-30 10:01:32 +01001496 high_res = gvn_->LookupValue(Instruction::CONST, 0xffff, 0xffff, 2);
buzbee2502e002012-12-31 16:05:53 -08001497 } else {
Vladimir Marko95a05972014-05-30 10:01:32 +01001498 high_res = gvn_->LookupValue(Instruction::CONST, 0, 0, 2);
buzbee2502e002012-12-31 16:05:53 -08001499 }
Vladimir Marko95a05972014-05-30 10:01:32 +01001500 res = gvn_->LookupValue(Instruction::CONST, low_res, high_res, 3);
Vladimir Markof59f18b2014-02-17 15:53:57 +00001501 SetOperandValueWide(mir->ssa_rep->defs[0], res);
buzbee2502e002012-12-31 16:05:53 -08001502 }
1503 break;
1504
1505 case Instruction::CONST_WIDE: {
1506 uint32_t low_word = Low32Bits(mir->dalvikInsn.vB_wide);
1507 uint32_t high_word = High32Bits(mir->dalvikInsn.vB_wide);
Vladimir Marko95a05972014-05-30 10:01:32 +01001508 uint16_t low_res = gvn_->LookupValue(Instruction::CONST, Low16Bits(low_word),
1509 High16Bits(low_word), 1);
1510 uint16_t high_res = gvn_->LookupValue(Instruction::CONST, Low16Bits(high_word),
1511 High16Bits(high_word), 2);
1512 res = gvn_->LookupValue(Instruction::CONST, low_res, high_res, 3);
buzbee2502e002012-12-31 16:05:53 -08001513 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1514 }
1515 break;
1516
1517 case Instruction::CONST_WIDE_HIGH16: {
Vladimir Marko95a05972014-05-30 10:01:32 +01001518 uint16_t low_res = gvn_->LookupValue(Instruction::CONST, 0, 0, 1);
1519 uint16_t high_res = gvn_->LookupValue(Instruction::CONST, 0,
1520 Low16Bits(mir->dalvikInsn.vB), 2);
1521 res = gvn_->LookupValue(Instruction::CONST, low_res, high_res, 3);
buzbee2502e002012-12-31 16:05:53 -08001522 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1523 }
1524 break;
1525
Vladimir Marko95a05972014-05-30 10:01:32 +01001526 case Instruction::ARRAY_LENGTH: {
1527 // Handle the null check.
1528 uint16_t reg = GetOperandValue(mir->ssa_rep->uses[0]);
1529 HandleNullCheck(mir, reg);
1530 }
1531 // Intentional fall-through.
buzbee2502e002012-12-31 16:05:53 -08001532 case Instruction::NEG_INT:
1533 case Instruction::NOT_INT:
1534 case Instruction::NEG_FLOAT:
1535 case Instruction::INT_TO_BYTE:
1536 case Instruction::INT_TO_SHORT:
1537 case Instruction::INT_TO_CHAR:
1538 case Instruction::INT_TO_FLOAT:
1539 case Instruction::FLOAT_TO_INT: {
1540 // res = op + 1 operand
1541 uint16_t operand1 = GetOperandValue(mir->ssa_rep->uses[0]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001542 res = gvn_->LookupValue(opcode, operand1, kNoValue, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001543 SetOperandValue(mir->ssa_rep->defs[0], res);
1544 }
1545 break;
1546
1547 case Instruction::LONG_TO_FLOAT:
1548 case Instruction::LONG_TO_INT:
1549 case Instruction::DOUBLE_TO_FLOAT:
1550 case Instruction::DOUBLE_TO_INT: {
1551 // res = op + 1 wide operand
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001552 uint16_t operand1 = GetOperandValueWide(mir->ssa_rep->uses[0]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001553 res = gvn_->LookupValue(opcode, operand1, kNoValue, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001554 SetOperandValue(mir->ssa_rep->defs[0], res);
1555 }
1556 break;
1557
1558
1559 case Instruction::DOUBLE_TO_LONG:
1560 case Instruction::LONG_TO_DOUBLE:
1561 case Instruction::NEG_LONG:
1562 case Instruction::NOT_LONG:
1563 case Instruction::NEG_DOUBLE: {
1564 // wide res = op + 1 wide operand
1565 uint16_t operand1 = GetOperandValueWide(mir->ssa_rep->uses[0]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001566 res = gvn_->LookupValue(opcode, operand1, kNoValue, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001567 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1568 }
1569 break;
1570
1571 case Instruction::FLOAT_TO_DOUBLE:
1572 case Instruction::FLOAT_TO_LONG:
1573 case Instruction::INT_TO_DOUBLE:
1574 case Instruction::INT_TO_LONG: {
1575 // wide res = op + 1 operand
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001576 uint16_t operand1 = GetOperandValue(mir->ssa_rep->uses[0]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001577 res = gvn_->LookupValue(opcode, operand1, kNoValue, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001578 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1579 }
1580 break;
1581
1582 case Instruction::CMPL_DOUBLE:
1583 case Instruction::CMPG_DOUBLE:
1584 case Instruction::CMP_LONG: {
1585 // res = op + 2 wide operands
1586 uint16_t operand1 = GetOperandValueWide(mir->ssa_rep->uses[0]);
1587 uint16_t operand2 = GetOperandValueWide(mir->ssa_rep->uses[2]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001588 res = gvn_->LookupValue(opcode, operand1, operand2, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001589 SetOperandValue(mir->ssa_rep->defs[0], res);
1590 }
1591 break;
1592
1593 case Instruction::CMPG_FLOAT:
1594 case Instruction::CMPL_FLOAT:
1595 case Instruction::ADD_INT:
1596 case Instruction::ADD_INT_2ADDR:
1597 case Instruction::MUL_INT:
1598 case Instruction::MUL_INT_2ADDR:
1599 case Instruction::AND_INT:
1600 case Instruction::AND_INT_2ADDR:
1601 case Instruction::OR_INT:
1602 case Instruction::OR_INT_2ADDR:
1603 case Instruction::XOR_INT:
1604 case Instruction::XOR_INT_2ADDR:
1605 case Instruction::SUB_INT:
1606 case Instruction::SUB_INT_2ADDR:
1607 case Instruction::DIV_INT:
1608 case Instruction::DIV_INT_2ADDR:
1609 case Instruction::REM_INT:
1610 case Instruction::REM_INT_2ADDR:
1611 case Instruction::SHL_INT:
1612 case Instruction::SHL_INT_2ADDR:
1613 case Instruction::SHR_INT:
1614 case Instruction::SHR_INT_2ADDR:
1615 case Instruction::USHR_INT:
1616 case Instruction::USHR_INT_2ADDR: {
1617 // res = op + 2 operands
1618 uint16_t operand1 = GetOperandValue(mir->ssa_rep->uses[0]);
1619 uint16_t operand2 = GetOperandValue(mir->ssa_rep->uses[1]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001620 res = gvn_->LookupValue(opcode, operand1, operand2, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001621 SetOperandValue(mir->ssa_rep->defs[0], res);
1622 }
1623 break;
1624
1625 case Instruction::ADD_LONG:
1626 case Instruction::SUB_LONG:
1627 case Instruction::MUL_LONG:
1628 case Instruction::DIV_LONG:
1629 case Instruction::REM_LONG:
1630 case Instruction::AND_LONG:
1631 case Instruction::OR_LONG:
1632 case Instruction::XOR_LONG:
1633 case Instruction::ADD_LONG_2ADDR:
1634 case Instruction::SUB_LONG_2ADDR:
1635 case Instruction::MUL_LONG_2ADDR:
1636 case Instruction::DIV_LONG_2ADDR:
1637 case Instruction::REM_LONG_2ADDR:
1638 case Instruction::AND_LONG_2ADDR:
1639 case Instruction::OR_LONG_2ADDR:
1640 case Instruction::XOR_LONG_2ADDR:
1641 case Instruction::ADD_DOUBLE:
1642 case Instruction::SUB_DOUBLE:
1643 case Instruction::MUL_DOUBLE:
1644 case Instruction::DIV_DOUBLE:
1645 case Instruction::REM_DOUBLE:
1646 case Instruction::ADD_DOUBLE_2ADDR:
1647 case Instruction::SUB_DOUBLE_2ADDR:
1648 case Instruction::MUL_DOUBLE_2ADDR:
1649 case Instruction::DIV_DOUBLE_2ADDR:
1650 case Instruction::REM_DOUBLE_2ADDR: {
1651 // wide res = op + 2 wide operands
1652 uint16_t operand1 = GetOperandValueWide(mir->ssa_rep->uses[0]);
1653 uint16_t operand2 = GetOperandValueWide(mir->ssa_rep->uses[2]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001654 res = gvn_->LookupValue(opcode, operand1, operand2, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001655 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1656 }
1657 break;
1658
1659 case Instruction::SHL_LONG:
1660 case Instruction::SHR_LONG:
1661 case Instruction::USHR_LONG:
1662 case Instruction::SHL_LONG_2ADDR:
1663 case Instruction::SHR_LONG_2ADDR:
1664 case Instruction::USHR_LONG_2ADDR: {
1665 // wide res = op + 1 wide operand + 1 operand
1666 uint16_t operand1 = GetOperandValueWide(mir->ssa_rep->uses[0]);
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001667 uint16_t operand2 = GetOperandValue(mir->ssa_rep->uses[2]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001668 res = gvn_->LookupValue(opcode, operand1, operand2, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001669 SetOperandValueWide(mir->ssa_rep->defs[0], res);
1670 }
1671 break;
1672
1673 case Instruction::ADD_FLOAT:
1674 case Instruction::SUB_FLOAT:
1675 case Instruction::MUL_FLOAT:
1676 case Instruction::DIV_FLOAT:
1677 case Instruction::REM_FLOAT:
1678 case Instruction::ADD_FLOAT_2ADDR:
1679 case Instruction::SUB_FLOAT_2ADDR:
1680 case Instruction::MUL_FLOAT_2ADDR:
1681 case Instruction::DIV_FLOAT_2ADDR:
1682 case Instruction::REM_FLOAT_2ADDR: {
1683 // res = op + 2 operands
1684 uint16_t operand1 = GetOperandValue(mir->ssa_rep->uses[0]);
1685 uint16_t operand2 = GetOperandValue(mir->ssa_rep->uses[1]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001686 res = gvn_->LookupValue(opcode, operand1, operand2, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001687 SetOperandValue(mir->ssa_rep->defs[0], res);
1688 }
1689 break;
1690
1691 case Instruction::RSUB_INT:
1692 case Instruction::ADD_INT_LIT16:
1693 case Instruction::MUL_INT_LIT16:
1694 case Instruction::DIV_INT_LIT16:
1695 case Instruction::REM_INT_LIT16:
1696 case Instruction::AND_INT_LIT16:
1697 case Instruction::OR_INT_LIT16:
1698 case Instruction::XOR_INT_LIT16:
1699 case Instruction::ADD_INT_LIT8:
1700 case Instruction::RSUB_INT_LIT8:
1701 case Instruction::MUL_INT_LIT8:
1702 case Instruction::DIV_INT_LIT8:
1703 case Instruction::REM_INT_LIT8:
1704 case Instruction::AND_INT_LIT8:
1705 case Instruction::OR_INT_LIT8:
1706 case Instruction::XOR_INT_LIT8:
1707 case Instruction::SHL_INT_LIT8:
1708 case Instruction::SHR_INT_LIT8:
1709 case Instruction::USHR_INT_LIT8: {
nikolay serdjukee40aa42014-03-25 12:21:29 +07001710 // Same as res = op + 2 operands, except use vC as operand 2
buzbee2502e002012-12-31 16:05:53 -08001711 uint16_t operand1 = GetOperandValue(mir->ssa_rep->uses[0]);
Vladimir Marko95a05972014-05-30 10:01:32 +01001712 uint16_t operand2 = gvn_->LookupValue(Instruction::CONST, mir->dalvikInsn.vC, 0, 0);
1713 res = gvn_->LookupValue(opcode, operand1, operand2, kNoValue);
buzbee2502e002012-12-31 16:05:53 -08001714 SetOperandValue(mir->ssa_rep->defs[0], res);
1715 }
1716 break;
1717
buzbee2502e002012-12-31 16:05:53 -08001718 case Instruction::AGET_OBJECT:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001719 case Instruction::AGET:
1720 case Instruction::AGET_WIDE:
buzbee2502e002012-12-31 16:05:53 -08001721 case Instruction::AGET_BOOLEAN:
1722 case Instruction::AGET_BYTE:
1723 case Instruction::AGET_CHAR:
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001724 case Instruction::AGET_SHORT:
1725 res = HandleAGet(mir, opcode);
buzbee2502e002012-12-31 16:05:53 -08001726 break;
1727
buzbee2502e002012-12-31 16:05:53 -08001728 case Instruction::APUT_OBJECT:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001729 HandlePutObject(mir);
1730 // Intentional fall-through.
1731 case Instruction::APUT:
1732 case Instruction::APUT_WIDE:
buzbee2502e002012-12-31 16:05:53 -08001733 case Instruction::APUT_BYTE:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001734 case Instruction::APUT_BOOLEAN:
1735 case Instruction::APUT_SHORT:
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001736 case Instruction::APUT_CHAR:
1737 HandleAPut(mir, opcode);
buzbee2502e002012-12-31 16:05:53 -08001738 break;
1739
1740 case Instruction::IGET_OBJECT:
buzbee2502e002012-12-31 16:05:53 -08001741 case Instruction::IGET:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001742 case Instruction::IGET_WIDE:
buzbee2502e002012-12-31 16:05:53 -08001743 case Instruction::IGET_BOOLEAN:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001744 case Instruction::IGET_BYTE:
1745 case Instruction::IGET_CHAR:
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001746 case Instruction::IGET_SHORT:
1747 res = HandleIGet(mir, opcode);
buzbee2502e002012-12-31 16:05:53 -08001748 break;
1749
buzbee2502e002012-12-31 16:05:53 -08001750 case Instruction::IPUT_OBJECT:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001751 HandlePutObject(mir);
1752 // Intentional fall-through.
buzbee2502e002012-12-31 16:05:53 -08001753 case Instruction::IPUT:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001754 case Instruction::IPUT_WIDE:
buzbee2502e002012-12-31 16:05:53 -08001755 case Instruction::IPUT_BOOLEAN:
1756 case Instruction::IPUT_BYTE:
1757 case Instruction::IPUT_CHAR:
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001758 case Instruction::IPUT_SHORT:
1759 HandleIPut(mir, opcode);
buzbee2502e002012-12-31 16:05:53 -08001760 break;
1761
1762 case Instruction::SGET_OBJECT:
1763 case Instruction::SGET:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001764 case Instruction::SGET_WIDE:
buzbee2502e002012-12-31 16:05:53 -08001765 case Instruction::SGET_BOOLEAN:
1766 case Instruction::SGET_BYTE:
1767 case Instruction::SGET_CHAR:
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001768 case Instruction::SGET_SHORT:
1769 res = HandleSGet(mir, opcode);
buzbee2502e002012-12-31 16:05:53 -08001770 break;
1771
1772 case Instruction::SPUT_OBJECT:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001773 HandlePutObject(mir);
1774 // Intentional fall-through.
buzbee2502e002012-12-31 16:05:53 -08001775 case Instruction::SPUT:
Vladimir Markof59f18b2014-02-17 15:53:57 +00001776 case Instruction::SPUT_WIDE:
buzbee2502e002012-12-31 16:05:53 -08001777 case Instruction::SPUT_BOOLEAN:
1778 case Instruction::SPUT_BYTE:
1779 case Instruction::SPUT_CHAR:
Vladimir Marko2ac01fc2014-05-22 12:09:08 +01001780 case Instruction::SPUT_SHORT:
1781 HandleSPut(mir, opcode);
buzbee2502e002012-12-31 16:05:53 -08001782 break;
buzbee2502e002012-12-31 16:05:53 -08001783 }
1784 return res;
1785}
1786
1787} // namespace art