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