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