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