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