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: |
| 44 | Temporaries(HGraph* graph, size_t count) : graph_(graph), count_(count), index_(0) { |
| 45 | graph_->UpdateNumberOfTemporaries(count_); |
| 46 | } |
| 47 | |
| 48 | void Add(HInstruction* instruction) { |
| 49 | // We currently only support vreg size temps. |
| 50 | DCHECK(instruction->GetType() != Primitive::kPrimLong |
| 51 | && instruction->GetType() != Primitive::kPrimDouble); |
| 52 | HInstruction* temp = new (graph_->GetArena()) HTemporary(index_++); |
| 53 | instruction->GetBlock()->AddInstruction(temp); |
| 54 | DCHECK(temp->GetPrevious() == instruction); |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | HGraph* const graph_; |
| 59 | |
| 60 | // The total number of temporaries that will be used. |
| 61 | const size_t count_; |
| 62 | |
| 63 | // Current index in the temporary stack, updated by `Add`. |
| 64 | size_t index_; |
| 65 | }; |
| 66 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 67 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 68 | graph_->SetNumberOfVRegs(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 69 | locals_.SetSize(count); |
| 70 | for (int i = 0; i < count; i++) { |
| 71 | HLocal* local = new (arena_) HLocal(i); |
| 72 | entry_block_->AddInstruction(local); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 73 | locals_.Put(i, local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 77 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 78 | // dex_compilation_unit_ is null only when unit testing. |
| 79 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 80 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 84 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 85 | int locals_index = locals_.Size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 86 | int parameter_index = 0; |
| 87 | |
| 88 | if (!dex_compilation_unit_->IsStatic()) { |
| 89 | // Add the implicit 'this' argument, not expressed in the signature. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 90 | HParameterValue* parameter = |
| 91 | new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 92 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 93 | HLocal* local = GetLocalAt(locals_index++); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 94 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 95 | number_of_parameters--; |
| 96 | } |
| 97 | |
| 98 | uint32_t pos = 1; |
| 99 | for (int i = 0; i < number_of_parameters; i++) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 100 | HParameterValue* parameter = |
| 101 | new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++])); |
| 102 | entry_block_->AddInstruction(parameter); |
| 103 | HLocal* local = GetLocalAt(locals_index++); |
| 104 | // Store the parameter value in the local that the dex code will use |
| 105 | // to reference that parameter. |
| 106 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
| 107 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 108 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 109 | if (is_wide) { |
| 110 | i++; |
| 111 | locals_index++; |
| 112 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 113 | } |
| 114 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 115 | } |
| 116 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 117 | template<typename T> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 118 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 119 | int32_t target_offset = instruction.GetTargetOffset(); |
| 120 | PotentiallyAddSuspendCheck(target_offset, dex_offset); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 121 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 122 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 123 | T* comparison = new (arena_) T(first, second); |
| 124 | current_block_->AddInstruction(comparison); |
| 125 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 126 | current_block_->AddInstruction(ifinst); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 127 | HBasicBlock* target = FindBlockStartingAt(dex_offset + target_offset); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 128 | DCHECK(target != nullptr); |
| 129 | current_block_->AddSuccessor(target); |
| 130 | target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits()); |
| 131 | DCHECK(target != nullptr); |
| 132 | current_block_->AddSuccessor(target); |
| 133 | current_block_ = nullptr; |
| 134 | } |
| 135 | |
| 136 | template<typename T> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 137 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | int32_t target_offset = instruction.GetTargetOffset(); |
| 139 | PotentiallyAddSuspendCheck(target_offset, dex_offset); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 140 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 141 | T* comparison = new (arena_) T(value, GetIntConstant(0)); |
| 142 | current_block_->AddInstruction(comparison); |
| 143 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 144 | current_block_->AddInstruction(ifinst); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | HBasicBlock* target = FindBlockStartingAt(dex_offset + target_offset); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 146 | DCHECK(target != nullptr); |
| 147 | current_block_->AddSuccessor(target); |
| 148 | target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits()); |
| 149 | DCHECK(target != nullptr); |
| 150 | current_block_->AddSuccessor(target); |
| 151 | current_block_ = nullptr; |
| 152 | } |
| 153 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 154 | HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 155 | const uint16_t* code_ptr = code_item.insns_; |
| 156 | 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] | 157 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 158 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 159 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 160 | graph_ = new (arena_) HGraph(arena_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 161 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 162 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 163 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 164 | graph_->SetEntryBlock(entry_block_); |
| 165 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 166 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 167 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 168 | graph_->UpdateMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 169 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 170 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 171 | // start a new block, and create these blocks. |
| 172 | ComputeBranchTargets(code_ptr, code_end); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 173 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 174 | // Also create blocks for catch handlers. |
| 175 | if (code_item.tries_size_ != 0) { |
| 176 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0); |
| 177 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 178 | for (uint32_t idx = 0; idx < handlers_size; ++idx) { |
| 179 | CatchHandlerIterator iterator(handlers_ptr); |
| 180 | for (; iterator.HasNext(); iterator.Next()) { |
| 181 | uint32_t address = iterator.GetHandlerAddress(); |
| 182 | HBasicBlock* block = FindBlockStartingAt(address); |
| 183 | if (block == nullptr) { |
| 184 | block = new (arena_) HBasicBlock(graph_, address); |
| 185 | branch_targets_.Put(address, block); |
| 186 | } |
| 187 | block->SetIsCatchBlock(); |
| 188 | } |
| 189 | handlers_ptr = iterator.EndDataPointer(); |
| 190 | } |
| 191 | } |
| 192 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 193 | InitializeParameters(code_item.ins_size_); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 194 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 195 | size_t dex_offset = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 196 | while (code_ptr < code_end) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 197 | // Update the current block if dex_offset starts a new block. |
| 198 | MaybeUpdateCurrentBlock(dex_offset); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 199 | const Instruction& instruction = *Instruction::At(code_ptr); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 200 | if (!AnalyzeDexInstruction(instruction, dex_offset)) return nullptr; |
| 201 | dex_offset += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 202 | code_ptr += instruction.SizeInCodeUnits(); |
| 203 | } |
| 204 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 205 | // 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] | 206 | graph_->AddBlock(exit_block_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 207 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 208 | // Add the suspend check to the entry block. |
| 209 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 210 | entry_block_->AddInstruction(new (arena_) HGoto()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 211 | return graph_; |
| 212 | } |
| 213 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 214 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) { |
| 215 | HBasicBlock* block = FindBlockStartingAt(index); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 216 | if (block == nullptr) { |
| 217 | return; |
| 218 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 219 | |
| 220 | if (current_block_ != nullptr) { |
| 221 | // Branching instructions clear current_block, so we know |
| 222 | // the last instruction of the current block is not a branching |
| 223 | // instruction. We add an unconditional goto to the found block. |
| 224 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 225 | current_block_->AddSuccessor(block); |
| 226 | } |
| 227 | graph_->AddBlock(block); |
| 228 | current_block_ = block; |
| 229 | } |
| 230 | |
| 231 | void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, const uint16_t* code_end) { |
| 232 | // TODO: Support switch instructions. |
| 233 | branch_targets_.SetSize(code_end - code_ptr); |
| 234 | |
| 235 | // 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] | 236 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 237 | branch_targets_.Put(0, block); |
| 238 | entry_block_->AddSuccessor(block); |
| 239 | |
| 240 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 241 | // the locations these instructions branch to. |
| 242 | size_t dex_offset = 0; |
| 243 | while (code_ptr < code_end) { |
| 244 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 245 | if (instruction.IsBranch()) { |
| 246 | int32_t target = instruction.GetTargetOffset() + dex_offset; |
| 247 | // Create a block for the target instruction. |
| 248 | if (FindBlockStartingAt(target) == nullptr) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 249 | block = new (arena_) HBasicBlock(graph_, target); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 250 | branch_targets_.Put(target, block); |
| 251 | } |
| 252 | dex_offset += instruction.SizeInCodeUnits(); |
| 253 | code_ptr += instruction.SizeInCodeUnits(); |
| 254 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_offset) == nullptr)) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 255 | block = new (arena_) HBasicBlock(graph_, dex_offset); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 256 | branch_targets_.Put(dex_offset, block); |
| 257 | } |
| 258 | } else { |
| 259 | code_ptr += instruction.SizeInCodeUnits(); |
| 260 | dex_offset += instruction.SizeInCodeUnits(); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const { |
| 266 | DCHECK_GE(index, 0); |
| 267 | return branch_targets_.Get(index); |
| 268 | } |
| 269 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 270 | template<typename T> |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 271 | void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) { |
| 272 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 273 | current_block_->AddInstruction(new (arena_) T(type, first)); |
| 274 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 275 | } |
| 276 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 277 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 278 | Primitive::Type input_type, |
| 279 | Primitive::Type result_type) { |
| 280 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type); |
| 281 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first)); |
| 282 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 283 | } |
| 284 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 285 | template<typename T> |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 286 | void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 287 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 288 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 289 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 290 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 291 | } |
| 292 | |
| 293 | template<typename T> |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 294 | void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) { |
| 295 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 296 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 297 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 298 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 299 | } |
| 300 | |
| 301 | template<typename T> |
| 302 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 303 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 304 | HInstruction* second = GetIntConstant(instruction.VRegC_22s()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 305 | if (reverse) { |
| 306 | std::swap(first, second); |
| 307 | } |
| 308 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 309 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 310 | } |
| 311 | |
| 312 | template<typename T> |
| 313 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 314 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 315 | HInstruction* second = GetIntConstant(instruction.VRegC_22b()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 316 | if (reverse) { |
| 317 | std::swap(first, second); |
| 318 | } |
| 319 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 320 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 321 | } |
| 322 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 323 | void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) { |
| 324 | if (type == Primitive::kPrimVoid) { |
| 325 | current_block_->AddInstruction(new (arena_) HReturnVoid()); |
| 326 | } else { |
| 327 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
| 328 | current_block_->AddInstruction(new (arena_) HReturn(value)); |
| 329 | } |
| 330 | current_block_->AddSuccessor(exit_block_); |
| 331 | current_block_ = nullptr; |
| 332 | } |
| 333 | |
| 334 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
| 335 | uint32_t dex_offset, |
| 336 | uint32_t method_idx, |
| 337 | uint32_t number_of_vreg_arguments, |
| 338 | bool is_range, |
| 339 | uint32_t* args, |
| 340 | uint32_t register_index) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 341 | Instruction::Code opcode = instruction.Opcode(); |
| 342 | InvokeType invoke_type; |
| 343 | switch (opcode) { |
| 344 | case Instruction::INVOKE_STATIC: |
| 345 | case Instruction::INVOKE_STATIC_RANGE: |
| 346 | invoke_type = kStatic; |
| 347 | break; |
| 348 | case Instruction::INVOKE_DIRECT: |
| 349 | case Instruction::INVOKE_DIRECT_RANGE: |
| 350 | invoke_type = kDirect; |
| 351 | break; |
| 352 | case Instruction::INVOKE_VIRTUAL: |
| 353 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 354 | invoke_type = kVirtual; |
| 355 | break; |
| 356 | case Instruction::INVOKE_INTERFACE: |
| 357 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 358 | invoke_type = kInterface; |
| 359 | break; |
| 360 | case Instruction::INVOKE_SUPER_RANGE: |
| 361 | case Instruction::INVOKE_SUPER: |
| 362 | invoke_type = kSuper; |
| 363 | break; |
| 364 | default: |
| 365 | LOG(FATAL) << "Unexpected invoke op: " << opcode; |
| 366 | return false; |
| 367 | } |
| 368 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 369 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 370 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 371 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 372 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 373 | bool is_instance_call = invoke_type != kStatic; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 374 | const size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1); |
| 375 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 376 | HInvoke* invoke = nullptr; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 377 | if (invoke_type == kVirtual || invoke_type == kInterface) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 378 | MethodReference target_method(dex_file_, method_idx); |
| 379 | uintptr_t direct_code; |
| 380 | uintptr_t direct_method; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 381 | int table_index; |
| 382 | InvokeType optimized_invoke_type = invoke_type; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 383 | // TODO: Add devirtualization support. |
| 384 | compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_offset, true, true, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 385 | &optimized_invoke_type, &target_method, &table_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 386 | &direct_code, &direct_method); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 387 | if (table_index == -1) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 388 | return false; |
| 389 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 390 | |
| 391 | if (invoke_type == kVirtual) { |
| 392 | invoke = new (arena_) HInvokeVirtual( |
| 393 | arena_, number_of_arguments, return_type, dex_offset, table_index); |
| 394 | } else { |
| 395 | DCHECK_EQ(invoke_type, kInterface); |
| 396 | invoke = new (arena_) HInvokeInterface( |
| 397 | arena_, number_of_arguments, return_type, dex_offset, method_idx, table_index); |
| 398 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 399 | } else { |
| 400 | // Treat invoke-direct like static calls for now. |
| 401 | invoke = new (arena_) HInvokeStatic( |
| 402 | arena_, number_of_arguments, return_type, dex_offset, method_idx); |
| 403 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 404 | |
| 405 | size_t start_index = 0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 406 | Temporaries temps(graph_, is_instance_call ? 1 : 0); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 407 | if (is_instance_call) { |
| 408 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 409 | HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_offset); |
| 410 | current_block_->AddInstruction(null_check); |
| 411 | temps.Add(null_check); |
| 412 | invoke->SetArgumentAt(0, null_check); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 413 | start_index = 1; |
| 414 | } |
| 415 | |
| 416 | uint32_t descriptor_index = 1; |
| 417 | uint32_t argument_index = start_index; |
| 418 | for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) { |
| 419 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 420 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
| 421 | if (!is_range && is_wide && args[i] + 1 != args[i + 1]) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 422 | LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol() |
| 423 | << " at " << dex_offset; |
| 424 | // We do not implement non sequential register pair. |
| 425 | return false; |
| 426 | } |
| 427 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 428 | invoke->SetArgumentAt(argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 429 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 430 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
| 434 | DCHECK_EQ(argument_index, number_of_arguments); |
| 435 | current_block_->AddInstruction(invoke); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 436 | latest_result_ = invoke; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 437 | return true; |
| 438 | } |
| 439 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 440 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
| 441 | uint32_t dex_offset, |
| 442 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 443 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 444 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 445 | uint16_t field_index = instruction.VRegC_22c(); |
| 446 | |
| 447 | ScopedObjectAccess soa(Thread::Current()); |
| 448 | StackHandleScope<1> hs(soa.Self()); |
| 449 | Handle<mirror::ArtField> resolved_field(hs.NewHandle( |
| 450 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa))); |
| 451 | |
| 452 | if (resolved_field.Get() == nullptr) { |
| 453 | return false; |
| 454 | } |
| 455 | if (resolved_field->IsVolatile()) { |
| 456 | return false; |
| 457 | } |
| 458 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 459 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 460 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 461 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
| 462 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_offset)); |
| 463 | if (is_put) { |
| 464 | Temporaries temps(graph_, 1); |
| 465 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 466 | // We need one temporary for the null check. |
| 467 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 468 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 469 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 470 | null_check, |
| 471 | value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 472 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 473 | resolved_field->GetOffset())); |
| 474 | } else { |
| 475 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 476 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 477 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 478 | resolved_field->GetOffset())); |
| 479 | |
| 480 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 481 | } |
| 482 | return true; |
| 483 | } |
| 484 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 485 | |
| 486 | |
| 487 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
| 488 | uint32_t dex_offset, |
| 489 | bool is_put) { |
| 490 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 491 | uint16_t field_index = instruction.VRegB_21c(); |
| 492 | |
| 493 | uint32_t storage_index; |
| 494 | bool is_referrers_class; |
| 495 | bool is_initialized; |
| 496 | bool is_volatile; |
| 497 | MemberOffset field_offset(0u); |
| 498 | Primitive::Type field_type; |
| 499 | |
| 500 | bool fast_path = compiler_driver_->ComputeStaticFieldInfo(field_index, |
| 501 | dex_compilation_unit_, |
| 502 | is_put, |
| 503 | &field_offset, |
| 504 | &storage_index, |
| 505 | &is_referrers_class, |
| 506 | &is_volatile, |
| 507 | &is_initialized, |
| 508 | &field_type); |
| 509 | if (!fast_path) { |
| 510 | return false; |
| 511 | } |
| 512 | |
| 513 | if (is_volatile) { |
| 514 | return false; |
| 515 | } |
| 516 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 517 | HLoadClass* constant = new (arena_) HLoadClass( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 518 | storage_index, is_referrers_class, dex_offset); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 519 | current_block_->AddInstruction(constant); |
| 520 | |
| 521 | HInstruction* cls = constant; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 522 | if (!is_initialized) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 523 | cls = new (arena_) HClinitCheck(constant, dex_offset); |
| 524 | current_block_->AddInstruction(cls); |
| 525 | } |
| 526 | |
| 527 | if (is_put) { |
| 528 | // We need to keep the class alive before loading the value. |
| 529 | Temporaries temps(graph_, 1); |
| 530 | temps.Add(cls); |
| 531 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 532 | DCHECK_EQ(value->GetType(), field_type); |
| 533 | current_block_->AddInstruction( |
| 534 | new (arena_) HStaticFieldSet(cls, value, field_type, field_offset)); |
| 535 | } else { |
| 536 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, field_type, field_offset)); |
| 537 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 538 | } |
| 539 | return true; |
| 540 | } |
| 541 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 542 | void HGraphBuilder::BuildCheckedDiv(uint16_t out_reg, |
| 543 | uint16_t first_reg, |
Calin Juravle | 0f00db7 | 2014-11-06 18:19:23 +0000 | [diff] [blame] | 544 | int32_t second_reg, |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 545 | uint32_t dex_offset, |
| 546 | Primitive::Type type, |
| 547 | bool second_is_lit) { |
| 548 | DCHECK(type == Primitive::kPrimInt); |
| 549 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 550 | HInstruction* first = LoadLocal(first_reg, type); |
| 551 | HInstruction* second = second_is_lit ? GetIntConstant(second_reg) : LoadLocal(second_reg, type); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 552 | if (!second->IsIntConstant() || (second->AsIntConstant()->GetValue() == 0)) { |
| 553 | second = new (arena_) HDivZeroCheck(second, dex_offset); |
| 554 | Temporaries temps(graph_, 1); |
| 555 | current_block_->AddInstruction(second); |
| 556 | temps.Add(current_block_->GetLastInstruction()); |
| 557 | } |
| 558 | |
| 559 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second)); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 560 | UpdateLocal(out_reg, current_block_->GetLastInstruction()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 563 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
| 564 | uint32_t dex_offset, |
| 565 | bool is_put, |
| 566 | Primitive::Type anticipated_type) { |
| 567 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 568 | uint8_t array_reg = instruction.VRegB_23x(); |
| 569 | uint8_t index_reg = instruction.VRegC_23x(); |
| 570 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 571 | // We need one temporary for the null check, one for the index, and one for the length. |
| 572 | Temporaries temps(graph_, 3); |
| 573 | |
| 574 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot); |
| 575 | object = new (arena_) HNullCheck(object, dex_offset); |
| 576 | current_block_->AddInstruction(object); |
| 577 | temps.Add(object); |
| 578 | |
| 579 | HInstruction* length = new (arena_) HArrayLength(object); |
| 580 | current_block_->AddInstruction(length); |
| 581 | temps.Add(length); |
| 582 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt); |
| 583 | index = new (arena_) HBoundsCheck(index, length, dex_offset); |
| 584 | current_block_->AddInstruction(index); |
| 585 | temps.Add(index); |
| 586 | if (is_put) { |
| 587 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 588 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 589 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 590 | object, index, value, anticipated_type, dex_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 591 | } else { |
| 592 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type)); |
| 593 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 594 | } |
| 595 | } |
| 596 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 597 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_offset, |
| 598 | uint32_t type_index, |
| 599 | uint32_t number_of_vreg_arguments, |
| 600 | bool is_range, |
| 601 | uint32_t* args, |
| 602 | uint32_t register_index) { |
| 603 | HInstruction* length = GetIntConstant(number_of_vreg_arguments); |
| 604 | HInstruction* object = new (arena_) HNewArray(length, dex_offset, type_index); |
| 605 | current_block_->AddInstruction(object); |
| 606 | |
| 607 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 608 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 609 | char primitive = descriptor[1]; |
| 610 | DCHECK(primitive == 'I' |
| 611 | || primitive == 'L' |
| 612 | || primitive == '[') << descriptor; |
| 613 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 614 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 615 | |
| 616 | Temporaries temps(graph_, 1); |
| 617 | temps.Add(object); |
| 618 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 619 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
| 620 | HInstruction* index = GetIntConstant(i); |
| 621 | current_block_->AddInstruction( |
| 622 | new (arena_) HArraySet(object, index, value, type, dex_offset)); |
| 623 | } |
| 624 | latest_result_ = object; |
| 625 | } |
| 626 | |
| 627 | template <typename T> |
| 628 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 629 | const T* data, |
| 630 | uint32_t element_count, |
| 631 | Primitive::Type anticipated_type, |
| 632 | uint32_t dex_offset) { |
| 633 | for (uint32_t i = 0; i < element_count; ++i) { |
| 634 | HInstruction* index = GetIntConstant(i); |
| 635 | HInstruction* value = GetIntConstant(data[i]); |
| 636 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 637 | object, index, value, anticipated_type, dex_offset)); |
| 638 | } |
| 639 | } |
| 640 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 641 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_offset) { |
| 642 | Temporaries temps(graph_, 1); |
| 643 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot); |
| 644 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_offset); |
| 645 | current_block_->AddInstruction(null_check); |
| 646 | temps.Add(null_check); |
| 647 | |
| 648 | HInstruction* length = new (arena_) HArrayLength(null_check); |
| 649 | current_block_->AddInstruction(length); |
| 650 | |
| 651 | int32_t payload_offset = instruction.VRegB_31t() + dex_offset; |
| 652 | const Instruction::ArrayDataPayload* payload = |
| 653 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 654 | const uint8_t* data = payload->data; |
| 655 | uint32_t element_count = payload->element_count; |
| 656 | |
| 657 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 658 | // done before doing any stores. |
| 659 | HInstruction* last_index = GetIntConstant(payload->element_count - 1); |
| 660 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_offset)); |
| 661 | |
| 662 | switch (payload->element_width) { |
| 663 | case 1: |
| 664 | BuildFillArrayData(null_check, |
| 665 | reinterpret_cast<const int8_t*>(data), |
| 666 | element_count, |
| 667 | Primitive::kPrimByte, |
| 668 | dex_offset); |
| 669 | break; |
| 670 | case 2: |
| 671 | BuildFillArrayData(null_check, |
| 672 | reinterpret_cast<const int16_t*>(data), |
| 673 | element_count, |
| 674 | Primitive::kPrimShort, |
| 675 | dex_offset); |
| 676 | break; |
| 677 | case 4: |
| 678 | BuildFillArrayData(null_check, |
| 679 | reinterpret_cast<const int32_t*>(data), |
| 680 | element_count, |
| 681 | Primitive::kPrimInt, |
| 682 | dex_offset); |
| 683 | break; |
| 684 | case 8: |
| 685 | BuildFillWideArrayData(null_check, |
| 686 | reinterpret_cast<const int64_t*>(data), |
| 687 | element_count, |
| 688 | dex_offset); |
| 689 | break; |
| 690 | default: |
| 691 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 692 | } |
| 693 | } |
| 694 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 695 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 696 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 697 | uint32_t element_count, |
| 698 | uint32_t dex_offset) { |
| 699 | for (uint32_t i = 0; i < element_count; ++i) { |
| 700 | HInstruction* index = GetIntConstant(i); |
| 701 | HInstruction* value = GetLongConstant(data[i]); |
| 702 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 703 | object, index, value, Primitive::kPrimLong, dex_offset)); |
| 704 | } |
| 705 | } |
| 706 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 707 | void HGraphBuilder::PotentiallyAddSuspendCheck(int32_t target_offset, uint32_t dex_offset) { |
| 708 | if (target_offset <= 0) { |
| 709 | // Unconditionnally add a suspend check to backward branches. We can remove |
| 710 | // them after we recognize loops in the graph. |
| 711 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_offset)); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 716 | if (current_block_ == nullptr) { |
| 717 | return true; // Dead code |
| 718 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 719 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 720 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 721 | case Instruction::CONST_4: { |
| 722 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 723 | HIntConstant* constant = GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 724 | UpdateLocal(register_index, constant); |
| 725 | break; |
| 726 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 727 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 728 | case Instruction::CONST_16: { |
| 729 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 730 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21s()); |
| 731 | UpdateLocal(register_index, constant); |
| 732 | break; |
| 733 | } |
| 734 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 735 | case Instruction::CONST: { |
| 736 | int32_t register_index = instruction.VRegA(); |
| 737 | HIntConstant* constant = GetIntConstant(instruction.VRegB_31i()); |
| 738 | UpdateLocal(register_index, constant); |
| 739 | break; |
| 740 | } |
| 741 | |
| 742 | case Instruction::CONST_HIGH16: { |
| 743 | int32_t register_index = instruction.VRegA(); |
| 744 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21h() << 16); |
| 745 | UpdateLocal(register_index, constant); |
| 746 | break; |
| 747 | } |
| 748 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 749 | case Instruction::CONST_WIDE_16: { |
| 750 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 751 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 752 | int64_t value = instruction.VRegB_21s(); |
| 753 | value <<= 48; |
| 754 | value >>= 48; |
| 755 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 756 | UpdateLocal(register_index, constant); |
| 757 | break; |
| 758 | } |
| 759 | |
| 760 | case Instruction::CONST_WIDE_32: { |
| 761 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 762 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 763 | int64_t value = instruction.VRegB_31i(); |
| 764 | value <<= 32; |
| 765 | value >>= 32; |
| 766 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 767 | UpdateLocal(register_index, constant); |
| 768 | break; |
| 769 | } |
| 770 | |
| 771 | case Instruction::CONST_WIDE: { |
| 772 | int32_t register_index = instruction.VRegA(); |
| 773 | HLongConstant* constant = GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 774 | UpdateLocal(register_index, constant); |
| 775 | break; |
| 776 | } |
| 777 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 778 | case Instruction::CONST_WIDE_HIGH16: { |
| 779 | int32_t register_index = instruction.VRegA(); |
| 780 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
| 781 | HLongConstant* constant = GetLongConstant(value); |
| 782 | UpdateLocal(register_index, constant); |
| 783 | break; |
| 784 | } |
| 785 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 786 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 787 | case Instruction::MOVE: |
| 788 | case Instruction::MOVE_FROM16: |
| 789 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 790 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 791 | UpdateLocal(instruction.VRegA(), value); |
| 792 | break; |
| 793 | } |
| 794 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 795 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 796 | case Instruction::MOVE_WIDE: |
| 797 | case Instruction::MOVE_WIDE_FROM16: |
| 798 | case Instruction::MOVE_WIDE_16: { |
| 799 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 800 | UpdateLocal(instruction.VRegA(), value); |
| 801 | break; |
| 802 | } |
| 803 | |
| 804 | case Instruction::MOVE_OBJECT: |
| 805 | case Instruction::MOVE_OBJECT_16: |
| 806 | case Instruction::MOVE_OBJECT_FROM16: { |
| 807 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 808 | UpdateLocal(instruction.VRegA(), value); |
| 809 | break; |
| 810 | } |
| 811 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 812 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 813 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 814 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 817 | #define IF_XX(comparison, cond) \ |
| 818 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_offset); break; \ |
| 819 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_offset); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 820 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 821 | IF_XX(HEqual, EQ); |
| 822 | IF_XX(HNotEqual, NE); |
| 823 | IF_XX(HLessThan, LT); |
| 824 | IF_XX(HLessThanOrEqual, LE); |
| 825 | IF_XX(HGreaterThan, GT); |
| 826 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 827 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 828 | case Instruction::GOTO: |
| 829 | case Instruction::GOTO_16: |
| 830 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 831 | int32_t offset = instruction.GetTargetOffset(); |
| 832 | PotentiallyAddSuspendCheck(offset, dex_offset); |
| 833 | HBasicBlock* target = FindBlockStartingAt(offset + dex_offset); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 834 | DCHECK(target != nullptr); |
| 835 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 836 | current_block_->AddSuccessor(target); |
| 837 | current_block_ = nullptr; |
| 838 | break; |
| 839 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 840 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 841 | case Instruction::RETURN: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 842 | DCHECK_NE(return_type_, Primitive::kPrimNot); |
| 843 | DCHECK_NE(return_type_, Primitive::kPrimLong); |
| 844 | DCHECK_NE(return_type_, Primitive::kPrimDouble); |
| 845 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 846 | break; |
| 847 | } |
| 848 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 849 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 850 | DCHECK(return_type_ == Primitive::kPrimNot); |
| 851 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 852 | break; |
| 853 | } |
| 854 | |
| 855 | case Instruction::RETURN_WIDE: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 856 | DCHECK(return_type_ == Primitive::kPrimDouble || return_type_ == Primitive::kPrimLong); |
| 857 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 858 | break; |
| 859 | } |
| 860 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 861 | case Instruction::INVOKE_STATIC: |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 862 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 863 | case Instruction::INVOKE_VIRTUAL: |
| 864 | case Instruction::INVOKE_INTERFACE: { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 865 | uint32_t method_idx = instruction.VRegB_35c(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 866 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 867 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 868 | instruction.GetVarArgs(args); |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 869 | if (!BuildInvoke(instruction, dex_offset, method_idx, |
| 870 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 871 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 872 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 873 | break; |
| 874 | } |
| 875 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 876 | case Instruction::INVOKE_STATIC_RANGE: |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 877 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 878 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 879 | case Instruction::INVOKE_INTERFACE_RANGE: { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 880 | uint32_t method_idx = instruction.VRegB_3rc(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 881 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 882 | uint32_t register_index = instruction.VRegC(); |
| 883 | if (!BuildInvoke(instruction, dex_offset, method_idx, |
| 884 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 885 | return false; |
| 886 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 887 | break; |
| 888 | } |
| 889 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 890 | case Instruction::NEG_INT: { |
| 891 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt); |
| 892 | break; |
| 893 | } |
| 894 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 895 | case Instruction::NEG_LONG: { |
| 896 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong); |
| 897 | break; |
| 898 | } |
| 899 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 900 | case Instruction::NEG_FLOAT: { |
| 901 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat); |
| 902 | break; |
| 903 | } |
| 904 | |
| 905 | case Instruction::NEG_DOUBLE: { |
| 906 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble); |
| 907 | break; |
| 908 | } |
| 909 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 910 | case Instruction::NOT_INT: { |
| 911 | Unop_12x<HNot>(instruction, Primitive::kPrimInt); |
| 912 | break; |
| 913 | } |
| 914 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 915 | case Instruction::NOT_LONG: { |
| 916 | Unop_12x<HNot>(instruction, Primitive::kPrimLong); |
| 917 | break; |
| 918 | } |
| 919 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 920 | case Instruction::INT_TO_LONG: { |
| 921 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong); |
| 922 | break; |
| 923 | } |
| 924 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 925 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 926 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 927 | break; |
| 928 | } |
| 929 | |
| 930 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 931 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 932 | break; |
| 933 | } |
| 934 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 935 | case Instruction::ADD_DOUBLE: { |
| 936 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble); |
| 937 | break; |
| 938 | } |
| 939 | |
| 940 | case Instruction::ADD_FLOAT: { |
| 941 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat); |
| 942 | break; |
| 943 | } |
| 944 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 945 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 946 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 947 | break; |
| 948 | } |
| 949 | |
| 950 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 951 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 952 | break; |
| 953 | } |
| 954 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 955 | case Instruction::SUB_FLOAT: { |
| 956 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat); |
| 957 | break; |
| 958 | } |
| 959 | |
| 960 | case Instruction::SUB_DOUBLE: { |
| 961 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble); |
| 962 | break; |
| 963 | } |
| 964 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 965 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 966 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 967 | break; |
| 968 | } |
| 969 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 970 | case Instruction::MUL_INT: { |
| 971 | Binop_23x<HMul>(instruction, Primitive::kPrimInt); |
| 972 | break; |
| 973 | } |
| 974 | |
| 975 | case Instruction::MUL_LONG: { |
| 976 | Binop_23x<HMul>(instruction, Primitive::kPrimLong); |
| 977 | break; |
| 978 | } |
| 979 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 980 | case Instruction::MUL_FLOAT: { |
| 981 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat); |
| 982 | break; |
| 983 | } |
| 984 | |
| 985 | case Instruction::MUL_DOUBLE: { |
| 986 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble); |
| 987 | break; |
| 988 | } |
| 989 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 990 | case Instruction::DIV_INT: { |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 991 | BuildCheckedDiv(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 992 | dex_offset, Primitive::kPrimInt, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 993 | break; |
| 994 | } |
| 995 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 996 | case Instruction::DIV_FLOAT: { |
| 997 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat); |
| 998 | break; |
| 999 | } |
| 1000 | |
| 1001 | case Instruction::DIV_DOUBLE: { |
| 1002 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble); |
| 1003 | break; |
| 1004 | } |
| 1005 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1006 | case Instruction::ADD_LONG_2ADDR: { |
| 1007 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1008 | break; |
| 1009 | } |
| 1010 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1011 | case Instruction::ADD_DOUBLE_2ADDR: { |
| 1012 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1013 | break; |
| 1014 | } |
| 1015 | |
| 1016 | case Instruction::ADD_FLOAT_2ADDR: { |
| 1017 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1018 | break; |
| 1019 | } |
| 1020 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1021 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1022 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 1023 | break; |
| 1024 | } |
| 1025 | |
| 1026 | case Instruction::SUB_LONG_2ADDR: { |
| 1027 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1028 | break; |
| 1029 | } |
| 1030 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1031 | case Instruction::SUB_FLOAT_2ADDR: { |
| 1032 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat); |
| 1033 | break; |
| 1034 | } |
| 1035 | |
| 1036 | case Instruction::SUB_DOUBLE_2ADDR: { |
| 1037 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble); |
| 1038 | break; |
| 1039 | } |
| 1040 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1041 | case Instruction::MUL_INT_2ADDR: { |
| 1042 | Binop_12x<HMul>(instruction, Primitive::kPrimInt); |
| 1043 | break; |
| 1044 | } |
| 1045 | |
| 1046 | case Instruction::MUL_LONG_2ADDR: { |
| 1047 | Binop_12x<HMul>(instruction, Primitive::kPrimLong); |
| 1048 | break; |
| 1049 | } |
| 1050 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1051 | case Instruction::MUL_FLOAT_2ADDR: { |
| 1052 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat); |
| 1053 | break; |
| 1054 | } |
| 1055 | |
| 1056 | case Instruction::MUL_DOUBLE_2ADDR: { |
| 1057 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble); |
| 1058 | break; |
| 1059 | } |
| 1060 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1061 | case Instruction::DIV_INT_2ADDR: { |
| 1062 | BuildCheckedDiv(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1063 | dex_offset, Primitive::kPrimInt, false); |
| 1064 | break; |
| 1065 | } |
| 1066 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1067 | case Instruction::DIV_FLOAT_2ADDR: { |
| 1068 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat); |
| 1069 | break; |
| 1070 | } |
| 1071 | |
| 1072 | case Instruction::DIV_DOUBLE_2ADDR: { |
| 1073 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble); |
| 1074 | break; |
| 1075 | } |
| 1076 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1077 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1078 | Binop_22s<HAdd>(instruction, false); |
| 1079 | break; |
| 1080 | } |
| 1081 | |
| 1082 | case Instruction::RSUB_INT: { |
| 1083 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1084 | break; |
| 1085 | } |
| 1086 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1087 | case Instruction::MUL_INT_LIT16: { |
| 1088 | Binop_22s<HMul>(instruction, false); |
| 1089 | break; |
| 1090 | } |
| 1091 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1092 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1093 | Binop_22b<HAdd>(instruction, false); |
| 1094 | break; |
| 1095 | } |
| 1096 | |
| 1097 | case Instruction::RSUB_INT_LIT8: { |
| 1098 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1099 | break; |
| 1100 | } |
| 1101 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1102 | case Instruction::MUL_INT_LIT8: { |
| 1103 | Binop_22b<HMul>(instruction, false); |
| 1104 | break; |
| 1105 | } |
| 1106 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1107 | case Instruction::DIV_INT_LIT16: |
| 1108 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1109 | BuildCheckedDiv(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1110 | dex_offset, Primitive::kPrimInt, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1111 | break; |
| 1112 | } |
| 1113 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1114 | case Instruction::NEW_INSTANCE: { |
| 1115 | current_block_->AddInstruction( |
| 1116 | new (arena_) HNewInstance(dex_offset, instruction.VRegB_21c())); |
| 1117 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 1118 | break; |
| 1119 | } |
| 1120 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1121 | case Instruction::NEW_ARRAY: { |
| 1122 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt); |
| 1123 | current_block_->AddInstruction( |
| 1124 | new (arena_) HNewArray(length, dex_offset, instruction.VRegC_22c())); |
| 1125 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 1126 | break; |
| 1127 | } |
| 1128 | |
| 1129 | case Instruction::FILLED_NEW_ARRAY: { |
| 1130 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 1131 | uint32_t type_index = instruction.VRegB_35c(); |
| 1132 | uint32_t args[5]; |
| 1133 | instruction.GetVarArgs(args); |
| 1134 | BuildFilledNewArray(dex_offset, type_index, number_of_vreg_arguments, false, args, 0); |
| 1135 | break; |
| 1136 | } |
| 1137 | |
| 1138 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 1139 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1140 | uint32_t type_index = instruction.VRegB_3rc(); |
| 1141 | uint32_t register_index = instruction.VRegC_3rc(); |
| 1142 | BuildFilledNewArray( |
| 1143 | dex_offset, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
| 1144 | break; |
| 1145 | } |
| 1146 | |
| 1147 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1148 | BuildFillArrayData(instruction, dex_offset); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1149 | break; |
| 1150 | } |
| 1151 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1152 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1153 | case Instruction::MOVE_RESULT_WIDE: |
| 1154 | case Instruction::MOVE_RESULT_OBJECT: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1155 | UpdateLocal(instruction.VRegA(), latest_result_); |
| 1156 | latest_result_ = nullptr; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1157 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1158 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1159 | case Instruction::CMP_LONG: { |
| 1160 | Binop_23x<HCompare>(instruction, Primitive::kPrimLong); |
| 1161 | break; |
| 1162 | } |
| 1163 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1164 | case Instruction::NOP: |
| 1165 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1166 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1167 | case Instruction::IGET: |
| 1168 | case Instruction::IGET_WIDE: |
| 1169 | case Instruction::IGET_OBJECT: |
| 1170 | case Instruction::IGET_BOOLEAN: |
| 1171 | case Instruction::IGET_BYTE: |
| 1172 | case Instruction::IGET_CHAR: |
| 1173 | case Instruction::IGET_SHORT: { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1174 | if (!BuildInstanceFieldAccess(instruction, dex_offset, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1175 | return false; |
| 1176 | } |
| 1177 | break; |
| 1178 | } |
| 1179 | |
| 1180 | case Instruction::IPUT: |
| 1181 | case Instruction::IPUT_WIDE: |
| 1182 | case Instruction::IPUT_OBJECT: |
| 1183 | case Instruction::IPUT_BOOLEAN: |
| 1184 | case Instruction::IPUT_BYTE: |
| 1185 | case Instruction::IPUT_CHAR: |
| 1186 | case Instruction::IPUT_SHORT: { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1187 | if (!BuildInstanceFieldAccess(instruction, dex_offset, true)) { |
| 1188 | return false; |
| 1189 | } |
| 1190 | break; |
| 1191 | } |
| 1192 | |
| 1193 | case Instruction::SGET: |
| 1194 | case Instruction::SGET_WIDE: |
| 1195 | case Instruction::SGET_OBJECT: |
| 1196 | case Instruction::SGET_BOOLEAN: |
| 1197 | case Instruction::SGET_BYTE: |
| 1198 | case Instruction::SGET_CHAR: |
| 1199 | case Instruction::SGET_SHORT: { |
| 1200 | if (!BuildStaticFieldAccess(instruction, dex_offset, false)) { |
| 1201 | return false; |
| 1202 | } |
| 1203 | break; |
| 1204 | } |
| 1205 | |
| 1206 | case Instruction::SPUT: |
| 1207 | case Instruction::SPUT_WIDE: |
| 1208 | case Instruction::SPUT_OBJECT: |
| 1209 | case Instruction::SPUT_BOOLEAN: |
| 1210 | case Instruction::SPUT_BYTE: |
| 1211 | case Instruction::SPUT_CHAR: |
| 1212 | case Instruction::SPUT_SHORT: { |
| 1213 | if (!BuildStaticFieldAccess(instruction, dex_offset, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1214 | return false; |
| 1215 | } |
| 1216 | break; |
| 1217 | } |
| 1218 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1219 | #define ARRAY_XX(kind, anticipated_type) \ |
| 1220 | case Instruction::AGET##kind: { \ |
| 1221 | BuildArrayAccess(instruction, dex_offset, false, anticipated_type); \ |
| 1222 | break; \ |
| 1223 | } \ |
| 1224 | case Instruction::APUT##kind: { \ |
| 1225 | BuildArrayAccess(instruction, dex_offset, true, anticipated_type); \ |
| 1226 | break; \ |
| 1227 | } |
| 1228 | |
| 1229 | ARRAY_XX(, Primitive::kPrimInt); |
| 1230 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 1231 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 1232 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 1233 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 1234 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 1235 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 1236 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1237 | case Instruction::ARRAY_LENGTH: { |
| 1238 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1239 | // No need for a temporary for the null check, it is the only input of the following |
| 1240 | // instruction. |
| 1241 | object = new (arena_) HNullCheck(object, dex_offset); |
| 1242 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1243 | current_block_->AddInstruction(new (arena_) HArrayLength(object)); |
| 1244 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 1245 | break; |
| 1246 | } |
| 1247 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1248 | case Instruction::CONST_STRING: { |
| 1249 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_21c(), dex_offset)); |
| 1250 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 1251 | break; |
| 1252 | } |
| 1253 | |
| 1254 | case Instruction::CONST_STRING_JUMBO: { |
| 1255 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_31c(), dex_offset)); |
| 1256 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 1257 | break; |
| 1258 | } |
| 1259 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 1260 | case Instruction::CONST_CLASS: { |
| 1261 | uint16_t type_index = instruction.VRegB_21c(); |
| 1262 | bool type_known_final; |
| 1263 | bool type_known_abstract; |
| 1264 | bool is_referrers_class; |
| 1265 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1266 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
| 1267 | &type_known_final, &type_known_abstract, &is_referrers_class); |
| 1268 | if (!can_access) { |
| 1269 | return false; |
| 1270 | } |
| 1271 | current_block_->AddInstruction( |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1272 | new (arena_) HLoadClass(type_index, is_referrers_class, dex_offset)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 1273 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 1274 | break; |
| 1275 | } |
| 1276 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1277 | case Instruction::MOVE_EXCEPTION: { |
| 1278 | current_block_->AddInstruction(new (arena_) HLoadException()); |
| 1279 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
| 1280 | break; |
| 1281 | } |
| 1282 | |
| 1283 | case Instruction::THROW: { |
| 1284 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot); |
| 1285 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_offset)); |
| 1286 | // A throw instruction must branch to the exit block. |
| 1287 | current_block_->AddSuccessor(exit_block_); |
| 1288 | // We finished building this block. Set the current block to null to avoid |
| 1289 | // adding dead instructions to it. |
| 1290 | current_block_ = nullptr; |
| 1291 | break; |
| 1292 | } |
| 1293 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1294 | case Instruction::INSTANCE_OF: { |
| 1295 | uint16_t type_index = instruction.VRegC_22c(); |
| 1296 | bool type_known_final; |
| 1297 | bool type_known_abstract; |
| 1298 | bool is_referrers_class; |
| 1299 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1300 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
| 1301 | &type_known_final, &type_known_abstract, &is_referrers_class); |
| 1302 | if (!can_access) { |
| 1303 | return false; |
| 1304 | } |
| 1305 | HInstruction* object = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimNot); |
| 1306 | HLoadClass* cls = new (arena_) HLoadClass(type_index, is_referrers_class, dex_offset); |
| 1307 | current_block_->AddInstruction(cls); |
| 1308 | // The class needs a temporary before being used by the type check. |
| 1309 | Temporaries temps(graph_, 1); |
| 1310 | temps.Add(cls); |
| 1311 | current_block_->AddInstruction( |
| 1312 | new (arena_) HTypeCheck(object, cls, type_known_final, dex_offset)); |
| 1313 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 1314 | break; |
| 1315 | } |
| 1316 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1317 | default: |
| 1318 | return false; |
| 1319 | } |
| 1320 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1321 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1322 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1323 | HIntConstant* HGraphBuilder::GetIntConstant0() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1324 | if (constant0_ != nullptr) { |
| 1325 | return constant0_; |
| 1326 | } |
| 1327 | constant0_ = new(arena_) HIntConstant(0); |
| 1328 | entry_block_->AddInstruction(constant0_); |
| 1329 | return constant0_; |
| 1330 | } |
| 1331 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1332 | HIntConstant* HGraphBuilder::GetIntConstant1() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1333 | if (constant1_ != nullptr) { |
| 1334 | return constant1_; |
| 1335 | } |
| 1336 | constant1_ = new(arena_) HIntConstant(1); |
| 1337 | entry_block_->AddInstruction(constant1_); |
| 1338 | return constant1_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1341 | HIntConstant* HGraphBuilder::GetIntConstant(int32_t constant) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1342 | switch (constant) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1343 | case 0: return GetIntConstant0(); |
| 1344 | case 1: return GetIntConstant1(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1345 | default: { |
| 1346 | HIntConstant* instruction = new (arena_) HIntConstant(constant); |
| 1347 | entry_block_->AddInstruction(instruction); |
| 1348 | return instruction; |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1353 | HLongConstant* HGraphBuilder::GetLongConstant(int64_t constant) { |
| 1354 | HLongConstant* instruction = new (arena_) HLongConstant(constant); |
| 1355 | entry_block_->AddInstruction(instruction); |
| 1356 | return instruction; |
| 1357 | } |
| 1358 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1359 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 1360 | return locals_.Get(register_index); |
| 1361 | } |
| 1362 | |
| 1363 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 1364 | HLocal* local = GetLocalAt(register_index); |
| 1365 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 1366 | } |
| 1367 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1368 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1369 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1370 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1371 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1374 | } // namespace art |