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