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