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 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 759 | void HGraphBuilder::PotentiallySimplifyFakeString(uint16_t original_dex_register, |
| 760 | uint32_t dex_pc, |
| 761 | HInvoke* actual_string) { |
| 762 | if (!graph_->IsDebuggable()) { |
| 763 | // Notify that we cannot compile with baseline. The dex registers aliasing |
| 764 | // with `original_dex_register` will be handled when we optimize |
| 765 | // (see HInstructionSimplifer::VisitFakeString). |
| 766 | can_use_baseline_for_string_init_ = false; |
| 767 | return; |
| 768 | } |
| 769 | const VerifiedMethod* verified_method = |
| 770 | compiler_driver_->GetVerifiedMethod(dex_file_, dex_compilation_unit_->GetDexMethodIndex()); |
| 771 | if (verified_method != nullptr) { |
| 772 | UpdateLocal(original_dex_register, actual_string); |
| 773 | const SafeMap<uint32_t, std::set<uint32_t>>& string_init_map = |
| 774 | verified_method->GetStringInitPcRegMap(); |
| 775 | auto map_it = string_init_map.find(dex_pc); |
| 776 | if (map_it != string_init_map.end()) { |
| 777 | std::set<uint32_t> reg_set = map_it->second; |
| 778 | for (auto set_it = reg_set.begin(); set_it != reg_set.end(); ++set_it) { |
| 779 | HInstruction* load_local = LoadLocal(original_dex_register, Primitive::kPrimNot); |
| 780 | UpdateLocal(*set_it, load_local); |
| 781 | } |
| 782 | } |
| 783 | } else { |
| 784 | can_use_baseline_for_string_init_ = false; |
| 785 | } |
| 786 | } |
| 787 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 788 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 789 | uint32_t dex_pc, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 790 | uint32_t method_idx, |
| 791 | uint32_t number_of_vreg_arguments, |
| 792 | bool is_range, |
| 793 | uint32_t* args, |
| 794 | uint32_t register_index) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 795 | Instruction::Code opcode = instruction.Opcode(); |
| 796 | InvokeType invoke_type; |
| 797 | switch (opcode) { |
| 798 | case Instruction::INVOKE_STATIC: |
| 799 | case Instruction::INVOKE_STATIC_RANGE: |
| 800 | invoke_type = kStatic; |
| 801 | break; |
| 802 | case Instruction::INVOKE_DIRECT: |
| 803 | case Instruction::INVOKE_DIRECT_RANGE: |
| 804 | invoke_type = kDirect; |
| 805 | break; |
| 806 | case Instruction::INVOKE_VIRTUAL: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 807 | case Instruction::INVOKE_VIRTUAL_QUICK: |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 808 | case Instruction::INVOKE_VIRTUAL_RANGE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 809 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 810 | invoke_type = kVirtual; |
| 811 | break; |
| 812 | case Instruction::INVOKE_INTERFACE: |
| 813 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 814 | invoke_type = kInterface; |
| 815 | break; |
| 816 | case Instruction::INVOKE_SUPER_RANGE: |
| 817 | case Instruction::INVOKE_SUPER: |
| 818 | invoke_type = kSuper; |
| 819 | break; |
| 820 | default: |
| 821 | LOG(FATAL) << "Unexpected invoke op: " << opcode; |
| 822 | return false; |
| 823 | } |
| 824 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 825 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 826 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 827 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 828 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 829 | bool is_instance_call = invoke_type != kStatic; |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 830 | // Remove the return type from the 'proto'. |
| 831 | size_t number_of_arguments = strlen(descriptor) - 1; |
| 832 | if (is_instance_call) { |
| 833 | // One extra argument for 'this'. |
| 834 | ++number_of_arguments; |
| 835 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 836 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 837 | MethodReference target_method(dex_file_, method_idx); |
| 838 | uintptr_t direct_code; |
| 839 | uintptr_t direct_method; |
| 840 | int table_index; |
| 841 | InvokeType optimized_invoke_type = invoke_type; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 842 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 843 | if (!compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_pc, true, true, |
| 844 | &optimized_invoke_type, &target_method, &table_index, |
| 845 | &direct_code, &direct_method)) { |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 846 | VLOG(compiler) << "Did not compile " |
| 847 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 848 | << " because a method call could not be resolved"; |
| 849 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedMethod); |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 850 | return false; |
| 851 | } |
| 852 | DCHECK(optimized_invoke_type != kSuper); |
| 853 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 854 | // By default, consider that the called method implicitly requires |
| 855 | // an initialization check of its declaring method. |
| 856 | HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement = |
| 857 | HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit; |
| 858 | // Potential class initialization check, in the case of a static method call. |
| 859 | HClinitCheck* clinit_check = nullptr; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 860 | // Replace calls to String.<init> with StringFactory. |
| 861 | int32_t string_init_offset = 0; |
| 862 | bool is_string_init = compiler_driver_->IsStringInit(method_idx, dex_file_, &string_init_offset); |
| 863 | if (is_string_init) { |
| 864 | return_type = Primitive::kPrimNot; |
| 865 | is_instance_call = false; |
| 866 | number_of_arguments--; |
| 867 | invoke_type = kStatic; |
| 868 | optimized_invoke_type = kStatic; |
| 869 | } |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 870 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 871 | HInvoke* invoke = nullptr; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 872 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 873 | if (optimized_invoke_type == kVirtual) { |
| 874 | invoke = new (arena_) HInvokeVirtual( |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 875 | arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 876 | } else if (optimized_invoke_type == kInterface) { |
| 877 | invoke = new (arena_) HInvokeInterface( |
| 878 | arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 879 | } else { |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 880 | DCHECK(optimized_invoke_type == kDirect || optimized_invoke_type == kStatic); |
| 881 | // Sharpening to kDirect only works if we compile PIC. |
| 882 | DCHECK((optimized_invoke_type == invoke_type) || (optimized_invoke_type != kDirect) |
| 883 | || compiler_driver_->GetCompilerOptions().GetCompilePic()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 884 | bool is_recursive = |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 885 | (target_method.dex_method_index == outer_compilation_unit_->GetDexMethodIndex()) |
| 886 | && (target_method.dex_file == outer_compilation_unit_->GetDexFile()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 887 | |
Jeff Hao | cad6542 | 2015-06-18 21:16:08 -0700 | [diff] [blame] | 888 | if (optimized_invoke_type == kStatic && !is_string_init) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 889 | ScopedObjectAccess soa(Thread::Current()); |
| 890 | StackHandleScope<4> hs(soa.Self()); |
| 891 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 892 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 893 | *dex_compilation_unit_->GetDexFile()))); |
| 894 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 895 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 896 | ArtMethod* resolved_method = compiler_driver_->ResolveMethod( |
| 897 | 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] | 898 | |
| 899 | if (resolved_method == nullptr) { |
| 900 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedMethod); |
| 901 | return false; |
| 902 | } |
| 903 | |
| 904 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 905 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 906 | outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file))); |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 907 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 908 | |
| 909 | // The index at which the method's class is stored in the DexCache's type array. |
| 910 | uint32_t storage_index = DexFile::kDexNoIndex; |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 911 | bool is_outer_class = (resolved_method->GetDeclaringClass() == outer_class.Get()); |
| 912 | if (is_outer_class) { |
| 913 | storage_index = outer_class->GetDexTypeIndex(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 914 | } else if (outer_dex_cache.Get() == dex_cache.Get()) { |
| 915 | // Get `storage_index` from IsClassOfStaticMethodAvailableToReferrer. |
| 916 | compiler_driver_->IsClassOfStaticMethodAvailableToReferrer(outer_dex_cache.Get(), |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 917 | GetCompilingClass(), |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 918 | resolved_method, |
| 919 | method_idx, |
| 920 | &storage_index); |
| 921 | } |
| 922 | |
Nicolas Geoffray | b783b40 | 2015-06-22 11:06:43 +0100 | [diff] [blame] | 923 | if (!outer_class->IsInterface() |
| 924 | && outer_class->IsSubClass(resolved_method->GetDeclaringClass())) { |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 925 | // If the outer class is the declaring class or a subclass |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 926 | // of the declaring class, no class initialization is needed |
| 927 | // before the static method call. |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 928 | // Note that in case of inlining, we do not need to add clinit checks |
| 929 | // to calls that satisfy this subclass check with any inlined methods. This |
| 930 | // will be detected by the optimization passes. |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 931 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 932 | } else if (storage_index != DexFile::kDexNoIndex) { |
| 933 | // If the method's class type index is available, check |
| 934 | // whether we should add an explicit class initialization |
| 935 | // check for its declaring class before the static method call. |
| 936 | |
| 937 | // TODO: find out why this check is needed. |
| 938 | bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache( |
| 939 | *outer_compilation_unit_->GetDexFile(), storage_index); |
| 940 | bool is_initialized = |
| 941 | resolved_method->GetDeclaringClass()->IsInitialized() && is_in_dex_cache; |
| 942 | |
| 943 | if (is_initialized) { |
| 944 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 945 | } else { |
| 946 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 947 | HLoadClass* load_class = new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 948 | graph_->GetCurrentMethod(), |
| 949 | storage_index, |
| 950 | *dex_compilation_unit_->GetDexFile(), |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 951 | is_outer_class, |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 952 | dex_pc); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 953 | current_block_->AddInstruction(load_class); |
| 954 | clinit_check = new (arena_) HClinitCheck(load_class, dex_pc); |
| 955 | current_block_->AddInstruction(clinit_check); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
Guillaume "Vermeille" Sanchez | ae09d2d | 2015-05-29 10:52:55 +0100 | [diff] [blame] | 960 | invoke = new (arena_) HInvokeStaticOrDirect(arena_, |
| 961 | number_of_arguments, |
| 962 | return_type, |
| 963 | dex_pc, |
| 964 | target_method.dex_method_index, |
| 965 | is_recursive, |
| 966 | string_init_offset, |
| 967 | invoke_type, |
| 968 | optimized_invoke_type, |
| 969 | clinit_check_requirement); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 970 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 971 | |
| 972 | size_t start_index = 0; |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 973 | Temporaries temps(graph_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 974 | if (is_instance_call) { |
| 975 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 976 | HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_pc); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 977 | current_block_->AddInstruction(null_check); |
| 978 | temps.Add(null_check); |
| 979 | invoke->SetArgumentAt(0, null_check); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 980 | start_index = 1; |
| 981 | } |
| 982 | |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 983 | uint32_t descriptor_index = 1; // Skip the return type. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 984 | uint32_t argument_index = start_index; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 985 | if (is_string_init) { |
| 986 | start_index = 1; |
| 987 | } |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 988 | for (size_t i = start_index; |
| 989 | // Make sure we don't go over the expected arguments or over the number of |
| 990 | // dex registers given. If the instruction was seen as dead by the verifier, |
| 991 | // it hasn't been properly checked. |
| 992 | (i < number_of_vreg_arguments) && (argument_index < number_of_arguments); |
| 993 | i++, argument_index++) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 994 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 995 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 996 | if (!is_range |
| 997 | && is_wide |
| 998 | && ((i + 1 == number_of_vreg_arguments) || (args[i] + 1 != args[i + 1]))) { |
| 999 | // Longs and doubles should be in pairs, that is, sequential registers. The verifier should |
| 1000 | // reject any class where this is violated. However, the verifier only does these checks |
| 1001 | // on non trivially dead instructions, so we just bailout the compilation. |
| 1002 | VLOG(compiler) << "Did not compile " |
| 1003 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 1004 | << " because of non-sequential dex register pair in wide argument"; |
| 1005 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 1006 | return false; |
| 1007 | } |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1008 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 1009 | invoke->SetArgumentAt(argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1010 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1011 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1012 | } |
| 1013 | } |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1014 | |
| 1015 | if (argument_index != number_of_arguments) { |
| 1016 | VLOG(compiler) << "Did not compile " |
| 1017 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 1018 | << " because of wrong number of arguments in invoke instruction"; |
| 1019 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 1020 | return false; |
| 1021 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1022 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1023 | if (invoke->IsInvokeStaticOrDirect()) { |
| 1024 | invoke->SetArgumentAt(argument_index, graph_->GetCurrentMethod()); |
| 1025 | argument_index++; |
| 1026 | } |
| 1027 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1028 | if (clinit_check_requirement == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit) { |
| 1029 | // Add the class initialization check as last input of `invoke`. |
| 1030 | DCHECK(clinit_check != nullptr); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1031 | DCHECK(!is_string_init); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1032 | invoke->SetArgumentAt(argument_index, clinit_check); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1033 | argument_index++; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1034 | } |
| 1035 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1036 | // Add move-result for StringFactory method. |
| 1037 | if (is_string_init) { |
| 1038 | uint32_t orig_this_reg = is_range ? register_index : args[0]; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1039 | HInstruction* fake_string = LoadLocal(orig_this_reg, Primitive::kPrimNot); |
| 1040 | invoke->SetArgumentAt(argument_index, fake_string); |
| 1041 | current_block_->AddInstruction(invoke); |
| 1042 | PotentiallySimplifyFakeString(orig_this_reg, dex_pc, invoke); |
| 1043 | } else { |
| 1044 | current_block_->AddInstruction(invoke); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1045 | } |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1046 | latest_result_ = invoke; |
| 1047 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1048 | return true; |
| 1049 | } |
| 1050 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1051 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1052 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1053 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1054 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 1055 | uint32_t obj_reg = instruction.VRegB_22c(); |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1056 | uint16_t field_index; |
| 1057 | if (instruction.IsQuickened()) { |
| 1058 | if (!CanDecodeQuickenedInfo()) { |
| 1059 | return false; |
| 1060 | } |
| 1061 | field_index = LookupQuickenedInfo(dex_pc); |
| 1062 | } else { |
| 1063 | field_index = instruction.VRegC_22c(); |
| 1064 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1065 | |
| 1066 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1067 | ArtField* resolved_field = |
| 1068 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1069 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1070 | if (resolved_field == nullptr) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1071 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedField); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1072 | return false; |
| 1073 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 1074 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1075 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1076 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1077 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1078 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_pc)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1079 | if (is_put) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1080 | Temporaries temps(graph_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1081 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 1082 | // We need one temporary for the null check. |
| 1083 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1084 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1085 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 1086 | null_check, |
| 1087 | value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1088 | field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 1089 | resolved_field->GetOffset(), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1090 | resolved_field->IsVolatile(), |
| 1091 | field_index, |
| 1092 | *dex_file_)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1093 | } else { |
| 1094 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 1095 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1096 | field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 1097 | resolved_field->GetOffset(), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1098 | resolved_field->IsVolatile(), |
| 1099 | field_index, |
| 1100 | *dex_file_)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1101 | |
| 1102 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1103 | } |
| 1104 | return true; |
| 1105 | } |
| 1106 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1107 | static mirror::Class* GetClassFrom(CompilerDriver* driver, |
| 1108 | const DexCompilationUnit& compilation_unit) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1109 | ScopedObjectAccess soa(Thread::Current()); |
| 1110 | StackHandleScope<2> hs(soa.Self()); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1111 | const DexFile& dex_file = *compilation_unit.GetDexFile(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1112 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1113 | soa.Decode<mirror::ClassLoader*>(compilation_unit.GetClassLoader()))); |
| 1114 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1115 | compilation_unit.GetClassLinker()->FindDexCache(dex_file))); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1116 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1117 | return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit); |
| 1118 | } |
| 1119 | |
| 1120 | mirror::Class* HGraphBuilder::GetOutermostCompilingClass() const { |
| 1121 | return GetClassFrom(compiler_driver_, *outer_compilation_unit_); |
| 1122 | } |
| 1123 | |
| 1124 | mirror::Class* HGraphBuilder::GetCompilingClass() const { |
| 1125 | return GetClassFrom(compiler_driver_, *dex_compilation_unit_); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | bool HGraphBuilder::IsOutermostCompilingClass(uint16_t type_index) const { |
| 1129 | ScopedObjectAccess soa(Thread::Current()); |
| 1130 | StackHandleScope<4> hs(soa.Self()); |
| 1131 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1132 | dex_compilation_unit_->GetClassLinker()->FindDexCache(*dex_compilation_unit_->GetDexFile()))); |
| 1133 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1134 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 1135 | Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass( |
| 1136 | soa, dex_cache, class_loader, type_index, dex_compilation_unit_))); |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 1137 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1138 | |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 1139 | return outer_class.Get() == cls.Get(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1142 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1143 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1144 | bool is_put) { |
| 1145 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1146 | uint16_t field_index = instruction.VRegB_21c(); |
| 1147 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1148 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1149 | StackHandleScope<4> hs(soa.Self()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1150 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1151 | dex_compilation_unit_->GetClassLinker()->FindDexCache(*dex_compilation_unit_->GetDexFile()))); |
| 1152 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1153 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1154 | ArtField* resolved_field = compiler_driver_->ResolveField( |
| 1155 | soa, dex_cache, class_loader, dex_compilation_unit_, field_index, true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1156 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1157 | if (resolved_field == nullptr) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1158 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedField); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1159 | return false; |
| 1160 | } |
| 1161 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1162 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 1163 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 1164 | outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file))); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1165 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1166 | |
| 1167 | // The index at which the field's class is stored in the DexCache's type array. |
| 1168 | uint32_t storage_index; |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1169 | bool is_outer_class = (outer_class.Get() == resolved_field->GetDeclaringClass()); |
| 1170 | if (is_outer_class) { |
| 1171 | storage_index = outer_class->GetDexTypeIndex(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1172 | } else if (outer_dex_cache.Get() != dex_cache.Get()) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1173 | // The compiler driver cannot currently understand multiple dex caches involved. Just bailout. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1174 | return false; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1175 | } else { |
| 1176 | std::pair<bool, bool> pair = compiler_driver_->IsFastStaticField( |
| 1177 | outer_dex_cache.Get(), |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1178 | GetCompilingClass(), |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1179 | resolved_field, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1180 | field_index, |
| 1181 | &storage_index); |
| 1182 | bool can_easily_access = is_put ? pair.second : pair.first; |
| 1183 | if (!can_easily_access) { |
| 1184 | return false; |
| 1185 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | // TODO: find out why this check is needed. |
| 1189 | bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache( |
Nicolas Geoffray | 6a816cf | 2015-03-24 16:17:56 +0000 | [diff] [blame] | 1190 | *outer_compilation_unit_->GetDexFile(), storage_index); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1191 | bool is_initialized = resolved_field->GetDeclaringClass()->IsInitialized() && is_in_dex_cache; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1192 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1193 | HLoadClass* constant = new (arena_) HLoadClass(graph_->GetCurrentMethod(), |
| 1194 | storage_index, |
| 1195 | *dex_compilation_unit_->GetDexFile(), |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1196 | is_outer_class, |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1197 | dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1198 | current_block_->AddInstruction(constant); |
| 1199 | |
| 1200 | HInstruction* cls = constant; |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1201 | if (!is_initialized && !is_outer_class) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1202 | cls = new (arena_) HClinitCheck(constant, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1203 | current_block_->AddInstruction(cls); |
| 1204 | } |
| 1205 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1206 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1207 | if (is_put) { |
| 1208 | // We need to keep the class alive before loading the value. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1209 | Temporaries temps(graph_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1210 | temps.Add(cls); |
| 1211 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 1212 | DCHECK_EQ(value->GetType(), field_type); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1213 | current_block_->AddInstruction(new (arena_) HStaticFieldSet(cls, |
| 1214 | value, |
| 1215 | field_type, |
| 1216 | resolved_field->GetOffset(), |
| 1217 | resolved_field->IsVolatile(), |
| 1218 | field_index, |
| 1219 | *dex_file_)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1220 | } else { |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1221 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, |
| 1222 | field_type, |
| 1223 | resolved_field->GetOffset(), |
| 1224 | resolved_field->IsVolatile(), |
| 1225 | field_index, |
| 1226 | *dex_file_)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1227 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1228 | } |
| 1229 | return true; |
| 1230 | } |
| 1231 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1232 | void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
| 1233 | uint16_t first_vreg, |
| 1234 | int64_t second_vreg_or_constant, |
| 1235 | uint32_t dex_pc, |
| 1236 | Primitive::Type type, |
| 1237 | bool second_is_constant, |
| 1238 | bool isDiv) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1239 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1240 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1241 | HInstruction* first = LoadLocal(first_vreg, type); |
| 1242 | HInstruction* second = nullptr; |
| 1243 | if (second_is_constant) { |
| 1244 | if (type == Primitive::kPrimInt) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1245 | second = graph_->GetIntConstant(second_vreg_or_constant); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1246 | } else { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1247 | second = graph_->GetLongConstant(second_vreg_or_constant); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1248 | } |
| 1249 | } else { |
| 1250 | second = LoadLocal(second_vreg_or_constant, type); |
| 1251 | } |
| 1252 | |
| 1253 | if (!second_is_constant |
| 1254 | || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0) |
| 1255 | || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) { |
| 1256 | second = new (arena_) HDivZeroCheck(second, dex_pc); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1257 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1258 | current_block_->AddInstruction(second); |
| 1259 | temps.Add(current_block_->GetLastInstruction()); |
| 1260 | } |
| 1261 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1262 | if (isDiv) { |
| 1263 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc)); |
| 1264 | } else { |
| 1265 | current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc)); |
| 1266 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1267 | UpdateLocal(out_vreg, current_block_->GetLastInstruction()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1270 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1271 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1272 | bool is_put, |
| 1273 | Primitive::Type anticipated_type) { |
| 1274 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 1275 | uint8_t array_reg = instruction.VRegB_23x(); |
| 1276 | uint8_t index_reg = instruction.VRegC_23x(); |
| 1277 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1278 | // 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] | 1279 | Temporaries temps(graph_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1280 | |
| 1281 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1282 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1283 | current_block_->AddInstruction(object); |
| 1284 | temps.Add(object); |
| 1285 | |
| 1286 | HInstruction* length = new (arena_) HArrayLength(object); |
| 1287 | current_block_->AddInstruction(length); |
| 1288 | temps.Add(length); |
| 1289 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1290 | index = new (arena_) HBoundsCheck(index, length, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1291 | current_block_->AddInstruction(index); |
| 1292 | temps.Add(index); |
| 1293 | if (is_put) { |
| 1294 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 1295 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1296 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1297 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1298 | } else { |
| 1299 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type)); |
| 1300 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1301 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1302 | graph_->SetHasBoundsChecks(true); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1305 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1306 | uint32_t type_index, |
| 1307 | uint32_t number_of_vreg_arguments, |
| 1308 | bool is_range, |
| 1309 | uint32_t* args, |
| 1310 | uint32_t register_index) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1311 | HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1312 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 1313 | ? kQuickAllocArrayWithAccessCheck |
| 1314 | : kQuickAllocArray; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1315 | HInstruction* object = new (arena_) HNewArray(length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 1316 | graph_->GetCurrentMethod(), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1317 | dex_pc, |
| 1318 | type_index, |
| 1319 | *dex_compilation_unit_->GetDexFile(), |
| 1320 | entrypoint); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1321 | current_block_->AddInstruction(object); |
| 1322 | |
| 1323 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 1324 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 1325 | char primitive = descriptor[1]; |
| 1326 | DCHECK(primitive == 'I' |
| 1327 | || primitive == 'L' |
| 1328 | || primitive == '[') << descriptor; |
| 1329 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 1330 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 1331 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1332 | Temporaries temps(graph_); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1333 | temps.Add(object); |
| 1334 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 1335 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1336 | HInstruction* index = graph_->GetIntConstant(i); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1337 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1338 | new (arena_) HArraySet(object, index, value, type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1339 | } |
| 1340 | latest_result_ = object; |
| 1341 | } |
| 1342 | |
| 1343 | template <typename T> |
| 1344 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 1345 | const T* data, |
| 1346 | uint32_t element_count, |
| 1347 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1348 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1349 | for (uint32_t i = 0; i < element_count; ++i) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1350 | HInstruction* index = graph_->GetIntConstant(i); |
| 1351 | HInstruction* value = graph_->GetIntConstant(data[i]); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1352 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1353 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1357 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1358 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1359 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1360 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1361 | current_block_->AddInstruction(null_check); |
| 1362 | temps.Add(null_check); |
| 1363 | |
| 1364 | HInstruction* length = new (arena_) HArrayLength(null_check); |
| 1365 | current_block_->AddInstruction(length); |
| 1366 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1367 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1368 | const Instruction::ArrayDataPayload* payload = |
| 1369 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 1370 | const uint8_t* data = payload->data; |
| 1371 | uint32_t element_count = payload->element_count; |
| 1372 | |
| 1373 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 1374 | // done before doing any stores. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1375 | HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1376 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1377 | |
| 1378 | switch (payload->element_width) { |
| 1379 | case 1: |
| 1380 | BuildFillArrayData(null_check, |
| 1381 | reinterpret_cast<const int8_t*>(data), |
| 1382 | element_count, |
| 1383 | Primitive::kPrimByte, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1384 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1385 | break; |
| 1386 | case 2: |
| 1387 | BuildFillArrayData(null_check, |
| 1388 | reinterpret_cast<const int16_t*>(data), |
| 1389 | element_count, |
| 1390 | Primitive::kPrimShort, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1391 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1392 | break; |
| 1393 | case 4: |
| 1394 | BuildFillArrayData(null_check, |
| 1395 | reinterpret_cast<const int32_t*>(data), |
| 1396 | element_count, |
| 1397 | Primitive::kPrimInt, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1398 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1399 | break; |
| 1400 | case 8: |
| 1401 | BuildFillWideArrayData(null_check, |
| 1402 | reinterpret_cast<const int64_t*>(data), |
| 1403 | element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1404 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1405 | break; |
| 1406 | default: |
| 1407 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 1408 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1409 | graph_->SetHasBoundsChecks(true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1412 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1413 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1414 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1415 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1416 | for (uint32_t i = 0; i < element_count; ++i) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1417 | HInstruction* index = graph_->GetIntConstant(i); |
| 1418 | HInstruction* value = graph_->GetLongConstant(data[i]); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1419 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1420 | object, index, value, Primitive::kPrimLong, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1424 | bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
| 1425 | uint8_t destination, |
| 1426 | uint8_t reference, |
| 1427 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1428 | uint32_t dex_pc) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1429 | bool type_known_final; |
| 1430 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1431 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 1432 | // built is trying to access its own class, so that the generated |
| 1433 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1434 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1435 | bool dont_use_is_referrers_class; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1436 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1437 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1438 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1439 | if (!can_access) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1440 | MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1441 | return false; |
| 1442 | } |
| 1443 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1444 | HLoadClass* cls = new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1445 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 1446 | type_index, |
| 1447 | *dex_compilation_unit_->GetDexFile(), |
| 1448 | IsOutermostCompilingClass(type_index), |
| 1449 | dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1450 | current_block_->AddInstruction(cls); |
| 1451 | // The class needs a temporary before being used by the type check. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1452 | Temporaries temps(graph_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1453 | temps.Add(cls); |
| 1454 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
| 1455 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1456 | new (arena_) HInstanceOf(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1457 | UpdateLocal(destination, current_block_->GetLastInstruction()); |
| 1458 | } else { |
| 1459 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
| 1460 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1461 | new (arena_) HCheckCast(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1462 | } |
| 1463 | return true; |
| 1464 | } |
| 1465 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1466 | bool HGraphBuilder::NeedsAccessCheck(uint32_t type_index) const { |
| 1467 | return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks( |
| 1468 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index); |
| 1469 | } |
| 1470 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1471 | void HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1472 | // Verifier guarantees that the payload for PackedSwitch contains: |
| 1473 | // (a) number of entries (may be zero) |
| 1474 | // (b) first and lowest switch case value (entry 0, always present) |
| 1475 | // (c) list of target pcs (entries 1 <= i <= N) |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1476 | SwitchTable table(instruction, dex_pc, false); |
| 1477 | |
| 1478 | // Value to test against. |
| 1479 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 1480 | |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1481 | // Retrieve number of entries. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1482 | uint16_t num_entries = table.GetNumEntries(); |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1483 | if (num_entries == 0) { |
| 1484 | return; |
| 1485 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1486 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1487 | // Chained cmp-and-branch, starting from starting_key. |
| 1488 | int32_t starting_key = table.GetEntryAt(0); |
| 1489 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1490 | for (size_t i = 1; i <= num_entries; i++) { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1491 | BuildSwitchCaseHelper(instruction, i, i == num_entries, table, value, starting_key + i - 1, |
| 1492 | table.GetEntryAt(i), dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1493 | } |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1494 | } |
| 1495 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1496 | void HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1497 | // Verifier guarantees that the payload for SparseSwitch contains: |
| 1498 | // (a) number of entries (may be zero) |
| 1499 | // (b) sorted key values (entries 0 <= i < N) |
| 1500 | // (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] | 1501 | SwitchTable table(instruction, dex_pc, true); |
| 1502 | |
| 1503 | // Value to test against. |
| 1504 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 1505 | |
| 1506 | uint16_t num_entries = table.GetNumEntries(); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1507 | |
| 1508 | for (size_t i = 0; i < num_entries; i++) { |
| 1509 | BuildSwitchCaseHelper(instruction, i, i == static_cast<size_t>(num_entries) - 1, table, value, |
| 1510 | table.GetEntryAt(i), table.GetEntryAt(i + num_entries), dex_pc); |
| 1511 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | void HGraphBuilder::BuildSwitchCaseHelper(const Instruction& instruction, size_t index, |
| 1515 | bool is_last_case, const SwitchTable& table, |
| 1516 | HInstruction* value, int32_t case_value_int, |
| 1517 | int32_t target_offset, uint32_t dex_pc) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1518 | HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset); |
| 1519 | DCHECK(case_target != nullptr); |
| 1520 | PotentiallyAddSuspendCheck(case_target, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1521 | |
| 1522 | // The current case's value. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1523 | HInstruction* this_case_value = graph_->GetIntConstant(case_value_int); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1524 | |
| 1525 | // Compare value and this_case_value. |
| 1526 | HEqual* comparison = new (arena_) HEqual(value, this_case_value); |
| 1527 | current_block_->AddInstruction(comparison); |
| 1528 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 1529 | current_block_->AddInstruction(ifinst); |
| 1530 | |
| 1531 | // Case hit: use the target offset to determine where to go. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1532 | current_block_->AddSuccessor(case_target); |
| 1533 | |
| 1534 | // Case miss: go to the next case (or default fall-through). |
| 1535 | // When there is a next case, we use the block stored with the table offset representing this |
| 1536 | // case (that is where we registered them in ComputeBranchTargets). |
| 1537 | // When there is no next case, we use the following instruction. |
| 1538 | // TODO: Find a good way to peel the last iteration to avoid conditional, but still have re-use. |
| 1539 | if (!is_last_case) { |
| 1540 | HBasicBlock* next_case_target = FindBlockStartingAt(table.GetDexPcForIndex(index)); |
| 1541 | DCHECK(next_case_target != nullptr); |
| 1542 | current_block_->AddSuccessor(next_case_target); |
| 1543 | |
| 1544 | // Need to manually add the block, as there is no dex-pc transition for the cases. |
| 1545 | graph_->AddBlock(next_case_target); |
| 1546 | |
| 1547 | current_block_ = next_case_target; |
| 1548 | } else { |
| 1549 | HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 1550 | DCHECK(default_target != nullptr); |
| 1551 | current_block_->AddSuccessor(default_target); |
| 1552 | current_block_ = nullptr; |
| 1553 | } |
| 1554 | } |
| 1555 | |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1556 | void HGraphBuilder::PotentiallyAddSuspendCheck(HBasicBlock* target, uint32_t dex_pc) { |
| 1557 | int32_t target_offset = target->GetDexPc() - dex_pc; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1558 | if (target_offset <= 0) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1559 | // DX generates back edges to the first encountered return. We can save |
| 1560 | // time of later passes by not adding redundant suspend checks. |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame] | 1561 | HInstruction* last_in_target = target->GetLastInstruction(); |
| 1562 | if (last_in_target != nullptr && |
| 1563 | (last_in_target->IsReturn() || last_in_target->IsReturnVoid())) { |
| 1564 | return; |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | // Add a suspend check to backward branches which may potentially loop. We |
| 1568 | // can remove them after we recognize loops in the graph. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1569 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc)); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1573 | bool HGraphBuilder::CanDecodeQuickenedInfo() const { |
| 1574 | return interpreter_metadata_ != nullptr; |
| 1575 | } |
| 1576 | |
| 1577 | uint16_t HGraphBuilder::LookupQuickenedInfo(uint32_t dex_pc) { |
| 1578 | DCHECK(interpreter_metadata_ != nullptr); |
| 1579 | uint32_t dex_pc_in_map = DecodeUnsignedLeb128(&interpreter_metadata_); |
| 1580 | DCHECK_EQ(dex_pc, dex_pc_in_map); |
| 1581 | return DecodeUnsignedLeb128(&interpreter_metadata_); |
| 1582 | } |
| 1583 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1584 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1585 | if (current_block_ == nullptr) { |
| 1586 | return true; // Dead code |
| 1587 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1588 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1589 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1590 | case Instruction::CONST_4: { |
| 1591 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1592 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1593 | UpdateLocal(register_index, constant); |
| 1594 | break; |
| 1595 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1596 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1597 | case Instruction::CONST_16: { |
| 1598 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1599 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1600 | UpdateLocal(register_index, constant); |
| 1601 | break; |
| 1602 | } |
| 1603 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1604 | case Instruction::CONST: { |
| 1605 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1606 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i()); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1607 | UpdateLocal(register_index, constant); |
| 1608 | break; |
| 1609 | } |
| 1610 | |
| 1611 | case Instruction::CONST_HIGH16: { |
| 1612 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1613 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1614 | UpdateLocal(register_index, constant); |
| 1615 | break; |
| 1616 | } |
| 1617 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1618 | case Instruction::CONST_WIDE_16: { |
| 1619 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1620 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 1621 | int64_t value = instruction.VRegB_21s(); |
| 1622 | value <<= 48; |
| 1623 | value >>= 48; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1624 | HLongConstant* constant = graph_->GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1625 | UpdateLocal(register_index, constant); |
| 1626 | break; |
| 1627 | } |
| 1628 | |
| 1629 | case Instruction::CONST_WIDE_32: { |
| 1630 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1631 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 1632 | int64_t value = instruction.VRegB_31i(); |
| 1633 | value <<= 32; |
| 1634 | value >>= 32; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1635 | HLongConstant* constant = graph_->GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1636 | UpdateLocal(register_index, constant); |
| 1637 | break; |
| 1638 | } |
| 1639 | |
| 1640 | case Instruction::CONST_WIDE: { |
| 1641 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1642 | HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1643 | UpdateLocal(register_index, constant); |
| 1644 | break; |
| 1645 | } |
| 1646 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1647 | case Instruction::CONST_WIDE_HIGH16: { |
| 1648 | int32_t register_index = instruction.VRegA(); |
| 1649 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1650 | HLongConstant* constant = graph_->GetLongConstant(value); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1651 | UpdateLocal(register_index, constant); |
| 1652 | break; |
| 1653 | } |
| 1654 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1655 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1656 | case Instruction::MOVE: |
| 1657 | case Instruction::MOVE_FROM16: |
| 1658 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1659 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1660 | UpdateLocal(instruction.VRegA(), value); |
| 1661 | break; |
| 1662 | } |
| 1663 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1664 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1665 | case Instruction::MOVE_WIDE: |
| 1666 | case Instruction::MOVE_WIDE_FROM16: |
| 1667 | case Instruction::MOVE_WIDE_16: { |
| 1668 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 1669 | UpdateLocal(instruction.VRegA(), value); |
| 1670 | break; |
| 1671 | } |
| 1672 | |
| 1673 | case Instruction::MOVE_OBJECT: |
| 1674 | case Instruction::MOVE_OBJECT_16: |
| 1675 | case Instruction::MOVE_OBJECT_FROM16: { |
| 1676 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 1677 | UpdateLocal(instruction.VRegA(), value); |
| 1678 | break; |
| 1679 | } |
| 1680 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1681 | case Instruction::RETURN_VOID_NO_BARRIER: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1682 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1683 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1684 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1687 | #define IF_XX(comparison, cond) \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1688 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 1689 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1690 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1691 | IF_XX(HEqual, EQ); |
| 1692 | IF_XX(HNotEqual, NE); |
| 1693 | IF_XX(HLessThan, LT); |
| 1694 | IF_XX(HLessThanOrEqual, LE); |
| 1695 | IF_XX(HGreaterThan, GT); |
| 1696 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1697 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1698 | case Instruction::GOTO: |
| 1699 | case Instruction::GOTO_16: |
| 1700 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1701 | int32_t offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1702 | HBasicBlock* target = FindBlockStartingAt(offset + dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1703 | DCHECK(target != nullptr); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1704 | PotentiallyAddSuspendCheck(target, dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1705 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 1706 | current_block_->AddSuccessor(target); |
| 1707 | current_block_ = nullptr; |
| 1708 | break; |
| 1709 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1710 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1711 | case Instruction::RETURN: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1712 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1713 | break; |
| 1714 | } |
| 1715 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1716 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1717 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1718 | break; |
| 1719 | } |
| 1720 | |
| 1721 | case Instruction::RETURN_WIDE: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1722 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1723 | break; |
| 1724 | } |
| 1725 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1726 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1727 | case Instruction::INVOKE_INTERFACE: |
| 1728 | case Instruction::INVOKE_STATIC: |
| 1729 | case Instruction::INVOKE_SUPER: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1730 | case Instruction::INVOKE_VIRTUAL: |
| 1731 | case Instruction::INVOKE_VIRTUAL_QUICK: { |
| 1732 | uint16_t method_idx; |
| 1733 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_QUICK) { |
| 1734 | if (!CanDecodeQuickenedInfo()) { |
| 1735 | return false; |
| 1736 | } |
| 1737 | method_idx = LookupQuickenedInfo(dex_pc); |
| 1738 | } else { |
| 1739 | method_idx = instruction.VRegB_35c(); |
| 1740 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1741 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1742 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1743 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1744 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1745 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1746 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1747 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1748 | break; |
| 1749 | } |
| 1750 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1751 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1752 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 1753 | case Instruction::INVOKE_STATIC_RANGE: |
| 1754 | case Instruction::INVOKE_SUPER_RANGE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1755 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 1756 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 1757 | uint16_t method_idx; |
| 1758 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK) { |
| 1759 | if (!CanDecodeQuickenedInfo()) { |
| 1760 | return false; |
| 1761 | } |
| 1762 | method_idx = LookupQuickenedInfo(dex_pc); |
| 1763 | } else { |
| 1764 | method_idx = instruction.VRegB_3rc(); |
| 1765 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1766 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1767 | uint32_t register_index = instruction.VRegC(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1768 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1769 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1770 | return false; |
| 1771 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1772 | break; |
| 1773 | } |
| 1774 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1775 | case Instruction::NEG_INT: { |
| 1776 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt); |
| 1777 | break; |
| 1778 | } |
| 1779 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1780 | case Instruction::NEG_LONG: { |
| 1781 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong); |
| 1782 | break; |
| 1783 | } |
| 1784 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1785 | case Instruction::NEG_FLOAT: { |
| 1786 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat); |
| 1787 | break; |
| 1788 | } |
| 1789 | |
| 1790 | case Instruction::NEG_DOUBLE: { |
| 1791 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble); |
| 1792 | break; |
| 1793 | } |
| 1794 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1795 | case Instruction::NOT_INT: { |
| 1796 | Unop_12x<HNot>(instruction, Primitive::kPrimInt); |
| 1797 | break; |
| 1798 | } |
| 1799 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1800 | case Instruction::NOT_LONG: { |
| 1801 | Unop_12x<HNot>(instruction, Primitive::kPrimLong); |
| 1802 | break; |
| 1803 | } |
| 1804 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1805 | case Instruction::INT_TO_LONG: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1806 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | } |
| 1809 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1810 | case Instruction::INT_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1811 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | } |
| 1814 | |
| 1815 | case Instruction::INT_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1816 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1817 | break; |
| 1818 | } |
| 1819 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1820 | case Instruction::LONG_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1821 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1822 | break; |
| 1823 | } |
| 1824 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1825 | case Instruction::LONG_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1826 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1827 | break; |
| 1828 | } |
| 1829 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1830 | case Instruction::LONG_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1831 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1832 | break; |
| 1833 | } |
| 1834 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1835 | case Instruction::FLOAT_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1836 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc); |
| 1837 | break; |
| 1838 | } |
| 1839 | |
| 1840 | case Instruction::FLOAT_TO_LONG: { |
| 1841 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1842 | break; |
| 1843 | } |
| 1844 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1845 | case Instruction::FLOAT_TO_DOUBLE: { |
| 1846 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc); |
| 1847 | break; |
| 1848 | } |
| 1849 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1850 | case Instruction::DOUBLE_TO_INT: { |
| 1851 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc); |
| 1852 | break; |
| 1853 | } |
| 1854 | |
| 1855 | case Instruction::DOUBLE_TO_LONG: { |
| 1856 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc); |
| 1857 | break; |
| 1858 | } |
| 1859 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1860 | case Instruction::DOUBLE_TO_FLOAT: { |
| 1861 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc); |
| 1862 | break; |
| 1863 | } |
| 1864 | |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1865 | case Instruction::INT_TO_BYTE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1866 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1867 | break; |
| 1868 | } |
| 1869 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1870 | case Instruction::INT_TO_SHORT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1871 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1872 | break; |
| 1873 | } |
| 1874 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1875 | case Instruction::INT_TO_CHAR: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1876 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1877 | break; |
| 1878 | } |
| 1879 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1880 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1881 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1882 | break; |
| 1883 | } |
| 1884 | |
| 1885 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1886 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1887 | break; |
| 1888 | } |
| 1889 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1890 | case Instruction::ADD_DOUBLE: { |
| 1891 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1892 | break; |
| 1893 | } |
| 1894 | |
| 1895 | case Instruction::ADD_FLOAT: { |
| 1896 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1897 | break; |
| 1898 | } |
| 1899 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1900 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1901 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1902 | break; |
| 1903 | } |
| 1904 | |
| 1905 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1906 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1907 | break; |
| 1908 | } |
| 1909 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1910 | case Instruction::SUB_FLOAT: { |
| 1911 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat); |
| 1912 | break; |
| 1913 | } |
| 1914 | |
| 1915 | case Instruction::SUB_DOUBLE: { |
| 1916 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble); |
| 1917 | break; |
| 1918 | } |
| 1919 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1920 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1921 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 1922 | break; |
| 1923 | } |
| 1924 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1925 | case Instruction::MUL_INT: { |
| 1926 | Binop_23x<HMul>(instruction, Primitive::kPrimInt); |
| 1927 | break; |
| 1928 | } |
| 1929 | |
| 1930 | case Instruction::MUL_LONG: { |
| 1931 | Binop_23x<HMul>(instruction, Primitive::kPrimLong); |
| 1932 | break; |
| 1933 | } |
| 1934 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1935 | case Instruction::MUL_FLOAT: { |
| 1936 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat); |
| 1937 | break; |
| 1938 | } |
| 1939 | |
| 1940 | case Instruction::MUL_DOUBLE: { |
| 1941 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble); |
| 1942 | break; |
| 1943 | } |
| 1944 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1945 | case Instruction::DIV_INT: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1946 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1947 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1948 | break; |
| 1949 | } |
| 1950 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1951 | case Instruction::DIV_LONG: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1952 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1953 | dex_pc, Primitive::kPrimLong, false, true); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1954 | break; |
| 1955 | } |
| 1956 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1957 | case Instruction::DIV_FLOAT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1958 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1959 | break; |
| 1960 | } |
| 1961 | |
| 1962 | case Instruction::DIV_DOUBLE: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1963 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1964 | break; |
| 1965 | } |
| 1966 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1967 | case Instruction::REM_INT: { |
| 1968 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1969 | dex_pc, Primitive::kPrimInt, false, false); |
| 1970 | break; |
| 1971 | } |
| 1972 | |
| 1973 | case Instruction::REM_LONG: { |
| 1974 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1975 | dex_pc, Primitive::kPrimLong, false, false); |
| 1976 | break; |
| 1977 | } |
| 1978 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 1979 | case Instruction::REM_FLOAT: { |
| 1980 | Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 1981 | break; |
| 1982 | } |
| 1983 | |
| 1984 | case Instruction::REM_DOUBLE: { |
| 1985 | Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 1986 | break; |
| 1987 | } |
| 1988 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1989 | case Instruction::AND_INT: { |
| 1990 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt); |
| 1991 | break; |
| 1992 | } |
| 1993 | |
| 1994 | case Instruction::AND_LONG: { |
| 1995 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong); |
| 1996 | break; |
| 1997 | } |
| 1998 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1999 | case Instruction::SHL_INT: { |
| 2000 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 2001 | break; |
| 2002 | } |
| 2003 | |
| 2004 | case Instruction::SHL_LONG: { |
| 2005 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 2006 | break; |
| 2007 | } |
| 2008 | |
| 2009 | case Instruction::SHR_INT: { |
| 2010 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 2011 | break; |
| 2012 | } |
| 2013 | |
| 2014 | case Instruction::SHR_LONG: { |
| 2015 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 2016 | break; |
| 2017 | } |
| 2018 | |
| 2019 | case Instruction::USHR_INT: { |
| 2020 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 2021 | break; |
| 2022 | } |
| 2023 | |
| 2024 | case Instruction::USHR_LONG: { |
| 2025 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 2026 | break; |
| 2027 | } |
| 2028 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2029 | case Instruction::OR_INT: { |
| 2030 | Binop_23x<HOr>(instruction, Primitive::kPrimInt); |
| 2031 | break; |
| 2032 | } |
| 2033 | |
| 2034 | case Instruction::OR_LONG: { |
| 2035 | Binop_23x<HOr>(instruction, Primitive::kPrimLong); |
| 2036 | break; |
| 2037 | } |
| 2038 | |
| 2039 | case Instruction::XOR_INT: { |
| 2040 | Binop_23x<HXor>(instruction, Primitive::kPrimInt); |
| 2041 | break; |
| 2042 | } |
| 2043 | |
| 2044 | case Instruction::XOR_LONG: { |
| 2045 | Binop_23x<HXor>(instruction, Primitive::kPrimLong); |
| 2046 | break; |
| 2047 | } |
| 2048 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2049 | case Instruction::ADD_LONG_2ADDR: { |
| 2050 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2051 | break; |
| 2052 | } |
| 2053 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2054 | case Instruction::ADD_DOUBLE_2ADDR: { |
| 2055 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble); |
| 2056 | break; |
| 2057 | } |
| 2058 | |
| 2059 | case Instruction::ADD_FLOAT_2ADDR: { |
| 2060 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat); |
| 2061 | break; |
| 2062 | } |
| 2063 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2064 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2065 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 2066 | break; |
| 2067 | } |
| 2068 | |
| 2069 | case Instruction::SUB_LONG_2ADDR: { |
| 2070 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2071 | break; |
| 2072 | } |
| 2073 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2074 | case Instruction::SUB_FLOAT_2ADDR: { |
| 2075 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat); |
| 2076 | break; |
| 2077 | } |
| 2078 | |
| 2079 | case Instruction::SUB_DOUBLE_2ADDR: { |
| 2080 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble); |
| 2081 | break; |
| 2082 | } |
| 2083 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2084 | case Instruction::MUL_INT_2ADDR: { |
| 2085 | Binop_12x<HMul>(instruction, Primitive::kPrimInt); |
| 2086 | break; |
| 2087 | } |
| 2088 | |
| 2089 | case Instruction::MUL_LONG_2ADDR: { |
| 2090 | Binop_12x<HMul>(instruction, Primitive::kPrimLong); |
| 2091 | break; |
| 2092 | } |
| 2093 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2094 | case Instruction::MUL_FLOAT_2ADDR: { |
| 2095 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat); |
| 2096 | break; |
| 2097 | } |
| 2098 | |
| 2099 | case Instruction::MUL_DOUBLE_2ADDR: { |
| 2100 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble); |
| 2101 | break; |
| 2102 | } |
| 2103 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2104 | case Instruction::DIV_INT_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2105 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2106 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2107 | break; |
| 2108 | } |
| 2109 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2110 | case Instruction::DIV_LONG_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2111 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2112 | dex_pc, Primitive::kPrimLong, false, true); |
| 2113 | break; |
| 2114 | } |
| 2115 | |
| 2116 | case Instruction::REM_INT_2ADDR: { |
| 2117 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2118 | dex_pc, Primitive::kPrimInt, false, false); |
| 2119 | break; |
| 2120 | } |
| 2121 | |
| 2122 | case Instruction::REM_LONG_2ADDR: { |
| 2123 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2124 | dex_pc, Primitive::kPrimLong, false, false); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2125 | break; |
| 2126 | } |
| 2127 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2128 | case Instruction::REM_FLOAT_2ADDR: { |
| 2129 | Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 2130 | break; |
| 2131 | } |
| 2132 | |
| 2133 | case Instruction::REM_DOUBLE_2ADDR: { |
| 2134 | Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 2135 | break; |
| 2136 | } |
| 2137 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2138 | case Instruction::SHL_INT_2ADDR: { |
| 2139 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 2140 | break; |
| 2141 | } |
| 2142 | |
| 2143 | case Instruction::SHL_LONG_2ADDR: { |
| 2144 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 2145 | break; |
| 2146 | } |
| 2147 | |
| 2148 | case Instruction::SHR_INT_2ADDR: { |
| 2149 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 2150 | break; |
| 2151 | } |
| 2152 | |
| 2153 | case Instruction::SHR_LONG_2ADDR: { |
| 2154 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 2155 | break; |
| 2156 | } |
| 2157 | |
| 2158 | case Instruction::USHR_INT_2ADDR: { |
| 2159 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 2160 | break; |
| 2161 | } |
| 2162 | |
| 2163 | case Instruction::USHR_LONG_2ADDR: { |
| 2164 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 2165 | break; |
| 2166 | } |
| 2167 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2168 | case Instruction::DIV_FLOAT_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2169 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2170 | break; |
| 2171 | } |
| 2172 | |
| 2173 | case Instruction::DIV_DOUBLE_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2174 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2175 | break; |
| 2176 | } |
| 2177 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2178 | case Instruction::AND_INT_2ADDR: { |
| 2179 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt); |
| 2180 | break; |
| 2181 | } |
| 2182 | |
| 2183 | case Instruction::AND_LONG_2ADDR: { |
| 2184 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong); |
| 2185 | break; |
| 2186 | } |
| 2187 | |
| 2188 | case Instruction::OR_INT_2ADDR: { |
| 2189 | Binop_12x<HOr>(instruction, Primitive::kPrimInt); |
| 2190 | break; |
| 2191 | } |
| 2192 | |
| 2193 | case Instruction::OR_LONG_2ADDR: { |
| 2194 | Binop_12x<HOr>(instruction, Primitive::kPrimLong); |
| 2195 | break; |
| 2196 | } |
| 2197 | |
| 2198 | case Instruction::XOR_INT_2ADDR: { |
| 2199 | Binop_12x<HXor>(instruction, Primitive::kPrimInt); |
| 2200 | break; |
| 2201 | } |
| 2202 | |
| 2203 | case Instruction::XOR_LONG_2ADDR: { |
| 2204 | Binop_12x<HXor>(instruction, Primitive::kPrimLong); |
| 2205 | break; |
| 2206 | } |
| 2207 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2208 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2209 | Binop_22s<HAdd>(instruction, false); |
| 2210 | break; |
| 2211 | } |
| 2212 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2213 | case Instruction::AND_INT_LIT16: { |
| 2214 | Binop_22s<HAnd>(instruction, false); |
| 2215 | break; |
| 2216 | } |
| 2217 | |
| 2218 | case Instruction::OR_INT_LIT16: { |
| 2219 | Binop_22s<HOr>(instruction, false); |
| 2220 | break; |
| 2221 | } |
| 2222 | |
| 2223 | case Instruction::XOR_INT_LIT16: { |
| 2224 | Binop_22s<HXor>(instruction, false); |
| 2225 | break; |
| 2226 | } |
| 2227 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2228 | case Instruction::RSUB_INT: { |
| 2229 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | } |
| 2232 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2233 | case Instruction::MUL_INT_LIT16: { |
| 2234 | Binop_22s<HMul>(instruction, false); |
| 2235 | break; |
| 2236 | } |
| 2237 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2238 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2239 | Binop_22b<HAdd>(instruction, false); |
| 2240 | break; |
| 2241 | } |
| 2242 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2243 | case Instruction::AND_INT_LIT8: { |
| 2244 | Binop_22b<HAnd>(instruction, false); |
| 2245 | break; |
| 2246 | } |
| 2247 | |
| 2248 | case Instruction::OR_INT_LIT8: { |
| 2249 | Binop_22b<HOr>(instruction, false); |
| 2250 | break; |
| 2251 | } |
| 2252 | |
| 2253 | case Instruction::XOR_INT_LIT8: { |
| 2254 | Binop_22b<HXor>(instruction, false); |
| 2255 | break; |
| 2256 | } |
| 2257 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2258 | case Instruction::RSUB_INT_LIT8: { |
| 2259 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2260 | break; |
| 2261 | } |
| 2262 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2263 | case Instruction::MUL_INT_LIT8: { |
| 2264 | Binop_22b<HMul>(instruction, false); |
| 2265 | break; |
| 2266 | } |
| 2267 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2268 | case Instruction::DIV_INT_LIT16: |
| 2269 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2270 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2271 | dex_pc, Primitive::kPrimInt, true, true); |
| 2272 | break; |
| 2273 | } |
| 2274 | |
| 2275 | case Instruction::REM_INT_LIT16: |
| 2276 | case Instruction::REM_INT_LIT8: { |
| 2277 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2278 | dex_pc, Primitive::kPrimInt, true, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2279 | break; |
| 2280 | } |
| 2281 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2282 | case Instruction::SHL_INT_LIT8: { |
| 2283 | Binop_22b<HShl>(instruction, false); |
| 2284 | break; |
| 2285 | } |
| 2286 | |
| 2287 | case Instruction::SHR_INT_LIT8: { |
| 2288 | Binop_22b<HShr>(instruction, false); |
| 2289 | break; |
| 2290 | } |
| 2291 | |
| 2292 | case Instruction::USHR_INT_LIT8: { |
| 2293 | Binop_22b<HUShr>(instruction, false); |
| 2294 | break; |
| 2295 | } |
| 2296 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2297 | case Instruction::NEW_INSTANCE: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2298 | uint16_t type_index = instruction.VRegB_21c(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2299 | if (compiler_driver_->IsStringTypeIndex(type_index, dex_file_)) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2300 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 2301 | HFakeString* fake_string = new (arena_) HFakeString(); |
| 2302 | current_block_->AddInstruction(fake_string); |
| 2303 | UpdateLocal(register_index, fake_string); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2304 | } else { |
| 2305 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 2306 | ? kQuickAllocObjectWithAccessCheck |
| 2307 | : kQuickAllocObject; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2308 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2309 | current_block_->AddInstruction(new (arena_) HNewInstance( |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2310 | graph_->GetCurrentMethod(), |
| 2311 | dex_pc, |
| 2312 | type_index, |
| 2313 | *dex_compilation_unit_->GetDexFile(), |
| 2314 | entrypoint)); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2315 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 2316 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2317 | break; |
| 2318 | } |
| 2319 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2320 | case Instruction::NEW_ARRAY: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2321 | uint16_t type_index = instruction.VRegC_22c(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2322 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2323 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 2324 | ? kQuickAllocArrayWithAccessCheck |
| 2325 | : kQuickAllocArray; |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2326 | current_block_->AddInstruction(new (arena_) HNewArray(length, |
| 2327 | graph_->GetCurrentMethod(), |
| 2328 | dex_pc, |
| 2329 | type_index, |
| 2330 | *dex_compilation_unit_->GetDexFile(), |
| 2331 | entrypoint)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2332 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 2333 | break; |
| 2334 | } |
| 2335 | |
| 2336 | case Instruction::FILLED_NEW_ARRAY: { |
| 2337 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 2338 | uint32_t type_index = instruction.VRegB_35c(); |
| 2339 | uint32_t args[5]; |
| 2340 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2341 | BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2342 | break; |
| 2343 | } |
| 2344 | |
| 2345 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 2346 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 2347 | uint32_t type_index = instruction.VRegB_3rc(); |
| 2348 | uint32_t register_index = instruction.VRegC_3rc(); |
| 2349 | BuildFilledNewArray( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2350 | dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2351 | break; |
| 2352 | } |
| 2353 | |
| 2354 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2355 | BuildFillArrayData(instruction, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2356 | break; |
| 2357 | } |
| 2358 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2359 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2360 | case Instruction::MOVE_RESULT_WIDE: |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2361 | case Instruction::MOVE_RESULT_OBJECT: { |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2362 | if (latest_result_ == nullptr) { |
| 2363 | // Only dead code can lead to this situation, where the verifier |
| 2364 | // does not reject the method. |
| 2365 | } else { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2366 | // An Invoke/FilledNewArray and its MoveResult could have landed in |
| 2367 | // different blocks if there was a try/catch block boundary between |
| 2368 | // them. For Invoke, we insert a StoreLocal after the instruction. For |
| 2369 | // FilledNewArray, the local needs to be updated after the array was |
| 2370 | // filled, otherwise we might overwrite an input vreg. |
| 2371 | HStoreLocal* update_local = |
| 2372 | new (arena_) HStoreLocal(GetLocalAt(instruction.VRegA()), latest_result_); |
| 2373 | HBasicBlock* block = latest_result_->GetBlock(); |
| 2374 | if (block == current_block_) { |
| 2375 | // MoveResult and the previous instruction are in the same block. |
| 2376 | current_block_->AddInstruction(update_local); |
| 2377 | } else { |
| 2378 | // The two instructions are in different blocks. Insert the MoveResult |
| 2379 | // before the final control-flow instruction of the previous block. |
| 2380 | DCHECK(block->EndsWithControlFlowInstruction()); |
| 2381 | DCHECK(current_block_->GetInstructions().IsEmpty()); |
| 2382 | block->InsertInstructionBefore(update_local, block->GetLastInstruction()); |
| 2383 | } |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2384 | latest_result_ = nullptr; |
| 2385 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2386 | break; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2387 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2388 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2389 | case Instruction::CMP_LONG: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2390 | Binop_23x_cmp(instruction, Primitive::kPrimLong, ComparisonBias::kNoBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | } |
| 2393 | |
| 2394 | case Instruction::CMPG_FLOAT: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2395 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2396 | break; |
| 2397 | } |
| 2398 | |
| 2399 | case Instruction::CMPG_DOUBLE: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2400 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | } |
| 2403 | |
| 2404 | case Instruction::CMPL_FLOAT: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2405 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kLtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2406 | break; |
| 2407 | } |
| 2408 | |
| 2409 | case Instruction::CMPL_DOUBLE: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2410 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kLtBias, dex_pc); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2411 | break; |
| 2412 | } |
| 2413 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2414 | case Instruction::NOP: |
| 2415 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2416 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2417 | case Instruction::IGET: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2418 | case Instruction::IGET_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2419 | case Instruction::IGET_WIDE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2420 | case Instruction::IGET_WIDE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2421 | case Instruction::IGET_OBJECT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2422 | case Instruction::IGET_OBJECT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2423 | case Instruction::IGET_BOOLEAN: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2424 | case Instruction::IGET_BOOLEAN_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2425 | case Instruction::IGET_BYTE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2426 | case Instruction::IGET_BYTE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2427 | case Instruction::IGET_CHAR: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2428 | case Instruction::IGET_CHAR_QUICK: |
| 2429 | case Instruction::IGET_SHORT: |
| 2430 | case Instruction::IGET_SHORT_QUICK: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2431 | if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2432 | return false; |
| 2433 | } |
| 2434 | break; |
| 2435 | } |
| 2436 | |
| 2437 | case Instruction::IPUT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2438 | case Instruction::IPUT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2439 | case Instruction::IPUT_WIDE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2440 | case Instruction::IPUT_WIDE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2441 | case Instruction::IPUT_OBJECT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2442 | case Instruction::IPUT_OBJECT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2443 | case Instruction::IPUT_BOOLEAN: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2444 | case Instruction::IPUT_BOOLEAN_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2445 | case Instruction::IPUT_BYTE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2446 | case Instruction::IPUT_BYTE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2447 | case Instruction::IPUT_CHAR: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2448 | case Instruction::IPUT_CHAR_QUICK: |
| 2449 | case Instruction::IPUT_SHORT: |
| 2450 | case Instruction::IPUT_SHORT_QUICK: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2451 | if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2452 | return false; |
| 2453 | } |
| 2454 | break; |
| 2455 | } |
| 2456 | |
| 2457 | case Instruction::SGET: |
| 2458 | case Instruction::SGET_WIDE: |
| 2459 | case Instruction::SGET_OBJECT: |
| 2460 | case Instruction::SGET_BOOLEAN: |
| 2461 | case Instruction::SGET_BYTE: |
| 2462 | case Instruction::SGET_CHAR: |
| 2463 | case Instruction::SGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2464 | if (!BuildStaticFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2465 | return false; |
| 2466 | } |
| 2467 | break; |
| 2468 | } |
| 2469 | |
| 2470 | case Instruction::SPUT: |
| 2471 | case Instruction::SPUT_WIDE: |
| 2472 | case Instruction::SPUT_OBJECT: |
| 2473 | case Instruction::SPUT_BOOLEAN: |
| 2474 | case Instruction::SPUT_BYTE: |
| 2475 | case Instruction::SPUT_CHAR: |
| 2476 | case Instruction::SPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2477 | if (!BuildStaticFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2478 | return false; |
| 2479 | } |
| 2480 | break; |
| 2481 | } |
| 2482 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2483 | #define ARRAY_XX(kind, anticipated_type) \ |
| 2484 | case Instruction::AGET##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2485 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2486 | break; \ |
| 2487 | } \ |
| 2488 | case Instruction::APUT##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2489 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2490 | break; \ |
| 2491 | } |
| 2492 | |
| 2493 | ARRAY_XX(, Primitive::kPrimInt); |
| 2494 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 2495 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 2496 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 2497 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 2498 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 2499 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 2500 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2501 | case Instruction::ARRAY_LENGTH: { |
| 2502 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2503 | // No need for a temporary for the null check, it is the only input of the following |
| 2504 | // instruction. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2505 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2506 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2507 | current_block_->AddInstruction(new (arena_) HArrayLength(object)); |
| 2508 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 2509 | break; |
| 2510 | } |
| 2511 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2512 | case Instruction::CONST_STRING: { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2513 | current_block_->AddInstruction( |
| 2514 | new (arena_) HLoadString(graph_->GetCurrentMethod(), instruction.VRegB_21c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2515 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 2516 | break; |
| 2517 | } |
| 2518 | |
| 2519 | case Instruction::CONST_STRING_JUMBO: { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2520 | current_block_->AddInstruction( |
| 2521 | new (arena_) HLoadString(graph_->GetCurrentMethod(), instruction.VRegB_31c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2522 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 2523 | break; |
| 2524 | } |
| 2525 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2526 | case Instruction::CONST_CLASS: { |
| 2527 | uint16_t type_index = instruction.VRegB_21c(); |
| 2528 | bool type_known_final; |
| 2529 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2530 | bool dont_use_is_referrers_class; |
| 2531 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 2532 | // built is trying to access its own class, so that the generated |
| 2533 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2534 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2535 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 2536 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2537 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2538 | if (!can_access) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2539 | MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2540 | return false; |
| 2541 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2542 | current_block_->AddInstruction(new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2543 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2544 | type_index, |
| 2545 | *dex_compilation_unit_->GetDexFile(), |
| 2546 | IsOutermostCompilingClass(type_index), |
| 2547 | dex_pc)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2548 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 2549 | break; |
| 2550 | } |
| 2551 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2552 | case Instruction::MOVE_EXCEPTION: { |
| 2553 | current_block_->AddInstruction(new (arena_) HLoadException()); |
| 2554 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
| 2555 | break; |
| 2556 | } |
| 2557 | |
| 2558 | case Instruction::THROW: { |
| 2559 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2560 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2561 | // A throw instruction must branch to the exit block. |
| 2562 | current_block_->AddSuccessor(exit_block_); |
| 2563 | // We finished building this block. Set the current block to null to avoid |
| 2564 | // adding dead instructions to it. |
| 2565 | current_block_ = nullptr; |
| 2566 | break; |
| 2567 | } |
| 2568 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2569 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2570 | uint8_t destination = instruction.VRegA_22c(); |
| 2571 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2572 | uint16_t type_index = instruction.VRegC_22c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2573 | if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2574 | return false; |
| 2575 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2576 | break; |
| 2577 | } |
| 2578 | |
| 2579 | case Instruction::CHECK_CAST: { |
| 2580 | uint8_t reference = instruction.VRegA_21c(); |
| 2581 | uint16_t type_index = instruction.VRegB_21c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2582 | if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2583 | return false; |
| 2584 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2585 | break; |
| 2586 | } |
| 2587 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2588 | case Instruction::MONITOR_ENTER: { |
| 2589 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 2590 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 2591 | HMonitorOperation::kEnter, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2592 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2593 | break; |
| 2594 | } |
| 2595 | |
| 2596 | case Instruction::MONITOR_EXIT: { |
| 2597 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 2598 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 2599 | HMonitorOperation::kExit, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2600 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2601 | break; |
| 2602 | } |
| 2603 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2604 | case Instruction::PACKED_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2605 | BuildPackedSwitch(instruction, dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2606 | break; |
| 2607 | } |
| 2608 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2609 | case Instruction::SPARSE_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2610 | BuildSparseSwitch(instruction, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2611 | break; |
| 2612 | } |
| 2613 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2614 | default: |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2615 | VLOG(compiler) << "Did not compile " |
| 2616 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 2617 | << " because of unhandled instruction " |
| 2618 | << instruction.Name(); |
| 2619 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnhandledInstruction); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2620 | return false; |
| 2621 | } |
| 2622 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2623 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2624 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2625 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 2626 | return locals_.Get(register_index); |
| 2627 | } |
| 2628 | |
| 2629 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 2630 | HLocal* local = GetLocalAt(register_index); |
| 2631 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 2632 | } |
| 2633 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2634 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2635 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2636 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2637 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2638 | } |
| 2639 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2640 | } // namespace art |