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