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 | |
| 19 | #include "class_linker.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 20 | #include "dex_file.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 21 | #include "dex_file-inl.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 22 | #include "dex_instruction.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 23 | #include "dex_instruction-inl.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 24 | #include "driver/compiler_driver-inl.h" |
| 25 | #include "mirror/art_field.h" |
| 26 | #include "mirror/art_field-inl.h" |
| 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 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 71 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 72 | graph_->SetNumberOfVRegs(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 73 | locals_.SetSize(count); |
| 74 | for (int i = 0; i < count; i++) { |
| 75 | HLocal* local = new (arena_) HLocal(i); |
| 76 | entry_block_->AddInstruction(local); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 77 | locals_.Put(i, local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 81 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 82 | // dex_compilation_unit_ is null only when unit testing. |
| 83 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 84 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 88 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 89 | int locals_index = locals_.Size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 90 | int parameter_index = 0; |
| 91 | |
| 92 | if (!dex_compilation_unit_->IsStatic()) { |
| 93 | // Add the implicit 'this' argument, not expressed in the signature. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 94 | HParameterValue* parameter = |
| 95 | new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 96 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 97 | HLocal* local = GetLocalAt(locals_index++); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 98 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 99 | number_of_parameters--; |
| 100 | } |
| 101 | |
| 102 | uint32_t pos = 1; |
| 103 | for (int i = 0; i < number_of_parameters; i++) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 104 | HParameterValue* parameter = |
| 105 | new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++])); |
| 106 | entry_block_->AddInstruction(parameter); |
| 107 | HLocal* local = GetLocalAt(locals_index++); |
| 108 | // Store the parameter value in the local that the dex code will use |
| 109 | // to reference that parameter. |
| 110 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
| 111 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 112 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 113 | if (is_wide) { |
| 114 | i++; |
| 115 | locals_index++; |
| 116 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 117 | } |
| 118 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 121 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 122 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 123 | int32_t target_offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 124 | PotentiallyAddSuspendCheck(target_offset, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 125 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 126 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 127 | T* comparison = new (arena_) T(first, second); |
| 128 | current_block_->AddInstruction(comparison); |
| 129 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 130 | current_block_->AddInstruction(ifinst); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 131 | HBasicBlock* target = FindBlockStartingAt(dex_pc + target_offset); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 132 | DCHECK(target != nullptr); |
| 133 | current_block_->AddSuccessor(target); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 134 | target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 135 | DCHECK(target != nullptr); |
| 136 | current_block_->AddSuccessor(target); |
| 137 | current_block_ = nullptr; |
| 138 | } |
| 139 | |
| 140 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 141 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | int32_t target_offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 143 | PotentiallyAddSuspendCheck(target_offset, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 144 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 145 | T* comparison = new (arena_) T(value, GetIntConstant(0)); |
| 146 | current_block_->AddInstruction(comparison); |
| 147 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 148 | current_block_->AddInstruction(ifinst); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 149 | HBasicBlock* target = FindBlockStartingAt(dex_pc + target_offset); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 150 | DCHECK(target != nullptr); |
| 151 | current_block_->AddSuccessor(target); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 152 | target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 153 | DCHECK(target != nullptr); |
| 154 | current_block_->AddSuccessor(target); |
| 155 | current_block_ = nullptr; |
| 156 | } |
| 157 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame^] | 158 | static bool ShouldSkipCompilation(const CompilerDriver& compiler_driver, |
| 159 | const DexCompilationUnit& dex_compilation_unit, |
| 160 | size_t number_of_dex_instructions, |
| 161 | size_t number_of_blocks ATTRIBUTE_UNUSED, |
| 162 | size_t number_of_branches) { |
| 163 | const CompilerOptions& compiler_options = compiler_driver.GetCompilerOptions(); |
| 164 | CompilerOptions::CompilerFilter compiler_filter = compiler_options.GetCompilerFilter(); |
| 165 | if (compiler_filter == CompilerOptions::kEverything) { |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | if (compiler_options.IsHugeMethod(number_of_dex_instructions)) { |
| 170 | LOG(INFO) << "Skip compilation of huge method " |
| 171 | << PrettyMethod(dex_compilation_unit.GetDexMethodIndex(), |
| 172 | *dex_compilation_unit.GetDexFile()) |
| 173 | << ": " << number_of_dex_instructions << " dex instructions"; |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | // If it's large and contains no branches, it's likely to be machine generated initialization. |
| 178 | if (compiler_options.IsLargeMethod(number_of_dex_instructions) && (number_of_branches == 0)) { |
| 179 | LOG(INFO) << "Skip compilation of large method with no branch " |
| 180 | << PrettyMethod(dex_compilation_unit.GetDexMethodIndex(), |
| 181 | *dex_compilation_unit.GetDexFile()) |
| 182 | << ": " << number_of_dex_instructions << " dex instructions"; |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | return false; |
| 187 | } |
| 188 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 189 | HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 190 | const uint16_t* code_ptr = code_item.insns_; |
| 191 | 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] | 192 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 193 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 194 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 195 | graph_ = new (arena_) HGraph(arena_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 196 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 197 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 199 | graph_->SetEntryBlock(entry_block_); |
| 200 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 201 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 202 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 203 | graph_->UpdateMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 204 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame^] | 205 | // Compute the number of dex instructions, blocks, and branches. We will |
| 206 | // check these values against limits given to the compiler. |
| 207 | size_t number_of_dex_instructions = 0; |
| 208 | size_t number_of_blocks = 0; |
| 209 | size_t number_of_branches = 0; |
| 210 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 211 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 212 | // start a new block, and create these blocks. |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame^] | 213 | ComputeBranchTargets( |
| 214 | code_ptr, code_end, &number_of_dex_instructions, &number_of_blocks, &number_of_branches); |
| 215 | |
| 216 | // Note that the compiler driver is null when unit testing. |
| 217 | if (compiler_driver_ != nullptr) { |
| 218 | if (ShouldSkipCompilation(*compiler_driver_, |
| 219 | *dex_compilation_unit_, |
| 220 | number_of_dex_instructions, |
| 221 | number_of_blocks, |
| 222 | number_of_branches)) { |
| 223 | return nullptr; |
| 224 | } |
| 225 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 226 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 227 | // Also create blocks for catch handlers. |
| 228 | if (code_item.tries_size_ != 0) { |
| 229 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0); |
| 230 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 231 | for (uint32_t idx = 0; idx < handlers_size; ++idx) { |
| 232 | CatchHandlerIterator iterator(handlers_ptr); |
| 233 | for (; iterator.HasNext(); iterator.Next()) { |
| 234 | uint32_t address = iterator.GetHandlerAddress(); |
| 235 | HBasicBlock* block = FindBlockStartingAt(address); |
| 236 | if (block == nullptr) { |
| 237 | block = new (arena_) HBasicBlock(graph_, address); |
| 238 | branch_targets_.Put(address, block); |
| 239 | } |
| 240 | block->SetIsCatchBlock(); |
| 241 | } |
| 242 | handlers_ptr = iterator.EndDataPointer(); |
| 243 | } |
| 244 | } |
| 245 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 246 | InitializeParameters(code_item.ins_size_); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 247 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 248 | size_t dex_pc = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 249 | while (code_ptr < code_end) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 250 | // Update the current block if dex_pc starts a new block. |
| 251 | MaybeUpdateCurrentBlock(dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 252 | const Instruction& instruction = *Instruction::At(code_ptr); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 253 | if (!AnalyzeDexInstruction(instruction, dex_pc)) return nullptr; |
| 254 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 255 | code_ptr += instruction.SizeInCodeUnits(); |
| 256 | } |
| 257 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 258 | // 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] | 259 | graph_->AddBlock(exit_block_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 260 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 261 | // Add the suspend check to the entry block. |
| 262 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 263 | entry_block_->AddInstruction(new (arena_) HGoto()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 264 | return graph_; |
| 265 | } |
| 266 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 267 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) { |
| 268 | HBasicBlock* block = FindBlockStartingAt(index); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 269 | if (block == nullptr) { |
| 270 | return; |
| 271 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 272 | |
| 273 | if (current_block_ != nullptr) { |
| 274 | // Branching instructions clear current_block, so we know |
| 275 | // the last instruction of the current block is not a branching |
| 276 | // instruction. We add an unconditional goto to the found block. |
| 277 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 278 | current_block_->AddSuccessor(block); |
| 279 | } |
| 280 | graph_->AddBlock(block); |
| 281 | current_block_ = block; |
| 282 | } |
| 283 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame^] | 284 | void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, |
| 285 | const uint16_t* code_end, |
| 286 | size_t* number_of_dex_instructions, |
| 287 | size_t* number_of_blocks, |
| 288 | size_t* number_of_branches) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 289 | // TODO: Support switch instructions. |
| 290 | branch_targets_.SetSize(code_end - code_ptr); |
| 291 | |
| 292 | // 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] | 293 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 294 | branch_targets_.Put(0, block); |
| 295 | entry_block_->AddSuccessor(block); |
| 296 | |
| 297 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 298 | // the locations these instructions branch to. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 299 | size_t dex_pc = 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 300 | while (code_ptr < code_end) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame^] | 301 | (*number_of_dex_instructions)++; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 302 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 303 | if (instruction.IsBranch()) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame^] | 304 | (*number_of_branches)++; |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 305 | int32_t target = instruction.GetTargetOffset() + dex_pc; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 306 | // Create a block for the target instruction. |
| 307 | if (FindBlockStartingAt(target) == nullptr) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 308 | block = new (arena_) HBasicBlock(graph_, target); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 309 | branch_targets_.Put(target, block); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame^] | 310 | (*number_of_blocks)++; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 311 | } |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 312 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 313 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 314 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_pc) == nullptr)) { |
| 315 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
| 316 | branch_targets_.Put(dex_pc, block); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame^] | 317 | (*number_of_blocks)++; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 318 | } |
| 319 | } else { |
| 320 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 321 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const { |
| 327 | DCHECK_GE(index, 0); |
| 328 | return branch_targets_.Get(index); |
| 329 | } |
| 330 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 331 | template<typename T> |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 332 | void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) { |
| 333 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 334 | current_block_->AddInstruction(new (arena_) T(type, first)); |
| 335 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 336 | } |
| 337 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 338 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 339 | Primitive::Type input_type, |
| 340 | Primitive::Type result_type) { |
| 341 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type); |
| 342 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first)); |
| 343 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 344 | } |
| 345 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 346 | template<typename T> |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 347 | void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 348 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 349 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 350 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 351 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 352 | } |
| 353 | |
| 354 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 355 | void HGraphBuilder::Binop_23x(const Instruction& instruction, |
| 356 | Primitive::Type type, |
| 357 | uint32_t dex_pc) { |
| 358 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 359 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 360 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 361 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 362 | } |
| 363 | |
| 364 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 365 | void HGraphBuilder::Binop_23x_shift(const Instruction& instruction, |
| 366 | Primitive::Type type) { |
| 367 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 368 | HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt); |
| 369 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
| 370 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 371 | } |
| 372 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 373 | void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction, |
| 374 | Primitive::Type type, |
| 375 | HCompare::Bias bias) { |
| 376 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 377 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 378 | current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias)); |
| 379 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 380 | } |
| 381 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 382 | template<typename T> |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 383 | void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) { |
| 384 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 385 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 386 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 387 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 388 | } |
| 389 | |
| 390 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 391 | void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type) { |
| 392 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 393 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 394 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
| 395 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 396 | } |
| 397 | |
| 398 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 399 | void HGraphBuilder::Binop_12x(const Instruction& instruction, |
| 400 | Primitive::Type type, |
| 401 | uint32_t dex_pc) { |
| 402 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 403 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 404 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 405 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 406 | } |
| 407 | |
| 408 | template<typename T> |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 409 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 410 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 411 | HInstruction* second = GetIntConstant(instruction.VRegC_22s()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 412 | if (reverse) { |
| 413 | std::swap(first, second); |
| 414 | } |
| 415 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 416 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 417 | } |
| 418 | |
| 419 | template<typename T> |
| 420 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 421 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 422 | HInstruction* second = GetIntConstant(instruction.VRegC_22b()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 423 | if (reverse) { |
| 424 | std::swap(first, second); |
| 425 | } |
| 426 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 427 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 428 | } |
| 429 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 430 | void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) { |
| 431 | if (type == Primitive::kPrimVoid) { |
| 432 | current_block_->AddInstruction(new (arena_) HReturnVoid()); |
| 433 | } else { |
| 434 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
| 435 | current_block_->AddInstruction(new (arena_) HReturn(value)); |
| 436 | } |
| 437 | current_block_->AddSuccessor(exit_block_); |
| 438 | current_block_ = nullptr; |
| 439 | } |
| 440 | |
| 441 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 442 | uint32_t dex_pc, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 443 | uint32_t method_idx, |
| 444 | uint32_t number_of_vreg_arguments, |
| 445 | bool is_range, |
| 446 | uint32_t* args, |
| 447 | uint32_t register_index) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 448 | Instruction::Code opcode = instruction.Opcode(); |
| 449 | InvokeType invoke_type; |
| 450 | switch (opcode) { |
| 451 | case Instruction::INVOKE_STATIC: |
| 452 | case Instruction::INVOKE_STATIC_RANGE: |
| 453 | invoke_type = kStatic; |
| 454 | break; |
| 455 | case Instruction::INVOKE_DIRECT: |
| 456 | case Instruction::INVOKE_DIRECT_RANGE: |
| 457 | invoke_type = kDirect; |
| 458 | break; |
| 459 | case Instruction::INVOKE_VIRTUAL: |
| 460 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 461 | invoke_type = kVirtual; |
| 462 | break; |
| 463 | case Instruction::INVOKE_INTERFACE: |
| 464 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 465 | invoke_type = kInterface; |
| 466 | break; |
| 467 | case Instruction::INVOKE_SUPER_RANGE: |
| 468 | case Instruction::INVOKE_SUPER: |
| 469 | invoke_type = kSuper; |
| 470 | break; |
| 471 | default: |
| 472 | LOG(FATAL) << "Unexpected invoke op: " << opcode; |
| 473 | return false; |
| 474 | } |
| 475 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 476 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 477 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 478 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 479 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 480 | bool is_instance_call = invoke_type != kStatic; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 481 | const size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1); |
| 482 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 483 | HInvoke* invoke = nullptr; |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 484 | if (invoke_type == kVirtual || invoke_type == kInterface || invoke_type == kSuper) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 485 | MethodReference target_method(dex_file_, method_idx); |
| 486 | uintptr_t direct_code; |
| 487 | uintptr_t direct_method; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 488 | int table_index; |
| 489 | InvokeType optimized_invoke_type = invoke_type; |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 490 | compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_pc, true, true, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 491 | &optimized_invoke_type, &target_method, &table_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 492 | &direct_code, &direct_method); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 493 | if (table_index == -1) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 494 | return false; |
| 495 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 496 | |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 497 | if (optimized_invoke_type == kVirtual) { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 498 | invoke = new (arena_) HInvokeVirtual( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 499 | arena_, number_of_arguments, return_type, dex_pc, table_index); |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 500 | } else if (optimized_invoke_type == kInterface) { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 501 | invoke = new (arena_) HInvokeInterface( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 502 | arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 503 | } else if (optimized_invoke_type == kDirect) { |
| 504 | // For this compiler, sharpening only works if we compile PIC. |
| 505 | DCHECK(compiler_driver_->GetCompilerOptions().GetCompilePic()); |
| 506 | // Treat invoke-direct like static calls for now. |
| 507 | invoke = new (arena_) HInvokeStatic( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 508 | arena_, number_of_arguments, return_type, dex_pc, target_method.dex_method_index); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 509 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 510 | } else { |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 511 | DCHECK(invoke_type == kDirect || invoke_type == kStatic); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 512 | // Treat invoke-direct like static calls for now. |
| 513 | invoke = new (arena_) HInvokeStatic( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 514 | arena_, number_of_arguments, return_type, dex_pc, method_idx); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 515 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 516 | |
| 517 | size_t start_index = 0; |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 518 | Temporaries temps(graph_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 519 | if (is_instance_call) { |
| 520 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 521 | HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_pc); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 522 | current_block_->AddInstruction(null_check); |
| 523 | temps.Add(null_check); |
| 524 | invoke->SetArgumentAt(0, null_check); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 525 | start_index = 1; |
| 526 | } |
| 527 | |
| 528 | uint32_t descriptor_index = 1; |
| 529 | uint32_t argument_index = start_index; |
| 530 | for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) { |
| 531 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 532 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
| 533 | if (!is_range && is_wide && args[i] + 1 != args[i + 1]) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 534 | LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol() |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 535 | << " at " << dex_pc; |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 536 | // We do not implement non sequential register pair. |
| 537 | return false; |
| 538 | } |
| 539 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 540 | invoke->SetArgumentAt(argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 541 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 542 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | |
| 546 | DCHECK_EQ(argument_index, number_of_arguments); |
| 547 | current_block_->AddInstruction(invoke); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 548 | latest_result_ = invoke; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 549 | return true; |
| 550 | } |
| 551 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 552 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 553 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 554 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 555 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 556 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 557 | uint16_t field_index = instruction.VRegC_22c(); |
| 558 | |
| 559 | ScopedObjectAccess soa(Thread::Current()); |
| 560 | StackHandleScope<1> hs(soa.Self()); |
| 561 | Handle<mirror::ArtField> resolved_field(hs.NewHandle( |
| 562 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa))); |
| 563 | |
| 564 | if (resolved_field.Get() == nullptr) { |
| 565 | return false; |
| 566 | } |
| 567 | if (resolved_field->IsVolatile()) { |
| 568 | return false; |
| 569 | } |
| 570 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 571 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 572 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 573 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 574 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_pc)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 575 | if (is_put) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 576 | Temporaries temps(graph_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 577 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 578 | // We need one temporary for the null check. |
| 579 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 580 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 581 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 582 | null_check, |
| 583 | value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 584 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 585 | resolved_field->GetOffset())); |
| 586 | } else { |
| 587 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 588 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 589 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 590 | resolved_field->GetOffset())); |
| 591 | |
| 592 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 593 | } |
| 594 | return true; |
| 595 | } |
| 596 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 597 | |
| 598 | |
| 599 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 600 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 601 | bool is_put) { |
| 602 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 603 | uint16_t field_index = instruction.VRegB_21c(); |
| 604 | |
| 605 | uint32_t storage_index; |
| 606 | bool is_referrers_class; |
| 607 | bool is_initialized; |
| 608 | bool is_volatile; |
| 609 | MemberOffset field_offset(0u); |
| 610 | Primitive::Type field_type; |
| 611 | |
| 612 | bool fast_path = compiler_driver_->ComputeStaticFieldInfo(field_index, |
| 613 | dex_compilation_unit_, |
| 614 | is_put, |
| 615 | &field_offset, |
| 616 | &storage_index, |
| 617 | &is_referrers_class, |
| 618 | &is_volatile, |
| 619 | &is_initialized, |
| 620 | &field_type); |
| 621 | if (!fast_path) { |
| 622 | return false; |
| 623 | } |
| 624 | |
| 625 | if (is_volatile) { |
| 626 | return false; |
| 627 | } |
| 628 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 629 | HLoadClass* constant = new (arena_) HLoadClass( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 630 | storage_index, is_referrers_class, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 631 | current_block_->AddInstruction(constant); |
| 632 | |
| 633 | HInstruction* cls = constant; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 634 | if (!is_initialized) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 635 | cls = new (arena_) HClinitCheck(constant, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 636 | current_block_->AddInstruction(cls); |
| 637 | } |
| 638 | |
| 639 | if (is_put) { |
| 640 | // We need to keep the class alive before loading the value. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 641 | Temporaries temps(graph_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 642 | temps.Add(cls); |
| 643 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 644 | DCHECK_EQ(value->GetType(), field_type); |
| 645 | current_block_->AddInstruction( |
| 646 | new (arena_) HStaticFieldSet(cls, value, field_type, field_offset)); |
| 647 | } else { |
| 648 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, field_type, field_offset)); |
| 649 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 650 | } |
| 651 | return true; |
| 652 | } |
| 653 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 654 | void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
| 655 | uint16_t first_vreg, |
| 656 | int64_t second_vreg_or_constant, |
| 657 | uint32_t dex_pc, |
| 658 | Primitive::Type type, |
| 659 | bool second_is_constant, |
| 660 | bool isDiv) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 661 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 662 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 663 | HInstruction* first = LoadLocal(first_vreg, type); |
| 664 | HInstruction* second = nullptr; |
| 665 | if (second_is_constant) { |
| 666 | if (type == Primitive::kPrimInt) { |
| 667 | second = GetIntConstant(second_vreg_or_constant); |
| 668 | } else { |
| 669 | second = GetLongConstant(second_vreg_or_constant); |
| 670 | } |
| 671 | } else { |
| 672 | second = LoadLocal(second_vreg_or_constant, type); |
| 673 | } |
| 674 | |
| 675 | if (!second_is_constant |
| 676 | || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0) |
| 677 | || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) { |
| 678 | second = new (arena_) HDivZeroCheck(second, dex_pc); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 679 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 680 | current_block_->AddInstruction(second); |
| 681 | temps.Add(current_block_->GetLastInstruction()); |
| 682 | } |
| 683 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 684 | if (isDiv) { |
| 685 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc)); |
| 686 | } else { |
| 687 | current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc)); |
| 688 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 689 | UpdateLocal(out_vreg, current_block_->GetLastInstruction()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 692 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 693 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 694 | bool is_put, |
| 695 | Primitive::Type anticipated_type) { |
| 696 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 697 | uint8_t array_reg = instruction.VRegB_23x(); |
| 698 | uint8_t index_reg = instruction.VRegC_23x(); |
| 699 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 700 | // 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] | 701 | Temporaries temps(graph_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 702 | |
| 703 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 704 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 705 | current_block_->AddInstruction(object); |
| 706 | temps.Add(object); |
| 707 | |
| 708 | HInstruction* length = new (arena_) HArrayLength(object); |
| 709 | current_block_->AddInstruction(length); |
| 710 | temps.Add(length); |
| 711 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 712 | index = new (arena_) HBoundsCheck(index, length, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 713 | current_block_->AddInstruction(index); |
| 714 | temps.Add(index); |
| 715 | if (is_put) { |
| 716 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 717 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 718 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 719 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 720 | } else { |
| 721 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type)); |
| 722 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 723 | } |
| 724 | } |
| 725 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 726 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 727 | uint32_t type_index, |
| 728 | uint32_t number_of_vreg_arguments, |
| 729 | bool is_range, |
| 730 | uint32_t* args, |
| 731 | uint32_t register_index) { |
| 732 | HInstruction* length = GetIntConstant(number_of_vreg_arguments); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 733 | HInstruction* object = new (arena_) HNewArray(length, dex_pc, type_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 734 | current_block_->AddInstruction(object); |
| 735 | |
| 736 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 737 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 738 | char primitive = descriptor[1]; |
| 739 | DCHECK(primitive == 'I' |
| 740 | || primitive == 'L' |
| 741 | || primitive == '[') << descriptor; |
| 742 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 743 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 744 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 745 | Temporaries temps(graph_); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 746 | temps.Add(object); |
| 747 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 748 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
| 749 | HInstruction* index = GetIntConstant(i); |
| 750 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 751 | new (arena_) HArraySet(object, index, value, type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 752 | } |
| 753 | latest_result_ = object; |
| 754 | } |
| 755 | |
| 756 | template <typename T> |
| 757 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 758 | const T* data, |
| 759 | uint32_t element_count, |
| 760 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 761 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 762 | for (uint32_t i = 0; i < element_count; ++i) { |
| 763 | HInstruction* index = GetIntConstant(i); |
| 764 | HInstruction* value = GetIntConstant(data[i]); |
| 765 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 766 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 770 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 771 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 772 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 773 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 774 | current_block_->AddInstruction(null_check); |
| 775 | temps.Add(null_check); |
| 776 | |
| 777 | HInstruction* length = new (arena_) HArrayLength(null_check); |
| 778 | current_block_->AddInstruction(length); |
| 779 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 780 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 781 | const Instruction::ArrayDataPayload* payload = |
| 782 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 783 | const uint8_t* data = payload->data; |
| 784 | uint32_t element_count = payload->element_count; |
| 785 | |
| 786 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 787 | // done before doing any stores. |
| 788 | HInstruction* last_index = GetIntConstant(payload->element_count - 1); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 789 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 790 | |
| 791 | switch (payload->element_width) { |
| 792 | case 1: |
| 793 | BuildFillArrayData(null_check, |
| 794 | reinterpret_cast<const int8_t*>(data), |
| 795 | element_count, |
| 796 | Primitive::kPrimByte, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 797 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 798 | break; |
| 799 | case 2: |
| 800 | BuildFillArrayData(null_check, |
| 801 | reinterpret_cast<const int16_t*>(data), |
| 802 | element_count, |
| 803 | Primitive::kPrimShort, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 804 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 805 | break; |
| 806 | case 4: |
| 807 | BuildFillArrayData(null_check, |
| 808 | reinterpret_cast<const int32_t*>(data), |
| 809 | element_count, |
| 810 | Primitive::kPrimInt, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 811 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 812 | break; |
| 813 | case 8: |
| 814 | BuildFillWideArrayData(null_check, |
| 815 | reinterpret_cast<const int64_t*>(data), |
| 816 | element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 817 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 818 | break; |
| 819 | default: |
| 820 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 821 | } |
| 822 | } |
| 823 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 824 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 825 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 826 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 827 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 828 | for (uint32_t i = 0; i < element_count; ++i) { |
| 829 | HInstruction* index = GetIntConstant(i); |
| 830 | HInstruction* value = GetLongConstant(data[i]); |
| 831 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 832 | object, index, value, Primitive::kPrimLong, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 836 | bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
| 837 | uint8_t destination, |
| 838 | uint8_t reference, |
| 839 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 840 | uint32_t dex_pc) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 841 | bool type_known_final; |
| 842 | bool type_known_abstract; |
| 843 | bool is_referrers_class; |
| 844 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 845 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
| 846 | &type_known_final, &type_known_abstract, &is_referrers_class); |
| 847 | if (!can_access) { |
| 848 | return false; |
| 849 | } |
| 850 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 851 | HLoadClass* cls = new (arena_) HLoadClass(type_index, is_referrers_class, dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 852 | current_block_->AddInstruction(cls); |
| 853 | // The class needs a temporary before being used by the type check. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 854 | Temporaries temps(graph_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 855 | temps.Add(cls); |
| 856 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
| 857 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 858 | new (arena_) HInstanceOf(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 859 | UpdateLocal(destination, current_block_->GetLastInstruction()); |
| 860 | } else { |
| 861 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
| 862 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 863 | new (arena_) HCheckCast(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 864 | } |
| 865 | return true; |
| 866 | } |
| 867 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 868 | void HGraphBuilder::PotentiallyAddSuspendCheck(int32_t target_offset, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 869 | if (target_offset <= 0) { |
| 870 | // Unconditionnally add a suspend check to backward branches. We can remove |
| 871 | // them after we recognize loops in the graph. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 872 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc)); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 876 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 877 | if (current_block_ == nullptr) { |
| 878 | return true; // Dead code |
| 879 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 880 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 881 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 882 | case Instruction::CONST_4: { |
| 883 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 884 | HIntConstant* constant = GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 885 | UpdateLocal(register_index, constant); |
| 886 | break; |
| 887 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 888 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 889 | case Instruction::CONST_16: { |
| 890 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 891 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21s()); |
| 892 | UpdateLocal(register_index, constant); |
| 893 | break; |
| 894 | } |
| 895 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 896 | case Instruction::CONST: { |
| 897 | int32_t register_index = instruction.VRegA(); |
| 898 | HIntConstant* constant = GetIntConstant(instruction.VRegB_31i()); |
| 899 | UpdateLocal(register_index, constant); |
| 900 | break; |
| 901 | } |
| 902 | |
| 903 | case Instruction::CONST_HIGH16: { |
| 904 | int32_t register_index = instruction.VRegA(); |
| 905 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21h() << 16); |
| 906 | UpdateLocal(register_index, constant); |
| 907 | break; |
| 908 | } |
| 909 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 910 | case Instruction::CONST_WIDE_16: { |
| 911 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 912 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 913 | int64_t value = instruction.VRegB_21s(); |
| 914 | value <<= 48; |
| 915 | value >>= 48; |
| 916 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 917 | UpdateLocal(register_index, constant); |
| 918 | break; |
| 919 | } |
| 920 | |
| 921 | case Instruction::CONST_WIDE_32: { |
| 922 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 923 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 924 | int64_t value = instruction.VRegB_31i(); |
| 925 | value <<= 32; |
| 926 | value >>= 32; |
| 927 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 928 | UpdateLocal(register_index, constant); |
| 929 | break; |
| 930 | } |
| 931 | |
| 932 | case Instruction::CONST_WIDE: { |
| 933 | int32_t register_index = instruction.VRegA(); |
| 934 | HLongConstant* constant = GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 935 | UpdateLocal(register_index, constant); |
| 936 | break; |
| 937 | } |
| 938 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 939 | case Instruction::CONST_WIDE_HIGH16: { |
| 940 | int32_t register_index = instruction.VRegA(); |
| 941 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
| 942 | HLongConstant* constant = GetLongConstant(value); |
| 943 | UpdateLocal(register_index, constant); |
| 944 | break; |
| 945 | } |
| 946 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 947 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 948 | case Instruction::MOVE: |
| 949 | case Instruction::MOVE_FROM16: |
| 950 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 951 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 952 | UpdateLocal(instruction.VRegA(), value); |
| 953 | break; |
| 954 | } |
| 955 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 956 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 957 | case Instruction::MOVE_WIDE: |
| 958 | case Instruction::MOVE_WIDE_FROM16: |
| 959 | case Instruction::MOVE_WIDE_16: { |
| 960 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 961 | UpdateLocal(instruction.VRegA(), value); |
| 962 | break; |
| 963 | } |
| 964 | |
| 965 | case Instruction::MOVE_OBJECT: |
| 966 | case Instruction::MOVE_OBJECT_16: |
| 967 | case Instruction::MOVE_OBJECT_FROM16: { |
| 968 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 969 | UpdateLocal(instruction.VRegA(), value); |
| 970 | break; |
| 971 | } |
| 972 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 973 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 974 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 975 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 978 | #define IF_XX(comparison, cond) \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 979 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 980 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 981 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 982 | IF_XX(HEqual, EQ); |
| 983 | IF_XX(HNotEqual, NE); |
| 984 | IF_XX(HLessThan, LT); |
| 985 | IF_XX(HLessThanOrEqual, LE); |
| 986 | IF_XX(HGreaterThan, GT); |
| 987 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 988 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 989 | case Instruction::GOTO: |
| 990 | case Instruction::GOTO_16: |
| 991 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 992 | int32_t offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 993 | PotentiallyAddSuspendCheck(offset, dex_pc); |
| 994 | HBasicBlock* target = FindBlockStartingAt(offset + dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 995 | DCHECK(target != nullptr); |
| 996 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 997 | current_block_->AddSuccessor(target); |
| 998 | current_block_ = nullptr; |
| 999 | break; |
| 1000 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1001 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1002 | case Instruction::RETURN: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1003 | DCHECK_NE(return_type_, Primitive::kPrimNot); |
| 1004 | DCHECK_NE(return_type_, Primitive::kPrimLong); |
| 1005 | DCHECK_NE(return_type_, Primitive::kPrimDouble); |
| 1006 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1007 | break; |
| 1008 | } |
| 1009 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1010 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1011 | DCHECK(return_type_ == Primitive::kPrimNot); |
| 1012 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1013 | break; |
| 1014 | } |
| 1015 | |
| 1016 | case Instruction::RETURN_WIDE: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1017 | DCHECK(return_type_ == Primitive::kPrimDouble || return_type_ == Primitive::kPrimLong); |
| 1018 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1019 | break; |
| 1020 | } |
| 1021 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1022 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1023 | case Instruction::INVOKE_INTERFACE: |
| 1024 | case Instruction::INVOKE_STATIC: |
| 1025 | case Instruction::INVOKE_SUPER: |
| 1026 | case Instruction::INVOKE_VIRTUAL: { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1027 | uint32_t method_idx = instruction.VRegB_35c(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1028 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1029 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1030 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1031 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1032 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1033 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1034 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1035 | break; |
| 1036 | } |
| 1037 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1038 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1039 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 1040 | case Instruction::INVOKE_STATIC_RANGE: |
| 1041 | case Instruction::INVOKE_SUPER_RANGE: |
| 1042 | case Instruction::INVOKE_VIRTUAL_RANGE: { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1043 | uint32_t method_idx = instruction.VRegB_3rc(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1044 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1045 | uint32_t register_index = instruction.VRegC(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1046 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1047 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1048 | return false; |
| 1049 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1050 | break; |
| 1051 | } |
| 1052 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1053 | case Instruction::NEG_INT: { |
| 1054 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt); |
| 1055 | break; |
| 1056 | } |
| 1057 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1058 | case Instruction::NEG_LONG: { |
| 1059 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong); |
| 1060 | break; |
| 1061 | } |
| 1062 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1063 | case Instruction::NEG_FLOAT: { |
| 1064 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat); |
| 1065 | break; |
| 1066 | } |
| 1067 | |
| 1068 | case Instruction::NEG_DOUBLE: { |
| 1069 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble); |
| 1070 | break; |
| 1071 | } |
| 1072 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1073 | case Instruction::NOT_INT: { |
| 1074 | Unop_12x<HNot>(instruction, Primitive::kPrimInt); |
| 1075 | break; |
| 1076 | } |
| 1077 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1078 | case Instruction::NOT_LONG: { |
| 1079 | Unop_12x<HNot>(instruction, Primitive::kPrimLong); |
| 1080 | break; |
| 1081 | } |
| 1082 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1083 | case Instruction::INT_TO_LONG: { |
| 1084 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong); |
| 1085 | break; |
| 1086 | } |
| 1087 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1088 | case Instruction::INT_TO_FLOAT: { |
| 1089 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat); |
| 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | case Instruction::INT_TO_DOUBLE: { |
| 1094 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble); |
| 1095 | break; |
| 1096 | } |
| 1097 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1098 | case Instruction::LONG_TO_INT: { |
| 1099 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt); |
| 1100 | break; |
| 1101 | } |
| 1102 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1103 | case Instruction::LONG_TO_FLOAT: { |
| 1104 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat); |
| 1105 | break; |
| 1106 | } |
| 1107 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1108 | case Instruction::LONG_TO_DOUBLE: { |
| 1109 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble); |
| 1110 | break; |
| 1111 | } |
| 1112 | |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1113 | case Instruction::INT_TO_BYTE: { |
| 1114 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte); |
| 1115 | break; |
| 1116 | } |
| 1117 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1118 | case Instruction::INT_TO_SHORT: { |
| 1119 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort); |
| 1120 | break; |
| 1121 | } |
| 1122 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1123 | case Instruction::INT_TO_CHAR: { |
| 1124 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar); |
| 1125 | break; |
| 1126 | } |
| 1127 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1128 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1129 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1130 | break; |
| 1131 | } |
| 1132 | |
| 1133 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1134 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1135 | break; |
| 1136 | } |
| 1137 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1138 | case Instruction::ADD_DOUBLE: { |
| 1139 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1140 | break; |
| 1141 | } |
| 1142 | |
| 1143 | case Instruction::ADD_FLOAT: { |
| 1144 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1145 | break; |
| 1146 | } |
| 1147 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1148 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1149 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1150 | break; |
| 1151 | } |
| 1152 | |
| 1153 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1154 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1155 | break; |
| 1156 | } |
| 1157 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1158 | case Instruction::SUB_FLOAT: { |
| 1159 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat); |
| 1160 | break; |
| 1161 | } |
| 1162 | |
| 1163 | case Instruction::SUB_DOUBLE: { |
| 1164 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble); |
| 1165 | break; |
| 1166 | } |
| 1167 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1168 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1169 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 1170 | break; |
| 1171 | } |
| 1172 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1173 | case Instruction::MUL_INT: { |
| 1174 | Binop_23x<HMul>(instruction, Primitive::kPrimInt); |
| 1175 | break; |
| 1176 | } |
| 1177 | |
| 1178 | case Instruction::MUL_LONG: { |
| 1179 | Binop_23x<HMul>(instruction, Primitive::kPrimLong); |
| 1180 | break; |
| 1181 | } |
| 1182 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1183 | case Instruction::MUL_FLOAT: { |
| 1184 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat); |
| 1185 | break; |
| 1186 | } |
| 1187 | |
| 1188 | case Instruction::MUL_DOUBLE: { |
| 1189 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble); |
| 1190 | break; |
| 1191 | } |
| 1192 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1193 | case Instruction::DIV_INT: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1194 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1195 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1196 | break; |
| 1197 | } |
| 1198 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1199 | case Instruction::DIV_LONG: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1200 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1201 | dex_pc, Primitive::kPrimLong, false, true); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1202 | break; |
| 1203 | } |
| 1204 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1205 | case Instruction::DIV_FLOAT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1206 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1207 | break; |
| 1208 | } |
| 1209 | |
| 1210 | case Instruction::DIV_DOUBLE: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1211 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1212 | break; |
| 1213 | } |
| 1214 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1215 | case Instruction::REM_INT: { |
| 1216 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1217 | dex_pc, Primitive::kPrimInt, false, false); |
| 1218 | break; |
| 1219 | } |
| 1220 | |
| 1221 | case Instruction::REM_LONG: { |
| 1222 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1223 | dex_pc, Primitive::kPrimLong, false, false); |
| 1224 | break; |
| 1225 | } |
| 1226 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1227 | case Instruction::AND_INT: { |
| 1228 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt); |
| 1229 | break; |
| 1230 | } |
| 1231 | |
| 1232 | case Instruction::AND_LONG: { |
| 1233 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong); |
| 1234 | break; |
| 1235 | } |
| 1236 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1237 | case Instruction::SHL_INT: { |
| 1238 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 1239 | break; |
| 1240 | } |
| 1241 | |
| 1242 | case Instruction::SHL_LONG: { |
| 1243 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 1244 | break; |
| 1245 | } |
| 1246 | |
| 1247 | case Instruction::SHR_INT: { |
| 1248 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 1249 | break; |
| 1250 | } |
| 1251 | |
| 1252 | case Instruction::SHR_LONG: { |
| 1253 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 1254 | break; |
| 1255 | } |
| 1256 | |
| 1257 | case Instruction::USHR_INT: { |
| 1258 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 1259 | break; |
| 1260 | } |
| 1261 | |
| 1262 | case Instruction::USHR_LONG: { |
| 1263 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 1264 | break; |
| 1265 | } |
| 1266 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1267 | case Instruction::OR_INT: { |
| 1268 | Binop_23x<HOr>(instruction, Primitive::kPrimInt); |
| 1269 | break; |
| 1270 | } |
| 1271 | |
| 1272 | case Instruction::OR_LONG: { |
| 1273 | Binop_23x<HOr>(instruction, Primitive::kPrimLong); |
| 1274 | break; |
| 1275 | } |
| 1276 | |
| 1277 | case Instruction::XOR_INT: { |
| 1278 | Binop_23x<HXor>(instruction, Primitive::kPrimInt); |
| 1279 | break; |
| 1280 | } |
| 1281 | |
| 1282 | case Instruction::XOR_LONG: { |
| 1283 | Binop_23x<HXor>(instruction, Primitive::kPrimLong); |
| 1284 | break; |
| 1285 | } |
| 1286 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1287 | case Instruction::ADD_LONG_2ADDR: { |
| 1288 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1289 | break; |
| 1290 | } |
| 1291 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1292 | case Instruction::ADD_DOUBLE_2ADDR: { |
| 1293 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1294 | break; |
| 1295 | } |
| 1296 | |
| 1297 | case Instruction::ADD_FLOAT_2ADDR: { |
| 1298 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1299 | break; |
| 1300 | } |
| 1301 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1302 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1303 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 1304 | break; |
| 1305 | } |
| 1306 | |
| 1307 | case Instruction::SUB_LONG_2ADDR: { |
| 1308 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1309 | break; |
| 1310 | } |
| 1311 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1312 | case Instruction::SUB_FLOAT_2ADDR: { |
| 1313 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat); |
| 1314 | break; |
| 1315 | } |
| 1316 | |
| 1317 | case Instruction::SUB_DOUBLE_2ADDR: { |
| 1318 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble); |
| 1319 | break; |
| 1320 | } |
| 1321 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1322 | case Instruction::MUL_INT_2ADDR: { |
| 1323 | Binop_12x<HMul>(instruction, Primitive::kPrimInt); |
| 1324 | break; |
| 1325 | } |
| 1326 | |
| 1327 | case Instruction::MUL_LONG_2ADDR: { |
| 1328 | Binop_12x<HMul>(instruction, Primitive::kPrimLong); |
| 1329 | break; |
| 1330 | } |
| 1331 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1332 | case Instruction::MUL_FLOAT_2ADDR: { |
| 1333 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat); |
| 1334 | break; |
| 1335 | } |
| 1336 | |
| 1337 | case Instruction::MUL_DOUBLE_2ADDR: { |
| 1338 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble); |
| 1339 | break; |
| 1340 | } |
| 1341 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1342 | case Instruction::DIV_INT_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1343 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1344 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1345 | break; |
| 1346 | } |
| 1347 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1348 | case Instruction::DIV_LONG_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1349 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1350 | dex_pc, Primitive::kPrimLong, false, true); |
| 1351 | break; |
| 1352 | } |
| 1353 | |
| 1354 | case Instruction::REM_INT_2ADDR: { |
| 1355 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1356 | dex_pc, Primitive::kPrimInt, false, false); |
| 1357 | break; |
| 1358 | } |
| 1359 | |
| 1360 | case Instruction::REM_LONG_2ADDR: { |
| 1361 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1362 | dex_pc, Primitive::kPrimLong, false, false); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1363 | break; |
| 1364 | } |
| 1365 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1366 | case Instruction::SHL_INT_2ADDR: { |
| 1367 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 1368 | break; |
| 1369 | } |
| 1370 | |
| 1371 | case Instruction::SHL_LONG_2ADDR: { |
| 1372 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 1373 | break; |
| 1374 | } |
| 1375 | |
| 1376 | case Instruction::SHR_INT_2ADDR: { |
| 1377 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 1378 | break; |
| 1379 | } |
| 1380 | |
| 1381 | case Instruction::SHR_LONG_2ADDR: { |
| 1382 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 1383 | break; |
| 1384 | } |
| 1385 | |
| 1386 | case Instruction::USHR_INT_2ADDR: { |
| 1387 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 1388 | break; |
| 1389 | } |
| 1390 | |
| 1391 | case Instruction::USHR_LONG_2ADDR: { |
| 1392 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 1393 | break; |
| 1394 | } |
| 1395 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1396 | case Instruction::DIV_FLOAT_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1397 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1398 | break; |
| 1399 | } |
| 1400 | |
| 1401 | case Instruction::DIV_DOUBLE_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1402 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1403 | break; |
| 1404 | } |
| 1405 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1406 | case Instruction::AND_INT_2ADDR: { |
| 1407 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt); |
| 1408 | break; |
| 1409 | } |
| 1410 | |
| 1411 | case Instruction::AND_LONG_2ADDR: { |
| 1412 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong); |
| 1413 | break; |
| 1414 | } |
| 1415 | |
| 1416 | case Instruction::OR_INT_2ADDR: { |
| 1417 | Binop_12x<HOr>(instruction, Primitive::kPrimInt); |
| 1418 | break; |
| 1419 | } |
| 1420 | |
| 1421 | case Instruction::OR_LONG_2ADDR: { |
| 1422 | Binop_12x<HOr>(instruction, Primitive::kPrimLong); |
| 1423 | break; |
| 1424 | } |
| 1425 | |
| 1426 | case Instruction::XOR_INT_2ADDR: { |
| 1427 | Binop_12x<HXor>(instruction, Primitive::kPrimInt); |
| 1428 | break; |
| 1429 | } |
| 1430 | |
| 1431 | case Instruction::XOR_LONG_2ADDR: { |
| 1432 | Binop_12x<HXor>(instruction, Primitive::kPrimLong); |
| 1433 | break; |
| 1434 | } |
| 1435 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1436 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1437 | Binop_22s<HAdd>(instruction, false); |
| 1438 | break; |
| 1439 | } |
| 1440 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1441 | case Instruction::AND_INT_LIT16: { |
| 1442 | Binop_22s<HAnd>(instruction, false); |
| 1443 | break; |
| 1444 | } |
| 1445 | |
| 1446 | case Instruction::OR_INT_LIT16: { |
| 1447 | Binop_22s<HOr>(instruction, false); |
| 1448 | break; |
| 1449 | } |
| 1450 | |
| 1451 | case Instruction::XOR_INT_LIT16: { |
| 1452 | Binop_22s<HXor>(instruction, false); |
| 1453 | break; |
| 1454 | } |
| 1455 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1456 | case Instruction::RSUB_INT: { |
| 1457 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1458 | break; |
| 1459 | } |
| 1460 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1461 | case Instruction::MUL_INT_LIT16: { |
| 1462 | Binop_22s<HMul>(instruction, false); |
| 1463 | break; |
| 1464 | } |
| 1465 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1466 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1467 | Binop_22b<HAdd>(instruction, false); |
| 1468 | break; |
| 1469 | } |
| 1470 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1471 | case Instruction::AND_INT_LIT8: { |
| 1472 | Binop_22b<HAnd>(instruction, false); |
| 1473 | break; |
| 1474 | } |
| 1475 | |
| 1476 | case Instruction::OR_INT_LIT8: { |
| 1477 | Binop_22b<HOr>(instruction, false); |
| 1478 | break; |
| 1479 | } |
| 1480 | |
| 1481 | case Instruction::XOR_INT_LIT8: { |
| 1482 | Binop_22b<HXor>(instruction, false); |
| 1483 | break; |
| 1484 | } |
| 1485 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1486 | case Instruction::RSUB_INT_LIT8: { |
| 1487 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1488 | break; |
| 1489 | } |
| 1490 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1491 | case Instruction::MUL_INT_LIT8: { |
| 1492 | Binop_22b<HMul>(instruction, false); |
| 1493 | break; |
| 1494 | } |
| 1495 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1496 | case Instruction::DIV_INT_LIT16: |
| 1497 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1498 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1499 | dex_pc, Primitive::kPrimInt, true, true); |
| 1500 | break; |
| 1501 | } |
| 1502 | |
| 1503 | case Instruction::REM_INT_LIT16: |
| 1504 | case Instruction::REM_INT_LIT8: { |
| 1505 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1506 | dex_pc, Primitive::kPrimInt, true, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1507 | break; |
| 1508 | } |
| 1509 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1510 | case Instruction::SHL_INT_LIT8: { |
| 1511 | Binop_22b<HShl>(instruction, false); |
| 1512 | break; |
| 1513 | } |
| 1514 | |
| 1515 | case Instruction::SHR_INT_LIT8: { |
| 1516 | Binop_22b<HShr>(instruction, false); |
| 1517 | break; |
| 1518 | } |
| 1519 | |
| 1520 | case Instruction::USHR_INT_LIT8: { |
| 1521 | Binop_22b<HUShr>(instruction, false); |
| 1522 | break; |
| 1523 | } |
| 1524 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1525 | case Instruction::NEW_INSTANCE: { |
| 1526 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1527 | new (arena_) HNewInstance(dex_pc, instruction.VRegB_21c())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1528 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 1529 | break; |
| 1530 | } |
| 1531 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1532 | case Instruction::NEW_ARRAY: { |
| 1533 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt); |
| 1534 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1535 | new (arena_) HNewArray(length, dex_pc, instruction.VRegC_22c())); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1536 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 1537 | break; |
| 1538 | } |
| 1539 | |
| 1540 | case Instruction::FILLED_NEW_ARRAY: { |
| 1541 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 1542 | uint32_t type_index = instruction.VRegB_35c(); |
| 1543 | uint32_t args[5]; |
| 1544 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1545 | BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1546 | break; |
| 1547 | } |
| 1548 | |
| 1549 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 1550 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1551 | uint32_t type_index = instruction.VRegB_3rc(); |
| 1552 | uint32_t register_index = instruction.VRegC_3rc(); |
| 1553 | BuildFilledNewArray( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1554 | dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1555 | break; |
| 1556 | } |
| 1557 | |
| 1558 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1559 | BuildFillArrayData(instruction, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1560 | break; |
| 1561 | } |
| 1562 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1563 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1564 | case Instruction::MOVE_RESULT_WIDE: |
| 1565 | case Instruction::MOVE_RESULT_OBJECT: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1566 | UpdateLocal(instruction.VRegA(), latest_result_); |
| 1567 | latest_result_ = nullptr; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1568 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1569 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1570 | case Instruction::CMP_LONG: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1571 | Binop_23x_cmp(instruction, Primitive::kPrimLong, HCompare::kNoBias); |
| 1572 | break; |
| 1573 | } |
| 1574 | |
| 1575 | case Instruction::CMPG_FLOAT: { |
| 1576 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, HCompare::kGtBias); |
| 1577 | break; |
| 1578 | } |
| 1579 | |
| 1580 | case Instruction::CMPG_DOUBLE: { |
| 1581 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, HCompare::kGtBias); |
| 1582 | break; |
| 1583 | } |
| 1584 | |
| 1585 | case Instruction::CMPL_FLOAT: { |
| 1586 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, HCompare::kLtBias); |
| 1587 | break; |
| 1588 | } |
| 1589 | |
| 1590 | case Instruction::CMPL_DOUBLE: { |
| 1591 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, HCompare::kLtBias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1592 | break; |
| 1593 | } |
| 1594 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1595 | case Instruction::NOP: |
| 1596 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1597 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1598 | case Instruction::IGET: |
| 1599 | case Instruction::IGET_WIDE: |
| 1600 | case Instruction::IGET_OBJECT: |
| 1601 | case Instruction::IGET_BOOLEAN: |
| 1602 | case Instruction::IGET_BYTE: |
| 1603 | case Instruction::IGET_CHAR: |
| 1604 | case Instruction::IGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1605 | if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1606 | return false; |
| 1607 | } |
| 1608 | break; |
| 1609 | } |
| 1610 | |
| 1611 | case Instruction::IPUT: |
| 1612 | case Instruction::IPUT_WIDE: |
| 1613 | case Instruction::IPUT_OBJECT: |
| 1614 | case Instruction::IPUT_BOOLEAN: |
| 1615 | case Instruction::IPUT_BYTE: |
| 1616 | case Instruction::IPUT_CHAR: |
| 1617 | case Instruction::IPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1618 | if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1619 | return false; |
| 1620 | } |
| 1621 | break; |
| 1622 | } |
| 1623 | |
| 1624 | case Instruction::SGET: |
| 1625 | case Instruction::SGET_WIDE: |
| 1626 | case Instruction::SGET_OBJECT: |
| 1627 | case Instruction::SGET_BOOLEAN: |
| 1628 | case Instruction::SGET_BYTE: |
| 1629 | case Instruction::SGET_CHAR: |
| 1630 | case Instruction::SGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1631 | if (!BuildStaticFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1632 | return false; |
| 1633 | } |
| 1634 | break; |
| 1635 | } |
| 1636 | |
| 1637 | case Instruction::SPUT: |
| 1638 | case Instruction::SPUT_WIDE: |
| 1639 | case Instruction::SPUT_OBJECT: |
| 1640 | case Instruction::SPUT_BOOLEAN: |
| 1641 | case Instruction::SPUT_BYTE: |
| 1642 | case Instruction::SPUT_CHAR: |
| 1643 | case Instruction::SPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1644 | if (!BuildStaticFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1645 | return false; |
| 1646 | } |
| 1647 | break; |
| 1648 | } |
| 1649 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1650 | #define ARRAY_XX(kind, anticipated_type) \ |
| 1651 | case Instruction::AGET##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1652 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1653 | break; \ |
| 1654 | } \ |
| 1655 | case Instruction::APUT##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1656 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1657 | break; \ |
| 1658 | } |
| 1659 | |
| 1660 | ARRAY_XX(, Primitive::kPrimInt); |
| 1661 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 1662 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 1663 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 1664 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 1665 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 1666 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 1667 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1668 | case Instruction::ARRAY_LENGTH: { |
| 1669 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1670 | // No need for a temporary for the null check, it is the only input of the following |
| 1671 | // instruction. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1672 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1673 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1674 | current_block_->AddInstruction(new (arena_) HArrayLength(object)); |
| 1675 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 1676 | break; |
| 1677 | } |
| 1678 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1679 | case Instruction::CONST_STRING: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1680 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_21c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1681 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 1682 | break; |
| 1683 | } |
| 1684 | |
| 1685 | case Instruction::CONST_STRING_JUMBO: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1686 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_31c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1687 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 1688 | break; |
| 1689 | } |
| 1690 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 1691 | case Instruction::CONST_CLASS: { |
| 1692 | uint16_t type_index = instruction.VRegB_21c(); |
| 1693 | bool type_known_final; |
| 1694 | bool type_known_abstract; |
| 1695 | bool is_referrers_class; |
| 1696 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1697 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
| 1698 | &type_known_final, &type_known_abstract, &is_referrers_class); |
| 1699 | if (!can_access) { |
| 1700 | return false; |
| 1701 | } |
| 1702 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1703 | new (arena_) HLoadClass(type_index, is_referrers_class, dex_pc)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 1704 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 1705 | break; |
| 1706 | } |
| 1707 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1708 | case Instruction::MOVE_EXCEPTION: { |
| 1709 | current_block_->AddInstruction(new (arena_) HLoadException()); |
| 1710 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
| 1711 | break; |
| 1712 | } |
| 1713 | |
| 1714 | case Instruction::THROW: { |
| 1715 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1716 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1717 | // A throw instruction must branch to the exit block. |
| 1718 | current_block_->AddSuccessor(exit_block_); |
| 1719 | // We finished building this block. Set the current block to null to avoid |
| 1720 | // adding dead instructions to it. |
| 1721 | current_block_ = nullptr; |
| 1722 | break; |
| 1723 | } |
| 1724 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1725 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1726 | uint8_t destination = instruction.VRegA_22c(); |
| 1727 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1728 | uint16_t type_index = instruction.VRegC_22c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1729 | if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1730 | return false; |
| 1731 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1732 | break; |
| 1733 | } |
| 1734 | |
| 1735 | case Instruction::CHECK_CAST: { |
| 1736 | uint8_t reference = instruction.VRegA_21c(); |
| 1737 | uint16_t type_index = instruction.VRegB_21c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1738 | if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1739 | return false; |
| 1740 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1741 | break; |
| 1742 | } |
| 1743 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1744 | case Instruction::MONITOR_ENTER: { |
| 1745 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 1746 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 1747 | HMonitorOperation::kEnter, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1748 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1749 | break; |
| 1750 | } |
| 1751 | |
| 1752 | case Instruction::MONITOR_EXIT: { |
| 1753 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 1754 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 1755 | HMonitorOperation::kExit, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1756 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1757 | break; |
| 1758 | } |
| 1759 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1760 | default: |
| 1761 | return false; |
| 1762 | } |
| 1763 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1764 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1765 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1766 | HIntConstant* HGraphBuilder::GetIntConstant0() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1767 | if (constant0_ != nullptr) { |
| 1768 | return constant0_; |
| 1769 | } |
| 1770 | constant0_ = new(arena_) HIntConstant(0); |
| 1771 | entry_block_->AddInstruction(constant0_); |
| 1772 | return constant0_; |
| 1773 | } |
| 1774 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1775 | HIntConstant* HGraphBuilder::GetIntConstant1() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1776 | if (constant1_ != nullptr) { |
| 1777 | return constant1_; |
| 1778 | } |
| 1779 | constant1_ = new(arena_) HIntConstant(1); |
| 1780 | entry_block_->AddInstruction(constant1_); |
| 1781 | return constant1_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1784 | HIntConstant* HGraphBuilder::GetIntConstant(int32_t constant) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1785 | switch (constant) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1786 | case 0: return GetIntConstant0(); |
| 1787 | case 1: return GetIntConstant1(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1788 | default: { |
| 1789 | HIntConstant* instruction = new (arena_) HIntConstant(constant); |
| 1790 | entry_block_->AddInstruction(instruction); |
| 1791 | return instruction; |
| 1792 | } |
| 1793 | } |
| 1794 | } |
| 1795 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1796 | HLongConstant* HGraphBuilder::GetLongConstant(int64_t constant) { |
| 1797 | HLongConstant* instruction = new (arena_) HLongConstant(constant); |
| 1798 | entry_block_->AddInstruction(instruction); |
| 1799 | return instruction; |
| 1800 | } |
| 1801 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1802 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 1803 | return locals_.Get(register_index); |
| 1804 | } |
| 1805 | |
| 1806 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 1807 | HLocal* local = GetLocalAt(register_index); |
| 1808 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 1809 | } |
| 1810 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1811 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1812 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1813 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1814 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1817 | } // namespace art |