Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 17 | #include "builder.h" |
| 18 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 20 | #include "base/arena_bit_vector.h" |
| 21 | #include "base/bit_vector-inl.h" |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 22 | #include "base/logging.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 23 | #include "class_linker.h" |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 24 | #include "dex/verified_method.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 25 | #include "dex_file-inl.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 26 | #include "dex_instruction-inl.h" |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 27 | #include "dex/verified_method.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 28 | #include "driver/compiler_driver-inl.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 29 | #include "driver/compiler_options.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 30 | #include "mirror/class_loader.h" |
| 31 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 32 | #include "nodes.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 33 | #include "primitive.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 34 | #include "scoped_thread_state_change.h" |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 35 | #include "ssa_builder.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 36 | #include "thread.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 37 | #include "utils/dex_cache_arrays_layout-inl.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 41 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 42 | graph_->SetNumberOfVRegs(count); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 43 | locals_.resize(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 44 | for (int i = 0; i < count; i++) { |
| 45 | HLocal* local = new (arena_) HLocal(i); |
| 46 | entry_block_->AddInstruction(local); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 47 | locals_[i] = local; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 51 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 52 | // dex_compilation_unit_ is null only when unit testing. |
| 53 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 54 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 58 | const char* shorty = dex_compilation_unit_->GetShorty(); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 59 | int locals_index = locals_.size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 60 | int parameter_index = 0; |
| 61 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 62 | const DexFile::MethodId& referrer_method_id = |
| 63 | dex_file_->GetMethodId(dex_compilation_unit_->GetDexMethodIndex()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 64 | if (!dex_compilation_unit_->IsStatic()) { |
| 65 | // Add the implicit 'this' argument, not expressed in the signature. |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 66 | HParameterValue* parameter = new (arena_) HParameterValue(*dex_file_, |
| 67 | referrer_method_id.class_idx_, |
| 68 | parameter_index++, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 69 | Primitive::kPrimNot, |
| 70 | true); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 71 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 72 | HLocal* local = GetLocalAt(locals_index++); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 73 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter, local->GetDexPc())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 74 | number_of_parameters--; |
| 75 | } |
| 76 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 77 | const DexFile::ProtoId& proto = dex_file_->GetMethodPrototype(referrer_method_id); |
| 78 | const DexFile::TypeList* arg_types = dex_file_->GetProtoParameters(proto); |
| 79 | for (int i = 0, shorty_pos = 1; i < number_of_parameters; i++) { |
| 80 | HParameterValue* parameter = new (arena_) HParameterValue( |
| 81 | *dex_file_, |
| 82 | arg_types->GetTypeItem(shorty_pos - 1).type_idx_, |
| 83 | parameter_index++, |
| 84 | Primitive::GetType(shorty[shorty_pos]), |
| 85 | false); |
| 86 | ++shorty_pos; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 87 | entry_block_->AddInstruction(parameter); |
| 88 | HLocal* local = GetLocalAt(locals_index++); |
| 89 | // Store the parameter value in the local that the dex code will use |
| 90 | // to reference that parameter. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 91 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter, local->GetDexPc())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 92 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 93 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 94 | if (is_wide) { |
| 95 | i++; |
| 96 | locals_index++; |
| 97 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 98 | } |
| 99 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 102 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 103 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 104 | int32_t target_offset = instruction.GetTargetOffset(); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 105 | HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset); |
| 106 | HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 107 | DCHECK(branch_target != nullptr); |
| 108 | DCHECK(fallthrough_target != nullptr); |
| 109 | PotentiallyAddSuspendCheck(branch_target, dex_pc); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 110 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
| 111 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 112 | T* comparison = new (arena_) T(first, second, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 113 | current_block_->AddInstruction(comparison); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 114 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 115 | current_block_->AddInstruction(ifinst); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 116 | current_block_->AddSuccessor(branch_target); |
| 117 | current_block_->AddSuccessor(fallthrough_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 118 | current_block_ = nullptr; |
| 119 | } |
| 120 | |
| 121 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 122 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 123 | int32_t target_offset = instruction.GetTargetOffset(); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 124 | HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset); |
| 125 | HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 126 | DCHECK(branch_target != nullptr); |
| 127 | DCHECK(fallthrough_target != nullptr); |
| 128 | PotentiallyAddSuspendCheck(branch_target, dex_pc); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 129 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
| 130 | T* comparison = new (arena_) T(value, graph_->GetIntConstant(0, dex_pc), dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 131 | current_block_->AddInstruction(comparison); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 132 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 133 | current_block_->AddInstruction(ifinst); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 134 | current_block_->AddSuccessor(branch_target); |
| 135 | current_block_->AddSuccessor(fallthrough_target); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 136 | current_block_ = nullptr; |
| 137 | } |
| 138 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 139 | void HGraphBuilder::MaybeRecordStat(MethodCompilationStat compilation_stat) { |
| 140 | if (compilation_stats_ != nullptr) { |
| 141 | compilation_stats_->RecordStat(compilation_stat); |
| 142 | } |
| 143 | } |
| 144 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 145 | bool HGraphBuilder::SkipCompilation(const DexFile::CodeItem& code_item, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 146 | size_t number_of_branches) { |
| 147 | const CompilerOptions& compiler_options = compiler_driver_->GetCompilerOptions(); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 148 | CompilerOptions::CompilerFilter compiler_filter = compiler_options.GetCompilerFilter(); |
| 149 | if (compiler_filter == CompilerOptions::kEverything) { |
| 150 | return false; |
| 151 | } |
| 152 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 153 | if (compiler_options.IsHugeMethod(code_item.insns_size_in_code_units_)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 154 | VLOG(compiler) << "Skip compilation of huge method " |
| 155 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 156 | << ": " << code_item.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 157 | MaybeRecordStat(MethodCompilationStat::kNotCompiledHugeMethod); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 158 | return true; |
| 159 | } |
| 160 | |
| 161 | // If it's large and contains no branches, it's likely to be machine generated initialization. |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 162 | if (compiler_options.IsLargeMethod(code_item.insns_size_in_code_units_) |
| 163 | && (number_of_branches == 0)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 164 | VLOG(compiler) << "Skip compilation of large method with no branch " |
| 165 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 166 | << ": " << code_item.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 167 | MaybeRecordStat(MethodCompilationStat::kNotCompiledLargeMethodNoBranches); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 168 | return true; |
| 169 | } |
| 170 | |
| 171 | return false; |
| 172 | } |
| 173 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 174 | void HGraphBuilder::CreateBlocksForTryCatch(const DexFile::CodeItem& code_item) { |
| 175 | if (code_item.tries_size_ == 0) { |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | // Create branch targets at the start/end of the TryItem range. These are |
| 180 | // places where the program might fall through into/out of the a block and |
| 181 | // where TryBoundary instructions will be inserted later. Other edges which |
| 182 | // enter/exit the try blocks are a result of branches/switches. |
| 183 | for (size_t idx = 0; idx < code_item.tries_size_; ++idx) { |
| 184 | const DexFile::TryItem* try_item = DexFile::GetTryItems(code_item, idx); |
| 185 | uint32_t dex_pc_start = try_item->start_addr_; |
| 186 | uint32_t dex_pc_end = dex_pc_start + try_item->insn_count_; |
| 187 | FindOrCreateBlockStartingAt(dex_pc_start); |
| 188 | if (dex_pc_end < code_item.insns_size_in_code_units_) { |
| 189 | // TODO: Do not create block if the last instruction cannot fall through. |
| 190 | FindOrCreateBlockStartingAt(dex_pc_end); |
| 191 | } else { |
| 192 | // The TryItem spans until the very end of the CodeItem (or beyond if |
| 193 | // invalid) and therefore cannot have any code afterwards. |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Create branch targets for exception handlers. |
| 198 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0); |
| 199 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 200 | for (uint32_t idx = 0; idx < handlers_size; ++idx) { |
| 201 | CatchHandlerIterator iterator(handlers_ptr); |
| 202 | for (; iterator.HasNext(); iterator.Next()) { |
| 203 | uint32_t address = iterator.GetHandlerAddress(); |
| 204 | HBasicBlock* block = FindOrCreateBlockStartingAt(address); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 205 | block->SetTryCatchInformation( |
| 206 | new (arena_) TryCatchInformation(iterator.GetHandlerTypeIndex(), *dex_file_)); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 207 | } |
| 208 | handlers_ptr = iterator.EndDataPointer(); |
| 209 | } |
| 210 | } |
| 211 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 212 | // Returns the TryItem stored for `block` or nullptr if there is no info for it. |
| 213 | static const DexFile::TryItem* GetTryItem( |
| 214 | HBasicBlock* block, |
| 215 | const ArenaSafeMap<uint32_t, const DexFile::TryItem*>& try_block_info) { |
| 216 | auto iterator = try_block_info.find(block->GetBlockId()); |
| 217 | return (iterator == try_block_info.end()) ? nullptr : iterator->second; |
| 218 | } |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 219 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 220 | void HGraphBuilder::LinkToCatchBlocks(HTryBoundary* try_boundary, |
| 221 | const DexFile::CodeItem& code_item, |
| 222 | const DexFile::TryItem* try_item) { |
| 223 | for (CatchHandlerIterator it(code_item, *try_item); it.HasNext(); it.Next()) { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 224 | try_boundary->AddExceptionHandler(FindBlockStartingAt(it.GetHandlerAddress())); |
| 225 | } |
| 226 | } |
| 227 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 228 | void HGraphBuilder::InsertTryBoundaryBlocks(const DexFile::CodeItem& code_item) { |
| 229 | if (code_item.tries_size_ == 0) { |
| 230 | return; |
| 231 | } |
| 232 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 233 | // Keep a map of all try blocks and their respective TryItems. We do not use |
| 234 | // the block's pointer but rather its id to ensure deterministic iteration. |
| 235 | ArenaSafeMap<uint32_t, const DexFile::TryItem*> try_block_info( |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 236 | std::less<uint32_t>(), arena_->Adapter(kArenaAllocGraphBuilder)); |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 237 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 238 | // Obtain TryItem information for blocks with throwing instructions, and split |
| 239 | // blocks which are both try & catch to simplify the graph. |
| 240 | // NOTE: We are appending new blocks inside the loop, so we need to use index |
| 241 | // because iterators can be invalidated. We remember the initial size to avoid |
| 242 | // iterating over the new blocks which cannot throw. |
| 243 | for (size_t i = 0, e = graph_->GetBlocks().size(); i < e; ++i) { |
| 244 | HBasicBlock* block = graph_->GetBlocks()[i]; |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 245 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 246 | // Do not bother creating exceptional edges for try blocks which have no |
| 247 | // throwing instructions. In that case we simply assume that the block is |
| 248 | // not covered by a TryItem. This prevents us from creating a throw-catch |
| 249 | // loop for synchronized blocks. |
| 250 | if (block->HasThrowingInstructions()) { |
| 251 | // Try to find a TryItem covering the block. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 252 | DCHECK_NE(block->GetDexPc(), kNoDexPc) << "Block must have a dex_pc to find its TryItem."; |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 253 | const int32_t try_item_idx = DexFile::FindTryItem(code_item, block->GetDexPc()); |
| 254 | if (try_item_idx != -1) { |
| 255 | // Block throwing and in a TryItem. Store the try block information. |
| 256 | HBasicBlock* throwing_block = block; |
| 257 | if (block->IsCatchBlock()) { |
| 258 | // Simplify blocks which are both try and catch, otherwise we would |
| 259 | // need a strategy for splitting exceptional edges. We split the block |
| 260 | // after the move-exception (if present) and mark the first part not |
| 261 | // throwing. The normal-flow edge between them will be split later. |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 262 | throwing_block = block->SplitCatchBlockAfterMoveException(); |
| 263 | // Move-exception does not throw and the block has throwing insructions |
| 264 | // so it must have been possible to split it. |
| 265 | DCHECK(throwing_block != nullptr); |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 266 | } |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 267 | |
| 268 | try_block_info.Put(throwing_block->GetBlockId(), |
| 269 | DexFile::GetTryItems(code_item, try_item_idx)); |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 270 | } |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 271 | } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 272 | } |
| 273 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 274 | // Do a pass over the try blocks and insert entering TryBoundaries where at |
| 275 | // least one predecessor is not covered by the same TryItem as the try block. |
| 276 | // We do not split each edge separately, but rather create one boundary block |
| 277 | // that all predecessors are relinked to. This preserves loop headers (b/23895756). |
| 278 | for (auto entry : try_block_info) { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 279 | HBasicBlock* try_block = graph_->GetBlocks()[entry.first]; |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 280 | for (HBasicBlock* predecessor : try_block->GetPredecessors()) { |
| 281 | if (GetTryItem(predecessor, try_block_info) != entry.second) { |
| 282 | // Found a predecessor not covered by the same TryItem. Insert entering |
| 283 | // boundary block. |
| 284 | HTryBoundary* try_entry = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 285 | new (arena_) HTryBoundary(HTryBoundary::BoundaryKind::kEntry, try_block->GetDexPc()); |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 286 | try_block->CreateImmediateDominator()->AddInstruction(try_entry); |
| 287 | LinkToCatchBlocks(try_entry, code_item, entry.second); |
| 288 | break; |
| 289 | } |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 290 | } |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 291 | } |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 292 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 293 | // Do a second pass over the try blocks and insert exit TryBoundaries where |
| 294 | // the successor is not in the same TryItem. |
| 295 | for (auto entry : try_block_info) { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 296 | HBasicBlock* try_block = graph_->GetBlocks()[entry.first]; |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 297 | // NOTE: Do not use iterators because SplitEdge would invalidate them. |
| 298 | for (size_t i = 0, e = try_block->GetSuccessors().size(); i < e; ++i) { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 299 | HBasicBlock* successor = try_block->GetSuccessors()[i]; |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 300 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 301 | // If the successor is a try block, all of its predecessors must be |
| 302 | // covered by the same TryItem. Otherwise the previous pass would have |
| 303 | // created a non-throwing boundary block. |
| 304 | if (GetTryItem(successor, try_block_info) != nullptr) { |
| 305 | DCHECK_EQ(entry.second, GetTryItem(successor, try_block_info)); |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 306 | continue; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 307 | } |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 308 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 309 | // Preserve the invariant that Return(Void) always jumps to Exit by moving |
| 310 | // it outside the try block if necessary. |
| 311 | HInstruction* last_instruction = try_block->GetLastInstruction(); |
| 312 | if (last_instruction->IsReturn() || last_instruction->IsReturnVoid()) { |
| 313 | DCHECK_EQ(successor, exit_block_); |
| 314 | successor = try_block->SplitBefore(last_instruction); |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 315 | } |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 316 | |
| 317 | // Insert TryBoundary and link to catch blocks. |
| 318 | HTryBoundary* try_exit = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 319 | new (arena_) HTryBoundary(HTryBoundary::BoundaryKind::kExit, successor->GetDexPc()); |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 320 | graph_->SplitEdge(try_block, successor)->AddInstruction(try_exit); |
| 321 | LinkToCatchBlocks(try_exit, code_item, entry.second); |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 322 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 326 | GraphAnalysisResult HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item, |
| 327 | StackHandleScopeCollection* handles) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 328 | DCHECK(graph_->GetBlocks().empty()); |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 329 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 330 | const uint16_t* code_ptr = code_item.insns_; |
| 331 | const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 332 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 333 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 334 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 335 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 336 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 337 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 338 | graph_->SetEntryBlock(entry_block_); |
| 339 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 340 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 341 | graph_->SetHasTryCatch(code_item.tries_size_ != 0); |
| 342 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 343 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 344 | graph_->SetMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 345 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 346 | // Compute the number of dex instructions, blocks, and branches. We will |
| 347 | // check these values against limits given to the compiler. |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 348 | size_t number_of_branches = 0; |
| 349 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 350 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 351 | // start a new block, and create these blocks. |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 352 | if (!ComputeBranchTargets(code_ptr, code_end, &number_of_branches)) { |
| 353 | MaybeRecordStat(MethodCompilationStat::kNotCompiledBranchOutsideMethodCode); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 354 | return kAnalysisInvalidBytecode; |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 355 | } |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 356 | |
| 357 | // Note that the compiler driver is null when unit testing. |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 358 | if ((compiler_driver_ != nullptr) && SkipCompilation(code_item, number_of_branches)) { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 359 | return kAnalysisInvalidBytecode; |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 360 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 361 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 362 | // Find locations where we want to generate extra stackmaps for native debugging. |
| 363 | // This allows us to generate the info only at interesting points (for example, |
| 364 | // at start of java statement) rather than before every dex instruction. |
| 365 | const bool native_debuggable = compiler_driver_ != nullptr && |
| 366 | compiler_driver_->GetCompilerOptions().GetNativeDebuggable(); |
| 367 | ArenaBitVector* native_debug_info_locations; |
| 368 | if (native_debuggable) { |
| 369 | const uint32_t num_instructions = code_item.insns_size_in_code_units_; |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 370 | native_debug_info_locations = |
| 371 | ArenaBitVector::Create(arena_, num_instructions, false, kArenaAllocGraphBuilder); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 372 | FindNativeDebugInfoLocations(code_item, native_debug_info_locations); |
| 373 | } |
| 374 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 375 | CreateBlocksForTryCatch(code_item); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 376 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 377 | InitializeParameters(code_item.ins_size_); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 378 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 379 | size_t dex_pc = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 380 | while (code_ptr < code_end) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 381 | // Update the current block if dex_pc starts a new block. |
| 382 | MaybeUpdateCurrentBlock(dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 383 | const Instruction& instruction = *Instruction::At(code_ptr); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 384 | if (native_debuggable && native_debug_info_locations->IsBitSet(dex_pc)) { |
| 385 | if (current_block_ != nullptr) { |
| 386 | current_block_->AddInstruction(new (arena_) HNativeDebugInfo(dex_pc)); |
| 387 | } |
| 388 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 389 | if (!AnalyzeDexInstruction(instruction, dex_pc)) { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 390 | return kAnalysisInvalidBytecode; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 391 | } |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 392 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 393 | code_ptr += instruction.SizeInCodeUnits(); |
| 394 | } |
| 395 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 396 | // Add Exit to the exit block. |
David Brazdil | 3e18738 | 2015-06-26 09:59:52 +0000 | [diff] [blame] | 397 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 398 | // Add the suspend check to the entry block. |
| 399 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 400 | entry_block_->AddInstruction(new (arena_) HGoto()); |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 401 | // Add the exit block at the end. |
| 402 | graph_->AddBlock(exit_block_); |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 403 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 404 | // Iterate over blocks covered by TryItems and insert TryBoundaries at entry |
| 405 | // and exit points. This requires all control-flow instructions and |
| 406 | // non-exceptional edges to have been created. |
| 407 | InsertTryBoundaryBlocks(code_item); |
| 408 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 409 | GraphAnalysisResult result = graph_->BuildDominatorTree(); |
| 410 | if (result != kAnalysisSuccess) { |
| 411 | return result; |
| 412 | } |
| 413 | |
| 414 | graph_->InitializeInexactObjectRTI(handles); |
| 415 | return SsaBuilder(graph_, handles).BuildSsa(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 416 | } |
| 417 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 418 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t dex_pc) { |
| 419 | HBasicBlock* block = FindBlockStartingAt(dex_pc); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 420 | if (block == nullptr) { |
| 421 | return; |
| 422 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 423 | |
| 424 | if (current_block_ != nullptr) { |
| 425 | // Branching instructions clear current_block, so we know |
| 426 | // the last instruction of the current block is not a branching |
| 427 | // instruction. We add an unconditional goto to the found block. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 428 | current_block_->AddInstruction(new (arena_) HGoto(dex_pc)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 429 | current_block_->AddSuccessor(block); |
| 430 | } |
| 431 | graph_->AddBlock(block); |
| 432 | current_block_ = block; |
| 433 | } |
| 434 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 435 | void HGraphBuilder::FindNativeDebugInfoLocations(const DexFile::CodeItem& code_item, |
| 436 | ArenaBitVector* locations) { |
| 437 | // The callback gets called when the line number changes. |
| 438 | // In other words, it marks the start of new java statement. |
| 439 | struct Callback { |
| 440 | static bool Position(void* ctx, const DexFile::PositionInfo& entry) { |
| 441 | static_cast<ArenaBitVector*>(ctx)->SetBit(entry.address_); |
| 442 | return false; |
| 443 | } |
| 444 | }; |
| 445 | dex_file_->DecodeDebugPositionInfo(&code_item, Callback::Position, locations); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 446 | // Instruction-specific tweaks. |
| 447 | const Instruction* const begin = Instruction::At(code_item.insns_); |
| 448 | const Instruction* const end = begin->RelativeAt(code_item.insns_size_in_code_units_); |
| 449 | for (const Instruction* inst = begin; inst < end; inst = inst->Next()) { |
| 450 | switch (inst->Opcode()) { |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 451 | case Instruction::MOVE_EXCEPTION: { |
| 452 | // Stop in native debugger after the exception has been moved. |
| 453 | // The compiler also expects the move at the start of basic block so |
| 454 | // we do not want to interfere by inserting native-debug-info before it. |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 455 | locations->ClearBit(inst->GetDexPc(code_item.insns_)); |
| 456 | const Instruction* next = inst->Next(); |
| 457 | if (next < end) { |
| 458 | locations->SetBit(next->GetDexPc(code_item.insns_)); |
| 459 | } |
| 460 | break; |
| 461 | } |
| 462 | default: |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 468 | bool HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 469 | const uint16_t* code_end, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 470 | size_t* number_of_branches) { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 471 | branch_targets_.resize(code_end - code_ptr, nullptr); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 472 | |
| 473 | // Create the first block for the dex instructions, single successor of the entry block. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 474 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 475 | branch_targets_[0] = block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 476 | entry_block_->AddSuccessor(block); |
| 477 | |
| 478 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 479 | // the locations these instructions branch to. |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 480 | uint32_t dex_pc = 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 481 | while (code_ptr < code_end) { |
| 482 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 483 | if (instruction.IsBranch()) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 484 | (*number_of_branches)++; |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 485 | int32_t target = instruction.GetTargetOffset() + dex_pc; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 486 | // Create a block for the target instruction. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 487 | FindOrCreateBlockStartingAt(target); |
| 488 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 489 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 490 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 491 | |
David Brazdil | fe65946 | 2015-06-24 14:23:56 +0100 | [diff] [blame] | 492 | if (instruction.CanFlowThrough()) { |
| 493 | if (code_ptr >= code_end) { |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 494 | // In the normal case we should never hit this but someone can artificially forge a dex |
| 495 | // file to fall-through out the method code. In this case we bail out compilation. |
| 496 | return false; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 497 | } else { |
| 498 | FindOrCreateBlockStartingAt(dex_pc); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 499 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 500 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 501 | } else if (instruction.IsSwitch()) { |
| 502 | SwitchTable table(instruction, dex_pc, instruction.Opcode() == Instruction::SPARSE_SWITCH); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 503 | |
| 504 | uint16_t num_entries = table.GetNumEntries(); |
| 505 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 506 | // In a packed-switch, the entry at index 0 is the starting key. In a sparse-switch, the |
| 507 | // entry at index 0 is the first key, and values are after *all* keys. |
| 508 | size_t offset = table.GetFirstValueIndex(); |
| 509 | |
| 510 | // Use a larger loop counter type to avoid overflow issues. |
| 511 | for (size_t i = 0; i < num_entries; ++i) { |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 512 | // The target of the case. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 513 | uint32_t target = dex_pc + table.GetEntryAt(i + offset); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 514 | FindOrCreateBlockStartingAt(target); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 515 | |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 516 | // Create a block for the switch-case logic. The block gets the dex_pc |
| 517 | // of the SWITCH instruction because it is part of its semantics. |
| 518 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 519 | branch_targets_[table.GetDexPcForIndex(i)] = block; |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | // Fall-through. Add a block if there is more code afterwards. |
| 523 | dex_pc += instruction.SizeInCodeUnits(); |
| 524 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 525 | if (code_ptr >= code_end) { |
| 526 | // In the normal case we should never hit this but someone can artificially forge a dex |
| 527 | // file to fall-through out the method code. In this case we bail out compilation. |
| 528 | // (A switch can fall-through so we don't need to check CanFlowThrough().) |
| 529 | return false; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 530 | } else { |
| 531 | FindOrCreateBlockStartingAt(dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 532 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 533 | } else { |
| 534 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 535 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 538 | return true; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 539 | } |
| 540 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 541 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t dex_pc) const { |
| 542 | DCHECK_GE(dex_pc, 0); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 543 | return branch_targets_[dex_pc]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | HBasicBlock* HGraphBuilder::FindOrCreateBlockStartingAt(int32_t dex_pc) { |
| 547 | HBasicBlock* block = FindBlockStartingAt(dex_pc); |
| 548 | if (block == nullptr) { |
| 549 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 550 | branch_targets_[dex_pc] = block; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 551 | } |
| 552 | return block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 555 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 556 | void HGraphBuilder::Unop_12x(const Instruction& instruction, |
| 557 | Primitive::Type type, |
| 558 | uint32_t dex_pc) { |
| 559 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 560 | current_block_->AddInstruction(new (arena_) T(type, first, dex_pc)); |
| 561 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 562 | } |
| 563 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 564 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 565 | Primitive::Type input_type, |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 566 | Primitive::Type result_type, |
| 567 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 568 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type, dex_pc); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 569 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 570 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 574 | void HGraphBuilder::Binop_23x(const Instruction& instruction, |
| 575 | Primitive::Type type, |
| 576 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 577 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 578 | HInstruction* second = LoadLocal(instruction.VRegC(), type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 579 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 580 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 584 | void HGraphBuilder::Binop_23x_shift(const Instruction& instruction, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 585 | Primitive::Type type, |
| 586 | uint32_t dex_pc) { |
| 587 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 588 | HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt, dex_pc); |
| 589 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 590 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 593 | void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction, |
| 594 | Primitive::Type type, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 595 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 596 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 597 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 598 | HInstruction* second = LoadLocal(instruction.VRegC(), type, dex_pc); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 599 | current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 600 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 603 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 604 | void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type, |
| 605 | uint32_t dex_pc) { |
| 606 | HInstruction* first = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 607 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 608 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 609 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 613 | void HGraphBuilder::Binop_12x(const Instruction& instruction, |
| 614 | Primitive::Type type, |
| 615 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 616 | HInstruction* first = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 617 | HInstruction* second = LoadLocal(instruction.VRegB(), type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 618 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 619 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 623 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
| 624 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 625 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 626 | if (reverse) { |
| 627 | std::swap(first, second); |
| 628 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 629 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second, dex_pc)); |
| 630 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 634 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
| 635 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 636 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 637 | if (reverse) { |
| 638 | std::swap(first, second); |
| 639 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 640 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second, dex_pc)); |
| 641 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 642 | } |
| 643 | |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 644 | static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 645 | Thread* self = Thread::Current(); |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 646 | return cu->IsConstructor() |
| 647 | && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 650 | void HGraphBuilder::BuildReturn(const Instruction& instruction, |
| 651 | Primitive::Type type, |
| 652 | uint32_t dex_pc) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 653 | if (type == Primitive::kPrimVoid) { |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 654 | if (graph_->ShouldGenerateConstructorBarrier()) { |
| 655 | // The compilation unit is null during testing. |
| 656 | if (dex_compilation_unit_ != nullptr) { |
| 657 | DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_)) |
| 658 | << "Inconsistent use of ShouldGenerateConstructorBarrier. Should not generate a barrier."; |
| 659 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 660 | current_block_->AddInstruction(new (arena_) HMemoryBarrier(kStoreStore, dex_pc)); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 661 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 662 | current_block_->AddInstruction(new (arena_) HReturnVoid(dex_pc)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 663 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 664 | HInstruction* value = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 665 | current_block_->AddInstruction(new (arena_) HReturn(value, dex_pc)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 666 | } |
| 667 | current_block_->AddSuccessor(exit_block_); |
| 668 | current_block_ = nullptr; |
| 669 | } |
| 670 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 671 | static InvokeType GetInvokeTypeFromOpCode(Instruction::Code opcode) { |
| 672 | switch (opcode) { |
| 673 | case Instruction::INVOKE_STATIC: |
| 674 | case Instruction::INVOKE_STATIC_RANGE: |
| 675 | return kStatic; |
| 676 | case Instruction::INVOKE_DIRECT: |
| 677 | case Instruction::INVOKE_DIRECT_RANGE: |
| 678 | return kDirect; |
| 679 | case Instruction::INVOKE_VIRTUAL: |
| 680 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 681 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 682 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: |
| 683 | return kVirtual; |
| 684 | case Instruction::INVOKE_INTERFACE: |
| 685 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 686 | return kInterface; |
| 687 | case Instruction::INVOKE_SUPER_RANGE: |
| 688 | case Instruction::INVOKE_SUPER: |
| 689 | return kSuper; |
| 690 | default: |
| 691 | LOG(FATAL) << "Unexpected invoke opcode: " << opcode; |
| 692 | UNREACHABLE(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 693 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 694 | } |
| 695 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 696 | ArtMethod* HGraphBuilder::ResolveMethod(uint16_t method_idx, InvokeType invoke_type) { |
| 697 | ScopedObjectAccess soa(Thread::Current()); |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 698 | StackHandleScope<3> hs(soa.Self()); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 699 | |
| 700 | ClassLinker* class_linker = dex_compilation_unit_->GetClassLinker(); |
| 701 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 702 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 703 | Handle<mirror::Class> compiling_class(hs.NewHandle(GetCompilingClass())); |
| 704 | |
Andreas Gampe | dae2414 | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 705 | ArtMethod* resolved_method = class_linker->ResolveMethod<ClassLinker::kForceICCECheck>( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 706 | *dex_compilation_unit_->GetDexFile(), |
| 707 | method_idx, |
| 708 | dex_compilation_unit_->GetDexCache(), |
| 709 | class_loader, |
| 710 | /* referrer */ nullptr, |
| 711 | invoke_type); |
| 712 | |
| 713 | if (UNLIKELY(resolved_method == nullptr)) { |
| 714 | // Clean up any exception left by type resolution. |
| 715 | soa.Self()->ClearException(); |
| 716 | return nullptr; |
| 717 | } |
| 718 | |
| 719 | // Check access. The class linker has a fast path for looking into the dex cache |
| 720 | // and does not check the access if it hits it. |
| 721 | if (compiling_class.Get() == nullptr) { |
| 722 | if (!resolved_method->IsPublic()) { |
| 723 | return nullptr; |
| 724 | } |
| 725 | } else if (!compiling_class->CanAccessResolvedMethod(resolved_method->GetDeclaringClass(), |
| 726 | resolved_method, |
| 727 | dex_compilation_unit_->GetDexCache().Get(), |
| 728 | method_idx)) { |
| 729 | return nullptr; |
| 730 | } |
| 731 | |
| 732 | // We have to special case the invoke-super case, as ClassLinker::ResolveMethod does not. |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 733 | // We need to look at the referrer's super class vtable. We need to do this to know if we need to |
| 734 | // make this an invoke-unresolved to handle cross-dex invokes or abstract super methods, both of |
| 735 | // which require runtime handling. |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 736 | if (invoke_type == kSuper) { |
| 737 | if (compiling_class.Get() == nullptr) { |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 738 | // We could not determine the method's class we need to wait until runtime. |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 739 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 740 | return nullptr; |
| 741 | } |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 742 | ArtMethod* current_method = graph_->GetArtMethod(); |
| 743 | DCHECK(current_method != nullptr); |
| 744 | Handle<mirror::Class> methods_class(hs.NewHandle( |
| 745 | dex_compilation_unit_->GetClassLinker()->ResolveReferencedClassOfMethod(Thread::Current(), |
| 746 | method_idx, |
| 747 | current_method))); |
| 748 | if (methods_class.Get() == nullptr) { |
| 749 | // Invoking a super method requires knowing the actual super class. If we did not resolve |
| 750 | // the compiling method's declaring class (which only happens for ahead of time |
| 751 | // compilation), bail out. |
| 752 | DCHECK(Runtime::Current()->IsAotCompiler()); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 753 | return nullptr; |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 754 | } else { |
| 755 | ArtMethod* actual_method; |
| 756 | if (methods_class->IsInterface()) { |
| 757 | actual_method = methods_class->FindVirtualMethodForInterfaceSuper( |
| 758 | resolved_method, class_linker->GetImagePointerSize()); |
| 759 | } else { |
| 760 | uint16_t vtable_index = resolved_method->GetMethodIndex(); |
| 761 | actual_method = compiling_class->GetSuperClass()->GetVTableEntry( |
| 762 | vtable_index, class_linker->GetImagePointerSize()); |
| 763 | } |
| 764 | if (actual_method != resolved_method && |
| 765 | !IsSameDexFile(*actual_method->GetDexFile(), *dex_compilation_unit_->GetDexFile())) { |
| 766 | // The back-end code generator relies on this check in order to ensure that it will not |
| 767 | // attempt to read the dex_cache with a dex_method_index that is not from the correct |
| 768 | // dex_file. If we didn't do this check then the dex_method_index will not be updated in the |
| 769 | // builder, which means that the code-generator (and compiler driver during sharpening and |
| 770 | // inliner, maybe) might invoke an incorrect method. |
| 771 | // TODO: The actual method could still be referenced in the current dex file, so we |
| 772 | // could try locating it. |
| 773 | // TODO: Remove the dex_file restriction. |
| 774 | return nullptr; |
| 775 | } |
| 776 | if (!actual_method->IsInvokable()) { |
| 777 | // Fail if the actual method cannot be invoked. Otherwise, the runtime resolution stub |
| 778 | // could resolve the callee to the wrong method. |
| 779 | return nullptr; |
| 780 | } |
| 781 | resolved_method = actual_method; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 782 | } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | // Check for incompatible class changes. The class linker has a fast path for |
| 786 | // looking into the dex cache and does not check incompatible class changes if it hits it. |
| 787 | if (resolved_method->CheckIncompatibleClassChange(invoke_type)) { |
| 788 | return nullptr; |
| 789 | } |
| 790 | |
| 791 | return resolved_method; |
| 792 | } |
| 793 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 794 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
| 795 | uint32_t dex_pc, |
| 796 | uint32_t method_idx, |
| 797 | uint32_t number_of_vreg_arguments, |
| 798 | bool is_range, |
| 799 | uint32_t* args, |
| 800 | uint32_t register_index) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 801 | InvokeType invoke_type = GetInvokeTypeFromOpCode(instruction.Opcode()); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 802 | const char* descriptor = dex_file_->GetMethodShorty(method_idx); |
| 803 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
| 804 | |
| 805 | // Remove the return type from the 'proto'. |
| 806 | size_t number_of_arguments = strlen(descriptor) - 1; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 807 | if (invoke_type != kStatic) { // instance call |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 808 | // One extra argument for 'this'. |
| 809 | number_of_arguments++; |
| 810 | } |
| 811 | |
| 812 | MethodReference target_method(dex_file_, method_idx); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 813 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 814 | // Special handling for string init. |
| 815 | int32_t string_init_offset = 0; |
| 816 | bool is_string_init = compiler_driver_->IsStringInit(method_idx, |
| 817 | dex_file_, |
| 818 | &string_init_offset); |
| 819 | // Replace calls to String.<init> with StringFactory. |
| 820 | if (is_string_init) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 821 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 822 | HInvokeStaticOrDirect::MethodLoadKind::kStringInit, |
| 823 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 824 | dchecked_integral_cast<uint64_t>(string_init_offset), |
| 825 | 0U |
| 826 | }; |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 827 | HInvoke* invoke = new (arena_) HInvokeStaticOrDirect( |
| 828 | arena_, |
| 829 | number_of_arguments - 1, |
| 830 | Primitive::kPrimNot /*return_type */, |
| 831 | dex_pc, |
| 832 | method_idx, |
| 833 | target_method, |
| 834 | dispatch_info, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 835 | invoke_type, |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 836 | kStatic /* optimized_invoke_type */, |
| 837 | HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit); |
| 838 | return HandleStringInit(invoke, |
| 839 | number_of_vreg_arguments, |
| 840 | args, |
| 841 | register_index, |
| 842 | is_range, |
| 843 | descriptor); |
| 844 | } |
| 845 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 846 | ArtMethod* resolved_method = ResolveMethod(method_idx, invoke_type); |
| 847 | |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 848 | if (UNLIKELY(resolved_method == nullptr)) { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 849 | MaybeRecordStat(MethodCompilationStat::kUnresolvedMethod); |
| 850 | HInvoke* invoke = new (arena_) HInvokeUnresolved(arena_, |
| 851 | number_of_arguments, |
| 852 | return_type, |
| 853 | dex_pc, |
| 854 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 855 | invoke_type); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 856 | return HandleInvoke(invoke, |
| 857 | number_of_vreg_arguments, |
| 858 | args, |
| 859 | register_index, |
| 860 | is_range, |
| 861 | descriptor, |
| 862 | nullptr /* clinit_check */); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 863 | } |
| 864 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 865 | // Potential class initialization check, in the case of a static method call. |
| 866 | HClinitCheck* clinit_check = nullptr; |
| 867 | HInvoke* invoke = nullptr; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 868 | if (invoke_type == kDirect || invoke_type == kStatic || invoke_type == kSuper) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 869 | // By default, consider that the called method implicitly requires |
| 870 | // an initialization check of its declaring method. |
| 871 | HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement |
| 872 | = HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 873 | ScopedObjectAccess soa(Thread::Current()); |
| 874 | if (invoke_type == kStatic) { |
| 875 | clinit_check = ProcessClinitCheckForInvoke( |
| 876 | dex_pc, resolved_method, method_idx, &clinit_check_requirement); |
| 877 | } else if (invoke_type == kSuper) { |
| 878 | if (IsSameDexFile(*resolved_method->GetDexFile(), *dex_compilation_unit_->GetDexFile())) { |
| 879 | // Update the target method to the one resolved. Note that this may be a no-op if |
| 880 | // we resolved to the method referenced by the instruction. |
| 881 | method_idx = resolved_method->GetDexMethodIndex(); |
| 882 | target_method = MethodReference(dex_file_, method_idx); |
| 883 | } |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 884 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 885 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 886 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 887 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 888 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 889 | 0u, |
| 890 | 0U |
| 891 | }; |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 892 | invoke = new (arena_) HInvokeStaticOrDirect(arena_, |
| 893 | number_of_arguments, |
| 894 | return_type, |
| 895 | dex_pc, |
| 896 | method_idx, |
| 897 | target_method, |
| 898 | dispatch_info, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 899 | invoke_type, |
| 900 | invoke_type, |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 901 | clinit_check_requirement); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 902 | } else if (invoke_type == kVirtual) { |
| 903 | ScopedObjectAccess soa(Thread::Current()); // Needed for the method index |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 904 | invoke = new (arena_) HInvokeVirtual(arena_, |
| 905 | number_of_arguments, |
| 906 | return_type, |
| 907 | dex_pc, |
| 908 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 909 | resolved_method->GetMethodIndex()); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 910 | } else { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 911 | DCHECK_EQ(invoke_type, kInterface); |
| 912 | ScopedObjectAccess soa(Thread::Current()); // Needed for the method index |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 913 | invoke = new (arena_) HInvokeInterface(arena_, |
| 914 | number_of_arguments, |
| 915 | return_type, |
| 916 | dex_pc, |
| 917 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 918 | resolved_method->GetDexMethodIndex()); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 919 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 920 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 921 | return HandleInvoke(invoke, |
| 922 | number_of_vreg_arguments, |
| 923 | args, |
| 924 | register_index, |
| 925 | is_range, |
| 926 | descriptor, |
| 927 | clinit_check); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 928 | } |
| 929 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 930 | bool HGraphBuilder::BuildNewInstance(uint16_t type_index, uint32_t dex_pc) { |
| 931 | bool finalizable; |
| 932 | bool can_throw = NeedsAccessCheck(type_index, &finalizable); |
| 933 | |
| 934 | // Only the non-resolved entrypoint handles the finalizable class case. If we |
| 935 | // need access checks, then we haven't resolved the method and the class may |
| 936 | // again be finalizable. |
| 937 | QuickEntrypointEnum entrypoint = (finalizable || can_throw) |
| 938 | ? kQuickAllocObject |
| 939 | : kQuickAllocObjectInitialized; |
| 940 | |
| 941 | ScopedObjectAccess soa(Thread::Current()); |
| 942 | StackHandleScope<3> hs(soa.Self()); |
| 943 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 944 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 945 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
| 946 | Handle<mirror::Class> resolved_class(hs.NewHandle(dex_cache->GetResolvedType(type_index))); |
| 947 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 948 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 949 | outer_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), outer_dex_file))); |
| 950 | |
| 951 | if (outer_dex_cache.Get() != dex_cache.Get()) { |
| 952 | // We currently do not support inlining allocations across dex files. |
| 953 | return false; |
| 954 | } |
| 955 | |
| 956 | HLoadClass* load_class = new (arena_) HLoadClass( |
| 957 | graph_->GetCurrentMethod(), |
| 958 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 959 | outer_dex_file, |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 960 | IsOutermostCompilingClass(type_index), |
| 961 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 962 | /*needs_access_check*/ can_throw, |
| 963 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, type_index)); |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 964 | |
| 965 | current_block_->AddInstruction(load_class); |
| 966 | HInstruction* cls = load_class; |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 967 | if (!IsInitialized(resolved_class)) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 968 | cls = new (arena_) HClinitCheck(load_class, dex_pc); |
| 969 | current_block_->AddInstruction(cls); |
| 970 | } |
| 971 | |
| 972 | current_block_->AddInstruction(new (arena_) HNewInstance( |
| 973 | cls, |
| 974 | graph_->GetCurrentMethod(), |
| 975 | dex_pc, |
| 976 | type_index, |
| 977 | *dex_compilation_unit_->GetDexFile(), |
| 978 | can_throw, |
| 979 | finalizable, |
| 980 | entrypoint)); |
| 981 | return true; |
| 982 | } |
| 983 | |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 984 | static bool IsSubClass(mirror::Class* to_test, mirror::Class* super_class) |
| 985 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 986 | return to_test != nullptr && !to_test->IsInterface() && to_test->IsSubClass(super_class); |
| 987 | } |
| 988 | |
| 989 | bool HGraphBuilder::IsInitialized(Handle<mirror::Class> cls) const { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 990 | if (cls.Get() == nullptr) { |
| 991 | return false; |
| 992 | } |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 993 | |
| 994 | // `CanAssumeClassIsLoaded` will return true if we're JITting, or will |
| 995 | // check whether the class is in an image for the AOT compilation. |
| 996 | if (cls->IsInitialized() && |
| 997 | compiler_driver_->CanAssumeClassIsLoaded(cls.Get())) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 998 | return true; |
| 999 | } |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1000 | |
| 1001 | if (IsSubClass(GetOutermostCompilingClass(), cls.Get())) { |
| 1002 | return true; |
| 1003 | } |
| 1004 | |
| 1005 | // TODO: We should walk over the inlined methods, but we don't pass |
| 1006 | // that information to the builder. |
| 1007 | if (IsSubClass(GetCompilingClass(), cls.Get())) { |
| 1008 | return true; |
| 1009 | } |
| 1010 | |
| 1011 | return false; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1014 | HClinitCheck* HGraphBuilder::ProcessClinitCheckForInvoke( |
| 1015 | uint32_t dex_pc, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1016 | ArtMethod* resolved_method, |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1017 | uint32_t method_idx, |
| 1018 | HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1019 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 1020 | Thread* self = Thread::Current(); |
| 1021 | StackHandleScope<4> hs(self); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1022 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1023 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1024 | self, *dex_compilation_unit_->GetDexFile()))); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1025 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1026 | outer_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1027 | self, outer_dex_file))); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1028 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1029 | Handle<mirror::Class> resolved_method_class(hs.NewHandle(resolved_method->GetDeclaringClass())); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1030 | |
| 1031 | // The index at which the method's class is stored in the DexCache's type array. |
| 1032 | uint32_t storage_index = DexFile::kDexNoIndex; |
| 1033 | bool is_outer_class = (resolved_method->GetDeclaringClass() == outer_class.Get()); |
| 1034 | if (is_outer_class) { |
| 1035 | storage_index = outer_class->GetDexTypeIndex(); |
| 1036 | } else if (outer_dex_cache.Get() == dex_cache.Get()) { |
| 1037 | // Get `storage_index` from IsClassOfStaticMethodAvailableToReferrer. |
| 1038 | compiler_driver_->IsClassOfStaticMethodAvailableToReferrer(outer_dex_cache.Get(), |
| 1039 | GetCompilingClass(), |
| 1040 | resolved_method, |
| 1041 | method_idx, |
| 1042 | &storage_index); |
| 1043 | } |
| 1044 | |
| 1045 | HClinitCheck* clinit_check = nullptr; |
| 1046 | |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1047 | if (IsInitialized(resolved_method_class)) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1048 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 1049 | } else if (storage_index != DexFile::kDexNoIndex) { |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1050 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit; |
| 1051 | HLoadClass* load_class = new (arena_) HLoadClass( |
| 1052 | graph_->GetCurrentMethod(), |
| 1053 | storage_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1054 | outer_dex_file, |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1055 | is_outer_class, |
| 1056 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1057 | /*needs_access_check*/ false, |
| 1058 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, storage_index)); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1059 | current_block_->AddInstruction(load_class); |
| 1060 | clinit_check = new (arena_) HClinitCheck(load_class, dex_pc); |
| 1061 | current_block_->AddInstruction(clinit_check); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1062 | } |
| 1063 | return clinit_check; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1066 | bool HGraphBuilder::SetupInvokeArguments(HInvoke* invoke, |
| 1067 | uint32_t number_of_vreg_arguments, |
| 1068 | uint32_t* args, |
| 1069 | uint32_t register_index, |
| 1070 | bool is_range, |
| 1071 | const char* descriptor, |
| 1072 | size_t start_index, |
| 1073 | size_t* argument_index) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1074 | uint32_t descriptor_index = 1; // Skip the return type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1075 | uint32_t dex_pc = invoke->GetDexPc(); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1076 | |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1077 | for (size_t i = start_index; |
| 1078 | // Make sure we don't go over the expected arguments or over the number of |
| 1079 | // dex registers given. If the instruction was seen as dead by the verifier, |
| 1080 | // it hasn't been properly checked. |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1081 | (i < number_of_vreg_arguments) && (*argument_index < invoke->GetNumberOfArguments()); |
| 1082 | i++, (*argument_index)++) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1083 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1084 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1085 | if (!is_range |
| 1086 | && is_wide |
| 1087 | && ((i + 1 == number_of_vreg_arguments) || (args[i] + 1 != args[i + 1]))) { |
| 1088 | // Longs and doubles should be in pairs, that is, sequential registers. The verifier should |
| 1089 | // reject any class where this is violated. However, the verifier only does these checks |
| 1090 | // on non trivially dead instructions, so we just bailout the compilation. |
| 1091 | VLOG(compiler) << "Did not compile " |
| 1092 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 1093 | << " because of non-sequential dex register pair in wide argument"; |
| 1094 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 1095 | return false; |
| 1096 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1097 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type, dex_pc); |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1098 | invoke->SetArgumentAt(*argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1099 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1100 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1101 | } |
| 1102 | } |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1103 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1104 | if (*argument_index != invoke->GetNumberOfArguments()) { |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1105 | VLOG(compiler) << "Did not compile " |
| 1106 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 1107 | << " because of wrong number of arguments in invoke instruction"; |
| 1108 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 1109 | return false; |
| 1110 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1111 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 1112 | if (invoke->IsInvokeStaticOrDirect() && |
| 1113 | HInvokeStaticOrDirect::NeedsCurrentMethodInput( |
| 1114 | invoke->AsInvokeStaticOrDirect()->GetMethodLoadKind())) { |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1115 | invoke->SetArgumentAt(*argument_index, graph_->GetCurrentMethod()); |
| 1116 | (*argument_index)++; |
| 1117 | } |
| 1118 | |
| 1119 | return true; |
| 1120 | } |
| 1121 | |
| 1122 | bool HGraphBuilder::HandleInvoke(HInvoke* invoke, |
| 1123 | uint32_t number_of_vreg_arguments, |
| 1124 | uint32_t* args, |
| 1125 | uint32_t register_index, |
| 1126 | bool is_range, |
| 1127 | const char* descriptor, |
| 1128 | HClinitCheck* clinit_check) { |
| 1129 | DCHECK(!invoke->IsInvokeStaticOrDirect() || !invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 1130 | |
| 1131 | size_t start_index = 0; |
| 1132 | size_t argument_index = 0; |
| 1133 | if (invoke->GetOriginalInvokeType() != InvokeType::kStatic) { // Instance call. |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1134 | HInstruction* arg = LoadLocal( |
| 1135 | is_range ? register_index : args[0], Primitive::kPrimNot, invoke->GetDexPc()); |
| 1136 | HNullCheck* null_check = new (arena_) HNullCheck(arg, invoke->GetDexPc()); |
| 1137 | current_block_->AddInstruction(null_check); |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1138 | invoke->SetArgumentAt(0, null_check); |
| 1139 | start_index = 1; |
| 1140 | argument_index = 1; |
| 1141 | } |
| 1142 | |
| 1143 | if (!SetupInvokeArguments(invoke, |
| 1144 | number_of_vreg_arguments, |
| 1145 | args, |
| 1146 | register_index, |
| 1147 | is_range, |
| 1148 | descriptor, |
| 1149 | start_index, |
| 1150 | &argument_index)) { |
| 1151 | return false; |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1154 | if (clinit_check != nullptr) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1155 | // Add the class initialization check as last input of `invoke`. |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1156 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 1157 | DCHECK(invoke->AsInvokeStaticOrDirect()->GetClinitCheckRequirement() |
| 1158 | == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1159 | invoke->SetArgumentAt(argument_index, clinit_check); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1160 | argument_index++; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1161 | } |
| 1162 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1163 | current_block_->AddInstruction(invoke); |
| 1164 | latest_result_ = invoke; |
| 1165 | |
| 1166 | return true; |
| 1167 | } |
| 1168 | |
| 1169 | bool HGraphBuilder::HandleStringInit(HInvoke* invoke, |
| 1170 | uint32_t number_of_vreg_arguments, |
| 1171 | uint32_t* args, |
| 1172 | uint32_t register_index, |
| 1173 | bool is_range, |
| 1174 | const char* descriptor) { |
| 1175 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 1176 | DCHECK(invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 1177 | |
| 1178 | size_t start_index = 1; |
| 1179 | size_t argument_index = 0; |
| 1180 | if (!SetupInvokeArguments(invoke, |
| 1181 | number_of_vreg_arguments, |
| 1182 | args, |
| 1183 | register_index, |
| 1184 | is_range, |
| 1185 | descriptor, |
| 1186 | start_index, |
| 1187 | &argument_index)) { |
| 1188 | return false; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1189 | } |
Calin Juravle | 0eedd7e | 2015-08-20 14:48:00 +0100 | [diff] [blame] | 1190 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1191 | // Add move-result for StringFactory method. |
| 1192 | uint32_t orig_this_reg = is_range ? register_index : args[0]; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 1193 | HInstruction* new_instance = LoadLocal(orig_this_reg, Primitive::kPrimNot, invoke->GetDexPc()); |
| 1194 | invoke->SetArgumentAt(argument_index, new_instance); |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1195 | current_block_->AddInstruction(invoke); |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1196 | |
Calin Juravle | 0eedd7e | 2015-08-20 14:48:00 +0100 | [diff] [blame] | 1197 | latest_result_ = invoke; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1198 | return true; |
| 1199 | } |
| 1200 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1201 | static Primitive::Type GetFieldAccessType(const DexFile& dex_file, uint16_t field_index) { |
| 1202 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 1203 | const char* type = dex_file.GetFieldTypeDescriptor(field_id); |
| 1204 | return Primitive::GetType(type[0]); |
| 1205 | } |
| 1206 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1207 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1208 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1209 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1210 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 1211 | uint32_t obj_reg = instruction.VRegB_22c(); |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1212 | uint16_t field_index; |
| 1213 | if (instruction.IsQuickened()) { |
| 1214 | if (!CanDecodeQuickenedInfo()) { |
| 1215 | return false; |
| 1216 | } |
| 1217 | field_index = LookupQuickenedInfo(dex_pc); |
| 1218 | } else { |
| 1219 | field_index = instruction.VRegC_22c(); |
| 1220 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1221 | |
| 1222 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1223 | ArtField* resolved_field = |
| 1224 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1225 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1226 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1227 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot, dex_pc); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1228 | HInstruction* null_check = new (arena_) HNullCheck(object, dex_pc); |
| 1229 | current_block_->AddInstruction(null_check); |
| 1230 | |
| 1231 | Primitive::Type field_type = (resolved_field == nullptr) |
| 1232 | ? GetFieldAccessType(*dex_file_, field_index) |
| 1233 | : resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1234 | if (is_put) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1235 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1236 | HInstruction* field_set = nullptr; |
| 1237 | if (resolved_field == nullptr) { |
| 1238 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1239 | field_set = new (arena_) HUnresolvedInstanceFieldSet(null_check, |
| 1240 | value, |
| 1241 | field_type, |
| 1242 | field_index, |
| 1243 | dex_pc); |
| 1244 | } else { |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1245 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1246 | field_set = new (arena_) HInstanceFieldSet(null_check, |
| 1247 | value, |
| 1248 | field_type, |
| 1249 | resolved_field->GetOffset(), |
| 1250 | resolved_field->IsVolatile(), |
| 1251 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1252 | class_def_index, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1253 | *dex_file_, |
| 1254 | dex_compilation_unit_->GetDexCache(), |
| 1255 | dex_pc); |
| 1256 | } |
| 1257 | current_block_->AddInstruction(field_set); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1258 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1259 | HInstruction* field_get = nullptr; |
| 1260 | if (resolved_field == nullptr) { |
| 1261 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1262 | field_get = new (arena_) HUnresolvedInstanceFieldGet(null_check, |
| 1263 | field_type, |
| 1264 | field_index, |
| 1265 | dex_pc); |
| 1266 | } else { |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1267 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1268 | field_get = new (arena_) HInstanceFieldGet(null_check, |
| 1269 | field_type, |
| 1270 | resolved_field->GetOffset(), |
| 1271 | resolved_field->IsVolatile(), |
| 1272 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1273 | class_def_index, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1274 | *dex_file_, |
| 1275 | dex_compilation_unit_->GetDexCache(), |
| 1276 | dex_pc); |
| 1277 | } |
| 1278 | current_block_->AddInstruction(field_get); |
| 1279 | UpdateLocal(source_or_dest_reg, field_get, dex_pc); |
Calin Juravle | e6f49b4 | 2015-09-17 14:04:33 +0000 | [diff] [blame] | 1280 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1281 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1282 | return true; |
| 1283 | } |
| 1284 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1285 | static mirror::Class* GetClassFrom(CompilerDriver* driver, |
| 1286 | const DexCompilationUnit& compilation_unit) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1287 | ScopedObjectAccess soa(Thread::Current()); |
| 1288 | StackHandleScope<2> hs(soa.Self()); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1289 | const DexFile& dex_file = *compilation_unit.GetDexFile(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1290 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1291 | soa.Decode<mirror::ClassLoader*>(compilation_unit.GetClassLoader()))); |
| 1292 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1293 | compilation_unit.GetClassLinker()->FindDexCache(soa.Self(), dex_file))); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1294 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1295 | return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit); |
| 1296 | } |
| 1297 | |
| 1298 | mirror::Class* HGraphBuilder::GetOutermostCompilingClass() const { |
| 1299 | return GetClassFrom(compiler_driver_, *outer_compilation_unit_); |
| 1300 | } |
| 1301 | |
| 1302 | mirror::Class* HGraphBuilder::GetCompilingClass() const { |
| 1303 | return GetClassFrom(compiler_driver_, *dex_compilation_unit_); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | bool HGraphBuilder::IsOutermostCompilingClass(uint16_t type_index) const { |
| 1307 | ScopedObjectAccess soa(Thread::Current()); |
| 1308 | StackHandleScope<4> hs(soa.Self()); |
| 1309 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1310 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1311 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1312 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1313 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 1314 | Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass( |
| 1315 | soa, dex_cache, class_loader, type_index, dex_compilation_unit_))); |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 1316 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1317 | |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 1318 | // GetOutermostCompilingClass returns null when the class is unresolved |
| 1319 | // (e.g. if it derives from an unresolved class). This is bogus knowing that |
| 1320 | // we are compiling it. |
| 1321 | // When this happens we cannot establish a direct relation between the current |
| 1322 | // class and the outer class, so we return false. |
| 1323 | // (Note that this is only used for optimizing invokes and field accesses) |
| 1324 | return (cls.Get() != nullptr) && (outer_class.Get() == cls.Get()); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1327 | void HGraphBuilder::BuildUnresolvedStaticFieldAccess(const Instruction& instruction, |
| 1328 | uint32_t dex_pc, |
| 1329 | bool is_put, |
| 1330 | Primitive::Type field_type) { |
| 1331 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1332 | uint16_t field_index = instruction.VRegB_21c(); |
| 1333 | |
| 1334 | if (is_put) { |
| 1335 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
| 1336 | current_block_->AddInstruction( |
| 1337 | new (arena_) HUnresolvedStaticFieldSet(value, field_type, field_index, dex_pc)); |
| 1338 | } else { |
| 1339 | current_block_->AddInstruction( |
| 1340 | new (arena_) HUnresolvedStaticFieldGet(field_type, field_index, dex_pc)); |
| 1341 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
| 1342 | } |
| 1343 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1344 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1345 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1346 | bool is_put) { |
| 1347 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1348 | uint16_t field_index = instruction.VRegB_21c(); |
| 1349 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1350 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1351 | StackHandleScope<5> hs(soa.Self()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1352 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1353 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1354 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1355 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1356 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1357 | ArtField* resolved_field = compiler_driver_->ResolveField( |
| 1358 | soa, dex_cache, class_loader, dex_compilation_unit_, field_index, true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1359 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1360 | if (resolved_field == nullptr) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1361 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1362 | Primitive::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1363 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1364 | return true; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1365 | } |
| 1366 | |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1367 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1368 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 1369 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1370 | outer_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), outer_dex_file))); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1371 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1372 | |
| 1373 | // The index at which the field's class is stored in the DexCache's type array. |
| 1374 | uint32_t storage_index; |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1375 | bool is_outer_class = (outer_class.Get() == resolved_field->GetDeclaringClass()); |
| 1376 | if (is_outer_class) { |
| 1377 | storage_index = outer_class->GetDexTypeIndex(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1378 | } else if (outer_dex_cache.Get() != dex_cache.Get()) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1379 | // The compiler driver cannot currently understand multiple dex caches involved. Just bailout. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1380 | return false; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1381 | } else { |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1382 | // TODO: This is rather expensive. Perf it and cache the results if needed. |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1383 | std::pair<bool, bool> pair = compiler_driver_->IsFastStaticField( |
| 1384 | outer_dex_cache.Get(), |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1385 | GetCompilingClass(), |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1386 | resolved_field, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1387 | field_index, |
| 1388 | &storage_index); |
| 1389 | bool can_easily_access = is_put ? pair.second : pair.first; |
| 1390 | if (!can_easily_access) { |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1391 | MaybeRecordStat(MethodCompilationStat::kUnresolvedFieldNotAFastAccess); |
| 1392 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
| 1393 | return true; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1394 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1397 | bool is_in_cache = |
| 1398 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, storage_index); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1399 | HLoadClass* constant = new (arena_) HLoadClass(graph_->GetCurrentMethod(), |
| 1400 | storage_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1401 | outer_dex_file, |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1402 | is_outer_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1403 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1404 | /*needs_access_check*/ false, |
| 1405 | is_in_cache); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1406 | current_block_->AddInstruction(constant); |
| 1407 | |
| 1408 | HInstruction* cls = constant; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1409 | |
| 1410 | Handle<mirror::Class> klass(hs.NewHandle(resolved_field->GetDeclaringClass())); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1411 | if (!IsInitialized(klass)) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1412 | cls = new (arena_) HClinitCheck(constant, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1413 | current_block_->AddInstruction(cls); |
| 1414 | } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1415 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1416 | uint16_t class_def_index = klass->GetDexClassDefIndex(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1417 | if (is_put) { |
| 1418 | // We need to keep the class alive before loading the value. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1419 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1420 | DCHECK_EQ(value->GetType(), field_type); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1421 | current_block_->AddInstruction(new (arena_) HStaticFieldSet(cls, |
| 1422 | value, |
| 1423 | field_type, |
| 1424 | resolved_field->GetOffset(), |
| 1425 | resolved_field->IsVolatile(), |
| 1426 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1427 | class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 1428 | *dex_file_, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1429 | dex_cache_, |
| 1430 | dex_pc)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1431 | } else { |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1432 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, |
| 1433 | field_type, |
| 1434 | resolved_field->GetOffset(), |
| 1435 | resolved_field->IsVolatile(), |
| 1436 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1437 | class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 1438 | *dex_file_, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1439 | dex_cache_, |
| 1440 | dex_pc)); |
| 1441 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1442 | } |
| 1443 | return true; |
| 1444 | } |
| 1445 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1446 | void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
| 1447 | uint16_t first_vreg, |
| 1448 | int64_t second_vreg_or_constant, |
| 1449 | uint32_t dex_pc, |
| 1450 | Primitive::Type type, |
| 1451 | bool second_is_constant, |
| 1452 | bool isDiv) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1453 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1454 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1455 | HInstruction* first = LoadLocal(first_vreg, type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1456 | HInstruction* second = nullptr; |
| 1457 | if (second_is_constant) { |
| 1458 | if (type == Primitive::kPrimInt) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1459 | second = graph_->GetIntConstant(second_vreg_or_constant, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1460 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1461 | second = graph_->GetLongConstant(second_vreg_or_constant, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1462 | } |
| 1463 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1464 | second = LoadLocal(second_vreg_or_constant, type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | if (!second_is_constant |
| 1468 | || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0) |
| 1469 | || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) { |
| 1470 | second = new (arena_) HDivZeroCheck(second, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1471 | current_block_->AddInstruction(second); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1474 | if (isDiv) { |
| 1475 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc)); |
| 1476 | } else { |
| 1477 | current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc)); |
| 1478 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1479 | UpdateLocal(out_vreg, current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1482 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1483 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1484 | bool is_put, |
| 1485 | Primitive::Type anticipated_type) { |
| 1486 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 1487 | uint8_t array_reg = instruction.VRegB_23x(); |
| 1488 | uint8_t index_reg = instruction.VRegC_23x(); |
| 1489 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1490 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1491 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1492 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1493 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1494 | HInstruction* length = new (arena_) HArrayLength(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1495 | current_block_->AddInstruction(length); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1496 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1497 | index = new (arena_) HBoundsCheck(index, length, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1498 | current_block_->AddInstruction(index); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1499 | if (is_put) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1500 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1501 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1502 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1503 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1504 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1505 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type, dex_pc)); |
| 1506 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1507 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1508 | graph_->SetHasBoundsChecks(true); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1509 | } |
| 1510 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1511 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1512 | uint32_t type_index, |
| 1513 | uint32_t number_of_vreg_arguments, |
| 1514 | bool is_range, |
| 1515 | uint32_t* args, |
| 1516 | uint32_t register_index) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1517 | HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments, dex_pc); |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1518 | bool finalizable; |
| 1519 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index, &finalizable) |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1520 | ? kQuickAllocArrayWithAccessCheck |
| 1521 | : kQuickAllocArray; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1522 | HInstruction* object = new (arena_) HNewArray(length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 1523 | graph_->GetCurrentMethod(), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1524 | dex_pc, |
| 1525 | type_index, |
| 1526 | *dex_compilation_unit_->GetDexFile(), |
| 1527 | entrypoint); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1528 | current_block_->AddInstruction(object); |
| 1529 | |
| 1530 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 1531 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 1532 | char primitive = descriptor[1]; |
| 1533 | DCHECK(primitive == 'I' |
| 1534 | || primitive == 'L' |
| 1535 | || primitive == '[') << descriptor; |
| 1536 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 1537 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 1538 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1539 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1540 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type, dex_pc); |
| 1541 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1542 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1543 | new (arena_) HArraySet(object, index, value, type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1544 | } |
| 1545 | latest_result_ = object; |
| 1546 | } |
| 1547 | |
| 1548 | template <typename T> |
| 1549 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 1550 | const T* data, |
| 1551 | uint32_t element_count, |
| 1552 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1553 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1554 | for (uint32_t i = 0; i < element_count; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1555 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 1556 | HInstruction* value = graph_->GetIntConstant(data[i], dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1557 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1558 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1562 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1563 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1564 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1565 | current_block_->AddInstruction(null_check); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1566 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1567 | HInstruction* length = new (arena_) HArrayLength(null_check, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1568 | current_block_->AddInstruction(length); |
| 1569 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1570 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1571 | const Instruction::ArrayDataPayload* payload = |
| 1572 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 1573 | const uint8_t* data = payload->data; |
| 1574 | uint32_t element_count = payload->element_count; |
| 1575 | |
| 1576 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 1577 | // done before doing any stores. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1578 | HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1579 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1580 | |
| 1581 | switch (payload->element_width) { |
| 1582 | case 1: |
| 1583 | BuildFillArrayData(null_check, |
| 1584 | reinterpret_cast<const int8_t*>(data), |
| 1585 | element_count, |
| 1586 | Primitive::kPrimByte, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1587 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1588 | break; |
| 1589 | case 2: |
| 1590 | BuildFillArrayData(null_check, |
| 1591 | reinterpret_cast<const int16_t*>(data), |
| 1592 | element_count, |
| 1593 | Primitive::kPrimShort, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1594 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1595 | break; |
| 1596 | case 4: |
| 1597 | BuildFillArrayData(null_check, |
| 1598 | reinterpret_cast<const int32_t*>(data), |
| 1599 | element_count, |
| 1600 | Primitive::kPrimInt, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1601 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1602 | break; |
| 1603 | case 8: |
| 1604 | BuildFillWideArrayData(null_check, |
| 1605 | reinterpret_cast<const int64_t*>(data), |
| 1606 | element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1607 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1608 | break; |
| 1609 | default: |
| 1610 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 1611 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1612 | graph_->SetHasBoundsChecks(true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1615 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1616 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1617 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1618 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1619 | for (uint32_t i = 0; i < element_count; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1620 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 1621 | HInstruction* value = graph_->GetLongConstant(data[i], dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1622 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1623 | object, index, value, Primitive::kPrimLong, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1624 | } |
| 1625 | } |
| 1626 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1627 | static TypeCheckKind ComputeTypeCheckKind(Handle<mirror::Class> cls) |
| 1628 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1629 | if (cls.Get() == nullptr) { |
| 1630 | return TypeCheckKind::kUnresolvedCheck; |
| 1631 | } else if (cls->IsInterface()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1632 | return TypeCheckKind::kInterfaceCheck; |
| 1633 | } else if (cls->IsArrayClass()) { |
| 1634 | if (cls->GetComponentType()->IsObjectClass()) { |
| 1635 | return TypeCheckKind::kArrayObjectCheck; |
| 1636 | } else if (cls->CannotBeAssignedFromOtherTypes()) { |
| 1637 | return TypeCheckKind::kExactCheck; |
| 1638 | } else { |
| 1639 | return TypeCheckKind::kArrayCheck; |
| 1640 | } |
| 1641 | } else if (cls->IsFinal()) { |
| 1642 | return TypeCheckKind::kExactCheck; |
| 1643 | } else if (cls->IsAbstract()) { |
| 1644 | return TypeCheckKind::kAbstractClassCheck; |
| 1645 | } else { |
| 1646 | return TypeCheckKind::kClassHierarchyCheck; |
| 1647 | } |
| 1648 | } |
| 1649 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1650 | void HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1651 | uint8_t destination, |
| 1652 | uint8_t reference, |
| 1653 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1654 | uint32_t dex_pc) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1655 | bool type_known_final, type_known_abstract, use_declaring_class; |
| 1656 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1657 | dex_compilation_unit_->GetDexMethodIndex(), |
| 1658 | *dex_compilation_unit_->GetDexFile(), |
| 1659 | type_index, |
| 1660 | &type_known_final, |
| 1661 | &type_known_abstract, |
| 1662 | &use_declaring_class); |
| 1663 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1664 | ScopedObjectAccess soa(Thread::Current()); |
| 1665 | StackHandleScope<2> hs(soa.Self()); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1666 | const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1667 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1668 | dex_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), dex_file))); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1669 | Handle<mirror::Class> resolved_class(hs.NewHandle(dex_cache->GetResolvedType(type_index))); |
| 1670 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1671 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot, dex_pc); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1672 | HLoadClass* cls = new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1673 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 1674 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1675 | dex_file, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 1676 | IsOutermostCompilingClass(type_index), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1677 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1678 | !can_access, |
| 1679 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(dex_file, type_index)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1680 | current_block_->AddInstruction(cls); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1681 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1682 | TypeCheckKind check_kind = ComputeTypeCheckKind(resolved_class); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1683 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1684 | current_block_->AddInstruction(new (arena_) HInstanceOf(object, cls, check_kind, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1685 | UpdateLocal(destination, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1686 | } else { |
| 1687 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 1688 | // We emit a CheckCast followed by a BoundType. CheckCast is a statement |
| 1689 | // which may throw. If it succeeds BoundType sets the new type of `object` |
| 1690 | // for all subsequent uses. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1691 | current_block_->AddInstruction(new (arena_) HCheckCast(object, cls, check_kind, dex_pc)); |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 1692 | current_block_->AddInstruction(new (arena_) HBoundType(object, dex_pc)); |
| 1693 | UpdateLocal(reference, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1694 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1697 | bool HGraphBuilder::NeedsAccessCheck(uint32_t type_index, bool* finalizable) const { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1698 | return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks( |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1699 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, finalizable); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1702 | void HGraphBuilder::BuildSwitchJumpTable(const SwitchTable& table, |
| 1703 | const Instruction& instruction, |
| 1704 | HInstruction* value, |
| 1705 | uint32_t dex_pc) { |
| 1706 | // Add the successor blocks to the current block. |
| 1707 | uint16_t num_entries = table.GetNumEntries(); |
| 1708 | for (size_t i = 1; i <= num_entries; i++) { |
| 1709 | int32_t target_offset = table.GetEntryAt(i); |
| 1710 | HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset); |
| 1711 | DCHECK(case_target != nullptr); |
| 1712 | |
| 1713 | // Add the target block as a successor. |
| 1714 | current_block_->AddSuccessor(case_target); |
| 1715 | } |
| 1716 | |
| 1717 | // Add the default target block as the last successor. |
| 1718 | HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 1719 | DCHECK(default_target != nullptr); |
| 1720 | current_block_->AddSuccessor(default_target); |
| 1721 | |
| 1722 | // Now add the Switch instruction. |
| 1723 | int32_t starting_key = table.GetEntryAt(0); |
| 1724 | current_block_->AddInstruction( |
| 1725 | new (arena_) HPackedSwitch(starting_key, num_entries, value, dex_pc)); |
| 1726 | // This block ends with control flow. |
| 1727 | current_block_ = nullptr; |
| 1728 | } |
| 1729 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1730 | void HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1731 | // Verifier guarantees that the payload for PackedSwitch contains: |
| 1732 | // (a) number of entries (may be zero) |
| 1733 | // (b) first and lowest switch case value (entry 0, always present) |
| 1734 | // (c) list of target pcs (entries 1 <= i <= N) |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1735 | SwitchTable table(instruction, dex_pc, false); |
| 1736 | |
| 1737 | // Value to test against. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1738 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1739 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1740 | // Starting key value. |
| 1741 | int32_t starting_key = table.GetEntryAt(0); |
| 1742 | |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1743 | // Retrieve number of entries. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1744 | uint16_t num_entries = table.GetNumEntries(); |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1745 | if (num_entries == 0) { |
| 1746 | return; |
| 1747 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1748 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1749 | // Don't use a packed switch if there are very few entries. |
| 1750 | if (num_entries > kSmallSwitchThreshold) { |
| 1751 | BuildSwitchJumpTable(table, instruction, value, dex_pc); |
| 1752 | } else { |
| 1753 | // Chained cmp-and-branch, starting from starting_key. |
| 1754 | for (size_t i = 1; i <= num_entries; i++) { |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 1755 | BuildSwitchCaseHelper(instruction, |
| 1756 | i, |
| 1757 | i == num_entries, |
| 1758 | table, |
| 1759 | value, |
| 1760 | starting_key + i - 1, |
| 1761 | table.GetEntryAt(i), |
| 1762 | dex_pc); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1763 | } |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1764 | } |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1765 | } |
| 1766 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1767 | void HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1768 | // Verifier guarantees that the payload for SparseSwitch contains: |
| 1769 | // (a) number of entries (may be zero) |
| 1770 | // (b) sorted key values (entries 0 <= i < N) |
| 1771 | // (c) target pcs corresponding to the switch values (entries N <= i < 2*N) |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1772 | SwitchTable table(instruction, dex_pc, true); |
| 1773 | |
| 1774 | // Value to test against. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1775 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1776 | |
| 1777 | uint16_t num_entries = table.GetNumEntries(); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1778 | |
| 1779 | for (size_t i = 0; i < num_entries; i++) { |
| 1780 | BuildSwitchCaseHelper(instruction, i, i == static_cast<size_t>(num_entries) - 1, table, value, |
| 1781 | table.GetEntryAt(i), table.GetEntryAt(i + num_entries), dex_pc); |
| 1782 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void HGraphBuilder::BuildSwitchCaseHelper(const Instruction& instruction, size_t index, |
| 1786 | bool is_last_case, const SwitchTable& table, |
| 1787 | HInstruction* value, int32_t case_value_int, |
| 1788 | int32_t target_offset, uint32_t dex_pc) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1789 | HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset); |
| 1790 | DCHECK(case_target != nullptr); |
| 1791 | PotentiallyAddSuspendCheck(case_target, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1792 | |
| 1793 | // The current case's value. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1794 | HInstruction* this_case_value = graph_->GetIntConstant(case_value_int, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1795 | |
| 1796 | // Compare value and this_case_value. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1797 | HEqual* comparison = new (arena_) HEqual(value, this_case_value, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1798 | current_block_->AddInstruction(comparison); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1799 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1800 | current_block_->AddInstruction(ifinst); |
| 1801 | |
| 1802 | // Case hit: use the target offset to determine where to go. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1803 | current_block_->AddSuccessor(case_target); |
| 1804 | |
| 1805 | // Case miss: go to the next case (or default fall-through). |
| 1806 | // When there is a next case, we use the block stored with the table offset representing this |
| 1807 | // case (that is where we registered them in ComputeBranchTargets). |
| 1808 | // When there is no next case, we use the following instruction. |
| 1809 | // TODO: Find a good way to peel the last iteration to avoid conditional, but still have re-use. |
| 1810 | if (!is_last_case) { |
| 1811 | HBasicBlock* next_case_target = FindBlockStartingAt(table.GetDexPcForIndex(index)); |
| 1812 | DCHECK(next_case_target != nullptr); |
| 1813 | current_block_->AddSuccessor(next_case_target); |
| 1814 | |
| 1815 | // Need to manually add the block, as there is no dex-pc transition for the cases. |
| 1816 | graph_->AddBlock(next_case_target); |
| 1817 | |
| 1818 | current_block_ = next_case_target; |
| 1819 | } else { |
| 1820 | HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 1821 | DCHECK(default_target != nullptr); |
| 1822 | current_block_->AddSuccessor(default_target); |
| 1823 | current_block_ = nullptr; |
| 1824 | } |
| 1825 | } |
| 1826 | |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1827 | void HGraphBuilder::PotentiallyAddSuspendCheck(HBasicBlock* target, uint32_t dex_pc) { |
| 1828 | int32_t target_offset = target->GetDexPc() - dex_pc; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1829 | if (target_offset <= 0) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1830 | // DX generates back edges to the first encountered return. We can save |
| 1831 | // time of later passes by not adding redundant suspend checks. |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame] | 1832 | HInstruction* last_in_target = target->GetLastInstruction(); |
| 1833 | if (last_in_target != nullptr && |
| 1834 | (last_in_target->IsReturn() || last_in_target->IsReturnVoid())) { |
| 1835 | return; |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | // Add a suspend check to backward branches which may potentially loop. We |
| 1839 | // can remove them after we recognize loops in the graph. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1840 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc)); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1841 | } |
| 1842 | } |
| 1843 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1844 | bool HGraphBuilder::CanDecodeQuickenedInfo() const { |
| 1845 | return interpreter_metadata_ != nullptr; |
| 1846 | } |
| 1847 | |
| 1848 | uint16_t HGraphBuilder::LookupQuickenedInfo(uint32_t dex_pc) { |
| 1849 | DCHECK(interpreter_metadata_ != nullptr); |
| 1850 | uint32_t dex_pc_in_map = DecodeUnsignedLeb128(&interpreter_metadata_); |
| 1851 | DCHECK_EQ(dex_pc, dex_pc_in_map); |
| 1852 | return DecodeUnsignedLeb128(&interpreter_metadata_); |
| 1853 | } |
| 1854 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1855 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1856 | if (current_block_ == nullptr) { |
| 1857 | return true; // Dead code |
| 1858 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1859 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1860 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1861 | case Instruction::CONST_4: { |
| 1862 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1863 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n(), dex_pc); |
| 1864 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1865 | break; |
| 1866 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1867 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1868 | case Instruction::CONST_16: { |
| 1869 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1870 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s(), dex_pc); |
| 1871 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1872 | break; |
| 1873 | } |
| 1874 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1875 | case Instruction::CONST: { |
| 1876 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1877 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i(), dex_pc); |
| 1878 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1879 | break; |
| 1880 | } |
| 1881 | |
| 1882 | case Instruction::CONST_HIGH16: { |
| 1883 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1884 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16, dex_pc); |
| 1885 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1886 | break; |
| 1887 | } |
| 1888 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1889 | case Instruction::CONST_WIDE_16: { |
| 1890 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1891 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 1892 | int64_t value = instruction.VRegB_21s(); |
| 1893 | value <<= 48; |
| 1894 | value >>= 48; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1895 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1896 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1897 | break; |
| 1898 | } |
| 1899 | |
| 1900 | case Instruction::CONST_WIDE_32: { |
| 1901 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1902 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 1903 | int64_t value = instruction.VRegB_31i(); |
| 1904 | value <<= 32; |
| 1905 | value >>= 32; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1906 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1907 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1908 | break; |
| 1909 | } |
| 1910 | |
| 1911 | case Instruction::CONST_WIDE: { |
| 1912 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1913 | HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l(), dex_pc); |
| 1914 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1915 | break; |
| 1916 | } |
| 1917 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1918 | case Instruction::CONST_WIDE_HIGH16: { |
| 1919 | int32_t register_index = instruction.VRegA(); |
| 1920 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1921 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1922 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1923 | break; |
| 1924 | } |
| 1925 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1926 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1927 | case Instruction::MOVE: |
| 1928 | case Instruction::MOVE_FROM16: |
| 1929 | case Instruction::MOVE_16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1930 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 1931 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1932 | break; |
| 1933 | } |
| 1934 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1935 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1936 | case Instruction::MOVE_WIDE: |
| 1937 | case Instruction::MOVE_WIDE_FROM16: |
| 1938 | case Instruction::MOVE_WIDE_16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1939 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong, dex_pc); |
| 1940 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1941 | break; |
| 1942 | } |
| 1943 | |
| 1944 | case Instruction::MOVE_OBJECT: |
| 1945 | case Instruction::MOVE_OBJECT_16: |
| 1946 | case Instruction::MOVE_OBJECT_FROM16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1947 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot, dex_pc); |
| 1948 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1949 | break; |
| 1950 | } |
| 1951 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1952 | case Instruction::RETURN_VOID_NO_BARRIER: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1953 | case Instruction::RETURN_VOID: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1954 | BuildReturn(instruction, Primitive::kPrimVoid, dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1955 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1958 | #define IF_XX(comparison, cond) \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1959 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 1960 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1961 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1962 | IF_XX(HEqual, EQ); |
| 1963 | IF_XX(HNotEqual, NE); |
| 1964 | IF_XX(HLessThan, LT); |
| 1965 | IF_XX(HLessThanOrEqual, LE); |
| 1966 | IF_XX(HGreaterThan, GT); |
| 1967 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1968 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1969 | case Instruction::GOTO: |
| 1970 | case Instruction::GOTO_16: |
| 1971 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1972 | int32_t offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1973 | HBasicBlock* target = FindBlockStartingAt(offset + dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1974 | DCHECK(target != nullptr); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1975 | PotentiallyAddSuspendCheck(target, dex_pc); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1976 | current_block_->AddInstruction(new (arena_) HGoto(dex_pc)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1977 | current_block_->AddSuccessor(target); |
| 1978 | current_block_ = nullptr; |
| 1979 | break; |
| 1980 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1981 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1982 | case Instruction::RETURN: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1983 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1984 | break; |
| 1985 | } |
| 1986 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1987 | case Instruction::RETURN_OBJECT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1988 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1989 | break; |
| 1990 | } |
| 1991 | |
| 1992 | case Instruction::RETURN_WIDE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1993 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1994 | break; |
| 1995 | } |
| 1996 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1997 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1998 | case Instruction::INVOKE_INTERFACE: |
| 1999 | case Instruction::INVOKE_STATIC: |
| 2000 | case Instruction::INVOKE_SUPER: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2001 | case Instruction::INVOKE_VIRTUAL: |
| 2002 | case Instruction::INVOKE_VIRTUAL_QUICK: { |
| 2003 | uint16_t method_idx; |
| 2004 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_QUICK) { |
| 2005 | if (!CanDecodeQuickenedInfo()) { |
| 2006 | return false; |
| 2007 | } |
| 2008 | method_idx = LookupQuickenedInfo(dex_pc); |
| 2009 | } else { |
| 2010 | method_idx = instruction.VRegB_35c(); |
| 2011 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2012 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2013 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 2014 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2015 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2016 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2017 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2018 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2019 | break; |
| 2020 | } |
| 2021 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2022 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 2023 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 2024 | case Instruction::INVOKE_STATIC_RANGE: |
| 2025 | case Instruction::INVOKE_SUPER_RANGE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2026 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 2027 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 2028 | uint16_t method_idx; |
| 2029 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK) { |
| 2030 | if (!CanDecodeQuickenedInfo()) { |
| 2031 | return false; |
| 2032 | } |
| 2033 | method_idx = LookupQuickenedInfo(dex_pc); |
| 2034 | } else { |
| 2035 | method_idx = instruction.VRegB_3rc(); |
| 2036 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2037 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 2038 | uint32_t register_index = instruction.VRegC(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2039 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2040 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2041 | return false; |
| 2042 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | } |
| 2045 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2046 | case Instruction::NEG_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2047 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2048 | break; |
| 2049 | } |
| 2050 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2051 | case Instruction::NEG_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2052 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2053 | break; |
| 2054 | } |
| 2055 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2056 | case Instruction::NEG_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2057 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2058 | break; |
| 2059 | } |
| 2060 | |
| 2061 | case Instruction::NEG_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2062 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2063 | break; |
| 2064 | } |
| 2065 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2066 | case Instruction::NOT_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2067 | Unop_12x<HNot>(instruction, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2068 | break; |
| 2069 | } |
| 2070 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2071 | case Instruction::NOT_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2072 | Unop_12x<HNot>(instruction, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2073 | break; |
| 2074 | } |
| 2075 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2076 | case Instruction::INT_TO_LONG: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2077 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2078 | break; |
| 2079 | } |
| 2080 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2081 | case Instruction::INT_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2082 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2083 | break; |
| 2084 | } |
| 2085 | |
| 2086 | case Instruction::INT_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2087 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2088 | break; |
| 2089 | } |
| 2090 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2091 | case Instruction::LONG_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2092 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2093 | break; |
| 2094 | } |
| 2095 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2096 | case Instruction::LONG_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2097 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2098 | break; |
| 2099 | } |
| 2100 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2101 | case Instruction::LONG_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2102 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2103 | break; |
| 2104 | } |
| 2105 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2106 | case Instruction::FLOAT_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2107 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc); |
| 2108 | break; |
| 2109 | } |
| 2110 | |
| 2111 | case Instruction::FLOAT_TO_LONG: { |
| 2112 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2113 | break; |
| 2114 | } |
| 2115 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2116 | case Instruction::FLOAT_TO_DOUBLE: { |
| 2117 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc); |
| 2118 | break; |
| 2119 | } |
| 2120 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2121 | case Instruction::DOUBLE_TO_INT: { |
| 2122 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc); |
| 2123 | break; |
| 2124 | } |
| 2125 | |
| 2126 | case Instruction::DOUBLE_TO_LONG: { |
| 2127 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc); |
| 2128 | break; |
| 2129 | } |
| 2130 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2131 | case Instruction::DOUBLE_TO_FLOAT: { |
| 2132 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc); |
| 2133 | break; |
| 2134 | } |
| 2135 | |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2136 | case Instruction::INT_TO_BYTE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2137 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2138 | break; |
| 2139 | } |
| 2140 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2141 | case Instruction::INT_TO_SHORT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2142 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2143 | break; |
| 2144 | } |
| 2145 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2146 | case Instruction::INT_TO_CHAR: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2147 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2148 | break; |
| 2149 | } |
| 2150 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2151 | case Instruction::ADD_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2152 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2153 | break; |
| 2154 | } |
| 2155 | |
| 2156 | case Instruction::ADD_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2157 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2158 | break; |
| 2159 | } |
| 2160 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2161 | case Instruction::ADD_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2162 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2163 | break; |
| 2164 | } |
| 2165 | |
| 2166 | case Instruction::ADD_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2167 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2168 | break; |
| 2169 | } |
| 2170 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2171 | case Instruction::SUB_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2172 | Binop_23x<HSub>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2173 | break; |
| 2174 | } |
| 2175 | |
| 2176 | case Instruction::SUB_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2177 | Binop_23x<HSub>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2178 | break; |
| 2179 | } |
| 2180 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2181 | case Instruction::SUB_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2182 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2183 | break; |
| 2184 | } |
| 2185 | |
| 2186 | case Instruction::SUB_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2187 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2188 | break; |
| 2189 | } |
| 2190 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2191 | case Instruction::ADD_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2192 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2193 | break; |
| 2194 | } |
| 2195 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2196 | case Instruction::MUL_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2197 | Binop_23x<HMul>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2198 | break; |
| 2199 | } |
| 2200 | |
| 2201 | case Instruction::MUL_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2202 | Binop_23x<HMul>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2203 | break; |
| 2204 | } |
| 2205 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2206 | case Instruction::MUL_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2207 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2208 | break; |
| 2209 | } |
| 2210 | |
| 2211 | case Instruction::MUL_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2212 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2213 | break; |
| 2214 | } |
| 2215 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2216 | case Instruction::DIV_INT: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2217 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2218 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2219 | break; |
| 2220 | } |
| 2221 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2222 | case Instruction::DIV_LONG: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2223 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2224 | dex_pc, Primitive::kPrimLong, false, true); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2225 | break; |
| 2226 | } |
| 2227 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2228 | case Instruction::DIV_FLOAT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2229 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | } |
| 2232 | |
| 2233 | case Instruction::DIV_DOUBLE: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2234 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2235 | break; |
| 2236 | } |
| 2237 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2238 | case Instruction::REM_INT: { |
| 2239 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2240 | dex_pc, Primitive::kPrimInt, false, false); |
| 2241 | break; |
| 2242 | } |
| 2243 | |
| 2244 | case Instruction::REM_LONG: { |
| 2245 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2246 | dex_pc, Primitive::kPrimLong, false, false); |
| 2247 | break; |
| 2248 | } |
| 2249 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2250 | case Instruction::REM_FLOAT: { |
| 2251 | Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 2252 | break; |
| 2253 | } |
| 2254 | |
| 2255 | case Instruction::REM_DOUBLE: { |
| 2256 | Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 2257 | break; |
| 2258 | } |
| 2259 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2260 | case Instruction::AND_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2261 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2262 | break; |
| 2263 | } |
| 2264 | |
| 2265 | case Instruction::AND_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2266 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2267 | break; |
| 2268 | } |
| 2269 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2270 | case Instruction::SHL_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2271 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2272 | break; |
| 2273 | } |
| 2274 | |
| 2275 | case Instruction::SHL_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2276 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2277 | break; |
| 2278 | } |
| 2279 | |
| 2280 | case Instruction::SHR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2281 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2282 | break; |
| 2283 | } |
| 2284 | |
| 2285 | case Instruction::SHR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2286 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2287 | break; |
| 2288 | } |
| 2289 | |
| 2290 | case Instruction::USHR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2291 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2292 | break; |
| 2293 | } |
| 2294 | |
| 2295 | case Instruction::USHR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2296 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | } |
| 2299 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2300 | case Instruction::OR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2301 | Binop_23x<HOr>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2302 | break; |
| 2303 | } |
| 2304 | |
| 2305 | case Instruction::OR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2306 | Binop_23x<HOr>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2307 | break; |
| 2308 | } |
| 2309 | |
| 2310 | case Instruction::XOR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2311 | Binop_23x<HXor>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2312 | break; |
| 2313 | } |
| 2314 | |
| 2315 | case Instruction::XOR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2316 | Binop_23x<HXor>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2317 | break; |
| 2318 | } |
| 2319 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2320 | case Instruction::ADD_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2321 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2322 | break; |
| 2323 | } |
| 2324 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2325 | case Instruction::ADD_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2326 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2327 | break; |
| 2328 | } |
| 2329 | |
| 2330 | case Instruction::ADD_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2331 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2332 | break; |
| 2333 | } |
| 2334 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2335 | case Instruction::SUB_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2336 | Binop_12x<HSub>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2337 | break; |
| 2338 | } |
| 2339 | |
| 2340 | case Instruction::SUB_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2341 | Binop_12x<HSub>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2342 | break; |
| 2343 | } |
| 2344 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2345 | case Instruction::SUB_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2346 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2347 | break; |
| 2348 | } |
| 2349 | |
| 2350 | case Instruction::SUB_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2351 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2352 | break; |
| 2353 | } |
| 2354 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2355 | case Instruction::MUL_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2356 | Binop_12x<HMul>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2357 | break; |
| 2358 | } |
| 2359 | |
| 2360 | case Instruction::MUL_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2361 | Binop_12x<HMul>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2362 | break; |
| 2363 | } |
| 2364 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2365 | case Instruction::MUL_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2366 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2367 | break; |
| 2368 | } |
| 2369 | |
| 2370 | case Instruction::MUL_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2371 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2372 | break; |
| 2373 | } |
| 2374 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2375 | case Instruction::DIV_INT_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2376 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2377 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | } |
| 2380 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2381 | case Instruction::DIV_LONG_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2382 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2383 | dex_pc, Primitive::kPrimLong, false, true); |
| 2384 | break; |
| 2385 | } |
| 2386 | |
| 2387 | case Instruction::REM_INT_2ADDR: { |
| 2388 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2389 | dex_pc, Primitive::kPrimInt, false, false); |
| 2390 | break; |
| 2391 | } |
| 2392 | |
| 2393 | case Instruction::REM_LONG_2ADDR: { |
| 2394 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2395 | dex_pc, Primitive::kPrimLong, false, false); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2396 | break; |
| 2397 | } |
| 2398 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2399 | case Instruction::REM_FLOAT_2ADDR: { |
| 2400 | Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 2401 | break; |
| 2402 | } |
| 2403 | |
| 2404 | case Instruction::REM_DOUBLE_2ADDR: { |
| 2405 | Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 2406 | break; |
| 2407 | } |
| 2408 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2409 | case Instruction::SHL_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2410 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2411 | break; |
| 2412 | } |
| 2413 | |
| 2414 | case Instruction::SHL_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2415 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | } |
| 2418 | |
| 2419 | case Instruction::SHR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2420 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2421 | break; |
| 2422 | } |
| 2423 | |
| 2424 | case Instruction::SHR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2425 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2426 | break; |
| 2427 | } |
| 2428 | |
| 2429 | case Instruction::USHR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2430 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2431 | break; |
| 2432 | } |
| 2433 | |
| 2434 | case Instruction::USHR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2435 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2436 | break; |
| 2437 | } |
| 2438 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2439 | case Instruction::DIV_FLOAT_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2440 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2441 | break; |
| 2442 | } |
| 2443 | |
| 2444 | case Instruction::DIV_DOUBLE_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2445 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2446 | break; |
| 2447 | } |
| 2448 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2449 | case Instruction::AND_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2450 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2451 | break; |
| 2452 | } |
| 2453 | |
| 2454 | case Instruction::AND_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2455 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | } |
| 2458 | |
| 2459 | case Instruction::OR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2460 | Binop_12x<HOr>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2461 | break; |
| 2462 | } |
| 2463 | |
| 2464 | case Instruction::OR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2465 | Binop_12x<HOr>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2466 | break; |
| 2467 | } |
| 2468 | |
| 2469 | case Instruction::XOR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2470 | Binop_12x<HXor>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2471 | break; |
| 2472 | } |
| 2473 | |
| 2474 | case Instruction::XOR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2475 | Binop_12x<HXor>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2476 | break; |
| 2477 | } |
| 2478 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2479 | case Instruction::ADD_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2480 | Binop_22s<HAdd>(instruction, false, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2481 | break; |
| 2482 | } |
| 2483 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2484 | case Instruction::AND_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2485 | Binop_22s<HAnd>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2486 | break; |
| 2487 | } |
| 2488 | |
| 2489 | case Instruction::OR_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2490 | Binop_22s<HOr>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2491 | break; |
| 2492 | } |
| 2493 | |
| 2494 | case Instruction::XOR_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2495 | Binop_22s<HXor>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2496 | break; |
| 2497 | } |
| 2498 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2499 | case Instruction::RSUB_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2500 | Binop_22s<HSub>(instruction, true, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2501 | break; |
| 2502 | } |
| 2503 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2504 | case Instruction::MUL_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2505 | Binop_22s<HMul>(instruction, false, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2506 | break; |
| 2507 | } |
| 2508 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2509 | case Instruction::ADD_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2510 | Binop_22b<HAdd>(instruction, false, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2511 | break; |
| 2512 | } |
| 2513 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2514 | case Instruction::AND_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2515 | Binop_22b<HAnd>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2516 | break; |
| 2517 | } |
| 2518 | |
| 2519 | case Instruction::OR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2520 | Binop_22b<HOr>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | } |
| 2523 | |
| 2524 | case Instruction::XOR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2525 | Binop_22b<HXor>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2526 | break; |
| 2527 | } |
| 2528 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2529 | case Instruction::RSUB_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2530 | Binop_22b<HSub>(instruction, true, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2531 | break; |
| 2532 | } |
| 2533 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2534 | case Instruction::MUL_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2535 | Binop_22b<HMul>(instruction, false, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2536 | break; |
| 2537 | } |
| 2538 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2539 | case Instruction::DIV_INT_LIT16: |
| 2540 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2541 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2542 | dex_pc, Primitive::kPrimInt, true, true); |
| 2543 | break; |
| 2544 | } |
| 2545 | |
| 2546 | case Instruction::REM_INT_LIT16: |
| 2547 | case Instruction::REM_INT_LIT8: { |
| 2548 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2549 | dex_pc, Primitive::kPrimInt, true, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2550 | break; |
| 2551 | } |
| 2552 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2553 | case Instruction::SHL_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2554 | Binop_22b<HShl>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2555 | break; |
| 2556 | } |
| 2557 | |
| 2558 | case Instruction::SHR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2559 | Binop_22b<HShr>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2560 | break; |
| 2561 | } |
| 2562 | |
| 2563 | case Instruction::USHR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2564 | Binop_22b<HUShr>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2565 | break; |
| 2566 | } |
| 2567 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2568 | case Instruction::NEW_INSTANCE: { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 2569 | if (!BuildNewInstance(instruction.VRegB_21c(), dex_pc)) { |
| 2570 | return false; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2571 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 2572 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2573 | break; |
| 2574 | } |
| 2575 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2576 | case Instruction::NEW_ARRAY: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2577 | uint16_t type_index = instruction.VRegC_22c(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2578 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt, dex_pc); |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 2579 | bool finalizable; |
| 2580 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index, &finalizable) |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2581 | ? kQuickAllocArrayWithAccessCheck |
| 2582 | : kQuickAllocArray; |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2583 | current_block_->AddInstruction(new (arena_) HNewArray(length, |
| 2584 | graph_->GetCurrentMethod(), |
| 2585 | dex_pc, |
| 2586 | type_index, |
| 2587 | *dex_compilation_unit_->GetDexFile(), |
| 2588 | entrypoint)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2589 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2590 | break; |
| 2591 | } |
| 2592 | |
| 2593 | case Instruction::FILLED_NEW_ARRAY: { |
| 2594 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 2595 | uint32_t type_index = instruction.VRegB_35c(); |
| 2596 | uint32_t args[5]; |
| 2597 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2598 | BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2599 | break; |
| 2600 | } |
| 2601 | |
| 2602 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 2603 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 2604 | uint32_t type_index = instruction.VRegB_3rc(); |
| 2605 | uint32_t register_index = instruction.VRegC_3rc(); |
| 2606 | BuildFilledNewArray( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2607 | dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2608 | break; |
| 2609 | } |
| 2610 | |
| 2611 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2612 | BuildFillArrayData(instruction, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2613 | break; |
| 2614 | } |
| 2615 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2616 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2617 | case Instruction::MOVE_RESULT_WIDE: |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2618 | case Instruction::MOVE_RESULT_OBJECT: { |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2619 | if (latest_result_ == nullptr) { |
| 2620 | // Only dead code can lead to this situation, where the verifier |
| 2621 | // does not reject the method. |
| 2622 | } else { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2623 | // An Invoke/FilledNewArray and its MoveResult could have landed in |
| 2624 | // different blocks if there was a try/catch block boundary between |
| 2625 | // them. For Invoke, we insert a StoreLocal after the instruction. For |
| 2626 | // FilledNewArray, the local needs to be updated after the array was |
| 2627 | // filled, otherwise we might overwrite an input vreg. |
| 2628 | HStoreLocal* update_local = |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2629 | new (arena_) HStoreLocal(GetLocalAt(instruction.VRegA()), latest_result_, dex_pc); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2630 | HBasicBlock* block = latest_result_->GetBlock(); |
| 2631 | if (block == current_block_) { |
| 2632 | // MoveResult and the previous instruction are in the same block. |
| 2633 | current_block_->AddInstruction(update_local); |
| 2634 | } else { |
| 2635 | // The two instructions are in different blocks. Insert the MoveResult |
| 2636 | // before the final control-flow instruction of the previous block. |
| 2637 | DCHECK(block->EndsWithControlFlowInstruction()); |
| 2638 | DCHECK(current_block_->GetInstructions().IsEmpty()); |
| 2639 | block->InsertInstructionBefore(update_local, block->GetLastInstruction()); |
| 2640 | } |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2641 | latest_result_ = nullptr; |
| 2642 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2643 | break; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2644 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2645 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2646 | case Instruction::CMP_LONG: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2647 | Binop_23x_cmp(instruction, Primitive::kPrimLong, ComparisonBias::kNoBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2648 | break; |
| 2649 | } |
| 2650 | |
| 2651 | case Instruction::CMPG_FLOAT: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2652 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2653 | break; |
| 2654 | } |
| 2655 | |
| 2656 | case Instruction::CMPG_DOUBLE: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2657 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2658 | break; |
| 2659 | } |
| 2660 | |
| 2661 | case Instruction::CMPL_FLOAT: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2662 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kLtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2663 | break; |
| 2664 | } |
| 2665 | |
| 2666 | case Instruction::CMPL_DOUBLE: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2667 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kLtBias, dex_pc); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2668 | break; |
| 2669 | } |
| 2670 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2671 | case Instruction::NOP: |
| 2672 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2673 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2674 | case Instruction::IGET: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2675 | case Instruction::IGET_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2676 | case Instruction::IGET_WIDE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2677 | case Instruction::IGET_WIDE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2678 | case Instruction::IGET_OBJECT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2679 | case Instruction::IGET_OBJECT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2680 | case Instruction::IGET_BOOLEAN: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2681 | case Instruction::IGET_BOOLEAN_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2682 | case Instruction::IGET_BYTE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2683 | case Instruction::IGET_BYTE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2684 | case Instruction::IGET_CHAR: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2685 | case Instruction::IGET_CHAR_QUICK: |
| 2686 | case Instruction::IGET_SHORT: |
| 2687 | case Instruction::IGET_SHORT_QUICK: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2688 | if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2689 | return false; |
| 2690 | } |
| 2691 | break; |
| 2692 | } |
| 2693 | |
| 2694 | case Instruction::IPUT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2695 | case Instruction::IPUT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2696 | case Instruction::IPUT_WIDE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2697 | case Instruction::IPUT_WIDE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2698 | case Instruction::IPUT_OBJECT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2699 | case Instruction::IPUT_OBJECT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2700 | case Instruction::IPUT_BOOLEAN: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2701 | case Instruction::IPUT_BOOLEAN_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2702 | case Instruction::IPUT_BYTE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2703 | case Instruction::IPUT_BYTE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2704 | case Instruction::IPUT_CHAR: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2705 | case Instruction::IPUT_CHAR_QUICK: |
| 2706 | case Instruction::IPUT_SHORT: |
| 2707 | case Instruction::IPUT_SHORT_QUICK: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2708 | if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2709 | return false; |
| 2710 | } |
| 2711 | break; |
| 2712 | } |
| 2713 | |
| 2714 | case Instruction::SGET: |
| 2715 | case Instruction::SGET_WIDE: |
| 2716 | case Instruction::SGET_OBJECT: |
| 2717 | case Instruction::SGET_BOOLEAN: |
| 2718 | case Instruction::SGET_BYTE: |
| 2719 | case Instruction::SGET_CHAR: |
| 2720 | case Instruction::SGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2721 | if (!BuildStaticFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2722 | return false; |
| 2723 | } |
| 2724 | break; |
| 2725 | } |
| 2726 | |
| 2727 | case Instruction::SPUT: |
| 2728 | case Instruction::SPUT_WIDE: |
| 2729 | case Instruction::SPUT_OBJECT: |
| 2730 | case Instruction::SPUT_BOOLEAN: |
| 2731 | case Instruction::SPUT_BYTE: |
| 2732 | case Instruction::SPUT_CHAR: |
| 2733 | case Instruction::SPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2734 | if (!BuildStaticFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2735 | return false; |
| 2736 | } |
| 2737 | break; |
| 2738 | } |
| 2739 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2740 | #define ARRAY_XX(kind, anticipated_type) \ |
| 2741 | case Instruction::AGET##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2742 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2743 | break; \ |
| 2744 | } \ |
| 2745 | case Instruction::APUT##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2746 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2747 | break; \ |
| 2748 | } |
| 2749 | |
| 2750 | ARRAY_XX(, Primitive::kPrimInt); |
| 2751 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 2752 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 2753 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 2754 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 2755 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 2756 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 2757 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2758 | case Instruction::ARRAY_LENGTH: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2759 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2760 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2761 | current_block_->AddInstruction(object); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2762 | current_block_->AddInstruction(new (arena_) HArrayLength(object, dex_pc)); |
| 2763 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2764 | break; |
| 2765 | } |
| 2766 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2767 | case Instruction::CONST_STRING: { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2768 | uint32_t string_index = instruction.VRegB_21c(); |
| 2769 | bool in_dex_cache = compiler_driver_->CanAssumeStringIsPresentInDexCache( |
| 2770 | *dex_file_, string_index); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2771 | current_block_->AddInstruction( |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2772 | new (arena_) HLoadString(graph_->GetCurrentMethod(), string_index, dex_pc, in_dex_cache)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2773 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2774 | break; |
| 2775 | } |
| 2776 | |
| 2777 | case Instruction::CONST_STRING_JUMBO: { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2778 | uint32_t string_index = instruction.VRegB_31c(); |
| 2779 | bool in_dex_cache = compiler_driver_->CanAssumeStringIsPresentInDexCache( |
| 2780 | *dex_file_, string_index); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2781 | current_block_->AddInstruction( |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2782 | new (arena_) HLoadString(graph_->GetCurrentMethod(), string_index, dex_pc, in_dex_cache)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2783 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2784 | break; |
| 2785 | } |
| 2786 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2787 | case Instruction::CONST_CLASS: { |
| 2788 | uint16_t type_index = instruction.VRegB_21c(); |
| 2789 | bool type_known_final; |
| 2790 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2791 | bool dont_use_is_referrers_class; |
| 2792 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 2793 | // built is trying to access its own class, so that the generated |
| 2794 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2795 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2796 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 2797 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2798 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2799 | current_block_->AddInstruction(new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2800 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2801 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 2802 | *dex_file_, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2803 | IsOutermostCompilingClass(type_index), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2804 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 2805 | !can_access, |
| 2806 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(*dex_file_, type_index))); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2807 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2808 | break; |
| 2809 | } |
| 2810 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2811 | case Instruction::MOVE_EXCEPTION: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2812 | current_block_->AddInstruction(new (arena_) HLoadException(dex_pc)); |
| 2813 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction(), dex_pc); |
| 2814 | current_block_->AddInstruction(new (arena_) HClearException(dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2815 | break; |
| 2816 | } |
| 2817 | |
| 2818 | case Instruction::THROW: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2819 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2820 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2821 | // A throw instruction must branch to the exit block. |
| 2822 | current_block_->AddSuccessor(exit_block_); |
| 2823 | // We finished building this block. Set the current block to null to avoid |
| 2824 | // adding dead instructions to it. |
| 2825 | current_block_ = nullptr; |
| 2826 | break; |
| 2827 | } |
| 2828 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2829 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2830 | uint8_t destination = instruction.VRegA_22c(); |
| 2831 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2832 | uint16_t type_index = instruction.VRegC_22c(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2833 | BuildTypeCheck(instruction, destination, reference, type_index, dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2834 | break; |
| 2835 | } |
| 2836 | |
| 2837 | case Instruction::CHECK_CAST: { |
| 2838 | uint8_t reference = instruction.VRegA_21c(); |
| 2839 | uint16_t type_index = instruction.VRegB_21c(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2840 | BuildTypeCheck(instruction, -1, reference, type_index, dex_pc); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2841 | break; |
| 2842 | } |
| 2843 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2844 | case Instruction::MONITOR_ENTER: { |
| 2845 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2846 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2847 | HMonitorOperation::OperationKind::kEnter, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2848 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2849 | break; |
| 2850 | } |
| 2851 | |
| 2852 | case Instruction::MONITOR_EXIT: { |
| 2853 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2854 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2855 | HMonitorOperation::OperationKind::kExit, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2856 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2857 | break; |
| 2858 | } |
| 2859 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2860 | case Instruction::PACKED_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2861 | BuildPackedSwitch(instruction, dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2862 | break; |
| 2863 | } |
| 2864 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2865 | case Instruction::SPARSE_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2866 | BuildSparseSwitch(instruction, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2867 | break; |
| 2868 | } |
| 2869 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2870 | default: |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2871 | VLOG(compiler) << "Did not compile " |
| 2872 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 2873 | << " because of unhandled instruction " |
| 2874 | << instruction.Name(); |
| 2875 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnhandledInstruction); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2876 | return false; |
| 2877 | } |
| 2878 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2879 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2880 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 2881 | HLocal* HGraphBuilder::GetLocalAt(uint32_t register_index) const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 2882 | return locals_[register_index]; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 2885 | void HGraphBuilder::UpdateLocal(uint32_t register_index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2886 | HInstruction* instruction, |
| 2887 | uint32_t dex_pc) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2888 | HLocal* local = GetLocalAt(register_index); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2889 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction, dex_pc)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 2892 | HInstruction* HGraphBuilder::LoadLocal(uint32_t register_index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2893 | Primitive::Type type, |
| 2894 | uint32_t dex_pc) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2895 | HLocal* local = GetLocalAt(register_index); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2896 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type, dex_pc)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2897 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2900 | } // namespace art |