Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2 | * Copyright (C) 2014 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 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 17 | #include "builder.h" |
| 18 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 20 | #include "base/logging.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 21 | #include "class_linker.h" |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 22 | #include "dex/verified_method.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 23 | #include "dex_file-inl.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 24 | #include "dex_instruction-inl.h" |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 25 | #include "dex/verified_method.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 26 | #include "driver/compiler_driver-inl.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 27 | #include "driver/compiler_options.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 28 | #include "mirror/class_loader.h" |
| 29 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 30 | #include "nodes.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 31 | #include "primitive.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 32 | #include "scoped_thread_state_change.h" |
| 33 | #include "thread.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 34 | |
| 35 | namespace art { |
| 36 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 37 | /** |
| 38 | * Helper class to add HTemporary instructions. This class is used when |
| 39 | * converting a DEX instruction to multiple HInstruction, and where those |
| 40 | * instructions do not die at the following instruction, but instead spans |
| 41 | * multiple instructions. |
| 42 | */ |
| 43 | class Temporaries : public ValueObject { |
| 44 | public: |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 45 | explicit Temporaries(HGraph* graph) : graph_(graph), index_(0) {} |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 46 | |
| 47 | void Add(HInstruction* instruction) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 48 | HInstruction* temp = new (graph_->GetArena()) HTemporary(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | instruction->GetBlock()->AddInstruction(temp); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 50 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 51 | DCHECK(temp->GetPrevious() == instruction); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 52 | |
| 53 | size_t offset; |
| 54 | if (instruction->GetType() == Primitive::kPrimLong |
| 55 | || instruction->GetType() == Primitive::kPrimDouble) { |
| 56 | offset = 2; |
| 57 | } else { |
| 58 | offset = 1; |
| 59 | } |
| 60 | index_ += offset; |
| 61 | |
| 62 | graph_->UpdateTemporariesVRegSlots(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | private: |
| 66 | HGraph* const graph_; |
| 67 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 68 | // Current index in the temporary stack, updated by `Add`. |
| 69 | size_t index_; |
| 70 | }; |
| 71 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 72 | class SwitchTable : public ValueObject { |
| 73 | public: |
| 74 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 75 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 76 | int32_t table_offset = instruction.VRegB_31t(); |
| 77 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 78 | if (sparse) { |
| 79 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 80 | } else { |
| 81 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 82 | } |
| 83 | num_entries_ = table[1]; |
| 84 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 85 | } |
| 86 | |
| 87 | uint16_t GetNumEntries() const { |
| 88 | return num_entries_; |
| 89 | } |
| 90 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 91 | void CheckIndex(size_t index) const { |
| 92 | if (sparse_) { |
| 93 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 94 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 95 | } else { |
| 96 | // In a packed table, we have the starting key and num_entries_ values. |
| 97 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 98 | } |
| 99 | } |
| 100 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 101 | int32_t GetEntryAt(size_t index) const { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 102 | CheckIndex(index); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 103 | return values_[index]; |
| 104 | } |
| 105 | |
| 106 | uint32_t GetDexPcForIndex(size_t index) const { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 107 | CheckIndex(index); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 108 | return dex_pc_ + |
| 109 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 110 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 111 | } |
| 112 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 113 | // Index of the first value in the table. |
| 114 | size_t GetFirstValueIndex() const { |
| 115 | if (sparse_) { |
| 116 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 117 | return num_entries_; |
| 118 | } else { |
| 119 | // In a packed table, we have the starting key and num_entries_ values. |
| 120 | return 1; |
| 121 | } |
| 122 | } |
| 123 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 124 | private: |
| 125 | const Instruction& instruction_; |
| 126 | const uint32_t dex_pc_; |
| 127 | |
| 128 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 129 | const bool sparse_; |
| 130 | |
| 131 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 132 | // expressions in the initializer list seemed very ugly. |
| 133 | uint16_t num_entries_; |
| 134 | |
| 135 | const int32_t* values_; |
| 136 | |
| 137 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 138 | }; |
| 139 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 140 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 141 | graph_->SetNumberOfVRegs(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 142 | locals_.SetSize(count); |
| 143 | for (int i = 0; i < count; i++) { |
| 144 | HLocal* local = new (arena_) HLocal(i); |
| 145 | entry_block_->AddInstruction(local); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 146 | locals_.Put(i, local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 150 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 151 | // dex_compilation_unit_ is null only when unit testing. |
| 152 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 153 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 157 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 158 | int locals_index = locals_.Size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 159 | int parameter_index = 0; |
| 160 | |
| 161 | if (!dex_compilation_unit_->IsStatic()) { |
| 162 | // Add the implicit 'this' argument, not expressed in the signature. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 163 | HParameterValue* parameter = |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 164 | new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot, true); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 165 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 166 | HLocal* local = GetLocalAt(locals_index++); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 167 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 168 | number_of_parameters--; |
| 169 | } |
| 170 | |
| 171 | uint32_t pos = 1; |
| 172 | for (int i = 0; i < number_of_parameters; i++) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 173 | HParameterValue* parameter = |
| 174 | new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++])); |
| 175 | entry_block_->AddInstruction(parameter); |
| 176 | HLocal* local = GetLocalAt(locals_index++); |
| 177 | // Store the parameter value in the local that the dex code will use |
| 178 | // to reference that parameter. |
| 179 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
| 180 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 181 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 182 | if (is_wide) { |
| 183 | i++; |
| 184 | locals_index++; |
| 185 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 186 | } |
| 187 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 190 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 191 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 192 | int32_t target_offset = instruction.GetTargetOffset(); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 193 | HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset); |
| 194 | HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 195 | DCHECK(branch_target != nullptr); |
| 196 | DCHECK(fallthrough_target != nullptr); |
| 197 | PotentiallyAddSuspendCheck(branch_target, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 198 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 199 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 200 | T* comparison = new (arena_) T(first, second); |
| 201 | current_block_->AddInstruction(comparison); |
| 202 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 203 | current_block_->AddInstruction(ifinst); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 204 | current_block_->AddSuccessor(branch_target); |
| 205 | current_block_->AddSuccessor(fallthrough_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 206 | current_block_ = nullptr; |
| 207 | } |
| 208 | |
| 209 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 210 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 211 | int32_t target_offset = instruction.GetTargetOffset(); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 212 | HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset); |
| 213 | HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 214 | DCHECK(branch_target != nullptr); |
| 215 | DCHECK(fallthrough_target != nullptr); |
| 216 | PotentiallyAddSuspendCheck(branch_target, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 217 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 218 | T* comparison = new (arena_) T(value, graph_->GetIntConstant(0)); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 219 | current_block_->AddInstruction(comparison); |
| 220 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 221 | current_block_->AddInstruction(ifinst); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 222 | current_block_->AddSuccessor(branch_target); |
| 223 | current_block_->AddSuccessor(fallthrough_target); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 224 | current_block_ = nullptr; |
| 225 | } |
| 226 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 227 | void HGraphBuilder::MaybeRecordStat(MethodCompilationStat compilation_stat) { |
| 228 | if (compilation_stats_ != nullptr) { |
| 229 | compilation_stats_->RecordStat(compilation_stat); |
| 230 | } |
| 231 | } |
| 232 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 233 | bool HGraphBuilder::SkipCompilation(const DexFile::CodeItem& code_item, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 234 | size_t number_of_branches) { |
| 235 | const CompilerOptions& compiler_options = compiler_driver_->GetCompilerOptions(); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 236 | CompilerOptions::CompilerFilter compiler_filter = compiler_options.GetCompilerFilter(); |
| 237 | if (compiler_filter == CompilerOptions::kEverything) { |
| 238 | return false; |
| 239 | } |
| 240 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 241 | if (compiler_options.IsHugeMethod(code_item.insns_size_in_code_units_)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 242 | VLOG(compiler) << "Skip compilation of huge method " |
| 243 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 244 | << ": " << code_item.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 245 | MaybeRecordStat(MethodCompilationStat::kNotCompiledHugeMethod); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 246 | return true; |
| 247 | } |
| 248 | |
| 249 | // If it's large and contains no branches, it's likely to be machine generated initialization. |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 250 | if (compiler_options.IsLargeMethod(code_item.insns_size_in_code_units_) |
| 251 | && (number_of_branches == 0)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 252 | VLOG(compiler) << "Skip compilation of large method with no branch " |
| 253 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 254 | << ": " << code_item.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 255 | MaybeRecordStat(MethodCompilationStat::kNotCompiledLargeMethodNoBranches); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 256 | return true; |
| 257 | } |
| 258 | |
| 259 | return false; |
| 260 | } |
| 261 | |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 262 | static const DexFile::TryItem* GetTryItem(HBasicBlock* block, |
| 263 | const DexFile::CodeItem& code_item, |
| 264 | const ArenaBitVector& can_block_throw) { |
| 265 | DCHECK(!block->IsSingleTryBoundary()); |
| 266 | |
| 267 | // Block does not contain throwing instructions. Even if it is covered by |
| 268 | // a TryItem, we will consider it not in a try block. |
| 269 | if (!can_block_throw.IsBitSet(block->GetBlockId())) { |
| 270 | return nullptr; |
| 271 | } |
| 272 | |
| 273 | // Instructions in the block may throw. Find a TryItem covering this block. |
| 274 | int32_t try_item_idx = DexFile::FindTryItem(code_item, block->GetDexPc()); |
David Brazdil | 6cd788f | 2015-07-08 16:44:00 +0100 | [diff] [blame] | 275 | return (try_item_idx == -1) ? nullptr : DexFile::GetTryItems(code_item, try_item_idx); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void HGraphBuilder::CreateBlocksForTryCatch(const DexFile::CodeItem& code_item) { |
| 279 | if (code_item.tries_size_ == 0) { |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | // Create branch targets at the start/end of the TryItem range. These are |
| 284 | // places where the program might fall through into/out of the a block and |
| 285 | // where TryBoundary instructions will be inserted later. Other edges which |
| 286 | // enter/exit the try blocks are a result of branches/switches. |
| 287 | for (size_t idx = 0; idx < code_item.tries_size_; ++idx) { |
| 288 | const DexFile::TryItem* try_item = DexFile::GetTryItems(code_item, idx); |
| 289 | uint32_t dex_pc_start = try_item->start_addr_; |
| 290 | uint32_t dex_pc_end = dex_pc_start + try_item->insn_count_; |
| 291 | FindOrCreateBlockStartingAt(dex_pc_start); |
| 292 | if (dex_pc_end < code_item.insns_size_in_code_units_) { |
| 293 | // TODO: Do not create block if the last instruction cannot fall through. |
| 294 | FindOrCreateBlockStartingAt(dex_pc_end); |
| 295 | } else { |
| 296 | // The TryItem spans until the very end of the CodeItem (or beyond if |
| 297 | // invalid) and therefore cannot have any code afterwards. |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // Create branch targets for exception handlers. |
| 302 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0); |
| 303 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 304 | for (uint32_t idx = 0; idx < handlers_size; ++idx) { |
| 305 | CatchHandlerIterator iterator(handlers_ptr); |
| 306 | for (; iterator.HasNext(); iterator.Next()) { |
| 307 | uint32_t address = iterator.GetHandlerAddress(); |
| 308 | HBasicBlock* block = FindOrCreateBlockStartingAt(address); |
| 309 | block->SetIsCatchBlock(); |
| 310 | } |
| 311 | handlers_ptr = iterator.EndDataPointer(); |
| 312 | } |
| 313 | } |
| 314 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 315 | void HGraphBuilder::SplitTryBoundaryEdge(HBasicBlock* predecessor, |
| 316 | HBasicBlock* successor, |
| 317 | HTryBoundary::BoundaryKind kind, |
| 318 | const DexFile::CodeItem& code_item, |
| 319 | const DexFile::TryItem& try_item) { |
| 320 | // Split the edge with a single TryBoundary instruction. |
| 321 | HTryBoundary* try_boundary = new (arena_) HTryBoundary(kind); |
| 322 | HBasicBlock* try_entry_block = graph_->SplitEdge(predecessor, successor); |
| 323 | try_entry_block->AddInstruction(try_boundary); |
| 324 | |
| 325 | // Link the TryBoundary to the handlers of `try_item`. |
| 326 | for (CatchHandlerIterator it(code_item, try_item); it.HasNext(); it.Next()) { |
| 327 | try_boundary->AddExceptionHandler(FindBlockStartingAt(it.GetHandlerAddress())); |
| 328 | } |
| 329 | } |
| 330 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 331 | void HGraphBuilder::InsertTryBoundaryBlocks(const DexFile::CodeItem& code_item) { |
| 332 | if (code_item.tries_size_ == 0) { |
| 333 | return; |
| 334 | } |
| 335 | |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 336 | // Bit vector stores information on which blocks contain throwing instructions. |
| 337 | // Must be expandable because catch blocks may be split into two. |
| 338 | ArenaBitVector can_block_throw(arena_, graph_->GetBlocks().Size(), /* expandable */ true); |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 339 | |
| 340 | // Scan blocks and mark those which contain throwing instructions. |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 341 | for (size_t block_id = 0, e = graph_->GetBlocks().Size(); block_id < e; ++block_id) { |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 342 | HBasicBlock* block = graph_->GetBlocks().Get(block_id); |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 343 | bool can_throw = false; |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 344 | for (HInstructionIterator insn(block->GetInstructions()); !insn.Done(); insn.Advance()) { |
| 345 | if (insn.Current()->CanThrow()) { |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 346 | can_throw = true; |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 347 | break; |
| 348 | } |
| 349 | } |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 350 | |
| 351 | if (can_throw) { |
| 352 | if (block->IsCatchBlock()) { |
| 353 | // Catch blocks are always considered an entry point into the TryItem in |
| 354 | // order to avoid splitting exceptional edges. We split the block after |
| 355 | // the move-exception (if present) and mark the first part non-throwing. |
| 356 | // Later on, a TryBoundary will be inserted between the two blocks. |
| 357 | HInstruction* first_insn = block->GetFirstInstruction(); |
| 358 | if (first_insn->IsLoadException()) { |
| 359 | // Catch block starts with a LoadException. Split the block after the |
| 360 | // StoreLocal that must come after the load. |
| 361 | DCHECK(first_insn->GetNext()->IsStoreLocal()); |
| 362 | block = block->SplitBefore(first_insn->GetNext()->GetNext()); |
| 363 | } else { |
| 364 | // Catch block does not load the exception. Split at the beginning to |
| 365 | // create an empty catch block. |
| 366 | block = block->SplitBefore(first_insn); |
| 367 | } |
| 368 | } |
| 369 | can_block_throw.SetBit(block->GetBlockId()); |
| 370 | } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 371 | } |
| 372 | |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 373 | // Iterate over all blocks, find those covered by some TryItem and: |
| 374 | // (a) split edges which enter/exit the try range, |
| 375 | // (b) create TryBoundary instructions in the new blocks, |
| 376 | // (c) link the new blocks to corresponding exception handlers. |
| 377 | // We cannot iterate only over blocks in `branch_targets_` because switch-case |
| 378 | // blocks share the same dex_pc. |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 379 | for (size_t block_id = 0, e = graph_->GetBlocks().Size(); block_id < e; ++block_id) { |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 380 | HBasicBlock* try_block = graph_->GetBlocks().Get(block_id); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 381 | |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 382 | // TryBoundary blocks are added at the end of the list and not iterated over. |
| 383 | DCHECK(!try_block->IsSingleTryBoundary()); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 384 | |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 385 | // Find the TryItem for this block. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 386 | const DexFile::TryItem* try_item = GetTryItem(try_block, code_item, can_block_throw); |
| 387 | if (try_item == nullptr) { |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 388 | continue; |
| 389 | } |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 390 | |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 391 | // Catch blocks were split earlier and cannot throw. |
| 392 | DCHECK(!try_block->IsCatchBlock()); |
| 393 | |
| 394 | // Find predecessors which are not covered by the same TryItem range. Such |
| 395 | // edges enter the try block and will have a TryBoundary inserted. |
| 396 | for (size_t i = 0; i < try_block->GetPredecessors().Size(); ++i) { |
| 397 | HBasicBlock* predecessor = try_block->GetPredecessors().Get(i); |
| 398 | if (predecessor->IsSingleTryBoundary()) { |
| 399 | // The edge was already split because of an exit from a neighbouring |
| 400 | // TryItem. We split it again and insert an entry point. |
| 401 | if (kIsDebugBuild) { |
| 402 | HTryBoundary* last_insn = predecessor->GetLastInstruction()->AsTryBoundary(); |
| 403 | const DexFile::TryItem* predecessor_try_item = |
| 404 | GetTryItem(predecessor->GetSinglePredecessor(), code_item, can_block_throw); |
| 405 | DCHECK(!last_insn->IsEntry()); |
| 406 | DCHECK_EQ(last_insn->GetNormalFlowSuccessor(), try_block); |
| 407 | DCHECK(try_block->IsFirstIndexOfPredecessor(predecessor, i)); |
| 408 | DCHECK_NE(try_item, predecessor_try_item); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 409 | } |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 410 | } else if (GetTryItem(predecessor, code_item, can_block_throw) != try_item) { |
| 411 | // This is an entry point into the TryItem and the edge has not been |
| 412 | // split yet. That means that `predecessor` is not in a TryItem, or |
| 413 | // it is in a different TryItem and we happened to iterate over this |
| 414 | // block first. We split the edge and insert an entry point. |
| 415 | } else { |
| 416 | // Not an edge on the boundary of the try block. |
| 417 | continue; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 418 | } |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame^] | 419 | SplitTryBoundaryEdge(predecessor, try_block, HTryBoundary::kEntry, code_item, *try_item); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 420 | } |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 421 | |
| 422 | // Find successors which are not covered by the same TryItem range. Such |
| 423 | // edges exit the try block and will have a TryBoundary inserted. |
| 424 | for (size_t i = 0; i < try_block->GetSuccessors().Size(); ++i) { |
| 425 | HBasicBlock* successor = try_block->GetSuccessors().Get(i); |
| 426 | if (successor->IsCatchBlock()) { |
| 427 | // A catch block is always considered an entry point into its TryItem. |
| 428 | // We therefore assume this is an exit point, regardless of whether |
| 429 | // the catch block is in a different TryItem or not. |
| 430 | } else if (successor->IsSingleTryBoundary()) { |
| 431 | // The edge was already split because of an entry into a neighbouring |
| 432 | // TryItem. We split it again and insert an exit. |
| 433 | if (kIsDebugBuild) { |
| 434 | HTryBoundary* last_insn = successor->GetLastInstruction()->AsTryBoundary(); |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 435 | const DexFile::TryItem* successor_try_item = |
| 436 | GetTryItem(last_insn->GetNormalFlowSuccessor(), code_item, can_block_throw); |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 437 | DCHECK_EQ(try_block, successor->GetSinglePredecessor()); |
| 438 | DCHECK(last_insn->IsEntry()); |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 439 | DCHECK_NE(try_item, successor_try_item); |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 440 | } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 441 | } else if (GetTryItem(successor, code_item, can_block_throw) != try_item) { |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 442 | // This is an exit out of the TryItem and the edge has not been split |
| 443 | // yet. That means that either `successor` is not in a TryItem, or it |
| 444 | // is in a different TryItem and we happened to iterate over this |
| 445 | // block first. We split the edge and insert an exit. |
| 446 | HInstruction* last_instruction = try_block->GetLastInstruction(); |
| 447 | if (last_instruction->IsReturn() || last_instruction->IsReturnVoid()) { |
| 448 | DCHECK_EQ(successor, exit_block_); |
| 449 | // Control flow exits the try block with a Return(Void). Because |
| 450 | // splitting the edge would invalidate the invariant that Return |
| 451 | // always jumps to Exit, we move the Return outside the try block. |
| 452 | successor = try_block->SplitBefore(last_instruction); |
| 453 | } |
| 454 | } else { |
| 455 | // Not an edge on the boundary of the try block. |
| 456 | continue; |
| 457 | } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 458 | SplitTryBoundaryEdge(try_block, successor, HTryBoundary::kExit, code_item, *try_item); |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 459 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 463 | bool HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
| 464 | DCHECK(graph_->GetBlocks().IsEmpty()); |
| 465 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 466 | const uint16_t* code_ptr = code_item.insns_; |
| 467 | const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 468 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 469 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 470 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 471 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 472 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 473 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 474 | graph_->SetEntryBlock(entry_block_); |
| 475 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 476 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 477 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 478 | graph_->SetMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 479 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 480 | // Compute the number of dex instructions, blocks, and branches. We will |
| 481 | // check these values against limits given to the compiler. |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 482 | size_t number_of_branches = 0; |
| 483 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 484 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 485 | // start a new block, and create these blocks. |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 486 | if (!ComputeBranchTargets(code_ptr, code_end, &number_of_branches)) { |
| 487 | MaybeRecordStat(MethodCompilationStat::kNotCompiledBranchOutsideMethodCode); |
| 488 | return false; |
| 489 | } |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 490 | |
| 491 | // Note that the compiler driver is null when unit testing. |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 492 | if ((compiler_driver_ != nullptr) && SkipCompilation(code_item, number_of_branches)) { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 493 | return false; |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 494 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 495 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 496 | CreateBlocksForTryCatch(code_item); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 497 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 498 | InitializeParameters(code_item.ins_size_); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 499 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 500 | size_t dex_pc = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 501 | while (code_ptr < code_end) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 502 | // Update the current block if dex_pc starts a new block. |
| 503 | MaybeUpdateCurrentBlock(dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 504 | const Instruction& instruction = *Instruction::At(code_ptr); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 505 | if (!AnalyzeDexInstruction(instruction, dex_pc)) { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 506 | return false; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 507 | } |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 508 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 509 | code_ptr += instruction.SizeInCodeUnits(); |
| 510 | } |
| 511 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 512 | // Add Exit to the exit block. |
David Brazdil | 3e18738 | 2015-06-26 09:59:52 +0000 | [diff] [blame] | 513 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 514 | // Add the suspend check to the entry block. |
| 515 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 516 | entry_block_->AddInstruction(new (arena_) HGoto()); |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 517 | // Add the exit block at the end. |
| 518 | graph_->AddBlock(exit_block_); |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 519 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 520 | // Iterate over blocks covered by TryItems and insert TryBoundaries at entry |
| 521 | // and exit points. This requires all control-flow instructions and |
| 522 | // non-exceptional edges to have been created. |
| 523 | InsertTryBoundaryBlocks(code_item); |
| 524 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 525 | return true; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 526 | } |
| 527 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 528 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t dex_pc) { |
| 529 | HBasicBlock* block = FindBlockStartingAt(dex_pc); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 530 | if (block == nullptr) { |
| 531 | return; |
| 532 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 533 | |
| 534 | if (current_block_ != nullptr) { |
| 535 | // Branching instructions clear current_block, so we know |
| 536 | // the last instruction of the current block is not a branching |
| 537 | // instruction. We add an unconditional goto to the found block. |
| 538 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 539 | current_block_->AddSuccessor(block); |
| 540 | } |
| 541 | graph_->AddBlock(block); |
| 542 | current_block_ = block; |
| 543 | } |
| 544 | |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 545 | bool HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 546 | const uint16_t* code_end, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 547 | size_t* number_of_branches) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 548 | branch_targets_.SetSize(code_end - code_ptr); |
| 549 | |
| 550 | // Create the first block for the dex instructions, single successor of the entry block. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 551 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 552 | branch_targets_.Put(0, block); |
| 553 | entry_block_->AddSuccessor(block); |
| 554 | |
| 555 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 556 | // the locations these instructions branch to. |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 557 | uint32_t dex_pc = 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 558 | while (code_ptr < code_end) { |
| 559 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 560 | if (instruction.IsBranch()) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 561 | (*number_of_branches)++; |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 562 | int32_t target = instruction.GetTargetOffset() + dex_pc; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 563 | // Create a block for the target instruction. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 564 | FindOrCreateBlockStartingAt(target); |
| 565 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 566 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 567 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 568 | |
David Brazdil | fe65946 | 2015-06-24 14:23:56 +0100 | [diff] [blame] | 569 | if (instruction.CanFlowThrough()) { |
| 570 | if (code_ptr >= code_end) { |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 571 | // In the normal case we should never hit this but someone can artificially forge a dex |
| 572 | // file to fall-through out the method code. In this case we bail out compilation. |
| 573 | return false; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 574 | } else { |
| 575 | FindOrCreateBlockStartingAt(dex_pc); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 576 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 577 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 578 | } else if (instruction.IsSwitch()) { |
| 579 | SwitchTable table(instruction, dex_pc, instruction.Opcode() == Instruction::SPARSE_SWITCH); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 580 | |
| 581 | uint16_t num_entries = table.GetNumEntries(); |
| 582 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 583 | // In a packed-switch, the entry at index 0 is the starting key. In a sparse-switch, the |
| 584 | // entry at index 0 is the first key, and values are after *all* keys. |
| 585 | size_t offset = table.GetFirstValueIndex(); |
| 586 | |
| 587 | // Use a larger loop counter type to avoid overflow issues. |
| 588 | for (size_t i = 0; i < num_entries; ++i) { |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 589 | // The target of the case. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 590 | uint32_t target = dex_pc + table.GetEntryAt(i + offset); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 591 | FindOrCreateBlockStartingAt(target); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 592 | |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 593 | // Create a block for the switch-case logic. The block gets the dex_pc |
| 594 | // of the SWITCH instruction because it is part of its semantics. |
| 595 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
| 596 | branch_targets_.Put(table.GetDexPcForIndex(i), block); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | // Fall-through. Add a block if there is more code afterwards. |
| 600 | dex_pc += instruction.SizeInCodeUnits(); |
| 601 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 602 | if (code_ptr >= code_end) { |
| 603 | // In the normal case we should never hit this but someone can artificially forge a dex |
| 604 | // file to fall-through out the method code. In this case we bail out compilation. |
| 605 | // (A switch can fall-through so we don't need to check CanFlowThrough().) |
| 606 | return false; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 607 | } else { |
| 608 | FindOrCreateBlockStartingAt(dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 609 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 610 | } else { |
| 611 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 612 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 615 | return true; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 616 | } |
| 617 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 618 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t dex_pc) const { |
| 619 | DCHECK_GE(dex_pc, 0); |
| 620 | DCHECK_LT(static_cast<size_t>(dex_pc), branch_targets_.Size()); |
| 621 | return branch_targets_.Get(dex_pc); |
| 622 | } |
| 623 | |
| 624 | HBasicBlock* HGraphBuilder::FindOrCreateBlockStartingAt(int32_t dex_pc) { |
| 625 | HBasicBlock* block = FindBlockStartingAt(dex_pc); |
| 626 | if (block == nullptr) { |
| 627 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
| 628 | branch_targets_.Put(dex_pc, block); |
| 629 | } |
| 630 | return block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 633 | template<typename T> |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 634 | void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) { |
| 635 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 636 | current_block_->AddInstruction(new (arena_) T(type, first)); |
| 637 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 638 | } |
| 639 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 640 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 641 | Primitive::Type input_type, |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 642 | Primitive::Type result_type, |
| 643 | uint32_t dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 644 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 645 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first, dex_pc)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 646 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 647 | } |
| 648 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 649 | template<typename T> |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 650 | void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 651 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 652 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 653 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 654 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 655 | } |
| 656 | |
| 657 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 658 | void HGraphBuilder::Binop_23x(const Instruction& instruction, |
| 659 | Primitive::Type type, |
| 660 | uint32_t dex_pc) { |
| 661 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 662 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 663 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 664 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 665 | } |
| 666 | |
| 667 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 668 | void HGraphBuilder::Binop_23x_shift(const Instruction& instruction, |
| 669 | Primitive::Type type) { |
| 670 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 671 | HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt); |
| 672 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
| 673 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 674 | } |
| 675 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 676 | void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction, |
| 677 | Primitive::Type type, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 678 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 679 | uint32_t dex_pc) { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 680 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 681 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 682 | current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias, dex_pc)); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 683 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 684 | } |
| 685 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 686 | template<typename T> |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 687 | void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) { |
| 688 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 689 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 690 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 691 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 692 | } |
| 693 | |
| 694 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 695 | void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type) { |
| 696 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 697 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 698 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
| 699 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 700 | } |
| 701 | |
| 702 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 703 | void HGraphBuilder::Binop_12x(const Instruction& instruction, |
| 704 | Primitive::Type type, |
| 705 | uint32_t dex_pc) { |
| 706 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 707 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 708 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 709 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 710 | } |
| 711 | |
| 712 | template<typename T> |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 713 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 714 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 715 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 716 | if (reverse) { |
| 717 | std::swap(first, second); |
| 718 | } |
| 719 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 720 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 721 | } |
| 722 | |
| 723 | template<typename T> |
| 724 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 725 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 726 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 727 | if (reverse) { |
| 728 | std::swap(first, second); |
| 729 | } |
| 730 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 731 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 732 | } |
| 733 | |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 734 | static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 735 | Thread* self = Thread::Current(); |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 736 | return cu->IsConstructor() |
| 737 | && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 738 | } |
| 739 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 740 | void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) { |
| 741 | if (type == Primitive::kPrimVoid) { |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 742 | if (graph_->ShouldGenerateConstructorBarrier()) { |
| 743 | // The compilation unit is null during testing. |
| 744 | if (dex_compilation_unit_ != nullptr) { |
| 745 | DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_)) |
| 746 | << "Inconsistent use of ShouldGenerateConstructorBarrier. Should not generate a barrier."; |
| 747 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 748 | current_block_->AddInstruction(new (arena_) HMemoryBarrier(kStoreStore)); |
| 749 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 750 | current_block_->AddInstruction(new (arena_) HReturnVoid()); |
| 751 | } else { |
| 752 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
| 753 | current_block_->AddInstruction(new (arena_) HReturn(value)); |
| 754 | } |
| 755 | current_block_->AddSuccessor(exit_block_); |
| 756 | current_block_ = nullptr; |
| 757 | } |
| 758 | |
| 759 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 760 | uint32_t dex_pc, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 761 | uint32_t method_idx, |
| 762 | uint32_t number_of_vreg_arguments, |
| 763 | bool is_range, |
| 764 | uint32_t* args, |
| 765 | uint32_t register_index) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 766 | Instruction::Code opcode = instruction.Opcode(); |
| 767 | InvokeType invoke_type; |
| 768 | switch (opcode) { |
| 769 | case Instruction::INVOKE_STATIC: |
| 770 | case Instruction::INVOKE_STATIC_RANGE: |
| 771 | invoke_type = kStatic; |
| 772 | break; |
| 773 | case Instruction::INVOKE_DIRECT: |
| 774 | case Instruction::INVOKE_DIRECT_RANGE: |
| 775 | invoke_type = kDirect; |
| 776 | break; |
| 777 | case Instruction::INVOKE_VIRTUAL: |
| 778 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 779 | invoke_type = kVirtual; |
| 780 | break; |
| 781 | case Instruction::INVOKE_INTERFACE: |
| 782 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 783 | invoke_type = kInterface; |
| 784 | break; |
| 785 | case Instruction::INVOKE_SUPER_RANGE: |
| 786 | case Instruction::INVOKE_SUPER: |
| 787 | invoke_type = kSuper; |
| 788 | break; |
| 789 | default: |
| 790 | LOG(FATAL) << "Unexpected invoke op: " << opcode; |
| 791 | return false; |
| 792 | } |
| 793 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 794 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 795 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 796 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 797 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 798 | bool is_instance_call = invoke_type != kStatic; |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 799 | // Remove the return type from the 'proto'. |
| 800 | size_t number_of_arguments = strlen(descriptor) - 1; |
| 801 | if (is_instance_call) { |
| 802 | // One extra argument for 'this'. |
| 803 | ++number_of_arguments; |
| 804 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 805 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 806 | MethodReference target_method(dex_file_, method_idx); |
| 807 | uintptr_t direct_code; |
| 808 | uintptr_t direct_method; |
| 809 | int table_index; |
| 810 | InvokeType optimized_invoke_type = invoke_type; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 811 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 812 | if (!compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_pc, true, true, |
| 813 | &optimized_invoke_type, &target_method, &table_index, |
| 814 | &direct_code, &direct_method)) { |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 815 | VLOG(compiler) << "Did not compile " |
| 816 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 817 | << " because a method call could not be resolved"; |
| 818 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedMethod); |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 819 | return false; |
| 820 | } |
| 821 | DCHECK(optimized_invoke_type != kSuper); |
| 822 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 823 | // By default, consider that the called method implicitly requires |
| 824 | // an initialization check of its declaring method. |
| 825 | HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement = |
| 826 | HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit; |
| 827 | // Potential class initialization check, in the case of a static method call. |
| 828 | HClinitCheck* clinit_check = nullptr; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 829 | // Replace calls to String.<init> with StringFactory. |
| 830 | int32_t string_init_offset = 0; |
| 831 | bool is_string_init = compiler_driver_->IsStringInit(method_idx, dex_file_, &string_init_offset); |
| 832 | if (is_string_init) { |
| 833 | return_type = Primitive::kPrimNot; |
| 834 | is_instance_call = false; |
| 835 | number_of_arguments--; |
| 836 | invoke_type = kStatic; |
| 837 | optimized_invoke_type = kStatic; |
| 838 | } |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 839 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 840 | HInvoke* invoke = nullptr; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 841 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 842 | if (optimized_invoke_type == kVirtual) { |
| 843 | invoke = new (arena_) HInvokeVirtual( |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 844 | arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 845 | } else if (optimized_invoke_type == kInterface) { |
| 846 | invoke = new (arena_) HInvokeInterface( |
| 847 | arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 848 | } else { |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 849 | DCHECK(optimized_invoke_type == kDirect || optimized_invoke_type == kStatic); |
| 850 | // Sharpening to kDirect only works if we compile PIC. |
| 851 | DCHECK((optimized_invoke_type == invoke_type) || (optimized_invoke_type != kDirect) |
| 852 | || compiler_driver_->GetCompilerOptions().GetCompilePic()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 853 | bool is_recursive = |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 854 | (target_method.dex_method_index == outer_compilation_unit_->GetDexMethodIndex()) |
| 855 | && (target_method.dex_file == outer_compilation_unit_->GetDexFile()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 856 | |
Jeff Hao | cad6542 | 2015-06-18 21:16:08 -0700 | [diff] [blame] | 857 | if (optimized_invoke_type == kStatic && !is_string_init) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 858 | ScopedObjectAccess soa(Thread::Current()); |
| 859 | StackHandleScope<4> hs(soa.Self()); |
| 860 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 861 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 862 | *dex_compilation_unit_->GetDexFile()))); |
| 863 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 864 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 865 | ArtMethod* resolved_method = compiler_driver_->ResolveMethod( |
| 866 | soa, dex_cache, class_loader, dex_compilation_unit_, method_idx, optimized_invoke_type); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 867 | |
| 868 | if (resolved_method == nullptr) { |
| 869 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedMethod); |
| 870 | return false; |
| 871 | } |
| 872 | |
| 873 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 874 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 875 | outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file))); |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 876 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 877 | |
| 878 | // The index at which the method's class is stored in the DexCache's type array. |
| 879 | uint32_t storage_index = DexFile::kDexNoIndex; |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 880 | bool is_outer_class = (resolved_method->GetDeclaringClass() == outer_class.Get()); |
| 881 | if (is_outer_class) { |
| 882 | storage_index = outer_class->GetDexTypeIndex(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 883 | } else if (outer_dex_cache.Get() == dex_cache.Get()) { |
| 884 | // Get `storage_index` from IsClassOfStaticMethodAvailableToReferrer. |
| 885 | compiler_driver_->IsClassOfStaticMethodAvailableToReferrer(outer_dex_cache.Get(), |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 886 | GetCompilingClass(), |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 887 | resolved_method, |
| 888 | method_idx, |
| 889 | &storage_index); |
| 890 | } |
| 891 | |
Nicolas Geoffray | b783b40 | 2015-06-22 11:06:43 +0100 | [diff] [blame] | 892 | if (!outer_class->IsInterface() |
| 893 | && outer_class->IsSubClass(resolved_method->GetDeclaringClass())) { |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 894 | // If the outer class is the declaring class or a subclass |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 895 | // of the declaring class, no class initialization is needed |
| 896 | // before the static method call. |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 897 | // Note that in case of inlining, we do not need to add clinit checks |
| 898 | // to calls that satisfy this subclass check with any inlined methods. This |
| 899 | // will be detected by the optimization passes. |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 900 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 901 | } else if (storage_index != DexFile::kDexNoIndex) { |
| 902 | // If the method's class type index is available, check |
| 903 | // whether we should add an explicit class initialization |
| 904 | // check for its declaring class before the static method call. |
| 905 | |
| 906 | // TODO: find out why this check is needed. |
| 907 | bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache( |
| 908 | *outer_compilation_unit_->GetDexFile(), storage_index); |
| 909 | bool is_initialized = |
| 910 | resolved_method->GetDeclaringClass()->IsInitialized() && is_in_dex_cache; |
| 911 | |
| 912 | if (is_initialized) { |
| 913 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 914 | } else { |
| 915 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 916 | HLoadClass* load_class = new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 917 | graph_->GetCurrentMethod(), |
| 918 | storage_index, |
| 919 | *dex_compilation_unit_->GetDexFile(), |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 920 | is_outer_class, |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 921 | dex_pc); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 922 | current_block_->AddInstruction(load_class); |
| 923 | clinit_check = new (arena_) HClinitCheck(load_class, dex_pc); |
| 924 | current_block_->AddInstruction(clinit_check); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
Guillaume "Vermeille" Sanchez | ae09d2d | 2015-05-29 10:52:55 +0100 | [diff] [blame] | 929 | invoke = new (arena_) HInvokeStaticOrDirect(arena_, |
| 930 | number_of_arguments, |
| 931 | return_type, |
| 932 | dex_pc, |
| 933 | target_method.dex_method_index, |
| 934 | is_recursive, |
| 935 | string_init_offset, |
| 936 | invoke_type, |
| 937 | optimized_invoke_type, |
| 938 | clinit_check_requirement); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 939 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 940 | |
| 941 | size_t start_index = 0; |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 942 | Temporaries temps(graph_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 943 | if (is_instance_call) { |
| 944 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 945 | HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_pc); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 946 | current_block_->AddInstruction(null_check); |
| 947 | temps.Add(null_check); |
| 948 | invoke->SetArgumentAt(0, null_check); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 949 | start_index = 1; |
| 950 | } |
| 951 | |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 952 | uint32_t descriptor_index = 1; // Skip the return type. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 953 | uint32_t argument_index = start_index; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 954 | if (is_string_init) { |
| 955 | start_index = 1; |
| 956 | } |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 957 | for (size_t i = start_index; |
| 958 | // Make sure we don't go over the expected arguments or over the number of |
| 959 | // dex registers given. If the instruction was seen as dead by the verifier, |
| 960 | // it hasn't been properly checked. |
| 961 | (i < number_of_vreg_arguments) && (argument_index < number_of_arguments); |
| 962 | i++, argument_index++) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 963 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 964 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 965 | if (!is_range |
| 966 | && is_wide |
| 967 | && ((i + 1 == number_of_vreg_arguments) || (args[i] + 1 != args[i + 1]))) { |
| 968 | // Longs and doubles should be in pairs, that is, sequential registers. The verifier should |
| 969 | // reject any class where this is violated. However, the verifier only does these checks |
| 970 | // on non trivially dead instructions, so we just bailout the compilation. |
| 971 | VLOG(compiler) << "Did not compile " |
| 972 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 973 | << " because of non-sequential dex register pair in wide argument"; |
| 974 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 975 | return false; |
| 976 | } |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 977 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 978 | invoke->SetArgumentAt(argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 979 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 980 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 981 | } |
| 982 | } |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 983 | |
| 984 | if (argument_index != number_of_arguments) { |
| 985 | VLOG(compiler) << "Did not compile " |
| 986 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 987 | << " because of wrong number of arguments in invoke instruction"; |
| 988 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 989 | return false; |
| 990 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 991 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 992 | if (invoke->IsInvokeStaticOrDirect()) { |
| 993 | invoke->SetArgumentAt(argument_index, graph_->GetCurrentMethod()); |
| 994 | argument_index++; |
| 995 | } |
| 996 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 997 | if (clinit_check_requirement == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit) { |
| 998 | // Add the class initialization check as last input of `invoke`. |
| 999 | DCHECK(clinit_check != nullptr); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1000 | invoke->SetArgumentAt(argument_index, clinit_check); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1001 | } |
| 1002 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1003 | current_block_->AddInstruction(invoke); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1004 | latest_result_ = invoke; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1005 | |
| 1006 | // Add move-result for StringFactory method. |
| 1007 | if (is_string_init) { |
| 1008 | uint32_t orig_this_reg = is_range ? register_index : args[0]; |
Nicolas Geoffray | aa91920 | 2015-06-21 18:57:02 +0100 | [diff] [blame] | 1009 | UpdateLocal(orig_this_reg, invoke); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1010 | const VerifiedMethod* verified_method = |
| 1011 | compiler_driver_->GetVerifiedMethod(dex_file_, dex_compilation_unit_->GetDexMethodIndex()); |
| 1012 | if (verified_method == nullptr) { |
| 1013 | LOG(WARNING) << "No verified method for method calling String.<init>: " |
| 1014 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_); |
| 1015 | return false; |
| 1016 | } |
| 1017 | const SafeMap<uint32_t, std::set<uint32_t>>& string_init_map = |
| 1018 | verified_method->GetStringInitPcRegMap(); |
| 1019 | auto map_it = string_init_map.find(dex_pc); |
| 1020 | if (map_it != string_init_map.end()) { |
| 1021 | std::set<uint32_t> reg_set = map_it->second; |
| 1022 | for (auto set_it = reg_set.begin(); set_it != reg_set.end(); ++set_it) { |
Nicolas Geoffray | aa91920 | 2015-06-21 18:57:02 +0100 | [diff] [blame] | 1023 | HInstruction* load_local = LoadLocal(orig_this_reg, Primitive::kPrimNot); |
| 1024 | UpdateLocal(*set_it, load_local); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1025 | } |
| 1026 | } |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1027 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1028 | return true; |
| 1029 | } |
| 1030 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1031 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1032 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1033 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1034 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 1035 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 1036 | uint16_t field_index = instruction.VRegC_22c(); |
| 1037 | |
| 1038 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1039 | ArtField* resolved_field = |
| 1040 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1041 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1042 | if (resolved_field == nullptr) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1043 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedField); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1044 | return false; |
| 1045 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 1046 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1047 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1048 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1049 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1050 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_pc)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1051 | if (is_put) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1052 | Temporaries temps(graph_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1053 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 1054 | // We need one temporary for the null check. |
| 1055 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1056 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1057 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 1058 | null_check, |
| 1059 | value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1060 | field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 1061 | resolved_field->GetOffset(), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1062 | resolved_field->IsVolatile(), |
| 1063 | field_index, |
| 1064 | *dex_file_)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1065 | } else { |
| 1066 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 1067 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1068 | field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 1069 | resolved_field->GetOffset(), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1070 | resolved_field->IsVolatile(), |
| 1071 | field_index, |
| 1072 | *dex_file_)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1073 | |
| 1074 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1075 | } |
| 1076 | return true; |
| 1077 | } |
| 1078 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1079 | static mirror::Class* GetClassFrom(CompilerDriver* driver, |
| 1080 | const DexCompilationUnit& compilation_unit) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1081 | ScopedObjectAccess soa(Thread::Current()); |
| 1082 | StackHandleScope<2> hs(soa.Self()); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1083 | const DexFile& dex_file = *compilation_unit.GetDexFile(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1084 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1085 | soa.Decode<mirror::ClassLoader*>(compilation_unit.GetClassLoader()))); |
| 1086 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1087 | compilation_unit.GetClassLinker()->FindDexCache(dex_file))); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1088 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1089 | return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit); |
| 1090 | } |
| 1091 | |
| 1092 | mirror::Class* HGraphBuilder::GetOutermostCompilingClass() const { |
| 1093 | return GetClassFrom(compiler_driver_, *outer_compilation_unit_); |
| 1094 | } |
| 1095 | |
| 1096 | mirror::Class* HGraphBuilder::GetCompilingClass() const { |
| 1097 | return GetClassFrom(compiler_driver_, *dex_compilation_unit_); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | bool HGraphBuilder::IsOutermostCompilingClass(uint16_t type_index) const { |
| 1101 | ScopedObjectAccess soa(Thread::Current()); |
| 1102 | StackHandleScope<4> hs(soa.Self()); |
| 1103 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1104 | dex_compilation_unit_->GetClassLinker()->FindDexCache(*dex_compilation_unit_->GetDexFile()))); |
| 1105 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1106 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 1107 | Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass( |
| 1108 | soa, dex_cache, class_loader, type_index, dex_compilation_unit_))); |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 1109 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1110 | |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 1111 | return outer_class.Get() == cls.Get(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1114 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1115 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1116 | bool is_put) { |
| 1117 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1118 | uint16_t field_index = instruction.VRegB_21c(); |
| 1119 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1120 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1121 | StackHandleScope<4> hs(soa.Self()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1122 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1123 | dex_compilation_unit_->GetClassLinker()->FindDexCache(*dex_compilation_unit_->GetDexFile()))); |
| 1124 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1125 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1126 | ArtField* resolved_field = compiler_driver_->ResolveField( |
| 1127 | soa, dex_cache, class_loader, dex_compilation_unit_, field_index, true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1128 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1129 | if (resolved_field == nullptr) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1130 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedField); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1131 | return false; |
| 1132 | } |
| 1133 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1134 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 1135 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 1136 | outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file))); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1137 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1138 | |
| 1139 | // The index at which the field's class is stored in the DexCache's type array. |
| 1140 | uint32_t storage_index; |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1141 | bool is_outer_class = (outer_class.Get() == resolved_field->GetDeclaringClass()); |
| 1142 | if (is_outer_class) { |
| 1143 | storage_index = outer_class->GetDexTypeIndex(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1144 | } else if (outer_dex_cache.Get() != dex_cache.Get()) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1145 | // The compiler driver cannot currently understand multiple dex caches involved. Just bailout. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1146 | return false; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1147 | } else { |
| 1148 | std::pair<bool, bool> pair = compiler_driver_->IsFastStaticField( |
| 1149 | outer_dex_cache.Get(), |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1150 | GetCompilingClass(), |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1151 | resolved_field, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1152 | field_index, |
| 1153 | &storage_index); |
| 1154 | bool can_easily_access = is_put ? pair.second : pair.first; |
| 1155 | if (!can_easily_access) { |
| 1156 | return false; |
| 1157 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | // TODO: find out why this check is needed. |
| 1161 | bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache( |
Nicolas Geoffray | 6a816cf | 2015-03-24 16:17:56 +0000 | [diff] [blame] | 1162 | *outer_compilation_unit_->GetDexFile(), storage_index); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1163 | bool is_initialized = resolved_field->GetDeclaringClass()->IsInitialized() && is_in_dex_cache; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1164 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1165 | HLoadClass* constant = new (arena_) HLoadClass(graph_->GetCurrentMethod(), |
| 1166 | storage_index, |
| 1167 | *dex_compilation_unit_->GetDexFile(), |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1168 | is_outer_class, |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1169 | dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1170 | current_block_->AddInstruction(constant); |
| 1171 | |
| 1172 | HInstruction* cls = constant; |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1173 | if (!is_initialized && !is_outer_class) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1174 | cls = new (arena_) HClinitCheck(constant, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1175 | current_block_->AddInstruction(cls); |
| 1176 | } |
| 1177 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1178 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1179 | if (is_put) { |
| 1180 | // We need to keep the class alive before loading the value. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1181 | Temporaries temps(graph_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1182 | temps.Add(cls); |
| 1183 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 1184 | DCHECK_EQ(value->GetType(), field_type); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1185 | current_block_->AddInstruction(new (arena_) HStaticFieldSet(cls, |
| 1186 | value, |
| 1187 | field_type, |
| 1188 | resolved_field->GetOffset(), |
| 1189 | resolved_field->IsVolatile(), |
| 1190 | field_index, |
| 1191 | *dex_file_)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1192 | } else { |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1193 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, |
| 1194 | field_type, |
| 1195 | resolved_field->GetOffset(), |
| 1196 | resolved_field->IsVolatile(), |
| 1197 | field_index, |
| 1198 | *dex_file_)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1199 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1200 | } |
| 1201 | return true; |
| 1202 | } |
| 1203 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1204 | void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
| 1205 | uint16_t first_vreg, |
| 1206 | int64_t second_vreg_or_constant, |
| 1207 | uint32_t dex_pc, |
| 1208 | Primitive::Type type, |
| 1209 | bool second_is_constant, |
| 1210 | bool isDiv) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1211 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1212 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1213 | HInstruction* first = LoadLocal(first_vreg, type); |
| 1214 | HInstruction* second = nullptr; |
| 1215 | if (second_is_constant) { |
| 1216 | if (type == Primitive::kPrimInt) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1217 | second = graph_->GetIntConstant(second_vreg_or_constant); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1218 | } else { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1219 | second = graph_->GetLongConstant(second_vreg_or_constant); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1220 | } |
| 1221 | } else { |
| 1222 | second = LoadLocal(second_vreg_or_constant, type); |
| 1223 | } |
| 1224 | |
| 1225 | if (!second_is_constant |
| 1226 | || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0) |
| 1227 | || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) { |
| 1228 | second = new (arena_) HDivZeroCheck(second, dex_pc); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1229 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1230 | current_block_->AddInstruction(second); |
| 1231 | temps.Add(current_block_->GetLastInstruction()); |
| 1232 | } |
| 1233 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1234 | if (isDiv) { |
| 1235 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc)); |
| 1236 | } else { |
| 1237 | current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc)); |
| 1238 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1239 | UpdateLocal(out_vreg, current_block_->GetLastInstruction()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1242 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1243 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1244 | bool is_put, |
| 1245 | Primitive::Type anticipated_type) { |
| 1246 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 1247 | uint8_t array_reg = instruction.VRegB_23x(); |
| 1248 | uint8_t index_reg = instruction.VRegC_23x(); |
| 1249 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1250 | // We need one temporary for the null check, one for the index, and one for the length. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1251 | Temporaries temps(graph_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1252 | |
| 1253 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1254 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1255 | current_block_->AddInstruction(object); |
| 1256 | temps.Add(object); |
| 1257 | |
| 1258 | HInstruction* length = new (arena_) HArrayLength(object); |
| 1259 | current_block_->AddInstruction(length); |
| 1260 | temps.Add(length); |
| 1261 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1262 | index = new (arena_) HBoundsCheck(index, length, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1263 | current_block_->AddInstruction(index); |
| 1264 | temps.Add(index); |
| 1265 | if (is_put) { |
| 1266 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 1267 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1268 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1269 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1270 | } else { |
| 1271 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type)); |
| 1272 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1273 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1274 | graph_->SetHasBoundsChecks(true); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1275 | } |
| 1276 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1277 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1278 | uint32_t type_index, |
| 1279 | uint32_t number_of_vreg_arguments, |
| 1280 | bool is_range, |
| 1281 | uint32_t* args, |
| 1282 | uint32_t register_index) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1283 | HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1284 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 1285 | ? kQuickAllocArrayWithAccessCheck |
| 1286 | : kQuickAllocArray; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1287 | HInstruction* object = new (arena_) HNewArray(length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 1288 | graph_->GetCurrentMethod(), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1289 | dex_pc, |
| 1290 | type_index, |
| 1291 | *dex_compilation_unit_->GetDexFile(), |
| 1292 | entrypoint); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1293 | current_block_->AddInstruction(object); |
| 1294 | |
| 1295 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 1296 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 1297 | char primitive = descriptor[1]; |
| 1298 | DCHECK(primitive == 'I' |
| 1299 | || primitive == 'L' |
| 1300 | || primitive == '[') << descriptor; |
| 1301 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 1302 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 1303 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1304 | Temporaries temps(graph_); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1305 | temps.Add(object); |
| 1306 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 1307 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1308 | HInstruction* index = graph_->GetIntConstant(i); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1309 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1310 | new (arena_) HArraySet(object, index, value, type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1311 | } |
| 1312 | latest_result_ = object; |
| 1313 | } |
| 1314 | |
| 1315 | template <typename T> |
| 1316 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 1317 | const T* data, |
| 1318 | uint32_t element_count, |
| 1319 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1320 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1321 | for (uint32_t i = 0; i < element_count; ++i) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1322 | HInstruction* index = graph_->GetIntConstant(i); |
| 1323 | HInstruction* value = graph_->GetIntConstant(data[i]); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1324 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1325 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1329 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1330 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1331 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1332 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1333 | current_block_->AddInstruction(null_check); |
| 1334 | temps.Add(null_check); |
| 1335 | |
| 1336 | HInstruction* length = new (arena_) HArrayLength(null_check); |
| 1337 | current_block_->AddInstruction(length); |
| 1338 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1339 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1340 | const Instruction::ArrayDataPayload* payload = |
| 1341 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 1342 | const uint8_t* data = payload->data; |
| 1343 | uint32_t element_count = payload->element_count; |
| 1344 | |
| 1345 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 1346 | // done before doing any stores. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1347 | HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1348 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1349 | |
| 1350 | switch (payload->element_width) { |
| 1351 | case 1: |
| 1352 | BuildFillArrayData(null_check, |
| 1353 | reinterpret_cast<const int8_t*>(data), |
| 1354 | element_count, |
| 1355 | Primitive::kPrimByte, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1356 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1357 | break; |
| 1358 | case 2: |
| 1359 | BuildFillArrayData(null_check, |
| 1360 | reinterpret_cast<const int16_t*>(data), |
| 1361 | element_count, |
| 1362 | Primitive::kPrimShort, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1363 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1364 | break; |
| 1365 | case 4: |
| 1366 | BuildFillArrayData(null_check, |
| 1367 | reinterpret_cast<const int32_t*>(data), |
| 1368 | element_count, |
| 1369 | Primitive::kPrimInt, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1370 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1371 | break; |
| 1372 | case 8: |
| 1373 | BuildFillWideArrayData(null_check, |
| 1374 | reinterpret_cast<const int64_t*>(data), |
| 1375 | element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1376 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1377 | break; |
| 1378 | default: |
| 1379 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 1380 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1381 | graph_->SetHasBoundsChecks(true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1384 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1385 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1386 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1387 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1388 | for (uint32_t i = 0; i < element_count; ++i) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1389 | HInstruction* index = graph_->GetIntConstant(i); |
| 1390 | HInstruction* value = graph_->GetLongConstant(data[i]); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1391 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1392 | object, index, value, Primitive::kPrimLong, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1393 | } |
| 1394 | } |
| 1395 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1396 | bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
| 1397 | uint8_t destination, |
| 1398 | uint8_t reference, |
| 1399 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1400 | uint32_t dex_pc) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1401 | bool type_known_final; |
| 1402 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1403 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 1404 | // built is trying to access its own class, so that the generated |
| 1405 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1406 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1407 | bool dont_use_is_referrers_class; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1408 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1409 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1410 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1411 | if (!can_access) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1412 | MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1413 | return false; |
| 1414 | } |
| 1415 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1416 | HLoadClass* cls = new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1417 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 1418 | type_index, |
| 1419 | *dex_compilation_unit_->GetDexFile(), |
| 1420 | IsOutermostCompilingClass(type_index), |
| 1421 | dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1422 | current_block_->AddInstruction(cls); |
| 1423 | // The class needs a temporary before being used by the type check. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1424 | Temporaries temps(graph_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1425 | temps.Add(cls); |
| 1426 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
| 1427 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1428 | new (arena_) HInstanceOf(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1429 | UpdateLocal(destination, current_block_->GetLastInstruction()); |
| 1430 | } else { |
| 1431 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
| 1432 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1433 | new (arena_) HCheckCast(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1434 | } |
| 1435 | return true; |
| 1436 | } |
| 1437 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1438 | bool HGraphBuilder::NeedsAccessCheck(uint32_t type_index) const { |
| 1439 | return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks( |
| 1440 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index); |
| 1441 | } |
| 1442 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1443 | void HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1444 | // Verifier guarantees that the payload for PackedSwitch contains: |
| 1445 | // (a) number of entries (may be zero) |
| 1446 | // (b) first and lowest switch case value (entry 0, always present) |
| 1447 | // (c) list of target pcs (entries 1 <= i <= N) |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1448 | SwitchTable table(instruction, dex_pc, false); |
| 1449 | |
| 1450 | // Value to test against. |
| 1451 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 1452 | |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1453 | // Retrieve number of entries. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1454 | uint16_t num_entries = table.GetNumEntries(); |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1455 | if (num_entries == 0) { |
| 1456 | return; |
| 1457 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1458 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1459 | // Chained cmp-and-branch, starting from starting_key. |
| 1460 | int32_t starting_key = table.GetEntryAt(0); |
| 1461 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1462 | for (size_t i = 1; i <= num_entries; i++) { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1463 | BuildSwitchCaseHelper(instruction, i, i == num_entries, table, value, starting_key + i - 1, |
| 1464 | table.GetEntryAt(i), dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1465 | } |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1466 | } |
| 1467 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1468 | void HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1469 | // Verifier guarantees that the payload for SparseSwitch contains: |
| 1470 | // (a) number of entries (may be zero) |
| 1471 | // (b) sorted key values (entries 0 <= i < N) |
| 1472 | // (c) target pcs corresponding to the switch values (entries N <= i < 2*N) |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1473 | SwitchTable table(instruction, dex_pc, true); |
| 1474 | |
| 1475 | // Value to test against. |
| 1476 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 1477 | |
| 1478 | uint16_t num_entries = table.GetNumEntries(); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1479 | |
| 1480 | for (size_t i = 0; i < num_entries; i++) { |
| 1481 | BuildSwitchCaseHelper(instruction, i, i == static_cast<size_t>(num_entries) - 1, table, value, |
| 1482 | table.GetEntryAt(i), table.GetEntryAt(i + num_entries), dex_pc); |
| 1483 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | void HGraphBuilder::BuildSwitchCaseHelper(const Instruction& instruction, size_t index, |
| 1487 | bool is_last_case, const SwitchTable& table, |
| 1488 | HInstruction* value, int32_t case_value_int, |
| 1489 | int32_t target_offset, uint32_t dex_pc) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1490 | HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset); |
| 1491 | DCHECK(case_target != nullptr); |
| 1492 | PotentiallyAddSuspendCheck(case_target, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1493 | |
| 1494 | // The current case's value. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1495 | HInstruction* this_case_value = graph_->GetIntConstant(case_value_int); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1496 | |
| 1497 | // Compare value and this_case_value. |
| 1498 | HEqual* comparison = new (arena_) HEqual(value, this_case_value); |
| 1499 | current_block_->AddInstruction(comparison); |
| 1500 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 1501 | current_block_->AddInstruction(ifinst); |
| 1502 | |
| 1503 | // Case hit: use the target offset to determine where to go. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1504 | current_block_->AddSuccessor(case_target); |
| 1505 | |
| 1506 | // Case miss: go to the next case (or default fall-through). |
| 1507 | // When there is a next case, we use the block stored with the table offset representing this |
| 1508 | // case (that is where we registered them in ComputeBranchTargets). |
| 1509 | // When there is no next case, we use the following instruction. |
| 1510 | // TODO: Find a good way to peel the last iteration to avoid conditional, but still have re-use. |
| 1511 | if (!is_last_case) { |
| 1512 | HBasicBlock* next_case_target = FindBlockStartingAt(table.GetDexPcForIndex(index)); |
| 1513 | DCHECK(next_case_target != nullptr); |
| 1514 | current_block_->AddSuccessor(next_case_target); |
| 1515 | |
| 1516 | // Need to manually add the block, as there is no dex-pc transition for the cases. |
| 1517 | graph_->AddBlock(next_case_target); |
| 1518 | |
| 1519 | current_block_ = next_case_target; |
| 1520 | } else { |
| 1521 | HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 1522 | DCHECK(default_target != nullptr); |
| 1523 | current_block_->AddSuccessor(default_target); |
| 1524 | current_block_ = nullptr; |
| 1525 | } |
| 1526 | } |
| 1527 | |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1528 | void HGraphBuilder::PotentiallyAddSuspendCheck(HBasicBlock* target, uint32_t dex_pc) { |
| 1529 | int32_t target_offset = target->GetDexPc() - dex_pc; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1530 | if (target_offset <= 0) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1531 | // DX generates back edges to the first encountered return. We can save |
| 1532 | // time of later passes by not adding redundant suspend checks. |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame] | 1533 | HInstruction* last_in_target = target->GetLastInstruction(); |
| 1534 | if (last_in_target != nullptr && |
| 1535 | (last_in_target->IsReturn() || last_in_target->IsReturnVoid())) { |
| 1536 | return; |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | // Add a suspend check to backward branches which may potentially loop. We |
| 1540 | // can remove them after we recognize loops in the graph. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1541 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc)); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1545 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1546 | if (current_block_ == nullptr) { |
| 1547 | return true; // Dead code |
| 1548 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1549 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1550 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1551 | case Instruction::CONST_4: { |
| 1552 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1553 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1554 | UpdateLocal(register_index, constant); |
| 1555 | break; |
| 1556 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1557 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1558 | case Instruction::CONST_16: { |
| 1559 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1560 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1561 | UpdateLocal(register_index, constant); |
| 1562 | break; |
| 1563 | } |
| 1564 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1565 | case Instruction::CONST: { |
| 1566 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1567 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i()); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1568 | UpdateLocal(register_index, constant); |
| 1569 | break; |
| 1570 | } |
| 1571 | |
| 1572 | case Instruction::CONST_HIGH16: { |
| 1573 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1574 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1575 | UpdateLocal(register_index, constant); |
| 1576 | break; |
| 1577 | } |
| 1578 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1579 | case Instruction::CONST_WIDE_16: { |
| 1580 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1581 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 1582 | int64_t value = instruction.VRegB_21s(); |
| 1583 | value <<= 48; |
| 1584 | value >>= 48; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1585 | HLongConstant* constant = graph_->GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1586 | UpdateLocal(register_index, constant); |
| 1587 | break; |
| 1588 | } |
| 1589 | |
| 1590 | case Instruction::CONST_WIDE_32: { |
| 1591 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1592 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 1593 | int64_t value = instruction.VRegB_31i(); |
| 1594 | value <<= 32; |
| 1595 | value >>= 32; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1596 | HLongConstant* constant = graph_->GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1597 | UpdateLocal(register_index, constant); |
| 1598 | break; |
| 1599 | } |
| 1600 | |
| 1601 | case Instruction::CONST_WIDE: { |
| 1602 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1603 | HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1604 | UpdateLocal(register_index, constant); |
| 1605 | break; |
| 1606 | } |
| 1607 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1608 | case Instruction::CONST_WIDE_HIGH16: { |
| 1609 | int32_t register_index = instruction.VRegA(); |
| 1610 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1611 | HLongConstant* constant = graph_->GetLongConstant(value); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1612 | UpdateLocal(register_index, constant); |
| 1613 | break; |
| 1614 | } |
| 1615 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1616 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1617 | case Instruction::MOVE: |
| 1618 | case Instruction::MOVE_FROM16: |
| 1619 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1620 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1621 | UpdateLocal(instruction.VRegA(), value); |
| 1622 | break; |
| 1623 | } |
| 1624 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1625 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1626 | case Instruction::MOVE_WIDE: |
| 1627 | case Instruction::MOVE_WIDE_FROM16: |
| 1628 | case Instruction::MOVE_WIDE_16: { |
| 1629 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 1630 | UpdateLocal(instruction.VRegA(), value); |
| 1631 | break; |
| 1632 | } |
| 1633 | |
| 1634 | case Instruction::MOVE_OBJECT: |
| 1635 | case Instruction::MOVE_OBJECT_16: |
| 1636 | case Instruction::MOVE_OBJECT_FROM16: { |
| 1637 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 1638 | UpdateLocal(instruction.VRegA(), value); |
| 1639 | break; |
| 1640 | } |
| 1641 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1642 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1643 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1644 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1647 | #define IF_XX(comparison, cond) \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1648 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 1649 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1650 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1651 | IF_XX(HEqual, EQ); |
| 1652 | IF_XX(HNotEqual, NE); |
| 1653 | IF_XX(HLessThan, LT); |
| 1654 | IF_XX(HLessThanOrEqual, LE); |
| 1655 | IF_XX(HGreaterThan, GT); |
| 1656 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1657 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1658 | case Instruction::GOTO: |
| 1659 | case Instruction::GOTO_16: |
| 1660 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1661 | int32_t offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1662 | HBasicBlock* target = FindBlockStartingAt(offset + dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1663 | DCHECK(target != nullptr); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1664 | PotentiallyAddSuspendCheck(target, dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1665 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 1666 | current_block_->AddSuccessor(target); |
| 1667 | current_block_ = nullptr; |
| 1668 | break; |
| 1669 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1670 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1671 | case Instruction::RETURN: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1672 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1673 | break; |
| 1674 | } |
| 1675 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1676 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1677 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1678 | break; |
| 1679 | } |
| 1680 | |
| 1681 | case Instruction::RETURN_WIDE: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1682 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1683 | break; |
| 1684 | } |
| 1685 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1686 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1687 | case Instruction::INVOKE_INTERFACE: |
| 1688 | case Instruction::INVOKE_STATIC: |
| 1689 | case Instruction::INVOKE_SUPER: |
| 1690 | case Instruction::INVOKE_VIRTUAL: { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1691 | uint32_t method_idx = instruction.VRegB_35c(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1692 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1693 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1694 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1695 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1696 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1697 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1698 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1699 | break; |
| 1700 | } |
| 1701 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1702 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1703 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 1704 | case Instruction::INVOKE_STATIC_RANGE: |
| 1705 | case Instruction::INVOKE_SUPER_RANGE: |
| 1706 | case Instruction::INVOKE_VIRTUAL_RANGE: { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1707 | uint32_t method_idx = instruction.VRegB_3rc(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1708 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1709 | uint32_t register_index = instruction.VRegC(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1710 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1711 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1712 | return false; |
| 1713 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1714 | break; |
| 1715 | } |
| 1716 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1717 | case Instruction::NEG_INT: { |
| 1718 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt); |
| 1719 | break; |
| 1720 | } |
| 1721 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1722 | case Instruction::NEG_LONG: { |
| 1723 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong); |
| 1724 | break; |
| 1725 | } |
| 1726 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1727 | case Instruction::NEG_FLOAT: { |
| 1728 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat); |
| 1729 | break; |
| 1730 | } |
| 1731 | |
| 1732 | case Instruction::NEG_DOUBLE: { |
| 1733 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble); |
| 1734 | break; |
| 1735 | } |
| 1736 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1737 | case Instruction::NOT_INT: { |
| 1738 | Unop_12x<HNot>(instruction, Primitive::kPrimInt); |
| 1739 | break; |
| 1740 | } |
| 1741 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1742 | case Instruction::NOT_LONG: { |
| 1743 | Unop_12x<HNot>(instruction, Primitive::kPrimLong); |
| 1744 | break; |
| 1745 | } |
| 1746 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1747 | case Instruction::INT_TO_LONG: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1748 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1749 | break; |
| 1750 | } |
| 1751 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1752 | case Instruction::INT_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1753 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1754 | break; |
| 1755 | } |
| 1756 | |
| 1757 | case Instruction::INT_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1758 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1759 | break; |
| 1760 | } |
| 1761 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1762 | case Instruction::LONG_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1763 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1764 | break; |
| 1765 | } |
| 1766 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1767 | case Instruction::LONG_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1768 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1769 | break; |
| 1770 | } |
| 1771 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1772 | case Instruction::LONG_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1773 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1774 | break; |
| 1775 | } |
| 1776 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1777 | case Instruction::FLOAT_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1778 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc); |
| 1779 | break; |
| 1780 | } |
| 1781 | |
| 1782 | case Instruction::FLOAT_TO_LONG: { |
| 1783 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1784 | break; |
| 1785 | } |
| 1786 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1787 | case Instruction::FLOAT_TO_DOUBLE: { |
| 1788 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc); |
| 1789 | break; |
| 1790 | } |
| 1791 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1792 | case Instruction::DOUBLE_TO_INT: { |
| 1793 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc); |
| 1794 | break; |
| 1795 | } |
| 1796 | |
| 1797 | case Instruction::DOUBLE_TO_LONG: { |
| 1798 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc); |
| 1799 | break; |
| 1800 | } |
| 1801 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1802 | case Instruction::DOUBLE_TO_FLOAT: { |
| 1803 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc); |
| 1804 | break; |
| 1805 | } |
| 1806 | |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1807 | case Instruction::INT_TO_BYTE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1808 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1809 | break; |
| 1810 | } |
| 1811 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1812 | case Instruction::INT_TO_SHORT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1813 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1814 | break; |
| 1815 | } |
| 1816 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1817 | case Instruction::INT_TO_CHAR: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1818 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1819 | break; |
| 1820 | } |
| 1821 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1822 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1823 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1824 | break; |
| 1825 | } |
| 1826 | |
| 1827 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1828 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1829 | break; |
| 1830 | } |
| 1831 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1832 | case Instruction::ADD_DOUBLE: { |
| 1833 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1834 | break; |
| 1835 | } |
| 1836 | |
| 1837 | case Instruction::ADD_FLOAT: { |
| 1838 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1839 | break; |
| 1840 | } |
| 1841 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1842 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1843 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1844 | break; |
| 1845 | } |
| 1846 | |
| 1847 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1848 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1849 | break; |
| 1850 | } |
| 1851 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1852 | case Instruction::SUB_FLOAT: { |
| 1853 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat); |
| 1854 | break; |
| 1855 | } |
| 1856 | |
| 1857 | case Instruction::SUB_DOUBLE: { |
| 1858 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble); |
| 1859 | break; |
| 1860 | } |
| 1861 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1862 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1863 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 1864 | break; |
| 1865 | } |
| 1866 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1867 | case Instruction::MUL_INT: { |
| 1868 | Binop_23x<HMul>(instruction, Primitive::kPrimInt); |
| 1869 | break; |
| 1870 | } |
| 1871 | |
| 1872 | case Instruction::MUL_LONG: { |
| 1873 | Binop_23x<HMul>(instruction, Primitive::kPrimLong); |
| 1874 | break; |
| 1875 | } |
| 1876 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1877 | case Instruction::MUL_FLOAT: { |
| 1878 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat); |
| 1879 | break; |
| 1880 | } |
| 1881 | |
| 1882 | case Instruction::MUL_DOUBLE: { |
| 1883 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble); |
| 1884 | break; |
| 1885 | } |
| 1886 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1887 | case Instruction::DIV_INT: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1888 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1889 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1890 | break; |
| 1891 | } |
| 1892 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1893 | case Instruction::DIV_LONG: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1894 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1895 | dex_pc, Primitive::kPrimLong, false, true); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1896 | break; |
| 1897 | } |
| 1898 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1899 | case Instruction::DIV_FLOAT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1900 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1901 | break; |
| 1902 | } |
| 1903 | |
| 1904 | case Instruction::DIV_DOUBLE: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1905 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1906 | break; |
| 1907 | } |
| 1908 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1909 | case Instruction::REM_INT: { |
| 1910 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1911 | dex_pc, Primitive::kPrimInt, false, false); |
| 1912 | break; |
| 1913 | } |
| 1914 | |
| 1915 | case Instruction::REM_LONG: { |
| 1916 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1917 | dex_pc, Primitive::kPrimLong, false, false); |
| 1918 | break; |
| 1919 | } |
| 1920 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 1921 | case Instruction::REM_FLOAT: { |
| 1922 | Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 1923 | break; |
| 1924 | } |
| 1925 | |
| 1926 | case Instruction::REM_DOUBLE: { |
| 1927 | Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 1928 | break; |
| 1929 | } |
| 1930 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1931 | case Instruction::AND_INT: { |
| 1932 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt); |
| 1933 | break; |
| 1934 | } |
| 1935 | |
| 1936 | case Instruction::AND_LONG: { |
| 1937 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong); |
| 1938 | break; |
| 1939 | } |
| 1940 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1941 | case Instruction::SHL_INT: { |
| 1942 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 1943 | break; |
| 1944 | } |
| 1945 | |
| 1946 | case Instruction::SHL_LONG: { |
| 1947 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 1948 | break; |
| 1949 | } |
| 1950 | |
| 1951 | case Instruction::SHR_INT: { |
| 1952 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 1953 | break; |
| 1954 | } |
| 1955 | |
| 1956 | case Instruction::SHR_LONG: { |
| 1957 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 1958 | break; |
| 1959 | } |
| 1960 | |
| 1961 | case Instruction::USHR_INT: { |
| 1962 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 1963 | break; |
| 1964 | } |
| 1965 | |
| 1966 | case Instruction::USHR_LONG: { |
| 1967 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 1968 | break; |
| 1969 | } |
| 1970 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1971 | case Instruction::OR_INT: { |
| 1972 | Binop_23x<HOr>(instruction, Primitive::kPrimInt); |
| 1973 | break; |
| 1974 | } |
| 1975 | |
| 1976 | case Instruction::OR_LONG: { |
| 1977 | Binop_23x<HOr>(instruction, Primitive::kPrimLong); |
| 1978 | break; |
| 1979 | } |
| 1980 | |
| 1981 | case Instruction::XOR_INT: { |
| 1982 | Binop_23x<HXor>(instruction, Primitive::kPrimInt); |
| 1983 | break; |
| 1984 | } |
| 1985 | |
| 1986 | case Instruction::XOR_LONG: { |
| 1987 | Binop_23x<HXor>(instruction, Primitive::kPrimLong); |
| 1988 | break; |
| 1989 | } |
| 1990 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1991 | case Instruction::ADD_LONG_2ADDR: { |
| 1992 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1993 | break; |
| 1994 | } |
| 1995 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1996 | case Instruction::ADD_DOUBLE_2ADDR: { |
| 1997 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1998 | break; |
| 1999 | } |
| 2000 | |
| 2001 | case Instruction::ADD_FLOAT_2ADDR: { |
| 2002 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat); |
| 2003 | break; |
| 2004 | } |
| 2005 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2006 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2007 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 2008 | break; |
| 2009 | } |
| 2010 | |
| 2011 | case Instruction::SUB_LONG_2ADDR: { |
| 2012 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2013 | break; |
| 2014 | } |
| 2015 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2016 | case Instruction::SUB_FLOAT_2ADDR: { |
| 2017 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat); |
| 2018 | break; |
| 2019 | } |
| 2020 | |
| 2021 | case Instruction::SUB_DOUBLE_2ADDR: { |
| 2022 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble); |
| 2023 | break; |
| 2024 | } |
| 2025 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2026 | case Instruction::MUL_INT_2ADDR: { |
| 2027 | Binop_12x<HMul>(instruction, Primitive::kPrimInt); |
| 2028 | break; |
| 2029 | } |
| 2030 | |
| 2031 | case Instruction::MUL_LONG_2ADDR: { |
| 2032 | Binop_12x<HMul>(instruction, Primitive::kPrimLong); |
| 2033 | break; |
| 2034 | } |
| 2035 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2036 | case Instruction::MUL_FLOAT_2ADDR: { |
| 2037 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat); |
| 2038 | break; |
| 2039 | } |
| 2040 | |
| 2041 | case Instruction::MUL_DOUBLE_2ADDR: { |
| 2042 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble); |
| 2043 | break; |
| 2044 | } |
| 2045 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2046 | case Instruction::DIV_INT_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2047 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2048 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2049 | break; |
| 2050 | } |
| 2051 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2052 | case Instruction::DIV_LONG_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2053 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2054 | dex_pc, Primitive::kPrimLong, false, true); |
| 2055 | break; |
| 2056 | } |
| 2057 | |
| 2058 | case Instruction::REM_INT_2ADDR: { |
| 2059 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2060 | dex_pc, Primitive::kPrimInt, false, false); |
| 2061 | break; |
| 2062 | } |
| 2063 | |
| 2064 | case Instruction::REM_LONG_2ADDR: { |
| 2065 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2066 | dex_pc, Primitive::kPrimLong, false, false); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2067 | break; |
| 2068 | } |
| 2069 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2070 | case Instruction::REM_FLOAT_2ADDR: { |
| 2071 | Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 2072 | break; |
| 2073 | } |
| 2074 | |
| 2075 | case Instruction::REM_DOUBLE_2ADDR: { |
| 2076 | Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 2077 | break; |
| 2078 | } |
| 2079 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2080 | case Instruction::SHL_INT_2ADDR: { |
| 2081 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 2082 | break; |
| 2083 | } |
| 2084 | |
| 2085 | case Instruction::SHL_LONG_2ADDR: { |
| 2086 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 2087 | break; |
| 2088 | } |
| 2089 | |
| 2090 | case Instruction::SHR_INT_2ADDR: { |
| 2091 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 2092 | break; |
| 2093 | } |
| 2094 | |
| 2095 | case Instruction::SHR_LONG_2ADDR: { |
| 2096 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 2097 | break; |
| 2098 | } |
| 2099 | |
| 2100 | case Instruction::USHR_INT_2ADDR: { |
| 2101 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 2102 | break; |
| 2103 | } |
| 2104 | |
| 2105 | case Instruction::USHR_LONG_2ADDR: { |
| 2106 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 2107 | break; |
| 2108 | } |
| 2109 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2110 | case Instruction::DIV_FLOAT_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2111 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2112 | break; |
| 2113 | } |
| 2114 | |
| 2115 | case Instruction::DIV_DOUBLE_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2116 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2117 | break; |
| 2118 | } |
| 2119 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2120 | case Instruction::AND_INT_2ADDR: { |
| 2121 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt); |
| 2122 | break; |
| 2123 | } |
| 2124 | |
| 2125 | case Instruction::AND_LONG_2ADDR: { |
| 2126 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong); |
| 2127 | break; |
| 2128 | } |
| 2129 | |
| 2130 | case Instruction::OR_INT_2ADDR: { |
| 2131 | Binop_12x<HOr>(instruction, Primitive::kPrimInt); |
| 2132 | break; |
| 2133 | } |
| 2134 | |
| 2135 | case Instruction::OR_LONG_2ADDR: { |
| 2136 | Binop_12x<HOr>(instruction, Primitive::kPrimLong); |
| 2137 | break; |
| 2138 | } |
| 2139 | |
| 2140 | case Instruction::XOR_INT_2ADDR: { |
| 2141 | Binop_12x<HXor>(instruction, Primitive::kPrimInt); |
| 2142 | break; |
| 2143 | } |
| 2144 | |
| 2145 | case Instruction::XOR_LONG_2ADDR: { |
| 2146 | Binop_12x<HXor>(instruction, Primitive::kPrimLong); |
| 2147 | break; |
| 2148 | } |
| 2149 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2150 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2151 | Binop_22s<HAdd>(instruction, false); |
| 2152 | break; |
| 2153 | } |
| 2154 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2155 | case Instruction::AND_INT_LIT16: { |
| 2156 | Binop_22s<HAnd>(instruction, false); |
| 2157 | break; |
| 2158 | } |
| 2159 | |
| 2160 | case Instruction::OR_INT_LIT16: { |
| 2161 | Binop_22s<HOr>(instruction, false); |
| 2162 | break; |
| 2163 | } |
| 2164 | |
| 2165 | case Instruction::XOR_INT_LIT16: { |
| 2166 | Binop_22s<HXor>(instruction, false); |
| 2167 | break; |
| 2168 | } |
| 2169 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2170 | case Instruction::RSUB_INT: { |
| 2171 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2172 | break; |
| 2173 | } |
| 2174 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2175 | case Instruction::MUL_INT_LIT16: { |
| 2176 | Binop_22s<HMul>(instruction, false); |
| 2177 | break; |
| 2178 | } |
| 2179 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2180 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2181 | Binop_22b<HAdd>(instruction, false); |
| 2182 | break; |
| 2183 | } |
| 2184 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2185 | case Instruction::AND_INT_LIT8: { |
| 2186 | Binop_22b<HAnd>(instruction, false); |
| 2187 | break; |
| 2188 | } |
| 2189 | |
| 2190 | case Instruction::OR_INT_LIT8: { |
| 2191 | Binop_22b<HOr>(instruction, false); |
| 2192 | break; |
| 2193 | } |
| 2194 | |
| 2195 | case Instruction::XOR_INT_LIT8: { |
| 2196 | Binop_22b<HXor>(instruction, false); |
| 2197 | break; |
| 2198 | } |
| 2199 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2200 | case Instruction::RSUB_INT_LIT8: { |
| 2201 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2202 | break; |
| 2203 | } |
| 2204 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2205 | case Instruction::MUL_INT_LIT8: { |
| 2206 | Binop_22b<HMul>(instruction, false); |
| 2207 | break; |
| 2208 | } |
| 2209 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2210 | case Instruction::DIV_INT_LIT16: |
| 2211 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2212 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2213 | dex_pc, Primitive::kPrimInt, true, true); |
| 2214 | break; |
| 2215 | } |
| 2216 | |
| 2217 | case Instruction::REM_INT_LIT16: |
| 2218 | case Instruction::REM_INT_LIT8: { |
| 2219 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2220 | dex_pc, Primitive::kPrimInt, true, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2221 | break; |
| 2222 | } |
| 2223 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2224 | case Instruction::SHL_INT_LIT8: { |
| 2225 | Binop_22b<HShl>(instruction, false); |
| 2226 | break; |
| 2227 | } |
| 2228 | |
| 2229 | case Instruction::SHR_INT_LIT8: { |
| 2230 | Binop_22b<HShr>(instruction, false); |
| 2231 | break; |
| 2232 | } |
| 2233 | |
| 2234 | case Instruction::USHR_INT_LIT8: { |
| 2235 | Binop_22b<HUShr>(instruction, false); |
| 2236 | break; |
| 2237 | } |
| 2238 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2239 | case Instruction::NEW_INSTANCE: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2240 | uint16_t type_index = instruction.VRegB_21c(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2241 | if (compiler_driver_->IsStringTypeIndex(type_index, dex_file_)) { |
| 2242 | // Turn new-instance of string into a const 0. |
| 2243 | int32_t register_index = instruction.VRegA(); |
| 2244 | HNullConstant* constant = graph_->GetNullConstant(); |
| 2245 | UpdateLocal(register_index, constant); |
| 2246 | } else { |
| 2247 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 2248 | ? kQuickAllocObjectWithAccessCheck |
| 2249 | : kQuickAllocObject; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2250 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2251 | current_block_->AddInstruction(new (arena_) HNewInstance( |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2252 | graph_->GetCurrentMethod(), |
| 2253 | dex_pc, |
| 2254 | type_index, |
| 2255 | *dex_compilation_unit_->GetDexFile(), |
| 2256 | entrypoint)); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2257 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 2258 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2259 | break; |
| 2260 | } |
| 2261 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2262 | case Instruction::NEW_ARRAY: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2263 | uint16_t type_index = instruction.VRegC_22c(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2264 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2265 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 2266 | ? kQuickAllocArrayWithAccessCheck |
| 2267 | : kQuickAllocArray; |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2268 | current_block_->AddInstruction(new (arena_) HNewArray(length, |
| 2269 | graph_->GetCurrentMethod(), |
| 2270 | dex_pc, |
| 2271 | type_index, |
| 2272 | *dex_compilation_unit_->GetDexFile(), |
| 2273 | entrypoint)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2274 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 2275 | break; |
| 2276 | } |
| 2277 | |
| 2278 | case Instruction::FILLED_NEW_ARRAY: { |
| 2279 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 2280 | uint32_t type_index = instruction.VRegB_35c(); |
| 2281 | uint32_t args[5]; |
| 2282 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2283 | BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2284 | break; |
| 2285 | } |
| 2286 | |
| 2287 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 2288 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 2289 | uint32_t type_index = instruction.VRegB_3rc(); |
| 2290 | uint32_t register_index = instruction.VRegC_3rc(); |
| 2291 | BuildFilledNewArray( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2292 | dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2293 | break; |
| 2294 | } |
| 2295 | |
| 2296 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2297 | BuildFillArrayData(instruction, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2298 | break; |
| 2299 | } |
| 2300 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2301 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2302 | case Instruction::MOVE_RESULT_WIDE: |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2303 | case Instruction::MOVE_RESULT_OBJECT: { |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2304 | if (latest_result_ == nullptr) { |
| 2305 | // Only dead code can lead to this situation, where the verifier |
| 2306 | // does not reject the method. |
| 2307 | } else { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2308 | // An Invoke/FilledNewArray and its MoveResult could have landed in |
| 2309 | // different blocks if there was a try/catch block boundary between |
| 2310 | // them. For Invoke, we insert a StoreLocal after the instruction. For |
| 2311 | // FilledNewArray, the local needs to be updated after the array was |
| 2312 | // filled, otherwise we might overwrite an input vreg. |
| 2313 | HStoreLocal* update_local = |
| 2314 | new (arena_) HStoreLocal(GetLocalAt(instruction.VRegA()), latest_result_); |
| 2315 | HBasicBlock* block = latest_result_->GetBlock(); |
| 2316 | if (block == current_block_) { |
| 2317 | // MoveResult and the previous instruction are in the same block. |
| 2318 | current_block_->AddInstruction(update_local); |
| 2319 | } else { |
| 2320 | // The two instructions are in different blocks. Insert the MoveResult |
| 2321 | // before the final control-flow instruction of the previous block. |
| 2322 | DCHECK(block->EndsWithControlFlowInstruction()); |
| 2323 | DCHECK(current_block_->GetInstructions().IsEmpty()); |
| 2324 | block->InsertInstructionBefore(update_local, block->GetLastInstruction()); |
| 2325 | } |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2326 | latest_result_ = nullptr; |
| 2327 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2328 | break; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2329 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2330 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2331 | case Instruction::CMP_LONG: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2332 | Binop_23x_cmp(instruction, Primitive::kPrimLong, kNoBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2333 | break; |
| 2334 | } |
| 2335 | |
| 2336 | case Instruction::CMPG_FLOAT: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2337 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2338 | break; |
| 2339 | } |
| 2340 | |
| 2341 | case Instruction::CMPG_DOUBLE: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2342 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2343 | break; |
| 2344 | } |
| 2345 | |
| 2346 | case Instruction::CMPL_FLOAT: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2347 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, kLtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2348 | break; |
| 2349 | } |
| 2350 | |
| 2351 | case Instruction::CMPL_DOUBLE: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2352 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, kLtBias, dex_pc); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2353 | break; |
| 2354 | } |
| 2355 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2356 | case Instruction::NOP: |
| 2357 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2358 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2359 | case Instruction::IGET: |
| 2360 | case Instruction::IGET_WIDE: |
| 2361 | case Instruction::IGET_OBJECT: |
| 2362 | case Instruction::IGET_BOOLEAN: |
| 2363 | case Instruction::IGET_BYTE: |
| 2364 | case Instruction::IGET_CHAR: |
| 2365 | case Instruction::IGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2366 | if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2367 | return false; |
| 2368 | } |
| 2369 | break; |
| 2370 | } |
| 2371 | |
| 2372 | case Instruction::IPUT: |
| 2373 | case Instruction::IPUT_WIDE: |
| 2374 | case Instruction::IPUT_OBJECT: |
| 2375 | case Instruction::IPUT_BOOLEAN: |
| 2376 | case Instruction::IPUT_BYTE: |
| 2377 | case Instruction::IPUT_CHAR: |
| 2378 | case Instruction::IPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2379 | if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2380 | return false; |
| 2381 | } |
| 2382 | break; |
| 2383 | } |
| 2384 | |
| 2385 | case Instruction::SGET: |
| 2386 | case Instruction::SGET_WIDE: |
| 2387 | case Instruction::SGET_OBJECT: |
| 2388 | case Instruction::SGET_BOOLEAN: |
| 2389 | case Instruction::SGET_BYTE: |
| 2390 | case Instruction::SGET_CHAR: |
| 2391 | case Instruction::SGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2392 | if (!BuildStaticFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2393 | return false; |
| 2394 | } |
| 2395 | break; |
| 2396 | } |
| 2397 | |
| 2398 | case Instruction::SPUT: |
| 2399 | case Instruction::SPUT_WIDE: |
| 2400 | case Instruction::SPUT_OBJECT: |
| 2401 | case Instruction::SPUT_BOOLEAN: |
| 2402 | case Instruction::SPUT_BYTE: |
| 2403 | case Instruction::SPUT_CHAR: |
| 2404 | case Instruction::SPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2405 | if (!BuildStaticFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2406 | return false; |
| 2407 | } |
| 2408 | break; |
| 2409 | } |
| 2410 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2411 | #define ARRAY_XX(kind, anticipated_type) \ |
| 2412 | case Instruction::AGET##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2413 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2414 | break; \ |
| 2415 | } \ |
| 2416 | case Instruction::APUT##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2417 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2418 | break; \ |
| 2419 | } |
| 2420 | |
| 2421 | ARRAY_XX(, Primitive::kPrimInt); |
| 2422 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 2423 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 2424 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 2425 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 2426 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 2427 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 2428 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2429 | case Instruction::ARRAY_LENGTH: { |
| 2430 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2431 | // No need for a temporary for the null check, it is the only input of the following |
| 2432 | // instruction. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2433 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2434 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2435 | current_block_->AddInstruction(new (arena_) HArrayLength(object)); |
| 2436 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 2437 | break; |
| 2438 | } |
| 2439 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2440 | case Instruction::CONST_STRING: { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2441 | current_block_->AddInstruction( |
| 2442 | new (arena_) HLoadString(graph_->GetCurrentMethod(), instruction.VRegB_21c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2443 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 2444 | break; |
| 2445 | } |
| 2446 | |
| 2447 | case Instruction::CONST_STRING_JUMBO: { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2448 | current_block_->AddInstruction( |
| 2449 | new (arena_) HLoadString(graph_->GetCurrentMethod(), instruction.VRegB_31c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2450 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 2451 | break; |
| 2452 | } |
| 2453 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2454 | case Instruction::CONST_CLASS: { |
| 2455 | uint16_t type_index = instruction.VRegB_21c(); |
| 2456 | bool type_known_final; |
| 2457 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2458 | bool dont_use_is_referrers_class; |
| 2459 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 2460 | // built is trying to access its own class, so that the generated |
| 2461 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2462 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2463 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 2464 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2465 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2466 | if (!can_access) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2467 | MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2468 | return false; |
| 2469 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2470 | current_block_->AddInstruction(new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2471 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2472 | type_index, |
| 2473 | *dex_compilation_unit_->GetDexFile(), |
| 2474 | IsOutermostCompilingClass(type_index), |
| 2475 | dex_pc)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2476 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 2477 | break; |
| 2478 | } |
| 2479 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2480 | case Instruction::MOVE_EXCEPTION: { |
| 2481 | current_block_->AddInstruction(new (arena_) HLoadException()); |
| 2482 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
| 2483 | break; |
| 2484 | } |
| 2485 | |
| 2486 | case Instruction::THROW: { |
| 2487 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2488 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2489 | // A throw instruction must branch to the exit block. |
| 2490 | current_block_->AddSuccessor(exit_block_); |
| 2491 | // We finished building this block. Set the current block to null to avoid |
| 2492 | // adding dead instructions to it. |
| 2493 | current_block_ = nullptr; |
| 2494 | break; |
| 2495 | } |
| 2496 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2497 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2498 | uint8_t destination = instruction.VRegA_22c(); |
| 2499 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2500 | uint16_t type_index = instruction.VRegC_22c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2501 | if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2502 | return false; |
| 2503 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2504 | break; |
| 2505 | } |
| 2506 | |
| 2507 | case Instruction::CHECK_CAST: { |
| 2508 | uint8_t reference = instruction.VRegA_21c(); |
| 2509 | uint16_t type_index = instruction.VRegB_21c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2510 | if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2511 | return false; |
| 2512 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2513 | break; |
| 2514 | } |
| 2515 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2516 | case Instruction::MONITOR_ENTER: { |
| 2517 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 2518 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 2519 | HMonitorOperation::kEnter, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2520 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | } |
| 2523 | |
| 2524 | case Instruction::MONITOR_EXIT: { |
| 2525 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 2526 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 2527 | HMonitorOperation::kExit, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2528 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2529 | break; |
| 2530 | } |
| 2531 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2532 | case Instruction::PACKED_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2533 | BuildPackedSwitch(instruction, dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2534 | break; |
| 2535 | } |
| 2536 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2537 | case Instruction::SPARSE_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2538 | BuildSparseSwitch(instruction, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2539 | break; |
| 2540 | } |
| 2541 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2542 | default: |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2543 | VLOG(compiler) << "Did not compile " |
| 2544 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 2545 | << " because of unhandled instruction " |
| 2546 | << instruction.Name(); |
| 2547 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnhandledInstruction); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2548 | return false; |
| 2549 | } |
| 2550 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2551 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2552 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2553 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 2554 | return locals_.Get(register_index); |
| 2555 | } |
| 2556 | |
| 2557 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 2558 | HLocal* local = GetLocalAt(register_index); |
| 2559 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 2560 | } |
| 2561 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2562 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2563 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2564 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2565 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2568 | } // namespace art |