David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
| 17 | #include "instruction_builder.h" |
| 18 | |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 19 | #include "art_method-inl.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 20 | #include "base/arena_bit_vector.h" |
| 21 | #include "base/bit_vector-inl.h" |
| 22 | #include "block_builder.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 23 | #include "bytecode_utils.h" |
| 24 | #include "class_linker.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 25 | #include "data_type-inl.h" |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 26 | #include "dex_instruction-inl.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 27 | #include "driver/compiler_driver-inl.h" |
| 28 | #include "driver/dex_compilation_unit.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 29 | #include "driver/compiler_options.h" |
Andreas Gampe | 75a7db6 | 2016-09-26 12:04:26 -0700 | [diff] [blame] | 30 | #include "imtable-inl.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 31 | #include "mirror/dex_cache.h" |
| 32 | #include "optimizing_compiler_stats.h" |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 33 | #include "quicken_info.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 34 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 35 | #include "sharpening.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 36 | #include "ssa_builder.h" |
Andreas Gampe | a7c83ac | 2017-09-11 08:14:23 -0700 | [diff] [blame] | 37 | #include "well_known_classes.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 41 | HBasicBlock* HInstructionBuilder::FindBlockStartingAt(uint32_t dex_pc) const { |
| 42 | return block_builder_->GetBlockAt(dex_pc); |
| 43 | } |
| 44 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 45 | inline ScopedArenaVector<HInstruction*>* HInstructionBuilder::GetLocalsFor(HBasicBlock* block) { |
| 46 | ScopedArenaVector<HInstruction*>* locals = &locals_for_[block->GetBlockId()]; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 47 | const size_t vregs = graph_->GetNumberOfVRegs(); |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 48 | if (locals->size() == vregs) { |
| 49 | return locals; |
| 50 | } |
| 51 | return GetLocalsForWithAllocation(block, locals, vregs); |
| 52 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 53 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 54 | ScopedArenaVector<HInstruction*>* HInstructionBuilder::GetLocalsForWithAllocation( |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 55 | HBasicBlock* block, |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 56 | ScopedArenaVector<HInstruction*>* locals, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 57 | const size_t vregs) { |
| 58 | DCHECK_NE(locals->size(), vregs); |
| 59 | locals->resize(vregs, nullptr); |
| 60 | if (block->IsCatchBlock()) { |
| 61 | // We record incoming inputs of catch phis at throwing instructions and |
| 62 | // must therefore eagerly create the phis. Phis for undefined vregs will |
| 63 | // be deleted when the first throwing instruction with the vreg undefined |
| 64 | // is encountered. Unused phis will be removed by dead phi analysis. |
| 65 | for (size_t i = 0; i < vregs; ++i) { |
| 66 | // No point in creating the catch phi if it is already undefined at |
| 67 | // the first throwing instruction. |
| 68 | HInstruction* current_local_value = (*current_locals_)[i]; |
| 69 | if (current_local_value != nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 70 | HPhi* phi = new (allocator_) HPhi( |
| 71 | allocator_, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 72 | i, |
| 73 | 0, |
| 74 | current_local_value->GetType()); |
| 75 | block->AddPhi(phi); |
| 76 | (*locals)[i] = phi; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | } |
| 80 | return locals; |
| 81 | } |
| 82 | |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 83 | inline HInstruction* HInstructionBuilder::ValueOfLocalAt(HBasicBlock* block, size_t local) { |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 84 | ScopedArenaVector<HInstruction*>* locals = GetLocalsFor(block); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 85 | return (*locals)[local]; |
| 86 | } |
| 87 | |
| 88 | void HInstructionBuilder::InitializeBlockLocals() { |
| 89 | current_locals_ = GetLocalsFor(current_block_); |
| 90 | |
| 91 | if (current_block_->IsCatchBlock()) { |
| 92 | // Catch phis were already created and inputs collected from throwing sites. |
| 93 | if (kIsDebugBuild) { |
| 94 | // Make sure there was at least one throwing instruction which initialized |
| 95 | // locals (guaranteed by HGraphBuilder) and that all try blocks have been |
| 96 | // visited already (from HTryBoundary scoping and reverse post order). |
| 97 | bool catch_block_visited = false; |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 98 | for (HBasicBlock* current : graph_->GetReversePostOrder()) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 99 | if (current == current_block_) { |
| 100 | catch_block_visited = true; |
| 101 | } else if (current->IsTryBlock()) { |
| 102 | const HTryBoundary& try_entry = current->GetTryCatchInformation()->GetTryEntry(); |
| 103 | if (try_entry.HasExceptionHandler(*current_block_)) { |
| 104 | DCHECK(!catch_block_visited) << "Catch block visited before its try block."; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | DCHECK_EQ(current_locals_->size(), graph_->GetNumberOfVRegs()) |
| 109 | << "No instructions throwing into a live catch block."; |
| 110 | } |
| 111 | } else if (current_block_->IsLoopHeader()) { |
| 112 | // If the block is a loop header, we know we only have visited the pre header |
| 113 | // because we are visiting in reverse post order. We create phis for all initialized |
| 114 | // locals from the pre header. Their inputs will be populated at the end of |
| 115 | // the analysis. |
| 116 | for (size_t local = 0; local < current_locals_->size(); ++local) { |
| 117 | HInstruction* incoming = |
| 118 | ValueOfLocalAt(current_block_->GetLoopInformation()->GetPreHeader(), local); |
| 119 | if (incoming != nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 120 | HPhi* phi = new (allocator_) HPhi( |
| 121 | allocator_, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 122 | local, |
| 123 | 0, |
| 124 | incoming->GetType()); |
| 125 | current_block_->AddPhi(phi); |
| 126 | (*current_locals_)[local] = phi; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // Save the loop header so that the last phase of the analysis knows which |
| 131 | // blocks need to be updated. |
| 132 | loop_headers_.push_back(current_block_); |
| 133 | } else if (current_block_->GetPredecessors().size() > 0) { |
| 134 | // All predecessors have already been visited because we are visiting in reverse post order. |
| 135 | // We merge the values of all locals, creating phis if those values differ. |
| 136 | for (size_t local = 0; local < current_locals_->size(); ++local) { |
| 137 | bool one_predecessor_has_no_value = false; |
| 138 | bool is_different = false; |
| 139 | HInstruction* value = ValueOfLocalAt(current_block_->GetPredecessors()[0], local); |
| 140 | |
| 141 | for (HBasicBlock* predecessor : current_block_->GetPredecessors()) { |
| 142 | HInstruction* current = ValueOfLocalAt(predecessor, local); |
| 143 | if (current == nullptr) { |
| 144 | one_predecessor_has_no_value = true; |
| 145 | break; |
| 146 | } else if (current != value) { |
| 147 | is_different = true; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if (one_predecessor_has_no_value) { |
| 152 | // If one predecessor has no value for this local, we trust the verifier has |
| 153 | // successfully checked that there is a store dominating any read after this block. |
| 154 | continue; |
| 155 | } |
| 156 | |
| 157 | if (is_different) { |
| 158 | HInstruction* first_input = ValueOfLocalAt(current_block_->GetPredecessors()[0], local); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 159 | HPhi* phi = new (allocator_) HPhi( |
| 160 | allocator_, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 161 | local, |
| 162 | current_block_->GetPredecessors().size(), |
| 163 | first_input->GetType()); |
| 164 | for (size_t i = 0; i < current_block_->GetPredecessors().size(); i++) { |
| 165 | HInstruction* pred_value = ValueOfLocalAt(current_block_->GetPredecessors()[i], local); |
| 166 | phi->SetRawInputAt(i, pred_value); |
| 167 | } |
| 168 | current_block_->AddPhi(phi); |
| 169 | value = phi; |
| 170 | } |
| 171 | (*current_locals_)[local] = value; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | void HInstructionBuilder::PropagateLocalsToCatchBlocks() { |
| 177 | const HTryBoundary& try_entry = current_block_->GetTryCatchInformation()->GetTryEntry(); |
| 178 | for (HBasicBlock* catch_block : try_entry.GetExceptionHandlers()) { |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 179 | ScopedArenaVector<HInstruction*>* handler_locals = GetLocalsFor(catch_block); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 180 | DCHECK_EQ(handler_locals->size(), current_locals_->size()); |
| 181 | for (size_t vreg = 0, e = current_locals_->size(); vreg < e; ++vreg) { |
| 182 | HInstruction* handler_value = (*handler_locals)[vreg]; |
| 183 | if (handler_value == nullptr) { |
| 184 | // Vreg was undefined at a previously encountered throwing instruction |
| 185 | // and the catch phi was deleted. Do not record the local value. |
| 186 | continue; |
| 187 | } |
| 188 | DCHECK(handler_value->IsPhi()); |
| 189 | |
| 190 | HInstruction* local_value = (*current_locals_)[vreg]; |
| 191 | if (local_value == nullptr) { |
| 192 | // This is the first instruction throwing into `catch_block` where |
| 193 | // `vreg` is undefined. Delete the catch phi. |
| 194 | catch_block->RemovePhi(handler_value->AsPhi()); |
| 195 | (*handler_locals)[vreg] = nullptr; |
| 196 | } else { |
| 197 | // Vreg has been defined at all instructions throwing into `catch_block` |
| 198 | // encountered so far. Record the local value in the catch phi. |
| 199 | handler_value->AsPhi()->AddInput(local_value); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | void HInstructionBuilder::AppendInstruction(HInstruction* instruction) { |
| 206 | current_block_->AddInstruction(instruction); |
| 207 | InitializeInstruction(instruction); |
| 208 | } |
| 209 | |
| 210 | void HInstructionBuilder::InsertInstructionAtTop(HInstruction* instruction) { |
| 211 | if (current_block_->GetInstructions().IsEmpty()) { |
| 212 | current_block_->AddInstruction(instruction); |
| 213 | } else { |
| 214 | current_block_->InsertInstructionBefore(instruction, current_block_->GetFirstInstruction()); |
| 215 | } |
| 216 | InitializeInstruction(instruction); |
| 217 | } |
| 218 | |
| 219 | void HInstructionBuilder::InitializeInstruction(HInstruction* instruction) { |
| 220 | if (instruction->NeedsEnvironment()) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 221 | HEnvironment* environment = new (allocator_) HEnvironment( |
| 222 | allocator_, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 223 | current_locals_->size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 224 | graph_->GetArtMethod(), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 225 | instruction->GetDexPc(), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 226 | instruction); |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 227 | environment->CopyFrom(ArrayRef<HInstruction* const>(*current_locals_)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 228 | instruction->SetRawEnvironment(environment); |
| 229 | } |
| 230 | } |
| 231 | |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 232 | HInstruction* HInstructionBuilder::LoadNullCheckedLocal(uint32_t register_index, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 233 | HInstruction* ref = LoadLocal(register_index, DataType::Type::kReference); |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 234 | if (!ref->CanBeNull()) { |
| 235 | return ref; |
| 236 | } |
| 237 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 238 | HNullCheck* null_check = new (allocator_) HNullCheck(ref, dex_pc); |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 239 | AppendInstruction(null_check); |
| 240 | return null_check; |
| 241 | } |
| 242 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 243 | void HInstructionBuilder::SetLoopHeaderPhiInputs() { |
| 244 | for (size_t i = loop_headers_.size(); i > 0; --i) { |
| 245 | HBasicBlock* block = loop_headers_[i - 1]; |
| 246 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 247 | HPhi* phi = it.Current()->AsPhi(); |
| 248 | size_t vreg = phi->GetRegNumber(); |
| 249 | for (HBasicBlock* predecessor : block->GetPredecessors()) { |
| 250 | HInstruction* value = ValueOfLocalAt(predecessor, vreg); |
| 251 | if (value == nullptr) { |
| 252 | // Vreg is undefined at this predecessor. Mark it dead and leave with |
| 253 | // fewer inputs than predecessors. SsaChecker will fail if not removed. |
| 254 | phi->SetDead(); |
| 255 | break; |
| 256 | } else { |
| 257 | phi->AddInput(value); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | static bool IsBlockPopulated(HBasicBlock* block) { |
| 265 | if (block->IsLoopHeader()) { |
| 266 | // Suspend checks were inserted into loop headers during building of dominator tree. |
| 267 | DCHECK(block->GetFirstInstruction()->IsSuspendCheck()); |
| 268 | return block->GetFirstInstruction() != block->GetLastInstruction(); |
| 269 | } else { |
| 270 | return !block->GetInstructions().IsEmpty(); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | bool HInstructionBuilder::Build() { |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 275 | DCHECK(code_item_ != nullptr); |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 276 | locals_for_.resize( |
| 277 | graph_->GetBlocks().size(), |
| 278 | ScopedArenaVector<HInstruction*>(local_allocator_->Adapter(kArenaAllocGraphBuilder))); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 279 | |
| 280 | // Find locations where we want to generate extra stackmaps for native debugging. |
| 281 | // This allows us to generate the info only at interesting points (for example, |
| 282 | // at start of java statement) rather than before every dex instruction. |
| 283 | const bool native_debuggable = compiler_driver_ != nullptr && |
| 284 | compiler_driver_->GetCompilerOptions().GetNativeDebuggable(); |
| 285 | ArenaBitVector* native_debug_info_locations = nullptr; |
| 286 | if (native_debuggable) { |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 287 | native_debug_info_locations = FindNativeDebugInfoLocations(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 290 | for (HBasicBlock* block : graph_->GetReversePostOrder()) { |
| 291 | current_block_ = block; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 292 | uint32_t block_dex_pc = current_block_->GetDexPc(); |
| 293 | |
| 294 | InitializeBlockLocals(); |
| 295 | |
| 296 | if (current_block_->IsEntryBlock()) { |
| 297 | InitializeParameters(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 298 | AppendInstruction(new (allocator_) HSuspendCheck(0u)); |
| 299 | AppendInstruction(new (allocator_) HGoto(0u)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 300 | continue; |
| 301 | } else if (current_block_->IsExitBlock()) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 302 | AppendInstruction(new (allocator_) HExit()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 303 | continue; |
| 304 | } else if (current_block_->IsLoopHeader()) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 305 | HSuspendCheck* suspend_check = new (allocator_) HSuspendCheck(current_block_->GetDexPc()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 306 | current_block_->GetLoopInformation()->SetSuspendCheck(suspend_check); |
| 307 | // This is slightly odd because the loop header might not be empty (TryBoundary). |
| 308 | // But we're still creating the environment with locals from the top of the block. |
| 309 | InsertInstructionAtTop(suspend_check); |
| 310 | } |
| 311 | |
| 312 | if (block_dex_pc == kNoDexPc || current_block_ != block_builder_->GetBlockAt(block_dex_pc)) { |
| 313 | // Synthetic block that does not need to be populated. |
| 314 | DCHECK(IsBlockPopulated(current_block_)); |
| 315 | continue; |
| 316 | } |
| 317 | |
| 318 | DCHECK(!IsBlockPopulated(current_block_)); |
| 319 | |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 320 | uint32_t quicken_index = 0; |
| 321 | if (CanDecodeQuickenedInfo()) { |
| 322 | quicken_index = block_builder_->GetQuickenIndex(block_dex_pc); |
| 323 | } |
| 324 | |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 325 | for (const DexInstructionPcPair& pair : code_item_->Instructions(block_dex_pc)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 326 | if (current_block_ == nullptr) { |
| 327 | // The previous instruction ended this block. |
| 328 | break; |
| 329 | } |
| 330 | |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 331 | const uint32_t dex_pc = pair.DexPc(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 332 | if (dex_pc != block_dex_pc && FindBlockStartingAt(dex_pc) != nullptr) { |
| 333 | // This dex_pc starts a new basic block. |
| 334 | break; |
| 335 | } |
| 336 | |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 337 | if (current_block_->IsTryBlock() && IsThrowingDexInstruction(pair.Inst())) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 338 | PropagateLocalsToCatchBlocks(); |
| 339 | } |
| 340 | |
| 341 | if (native_debuggable && native_debug_info_locations->IsBitSet(dex_pc)) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 342 | AppendInstruction(new (allocator_) HNativeDebugInfo(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 345 | if (!ProcessDexInstruction(pair.Inst(), dex_pc, quicken_index)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 346 | return false; |
| 347 | } |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 348 | |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 349 | if (QuickenInfoTable::NeedsIndexForInstruction(&pair.Inst())) { |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 350 | ++quicken_index; |
| 351 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | if (current_block_ != nullptr) { |
| 355 | // Branching instructions clear current_block, so we know the last |
| 356 | // instruction of the current block is not a branching instruction. |
| 357 | // We add an unconditional Goto to the next block. |
| 358 | DCHECK_EQ(current_block_->GetSuccessors().size(), 1u); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 359 | AppendInstruction(new (allocator_) HGoto()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | SetLoopHeaderPhiInputs(); |
| 364 | |
| 365 | return true; |
| 366 | } |
| 367 | |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 368 | void HInstructionBuilder::BuildIntrinsic(ArtMethod* method) { |
| 369 | DCHECK(code_item_ == nullptr); |
| 370 | DCHECK(method->IsIntrinsic()); |
| 371 | |
| 372 | locals_for_.resize( |
| 373 | graph_->GetBlocks().size(), |
| 374 | ScopedArenaVector<HInstruction*>(local_allocator_->Adapter(kArenaAllocGraphBuilder))); |
| 375 | |
| 376 | // Fill the entry block. Do not add suspend check, we do not want a suspend |
| 377 | // check in intrinsics; intrinsic methods are supposed to be fast. |
| 378 | current_block_ = graph_->GetEntryBlock(); |
| 379 | InitializeBlockLocals(); |
| 380 | InitializeParameters(); |
| 381 | AppendInstruction(new (allocator_) HGoto(0u)); |
| 382 | |
| 383 | // Fill the body. |
| 384 | current_block_ = current_block_->GetSingleSuccessor(); |
| 385 | InitializeBlockLocals(); |
| 386 | DCHECK(!IsBlockPopulated(current_block_)); |
| 387 | |
| 388 | // Add the invoke and return instruction. Use HInvokeStaticOrDirect even |
| 389 | // for methods that would normally use an HInvokeVirtual (sharpen the call). |
| 390 | size_t in_vregs = graph_->GetNumberOfInVRegs(); |
| 391 | size_t number_of_arguments = |
| 392 | in_vregs - std::count(current_locals_->end() - in_vregs, current_locals_->end(), nullptr); |
| 393 | uint32_t method_idx = dex_compilation_unit_->GetDexMethodIndex(); |
| 394 | MethodReference target_method(dex_file_, method_idx); |
| 395 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 396 | HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall, |
| 397 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 398 | /* method_load_data */ 0u |
| 399 | }; |
| 400 | InvokeType invoke_type = dex_compilation_unit_->IsStatic() ? kStatic : kDirect; |
| 401 | HInvokeStaticOrDirect* invoke = new (allocator_) HInvokeStaticOrDirect( |
| 402 | allocator_, |
| 403 | number_of_arguments, |
| 404 | return_type_, |
| 405 | kNoDexPc, |
| 406 | method_idx, |
| 407 | method, |
| 408 | dispatch_info, |
| 409 | invoke_type, |
| 410 | target_method, |
| 411 | HInvokeStaticOrDirect::ClinitCheckRequirement::kNone); |
| 412 | HandleInvoke(invoke, |
| 413 | in_vregs, |
| 414 | /* args */ nullptr, |
| 415 | graph_->GetNumberOfVRegs() - in_vregs, |
| 416 | /* is_range */ true, |
| 417 | dex_file_->GetMethodShorty(method_idx), |
| 418 | /* clinit_check */ nullptr, |
| 419 | /* is_unresolved */ false); |
| 420 | |
| 421 | // Add the return instruction. |
| 422 | if (return_type_ == DataType::Type::kVoid) { |
| 423 | AppendInstruction(new (allocator_) HReturnVoid()); |
| 424 | } else { |
| 425 | AppendInstruction(new (allocator_) HReturn(invoke)); |
| 426 | } |
| 427 | |
| 428 | // Fill the exit block. |
| 429 | DCHECK_EQ(current_block_->GetSingleSuccessor(), graph_->GetExitBlock()); |
| 430 | current_block_ = graph_->GetExitBlock(); |
| 431 | InitializeBlockLocals(); |
| 432 | AppendInstruction(new (allocator_) HExit()); |
| 433 | } |
| 434 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 435 | ArenaBitVector* HInstructionBuilder::FindNativeDebugInfoLocations() { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 436 | // The callback gets called when the line number changes. |
| 437 | // In other words, it marks the start of new java statement. |
| 438 | struct Callback { |
| 439 | static bool Position(void* ctx, const DexFile::PositionInfo& entry) { |
| 440 | static_cast<ArenaBitVector*>(ctx)->SetBit(entry.address_); |
| 441 | return false; |
| 442 | } |
| 443 | }; |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 444 | const uint32_t num_instructions = code_item_->insns_size_in_code_units_; |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 445 | ArenaBitVector* locations = ArenaBitVector::Create(local_allocator_, |
| 446 | num_instructions, |
| 447 | /* expandable */ false, |
| 448 | kArenaAllocGraphBuilder); |
| 449 | locations->ClearAllBits(); |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 450 | dex_file_->DecodeDebugPositionInfo(code_item_, Callback::Position, locations); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 451 | // Instruction-specific tweaks. |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 452 | IterationRange<DexInstructionIterator> instructions = code_item_->Instructions(); |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 453 | for (const DexInstructionPcPair& inst : instructions) { |
| 454 | switch (inst->Opcode()) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 455 | case Instruction::MOVE_EXCEPTION: { |
| 456 | // Stop in native debugger after the exception has been moved. |
| 457 | // The compiler also expects the move at the start of basic block so |
| 458 | // we do not want to interfere by inserting native-debug-info before it. |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 459 | locations->ClearBit(inst.DexPc()); |
| 460 | DexInstructionIterator next = std::next(DexInstructionIterator(inst)); |
| 461 | DCHECK(next.DexPc() != inst.DexPc()); |
Mathieu Chartier | 2b2bef2 | 2017-10-26 17:10:19 -0700 | [diff] [blame] | 462 | if (next != instructions.end()) { |
| 463 | locations->SetBit(next.DexPc()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 464 | } |
| 465 | break; |
| 466 | } |
| 467 | default: |
| 468 | break; |
| 469 | } |
| 470 | } |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 471 | return locations; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 474 | HInstruction* HInstructionBuilder::LoadLocal(uint32_t reg_number, DataType::Type type) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 475 | HInstruction* value = (*current_locals_)[reg_number]; |
| 476 | DCHECK(value != nullptr); |
| 477 | |
| 478 | // If the operation requests a specific type, we make sure its input is of that type. |
| 479 | if (type != value->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 480 | if (DataType::IsFloatingPointType(type)) { |
Aart Bik | 3188364 | 2016-06-06 15:02:44 -0700 | [diff] [blame] | 481 | value = ssa_builder_->GetFloatOrDoubleEquivalent(value, type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 482 | } else if (type == DataType::Type::kReference) { |
Aart Bik | 3188364 | 2016-06-06 15:02:44 -0700 | [diff] [blame] | 483 | value = ssa_builder_->GetReferenceTypeEquivalent(value); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 484 | } |
Aart Bik | 3188364 | 2016-06-06 15:02:44 -0700 | [diff] [blame] | 485 | DCHECK(value != nullptr); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | return value; |
| 489 | } |
| 490 | |
| 491 | void HInstructionBuilder::UpdateLocal(uint32_t reg_number, HInstruction* stored_value) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 492 | DataType::Type stored_type = stored_value->GetType(); |
| 493 | DCHECK_NE(stored_type, DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 494 | |
| 495 | // Storing into vreg `reg_number` may implicitly invalidate the surrounding |
| 496 | // registers. Consider the following cases: |
| 497 | // (1) Storing a wide value must overwrite previous values in both `reg_number` |
| 498 | // and `reg_number+1`. We store `nullptr` in `reg_number+1`. |
| 499 | // (2) If vreg `reg_number-1` holds a wide value, writing into `reg_number` |
| 500 | // must invalidate it. We store `nullptr` in `reg_number-1`. |
| 501 | // Consequently, storing a wide value into the high vreg of another wide value |
| 502 | // will invalidate both `reg_number-1` and `reg_number+1`. |
| 503 | |
| 504 | if (reg_number != 0) { |
| 505 | HInstruction* local_low = (*current_locals_)[reg_number - 1]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 506 | if (local_low != nullptr && DataType::Is64BitType(local_low->GetType())) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 507 | // The vreg we are storing into was previously the high vreg of a pair. |
| 508 | // We need to invalidate its low vreg. |
| 509 | DCHECK((*current_locals_)[reg_number] == nullptr); |
| 510 | (*current_locals_)[reg_number - 1] = nullptr; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | (*current_locals_)[reg_number] = stored_value; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 515 | if (DataType::Is64BitType(stored_type)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 516 | // We are storing a pair. Invalidate the instruction in the high vreg. |
| 517 | (*current_locals_)[reg_number + 1] = nullptr; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | void HInstructionBuilder::InitializeParameters() { |
| 522 | DCHECK(current_block_->IsEntryBlock()); |
| 523 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 524 | // outer_compilation_unit_ is null only when unit testing. |
| 525 | if (outer_compilation_unit_ == nullptr) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 526 | return; |
| 527 | } |
| 528 | |
| 529 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 530 | uint16_t number_of_parameters = graph_->GetNumberOfInVRegs(); |
| 531 | uint16_t locals_index = graph_->GetNumberOfLocalVRegs(); |
| 532 | uint16_t parameter_index = 0; |
| 533 | |
| 534 | const DexFile::MethodId& referrer_method_id = |
| 535 | dex_file_->GetMethodId(dex_compilation_unit_->GetDexMethodIndex()); |
| 536 | if (!dex_compilation_unit_->IsStatic()) { |
| 537 | // Add the implicit 'this' argument, not expressed in the signature. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 538 | HParameterValue* parameter = new (allocator_) HParameterValue(*dex_file_, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 539 | referrer_method_id.class_idx_, |
| 540 | parameter_index++, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 541 | DataType::Type::kReference, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 542 | /* is_this */ true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 543 | AppendInstruction(parameter); |
| 544 | UpdateLocal(locals_index++, parameter); |
| 545 | number_of_parameters--; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 546 | current_this_parameter_ = parameter; |
| 547 | } else { |
| 548 | DCHECK(current_this_parameter_ == nullptr); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | const DexFile::ProtoId& proto = dex_file_->GetMethodPrototype(referrer_method_id); |
| 552 | const DexFile::TypeList* arg_types = dex_file_->GetProtoParameters(proto); |
| 553 | for (int i = 0, shorty_pos = 1; i < number_of_parameters; i++) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 554 | HParameterValue* parameter = new (allocator_) HParameterValue( |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 555 | *dex_file_, |
| 556 | arg_types->GetTypeItem(shorty_pos - 1).type_idx_, |
| 557 | parameter_index++, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 558 | DataType::FromShorty(shorty[shorty_pos]), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 559 | /* is_this */ false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 560 | ++shorty_pos; |
| 561 | AppendInstruction(parameter); |
| 562 | // Store the parameter value in the local that the dex code will use |
| 563 | // to reference that parameter. |
| 564 | UpdateLocal(locals_index++, parameter); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 565 | if (DataType::Is64BitType(parameter->GetType())) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 566 | i++; |
| 567 | locals_index++; |
| 568 | parameter_index++; |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | template<typename T> |
| 574 | void HInstructionBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 575 | HInstruction* first = LoadLocal(instruction.VRegA(), DataType::Type::kInt32); |
| 576 | HInstruction* second = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 577 | T* comparison = new (allocator_) T(first, second, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 578 | AppendInstruction(comparison); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 579 | AppendInstruction(new (allocator_) HIf(comparison, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 580 | current_block_ = nullptr; |
| 581 | } |
| 582 | |
| 583 | template<typename T> |
| 584 | void HInstructionBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 585 | HInstruction* value = LoadLocal(instruction.VRegA(), DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 586 | T* comparison = new (allocator_) T(value, graph_->GetIntConstant(0, dex_pc), dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 587 | AppendInstruction(comparison); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 588 | AppendInstruction(new (allocator_) HIf(comparison, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 589 | current_block_ = nullptr; |
| 590 | } |
| 591 | |
| 592 | template<typename T> |
| 593 | void HInstructionBuilder::Unop_12x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 594 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 595 | uint32_t dex_pc) { |
| 596 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 597 | AppendInstruction(new (allocator_) T(type, first, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 598 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 599 | } |
| 600 | |
| 601 | void HInstructionBuilder::Conversion_12x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 602 | DataType::Type input_type, |
| 603 | DataType::Type result_type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 604 | uint32_t dex_pc) { |
| 605 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 606 | AppendInstruction(new (allocator_) HTypeConversion(result_type, first, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 607 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 608 | } |
| 609 | |
| 610 | template<typename T> |
| 611 | void HInstructionBuilder::Binop_23x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 612 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 613 | uint32_t dex_pc) { |
| 614 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 615 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 616 | AppendInstruction(new (allocator_) T(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 617 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 618 | } |
| 619 | |
| 620 | template<typename T> |
| 621 | void HInstructionBuilder::Binop_23x_shift(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 622 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 623 | uint32_t dex_pc) { |
| 624 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 625 | HInstruction* second = LoadLocal(instruction.VRegC(), DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 626 | AppendInstruction(new (allocator_) T(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 627 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 628 | } |
| 629 | |
| 630 | void HInstructionBuilder::Binop_23x_cmp(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 631 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 632 | ComparisonBias bias, |
| 633 | uint32_t dex_pc) { |
| 634 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 635 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 636 | AppendInstruction(new (allocator_) HCompare(type, first, second, bias, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 637 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 638 | } |
| 639 | |
| 640 | template<typename T> |
| 641 | void HInstructionBuilder::Binop_12x_shift(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 642 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 643 | uint32_t dex_pc) { |
| 644 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 645 | HInstruction* second = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 646 | AppendInstruction(new (allocator_) T(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 647 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 648 | } |
| 649 | |
| 650 | template<typename T> |
| 651 | void HInstructionBuilder::Binop_12x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 652 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 653 | uint32_t dex_pc) { |
| 654 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 655 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 656 | AppendInstruction(new (allocator_) T(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 657 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 658 | } |
| 659 | |
| 660 | template<typename T> |
| 661 | void HInstructionBuilder::Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 662 | HInstruction* first = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 663 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s(), dex_pc); |
| 664 | if (reverse) { |
| 665 | std::swap(first, second); |
| 666 | } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 667 | AppendInstruction(new (allocator_) T(DataType::Type::kInt32, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 668 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 669 | } |
| 670 | |
| 671 | template<typename T> |
| 672 | void HInstructionBuilder::Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 673 | HInstruction* first = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 674 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b(), dex_pc); |
| 675 | if (reverse) { |
| 676 | std::swap(first, second); |
| 677 | } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 678 | AppendInstruction(new (allocator_) T(DataType::Type::kInt32, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 679 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 680 | } |
| 681 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 682 | // Does the method being compiled need any constructor barriers being inserted? |
| 683 | // (Always 'false' for methods that aren't <init>.) |
Mathieu Chartier | c4ae916 | 2016-04-07 13:19:19 -0700 | [diff] [blame] | 684 | static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, CompilerDriver* driver) { |
Igor Murashkin | 032cacd | 2017-04-06 14:40:08 -0700 | [diff] [blame] | 685 | // Can be null in unit tests only. |
| 686 | if (UNLIKELY(cu == nullptr)) { |
| 687 | return false; |
| 688 | } |
| 689 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 690 | Thread* self = Thread::Current(); |
| 691 | return cu->IsConstructor() |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 692 | && !cu->IsStatic() |
| 693 | // RequiresConstructorBarrier must only be queried for <init> methods; |
| 694 | // it's effectively "false" for every other method. |
| 695 | // |
| 696 | // See CompilerDriver::RequiresConstructBarrier for more explanation. |
Mathieu Chartier | c4ae916 | 2016-04-07 13:19:19 -0700 | [diff] [blame] | 697 | && driver->RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | // Returns true if `block` has only one successor which starts at the next |
| 701 | // dex_pc after `instruction` at `dex_pc`. |
| 702 | static bool IsFallthroughInstruction(const Instruction& instruction, |
| 703 | uint32_t dex_pc, |
| 704 | HBasicBlock* block) { |
| 705 | uint32_t next_dex_pc = dex_pc + instruction.SizeInCodeUnits(); |
| 706 | return block->GetSingleSuccessor()->GetDexPc() == next_dex_pc; |
| 707 | } |
| 708 | |
| 709 | void HInstructionBuilder::BuildSwitch(const Instruction& instruction, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 710 | HInstruction* value = LoadLocal(instruction.VRegA(), DataType::Type::kInt32); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 711 | DexSwitchTable table(instruction, dex_pc); |
| 712 | |
| 713 | if (table.GetNumEntries() == 0) { |
| 714 | // Empty Switch. Code falls through to the next block. |
| 715 | DCHECK(IsFallthroughInstruction(instruction, dex_pc, current_block_)); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 716 | AppendInstruction(new (allocator_) HGoto(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 717 | } else if (table.ShouldBuildDecisionTree()) { |
| 718 | for (DexSwitchTableIterator it(table); !it.Done(); it.Advance()) { |
| 719 | HInstruction* case_value = graph_->GetIntConstant(it.CurrentKey(), dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 720 | HEqual* comparison = new (allocator_) HEqual(value, case_value, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 721 | AppendInstruction(comparison); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 722 | AppendInstruction(new (allocator_) HIf(comparison, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 723 | |
| 724 | if (!it.IsLast()) { |
| 725 | current_block_ = FindBlockStartingAt(it.GetDexPcForCurrentIndex()); |
| 726 | } |
| 727 | } |
| 728 | } else { |
| 729 | AppendInstruction( |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 730 | new (allocator_) HPackedSwitch(table.GetEntryAt(0), table.GetNumEntries(), value, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | current_block_ = nullptr; |
| 734 | } |
| 735 | |
| 736 | void HInstructionBuilder::BuildReturn(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 737 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 738 | uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 739 | if (type == DataType::Type::kVoid) { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 740 | // Only <init> (which is a return-void) could possibly have a constructor fence. |
Igor Murashkin | 032cacd | 2017-04-06 14:40:08 -0700 | [diff] [blame] | 741 | // This may insert additional redundant constructor fences from the super constructors. |
| 742 | // TODO: remove redundant constructor fences (b/36656456). |
| 743 | if (RequiresConstructorBarrier(dex_compilation_unit_, compiler_driver_)) { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 744 | // Compiling instance constructor. |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 745 | DCHECK_STREQ("<init>", graph_->GetMethodName()); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 746 | |
| 747 | HInstruction* fence_target = current_this_parameter_; |
| 748 | DCHECK(fence_target != nullptr); |
| 749 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 750 | AppendInstruction(new (allocator_) HConstructorFence(fence_target, dex_pc, allocator_)); |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 751 | MaybeRecordStat( |
| 752 | compilation_stats_, |
| 753 | MethodCompilationStat::kConstructorFenceGeneratedFinal); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 754 | } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 755 | AppendInstruction(new (allocator_) HReturnVoid(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 756 | } else { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 757 | DCHECK(!RequiresConstructorBarrier(dex_compilation_unit_, compiler_driver_)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 758 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 759 | AppendInstruction(new (allocator_) HReturn(value, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 760 | } |
| 761 | current_block_ = nullptr; |
| 762 | } |
| 763 | |
| 764 | static InvokeType GetInvokeTypeFromOpCode(Instruction::Code opcode) { |
| 765 | switch (opcode) { |
| 766 | case Instruction::INVOKE_STATIC: |
| 767 | case Instruction::INVOKE_STATIC_RANGE: |
| 768 | return kStatic; |
| 769 | case Instruction::INVOKE_DIRECT: |
| 770 | case Instruction::INVOKE_DIRECT_RANGE: |
| 771 | return kDirect; |
| 772 | case Instruction::INVOKE_VIRTUAL: |
| 773 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 774 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 775 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: |
| 776 | return kVirtual; |
| 777 | case Instruction::INVOKE_INTERFACE: |
| 778 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 779 | return kInterface; |
| 780 | case Instruction::INVOKE_SUPER_RANGE: |
| 781 | case Instruction::INVOKE_SUPER: |
| 782 | return kSuper; |
| 783 | default: |
| 784 | LOG(FATAL) << "Unexpected invoke opcode: " << opcode; |
| 785 | UNREACHABLE(); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | ArtMethod* HInstructionBuilder::ResolveMethod(uint16_t method_idx, InvokeType invoke_type) { |
| 790 | ScopedObjectAccess soa(Thread::Current()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 791 | |
| 792 | ClassLinker* class_linker = dex_compilation_unit_->GetClassLinker(); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 793 | Handle<mirror::ClassLoader> class_loader = dex_compilation_unit_->GetClassLoader(); |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 794 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 795 | ArtMethod* resolved_method = |
| 796 | class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( |
| 797 | *dex_compilation_unit_->GetDexFile(), |
| 798 | method_idx, |
| 799 | dex_compilation_unit_->GetDexCache(), |
| 800 | class_loader, |
| 801 | graph_->GetArtMethod(), |
| 802 | invoke_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 803 | |
| 804 | if (UNLIKELY(resolved_method == nullptr)) { |
| 805 | // Clean up any exception left by type resolution. |
| 806 | soa.Self()->ClearException(); |
| 807 | return nullptr; |
| 808 | } |
| 809 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 810 | // The referrer may be unresolved for AOT if we're compiling a class that cannot be |
| 811 | // resolved because, for example, we don't find a superclass in the classpath. |
| 812 | if (graph_->GetArtMethod() == nullptr) { |
| 813 | // The class linker cannot check access without a referrer, so we have to do it. |
| 814 | // Fall back to HInvokeUnresolved if the method isn't public. |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 815 | if (!resolved_method->IsPublic()) { |
| 816 | return nullptr; |
| 817 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | // We have to special case the invoke-super case, as ClassLinker::ResolveMethod does not. |
| 821 | // We need to look at the referrer's super class vtable. We need to do this to know if we need to |
| 822 | // make this an invoke-unresolved to handle cross-dex invokes or abstract super methods, both of |
| 823 | // which require runtime handling. |
| 824 | if (invoke_type == kSuper) { |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 825 | ObjPtr<mirror::Class> compiling_class = GetCompilingClass(); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 826 | if (compiling_class == nullptr) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 827 | // We could not determine the method's class we need to wait until runtime. |
| 828 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 829 | return nullptr; |
| 830 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 831 | ObjPtr<mirror::Class> referenced_class = class_linker->LookupResolvedType( |
| 832 | *dex_compilation_unit_->GetDexFile(), |
| 833 | dex_compilation_unit_->GetDexFile()->GetMethodId(method_idx).class_idx_, |
| 834 | dex_compilation_unit_->GetDexCache().Get(), |
| 835 | class_loader.Get()); |
| 836 | DCHECK(referenced_class != nullptr); // We have already resolved a method from this class. |
| 837 | if (!referenced_class->IsAssignableFrom(compiling_class)) { |
Aart Bik | f663e34 | 2016-04-04 17:28:59 -0700 | [diff] [blame] | 838 | // We cannot statically determine the target method. The runtime will throw a |
| 839 | // NoSuchMethodError on this one. |
| 840 | return nullptr; |
| 841 | } |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 842 | ArtMethod* actual_method; |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 843 | if (referenced_class->IsInterface()) { |
| 844 | actual_method = referenced_class->FindVirtualMethodForInterfaceSuper( |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 845 | resolved_method, class_linker->GetImagePointerSize()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 846 | } else { |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 847 | uint16_t vtable_index = resolved_method->GetMethodIndex(); |
| 848 | actual_method = compiling_class->GetSuperClass()->GetVTableEntry( |
| 849 | vtable_index, class_linker->GetImagePointerSize()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 850 | } |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 851 | if (actual_method != resolved_method && |
| 852 | !IsSameDexFile(*actual_method->GetDexFile(), *dex_compilation_unit_->GetDexFile())) { |
| 853 | // The back-end code generator relies on this check in order to ensure that it will not |
| 854 | // attempt to read the dex_cache with a dex_method_index that is not from the correct |
| 855 | // dex_file. If we didn't do this check then the dex_method_index will not be updated in the |
| 856 | // builder, which means that the code-generator (and compiler driver during sharpening and |
| 857 | // inliner, maybe) might invoke an incorrect method. |
| 858 | // TODO: The actual method could still be referenced in the current dex file, so we |
| 859 | // could try locating it. |
| 860 | // TODO: Remove the dex_file restriction. |
| 861 | return nullptr; |
| 862 | } |
| 863 | if (!actual_method->IsInvokable()) { |
| 864 | // Fail if the actual method cannot be invoked. Otherwise, the runtime resolution stub |
| 865 | // could resolve the callee to the wrong method. |
| 866 | return nullptr; |
| 867 | } |
| 868 | resolved_method = actual_method; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 869 | } |
| 870 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 871 | return resolved_method; |
| 872 | } |
| 873 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 874 | static bool IsStringConstructor(ArtMethod* method) { |
| 875 | ScopedObjectAccess soa(Thread::Current()); |
| 876 | return method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); |
| 877 | } |
| 878 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 879 | bool HInstructionBuilder::BuildInvoke(const Instruction& instruction, |
| 880 | uint32_t dex_pc, |
| 881 | uint32_t method_idx, |
| 882 | uint32_t number_of_vreg_arguments, |
| 883 | bool is_range, |
| 884 | uint32_t* args, |
| 885 | uint32_t register_index) { |
| 886 | InvokeType invoke_type = GetInvokeTypeFromOpCode(instruction.Opcode()); |
| 887 | const char* descriptor = dex_file_->GetMethodShorty(method_idx); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 888 | DataType::Type return_type = DataType::FromShorty(descriptor[0]); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 889 | |
| 890 | // Remove the return type from the 'proto'. |
| 891 | size_t number_of_arguments = strlen(descriptor) - 1; |
| 892 | if (invoke_type != kStatic) { // instance call |
| 893 | // One extra argument for 'this'. |
| 894 | number_of_arguments++; |
| 895 | } |
| 896 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 897 | ArtMethod* resolved_method = ResolveMethod(method_idx, invoke_type); |
| 898 | |
| 899 | if (UNLIKELY(resolved_method == nullptr)) { |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 900 | MaybeRecordStat(compilation_stats_, |
| 901 | MethodCompilationStat::kUnresolvedMethod); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 902 | HInvoke* invoke = new (allocator_) HInvokeUnresolved(allocator_, |
| 903 | number_of_arguments, |
| 904 | return_type, |
| 905 | dex_pc, |
| 906 | method_idx, |
| 907 | invoke_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 908 | return HandleInvoke(invoke, |
| 909 | number_of_vreg_arguments, |
| 910 | args, |
| 911 | register_index, |
| 912 | is_range, |
| 913 | descriptor, |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 914 | nullptr, /* clinit_check */ |
| 915 | true /* is_unresolved */); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 918 | // Replace calls to String.<init> with StringFactory. |
| 919 | if (IsStringConstructor(resolved_method)) { |
| 920 | uint32_t string_init_entry_point = WellKnownClasses::StringInitToEntryPoint(resolved_method); |
| 921 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 922 | HInvokeStaticOrDirect::MethodLoadKind::kStringInit, |
| 923 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 924 | dchecked_integral_cast<uint64_t>(string_init_entry_point) |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 925 | }; |
| 926 | MethodReference target_method(dex_file_, method_idx); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 927 | HInvoke* invoke = new (allocator_) HInvokeStaticOrDirect( |
| 928 | allocator_, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 929 | number_of_arguments - 1, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 930 | DataType::Type::kReference /*return_type */, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 931 | dex_pc, |
| 932 | method_idx, |
| 933 | nullptr, |
| 934 | dispatch_info, |
| 935 | invoke_type, |
| 936 | target_method, |
| 937 | HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit); |
| 938 | return HandleStringInit(invoke, |
| 939 | number_of_vreg_arguments, |
| 940 | args, |
| 941 | register_index, |
| 942 | is_range, |
| 943 | descriptor); |
| 944 | } |
| 945 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 946 | // Potential class initialization check, in the case of a static method call. |
| 947 | HClinitCheck* clinit_check = nullptr; |
| 948 | HInvoke* invoke = nullptr; |
| 949 | if (invoke_type == kDirect || invoke_type == kStatic || invoke_type == kSuper) { |
| 950 | // By default, consider that the called method implicitly requires |
| 951 | // an initialization check of its declaring method. |
| 952 | HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement |
| 953 | = HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit; |
| 954 | ScopedObjectAccess soa(Thread::Current()); |
| 955 | if (invoke_type == kStatic) { |
| 956 | clinit_check = ProcessClinitCheckForInvoke( |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 957 | dex_pc, resolved_method, &clinit_check_requirement); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 958 | } else if (invoke_type == kSuper) { |
| 959 | if (IsSameDexFile(*resolved_method->GetDexFile(), *dex_compilation_unit_->GetDexFile())) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 960 | // Update the method index to the one resolved. Note that this may be a no-op if |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 961 | // we resolved to the method referenced by the instruction. |
| 962 | method_idx = resolved_method->GetDexMethodIndex(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
| 966 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 967 | HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 968 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 969 | 0u |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 970 | }; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 971 | MethodReference target_method(resolved_method->GetDexFile(), |
| 972 | resolved_method->GetDexMethodIndex()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 973 | invoke = new (allocator_) HInvokeStaticOrDirect(allocator_, |
| 974 | number_of_arguments, |
| 975 | return_type, |
| 976 | dex_pc, |
| 977 | method_idx, |
| 978 | resolved_method, |
| 979 | dispatch_info, |
| 980 | invoke_type, |
| 981 | target_method, |
| 982 | clinit_check_requirement); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 983 | } else if (invoke_type == kVirtual) { |
| 984 | ScopedObjectAccess soa(Thread::Current()); // Needed for the method index |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 985 | invoke = new (allocator_) HInvokeVirtual(allocator_, |
| 986 | number_of_arguments, |
| 987 | return_type, |
| 988 | dex_pc, |
| 989 | method_idx, |
| 990 | resolved_method, |
| 991 | resolved_method->GetMethodIndex()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 992 | } else { |
| 993 | DCHECK_EQ(invoke_type, kInterface); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 994 | ScopedObjectAccess soa(Thread::Current()); // Needed for the IMT index. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 995 | invoke = new (allocator_) HInvokeInterface(allocator_, |
| 996 | number_of_arguments, |
| 997 | return_type, |
| 998 | dex_pc, |
| 999 | method_idx, |
| 1000 | resolved_method, |
| 1001 | ImTable::GetImtIndex(resolved_method)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | return HandleInvoke(invoke, |
| 1005 | number_of_vreg_arguments, |
| 1006 | args, |
| 1007 | register_index, |
| 1008 | is_range, |
| 1009 | descriptor, |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 1010 | clinit_check, |
| 1011 | false /* is_unresolved */); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1014 | bool HInstructionBuilder::BuildInvokePolymorphic(const Instruction& instruction ATTRIBUTE_UNUSED, |
| 1015 | uint32_t dex_pc, |
| 1016 | uint32_t method_idx, |
| 1017 | uint32_t proto_idx, |
| 1018 | uint32_t number_of_vreg_arguments, |
| 1019 | bool is_range, |
| 1020 | uint32_t* args, |
| 1021 | uint32_t register_index) { |
| 1022 | const char* descriptor = dex_file_->GetShorty(proto_idx); |
| 1023 | DCHECK_EQ(1 + ArtMethod::NumArgRegisters(descriptor), number_of_vreg_arguments); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1024 | DataType::Type return_type = DataType::FromShorty(descriptor[0]); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1025 | size_t number_of_arguments = strlen(descriptor); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1026 | HInvoke* invoke = new (allocator_) HInvokePolymorphic(allocator_, |
| 1027 | number_of_arguments, |
| 1028 | return_type, |
| 1029 | dex_pc, |
| 1030 | method_idx); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1031 | return HandleInvoke(invoke, |
| 1032 | number_of_vreg_arguments, |
| 1033 | args, |
| 1034 | register_index, |
| 1035 | is_range, |
| 1036 | descriptor, |
| 1037 | nullptr /* clinit_check */, |
| 1038 | false /* is_unresolved */); |
| 1039 | } |
| 1040 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1041 | HNewInstance* HInstructionBuilder::BuildNewInstance(dex::TypeIndex type_index, uint32_t dex_pc) { |
Vladimir Marko | 3cd50df | 2016-04-13 19:29:26 +0100 | [diff] [blame] | 1042 | ScopedObjectAccess soa(Thread::Current()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1043 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1044 | HLoadClass* load_class = BuildLoadClass(type_index, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1045 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1046 | HInstruction* cls = load_class; |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1047 | Handle<mirror::Class> klass = load_class->GetClass(); |
| 1048 | |
| 1049 | if (!IsInitialized(klass)) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1050 | cls = new (allocator_) HClinitCheck(load_class, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1051 | AppendInstruction(cls); |
| 1052 | } |
| 1053 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1054 | // Only the access check entrypoint handles the finalizable class case. If we |
| 1055 | // need access checks, then we haven't resolved the method and the class may |
| 1056 | // again be finalizable. |
| 1057 | QuickEntrypointEnum entrypoint = kQuickAllocObjectInitialized; |
| 1058 | if (load_class->NeedsAccessCheck() || klass->IsFinalizable() || !klass->IsInstantiable()) { |
| 1059 | entrypoint = kQuickAllocObjectWithChecks; |
| 1060 | } |
| 1061 | |
| 1062 | // Consider classes we haven't resolved as potentially finalizable. |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1063 | bool finalizable = (klass == nullptr) || klass->IsFinalizable(); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1064 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1065 | HNewInstance* new_instance = new (allocator_) HNewInstance( |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1066 | cls, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1067 | dex_pc, |
| 1068 | type_index, |
| 1069 | *dex_compilation_unit_->GetDexFile(), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1070 | finalizable, |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1071 | entrypoint); |
| 1072 | AppendInstruction(new_instance); |
| 1073 | |
| 1074 | return new_instance; |
| 1075 | } |
| 1076 | |
| 1077 | void HInstructionBuilder::BuildConstructorFenceForAllocation(HInstruction* allocation) { |
| 1078 | DCHECK(allocation != nullptr && |
George Burgess IV | f207299 | 2017-05-23 15:36:41 -0700 | [diff] [blame] | 1079 | (allocation->IsNewInstance() || |
| 1080 | allocation->IsNewArray())); // corresponding to "new" keyword in JLS. |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1081 | |
| 1082 | if (allocation->IsNewInstance()) { |
| 1083 | // STRING SPECIAL HANDLING: |
| 1084 | // ------------------------------- |
| 1085 | // Strings have a real HNewInstance node but they end up always having 0 uses. |
| 1086 | // All uses of a String HNewInstance are always transformed to replace their input |
| 1087 | // of the HNewInstance with an input of the invoke to StringFactory. |
| 1088 | // |
| 1089 | // Do not emit an HConstructorFence here since it can inhibit some String new-instance |
| 1090 | // optimizations (to pass checker tests that rely on those optimizations). |
| 1091 | HNewInstance* new_inst = allocation->AsNewInstance(); |
| 1092 | HLoadClass* load_class = new_inst->GetLoadClass(); |
| 1093 | |
| 1094 | Thread* self = Thread::Current(); |
| 1095 | ScopedObjectAccess soa(self); |
| 1096 | StackHandleScope<1> hs(self); |
| 1097 | Handle<mirror::Class> klass = load_class->GetClass(); |
| 1098 | if (klass != nullptr && klass->IsStringClass()) { |
| 1099 | return; |
| 1100 | // Note: Do not use allocation->IsStringAlloc which requires |
| 1101 | // a valid ReferenceTypeInfo, but that doesn't get made until after reference type |
| 1102 | // propagation (and instruction builder is too early). |
| 1103 | } |
| 1104 | // (In terms of correctness, the StringFactory needs to provide its own |
| 1105 | // default initialization barrier, see below.) |
| 1106 | } |
| 1107 | |
| 1108 | // JLS 17.4.5 "Happens-before Order" describes: |
| 1109 | // |
| 1110 | // The default initialization of any object happens-before any other actions (other than |
| 1111 | // default-writes) of a program. |
| 1112 | // |
| 1113 | // In our implementation the default initialization of an object to type T means |
| 1114 | // setting all of its initial data (object[0..size)) to 0, and setting the |
| 1115 | // object's class header (i.e. object.getClass() == T.class). |
| 1116 | // |
| 1117 | // In practice this fence ensures that the writes to the object header |
| 1118 | // are visible to other threads if this object escapes the current thread. |
| 1119 | // (and in theory the 0-initializing, but that happens automatically |
| 1120 | // when new memory pages are mapped in by the OS). |
| 1121 | HConstructorFence* ctor_fence = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1122 | new (allocator_) HConstructorFence(allocation, allocation->GetDexPc(), allocator_); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1123 | AppendInstruction(ctor_fence); |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 1124 | MaybeRecordStat( |
| 1125 | compilation_stats_, |
| 1126 | MethodCompilationStat::kConstructorFenceGeneratedNew); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static bool IsSubClass(mirror::Class* to_test, mirror::Class* super_class) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1130 | REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1131 | return to_test != nullptr && !to_test->IsInterface() && to_test->IsSubClass(super_class); |
| 1132 | } |
| 1133 | |
| 1134 | bool HInstructionBuilder::IsInitialized(Handle<mirror::Class> cls) const { |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1135 | if (cls == nullptr) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1136 | return false; |
| 1137 | } |
| 1138 | |
| 1139 | // `CanAssumeClassIsLoaded` will return true if we're JITting, or will |
| 1140 | // check whether the class is in an image for the AOT compilation. |
| 1141 | if (cls->IsInitialized() && |
| 1142 | compiler_driver_->CanAssumeClassIsLoaded(cls.Get())) { |
| 1143 | return true; |
| 1144 | } |
| 1145 | |
| 1146 | if (IsSubClass(GetOutermostCompilingClass(), cls.Get())) { |
| 1147 | return true; |
| 1148 | } |
| 1149 | |
| 1150 | // TODO: We should walk over the inlined methods, but we don't pass |
| 1151 | // that information to the builder. |
| 1152 | if (IsSubClass(GetCompilingClass(), cls.Get())) { |
| 1153 | return true; |
| 1154 | } |
| 1155 | |
| 1156 | return false; |
| 1157 | } |
| 1158 | |
| 1159 | HClinitCheck* HInstructionBuilder::ProcessClinitCheckForInvoke( |
| 1160 | uint32_t dex_pc, |
| 1161 | ArtMethod* resolved_method, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1162 | HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1163 | Handle<mirror::Class> klass = handles_->NewHandle(resolved_method->GetDeclaringClass()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1164 | |
| 1165 | HClinitCheck* clinit_check = nullptr; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1166 | if (IsInitialized(klass)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1167 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1168 | } else { |
| 1169 | HLoadClass* cls = BuildLoadClass(klass->GetDexTypeIndex(), |
| 1170 | klass->GetDexFile(), |
| 1171 | klass, |
| 1172 | dex_pc, |
| 1173 | /* needs_access_check */ false); |
| 1174 | if (cls != nullptr) { |
| 1175 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1176 | clinit_check = new (allocator_) HClinitCheck(cls, dex_pc); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1177 | AppendInstruction(clinit_check); |
| 1178 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1179 | } |
| 1180 | return clinit_check; |
| 1181 | } |
| 1182 | |
| 1183 | bool HInstructionBuilder::SetupInvokeArguments(HInvoke* invoke, |
| 1184 | uint32_t number_of_vreg_arguments, |
| 1185 | uint32_t* args, |
| 1186 | uint32_t register_index, |
| 1187 | bool is_range, |
| 1188 | const char* descriptor, |
| 1189 | size_t start_index, |
| 1190 | size_t* argument_index) { |
| 1191 | uint32_t descriptor_index = 1; // Skip the return type. |
| 1192 | |
| 1193 | for (size_t i = start_index; |
| 1194 | // Make sure we don't go over the expected arguments or over the number of |
| 1195 | // dex registers given. If the instruction was seen as dead by the verifier, |
| 1196 | // it hasn't been properly checked. |
| 1197 | (i < number_of_vreg_arguments) && (*argument_index < invoke->GetNumberOfArguments()); |
| 1198 | i++, (*argument_index)++) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1199 | DataType::Type type = DataType::FromShorty(descriptor[descriptor_index++]); |
| 1200 | bool is_wide = (type == DataType::Type::kInt64) || (type == DataType::Type::kFloat64); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1201 | if (!is_range |
| 1202 | && is_wide |
| 1203 | && ((i + 1 == number_of_vreg_arguments) || (args[i] + 1 != args[i + 1]))) { |
| 1204 | // Longs and doubles should be in pairs, that is, sequential registers. The verifier should |
| 1205 | // reject any class where this is violated. However, the verifier only does these checks |
| 1206 | // on non trivially dead instructions, so we just bailout the compilation. |
| 1207 | VLOG(compiler) << "Did not compile " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1208 | << dex_file_->PrettyMethod(dex_compilation_unit_->GetDexMethodIndex()) |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1209 | << " because of non-sequential dex register pair in wide argument"; |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1210 | MaybeRecordStat(compilation_stats_, |
| 1211 | MethodCompilationStat::kNotCompiledMalformedOpcode); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1212 | return false; |
| 1213 | } |
| 1214 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 1215 | invoke->SetArgumentAt(*argument_index, arg); |
| 1216 | if (is_wide) { |
| 1217 | i++; |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | if (*argument_index != invoke->GetNumberOfArguments()) { |
| 1222 | VLOG(compiler) << "Did not compile " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1223 | << dex_file_->PrettyMethod(dex_compilation_unit_->GetDexMethodIndex()) |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1224 | << " because of wrong number of arguments in invoke instruction"; |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1225 | MaybeRecordStat(compilation_stats_, |
| 1226 | MethodCompilationStat::kNotCompiledMalformedOpcode); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1227 | return false; |
| 1228 | } |
| 1229 | |
| 1230 | if (invoke->IsInvokeStaticOrDirect() && |
| 1231 | HInvokeStaticOrDirect::NeedsCurrentMethodInput( |
| 1232 | invoke->AsInvokeStaticOrDirect()->GetMethodLoadKind())) { |
| 1233 | invoke->SetArgumentAt(*argument_index, graph_->GetCurrentMethod()); |
| 1234 | (*argument_index)++; |
| 1235 | } |
| 1236 | |
| 1237 | return true; |
| 1238 | } |
| 1239 | |
| 1240 | bool HInstructionBuilder::HandleInvoke(HInvoke* invoke, |
| 1241 | uint32_t number_of_vreg_arguments, |
| 1242 | uint32_t* args, |
| 1243 | uint32_t register_index, |
| 1244 | bool is_range, |
| 1245 | const char* descriptor, |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 1246 | HClinitCheck* clinit_check, |
| 1247 | bool is_unresolved) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1248 | DCHECK(!invoke->IsInvokeStaticOrDirect() || !invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 1249 | |
| 1250 | size_t start_index = 0; |
| 1251 | size_t argument_index = 0; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 1252 | if (invoke->GetInvokeType() != InvokeType::kStatic) { // Instance call. |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 1253 | uint32_t obj_reg = is_range ? register_index : args[0]; |
| 1254 | HInstruction* arg = is_unresolved |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1255 | ? LoadLocal(obj_reg, DataType::Type::kReference) |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 1256 | : LoadNullCheckedLocal(obj_reg, invoke->GetDexPc()); |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 1257 | invoke->SetArgumentAt(0, arg); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1258 | start_index = 1; |
| 1259 | argument_index = 1; |
| 1260 | } |
| 1261 | |
| 1262 | if (!SetupInvokeArguments(invoke, |
| 1263 | number_of_vreg_arguments, |
| 1264 | args, |
| 1265 | register_index, |
| 1266 | is_range, |
| 1267 | descriptor, |
| 1268 | start_index, |
| 1269 | &argument_index)) { |
| 1270 | return false; |
| 1271 | } |
| 1272 | |
| 1273 | if (clinit_check != nullptr) { |
| 1274 | // Add the class initialization check as last input of `invoke`. |
| 1275 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 1276 | DCHECK(invoke->AsInvokeStaticOrDirect()->GetClinitCheckRequirement() |
| 1277 | == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit); |
| 1278 | invoke->SetArgumentAt(argument_index, clinit_check); |
| 1279 | argument_index++; |
| 1280 | } |
| 1281 | |
| 1282 | AppendInstruction(invoke); |
| 1283 | latest_result_ = invoke; |
| 1284 | |
| 1285 | return true; |
| 1286 | } |
| 1287 | |
| 1288 | bool HInstructionBuilder::HandleStringInit(HInvoke* invoke, |
| 1289 | uint32_t number_of_vreg_arguments, |
| 1290 | uint32_t* args, |
| 1291 | uint32_t register_index, |
| 1292 | bool is_range, |
| 1293 | const char* descriptor) { |
| 1294 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 1295 | DCHECK(invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 1296 | |
| 1297 | size_t start_index = 1; |
| 1298 | size_t argument_index = 0; |
| 1299 | if (!SetupInvokeArguments(invoke, |
| 1300 | number_of_vreg_arguments, |
| 1301 | args, |
| 1302 | register_index, |
| 1303 | is_range, |
| 1304 | descriptor, |
| 1305 | start_index, |
| 1306 | &argument_index)) { |
| 1307 | return false; |
| 1308 | } |
| 1309 | |
| 1310 | AppendInstruction(invoke); |
| 1311 | |
| 1312 | // This is a StringFactory call, not an actual String constructor. Its result |
| 1313 | // replaces the empty String pre-allocated by NewInstance. |
| 1314 | uint32_t orig_this_reg = is_range ? register_index : args[0]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1315 | HInstruction* arg_this = LoadLocal(orig_this_reg, DataType::Type::kReference); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1316 | |
| 1317 | // Replacing the NewInstance might render it redundant. Keep a list of these |
| 1318 | // to be visited once it is clear whether it is has remaining uses. |
| 1319 | if (arg_this->IsNewInstance()) { |
| 1320 | ssa_builder_->AddUninitializedString(arg_this->AsNewInstance()); |
| 1321 | } else { |
| 1322 | DCHECK(arg_this->IsPhi()); |
| 1323 | // NewInstance is not the direct input of the StringFactory call. It might |
| 1324 | // be redundant but optimizing this case is not worth the effort. |
| 1325 | } |
| 1326 | |
| 1327 | // Walk over all vregs and replace any occurrence of `arg_this` with `invoke`. |
| 1328 | for (size_t vreg = 0, e = current_locals_->size(); vreg < e; ++vreg) { |
| 1329 | if ((*current_locals_)[vreg] == arg_this) { |
| 1330 | (*current_locals_)[vreg] = invoke; |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | return true; |
| 1335 | } |
| 1336 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1337 | static DataType::Type GetFieldAccessType(const DexFile& dex_file, uint16_t field_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1338 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 1339 | const char* type = dex_file.GetFieldTypeDescriptor(field_id); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1340 | return DataType::FromShorty(type[0]); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | bool HInstructionBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
| 1344 | uint32_t dex_pc, |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 1345 | bool is_put, |
| 1346 | size_t quicken_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1347 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 1348 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 1349 | uint16_t field_index; |
| 1350 | if (instruction.IsQuickened()) { |
| 1351 | if (!CanDecodeQuickenedInfo()) { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 1352 | VLOG(compiler) << "Not compiled: Could not decode quickened instruction " |
| 1353 | << instruction.Opcode(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1354 | return false; |
| 1355 | } |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 1356 | field_index = LookupQuickenedInfo(quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1357 | } else { |
| 1358 | field_index = instruction.VRegC_22c(); |
| 1359 | } |
| 1360 | |
| 1361 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1362 | ArtField* resolved_field = ResolveField(field_index, /* is_static */ false, is_put); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1363 | |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 1364 | // Generate an explicit null check on the reference, unless the field access |
| 1365 | // is unresolved. In that case, we rely on the runtime to perform various |
| 1366 | // checks first, followed by a null check. |
| 1367 | HInstruction* object = (resolved_field == nullptr) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1368 | ? LoadLocal(obj_reg, DataType::Type::kReference) |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 1369 | : LoadNullCheckedLocal(obj_reg, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1370 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1371 | DataType::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1372 | if (is_put) { |
| 1373 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 1374 | HInstruction* field_set = nullptr; |
| 1375 | if (resolved_field == nullptr) { |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1376 | MaybeRecordStat(compilation_stats_, |
| 1377 | MethodCompilationStat::kUnresolvedField); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1378 | field_set = new (allocator_) HUnresolvedInstanceFieldSet(object, |
| 1379 | value, |
| 1380 | field_type, |
| 1381 | field_index, |
| 1382 | dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1383 | } else { |
| 1384 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1385 | field_set = new (allocator_) HInstanceFieldSet(object, |
| 1386 | value, |
| 1387 | resolved_field, |
| 1388 | field_type, |
| 1389 | resolved_field->GetOffset(), |
| 1390 | resolved_field->IsVolatile(), |
| 1391 | field_index, |
| 1392 | class_def_index, |
| 1393 | *dex_file_, |
| 1394 | dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1395 | } |
| 1396 | AppendInstruction(field_set); |
| 1397 | } else { |
| 1398 | HInstruction* field_get = nullptr; |
| 1399 | if (resolved_field == nullptr) { |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1400 | MaybeRecordStat(compilation_stats_, |
| 1401 | MethodCompilationStat::kUnresolvedField); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1402 | field_get = new (allocator_) HUnresolvedInstanceFieldGet(object, |
| 1403 | field_type, |
| 1404 | field_index, |
| 1405 | dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1406 | } else { |
| 1407 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1408 | field_get = new (allocator_) HInstanceFieldGet(object, |
| 1409 | resolved_field, |
| 1410 | field_type, |
| 1411 | resolved_field->GetOffset(), |
| 1412 | resolved_field->IsVolatile(), |
| 1413 | field_index, |
| 1414 | class_def_index, |
| 1415 | *dex_file_, |
| 1416 | dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1417 | } |
| 1418 | AppendInstruction(field_get); |
| 1419 | UpdateLocal(source_or_dest_reg, field_get); |
| 1420 | } |
| 1421 | |
| 1422 | return true; |
| 1423 | } |
| 1424 | |
| 1425 | static mirror::Class* GetClassFrom(CompilerDriver* driver, |
| 1426 | const DexCompilationUnit& compilation_unit) { |
| 1427 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 1428 | Handle<mirror::ClassLoader> class_loader = compilation_unit.GetClassLoader(); |
Vladimir Marko | 3cd50df | 2016-04-13 19:29:26 +0100 | [diff] [blame] | 1429 | Handle<mirror::DexCache> dex_cache = compilation_unit.GetDexCache(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1430 | |
| 1431 | return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit); |
| 1432 | } |
| 1433 | |
| 1434 | mirror::Class* HInstructionBuilder::GetOutermostCompilingClass() const { |
| 1435 | return GetClassFrom(compiler_driver_, *outer_compilation_unit_); |
| 1436 | } |
| 1437 | |
| 1438 | mirror::Class* HInstructionBuilder::GetCompilingClass() const { |
| 1439 | return GetClassFrom(compiler_driver_, *dex_compilation_unit_); |
| 1440 | } |
| 1441 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1442 | bool HInstructionBuilder::IsOutermostCompilingClass(dex::TypeIndex type_index) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1443 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 1444 | StackHandleScope<2> hs(soa.Self()); |
Vladimir Marko | 3cd50df | 2016-04-13 19:29:26 +0100 | [diff] [blame] | 1445 | Handle<mirror::DexCache> dex_cache = dex_compilation_unit_->GetDexCache(); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 1446 | Handle<mirror::ClassLoader> class_loader = dex_compilation_unit_->GetClassLoader(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1447 | Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass( |
| 1448 | soa, dex_cache, class_loader, type_index, dex_compilation_unit_))); |
| 1449 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
| 1450 | |
| 1451 | // GetOutermostCompilingClass returns null when the class is unresolved |
| 1452 | // (e.g. if it derives from an unresolved class). This is bogus knowing that |
| 1453 | // we are compiling it. |
| 1454 | // When this happens we cannot establish a direct relation between the current |
| 1455 | // class and the outer class, so we return false. |
| 1456 | // (Note that this is only used for optimizing invokes and field accesses) |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1457 | return (cls != nullptr) && (outer_class.Get() == cls.Get()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | void HInstructionBuilder::BuildUnresolvedStaticFieldAccess(const Instruction& instruction, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 1461 | uint32_t dex_pc, |
| 1462 | bool is_put, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1463 | DataType::Type field_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1464 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1465 | uint16_t field_index = instruction.VRegB_21c(); |
| 1466 | |
| 1467 | if (is_put) { |
| 1468 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 1469 | AppendInstruction( |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1470 | new (allocator_) HUnresolvedStaticFieldSet(value, field_type, field_index, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1471 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1472 | AppendInstruction(new (allocator_) HUnresolvedStaticFieldGet(field_type, field_index, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1473 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1474 | } |
| 1475 | } |
| 1476 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1477 | ArtField* HInstructionBuilder::ResolveField(uint16_t field_idx, bool is_static, bool is_put) { |
| 1478 | ScopedObjectAccess soa(Thread::Current()); |
| 1479 | StackHandleScope<2> hs(soa.Self()); |
| 1480 | |
| 1481 | ClassLinker* class_linker = dex_compilation_unit_->GetClassLinker(); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 1482 | Handle<mirror::ClassLoader> class_loader = dex_compilation_unit_->GetClassLoader(); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1483 | Handle<mirror::Class> compiling_class(hs.NewHandle(GetCompilingClass())); |
| 1484 | |
| 1485 | ArtField* resolved_field = class_linker->ResolveField(*dex_compilation_unit_->GetDexFile(), |
| 1486 | field_idx, |
| 1487 | dex_compilation_unit_->GetDexCache(), |
| 1488 | class_loader, |
| 1489 | is_static); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1490 | if (UNLIKELY(resolved_field == nullptr)) { |
| 1491 | // Clean up any exception left by type resolution. |
| 1492 | soa.Self()->ClearException(); |
| 1493 | return nullptr; |
| 1494 | } |
| 1495 | |
| 1496 | // Check static/instance. The class linker has a fast path for looking into the dex cache |
| 1497 | // and does not check static/instance if it hits it. |
| 1498 | if (UNLIKELY(resolved_field->IsStatic() != is_static)) { |
| 1499 | return nullptr; |
| 1500 | } |
| 1501 | |
| 1502 | // Check access. |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1503 | if (compiling_class == nullptr) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1504 | if (!resolved_field->IsPublic()) { |
| 1505 | return nullptr; |
| 1506 | } |
| 1507 | } else if (!compiling_class->CanAccessResolvedField(resolved_field->GetDeclaringClass(), |
| 1508 | resolved_field, |
| 1509 | dex_compilation_unit_->GetDexCache().Get(), |
| 1510 | field_idx)) { |
| 1511 | return nullptr; |
| 1512 | } |
| 1513 | |
| 1514 | if (is_put && |
| 1515 | resolved_field->IsFinal() && |
| 1516 | (compiling_class.Get() != resolved_field->GetDeclaringClass())) { |
| 1517 | // Final fields can only be updated within their own class. |
| 1518 | // TODO: Only allow it in constructors. b/34966607. |
| 1519 | return nullptr; |
| 1520 | } |
| 1521 | |
| 1522 | return resolved_field; |
| 1523 | } |
| 1524 | |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 1525 | void HInstructionBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1526 | uint32_t dex_pc, |
| 1527 | bool is_put) { |
| 1528 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1529 | uint16_t field_index = instruction.VRegB_21c(); |
| 1530 | |
| 1531 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1532 | ArtField* resolved_field = ResolveField(field_index, /* is_static */ true, is_put); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1533 | |
| 1534 | if (resolved_field == nullptr) { |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1535 | MaybeRecordStat(compilation_stats_, |
| 1536 | MethodCompilationStat::kUnresolvedField); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1537 | DataType::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1538 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 1539 | return; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1542 | DataType::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1543 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1544 | Handle<mirror::Class> klass = handles_->NewHandle(resolved_field->GetDeclaringClass()); |
| 1545 | HLoadClass* constant = BuildLoadClass(klass->GetDexTypeIndex(), |
| 1546 | klass->GetDexFile(), |
| 1547 | klass, |
| 1548 | dex_pc, |
| 1549 | /* needs_access_check */ false); |
| 1550 | |
| 1551 | if (constant == nullptr) { |
| 1552 | // The class cannot be referenced from this compiled code. Generate |
| 1553 | // an unresolved access. |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1554 | MaybeRecordStat(compilation_stats_, |
| 1555 | MethodCompilationStat::kUnresolvedFieldNotAFastAccess); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1556 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 1557 | return; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1560 | HInstruction* cls = constant; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1561 | if (!IsInitialized(klass)) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1562 | cls = new (allocator_) HClinitCheck(constant, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1563 | AppendInstruction(cls); |
| 1564 | } |
| 1565 | |
| 1566 | uint16_t class_def_index = klass->GetDexClassDefIndex(); |
| 1567 | if (is_put) { |
| 1568 | // We need to keep the class alive before loading the value. |
| 1569 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 1570 | DCHECK_EQ(HPhi::ToPhiType(value->GetType()), HPhi::ToPhiType(field_type)); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1571 | AppendInstruction(new (allocator_) HStaticFieldSet(cls, |
| 1572 | value, |
| 1573 | resolved_field, |
| 1574 | field_type, |
| 1575 | resolved_field->GetOffset(), |
| 1576 | resolved_field->IsVolatile(), |
| 1577 | field_index, |
| 1578 | class_def_index, |
| 1579 | *dex_file_, |
| 1580 | dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1581 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1582 | AppendInstruction(new (allocator_) HStaticFieldGet(cls, |
| 1583 | resolved_field, |
| 1584 | field_type, |
| 1585 | resolved_field->GetOffset(), |
| 1586 | resolved_field->IsVolatile(), |
| 1587 | field_index, |
| 1588 | class_def_index, |
| 1589 | *dex_file_, |
| 1590 | dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1591 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1592 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | void HInstructionBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1596 | uint16_t first_vreg, |
| 1597 | int64_t second_vreg_or_constant, |
| 1598 | uint32_t dex_pc, |
| 1599 | DataType::Type type, |
| 1600 | bool second_is_constant, |
| 1601 | bool isDiv) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1602 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1603 | |
| 1604 | HInstruction* first = LoadLocal(first_vreg, type); |
| 1605 | HInstruction* second = nullptr; |
| 1606 | if (second_is_constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1607 | if (type == DataType::Type::kInt32) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1608 | second = graph_->GetIntConstant(second_vreg_or_constant, dex_pc); |
| 1609 | } else { |
| 1610 | second = graph_->GetLongConstant(second_vreg_or_constant, dex_pc); |
| 1611 | } |
| 1612 | } else { |
| 1613 | second = LoadLocal(second_vreg_or_constant, type); |
| 1614 | } |
| 1615 | |
| 1616 | if (!second_is_constant |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1617 | || (type == DataType::Type::kInt32 && second->AsIntConstant()->GetValue() == 0) |
| 1618 | || (type == DataType::Type::kInt64 && second->AsLongConstant()->GetValue() == 0)) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1619 | second = new (allocator_) HDivZeroCheck(second, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1620 | AppendInstruction(second); |
| 1621 | } |
| 1622 | |
| 1623 | if (isDiv) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1624 | AppendInstruction(new (allocator_) HDiv(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1625 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1626 | AppendInstruction(new (allocator_) HRem(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1627 | } |
| 1628 | UpdateLocal(out_vreg, current_block_->GetLastInstruction()); |
| 1629 | } |
| 1630 | |
| 1631 | void HInstructionBuilder::BuildArrayAccess(const Instruction& instruction, |
| 1632 | uint32_t dex_pc, |
| 1633 | bool is_put, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1634 | DataType::Type anticipated_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1635 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 1636 | uint8_t array_reg = instruction.VRegB_23x(); |
| 1637 | uint8_t index_reg = instruction.VRegC_23x(); |
| 1638 | |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 1639 | HInstruction* object = LoadNullCheckedLocal(array_reg, dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1640 | HInstruction* length = new (allocator_) HArrayLength(object, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1641 | AppendInstruction(length); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1642 | HInstruction* index = LoadLocal(index_reg, DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1643 | index = new (allocator_) HBoundsCheck(index, length, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1644 | AppendInstruction(index); |
| 1645 | if (is_put) { |
| 1646 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 1647 | // TODO: Insert a type check node if the type is Object. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1648 | HArraySet* aset = new (allocator_) HArraySet(object, index, value, anticipated_type, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1649 | ssa_builder_->MaybeAddAmbiguousArraySet(aset); |
| 1650 | AppendInstruction(aset); |
| 1651 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1652 | HArrayGet* aget = new (allocator_) HArrayGet(object, index, anticipated_type, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1653 | ssa_builder_->MaybeAddAmbiguousArrayGet(aget); |
| 1654 | AppendInstruction(aget); |
| 1655 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1656 | } |
| 1657 | graph_->SetHasBoundsChecks(true); |
| 1658 | } |
| 1659 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1660 | HNewArray* HInstructionBuilder::BuildFilledNewArray(uint32_t dex_pc, |
| 1661 | dex::TypeIndex type_index, |
| 1662 | uint32_t number_of_vreg_arguments, |
| 1663 | bool is_range, |
| 1664 | uint32_t* args, |
| 1665 | uint32_t register_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1666 | HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments, dex_pc); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1667 | HLoadClass* cls = BuildLoadClass(type_index, dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1668 | HNewArray* const object = new (allocator_) HNewArray(cls, length, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1669 | AppendInstruction(object); |
| 1670 | |
| 1671 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 1672 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 1673 | char primitive = descriptor[1]; |
| 1674 | DCHECK(primitive == 'I' |
| 1675 | || primitive == 'L' |
| 1676 | || primitive == '[') << descriptor; |
| 1677 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | DataType::Type type = is_reference_array ? DataType::Type::kReference : DataType::Type::kInt32; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1679 | |
| 1680 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 1681 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
| 1682 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1683 | HArraySet* aset = new (allocator_) HArraySet(object, index, value, type, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1684 | ssa_builder_->MaybeAddAmbiguousArraySet(aset); |
| 1685 | AppendInstruction(aset); |
| 1686 | } |
| 1687 | latest_result_ = object; |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1688 | |
| 1689 | return object; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | template <typename T> |
| 1693 | void HInstructionBuilder::BuildFillArrayData(HInstruction* object, |
| 1694 | const T* data, |
| 1695 | uint32_t element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1696 | DataType::Type anticipated_type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1697 | uint32_t dex_pc) { |
| 1698 | for (uint32_t i = 0; i < element_count; ++i) { |
| 1699 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 1700 | HInstruction* value = graph_->GetIntConstant(data[i], dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1701 | HArraySet* aset = new (allocator_) HArraySet(object, index, value, anticipated_type, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1702 | ssa_builder_->MaybeAddAmbiguousArraySet(aset); |
| 1703 | AppendInstruction(aset); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | void HInstructionBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 1708 | HInstruction* array = LoadNullCheckedLocal(instruction.VRegA_31t(), dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1709 | |
| 1710 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
| 1711 | const Instruction::ArrayDataPayload* payload = |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 1712 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_item_->insns_ + payload_offset); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1713 | const uint8_t* data = payload->data; |
| 1714 | uint32_t element_count = payload->element_count; |
| 1715 | |
Vladimir Marko | c69fba2 | 2016-09-06 16:49:15 +0100 | [diff] [blame] | 1716 | if (element_count == 0u) { |
| 1717 | // For empty payload we emit only the null check above. |
| 1718 | return; |
| 1719 | } |
| 1720 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1721 | HInstruction* length = new (allocator_) HArrayLength(array, dex_pc); |
Vladimir Marko | c69fba2 | 2016-09-06 16:49:15 +0100 | [diff] [blame] | 1722 | AppendInstruction(length); |
| 1723 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1724 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 1725 | // done before doing any stores. |
| 1726 | HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1, dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1727 | AppendInstruction(new (allocator_) HBoundsCheck(last_index, length, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1728 | |
| 1729 | switch (payload->element_width) { |
| 1730 | case 1: |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 1731 | BuildFillArrayData(array, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1732 | reinterpret_cast<const int8_t*>(data), |
| 1733 | element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1734 | DataType::Type::kInt8, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1735 | dex_pc); |
| 1736 | break; |
| 1737 | case 2: |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 1738 | BuildFillArrayData(array, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1739 | reinterpret_cast<const int16_t*>(data), |
| 1740 | element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1741 | DataType::Type::kInt16, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1742 | dex_pc); |
| 1743 | break; |
| 1744 | case 4: |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 1745 | BuildFillArrayData(array, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1746 | reinterpret_cast<const int32_t*>(data), |
| 1747 | element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1748 | DataType::Type::kInt32, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1749 | dex_pc); |
| 1750 | break; |
| 1751 | case 8: |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 1752 | BuildFillWideArrayData(array, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1753 | reinterpret_cast<const int64_t*>(data), |
| 1754 | element_count, |
| 1755 | dex_pc); |
| 1756 | break; |
| 1757 | default: |
| 1758 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 1759 | } |
| 1760 | graph_->SetHasBoundsChecks(true); |
| 1761 | } |
| 1762 | |
| 1763 | void HInstructionBuilder::BuildFillWideArrayData(HInstruction* object, |
| 1764 | const int64_t* data, |
| 1765 | uint32_t element_count, |
| 1766 | uint32_t dex_pc) { |
| 1767 | for (uint32_t i = 0; i < element_count; ++i) { |
| 1768 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 1769 | HInstruction* value = graph_->GetLongConstant(data[i], dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1770 | HArraySet* aset = |
| 1771 | new (allocator_) HArraySet(object, index, value, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1772 | ssa_builder_->MaybeAddAmbiguousArraySet(aset); |
| 1773 | AppendInstruction(aset); |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | static TypeCheckKind ComputeTypeCheckKind(Handle<mirror::Class> cls) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1778 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1779 | if (cls == nullptr) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1780 | return TypeCheckKind::kUnresolvedCheck; |
| 1781 | } else if (cls->IsInterface()) { |
| 1782 | return TypeCheckKind::kInterfaceCheck; |
| 1783 | } else if (cls->IsArrayClass()) { |
| 1784 | if (cls->GetComponentType()->IsObjectClass()) { |
| 1785 | return TypeCheckKind::kArrayObjectCheck; |
| 1786 | } else if (cls->CannotBeAssignedFromOtherTypes()) { |
| 1787 | return TypeCheckKind::kExactCheck; |
| 1788 | } else { |
| 1789 | return TypeCheckKind::kArrayCheck; |
| 1790 | } |
| 1791 | } else if (cls->IsFinal()) { |
| 1792 | return TypeCheckKind::kExactCheck; |
| 1793 | } else if (cls->IsAbstract()) { |
| 1794 | return TypeCheckKind::kAbstractClassCheck; |
| 1795 | } else { |
| 1796 | return TypeCheckKind::kClassHierarchyCheck; |
| 1797 | } |
| 1798 | } |
| 1799 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1800 | HLoadClass* HInstructionBuilder::BuildLoadClass(dex::TypeIndex type_index, uint32_t dex_pc) { |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1801 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1802 | const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 1803 | Handle<mirror::ClassLoader> class_loader = dex_compilation_unit_->GetClassLoader(); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 1804 | Handle<mirror::Class> klass = handles_->NewHandle(compiler_driver_->ResolveClass( |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1805 | soa, dex_compilation_unit_->GetDexCache(), class_loader, type_index, dex_compilation_unit_)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 1806 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1807 | bool needs_access_check = true; |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1808 | if (klass != nullptr) { |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1809 | if (klass->IsPublic()) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1810 | needs_access_check = false; |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1811 | } else { |
| 1812 | mirror::Class* compiling_class = GetCompilingClass(); |
| 1813 | if (compiling_class != nullptr && compiling_class->CanAccess(klass.Get())) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1814 | needs_access_check = false; |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1819 | return BuildLoadClass(type_index, dex_file, klass, dex_pc, needs_access_check); |
| 1820 | } |
| 1821 | |
| 1822 | HLoadClass* HInstructionBuilder::BuildLoadClass(dex::TypeIndex type_index, |
| 1823 | const DexFile& dex_file, |
| 1824 | Handle<mirror::Class> klass, |
| 1825 | uint32_t dex_pc, |
| 1826 | bool needs_access_check) { |
| 1827 | // Try to find a reference in the compiling dex file. |
| 1828 | const DexFile* actual_dex_file = &dex_file; |
| 1829 | if (!IsSameDexFile(dex_file, *dex_compilation_unit_->GetDexFile())) { |
| 1830 | dex::TypeIndex local_type_index = |
| 1831 | klass->FindTypeIndexInOtherDexFile(*dex_compilation_unit_->GetDexFile()); |
| 1832 | if (local_type_index.IsValid()) { |
| 1833 | type_index = local_type_index; |
| 1834 | actual_dex_file = dex_compilation_unit_->GetDexFile(); |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | // Note: `klass` must be from `handles_`. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1839 | HLoadClass* load_class = new (allocator_) HLoadClass( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1840 | graph_->GetCurrentMethod(), |
| 1841 | type_index, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1842 | *actual_dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1843 | klass, |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1844 | klass != nullptr && (klass.Get() == GetOutermostCompilingClass()), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1845 | dex_pc, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1846 | needs_access_check); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1847 | |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 1848 | HLoadClass::LoadKind load_kind = HSharpening::ComputeLoadClassKind(load_class, |
| 1849 | code_generator_, |
| 1850 | compiler_driver_, |
| 1851 | *dex_compilation_unit_); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1852 | |
| 1853 | if (load_kind == HLoadClass::LoadKind::kInvalid) { |
| 1854 | // We actually cannot reference this class, we're forced to bail. |
| 1855 | return nullptr; |
| 1856 | } |
| 1857 | // Append the instruction first, as setting the load kind affects the inputs. |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1858 | AppendInstruction(load_class); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1859 | load_class->SetLoadKind(load_kind); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1860 | return load_class; |
| 1861 | } |
| 1862 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1863 | void HInstructionBuilder::BuildTypeCheck(const Instruction& instruction, |
| 1864 | uint8_t destination, |
| 1865 | uint8_t reference, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1866 | dex::TypeIndex type_index, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1867 | uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1868 | HInstruction* object = LoadLocal(reference, DataType::Type::kReference); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1869 | HLoadClass* cls = BuildLoadClass(type_index, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1870 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1871 | ScopedObjectAccess soa(Thread::Current()); |
| 1872 | TypeCheckKind check_kind = ComputeTypeCheckKind(cls->GetClass()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1873 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1874 | AppendInstruction(new (allocator_) HInstanceOf(object, cls, check_kind, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1875 | UpdateLocal(destination, current_block_->GetLastInstruction()); |
| 1876 | } else { |
| 1877 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
| 1878 | // We emit a CheckCast followed by a BoundType. CheckCast is a statement |
| 1879 | // which may throw. If it succeeds BoundType sets the new type of `object` |
| 1880 | // for all subsequent uses. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1881 | AppendInstruction(new (allocator_) HCheckCast(object, cls, check_kind, dex_pc)); |
| 1882 | AppendInstruction(new (allocator_) HBoundType(object, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1883 | UpdateLocal(reference, current_block_->GetLastInstruction()); |
| 1884 | } |
| 1885 | } |
| 1886 | |
Vladimir Marko | 0b66d61 | 2017-03-13 14:50:04 +0000 | [diff] [blame] | 1887 | bool HInstructionBuilder::NeedsAccessCheck(dex::TypeIndex type_index, bool* finalizable) const { |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 1888 | return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks( |
| 1889 | LookupReferrerClass(), LookupResolvedType(type_index, *dex_compilation_unit_), finalizable); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | bool HInstructionBuilder::CanDecodeQuickenedInfo() const { |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 1893 | return !quicken_info_.IsNull(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 1896 | uint16_t HInstructionBuilder::LookupQuickenedInfo(uint32_t quicken_index) { |
| 1897 | DCHECK(CanDecodeQuickenedInfo()); |
| 1898 | return quicken_info_.GetData(quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 1901 | bool HInstructionBuilder::ProcessDexInstruction(const Instruction& instruction, |
| 1902 | uint32_t dex_pc, |
| 1903 | size_t quicken_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1904 | switch (instruction.Opcode()) { |
| 1905 | case Instruction::CONST_4: { |
| 1906 | int32_t register_index = instruction.VRegA(); |
| 1907 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n(), dex_pc); |
| 1908 | UpdateLocal(register_index, constant); |
| 1909 | break; |
| 1910 | } |
| 1911 | |
| 1912 | case Instruction::CONST_16: { |
| 1913 | int32_t register_index = instruction.VRegA(); |
| 1914 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s(), dex_pc); |
| 1915 | UpdateLocal(register_index, constant); |
| 1916 | break; |
| 1917 | } |
| 1918 | |
| 1919 | case Instruction::CONST: { |
| 1920 | int32_t register_index = instruction.VRegA(); |
| 1921 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i(), dex_pc); |
| 1922 | UpdateLocal(register_index, constant); |
| 1923 | break; |
| 1924 | } |
| 1925 | |
| 1926 | case Instruction::CONST_HIGH16: { |
| 1927 | int32_t register_index = instruction.VRegA(); |
| 1928 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16, dex_pc); |
| 1929 | UpdateLocal(register_index, constant); |
| 1930 | break; |
| 1931 | } |
| 1932 | |
| 1933 | case Instruction::CONST_WIDE_16: { |
| 1934 | int32_t register_index = instruction.VRegA(); |
| 1935 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 1936 | int64_t value = instruction.VRegB_21s(); |
| 1937 | value <<= 48; |
| 1938 | value >>= 48; |
| 1939 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1940 | UpdateLocal(register_index, constant); |
| 1941 | break; |
| 1942 | } |
| 1943 | |
| 1944 | case Instruction::CONST_WIDE_32: { |
| 1945 | int32_t register_index = instruction.VRegA(); |
| 1946 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 1947 | int64_t value = instruction.VRegB_31i(); |
| 1948 | value <<= 32; |
| 1949 | value >>= 32; |
| 1950 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1951 | UpdateLocal(register_index, constant); |
| 1952 | break; |
| 1953 | } |
| 1954 | |
| 1955 | case Instruction::CONST_WIDE: { |
| 1956 | int32_t register_index = instruction.VRegA(); |
| 1957 | HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l(), dex_pc); |
| 1958 | UpdateLocal(register_index, constant); |
| 1959 | break; |
| 1960 | } |
| 1961 | |
| 1962 | case Instruction::CONST_WIDE_HIGH16: { |
| 1963 | int32_t register_index = instruction.VRegA(); |
| 1964 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
| 1965 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1966 | UpdateLocal(register_index, constant); |
| 1967 | break; |
| 1968 | } |
| 1969 | |
| 1970 | // Note that the SSA building will refine the types. |
| 1971 | case Instruction::MOVE: |
| 1972 | case Instruction::MOVE_FROM16: |
| 1973 | case Instruction::MOVE_16: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1974 | HInstruction* value = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1975 | UpdateLocal(instruction.VRegA(), value); |
| 1976 | break; |
| 1977 | } |
| 1978 | |
| 1979 | // Note that the SSA building will refine the types. |
| 1980 | case Instruction::MOVE_WIDE: |
| 1981 | case Instruction::MOVE_WIDE_FROM16: |
| 1982 | case Instruction::MOVE_WIDE_16: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1983 | HInstruction* value = LoadLocal(instruction.VRegB(), DataType::Type::kInt64); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1984 | UpdateLocal(instruction.VRegA(), value); |
| 1985 | break; |
| 1986 | } |
| 1987 | |
| 1988 | case Instruction::MOVE_OBJECT: |
| 1989 | case Instruction::MOVE_OBJECT_16: |
| 1990 | case Instruction::MOVE_OBJECT_FROM16: { |
Nicolas Geoffray | 50a9ed0 | 2016-09-23 15:40:41 +0100 | [diff] [blame] | 1991 | // The verifier has no notion of a null type, so a move-object of constant 0 |
| 1992 | // will lead to the same constant 0 in the destination register. To mimic |
| 1993 | // this behavior, we just pretend we haven't seen a type change (int to reference) |
| 1994 | // for the 0 constant and phis. We rely on our type propagation to eventually get the |
| 1995 | // types correct. |
| 1996 | uint32_t reg_number = instruction.VRegB(); |
| 1997 | HInstruction* value = (*current_locals_)[reg_number]; |
| 1998 | if (value->IsIntConstant()) { |
| 1999 | DCHECK_EQ(value->AsIntConstant()->GetValue(), 0); |
| 2000 | } else if (value->IsPhi()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2001 | DCHECK(value->GetType() == DataType::Type::kInt32 || |
| 2002 | value->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 50a9ed0 | 2016-09-23 15:40:41 +0100 | [diff] [blame] | 2003 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2004 | value = LoadLocal(reg_number, DataType::Type::kReference); |
Nicolas Geoffray | 50a9ed0 | 2016-09-23 15:40:41 +0100 | [diff] [blame] | 2005 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2006 | UpdateLocal(instruction.VRegA(), value); |
| 2007 | break; |
| 2008 | } |
| 2009 | |
| 2010 | case Instruction::RETURN_VOID_NO_BARRIER: |
| 2011 | case Instruction::RETURN_VOID: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2012 | BuildReturn(instruction, DataType::Type::kVoid, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2013 | break; |
| 2014 | } |
| 2015 | |
| 2016 | #define IF_XX(comparison, cond) \ |
| 2017 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 2018 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
| 2019 | |
| 2020 | IF_XX(HEqual, EQ); |
| 2021 | IF_XX(HNotEqual, NE); |
| 2022 | IF_XX(HLessThan, LT); |
| 2023 | IF_XX(HLessThanOrEqual, LE); |
| 2024 | IF_XX(HGreaterThan, GT); |
| 2025 | IF_XX(HGreaterThanOrEqual, GE); |
| 2026 | |
| 2027 | case Instruction::GOTO: |
| 2028 | case Instruction::GOTO_16: |
| 2029 | case Instruction::GOTO_32: { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2030 | AppendInstruction(new (allocator_) HGoto(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2031 | current_block_ = nullptr; |
| 2032 | break; |
| 2033 | } |
| 2034 | |
| 2035 | case Instruction::RETURN: { |
| 2036 | BuildReturn(instruction, return_type_, dex_pc); |
| 2037 | break; |
| 2038 | } |
| 2039 | |
| 2040 | case Instruction::RETURN_OBJECT: { |
| 2041 | BuildReturn(instruction, return_type_, dex_pc); |
| 2042 | break; |
| 2043 | } |
| 2044 | |
| 2045 | case Instruction::RETURN_WIDE: { |
| 2046 | BuildReturn(instruction, return_type_, dex_pc); |
| 2047 | break; |
| 2048 | } |
| 2049 | |
| 2050 | case Instruction::INVOKE_DIRECT: |
| 2051 | case Instruction::INVOKE_INTERFACE: |
| 2052 | case Instruction::INVOKE_STATIC: |
| 2053 | case Instruction::INVOKE_SUPER: |
| 2054 | case Instruction::INVOKE_VIRTUAL: |
| 2055 | case Instruction::INVOKE_VIRTUAL_QUICK: { |
| 2056 | uint16_t method_idx; |
| 2057 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_QUICK) { |
| 2058 | if (!CanDecodeQuickenedInfo()) { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 2059 | VLOG(compiler) << "Not compiled: Could not decode quickened instruction " |
| 2060 | << instruction.Opcode(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2061 | return false; |
| 2062 | } |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 2063 | method_idx = LookupQuickenedInfo(quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2064 | } else { |
| 2065 | method_idx = instruction.VRegB_35c(); |
| 2066 | } |
| 2067 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 2068 | uint32_t args[5]; |
| 2069 | instruction.GetVarArgs(args); |
| 2070 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
| 2071 | number_of_vreg_arguments, false, args, -1)) { |
| 2072 | return false; |
| 2073 | } |
| 2074 | break; |
| 2075 | } |
| 2076 | |
| 2077 | case Instruction::INVOKE_DIRECT_RANGE: |
| 2078 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 2079 | case Instruction::INVOKE_STATIC_RANGE: |
| 2080 | case Instruction::INVOKE_SUPER_RANGE: |
| 2081 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 2082 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 2083 | uint16_t method_idx; |
| 2084 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK) { |
| 2085 | if (!CanDecodeQuickenedInfo()) { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 2086 | VLOG(compiler) << "Not compiled: Could not decode quickened instruction " |
| 2087 | << instruction.Opcode(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2088 | return false; |
| 2089 | } |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 2090 | method_idx = LookupQuickenedInfo(quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2091 | } else { |
| 2092 | method_idx = instruction.VRegB_3rc(); |
| 2093 | } |
| 2094 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 2095 | uint32_t register_index = instruction.VRegC(); |
| 2096 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
| 2097 | number_of_vreg_arguments, true, nullptr, register_index)) { |
| 2098 | return false; |
| 2099 | } |
| 2100 | break; |
| 2101 | } |
| 2102 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2103 | case Instruction::INVOKE_POLYMORPHIC: { |
| 2104 | uint16_t method_idx = instruction.VRegB_45cc(); |
| 2105 | uint16_t proto_idx = instruction.VRegH_45cc(); |
| 2106 | uint32_t number_of_vreg_arguments = instruction.VRegA_45cc(); |
| 2107 | uint32_t args[5]; |
| 2108 | instruction.GetVarArgs(args); |
| 2109 | return BuildInvokePolymorphic(instruction, |
| 2110 | dex_pc, |
| 2111 | method_idx, |
| 2112 | proto_idx, |
| 2113 | number_of_vreg_arguments, |
| 2114 | false, |
| 2115 | args, |
| 2116 | -1); |
| 2117 | } |
| 2118 | |
| 2119 | case Instruction::INVOKE_POLYMORPHIC_RANGE: { |
| 2120 | uint16_t method_idx = instruction.VRegB_4rcc(); |
| 2121 | uint16_t proto_idx = instruction.VRegH_4rcc(); |
| 2122 | uint32_t number_of_vreg_arguments = instruction.VRegA_4rcc(); |
| 2123 | uint32_t register_index = instruction.VRegC_4rcc(); |
| 2124 | return BuildInvokePolymorphic(instruction, |
| 2125 | dex_pc, |
| 2126 | method_idx, |
| 2127 | proto_idx, |
| 2128 | number_of_vreg_arguments, |
| 2129 | true, |
| 2130 | nullptr, |
| 2131 | register_index); |
| 2132 | } |
| 2133 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2134 | case Instruction::NEG_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2135 | Unop_12x<HNeg>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2136 | break; |
| 2137 | } |
| 2138 | |
| 2139 | case Instruction::NEG_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2140 | Unop_12x<HNeg>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | } |
| 2143 | |
| 2144 | case Instruction::NEG_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2145 | Unop_12x<HNeg>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2146 | break; |
| 2147 | } |
| 2148 | |
| 2149 | case Instruction::NEG_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2150 | Unop_12x<HNeg>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | } |
| 2153 | |
| 2154 | case Instruction::NOT_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2155 | Unop_12x<HNot>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2156 | break; |
| 2157 | } |
| 2158 | |
| 2159 | case Instruction::NOT_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2160 | Unop_12x<HNot>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2161 | break; |
| 2162 | } |
| 2163 | |
| 2164 | case Instruction::INT_TO_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2165 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2166 | break; |
| 2167 | } |
| 2168 | |
| 2169 | case Instruction::INT_TO_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2170 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2171 | break; |
| 2172 | } |
| 2173 | |
| 2174 | case Instruction::INT_TO_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2175 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2176 | break; |
| 2177 | } |
| 2178 | |
| 2179 | case Instruction::LONG_TO_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2180 | Conversion_12x(instruction, DataType::Type::kInt64, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2181 | break; |
| 2182 | } |
| 2183 | |
| 2184 | case Instruction::LONG_TO_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2185 | Conversion_12x(instruction, DataType::Type::kInt64, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2186 | break; |
| 2187 | } |
| 2188 | |
| 2189 | case Instruction::LONG_TO_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2190 | Conversion_12x(instruction, DataType::Type::kInt64, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2191 | break; |
| 2192 | } |
| 2193 | |
| 2194 | case Instruction::FLOAT_TO_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2195 | Conversion_12x(instruction, DataType::Type::kFloat32, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2196 | break; |
| 2197 | } |
| 2198 | |
| 2199 | case Instruction::FLOAT_TO_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2200 | Conversion_12x(instruction, DataType::Type::kFloat32, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2201 | break; |
| 2202 | } |
| 2203 | |
| 2204 | case Instruction::FLOAT_TO_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2205 | Conversion_12x(instruction, DataType::Type::kFloat32, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2206 | break; |
| 2207 | } |
| 2208 | |
| 2209 | case Instruction::DOUBLE_TO_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2210 | Conversion_12x(instruction, DataType::Type::kFloat64, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | } |
| 2213 | |
| 2214 | case Instruction::DOUBLE_TO_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2215 | Conversion_12x(instruction, DataType::Type::kFloat64, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2216 | break; |
| 2217 | } |
| 2218 | |
| 2219 | case Instruction::DOUBLE_TO_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2220 | Conversion_12x(instruction, DataType::Type::kFloat64, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2221 | break; |
| 2222 | } |
| 2223 | |
| 2224 | case Instruction::INT_TO_BYTE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2225 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kInt8, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2226 | break; |
| 2227 | } |
| 2228 | |
| 2229 | case Instruction::INT_TO_SHORT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2230 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kInt16, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2231 | break; |
| 2232 | } |
| 2233 | |
| 2234 | case Instruction::INT_TO_CHAR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2235 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kUint16, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2236 | break; |
| 2237 | } |
| 2238 | |
| 2239 | case Instruction::ADD_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2240 | Binop_23x<HAdd>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2241 | break; |
| 2242 | } |
| 2243 | |
| 2244 | case Instruction::ADD_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2245 | Binop_23x<HAdd>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2246 | break; |
| 2247 | } |
| 2248 | |
| 2249 | case Instruction::ADD_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2250 | Binop_23x<HAdd>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2251 | break; |
| 2252 | } |
| 2253 | |
| 2254 | case Instruction::ADD_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2255 | Binop_23x<HAdd>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2256 | break; |
| 2257 | } |
| 2258 | |
| 2259 | case Instruction::SUB_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2260 | Binop_23x<HSub>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2261 | break; |
| 2262 | } |
| 2263 | |
| 2264 | case Instruction::SUB_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2265 | Binop_23x<HSub>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2266 | break; |
| 2267 | } |
| 2268 | |
| 2269 | case Instruction::SUB_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2270 | Binop_23x<HSub>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2271 | break; |
| 2272 | } |
| 2273 | |
| 2274 | case Instruction::SUB_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2275 | Binop_23x<HSub>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2276 | break; |
| 2277 | } |
| 2278 | |
| 2279 | case Instruction::ADD_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2280 | Binop_12x<HAdd>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2281 | break; |
| 2282 | } |
| 2283 | |
| 2284 | case Instruction::MUL_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2285 | Binop_23x<HMul>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2286 | break; |
| 2287 | } |
| 2288 | |
| 2289 | case Instruction::MUL_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2290 | Binop_23x<HMul>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | } |
| 2293 | |
| 2294 | case Instruction::MUL_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2295 | Binop_23x<HMul>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2296 | break; |
| 2297 | } |
| 2298 | |
| 2299 | case Instruction::MUL_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2300 | Binop_23x<HMul>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2301 | break; |
| 2302 | } |
| 2303 | |
| 2304 | case Instruction::DIV_INT: { |
| 2305 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2306 | dex_pc, DataType::Type::kInt32, false, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2307 | break; |
| 2308 | } |
| 2309 | |
| 2310 | case Instruction::DIV_LONG: { |
| 2311 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2312 | dex_pc, DataType::Type::kInt64, false, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2313 | break; |
| 2314 | } |
| 2315 | |
| 2316 | case Instruction::DIV_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2317 | Binop_23x<HDiv>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2318 | break; |
| 2319 | } |
| 2320 | |
| 2321 | case Instruction::DIV_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2322 | Binop_23x<HDiv>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2323 | break; |
| 2324 | } |
| 2325 | |
| 2326 | case Instruction::REM_INT: { |
| 2327 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2328 | dex_pc, DataType::Type::kInt32, false, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2329 | break; |
| 2330 | } |
| 2331 | |
| 2332 | case Instruction::REM_LONG: { |
| 2333 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2334 | dex_pc, DataType::Type::kInt64, false, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2335 | break; |
| 2336 | } |
| 2337 | |
| 2338 | case Instruction::REM_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2339 | Binop_23x<HRem>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2340 | break; |
| 2341 | } |
| 2342 | |
| 2343 | case Instruction::REM_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2344 | Binop_23x<HRem>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2345 | break; |
| 2346 | } |
| 2347 | |
| 2348 | case Instruction::AND_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2349 | Binop_23x<HAnd>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2350 | break; |
| 2351 | } |
| 2352 | |
| 2353 | case Instruction::AND_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2354 | Binop_23x<HAnd>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2355 | break; |
| 2356 | } |
| 2357 | |
| 2358 | case Instruction::SHL_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2359 | Binop_23x_shift<HShl>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2360 | break; |
| 2361 | } |
| 2362 | |
| 2363 | case Instruction::SHL_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2364 | Binop_23x_shift<HShl>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2365 | break; |
| 2366 | } |
| 2367 | |
| 2368 | case Instruction::SHR_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2369 | Binop_23x_shift<HShr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2370 | break; |
| 2371 | } |
| 2372 | |
| 2373 | case Instruction::SHR_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2374 | Binop_23x_shift<HShr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2375 | break; |
| 2376 | } |
| 2377 | |
| 2378 | case Instruction::USHR_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2379 | Binop_23x_shift<HUShr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2380 | break; |
| 2381 | } |
| 2382 | |
| 2383 | case Instruction::USHR_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2384 | Binop_23x_shift<HUShr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | } |
| 2387 | |
| 2388 | case Instruction::OR_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2389 | Binop_23x<HOr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2390 | break; |
| 2391 | } |
| 2392 | |
| 2393 | case Instruction::OR_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2394 | Binop_23x<HOr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | } |
| 2397 | |
| 2398 | case Instruction::XOR_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2399 | Binop_23x<HXor>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2400 | break; |
| 2401 | } |
| 2402 | |
| 2403 | case Instruction::XOR_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2404 | Binop_23x<HXor>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2405 | break; |
| 2406 | } |
| 2407 | |
| 2408 | case Instruction::ADD_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2409 | Binop_12x<HAdd>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2410 | break; |
| 2411 | } |
| 2412 | |
| 2413 | case Instruction::ADD_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2414 | Binop_12x<HAdd>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2415 | break; |
| 2416 | } |
| 2417 | |
| 2418 | case Instruction::ADD_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2419 | Binop_12x<HAdd>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2420 | break; |
| 2421 | } |
| 2422 | |
| 2423 | case Instruction::SUB_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2424 | Binop_12x<HSub>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2425 | break; |
| 2426 | } |
| 2427 | |
| 2428 | case Instruction::SUB_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2429 | Binop_12x<HSub>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2430 | break; |
| 2431 | } |
| 2432 | |
| 2433 | case Instruction::SUB_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2434 | Binop_12x<HSub>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2435 | break; |
| 2436 | } |
| 2437 | |
| 2438 | case Instruction::SUB_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2439 | Binop_12x<HSub>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2440 | break; |
| 2441 | } |
| 2442 | |
| 2443 | case Instruction::MUL_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2444 | Binop_12x<HMul>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2445 | break; |
| 2446 | } |
| 2447 | |
| 2448 | case Instruction::MUL_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2449 | Binop_12x<HMul>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2450 | break; |
| 2451 | } |
| 2452 | |
| 2453 | case Instruction::MUL_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2454 | Binop_12x<HMul>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2455 | break; |
| 2456 | } |
| 2457 | |
| 2458 | case Instruction::MUL_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2459 | Binop_12x<HMul>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2460 | break; |
| 2461 | } |
| 2462 | |
| 2463 | case Instruction::DIV_INT_2ADDR: { |
| 2464 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2465 | dex_pc, DataType::Type::kInt32, false, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2466 | break; |
| 2467 | } |
| 2468 | |
| 2469 | case Instruction::DIV_LONG_2ADDR: { |
| 2470 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2471 | dex_pc, DataType::Type::kInt64, false, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | } |
| 2474 | |
| 2475 | case Instruction::REM_INT_2ADDR: { |
| 2476 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2477 | dex_pc, DataType::Type::kInt32, false, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2478 | break; |
| 2479 | } |
| 2480 | |
| 2481 | case Instruction::REM_LONG_2ADDR: { |
| 2482 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2483 | dex_pc, DataType::Type::kInt64, false, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2484 | break; |
| 2485 | } |
| 2486 | |
| 2487 | case Instruction::REM_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2488 | Binop_12x<HRem>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2489 | break; |
| 2490 | } |
| 2491 | |
| 2492 | case Instruction::REM_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2493 | Binop_12x<HRem>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2494 | break; |
| 2495 | } |
| 2496 | |
| 2497 | case Instruction::SHL_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2498 | Binop_12x_shift<HShl>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2499 | break; |
| 2500 | } |
| 2501 | |
| 2502 | case Instruction::SHL_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2503 | Binop_12x_shift<HShl>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2504 | break; |
| 2505 | } |
| 2506 | |
| 2507 | case Instruction::SHR_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2508 | Binop_12x_shift<HShr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2509 | break; |
| 2510 | } |
| 2511 | |
| 2512 | case Instruction::SHR_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2513 | Binop_12x_shift<HShr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2514 | break; |
| 2515 | } |
| 2516 | |
| 2517 | case Instruction::USHR_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2518 | Binop_12x_shift<HUShr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2519 | break; |
| 2520 | } |
| 2521 | |
| 2522 | case Instruction::USHR_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2523 | Binop_12x_shift<HUShr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2524 | break; |
| 2525 | } |
| 2526 | |
| 2527 | case Instruction::DIV_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2528 | Binop_12x<HDiv>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2529 | break; |
| 2530 | } |
| 2531 | |
| 2532 | case Instruction::DIV_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2533 | Binop_12x<HDiv>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2534 | break; |
| 2535 | } |
| 2536 | |
| 2537 | case Instruction::AND_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2538 | Binop_12x<HAnd>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2539 | break; |
| 2540 | } |
| 2541 | |
| 2542 | case Instruction::AND_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2543 | Binop_12x<HAnd>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2544 | break; |
| 2545 | } |
| 2546 | |
| 2547 | case Instruction::OR_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2548 | Binop_12x<HOr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | } |
| 2551 | |
| 2552 | case Instruction::OR_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2553 | Binop_12x<HOr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2554 | break; |
| 2555 | } |
| 2556 | |
| 2557 | case Instruction::XOR_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2558 | Binop_12x<HXor>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2559 | break; |
| 2560 | } |
| 2561 | |
| 2562 | case Instruction::XOR_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2563 | Binop_12x<HXor>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2564 | break; |
| 2565 | } |
| 2566 | |
| 2567 | case Instruction::ADD_INT_LIT16: { |
| 2568 | Binop_22s<HAdd>(instruction, false, dex_pc); |
| 2569 | break; |
| 2570 | } |
| 2571 | |
| 2572 | case Instruction::AND_INT_LIT16: { |
| 2573 | Binop_22s<HAnd>(instruction, false, dex_pc); |
| 2574 | break; |
| 2575 | } |
| 2576 | |
| 2577 | case Instruction::OR_INT_LIT16: { |
| 2578 | Binop_22s<HOr>(instruction, false, dex_pc); |
| 2579 | break; |
| 2580 | } |
| 2581 | |
| 2582 | case Instruction::XOR_INT_LIT16: { |
| 2583 | Binop_22s<HXor>(instruction, false, dex_pc); |
| 2584 | break; |
| 2585 | } |
| 2586 | |
| 2587 | case Instruction::RSUB_INT: { |
| 2588 | Binop_22s<HSub>(instruction, true, dex_pc); |
| 2589 | break; |
| 2590 | } |
| 2591 | |
| 2592 | case Instruction::MUL_INT_LIT16: { |
| 2593 | Binop_22s<HMul>(instruction, false, dex_pc); |
| 2594 | break; |
| 2595 | } |
| 2596 | |
| 2597 | case Instruction::ADD_INT_LIT8: { |
| 2598 | Binop_22b<HAdd>(instruction, false, dex_pc); |
| 2599 | break; |
| 2600 | } |
| 2601 | |
| 2602 | case Instruction::AND_INT_LIT8: { |
| 2603 | Binop_22b<HAnd>(instruction, false, dex_pc); |
| 2604 | break; |
| 2605 | } |
| 2606 | |
| 2607 | case Instruction::OR_INT_LIT8: { |
| 2608 | Binop_22b<HOr>(instruction, false, dex_pc); |
| 2609 | break; |
| 2610 | } |
| 2611 | |
| 2612 | case Instruction::XOR_INT_LIT8: { |
| 2613 | Binop_22b<HXor>(instruction, false, dex_pc); |
| 2614 | break; |
| 2615 | } |
| 2616 | |
| 2617 | case Instruction::RSUB_INT_LIT8: { |
| 2618 | Binop_22b<HSub>(instruction, true, dex_pc); |
| 2619 | break; |
| 2620 | } |
| 2621 | |
| 2622 | case Instruction::MUL_INT_LIT8: { |
| 2623 | Binop_22b<HMul>(instruction, false, dex_pc); |
| 2624 | break; |
| 2625 | } |
| 2626 | |
| 2627 | case Instruction::DIV_INT_LIT16: |
| 2628 | case Instruction::DIV_INT_LIT8: { |
| 2629 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2630 | dex_pc, DataType::Type::kInt32, true, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2631 | break; |
| 2632 | } |
| 2633 | |
| 2634 | case Instruction::REM_INT_LIT16: |
| 2635 | case Instruction::REM_INT_LIT8: { |
| 2636 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2637 | dex_pc, DataType::Type::kInt32, true, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2638 | break; |
| 2639 | } |
| 2640 | |
| 2641 | case Instruction::SHL_INT_LIT8: { |
| 2642 | Binop_22b<HShl>(instruction, false, dex_pc); |
| 2643 | break; |
| 2644 | } |
| 2645 | |
| 2646 | case Instruction::SHR_INT_LIT8: { |
| 2647 | Binop_22b<HShr>(instruction, false, dex_pc); |
| 2648 | break; |
| 2649 | } |
| 2650 | |
| 2651 | case Instruction::USHR_INT_LIT8: { |
| 2652 | Binop_22b<HUShr>(instruction, false, dex_pc); |
| 2653 | break; |
| 2654 | } |
| 2655 | |
| 2656 | case Instruction::NEW_INSTANCE: { |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2657 | HNewInstance* new_instance = |
| 2658 | BuildNewInstance(dex::TypeIndex(instruction.VRegB_21c()), dex_pc); |
| 2659 | DCHECK(new_instance != nullptr); |
| 2660 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2661 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2662 | BuildConstructorFenceForAllocation(new_instance); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2663 | break; |
| 2664 | } |
| 2665 | |
| 2666 | case Instruction::NEW_ARRAY: { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 2667 | dex::TypeIndex type_index(instruction.VRegC_22c()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2668 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), DataType::Type::kInt32); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2669 | HLoadClass* cls = BuildLoadClass(type_index, dex_pc); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2670 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2671 | HNewArray* new_array = new (allocator_) HNewArray(cls, length, dex_pc); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2672 | AppendInstruction(new_array); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2673 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2674 | BuildConstructorFenceForAllocation(new_array); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2675 | break; |
| 2676 | } |
| 2677 | |
| 2678 | case Instruction::FILLED_NEW_ARRAY: { |
| 2679 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 2680 | dex::TypeIndex type_index(instruction.VRegB_35c()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2681 | uint32_t args[5]; |
| 2682 | instruction.GetVarArgs(args); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2683 | HNewArray* new_array = BuildFilledNewArray(dex_pc, |
| 2684 | type_index, |
| 2685 | number_of_vreg_arguments, |
| 2686 | /* is_range */ false, |
| 2687 | args, |
| 2688 | /* register_index */ 0); |
| 2689 | BuildConstructorFenceForAllocation(new_array); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2690 | break; |
| 2691 | } |
| 2692 | |
| 2693 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 2694 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 2695 | dex::TypeIndex type_index(instruction.VRegB_3rc()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2696 | uint32_t register_index = instruction.VRegC_3rc(); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2697 | HNewArray* new_array = BuildFilledNewArray(dex_pc, |
| 2698 | type_index, |
| 2699 | number_of_vreg_arguments, |
| 2700 | /* is_range */ true, |
| 2701 | /* args*/ nullptr, |
| 2702 | register_index); |
| 2703 | BuildConstructorFenceForAllocation(new_array); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2704 | break; |
| 2705 | } |
| 2706 | |
| 2707 | case Instruction::FILL_ARRAY_DATA: { |
| 2708 | BuildFillArrayData(instruction, dex_pc); |
| 2709 | break; |
| 2710 | } |
| 2711 | |
| 2712 | case Instruction::MOVE_RESULT: |
| 2713 | case Instruction::MOVE_RESULT_WIDE: |
| 2714 | case Instruction::MOVE_RESULT_OBJECT: { |
| 2715 | DCHECK(latest_result_ != nullptr); |
| 2716 | UpdateLocal(instruction.VRegA(), latest_result_); |
| 2717 | latest_result_ = nullptr; |
| 2718 | break; |
| 2719 | } |
| 2720 | |
| 2721 | case Instruction::CMP_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2722 | Binop_23x_cmp(instruction, DataType::Type::kInt64, ComparisonBias::kNoBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2723 | break; |
| 2724 | } |
| 2725 | |
| 2726 | case Instruction::CMPG_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2727 | Binop_23x_cmp(instruction, DataType::Type::kFloat32, ComparisonBias::kGtBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2728 | break; |
| 2729 | } |
| 2730 | |
| 2731 | case Instruction::CMPG_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2732 | Binop_23x_cmp(instruction, DataType::Type::kFloat64, ComparisonBias::kGtBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2733 | break; |
| 2734 | } |
| 2735 | |
| 2736 | case Instruction::CMPL_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2737 | Binop_23x_cmp(instruction, DataType::Type::kFloat32, ComparisonBias::kLtBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2738 | break; |
| 2739 | } |
| 2740 | |
| 2741 | case Instruction::CMPL_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2742 | Binop_23x_cmp(instruction, DataType::Type::kFloat64, ComparisonBias::kLtBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2743 | break; |
| 2744 | } |
| 2745 | |
| 2746 | case Instruction::NOP: |
| 2747 | break; |
| 2748 | |
| 2749 | case Instruction::IGET: |
| 2750 | case Instruction::IGET_QUICK: |
| 2751 | case Instruction::IGET_WIDE: |
| 2752 | case Instruction::IGET_WIDE_QUICK: |
| 2753 | case Instruction::IGET_OBJECT: |
| 2754 | case Instruction::IGET_OBJECT_QUICK: |
| 2755 | case Instruction::IGET_BOOLEAN: |
| 2756 | case Instruction::IGET_BOOLEAN_QUICK: |
| 2757 | case Instruction::IGET_BYTE: |
| 2758 | case Instruction::IGET_BYTE_QUICK: |
| 2759 | case Instruction::IGET_CHAR: |
| 2760 | case Instruction::IGET_CHAR_QUICK: |
| 2761 | case Instruction::IGET_SHORT: |
| 2762 | case Instruction::IGET_SHORT_QUICK: { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 2763 | if (!BuildInstanceFieldAccess(instruction, dex_pc, /* is_put */ false, quicken_index)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2764 | return false; |
| 2765 | } |
| 2766 | break; |
| 2767 | } |
| 2768 | |
| 2769 | case Instruction::IPUT: |
| 2770 | case Instruction::IPUT_QUICK: |
| 2771 | case Instruction::IPUT_WIDE: |
| 2772 | case Instruction::IPUT_WIDE_QUICK: |
| 2773 | case Instruction::IPUT_OBJECT: |
| 2774 | case Instruction::IPUT_OBJECT_QUICK: |
| 2775 | case Instruction::IPUT_BOOLEAN: |
| 2776 | case Instruction::IPUT_BOOLEAN_QUICK: |
| 2777 | case Instruction::IPUT_BYTE: |
| 2778 | case Instruction::IPUT_BYTE_QUICK: |
| 2779 | case Instruction::IPUT_CHAR: |
| 2780 | case Instruction::IPUT_CHAR_QUICK: |
| 2781 | case Instruction::IPUT_SHORT: |
| 2782 | case Instruction::IPUT_SHORT_QUICK: { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 2783 | if (!BuildInstanceFieldAccess(instruction, dex_pc, /* is_put */ true, quicken_index)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2784 | return false; |
| 2785 | } |
| 2786 | break; |
| 2787 | } |
| 2788 | |
| 2789 | case Instruction::SGET: |
| 2790 | case Instruction::SGET_WIDE: |
| 2791 | case Instruction::SGET_OBJECT: |
| 2792 | case Instruction::SGET_BOOLEAN: |
| 2793 | case Instruction::SGET_BYTE: |
| 2794 | case Instruction::SGET_CHAR: |
| 2795 | case Instruction::SGET_SHORT: { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 2796 | BuildStaticFieldAccess(instruction, dex_pc, /* is_put */ false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2797 | break; |
| 2798 | } |
| 2799 | |
| 2800 | case Instruction::SPUT: |
| 2801 | case Instruction::SPUT_WIDE: |
| 2802 | case Instruction::SPUT_OBJECT: |
| 2803 | case Instruction::SPUT_BOOLEAN: |
| 2804 | case Instruction::SPUT_BYTE: |
| 2805 | case Instruction::SPUT_CHAR: |
| 2806 | case Instruction::SPUT_SHORT: { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame^] | 2807 | BuildStaticFieldAccess(instruction, dex_pc, /* is_put */ true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2808 | break; |
| 2809 | } |
| 2810 | |
| 2811 | #define ARRAY_XX(kind, anticipated_type) \ |
| 2812 | case Instruction::AGET##kind: { \ |
| 2813 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
| 2814 | break; \ |
| 2815 | } \ |
| 2816 | case Instruction::APUT##kind: { \ |
| 2817 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
| 2818 | break; \ |
| 2819 | } |
| 2820 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2821 | ARRAY_XX(, DataType::Type::kInt32); |
| 2822 | ARRAY_XX(_WIDE, DataType::Type::kInt64); |
| 2823 | ARRAY_XX(_OBJECT, DataType::Type::kReference); |
| 2824 | ARRAY_XX(_BOOLEAN, DataType::Type::kBool); |
| 2825 | ARRAY_XX(_BYTE, DataType::Type::kInt8); |
| 2826 | ARRAY_XX(_CHAR, DataType::Type::kUint16); |
| 2827 | ARRAY_XX(_SHORT, DataType::Type::kInt16); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2828 | |
| 2829 | case Instruction::ARRAY_LENGTH: { |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 2830 | HInstruction* object = LoadNullCheckedLocal(instruction.VRegB_12x(), dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2831 | AppendInstruction(new (allocator_) HArrayLength(object, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2832 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 2833 | break; |
| 2834 | } |
| 2835 | |
| 2836 | case Instruction::CONST_STRING: { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 2837 | dex::StringIndex string_index(instruction.VRegB_21c()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2838 | AppendInstruction(new (allocator_) HLoadString(graph_->GetCurrentMethod(), |
| 2839 | string_index, |
| 2840 | *dex_file_, |
| 2841 | dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2842 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 2843 | break; |
| 2844 | } |
| 2845 | |
| 2846 | case Instruction::CONST_STRING_JUMBO: { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 2847 | dex::StringIndex string_index(instruction.VRegB_31c()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2848 | AppendInstruction(new (allocator_) HLoadString(graph_->GetCurrentMethod(), |
| 2849 | string_index, |
| 2850 | *dex_file_, |
| 2851 | dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2852 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 2853 | break; |
| 2854 | } |
| 2855 | |
| 2856 | case Instruction::CONST_CLASS: { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 2857 | dex::TypeIndex type_index(instruction.VRegB_21c()); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2858 | BuildLoadClass(type_index, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2859 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 2860 | break; |
| 2861 | } |
| 2862 | |
| 2863 | case Instruction::MOVE_EXCEPTION: { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2864 | AppendInstruction(new (allocator_) HLoadException(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2865 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2866 | AppendInstruction(new (allocator_) HClearException(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2867 | break; |
| 2868 | } |
| 2869 | |
| 2870 | case Instruction::THROW: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2871 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2872 | AppendInstruction(new (allocator_) HThrow(exception, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2873 | // We finished building this block. Set the current block to null to avoid |
| 2874 | // adding dead instructions to it. |
| 2875 | current_block_ = nullptr; |
| 2876 | break; |
| 2877 | } |
| 2878 | |
| 2879 | case Instruction::INSTANCE_OF: { |
| 2880 | uint8_t destination = instruction.VRegA_22c(); |
| 2881 | uint8_t reference = instruction.VRegB_22c(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 2882 | dex::TypeIndex type_index(instruction.VRegC_22c()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2883 | BuildTypeCheck(instruction, destination, reference, type_index, dex_pc); |
| 2884 | break; |
| 2885 | } |
| 2886 | |
| 2887 | case Instruction::CHECK_CAST: { |
| 2888 | uint8_t reference = instruction.VRegA_21c(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 2889 | dex::TypeIndex type_index(instruction.VRegB_21c()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2890 | BuildTypeCheck(instruction, -1, reference, type_index, dex_pc); |
| 2891 | break; |
| 2892 | } |
| 2893 | |
| 2894 | case Instruction::MONITOR_ENTER: { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2895 | AppendInstruction(new (allocator_) HMonitorOperation( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2896 | LoadLocal(instruction.VRegA_11x(), DataType::Type::kReference), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2897 | HMonitorOperation::OperationKind::kEnter, |
| 2898 | dex_pc)); |
| 2899 | break; |
| 2900 | } |
| 2901 | |
| 2902 | case Instruction::MONITOR_EXIT: { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2903 | AppendInstruction(new (allocator_) HMonitorOperation( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2904 | LoadLocal(instruction.VRegA_11x(), DataType::Type::kReference), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2905 | HMonitorOperation::OperationKind::kExit, |
| 2906 | dex_pc)); |
| 2907 | break; |
| 2908 | } |
| 2909 | |
| 2910 | case Instruction::SPARSE_SWITCH: |
| 2911 | case Instruction::PACKED_SWITCH: { |
| 2912 | BuildSwitch(instruction, dex_pc); |
| 2913 | break; |
| 2914 | } |
| 2915 | |
| 2916 | default: |
| 2917 | VLOG(compiler) << "Did not compile " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2918 | << dex_file_->PrettyMethod(dex_compilation_unit_->GetDexMethodIndex()) |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2919 | << " because of unhandled instruction " |
| 2920 | << instruction.Name(); |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 2921 | MaybeRecordStat(compilation_stats_, |
| 2922 | MethodCompilationStat::kNotCompiledUnhandledInstruction); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2923 | return false; |
| 2924 | } |
| 2925 | return true; |
| 2926 | } // NOLINT(readability/fn_size) |
| 2927 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 2928 | ObjPtr<mirror::Class> HInstructionBuilder::LookupResolvedType( |
| 2929 | dex::TypeIndex type_index, |
| 2930 | const DexCompilationUnit& compilation_unit) const { |
| 2931 | return ClassLinker::LookupResolvedType( |
| 2932 | type_index, compilation_unit.GetDexCache().Get(), compilation_unit.GetClassLoader().Get()); |
| 2933 | } |
| 2934 | |
| 2935 | ObjPtr<mirror::Class> HInstructionBuilder::LookupReferrerClass() const { |
| 2936 | // TODO: Cache the result in a Handle<mirror::Class>. |
| 2937 | const DexFile::MethodId& method_id = |
| 2938 | dex_compilation_unit_->GetDexFile()->GetMethodId(dex_compilation_unit_->GetDexMethodIndex()); |
| 2939 | return LookupResolvedType(method_id.class_idx_, *dex_compilation_unit_); |
| 2940 | } |
| 2941 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2942 | } // namespace art |