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