buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DEX_LOCAL_VALUE_NUMBERING_H_ |
| 18 | #define ART_COMPILER_DEX_LOCAL_VALUE_NUMBERING_H_ |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 19 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 20 | #include <memory> |
| 21 | |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 22 | #include "compiler_internals.h" |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 23 | #include "global_value_numbering.h" |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 24 | #include "utils/arena_object.h" |
Vladimir Marko | 321b987 | 2014-11-24 16:33:51 +0000 | [diff] [blame] | 25 | #include "utils/dex_instruction_utils.h" |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 26 | |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 27 | namespace art { |
| 28 | |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 29 | class DexFile; |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 30 | |
| 31 | // Enable/disable tracking values stored in the FILLED_NEW_ARRAY result. |
| 32 | static constexpr bool kLocalValueNumberingEnableFilledNewArrayTracking = true; |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 33 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 34 | class LocalValueNumbering : public DeletableArenaObject<kArenaAllocMisc> { |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 35 | private: |
| 36 | static constexpr uint16_t kNoValue = GlobalValueNumbering::kNoValue; |
| 37 | |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 38 | public: |
Vladimir Marko | b19955d | 2014-07-29 12:04:10 +0100 | [diff] [blame] | 39 | LocalValueNumbering(GlobalValueNumbering* gvn, BasicBlockId id, ScopedArenaAllocator* allocator); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 40 | |
| 41 | BasicBlockId Id() const { |
| 42 | return id_; |
| 43 | } |
| 44 | |
| 45 | bool Equals(const LocalValueNumbering& other) const; |
| 46 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 47 | bool IsValueNullChecked(uint16_t value_name) const { |
| 48 | return null_checked_.find(value_name) != null_checked_.end(); |
| 49 | } |
| 50 | |
Razvan A Lupusoru | e095114 | 2014-11-14 14:36:55 -0800 | [diff] [blame] | 51 | bool IsValueDivZeroChecked(uint16_t value_name) const { |
| 52 | return div_zero_checked_.find(value_name) != div_zero_checked_.end(); |
| 53 | } |
| 54 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 55 | bool IsSregValue(uint16_t s_reg, uint16_t value_name) const { |
| 56 | auto it = sreg_value_map_.find(s_reg); |
| 57 | if (it != sreg_value_map_.end()) { |
| 58 | return it->second == value_name; |
| 59 | } else { |
| 60 | return gvn_->HasValue(kNoValue, s_reg, kNoValue, kNoValue, value_name); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | enum MergeType { |
| 65 | kNormalMerge, |
| 66 | kCatchMerge, |
| 67 | kReturnMerge, // RETURN or PHI+RETURN. Merge only sreg maps. |
| 68 | }; |
| 69 | |
| 70 | void MergeOne(const LocalValueNumbering& other, MergeType merge_type); |
| 71 | void Merge(MergeType merge_type); // Merge gvn_->merge_lvns_. |
Vladimir Marko | a4426cf | 2014-10-22 17:15:53 +0100 | [diff] [blame] | 72 | void PrepareEntryBlock(); |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 73 | |
| 74 | uint16_t GetValueNumber(MIR* mir); |
| 75 | |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 76 | private: |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 77 | // A set of value names. |
| 78 | typedef GlobalValueNumbering::ValueNameSet ValueNameSet; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 79 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 80 | // Key is s_reg, value is value name. |
| 81 | typedef ScopedArenaSafeMap<uint16_t, uint16_t> SregValueMap; |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 82 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 83 | void SetOperandValueImpl(uint16_t s_reg, uint16_t value, SregValueMap* map) { |
| 84 | DCHECK_EQ(map->count(s_reg), 0u) << PrettyMethod(gvn_->cu_->method_idx, *gvn_->cu_->dex_file) |
| 85 | << " LVN id: " << id_ << ", s_reg: " << s_reg; |
| 86 | map->Put(s_reg, value); |
| 87 | } |
| 88 | |
| 89 | uint16_t GetOperandValueImpl(int s_reg, const SregValueMap* map) const { |
| 90 | uint16_t res = kNoValue; |
| 91 | auto lb = map->find(s_reg); |
| 92 | if (lb != map->end()) { |
| 93 | res = lb->second; |
| 94 | } else { |
| 95 | // Using the original value; s_reg refers to an input reg. |
| 96 | res = gvn_->LookupValue(kNoValue, s_reg, kNoValue, kNoValue); |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 97 | } |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 98 | return res; |
| 99 | } |
| 100 | |
| 101 | void SetOperandValue(uint16_t s_reg, uint16_t value) { |
Vladimir Marko | a4426cf | 2014-10-22 17:15:53 +0100 | [diff] [blame] | 102 | DCHECK_EQ(sreg_wide_value_map_.count(s_reg), 0u); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 103 | SetOperandValueImpl(s_reg, value, &sreg_value_map_); |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 104 | } |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 105 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 106 | uint16_t GetOperandValue(int s_reg) const { |
Vladimir Marko | a4426cf | 2014-10-22 17:15:53 +0100 | [diff] [blame] | 107 | DCHECK_EQ(sreg_wide_value_map_.count(s_reg), 0u); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 108 | return GetOperandValueImpl(s_reg, &sreg_value_map_); |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 109 | } |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 110 | |
| 111 | void SetOperandValueWide(uint16_t s_reg, uint16_t value) { |
Vladimir Marko | a4426cf | 2014-10-22 17:15:53 +0100 | [diff] [blame] | 112 | DCHECK_EQ(sreg_value_map_.count(s_reg), 0u); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 113 | SetOperandValueImpl(s_reg, value, &sreg_wide_value_map_); |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 114 | } |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 115 | |
| 116 | uint16_t GetOperandValueWide(int s_reg) const { |
Vladimir Marko | a4426cf | 2014-10-22 17:15:53 +0100 | [diff] [blame] | 117 | DCHECK_EQ(sreg_value_map_.count(s_reg), 0u); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 118 | return GetOperandValueImpl(s_reg, &sreg_wide_value_map_); |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 119 | } |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 120 | |
| 121 | struct RangeCheckKey { |
| 122 | uint16_t array; |
| 123 | uint16_t index; |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 124 | |
| 125 | // NOTE: Can't define this at namespace scope for a private struct. |
| 126 | bool operator==(const RangeCheckKey& other) const { |
| 127 | return array == other.array && index == other.index; |
| 128 | } |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | struct RangeCheckKeyComparator { |
| 132 | bool operator()(const RangeCheckKey& lhs, const RangeCheckKey& rhs) const { |
| 133 | if (lhs.array != rhs.array) { |
| 134 | return lhs.array < rhs.array; |
| 135 | } |
| 136 | return lhs.index < rhs.index; |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | typedef ScopedArenaSet<RangeCheckKey, RangeCheckKeyComparator> RangeCheckSet; |
| 141 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 142 | // Maps instance field "location" (derived from base, field_id and type) to value name. |
| 143 | typedef ScopedArenaSafeMap<uint16_t, uint16_t> IFieldLocToValueMap; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 144 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 145 | // Maps static field id to value name |
| 146 | typedef ScopedArenaSafeMap<uint16_t, uint16_t> SFieldToValueMap; |
| 147 | |
| 148 | struct EscapedIFieldClobberKey { |
| 149 | uint16_t base; // Or array. |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 150 | uint16_t type; |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 151 | uint16_t field_id; // None (kNoValue) for arrays and unresolved instance field stores. |
| 152 | |
| 153 | // NOTE: Can't define this at namespace scope for a private struct. |
| 154 | bool operator==(const EscapedIFieldClobberKey& other) const { |
| 155 | return base == other.base && type == other.type && field_id == other.field_id; |
| 156 | } |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 159 | struct EscapedIFieldClobberKeyComparator { |
| 160 | bool operator()(const EscapedIFieldClobberKey& lhs, const EscapedIFieldClobberKey& rhs) const { |
| 161 | // Compare base first. This makes sequential iteration respect the order of base. |
| 162 | if (lhs.base != rhs.base) { |
| 163 | return lhs.base < rhs.base; |
| 164 | } |
| 165 | // Compare type second. This makes the type-clobber entries (field_id == kNoValue) last |
| 166 | // for given base and type and makes it easy to prune unnecessary entries when merging |
| 167 | // escaped_ifield_clobber_set_ from multiple LVNs. |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 168 | if (lhs.type != rhs.type) { |
| 169 | return lhs.type < rhs.type; |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 170 | } |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 171 | return lhs.field_id < rhs.field_id; |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 172 | } |
| 173 | }; |
| 174 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 175 | typedef ScopedArenaSet<EscapedIFieldClobberKey, EscapedIFieldClobberKeyComparator> |
| 176 | EscapedIFieldClobberSet; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 177 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 178 | struct EscapedArrayClobberKey { |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 179 | uint16_t base; |
| 180 | uint16_t type; |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 181 | |
| 182 | // NOTE: Can't define this at namespace scope for a private struct. |
| 183 | bool operator==(const EscapedArrayClobberKey& other) const { |
| 184 | return base == other.base && type == other.type; |
| 185 | } |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 186 | }; |
| 187 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 188 | struct EscapedArrayClobberKeyComparator { |
| 189 | bool operator()(const EscapedArrayClobberKey& lhs, const EscapedArrayClobberKey& rhs) const { |
| 190 | // Compare base first. This makes sequential iteration respect the order of base. |
| 191 | if (lhs.base != rhs.base) { |
| 192 | return lhs.base < rhs.base; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 193 | } |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 194 | return lhs.type < rhs.type; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 195 | } |
| 196 | }; |
| 197 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 198 | // Clobber set for previously non-aliasing array refs that escaped. |
| 199 | typedef ScopedArenaSet<EscapedArrayClobberKey, EscapedArrayClobberKeyComparator> |
| 200 | EscapedArrayClobberSet; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 201 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 202 | // Known location values for an aliasing set. The set can be tied to one of: |
| 203 | // 1. Instance field. The locations are aliasing references used to access the field. |
| 204 | // 2. Non-aliasing array reference. The locations are indexes to the array. |
| 205 | // 3. Aliasing array type. The locations are (reference, index) pair ids assigned by GVN. |
| 206 | // In each case we keep track of the last stored value, if any, and the set of locations |
| 207 | // where it was stored. We also keep track of all values known for the current write state |
| 208 | // (load_value_map), which can be known either because they have been loaded since the last |
| 209 | // store or because they contained the last_stored_value before the store and thus could not |
| 210 | // have changed as a result. |
| 211 | struct AliasingValues { |
Vladimir Marko | b19955d | 2014-07-29 12:04:10 +0100 | [diff] [blame] | 212 | explicit AliasingValues(LocalValueNumbering* lvn) |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 213 | : memory_version_before_stores(kNoValue), |
| 214 | last_stored_value(kNoValue), |
Vladimir Marko | b19955d | 2014-07-29 12:04:10 +0100 | [diff] [blame] | 215 | store_loc_set(std::less<uint16_t>(), lvn->null_checked_.get_allocator()), |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 216 | last_load_memory_version(kNoValue), |
Vladimir Marko | b19955d | 2014-07-29 12:04:10 +0100 | [diff] [blame] | 217 | load_value_map(std::less<uint16_t>(), lvn->null_checked_.get_allocator()) { |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 218 | } |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 219 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 220 | uint16_t memory_version_before_stores; // kNoValue if start version for the field. |
| 221 | uint16_t last_stored_value; // Last stored value name, kNoValue if none. |
| 222 | ValueNameSet store_loc_set; // Where was last_stored_value stored. |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 223 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 224 | // Maps refs (other than stored_to) to currently known values for this field other. On write, |
| 225 | // anything that differs from the written value is removed as it may be overwritten. |
| 226 | uint16_t last_load_memory_version; // kNoValue if not known. |
| 227 | ScopedArenaSafeMap<uint16_t, uint16_t> load_value_map; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 228 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 229 | // NOTE: Can't define this at namespace scope for a private struct. |
| 230 | bool operator==(const AliasingValues& other) const { |
| 231 | return memory_version_before_stores == other.memory_version_before_stores && |
| 232 | last_load_memory_version == other.last_load_memory_version && |
| 233 | last_stored_value == other.last_stored_value && |
| 234 | store_loc_set == other.store_loc_set && |
| 235 | load_value_map == other.load_value_map; |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 236 | } |
| 237 | }; |
| 238 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 239 | // Maps instance field id to AliasingValues, locations are object refs. |
| 240 | typedef ScopedArenaSafeMap<uint16_t, AliasingValues> AliasingIFieldValuesMap; |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 241 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 242 | // Maps non-aliasing array reference to AliasingValues, locations are array indexes. |
| 243 | typedef ScopedArenaSafeMap<uint16_t, AliasingValues> NonAliasingArrayValuesMap; |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 244 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 245 | // Maps aliasing array type to AliasingValues, locations are (array, index) pair ids. |
| 246 | typedef ScopedArenaSafeMap<uint16_t, AliasingValues> AliasingArrayValuesMap; |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 247 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 248 | // Helper classes defining versions for updating and merging the AliasingValues maps above. |
| 249 | class AliasingIFieldVersions; |
| 250 | class NonAliasingArrayVersions; |
| 251 | class AliasingArrayVersions; |
| 252 | |
| 253 | template <typename Map> |
| 254 | AliasingValues* GetAliasingValues(Map* map, const typename Map::key_type& key); |
| 255 | |
| 256 | template <typename Versions, typename KeyType> |
| 257 | void UpdateAliasingValuesLoadVersion(const KeyType& key, AliasingValues* values); |
| 258 | |
| 259 | template <typename Versions, typename Map> |
| 260 | static uint16_t AliasingValuesMergeGet(GlobalValueNumbering* gvn, |
| 261 | const LocalValueNumbering* lvn, |
| 262 | Map* map, const typename Map::key_type& key, |
| 263 | uint16_t location); |
| 264 | |
| 265 | template <typename Versions, typename Map> |
| 266 | uint16_t HandleAliasingValuesGet(Map* map, const typename Map::key_type& key, |
| 267 | uint16_t location); |
| 268 | |
| 269 | template <typename Versions, typename Map> |
| 270 | bool HandleAliasingValuesPut(Map* map, const typename Map::key_type& key, |
| 271 | uint16_t location, uint16_t value); |
| 272 | |
Vladimir Marko | b19955d | 2014-07-29 12:04:10 +0100 | [diff] [blame] | 273 | template <typename K> |
| 274 | void CopyAliasingValuesMap(ScopedArenaSafeMap<K, AliasingValues>* dest, |
| 275 | const ScopedArenaSafeMap<K, AliasingValues>& src); |
| 276 | |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 277 | uint16_t MarkNonAliasingNonNull(MIR* mir); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 278 | bool IsNonAliasing(uint16_t reg) const; |
| 279 | bool IsNonAliasingIField(uint16_t reg, uint16_t field_id, uint16_t type) const; |
| 280 | bool IsNonAliasingArray(uint16_t reg, uint16_t type) const; |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 281 | void HandleNullCheck(MIR* mir, uint16_t reg); |
| 282 | void HandleRangeCheck(MIR* mir, uint16_t array, uint16_t index); |
Razvan A Lupusoru | e095114 | 2014-11-14 14:36:55 -0800 | [diff] [blame] | 283 | void HandleDivZeroCheck(MIR* mir, uint16_t reg); |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 284 | void HandlePutObject(MIR* mir); |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 285 | void HandleEscapingRef(uint16_t base); |
Vladimir Marko | a4426cf | 2014-10-22 17:15:53 +0100 | [diff] [blame] | 286 | void HandleInvokeArgs(const MIR* mir, const LocalValueNumbering* mir_lvn); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 287 | uint16_t HandlePhi(MIR* mir); |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 288 | uint16_t HandleAGet(MIR* mir, uint16_t opcode); |
| 289 | void HandleAPut(MIR* mir, uint16_t opcode); |
| 290 | uint16_t HandleIGet(MIR* mir, uint16_t opcode); |
| 291 | void HandleIPut(MIR* mir, uint16_t opcode); |
| 292 | uint16_t HandleSGet(MIR* mir, uint16_t opcode); |
| 293 | void HandleSPut(MIR* mir, uint16_t opcode); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 294 | void RemoveSFieldsForType(uint16_t type); |
Vladimir Marko | fa23645 | 2014-09-29 17:58:10 +0100 | [diff] [blame] | 295 | void HandleInvokeOrClInitOrAcquireOp(MIR* mir); |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 296 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 297 | bool SameMemoryVersion(const LocalValueNumbering& other) const; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 298 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 299 | uint16_t NewMemoryVersion(uint16_t* new_version); |
| 300 | void MergeMemoryVersions(bool clobbered_catch); |
| 301 | |
| 302 | void PruneNonAliasingRefsForCatch(); |
| 303 | |
| 304 | template <typename Set, Set LocalValueNumbering::* set_ptr> |
| 305 | void IntersectSets(); |
| 306 | |
Vladimir Marko | b19955d | 2014-07-29 12:04:10 +0100 | [diff] [blame] | 307 | void CopyLiveSregValues(SregValueMap* dest, const SregValueMap& src); |
| 308 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 309 | // Intersect maps as sets. The value type must be equality-comparable. |
Vladimir Marko | b19955d | 2014-07-29 12:04:10 +0100 | [diff] [blame] | 310 | template <SregValueMap LocalValueNumbering::* map_ptr> |
| 311 | void IntersectSregValueMaps(); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 312 | |
| 313 | // Intersect maps as sets. The value type must be equality-comparable. |
| 314 | template <typename Map> |
| 315 | static void InPlaceIntersectMaps(Map* work_map, const Map& other_map); |
| 316 | |
| 317 | template <typename Set, Set LocalValueNumbering::*set_ptr, void (LocalValueNumbering::*MergeFn)( |
| 318 | const typename Set::value_type& entry, typename Set::iterator hint)> |
| 319 | void MergeSets(); |
| 320 | |
| 321 | void IntersectAliasingValueLocations(AliasingValues* work_values, const AliasingValues* values); |
| 322 | |
| 323 | void MergeEscapedRefs(const ValueNameSet::value_type& entry, ValueNameSet::iterator hint); |
| 324 | void MergeEscapedIFieldTypeClobberSets(const EscapedIFieldClobberSet::value_type& entry, |
| 325 | EscapedIFieldClobberSet::iterator hint); |
| 326 | void MergeEscapedIFieldClobberSets(const EscapedIFieldClobberSet::value_type& entry, |
| 327 | EscapedIFieldClobberSet::iterator hint); |
| 328 | void MergeEscapedArrayClobberSets(const EscapedArrayClobberSet::value_type& entry, |
| 329 | EscapedArrayClobberSet::iterator hint); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 330 | void MergeSFieldValues(const SFieldToValueMap::value_type& entry, |
| 331 | SFieldToValueMap::iterator hint); |
| 332 | void MergeNonAliasingIFieldValues(const IFieldLocToValueMap::value_type& entry, |
| 333 | IFieldLocToValueMap::iterator hint); |
Vladimir Marko | 2d2365c | 2014-08-19 18:08:39 +0100 | [diff] [blame] | 334 | void MergeNullChecked(); |
Razvan A Lupusoru | e095114 | 2014-11-14 14:36:55 -0800 | [diff] [blame] | 335 | void MergeDivZeroChecked(); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 336 | |
| 337 | template <typename Map, Map LocalValueNumbering::*map_ptr, typename Versions> |
| 338 | void MergeAliasingValues(const typename Map::value_type& entry, typename Map::iterator hint); |
| 339 | |
| 340 | GlobalValueNumbering* gvn_; |
| 341 | |
| 342 | // We're using the block id as a 16-bit operand value for some lookups. |
Andreas Gampe | 785d2f2 | 2014-11-03 22:57:30 -0800 | [diff] [blame] | 343 | static_assert(sizeof(BasicBlockId) == sizeof(uint16_t), "BasicBlockId must be 16 bit"); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 344 | BasicBlockId id_; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 345 | |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 346 | SregValueMap sreg_value_map_; |
| 347 | SregValueMap sreg_wide_value_map_; |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 348 | |
| 349 | SFieldToValueMap sfield_value_map_; |
| 350 | IFieldLocToValueMap non_aliasing_ifield_value_map_; |
| 351 | AliasingIFieldValuesMap aliasing_ifield_value_map_; |
| 352 | NonAliasingArrayValuesMap non_aliasing_array_value_map_; |
| 353 | AliasingArrayValuesMap aliasing_array_value_map_; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 354 | |
| 355 | // Data for dealing with memory clobbering and store/load aliasing. |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 356 | uint16_t global_memory_version_; |
Vladimir Marko | 321b987 | 2014-11-24 16:33:51 +0000 | [diff] [blame] | 357 | uint16_t unresolved_sfield_version_[kDexMemAccessTypeCount]; |
| 358 | uint16_t unresolved_ifield_version_[kDexMemAccessTypeCount]; |
Vladimir Marko | f59f18b | 2014-02-17 15:53:57 +0000 | [diff] [blame] | 359 | // Value names of references to objects that cannot be reached through a different value name. |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 360 | ValueNameSet non_aliasing_refs_; |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 361 | // Previously non-aliasing refs that escaped but can still be used for non-aliasing AGET/IGET. |
| 362 | ValueNameSet escaped_refs_; |
| 363 | // Blacklists for cases where escaped_refs_ can't be used. |
| 364 | EscapedIFieldClobberSet escaped_ifield_clobber_set_; |
| 365 | EscapedArrayClobberSet escaped_array_clobber_set_; |
Vladimir Marko | 2ac01fc | 2014-05-22 12:09:08 +0100 | [diff] [blame] | 366 | |
| 367 | // Range check and null check elimination. |
| 368 | RangeCheckSet range_checked_; |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 369 | ValueNameSet null_checked_; |
Razvan A Lupusoru | e095114 | 2014-11-14 14:36:55 -0800 | [diff] [blame] | 370 | ValueNameSet div_zero_checked_; |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 371 | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 372 | // Reuse one vector for all merges to avoid leaking too much memory on the ArenaStack. |
| 373 | ScopedArenaVector<BasicBlockId> merge_names_; |
| 374 | // Map to identify when different locations merge the same values. |
| 375 | ScopedArenaSafeMap<ScopedArenaVector<BasicBlockId>, uint16_t> merge_map_; |
| 376 | // New memory version for merge, kNoValue if all memory versions matched. |
| 377 | uint16_t merge_new_memory_version_; |
| 378 | |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 379 | DISALLOW_COPY_AND_ASSIGN(LocalValueNumbering); |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 380 | }; |
| 381 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 382 | } // namespace art |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 383 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 384 | #endif // ART_COMPILER_DEX_LOCAL_VALUE_NUMBERING_H_ |