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" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 22 | #include "dex_file-inl.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 23 | #include "dex_instruction-inl.h" |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 24 | #include "dex/verified_method.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 25 | #include "driver/compiler_driver-inl.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 26 | #include "driver/compiler_options.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 27 | #include "mirror/class_loader.h" |
| 28 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 29 | #include "nodes.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 30 | #include "primitive.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 31 | #include "scoped_thread_state_change.h" |
| 32 | #include "thread.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 33 | |
| 34 | namespace art { |
| 35 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | /** |
| 37 | * Helper class to add HTemporary instructions. This class is used when |
| 38 | * converting a DEX instruction to multiple HInstruction, and where those |
| 39 | * instructions do not die at the following instruction, but instead spans |
| 40 | * multiple instructions. |
| 41 | */ |
| 42 | class Temporaries : public ValueObject { |
| 43 | public: |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 44 | explicit Temporaries(HGraph* graph) : graph_(graph), index_(0) {} |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 45 | |
| 46 | void Add(HInstruction* instruction) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 47 | HInstruction* temp = new (graph_->GetArena()) HTemporary(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | instruction->GetBlock()->AddInstruction(temp); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 49 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | DCHECK(temp->GetPrevious() == instruction); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 51 | |
| 52 | size_t offset; |
| 53 | if (instruction->GetType() == Primitive::kPrimLong |
| 54 | || instruction->GetType() == Primitive::kPrimDouble) { |
| 55 | offset = 2; |
| 56 | } else { |
| 57 | offset = 1; |
| 58 | } |
| 59 | index_ += offset; |
| 60 | |
| 61 | graph_->UpdateTemporariesVRegSlots(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | private: |
| 65 | HGraph* const graph_; |
| 66 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 67 | // Current index in the temporary stack, updated by `Add`. |
| 68 | size_t index_; |
| 69 | }; |
| 70 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 71 | class SwitchTable : public ValueObject { |
| 72 | public: |
| 73 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 74 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 75 | int32_t table_offset = instruction.VRegB_31t(); |
| 76 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 77 | if (sparse) { |
| 78 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 79 | } else { |
| 80 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 81 | } |
| 82 | num_entries_ = table[1]; |
| 83 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 84 | } |
| 85 | |
| 86 | uint16_t GetNumEntries() const { |
| 87 | return num_entries_; |
| 88 | } |
| 89 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 90 | void CheckIndex(size_t index) const { |
| 91 | if (sparse_) { |
| 92 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 93 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 94 | } else { |
| 95 | // In a packed table, we have the starting key and num_entries_ values. |
| 96 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 97 | } |
| 98 | } |
| 99 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 100 | int32_t GetEntryAt(size_t index) const { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 101 | CheckIndex(index); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 102 | return values_[index]; |
| 103 | } |
| 104 | |
| 105 | uint32_t GetDexPcForIndex(size_t index) const { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 106 | CheckIndex(index); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 107 | return dex_pc_ + |
| 108 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 109 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 110 | } |
| 111 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 112 | // Index of the first value in the table. |
| 113 | size_t GetFirstValueIndex() const { |
| 114 | if (sparse_) { |
| 115 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 116 | return num_entries_; |
| 117 | } else { |
| 118 | // In a packed table, we have the starting key and num_entries_ values. |
| 119 | return 1; |
| 120 | } |
| 121 | } |
| 122 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 123 | private: |
| 124 | const Instruction& instruction_; |
| 125 | const uint32_t dex_pc_; |
| 126 | |
| 127 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 128 | const bool sparse_; |
| 129 | |
| 130 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 131 | // expressions in the initializer list seemed very ugly. |
| 132 | uint16_t num_entries_; |
| 133 | |
| 134 | const int32_t* values_; |
| 135 | |
| 136 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 137 | }; |
| 138 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 139 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 140 | graph_->SetNumberOfVRegs(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 141 | locals_.SetSize(count); |
| 142 | for (int i = 0; i < count; i++) { |
| 143 | HLocal* local = new (arena_) HLocal(i); |
| 144 | entry_block_->AddInstruction(local); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 145 | locals_.Put(i, local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 149 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 150 | // dex_compilation_unit_ is null only when unit testing. |
| 151 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 152 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 156 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 157 | int locals_index = locals_.Size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 158 | int parameter_index = 0; |
| 159 | |
| 160 | if (!dex_compilation_unit_->IsStatic()) { |
| 161 | // Add the implicit 'this' argument, not expressed in the signature. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 162 | HParameterValue* parameter = |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 163 | new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot, true); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 164 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 165 | HLocal* local = GetLocalAt(locals_index++); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 166 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 167 | number_of_parameters--; |
| 168 | } |
| 169 | |
| 170 | uint32_t pos = 1; |
| 171 | for (int i = 0; i < number_of_parameters; i++) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 172 | HParameterValue* parameter = |
| 173 | new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++])); |
| 174 | entry_block_->AddInstruction(parameter); |
| 175 | HLocal* local = GetLocalAt(locals_index++); |
| 176 | // Store the parameter value in the local that the dex code will use |
| 177 | // to reference that parameter. |
| 178 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
| 179 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 180 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 181 | if (is_wide) { |
| 182 | i++; |
| 183 | locals_index++; |
| 184 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 185 | } |
| 186 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 187 | } |
| 188 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 189 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 190 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 191 | int32_t target_offset = instruction.GetTargetOffset(); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 192 | HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset); |
| 193 | HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 194 | DCHECK(branch_target != nullptr); |
| 195 | DCHECK(fallthrough_target != nullptr); |
| 196 | PotentiallyAddSuspendCheck(branch_target, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 197 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 198 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 199 | T* comparison = new (arena_) T(first, second); |
| 200 | current_block_->AddInstruction(comparison); |
| 201 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 202 | current_block_->AddInstruction(ifinst); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 203 | current_block_->AddSuccessor(branch_target); |
| 204 | current_block_->AddSuccessor(fallthrough_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 205 | current_block_ = nullptr; |
| 206 | } |
| 207 | |
| 208 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 209 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 210 | int32_t target_offset = instruction.GetTargetOffset(); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 211 | HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset); |
| 212 | HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 213 | DCHECK(branch_target != nullptr); |
| 214 | DCHECK(fallthrough_target != nullptr); |
| 215 | PotentiallyAddSuspendCheck(branch_target, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 216 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 217 | T* comparison = new (arena_) T(value, graph_->GetIntConstant(0)); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 218 | current_block_->AddInstruction(comparison); |
| 219 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 220 | current_block_->AddInstruction(ifinst); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 221 | current_block_->AddSuccessor(branch_target); |
| 222 | current_block_->AddSuccessor(fallthrough_target); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 223 | current_block_ = nullptr; |
| 224 | } |
| 225 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 226 | void HGraphBuilder::MaybeRecordStat(MethodCompilationStat compilation_stat) { |
| 227 | if (compilation_stats_ != nullptr) { |
| 228 | compilation_stats_->RecordStat(compilation_stat); |
| 229 | } |
| 230 | } |
| 231 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 232 | bool HGraphBuilder::SkipCompilation(const DexFile::CodeItem& code_item, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 233 | size_t number_of_branches) { |
| 234 | const CompilerOptions& compiler_options = compiler_driver_->GetCompilerOptions(); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 235 | CompilerOptions::CompilerFilter compiler_filter = compiler_options.GetCompilerFilter(); |
| 236 | if (compiler_filter == CompilerOptions::kEverything) { |
| 237 | return false; |
| 238 | } |
| 239 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 240 | if (compiler_options.IsHugeMethod(code_item.insns_size_in_code_units_)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 241 | VLOG(compiler) << "Skip compilation of huge method " |
| 242 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 243 | << ": " << code_item.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 244 | MaybeRecordStat(MethodCompilationStat::kNotCompiledHugeMethod); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 245 | return true; |
| 246 | } |
| 247 | |
| 248 | // 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] | 249 | if (compiler_options.IsLargeMethod(code_item.insns_size_in_code_units_) |
| 250 | && (number_of_branches == 0)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 251 | VLOG(compiler) << "Skip compilation of large method with no branch " |
| 252 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 253 | << ": " << code_item.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 254 | MaybeRecordStat(MethodCompilationStat::kNotCompiledLargeMethodNoBranches); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 255 | return true; |
| 256 | } |
| 257 | |
| 258 | return false; |
| 259 | } |
| 260 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 261 | bool HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
| 262 | DCHECK(graph_->GetBlocks().IsEmpty()); |
| 263 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 264 | const uint16_t* code_ptr = code_item.insns_; |
| 265 | 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] | 266 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 267 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 268 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 269 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 270 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 271 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 272 | graph_->SetEntryBlock(entry_block_); |
| 273 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 274 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 275 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 276 | graph_->SetMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 277 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 278 | // Compute the number of dex instructions, blocks, and branches. We will |
| 279 | // check these values against limits given to the compiler. |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 280 | size_t number_of_branches = 0; |
| 281 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 282 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 283 | // start a new block, and create these blocks. |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 284 | ComputeBranchTargets(code_ptr, code_end, &number_of_branches); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 285 | |
| 286 | // Note that the compiler driver is null when unit testing. |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 287 | if ((compiler_driver_ != nullptr) && SkipCompilation(code_item, number_of_branches)) { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 288 | return false; |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 289 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 290 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 291 | // Also create blocks for catch handlers. |
| 292 | if (code_item.tries_size_ != 0) { |
| 293 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0); |
| 294 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 295 | for (uint32_t idx = 0; idx < handlers_size; ++idx) { |
| 296 | CatchHandlerIterator iterator(handlers_ptr); |
| 297 | for (; iterator.HasNext(); iterator.Next()) { |
| 298 | uint32_t address = iterator.GetHandlerAddress(); |
| 299 | HBasicBlock* block = FindBlockStartingAt(address); |
| 300 | if (block == nullptr) { |
| 301 | block = new (arena_) HBasicBlock(graph_, address); |
| 302 | branch_targets_.Put(address, block); |
| 303 | } |
| 304 | block->SetIsCatchBlock(); |
| 305 | } |
| 306 | handlers_ptr = iterator.EndDataPointer(); |
| 307 | } |
| 308 | } |
| 309 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 310 | InitializeParameters(code_item.ins_size_); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 311 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 312 | size_t dex_pc = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 313 | while (code_ptr < code_end) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 314 | // Update the current block if dex_pc starts a new block. |
| 315 | MaybeUpdateCurrentBlock(dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 316 | const Instruction& instruction = *Instruction::At(code_ptr); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 317 | if (!AnalyzeDexInstruction(instruction, dex_pc)) { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 318 | return false; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 319 | } |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 320 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 321 | code_ptr += instruction.SizeInCodeUnits(); |
| 322 | } |
| 323 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 324 | // Add the exit block at the end to give it the highest id. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 325 | graph_->AddBlock(exit_block_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 326 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 327 | // Add the suspend check to the entry block. |
| 328 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 329 | entry_block_->AddInstruction(new (arena_) HGoto()); |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 330 | |
| 331 | return true; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 334 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) { |
| 335 | HBasicBlock* block = FindBlockStartingAt(index); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 336 | if (block == nullptr) { |
| 337 | return; |
| 338 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 339 | |
| 340 | if (current_block_ != nullptr) { |
| 341 | // Branching instructions clear current_block, so we know |
| 342 | // the last instruction of the current block is not a branching |
| 343 | // instruction. We add an unconditional goto to the found block. |
| 344 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 345 | current_block_->AddSuccessor(block); |
| 346 | } |
| 347 | graph_->AddBlock(block); |
| 348 | current_block_ = block; |
| 349 | } |
| 350 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 351 | void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, |
| 352 | const uint16_t* code_end, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 353 | size_t* number_of_branches) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 354 | branch_targets_.SetSize(code_end - code_ptr); |
| 355 | |
| 356 | // 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] | 357 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 358 | branch_targets_.Put(0, block); |
| 359 | entry_block_->AddSuccessor(block); |
| 360 | |
| 361 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 362 | // the locations these instructions branch to. |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 363 | uint32_t dex_pc = 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 364 | while (code_ptr < code_end) { |
| 365 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 366 | if (instruction.IsBranch()) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 367 | (*number_of_branches)++; |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 368 | int32_t target = instruction.GetTargetOffset() + dex_pc; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 369 | // Create a block for the target instruction. |
| 370 | if (FindBlockStartingAt(target) == nullptr) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 371 | block = new (arena_) HBasicBlock(graph_, target); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 372 | branch_targets_.Put(target, block); |
| 373 | } |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 374 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 375 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 376 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_pc) == nullptr)) { |
| 377 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
| 378 | branch_targets_.Put(dex_pc, block); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 379 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 380 | } else if (instruction.IsSwitch()) { |
| 381 | SwitchTable table(instruction, dex_pc, instruction.Opcode() == Instruction::SPARSE_SWITCH); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 382 | |
| 383 | uint16_t num_entries = table.GetNumEntries(); |
| 384 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 385 | // In a packed-switch, the entry at index 0 is the starting key. In a sparse-switch, the |
| 386 | // entry at index 0 is the first key, and values are after *all* keys. |
| 387 | size_t offset = table.GetFirstValueIndex(); |
| 388 | |
| 389 | // Use a larger loop counter type to avoid overflow issues. |
| 390 | for (size_t i = 0; i < num_entries; ++i) { |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 391 | // The target of the case. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 392 | uint32_t target = dex_pc + table.GetEntryAt(i + offset); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 393 | if (FindBlockStartingAt(target) == nullptr) { |
| 394 | block = new (arena_) HBasicBlock(graph_, target); |
| 395 | branch_targets_.Put(target, block); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // The next case gets its own block. |
| 399 | if (i < num_entries) { |
| 400 | block = new (arena_) HBasicBlock(graph_, target); |
| 401 | branch_targets_.Put(table.GetDexPcForIndex(i), block); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | // Fall-through. Add a block if there is more code afterwards. |
| 406 | dex_pc += instruction.SizeInCodeUnits(); |
| 407 | code_ptr += instruction.SizeInCodeUnits(); |
| 408 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_pc) == nullptr)) { |
| 409 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
| 410 | branch_targets_.Put(dex_pc, block); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 411 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 412 | } else { |
| 413 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 414 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const { |
| 420 | DCHECK_GE(index, 0); |
| 421 | return branch_targets_.Get(index); |
| 422 | } |
| 423 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 424 | template<typename T> |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 425 | void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) { |
| 426 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 427 | current_block_->AddInstruction(new (arena_) T(type, first)); |
| 428 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 429 | } |
| 430 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 431 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 432 | Primitive::Type input_type, |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 433 | Primitive::Type result_type, |
| 434 | uint32_t dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 435 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 436 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first, dex_pc)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 437 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 438 | } |
| 439 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 440 | template<typename T> |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 441 | void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 442 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 443 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 444 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 445 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 446 | } |
| 447 | |
| 448 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 449 | void HGraphBuilder::Binop_23x(const Instruction& instruction, |
| 450 | Primitive::Type type, |
| 451 | uint32_t dex_pc) { |
| 452 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 453 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 454 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 455 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 456 | } |
| 457 | |
| 458 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 459 | void HGraphBuilder::Binop_23x_shift(const Instruction& instruction, |
| 460 | Primitive::Type type) { |
| 461 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 462 | HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt); |
| 463 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
| 464 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 465 | } |
| 466 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 467 | void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction, |
| 468 | Primitive::Type type, |
| 469 | HCompare::Bias bias) { |
| 470 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 471 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 472 | current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias)); |
| 473 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 474 | } |
| 475 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 476 | template<typename T> |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 477 | void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) { |
| 478 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 479 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 480 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 481 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 482 | } |
| 483 | |
| 484 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 485 | void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type) { |
| 486 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 487 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 488 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
| 489 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 490 | } |
| 491 | |
| 492 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 493 | void HGraphBuilder::Binop_12x(const Instruction& instruction, |
| 494 | Primitive::Type type, |
| 495 | uint32_t dex_pc) { |
| 496 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 497 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 498 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 499 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 500 | } |
| 501 | |
| 502 | template<typename T> |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 503 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 504 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 505 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 506 | if (reverse) { |
| 507 | std::swap(first, second); |
| 508 | } |
| 509 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 510 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 511 | } |
| 512 | |
| 513 | template<typename T> |
| 514 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 515 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 516 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 517 | if (reverse) { |
| 518 | std::swap(first, second); |
| 519 | } |
| 520 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 521 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 522 | } |
| 523 | |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 524 | static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) { |
| 525 | // dex compilation unit is null only when unit testing. |
| 526 | if (cu == nullptr) { |
| 527 | return false; |
| 528 | } |
| 529 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 530 | Thread* self = Thread::Current(); |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 531 | return cu->IsConstructor() |
| 532 | && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 533 | } |
| 534 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 535 | void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) { |
| 536 | if (type == Primitive::kPrimVoid) { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 537 | // Note that we might insert redundant barriers when inlining `super` calls. |
| 538 | // TODO: add a data flow analysis to get rid of duplicate barriers. |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 539 | if (RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_)) { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 540 | current_block_->AddInstruction(new (arena_) HMemoryBarrier(kStoreStore)); |
| 541 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 542 | current_block_->AddInstruction(new (arena_) HReturnVoid()); |
| 543 | } else { |
| 544 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
| 545 | current_block_->AddInstruction(new (arena_) HReturn(value)); |
| 546 | } |
| 547 | current_block_->AddSuccessor(exit_block_); |
| 548 | current_block_ = nullptr; |
| 549 | } |
| 550 | |
| 551 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 552 | uint32_t dex_pc, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 553 | uint32_t method_idx, |
| 554 | uint32_t number_of_vreg_arguments, |
| 555 | bool is_range, |
| 556 | uint32_t* args, |
| 557 | uint32_t register_index) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 558 | Instruction::Code opcode = instruction.Opcode(); |
| 559 | InvokeType invoke_type; |
| 560 | switch (opcode) { |
| 561 | case Instruction::INVOKE_STATIC: |
| 562 | case Instruction::INVOKE_STATIC_RANGE: |
| 563 | invoke_type = kStatic; |
| 564 | break; |
| 565 | case Instruction::INVOKE_DIRECT: |
| 566 | case Instruction::INVOKE_DIRECT_RANGE: |
| 567 | invoke_type = kDirect; |
| 568 | break; |
| 569 | case Instruction::INVOKE_VIRTUAL: |
| 570 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 571 | invoke_type = kVirtual; |
| 572 | break; |
| 573 | case Instruction::INVOKE_INTERFACE: |
| 574 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 575 | invoke_type = kInterface; |
| 576 | break; |
| 577 | case Instruction::INVOKE_SUPER_RANGE: |
| 578 | case Instruction::INVOKE_SUPER: |
| 579 | invoke_type = kSuper; |
| 580 | break; |
| 581 | default: |
| 582 | LOG(FATAL) << "Unexpected invoke op: " << opcode; |
| 583 | return false; |
| 584 | } |
| 585 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 586 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 587 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 588 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 589 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 590 | bool is_instance_call = invoke_type != kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 591 | size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 592 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 593 | MethodReference target_method(dex_file_, method_idx); |
| 594 | uintptr_t direct_code; |
| 595 | uintptr_t direct_method; |
| 596 | int table_index; |
| 597 | InvokeType optimized_invoke_type = invoke_type; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 598 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 599 | if (!compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_pc, true, true, |
| 600 | &optimized_invoke_type, &target_method, &table_index, |
| 601 | &direct_code, &direct_method)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 602 | VLOG(compiler) << "Did not compile " << PrettyMethod(method_idx, *dex_file_) |
| 603 | << " because a method call could not be resolved"; |
| 604 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedMethod); |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 605 | return false; |
| 606 | } |
| 607 | DCHECK(optimized_invoke_type != kSuper); |
| 608 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 609 | // By default, consider that the called method implicitly requires |
| 610 | // an initialization check of its declaring method. |
| 611 | HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement = |
| 612 | HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit; |
| 613 | // Potential class initialization check, in the case of a static method call. |
| 614 | HClinitCheck* clinit_check = nullptr; |
| 615 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 616 | HInvoke* invoke = nullptr; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 617 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 618 | if (optimized_invoke_type == kVirtual) { |
| 619 | invoke = new (arena_) HInvokeVirtual( |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 620 | arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 621 | } else if (optimized_invoke_type == kInterface) { |
| 622 | invoke = new (arena_) HInvokeInterface( |
| 623 | arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 624 | } else { |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 625 | DCHECK(optimized_invoke_type == kDirect || optimized_invoke_type == kStatic); |
| 626 | // Sharpening to kDirect only works if we compile PIC. |
| 627 | DCHECK((optimized_invoke_type == invoke_type) || (optimized_invoke_type != kDirect) |
| 628 | || compiler_driver_->GetCompilerOptions().GetCompilePic()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 629 | bool is_recursive = |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 630 | (target_method.dex_method_index == dex_compilation_unit_->GetDexMethodIndex()); |
| 631 | DCHECK(!is_recursive || (target_method.dex_file == dex_compilation_unit_->GetDexFile())); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 632 | |
| 633 | if (optimized_invoke_type == kStatic) { |
| 634 | ScopedObjectAccess soa(Thread::Current()); |
| 635 | StackHandleScope<4> hs(soa.Self()); |
| 636 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 637 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 638 | *dex_compilation_unit_->GetDexFile()))); |
| 639 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 640 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 641 | mirror::ArtMethod* resolved_method = compiler_driver_->ResolveMethod( |
| 642 | soa, dex_cache, class_loader, dex_compilation_unit_, method_idx, |
| 643 | optimized_invoke_type); |
| 644 | |
| 645 | if (resolved_method == nullptr) { |
| 646 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedMethod); |
| 647 | return false; |
| 648 | } |
| 649 | |
| 650 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 651 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 652 | outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file))); |
| 653 | Handle<mirror::Class> referrer_class(hs.NewHandle(GetOutermostCompilingClass())); |
| 654 | |
| 655 | // The index at which the method's class is stored in the DexCache's type array. |
| 656 | uint32_t storage_index = DexFile::kDexNoIndex; |
| 657 | bool is_referrer_class = (resolved_method->GetDeclaringClass() == referrer_class.Get()); |
| 658 | if (is_referrer_class) { |
| 659 | storage_index = referrer_class->GetDexTypeIndex(); |
| 660 | } else if (outer_dex_cache.Get() == dex_cache.Get()) { |
| 661 | // Get `storage_index` from IsClassOfStaticMethodAvailableToReferrer. |
| 662 | compiler_driver_->IsClassOfStaticMethodAvailableToReferrer(outer_dex_cache.Get(), |
| 663 | referrer_class.Get(), |
| 664 | resolved_method, |
| 665 | method_idx, |
| 666 | &storage_index); |
| 667 | } |
| 668 | |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 669 | if (referrer_class.Get()->IsSubClass(resolved_method->GetDeclaringClass())) { |
| 670 | // If the referrer class is the declaring class or a subclass |
| 671 | // of the declaring class, no class initialization is needed |
| 672 | // before the static method call. |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 673 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 674 | } else if (storage_index != DexFile::kDexNoIndex) { |
| 675 | // If the method's class type index is available, check |
| 676 | // whether we should add an explicit class initialization |
| 677 | // check for its declaring class before the static method call. |
| 678 | |
| 679 | // TODO: find out why this check is needed. |
| 680 | bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache( |
| 681 | *outer_compilation_unit_->GetDexFile(), storage_index); |
| 682 | bool is_initialized = |
| 683 | resolved_method->GetDeclaringClass()->IsInitialized() && is_in_dex_cache; |
| 684 | |
| 685 | if (is_initialized) { |
| 686 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 687 | } else { |
| 688 | clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit; |
| 689 | HLoadClass* load_class = |
| 690 | new (arena_) HLoadClass(storage_index, is_referrer_class, dex_pc); |
| 691 | current_block_->AddInstruction(load_class); |
| 692 | clinit_check = new (arena_) HClinitCheck(load_class, dex_pc); |
| 693 | current_block_->AddInstruction(clinit_check); |
| 694 | ++number_of_arguments; |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 699 | invoke = new (arena_) HInvokeStaticOrDirect( |
| 700 | arena_, number_of_arguments, return_type, dex_pc, target_method.dex_method_index, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 701 | is_recursive, invoke_type, optimized_invoke_type, clinit_check_requirement); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 702 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 703 | |
| 704 | size_t start_index = 0; |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 705 | Temporaries temps(graph_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 706 | if (is_instance_call) { |
| 707 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 708 | HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_pc); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 709 | current_block_->AddInstruction(null_check); |
| 710 | temps.Add(null_check); |
| 711 | invoke->SetArgumentAt(0, null_check); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 712 | start_index = 1; |
| 713 | } |
| 714 | |
| 715 | uint32_t descriptor_index = 1; |
| 716 | uint32_t argument_index = start_index; |
| 717 | for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) { |
| 718 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 719 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
| 720 | if (!is_range && is_wide && args[i] + 1 != args[i + 1]) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 721 | LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol() |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 722 | << " at " << dex_pc; |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 723 | // We do not implement non sequential register pair. |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 724 | MaybeRecordStat(MethodCompilationStat::kNotCompiledNonSequentialRegPair); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 725 | return false; |
| 726 | } |
| 727 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 728 | invoke->SetArgumentAt(argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 729 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 730 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 734 | if (clinit_check_requirement == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit) { |
| 735 | // Add the class initialization check as last input of `invoke`. |
| 736 | DCHECK(clinit_check != nullptr); |
| 737 | invoke->SetArgumentAt(argument_index++, clinit_check); |
| 738 | } |
| 739 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 740 | DCHECK_EQ(argument_index, number_of_arguments); |
| 741 | current_block_->AddInstruction(invoke); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 742 | latest_result_ = invoke; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 743 | return true; |
| 744 | } |
| 745 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 746 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 747 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 748 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 749 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 750 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 751 | uint16_t field_index = instruction.VRegC_22c(); |
| 752 | |
| 753 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 754 | ArtField* resolved_field = |
| 755 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 756 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 757 | if (resolved_field == nullptr) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 758 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedField); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 759 | return false; |
| 760 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 761 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 762 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 763 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 764 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 765 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_pc)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 766 | if (is_put) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 767 | Temporaries temps(graph_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 768 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 769 | // We need one temporary for the null check. |
| 770 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 771 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 772 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 773 | null_check, |
| 774 | value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 775 | field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 776 | resolved_field->GetOffset(), |
| 777 | resolved_field->IsVolatile())); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 778 | } else { |
| 779 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 780 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 781 | field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 782 | resolved_field->GetOffset(), |
| 783 | resolved_field->IsVolatile())); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 784 | |
| 785 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 786 | } |
| 787 | return true; |
| 788 | } |
| 789 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 790 | mirror::Class* HGraphBuilder::GetOutermostCompilingClass() const { |
| 791 | ScopedObjectAccess soa(Thread::Current()); |
| 792 | StackHandleScope<2> hs(soa.Self()); |
| 793 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 794 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 795 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 796 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 797 | outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file))); |
| 798 | |
| 799 | return compiler_driver_->ResolveCompilingMethodsClass( |
| 800 | soa, outer_dex_cache, class_loader, outer_compilation_unit_); |
| 801 | } |
| 802 | |
| 803 | bool HGraphBuilder::IsOutermostCompilingClass(uint16_t type_index) const { |
| 804 | ScopedObjectAccess soa(Thread::Current()); |
| 805 | StackHandleScope<4> hs(soa.Self()); |
| 806 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 807 | dex_compilation_unit_->GetClassLinker()->FindDexCache(*dex_compilation_unit_->GetDexFile()))); |
| 808 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 809 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 810 | Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass( |
| 811 | soa, dex_cache, class_loader, type_index, dex_compilation_unit_))); |
| 812 | Handle<mirror::Class> compiling_class(hs.NewHandle(GetOutermostCompilingClass())); |
| 813 | |
| 814 | return compiling_class.Get() == cls.Get(); |
| 815 | } |
| 816 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 817 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 818 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 819 | bool is_put) { |
| 820 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 821 | uint16_t field_index = instruction.VRegB_21c(); |
| 822 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 823 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 824 | StackHandleScope<4> hs(soa.Self()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 825 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 826 | dex_compilation_unit_->GetClassLinker()->FindDexCache(*dex_compilation_unit_->GetDexFile()))); |
| 827 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 828 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 829 | ArtField* resolved_field = compiler_driver_->ResolveField( |
| 830 | soa, dex_cache, class_loader, dex_compilation_unit_, field_index, true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 831 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 832 | if (resolved_field == nullptr) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 833 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedField); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 834 | return false; |
| 835 | } |
| 836 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 837 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 838 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 839 | outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file))); |
| 840 | Handle<mirror::Class> referrer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 841 | |
| 842 | // The index at which the field's class is stored in the DexCache's type array. |
| 843 | uint32_t storage_index; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 844 | bool is_referrer_class = (referrer_class.Get() == resolved_field->GetDeclaringClass()); |
| 845 | if (is_referrer_class) { |
| 846 | storage_index = referrer_class->GetDexTypeIndex(); |
| 847 | } else if (outer_dex_cache.Get() != dex_cache.Get()) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 848 | // The compiler driver cannot currently understand multiple dex caches involved. Just bailout. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 849 | return false; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 850 | } else { |
| 851 | std::pair<bool, bool> pair = compiler_driver_->IsFastStaticField( |
| 852 | outer_dex_cache.Get(), |
| 853 | referrer_class.Get(), |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 854 | resolved_field, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 855 | field_index, |
| 856 | &storage_index); |
| 857 | bool can_easily_access = is_put ? pair.second : pair.first; |
| 858 | if (!can_easily_access) { |
| 859 | return false; |
| 860 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | // TODO: find out why this check is needed. |
| 864 | bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache( |
Nicolas Geoffray | 6a816cf | 2015-03-24 16:17:56 +0000 | [diff] [blame] | 865 | *outer_compilation_unit_->GetDexFile(), storage_index); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 866 | bool is_initialized = resolved_field->GetDeclaringClass()->IsInitialized() && is_in_dex_cache; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 867 | |
| 868 | HLoadClass* constant = new (arena_) HLoadClass(storage_index, is_referrer_class, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 869 | current_block_->AddInstruction(constant); |
| 870 | |
| 871 | HInstruction* cls = constant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 872 | if (!is_initialized && !is_referrer_class) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 873 | cls = new (arena_) HClinitCheck(constant, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 874 | current_block_->AddInstruction(cls); |
| 875 | } |
| 876 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 877 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 878 | if (is_put) { |
| 879 | // We need to keep the class alive before loading the value. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 880 | Temporaries temps(graph_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 881 | temps.Add(cls); |
| 882 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 883 | DCHECK_EQ(value->GetType(), field_type); |
| 884 | current_block_->AddInstruction( |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 885 | new (arena_) HStaticFieldSet(cls, value, field_type, resolved_field->GetOffset(), |
| 886 | resolved_field->IsVolatile())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 887 | } else { |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 888 | current_block_->AddInstruction( |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 889 | new (arena_) HStaticFieldGet(cls, field_type, resolved_field->GetOffset(), |
| 890 | resolved_field->IsVolatile())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 891 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 892 | } |
| 893 | return true; |
| 894 | } |
| 895 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 896 | void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
| 897 | uint16_t first_vreg, |
| 898 | int64_t second_vreg_or_constant, |
| 899 | uint32_t dex_pc, |
| 900 | Primitive::Type type, |
| 901 | bool second_is_constant, |
| 902 | bool isDiv) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 903 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 904 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 905 | HInstruction* first = LoadLocal(first_vreg, type); |
| 906 | HInstruction* second = nullptr; |
| 907 | if (second_is_constant) { |
| 908 | if (type == Primitive::kPrimInt) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 909 | second = graph_->GetIntConstant(second_vreg_or_constant); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 910 | } else { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 911 | second = graph_->GetLongConstant(second_vreg_or_constant); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 912 | } |
| 913 | } else { |
| 914 | second = LoadLocal(second_vreg_or_constant, type); |
| 915 | } |
| 916 | |
| 917 | if (!second_is_constant |
| 918 | || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0) |
| 919 | || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) { |
| 920 | second = new (arena_) HDivZeroCheck(second, dex_pc); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 921 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 922 | current_block_->AddInstruction(second); |
| 923 | temps.Add(current_block_->GetLastInstruction()); |
| 924 | } |
| 925 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 926 | if (isDiv) { |
| 927 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc)); |
| 928 | } else { |
| 929 | current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc)); |
| 930 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 931 | UpdateLocal(out_vreg, current_block_->GetLastInstruction()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 934 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 935 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 936 | bool is_put, |
| 937 | Primitive::Type anticipated_type) { |
| 938 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 939 | uint8_t array_reg = instruction.VRegB_23x(); |
| 940 | uint8_t index_reg = instruction.VRegC_23x(); |
| 941 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 942 | // 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] | 943 | Temporaries temps(graph_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 944 | |
| 945 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 946 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 947 | current_block_->AddInstruction(object); |
| 948 | temps.Add(object); |
| 949 | |
| 950 | HInstruction* length = new (arena_) HArrayLength(object); |
| 951 | current_block_->AddInstruction(length); |
| 952 | temps.Add(length); |
| 953 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 954 | index = new (arena_) HBoundsCheck(index, length, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 955 | current_block_->AddInstruction(index); |
| 956 | temps.Add(index); |
| 957 | if (is_put) { |
| 958 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 959 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 960 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 961 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 962 | } else { |
| 963 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type)); |
| 964 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 965 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 966 | graph_->SetHasBoundsChecks(true); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 967 | } |
| 968 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 969 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 970 | uint32_t type_index, |
| 971 | uint32_t number_of_vreg_arguments, |
| 972 | bool is_range, |
| 973 | uint32_t* args, |
| 974 | uint32_t register_index) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 975 | HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 976 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 977 | ? kQuickAllocArrayWithAccessCheck |
| 978 | : kQuickAllocArray; |
| 979 | HInstruction* object = new (arena_) HNewArray(length, dex_pc, type_index, entrypoint); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 980 | current_block_->AddInstruction(object); |
| 981 | |
| 982 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 983 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 984 | char primitive = descriptor[1]; |
| 985 | DCHECK(primitive == 'I' |
| 986 | || primitive == 'L' |
| 987 | || primitive == '[') << descriptor; |
| 988 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 989 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 990 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 991 | Temporaries temps(graph_); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 992 | temps.Add(object); |
| 993 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 994 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 995 | HInstruction* index = graph_->GetIntConstant(i); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 996 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 997 | new (arena_) HArraySet(object, index, value, type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 998 | } |
| 999 | latest_result_ = object; |
| 1000 | } |
| 1001 | |
| 1002 | template <typename T> |
| 1003 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 1004 | const T* data, |
| 1005 | uint32_t element_count, |
| 1006 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1007 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1008 | for (uint32_t i = 0; i < element_count; ++i) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1009 | HInstruction* index = graph_->GetIntConstant(i); |
| 1010 | HInstruction* value = graph_->GetIntConstant(data[i]); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1011 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1012 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1016 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1017 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1018 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1019 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1020 | current_block_->AddInstruction(null_check); |
| 1021 | temps.Add(null_check); |
| 1022 | |
| 1023 | HInstruction* length = new (arena_) HArrayLength(null_check); |
| 1024 | current_block_->AddInstruction(length); |
| 1025 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1026 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1027 | const Instruction::ArrayDataPayload* payload = |
| 1028 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 1029 | const uint8_t* data = payload->data; |
| 1030 | uint32_t element_count = payload->element_count; |
| 1031 | |
| 1032 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 1033 | // done before doing any stores. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1034 | HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1035 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1036 | |
| 1037 | switch (payload->element_width) { |
| 1038 | case 1: |
| 1039 | BuildFillArrayData(null_check, |
| 1040 | reinterpret_cast<const int8_t*>(data), |
| 1041 | element_count, |
| 1042 | Primitive::kPrimByte, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1043 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1044 | break; |
| 1045 | case 2: |
| 1046 | BuildFillArrayData(null_check, |
| 1047 | reinterpret_cast<const int16_t*>(data), |
| 1048 | element_count, |
| 1049 | Primitive::kPrimShort, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1050 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1051 | break; |
| 1052 | case 4: |
| 1053 | BuildFillArrayData(null_check, |
| 1054 | reinterpret_cast<const int32_t*>(data), |
| 1055 | element_count, |
| 1056 | Primitive::kPrimInt, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1057 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1058 | break; |
| 1059 | case 8: |
| 1060 | BuildFillWideArrayData(null_check, |
| 1061 | reinterpret_cast<const int64_t*>(data), |
| 1062 | element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1063 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1064 | break; |
| 1065 | default: |
| 1066 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 1067 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1068 | graph_->SetHasBoundsChecks(true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1071 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1072 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1073 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1074 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1075 | for (uint32_t i = 0; i < element_count; ++i) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1076 | HInstruction* index = graph_->GetIntConstant(i); |
| 1077 | HInstruction* value = graph_->GetLongConstant(data[i]); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1078 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1079 | object, index, value, Primitive::kPrimLong, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1083 | bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
| 1084 | uint8_t destination, |
| 1085 | uint8_t reference, |
| 1086 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1087 | uint32_t dex_pc) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1088 | bool type_known_final; |
| 1089 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1090 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 1091 | // built is trying to access its own class, so that the generated |
| 1092 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1093 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1094 | bool dont_use_is_referrers_class; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1095 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1096 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1097 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1098 | if (!can_access) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1099 | MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1100 | return false; |
| 1101 | } |
| 1102 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1103 | HLoadClass* cls = new (arena_) HLoadClass( |
| 1104 | type_index, IsOutermostCompilingClass(type_index), dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1105 | current_block_->AddInstruction(cls); |
| 1106 | // The class needs a temporary before being used by the type check. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1107 | Temporaries temps(graph_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1108 | temps.Add(cls); |
| 1109 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
| 1110 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1111 | new (arena_) HInstanceOf(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1112 | UpdateLocal(destination, current_block_->GetLastInstruction()); |
| 1113 | } else { |
| 1114 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
| 1115 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1116 | new (arena_) HCheckCast(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1117 | } |
| 1118 | return true; |
| 1119 | } |
| 1120 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1121 | bool HGraphBuilder::NeedsAccessCheck(uint32_t type_index) const { |
| 1122 | return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks( |
| 1123 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index); |
| 1124 | } |
| 1125 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1126 | void HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) { |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1127 | SwitchTable table(instruction, dex_pc, false); |
| 1128 | |
| 1129 | // Value to test against. |
| 1130 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 1131 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1132 | uint16_t num_entries = table.GetNumEntries(); |
| 1133 | // There should be at least one entry here. |
| 1134 | DCHECK_GT(num_entries, 0U); |
| 1135 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1136 | // Chained cmp-and-branch, starting from starting_key. |
| 1137 | int32_t starting_key = table.GetEntryAt(0); |
| 1138 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1139 | for (size_t i = 1; i <= num_entries; i++) { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1140 | BuildSwitchCaseHelper(instruction, i, i == num_entries, table, value, starting_key + i - 1, |
| 1141 | table.GetEntryAt(i), dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1142 | } |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1143 | } |
| 1144 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1145 | void HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1146 | SwitchTable table(instruction, dex_pc, true); |
| 1147 | |
| 1148 | // Value to test against. |
| 1149 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 1150 | |
| 1151 | uint16_t num_entries = table.GetNumEntries(); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1152 | |
| 1153 | for (size_t i = 0; i < num_entries; i++) { |
| 1154 | BuildSwitchCaseHelper(instruction, i, i == static_cast<size_t>(num_entries) - 1, table, value, |
| 1155 | table.GetEntryAt(i), table.GetEntryAt(i + num_entries), dex_pc); |
| 1156 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | void HGraphBuilder::BuildSwitchCaseHelper(const Instruction& instruction, size_t index, |
| 1160 | bool is_last_case, const SwitchTable& table, |
| 1161 | HInstruction* value, int32_t case_value_int, |
| 1162 | int32_t target_offset, uint32_t dex_pc) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1163 | HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset); |
| 1164 | DCHECK(case_target != nullptr); |
| 1165 | PotentiallyAddSuspendCheck(case_target, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1166 | |
| 1167 | // The current case's value. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1168 | HInstruction* this_case_value = graph_->GetIntConstant(case_value_int); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1169 | |
| 1170 | // Compare value and this_case_value. |
| 1171 | HEqual* comparison = new (arena_) HEqual(value, this_case_value); |
| 1172 | current_block_->AddInstruction(comparison); |
| 1173 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 1174 | current_block_->AddInstruction(ifinst); |
| 1175 | |
| 1176 | // Case hit: use the target offset to determine where to go. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1177 | current_block_->AddSuccessor(case_target); |
| 1178 | |
| 1179 | // Case miss: go to the next case (or default fall-through). |
| 1180 | // When there is a next case, we use the block stored with the table offset representing this |
| 1181 | // case (that is where we registered them in ComputeBranchTargets). |
| 1182 | // When there is no next case, we use the following instruction. |
| 1183 | // TODO: Find a good way to peel the last iteration to avoid conditional, but still have re-use. |
| 1184 | if (!is_last_case) { |
| 1185 | HBasicBlock* next_case_target = FindBlockStartingAt(table.GetDexPcForIndex(index)); |
| 1186 | DCHECK(next_case_target != nullptr); |
| 1187 | current_block_->AddSuccessor(next_case_target); |
| 1188 | |
| 1189 | // Need to manually add the block, as there is no dex-pc transition for the cases. |
| 1190 | graph_->AddBlock(next_case_target); |
| 1191 | |
| 1192 | current_block_ = next_case_target; |
| 1193 | } else { |
| 1194 | HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 1195 | DCHECK(default_target != nullptr); |
| 1196 | current_block_->AddSuccessor(default_target); |
| 1197 | current_block_ = nullptr; |
| 1198 | } |
| 1199 | } |
| 1200 | |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1201 | void HGraphBuilder::PotentiallyAddSuspendCheck(HBasicBlock* target, uint32_t dex_pc) { |
| 1202 | int32_t target_offset = target->GetDexPc() - dex_pc; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1203 | if (target_offset <= 0) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1204 | // DX generates back edges to the first encountered return. We can save |
| 1205 | // time of later passes by not adding redundant suspend checks. |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame] | 1206 | HInstruction* last_in_target = target->GetLastInstruction(); |
| 1207 | if (last_in_target != nullptr && |
| 1208 | (last_in_target->IsReturn() || last_in_target->IsReturnVoid())) { |
| 1209 | return; |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | // Add a suspend check to backward branches which may potentially loop. We |
| 1213 | // can remove them after we recognize loops in the graph. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1214 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc)); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1218 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1219 | if (current_block_ == nullptr) { |
| 1220 | return true; // Dead code |
| 1221 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1222 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1223 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1224 | case Instruction::CONST_4: { |
| 1225 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1226 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1227 | UpdateLocal(register_index, constant); |
| 1228 | break; |
| 1229 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1230 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1231 | case Instruction::CONST_16: { |
| 1232 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1233 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1234 | UpdateLocal(register_index, constant); |
| 1235 | break; |
| 1236 | } |
| 1237 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1238 | case Instruction::CONST: { |
| 1239 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1240 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i()); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1241 | UpdateLocal(register_index, constant); |
| 1242 | break; |
| 1243 | } |
| 1244 | |
| 1245 | case Instruction::CONST_HIGH16: { |
| 1246 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1247 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1248 | UpdateLocal(register_index, constant); |
| 1249 | break; |
| 1250 | } |
| 1251 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1252 | case Instruction::CONST_WIDE_16: { |
| 1253 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1254 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 1255 | int64_t value = instruction.VRegB_21s(); |
| 1256 | value <<= 48; |
| 1257 | value >>= 48; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1258 | HLongConstant* constant = graph_->GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1259 | UpdateLocal(register_index, constant); |
| 1260 | break; |
| 1261 | } |
| 1262 | |
| 1263 | case Instruction::CONST_WIDE_32: { |
| 1264 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1265 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 1266 | int64_t value = instruction.VRegB_31i(); |
| 1267 | value <<= 32; |
| 1268 | value >>= 32; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1269 | HLongConstant* constant = graph_->GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1270 | UpdateLocal(register_index, constant); |
| 1271 | break; |
| 1272 | } |
| 1273 | |
| 1274 | case Instruction::CONST_WIDE: { |
| 1275 | int32_t register_index = instruction.VRegA(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1276 | HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1277 | UpdateLocal(register_index, constant); |
| 1278 | break; |
| 1279 | } |
| 1280 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1281 | case Instruction::CONST_WIDE_HIGH16: { |
| 1282 | int32_t register_index = instruction.VRegA(); |
| 1283 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1284 | HLongConstant* constant = graph_->GetLongConstant(value); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1285 | UpdateLocal(register_index, constant); |
| 1286 | break; |
| 1287 | } |
| 1288 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1289 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1290 | case Instruction::MOVE: |
| 1291 | case Instruction::MOVE_FROM16: |
| 1292 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1293 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1294 | UpdateLocal(instruction.VRegA(), value); |
| 1295 | break; |
| 1296 | } |
| 1297 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1298 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1299 | case Instruction::MOVE_WIDE: |
| 1300 | case Instruction::MOVE_WIDE_FROM16: |
| 1301 | case Instruction::MOVE_WIDE_16: { |
| 1302 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 1303 | UpdateLocal(instruction.VRegA(), value); |
| 1304 | break; |
| 1305 | } |
| 1306 | |
| 1307 | case Instruction::MOVE_OBJECT: |
| 1308 | case Instruction::MOVE_OBJECT_16: |
| 1309 | case Instruction::MOVE_OBJECT_FROM16: { |
| 1310 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 1311 | UpdateLocal(instruction.VRegA(), value); |
| 1312 | break; |
| 1313 | } |
| 1314 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1315 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1316 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1317 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1320 | #define IF_XX(comparison, cond) \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1321 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 1322 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1323 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1324 | IF_XX(HEqual, EQ); |
| 1325 | IF_XX(HNotEqual, NE); |
| 1326 | IF_XX(HLessThan, LT); |
| 1327 | IF_XX(HLessThanOrEqual, LE); |
| 1328 | IF_XX(HGreaterThan, GT); |
| 1329 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1330 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1331 | case Instruction::GOTO: |
| 1332 | case Instruction::GOTO_16: |
| 1333 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1334 | int32_t offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1335 | HBasicBlock* target = FindBlockStartingAt(offset + dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1336 | DCHECK(target != nullptr); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1337 | PotentiallyAddSuspendCheck(target, dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1338 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 1339 | current_block_->AddSuccessor(target); |
| 1340 | current_block_ = nullptr; |
| 1341 | break; |
| 1342 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1343 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1344 | case Instruction::RETURN: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1345 | DCHECK_NE(return_type_, Primitive::kPrimNot); |
| 1346 | DCHECK_NE(return_type_, Primitive::kPrimLong); |
| 1347 | DCHECK_NE(return_type_, Primitive::kPrimDouble); |
| 1348 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1349 | break; |
| 1350 | } |
| 1351 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1352 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1353 | DCHECK(return_type_ == Primitive::kPrimNot); |
| 1354 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1355 | break; |
| 1356 | } |
| 1357 | |
| 1358 | case Instruction::RETURN_WIDE: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1359 | DCHECK(return_type_ == Primitive::kPrimDouble || return_type_ == Primitive::kPrimLong); |
| 1360 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1361 | break; |
| 1362 | } |
| 1363 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1364 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1365 | case Instruction::INVOKE_INTERFACE: |
| 1366 | case Instruction::INVOKE_STATIC: |
| 1367 | case Instruction::INVOKE_SUPER: |
| 1368 | case Instruction::INVOKE_VIRTUAL: { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1369 | uint32_t method_idx = instruction.VRegB_35c(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1370 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1371 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1372 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1373 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1374 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1375 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1376 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1377 | break; |
| 1378 | } |
| 1379 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1380 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1381 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 1382 | case Instruction::INVOKE_STATIC_RANGE: |
| 1383 | case Instruction::INVOKE_SUPER_RANGE: |
| 1384 | case Instruction::INVOKE_VIRTUAL_RANGE: { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1385 | uint32_t method_idx = instruction.VRegB_3rc(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1386 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1387 | uint32_t register_index = instruction.VRegC(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1388 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1389 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1390 | return false; |
| 1391 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1392 | break; |
| 1393 | } |
| 1394 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1395 | case Instruction::NEG_INT: { |
| 1396 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt); |
| 1397 | break; |
| 1398 | } |
| 1399 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1400 | case Instruction::NEG_LONG: { |
| 1401 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong); |
| 1402 | break; |
| 1403 | } |
| 1404 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1405 | case Instruction::NEG_FLOAT: { |
| 1406 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat); |
| 1407 | break; |
| 1408 | } |
| 1409 | |
| 1410 | case Instruction::NEG_DOUBLE: { |
| 1411 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble); |
| 1412 | break; |
| 1413 | } |
| 1414 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1415 | case Instruction::NOT_INT: { |
| 1416 | Unop_12x<HNot>(instruction, Primitive::kPrimInt); |
| 1417 | break; |
| 1418 | } |
| 1419 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1420 | case Instruction::NOT_LONG: { |
| 1421 | Unop_12x<HNot>(instruction, Primitive::kPrimLong); |
| 1422 | break; |
| 1423 | } |
| 1424 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1425 | case Instruction::INT_TO_LONG: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1426 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | } |
| 1429 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1430 | case Instruction::INT_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1431 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1432 | break; |
| 1433 | } |
| 1434 | |
| 1435 | case Instruction::INT_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1436 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1437 | break; |
| 1438 | } |
| 1439 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1440 | case Instruction::LONG_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1441 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1442 | break; |
| 1443 | } |
| 1444 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1445 | case Instruction::LONG_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1446 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1447 | break; |
| 1448 | } |
| 1449 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1450 | case Instruction::LONG_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1451 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1452 | break; |
| 1453 | } |
| 1454 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1455 | case Instruction::FLOAT_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1456 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc); |
| 1457 | break; |
| 1458 | } |
| 1459 | |
| 1460 | case Instruction::FLOAT_TO_LONG: { |
| 1461 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1462 | break; |
| 1463 | } |
| 1464 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1465 | case Instruction::FLOAT_TO_DOUBLE: { |
| 1466 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc); |
| 1467 | break; |
| 1468 | } |
| 1469 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1470 | case Instruction::DOUBLE_TO_INT: { |
| 1471 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc); |
| 1472 | break; |
| 1473 | } |
| 1474 | |
| 1475 | case Instruction::DOUBLE_TO_LONG: { |
| 1476 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc); |
| 1477 | break; |
| 1478 | } |
| 1479 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1480 | case Instruction::DOUBLE_TO_FLOAT: { |
| 1481 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc); |
| 1482 | break; |
| 1483 | } |
| 1484 | |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1485 | case Instruction::INT_TO_BYTE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1486 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1487 | break; |
| 1488 | } |
| 1489 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1490 | case Instruction::INT_TO_SHORT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1491 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1492 | break; |
| 1493 | } |
| 1494 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1495 | case Instruction::INT_TO_CHAR: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1496 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1497 | break; |
| 1498 | } |
| 1499 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1500 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1501 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1502 | break; |
| 1503 | } |
| 1504 | |
| 1505 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1506 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1507 | break; |
| 1508 | } |
| 1509 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1510 | case Instruction::ADD_DOUBLE: { |
| 1511 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1512 | break; |
| 1513 | } |
| 1514 | |
| 1515 | case Instruction::ADD_FLOAT: { |
| 1516 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1517 | break; |
| 1518 | } |
| 1519 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1520 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1521 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1522 | break; |
| 1523 | } |
| 1524 | |
| 1525 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1526 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1527 | break; |
| 1528 | } |
| 1529 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1530 | case Instruction::SUB_FLOAT: { |
| 1531 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat); |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | case Instruction::SUB_DOUBLE: { |
| 1536 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble); |
| 1537 | break; |
| 1538 | } |
| 1539 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1540 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1541 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 1542 | break; |
| 1543 | } |
| 1544 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1545 | case Instruction::MUL_INT: { |
| 1546 | Binop_23x<HMul>(instruction, Primitive::kPrimInt); |
| 1547 | break; |
| 1548 | } |
| 1549 | |
| 1550 | case Instruction::MUL_LONG: { |
| 1551 | Binop_23x<HMul>(instruction, Primitive::kPrimLong); |
| 1552 | break; |
| 1553 | } |
| 1554 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1555 | case Instruction::MUL_FLOAT: { |
| 1556 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat); |
| 1557 | break; |
| 1558 | } |
| 1559 | |
| 1560 | case Instruction::MUL_DOUBLE: { |
| 1561 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble); |
| 1562 | break; |
| 1563 | } |
| 1564 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1565 | case Instruction::DIV_INT: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1566 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1567 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1568 | break; |
| 1569 | } |
| 1570 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1571 | case Instruction::DIV_LONG: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1572 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1573 | dex_pc, Primitive::kPrimLong, false, true); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1574 | break; |
| 1575 | } |
| 1576 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1577 | case Instruction::DIV_FLOAT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1578 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1579 | break; |
| 1580 | } |
| 1581 | |
| 1582 | case Instruction::DIV_DOUBLE: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1583 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1584 | break; |
| 1585 | } |
| 1586 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1587 | case Instruction::REM_INT: { |
| 1588 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1589 | dex_pc, Primitive::kPrimInt, false, false); |
| 1590 | break; |
| 1591 | } |
| 1592 | |
| 1593 | case Instruction::REM_LONG: { |
| 1594 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1595 | dex_pc, Primitive::kPrimLong, false, false); |
| 1596 | break; |
| 1597 | } |
| 1598 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 1599 | case Instruction::REM_FLOAT: { |
| 1600 | Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 1601 | break; |
| 1602 | } |
| 1603 | |
| 1604 | case Instruction::REM_DOUBLE: { |
| 1605 | Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 1606 | break; |
| 1607 | } |
| 1608 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1609 | case Instruction::AND_INT: { |
| 1610 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt); |
| 1611 | break; |
| 1612 | } |
| 1613 | |
| 1614 | case Instruction::AND_LONG: { |
| 1615 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong); |
| 1616 | break; |
| 1617 | } |
| 1618 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1619 | case Instruction::SHL_INT: { |
| 1620 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 1621 | break; |
| 1622 | } |
| 1623 | |
| 1624 | case Instruction::SHL_LONG: { |
| 1625 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 1626 | break; |
| 1627 | } |
| 1628 | |
| 1629 | case Instruction::SHR_INT: { |
| 1630 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 1631 | break; |
| 1632 | } |
| 1633 | |
| 1634 | case Instruction::SHR_LONG: { |
| 1635 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 1636 | break; |
| 1637 | } |
| 1638 | |
| 1639 | case Instruction::USHR_INT: { |
| 1640 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 1641 | break; |
| 1642 | } |
| 1643 | |
| 1644 | case Instruction::USHR_LONG: { |
| 1645 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 1646 | break; |
| 1647 | } |
| 1648 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1649 | case Instruction::OR_INT: { |
| 1650 | Binop_23x<HOr>(instruction, Primitive::kPrimInt); |
| 1651 | break; |
| 1652 | } |
| 1653 | |
| 1654 | case Instruction::OR_LONG: { |
| 1655 | Binop_23x<HOr>(instruction, Primitive::kPrimLong); |
| 1656 | break; |
| 1657 | } |
| 1658 | |
| 1659 | case Instruction::XOR_INT: { |
| 1660 | Binop_23x<HXor>(instruction, Primitive::kPrimInt); |
| 1661 | break; |
| 1662 | } |
| 1663 | |
| 1664 | case Instruction::XOR_LONG: { |
| 1665 | Binop_23x<HXor>(instruction, Primitive::kPrimLong); |
| 1666 | break; |
| 1667 | } |
| 1668 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1669 | case Instruction::ADD_LONG_2ADDR: { |
| 1670 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1671 | break; |
| 1672 | } |
| 1673 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1674 | case Instruction::ADD_DOUBLE_2ADDR: { |
| 1675 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1676 | break; |
| 1677 | } |
| 1678 | |
| 1679 | case Instruction::ADD_FLOAT_2ADDR: { |
| 1680 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1681 | break; |
| 1682 | } |
| 1683 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1684 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1685 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 1686 | break; |
| 1687 | } |
| 1688 | |
| 1689 | case Instruction::SUB_LONG_2ADDR: { |
| 1690 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1691 | break; |
| 1692 | } |
| 1693 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1694 | case Instruction::SUB_FLOAT_2ADDR: { |
| 1695 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat); |
| 1696 | break; |
| 1697 | } |
| 1698 | |
| 1699 | case Instruction::SUB_DOUBLE_2ADDR: { |
| 1700 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble); |
| 1701 | break; |
| 1702 | } |
| 1703 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1704 | case Instruction::MUL_INT_2ADDR: { |
| 1705 | Binop_12x<HMul>(instruction, Primitive::kPrimInt); |
| 1706 | break; |
| 1707 | } |
| 1708 | |
| 1709 | case Instruction::MUL_LONG_2ADDR: { |
| 1710 | Binop_12x<HMul>(instruction, Primitive::kPrimLong); |
| 1711 | break; |
| 1712 | } |
| 1713 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1714 | case Instruction::MUL_FLOAT_2ADDR: { |
| 1715 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat); |
| 1716 | break; |
| 1717 | } |
| 1718 | |
| 1719 | case Instruction::MUL_DOUBLE_2ADDR: { |
| 1720 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble); |
| 1721 | break; |
| 1722 | } |
| 1723 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1724 | case Instruction::DIV_INT_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1725 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1726 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1727 | break; |
| 1728 | } |
| 1729 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1730 | case Instruction::DIV_LONG_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1731 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1732 | dex_pc, Primitive::kPrimLong, false, true); |
| 1733 | break; |
| 1734 | } |
| 1735 | |
| 1736 | case Instruction::REM_INT_2ADDR: { |
| 1737 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1738 | dex_pc, Primitive::kPrimInt, false, false); |
| 1739 | break; |
| 1740 | } |
| 1741 | |
| 1742 | case Instruction::REM_LONG_2ADDR: { |
| 1743 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1744 | dex_pc, Primitive::kPrimLong, false, false); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1745 | break; |
| 1746 | } |
| 1747 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 1748 | case Instruction::REM_FLOAT_2ADDR: { |
| 1749 | Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 1750 | break; |
| 1751 | } |
| 1752 | |
| 1753 | case Instruction::REM_DOUBLE_2ADDR: { |
| 1754 | Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 1755 | break; |
| 1756 | } |
| 1757 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1758 | case Instruction::SHL_INT_2ADDR: { |
| 1759 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 1760 | break; |
| 1761 | } |
| 1762 | |
| 1763 | case Instruction::SHL_LONG_2ADDR: { |
| 1764 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 1765 | break; |
| 1766 | } |
| 1767 | |
| 1768 | case Instruction::SHR_INT_2ADDR: { |
| 1769 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 1770 | break; |
| 1771 | } |
| 1772 | |
| 1773 | case Instruction::SHR_LONG_2ADDR: { |
| 1774 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 1775 | break; |
| 1776 | } |
| 1777 | |
| 1778 | case Instruction::USHR_INT_2ADDR: { |
| 1779 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 1780 | break; |
| 1781 | } |
| 1782 | |
| 1783 | case Instruction::USHR_LONG_2ADDR: { |
| 1784 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 1785 | break; |
| 1786 | } |
| 1787 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1788 | case Instruction::DIV_FLOAT_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1789 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1790 | break; |
| 1791 | } |
| 1792 | |
| 1793 | case Instruction::DIV_DOUBLE_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1794 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1795 | break; |
| 1796 | } |
| 1797 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1798 | case Instruction::AND_INT_2ADDR: { |
| 1799 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt); |
| 1800 | break; |
| 1801 | } |
| 1802 | |
| 1803 | case Instruction::AND_LONG_2ADDR: { |
| 1804 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong); |
| 1805 | break; |
| 1806 | } |
| 1807 | |
| 1808 | case Instruction::OR_INT_2ADDR: { |
| 1809 | Binop_12x<HOr>(instruction, Primitive::kPrimInt); |
| 1810 | break; |
| 1811 | } |
| 1812 | |
| 1813 | case Instruction::OR_LONG_2ADDR: { |
| 1814 | Binop_12x<HOr>(instruction, Primitive::kPrimLong); |
| 1815 | break; |
| 1816 | } |
| 1817 | |
| 1818 | case Instruction::XOR_INT_2ADDR: { |
| 1819 | Binop_12x<HXor>(instruction, Primitive::kPrimInt); |
| 1820 | break; |
| 1821 | } |
| 1822 | |
| 1823 | case Instruction::XOR_LONG_2ADDR: { |
| 1824 | Binop_12x<HXor>(instruction, Primitive::kPrimLong); |
| 1825 | break; |
| 1826 | } |
| 1827 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1828 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1829 | Binop_22s<HAdd>(instruction, false); |
| 1830 | break; |
| 1831 | } |
| 1832 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1833 | case Instruction::AND_INT_LIT16: { |
| 1834 | Binop_22s<HAnd>(instruction, false); |
| 1835 | break; |
| 1836 | } |
| 1837 | |
| 1838 | case Instruction::OR_INT_LIT16: { |
| 1839 | Binop_22s<HOr>(instruction, false); |
| 1840 | break; |
| 1841 | } |
| 1842 | |
| 1843 | case Instruction::XOR_INT_LIT16: { |
| 1844 | Binop_22s<HXor>(instruction, false); |
| 1845 | break; |
| 1846 | } |
| 1847 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1848 | case Instruction::RSUB_INT: { |
| 1849 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1850 | break; |
| 1851 | } |
| 1852 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1853 | case Instruction::MUL_INT_LIT16: { |
| 1854 | Binop_22s<HMul>(instruction, false); |
| 1855 | break; |
| 1856 | } |
| 1857 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1858 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1859 | Binop_22b<HAdd>(instruction, false); |
| 1860 | break; |
| 1861 | } |
| 1862 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1863 | case Instruction::AND_INT_LIT8: { |
| 1864 | Binop_22b<HAnd>(instruction, false); |
| 1865 | break; |
| 1866 | } |
| 1867 | |
| 1868 | case Instruction::OR_INT_LIT8: { |
| 1869 | Binop_22b<HOr>(instruction, false); |
| 1870 | break; |
| 1871 | } |
| 1872 | |
| 1873 | case Instruction::XOR_INT_LIT8: { |
| 1874 | Binop_22b<HXor>(instruction, false); |
| 1875 | break; |
| 1876 | } |
| 1877 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1878 | case Instruction::RSUB_INT_LIT8: { |
| 1879 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1880 | break; |
| 1881 | } |
| 1882 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1883 | case Instruction::MUL_INT_LIT8: { |
| 1884 | Binop_22b<HMul>(instruction, false); |
| 1885 | break; |
| 1886 | } |
| 1887 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1888 | case Instruction::DIV_INT_LIT16: |
| 1889 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1890 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1891 | dex_pc, Primitive::kPrimInt, true, true); |
| 1892 | break; |
| 1893 | } |
| 1894 | |
| 1895 | case Instruction::REM_INT_LIT16: |
| 1896 | case Instruction::REM_INT_LIT8: { |
| 1897 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1898 | dex_pc, Primitive::kPrimInt, true, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1899 | break; |
| 1900 | } |
| 1901 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1902 | case Instruction::SHL_INT_LIT8: { |
| 1903 | Binop_22b<HShl>(instruction, false); |
| 1904 | break; |
| 1905 | } |
| 1906 | |
| 1907 | case Instruction::SHR_INT_LIT8: { |
| 1908 | Binop_22b<HShr>(instruction, false); |
| 1909 | break; |
| 1910 | } |
| 1911 | |
| 1912 | case Instruction::USHR_INT_LIT8: { |
| 1913 | Binop_22b<HUShr>(instruction, false); |
| 1914 | break; |
| 1915 | } |
| 1916 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1917 | case Instruction::NEW_INSTANCE: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1918 | uint16_t type_index = instruction.VRegB_21c(); |
| 1919 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 1920 | ? kQuickAllocObjectWithAccessCheck |
| 1921 | : kQuickAllocObject; |
| 1922 | |
| 1923 | current_block_->AddInstruction(new (arena_) HNewInstance(dex_pc, type_index, entrypoint)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1924 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 1925 | break; |
| 1926 | } |
| 1927 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1928 | case Instruction::NEW_ARRAY: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1929 | uint16_t type_index = instruction.VRegC_22c(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1930 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1931 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index) |
| 1932 | ? kQuickAllocArrayWithAccessCheck |
| 1933 | : kQuickAllocArray; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1934 | current_block_->AddInstruction( |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1935 | new (arena_) HNewArray(length, dex_pc, type_index, entrypoint)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1936 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 1937 | break; |
| 1938 | } |
| 1939 | |
| 1940 | case Instruction::FILLED_NEW_ARRAY: { |
| 1941 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 1942 | uint32_t type_index = instruction.VRegB_35c(); |
| 1943 | uint32_t args[5]; |
| 1944 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1945 | BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1946 | break; |
| 1947 | } |
| 1948 | |
| 1949 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 1950 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1951 | uint32_t type_index = instruction.VRegB_3rc(); |
| 1952 | uint32_t register_index = instruction.VRegC_3rc(); |
| 1953 | BuildFilledNewArray( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1954 | dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1955 | break; |
| 1956 | } |
| 1957 | |
| 1958 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1959 | BuildFillArrayData(instruction, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1960 | break; |
| 1961 | } |
| 1962 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1963 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1964 | case Instruction::MOVE_RESULT_WIDE: |
| 1965 | case Instruction::MOVE_RESULT_OBJECT: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1966 | UpdateLocal(instruction.VRegA(), latest_result_); |
| 1967 | latest_result_ = nullptr; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1968 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1969 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1970 | case Instruction::CMP_LONG: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1971 | Binop_23x_cmp(instruction, Primitive::kPrimLong, HCompare::kNoBias); |
| 1972 | break; |
| 1973 | } |
| 1974 | |
| 1975 | case Instruction::CMPG_FLOAT: { |
| 1976 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, HCompare::kGtBias); |
| 1977 | break; |
| 1978 | } |
| 1979 | |
| 1980 | case Instruction::CMPG_DOUBLE: { |
| 1981 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, HCompare::kGtBias); |
| 1982 | break; |
| 1983 | } |
| 1984 | |
| 1985 | case Instruction::CMPL_FLOAT: { |
| 1986 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, HCompare::kLtBias); |
| 1987 | break; |
| 1988 | } |
| 1989 | |
| 1990 | case Instruction::CMPL_DOUBLE: { |
| 1991 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, HCompare::kLtBias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1992 | break; |
| 1993 | } |
| 1994 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1995 | case Instruction::NOP: |
| 1996 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1997 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1998 | case Instruction::IGET: |
| 1999 | case Instruction::IGET_WIDE: |
| 2000 | case Instruction::IGET_OBJECT: |
| 2001 | case Instruction::IGET_BOOLEAN: |
| 2002 | case Instruction::IGET_BYTE: |
| 2003 | case Instruction::IGET_CHAR: |
| 2004 | case Instruction::IGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2005 | if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2006 | return false; |
| 2007 | } |
| 2008 | break; |
| 2009 | } |
| 2010 | |
| 2011 | case Instruction::IPUT: |
| 2012 | case Instruction::IPUT_WIDE: |
| 2013 | case Instruction::IPUT_OBJECT: |
| 2014 | case Instruction::IPUT_BOOLEAN: |
| 2015 | case Instruction::IPUT_BYTE: |
| 2016 | case Instruction::IPUT_CHAR: |
| 2017 | case Instruction::IPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2018 | if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2019 | return false; |
| 2020 | } |
| 2021 | break; |
| 2022 | } |
| 2023 | |
| 2024 | case Instruction::SGET: |
| 2025 | case Instruction::SGET_WIDE: |
| 2026 | case Instruction::SGET_OBJECT: |
| 2027 | case Instruction::SGET_BOOLEAN: |
| 2028 | case Instruction::SGET_BYTE: |
| 2029 | case Instruction::SGET_CHAR: |
| 2030 | case Instruction::SGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2031 | if (!BuildStaticFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2032 | return false; |
| 2033 | } |
| 2034 | break; |
| 2035 | } |
| 2036 | |
| 2037 | case Instruction::SPUT: |
| 2038 | case Instruction::SPUT_WIDE: |
| 2039 | case Instruction::SPUT_OBJECT: |
| 2040 | case Instruction::SPUT_BOOLEAN: |
| 2041 | case Instruction::SPUT_BYTE: |
| 2042 | case Instruction::SPUT_CHAR: |
| 2043 | case Instruction::SPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2044 | if (!BuildStaticFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2045 | return false; |
| 2046 | } |
| 2047 | break; |
| 2048 | } |
| 2049 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2050 | #define ARRAY_XX(kind, anticipated_type) \ |
| 2051 | case Instruction::AGET##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2052 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2053 | break; \ |
| 2054 | } \ |
| 2055 | case Instruction::APUT##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2056 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2057 | break; \ |
| 2058 | } |
| 2059 | |
| 2060 | ARRAY_XX(, Primitive::kPrimInt); |
| 2061 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 2062 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 2063 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 2064 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 2065 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 2066 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 2067 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2068 | case Instruction::ARRAY_LENGTH: { |
| 2069 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2070 | // No need for a temporary for the null check, it is the only input of the following |
| 2071 | // instruction. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2072 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2073 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2074 | current_block_->AddInstruction(new (arena_) HArrayLength(object)); |
| 2075 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 2076 | break; |
| 2077 | } |
| 2078 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2079 | case Instruction::CONST_STRING: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2080 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_21c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2081 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 2082 | break; |
| 2083 | } |
| 2084 | |
| 2085 | case Instruction::CONST_STRING_JUMBO: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2086 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_31c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2087 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 2088 | break; |
| 2089 | } |
| 2090 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2091 | case Instruction::CONST_CLASS: { |
| 2092 | uint16_t type_index = instruction.VRegB_21c(); |
| 2093 | bool type_known_final; |
| 2094 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2095 | bool dont_use_is_referrers_class; |
| 2096 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 2097 | // built is trying to access its own class, so that the generated |
| 2098 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2099 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2100 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 2101 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2102 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2103 | if (!can_access) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2104 | MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2105 | return false; |
| 2106 | } |
| 2107 | current_block_->AddInstruction( |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2108 | new (arena_) HLoadClass(type_index, IsOutermostCompilingClass(type_index), dex_pc)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2109 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 2110 | break; |
| 2111 | } |
| 2112 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2113 | case Instruction::MOVE_EXCEPTION: { |
| 2114 | current_block_->AddInstruction(new (arena_) HLoadException()); |
| 2115 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
| 2116 | break; |
| 2117 | } |
| 2118 | |
| 2119 | case Instruction::THROW: { |
| 2120 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2121 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2122 | // A throw instruction must branch to the exit block. |
| 2123 | current_block_->AddSuccessor(exit_block_); |
| 2124 | // We finished building this block. Set the current block to null to avoid |
| 2125 | // adding dead instructions to it. |
| 2126 | current_block_ = nullptr; |
| 2127 | break; |
| 2128 | } |
| 2129 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2130 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2131 | uint8_t destination = instruction.VRegA_22c(); |
| 2132 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2133 | uint16_t type_index = instruction.VRegC_22c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2134 | if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2135 | return false; |
| 2136 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2137 | break; |
| 2138 | } |
| 2139 | |
| 2140 | case Instruction::CHECK_CAST: { |
| 2141 | uint8_t reference = instruction.VRegA_21c(); |
| 2142 | uint16_t type_index = instruction.VRegB_21c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2143 | if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2144 | return false; |
| 2145 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2146 | break; |
| 2147 | } |
| 2148 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2149 | case Instruction::MONITOR_ENTER: { |
| 2150 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 2151 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 2152 | HMonitorOperation::kEnter, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2153 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2154 | break; |
| 2155 | } |
| 2156 | |
| 2157 | case Instruction::MONITOR_EXIT: { |
| 2158 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 2159 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 2160 | HMonitorOperation::kExit, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2161 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2162 | break; |
| 2163 | } |
| 2164 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2165 | case Instruction::PACKED_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2166 | BuildPackedSwitch(instruction, dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2167 | break; |
| 2168 | } |
| 2169 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2170 | case Instruction::SPARSE_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2171 | BuildSparseSwitch(instruction, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2172 | break; |
| 2173 | } |
| 2174 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2175 | default: |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2176 | VLOG(compiler) << "Did not compile " |
| 2177 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 2178 | << " because of unhandled instruction " |
| 2179 | << instruction.Name(); |
| 2180 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnhandledInstruction); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2181 | return false; |
| 2182 | } |
| 2183 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2184 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2185 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2186 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 2187 | return locals_.Get(register_index); |
| 2188 | } |
| 2189 | |
| 2190 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 2191 | HLocal* local = GetLocalAt(register_index); |
| 2192 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 2193 | } |
| 2194 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2195 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2196 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2197 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2198 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2201 | } // namespace art |