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