David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_INSTRUCTION_BUILDER_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_INSTRUCTION_BUILDER_H_ |
| 19 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 20 | #include "base/scoped_arena_allocator.h" |
| 21 | #include "base/scoped_arena_containers.h" |
| 22 | #include "data_type.h" |
| 23 | #include "dex_file.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 24 | #include "dex_file_types.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 25 | #include "handle.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 26 | #include "nodes.h" |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 27 | #include "quicken_info.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 31 | class ArenaBitVector; |
| 32 | class ArtField; |
| 33 | class ArtMethod; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 34 | class CodeGenerator; |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 35 | class CompilerDriver; |
| 36 | class DexCompilationUnit; |
| 37 | class HBasicBlockBuilder; |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 38 | class Instruction; |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 39 | class OptimizingCompilerStats; |
| 40 | class SsaBuilder; |
| 41 | class VariableSizedHandleScope; |
| 42 | |
| 43 | namespace mirror { |
| 44 | class Class; |
| 45 | } // namespace mirror |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 46 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 47 | class HInstructionBuilder : public ValueObject { |
| 48 | public: |
| 49 | HInstructionBuilder(HGraph* graph, |
| 50 | HBasicBlockBuilder* block_builder, |
| 51 | SsaBuilder* ssa_builder, |
| 52 | const DexFile* dex_file, |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame^] | 53 | const DexFile::CodeItem* code_item, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 54 | DataType::Type return_type, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 55 | const DexCompilationUnit* dex_compilation_unit, |
| 56 | const DexCompilationUnit* outer_compilation_unit, |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 57 | CompilerDriver* compiler_driver, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 58 | CodeGenerator* code_generator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 59 | const uint8_t* interpreter_metadata, |
| 60 | OptimizingCompilerStats* compiler_stats, |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 61 | VariableSizedHandleScope* handles, |
| 62 | ScopedArenaAllocator* local_allocator) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 63 | : allocator_(graph->GetAllocator()), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 64 | graph_(graph), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 65 | handles_(handles), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 66 | dex_file_(dex_file), |
| 67 | code_item_(code_item), |
| 68 | return_type_(return_type), |
| 69 | block_builder_(block_builder), |
| 70 | ssa_builder_(ssa_builder), |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 71 | compiler_driver_(compiler_driver), |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 72 | code_generator_(code_generator), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 73 | dex_compilation_unit_(dex_compilation_unit), |
| 74 | outer_compilation_unit_(outer_compilation_unit), |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 75 | quicken_info_(interpreter_metadata), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 76 | compilation_stats_(compiler_stats), |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 77 | local_allocator_(local_allocator), |
| 78 | locals_for_(local_allocator->Adapter(kArenaAllocGraphBuilder)), |
| 79 | current_block_(nullptr), |
| 80 | current_locals_(nullptr), |
| 81 | latest_result_(nullptr), |
| 82 | current_this_parameter_(nullptr), |
| 83 | loop_headers_(local_allocator->Adapter(kArenaAllocGraphBuilder)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 84 | loop_headers_.reserve(kDefaultNumberOfLoops); |
| 85 | } |
| 86 | |
| 87 | bool Build(); |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame^] | 88 | void BuildIntrinsic(ArtMethod* method); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 89 | |
| 90 | private: |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 91 | void InitializeBlockLocals(); |
| 92 | void PropagateLocalsToCatchBlocks(); |
| 93 | void SetLoopHeaderPhiInputs(); |
| 94 | |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 95 | bool ProcessDexInstruction(const Instruction& instruction, uint32_t dex_pc, size_t quicken_index); |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 96 | ArenaBitVector* FindNativeDebugInfoLocations(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 97 | |
| 98 | bool CanDecodeQuickenedInfo() const; |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 99 | uint16_t LookupQuickenedInfo(uint32_t quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 100 | |
| 101 | HBasicBlock* FindBlockStartingAt(uint32_t dex_pc) const; |
| 102 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 103 | ScopedArenaVector<HInstruction*>* GetLocalsFor(HBasicBlock* block); |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 104 | // Out of line version of GetLocalsFor(), which has a fast path that is |
| 105 | // beneficial to get inlined by callers. |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 106 | ScopedArenaVector<HInstruction*>* GetLocalsForWithAllocation( |
| 107 | HBasicBlock* block, ScopedArenaVector<HInstruction*>* locals, const size_t vregs); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 108 | HInstruction* ValueOfLocalAt(HBasicBlock* block, size_t local); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 109 | HInstruction* LoadLocal(uint32_t register_index, DataType::Type type) const; |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 110 | HInstruction* LoadNullCheckedLocal(uint32_t register_index, uint32_t dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 111 | void UpdateLocal(uint32_t register_index, HInstruction* instruction); |
| 112 | |
| 113 | void AppendInstruction(HInstruction* instruction); |
| 114 | void InsertInstructionAtTop(HInstruction* instruction); |
| 115 | void InitializeInstruction(HInstruction* instruction); |
| 116 | |
| 117 | void InitializeParameters(); |
| 118 | |
| 119 | // Returns whether the current method needs access check for the type. |
| 120 | // Output parameter finalizable is set to whether the type is finalizable. |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 121 | bool NeedsAccessCheck(dex::TypeIndex type_index, /*out*/bool* finalizable) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 122 | REQUIRES_SHARED(Locks::mutator_lock_); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 123 | |
| 124 | template<typename T> |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 125 | void Unop_12x(const Instruction& instruction, DataType::Type type, uint32_t dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 126 | |
| 127 | template<typename T> |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 128 | void Binop_23x(const Instruction& instruction, DataType::Type type, uint32_t dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 129 | |
| 130 | template<typename T> |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 131 | void Binop_23x_shift(const Instruction& instruction, DataType::Type type, uint32_t dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 132 | |
| 133 | void Binop_23x_cmp(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 134 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 135 | ComparisonBias bias, |
| 136 | uint32_t dex_pc); |
| 137 | |
| 138 | template<typename T> |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 139 | void Binop_12x(const Instruction& instruction, DataType::Type type, uint32_t dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 140 | |
| 141 | template<typename T> |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 142 | void Binop_12x_shift(const Instruction& instruction, DataType::Type type, uint32_t dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 143 | |
| 144 | template<typename T> |
| 145 | void Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc); |
| 146 | |
| 147 | template<typename T> |
| 148 | void Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc); |
| 149 | |
| 150 | template<typename T> void If_21t(const Instruction& instruction, uint32_t dex_pc); |
| 151 | template<typename T> void If_22t(const Instruction& instruction, uint32_t dex_pc); |
| 152 | |
| 153 | void Conversion_12x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 154 | DataType::Type input_type, |
| 155 | DataType::Type result_type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 156 | uint32_t dex_pc); |
| 157 | |
| 158 | void BuildCheckedDivRem(uint16_t out_reg, |
| 159 | uint16_t first_reg, |
| 160 | int64_t second_reg_or_constant, |
| 161 | uint32_t dex_pc, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 162 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 163 | bool second_is_lit, |
| 164 | bool is_div); |
| 165 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 166 | void BuildReturn(const Instruction& instruction, DataType::Type type, uint32_t dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 167 | |
| 168 | // Builds an instance field access node and returns whether the instruction is supported. |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 169 | bool BuildInstanceFieldAccess(const Instruction& instruction, |
| 170 | uint32_t dex_pc, |
| 171 | bool is_put, |
| 172 | size_t quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 173 | |
| 174 | void BuildUnresolvedStaticFieldAccess(const Instruction& instruction, |
| 175 | uint32_t dex_pc, |
| 176 | bool is_put, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 177 | DataType::Type field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 178 | // Builds a static field access node and returns whether the instruction is supported. |
| 179 | bool BuildStaticFieldAccess(const Instruction& instruction, uint32_t dex_pc, bool is_put); |
| 180 | |
| 181 | void BuildArrayAccess(const Instruction& instruction, |
| 182 | uint32_t dex_pc, |
| 183 | bool is_get, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 184 | DataType::Type anticipated_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 185 | |
| 186 | // Builds an invocation node and returns whether the instruction is supported. |
| 187 | bool BuildInvoke(const Instruction& instruction, |
| 188 | uint32_t dex_pc, |
| 189 | uint32_t method_idx, |
| 190 | uint32_t number_of_vreg_arguments, |
| 191 | bool is_range, |
| 192 | uint32_t* args, |
| 193 | uint32_t register_index); |
| 194 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 195 | // Builds an invocation node for invoke-polymorphic and returns whether the |
| 196 | // instruction is supported. |
| 197 | bool BuildInvokePolymorphic(const Instruction& instruction, |
| 198 | uint32_t dex_pc, |
| 199 | uint32_t method_idx, |
| 200 | uint32_t proto_idx, |
| 201 | uint32_t number_of_vreg_arguments, |
| 202 | bool is_range, |
| 203 | uint32_t* args, |
| 204 | uint32_t register_index); |
| 205 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 206 | // Builds a new array node and the instructions that fill it. |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 207 | HNewArray* BuildFilledNewArray(uint32_t dex_pc, |
| 208 | dex::TypeIndex type_index, |
| 209 | uint32_t number_of_vreg_arguments, |
| 210 | bool is_range, |
| 211 | uint32_t* args, |
| 212 | uint32_t register_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 213 | |
| 214 | void BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc); |
| 215 | |
| 216 | // Fills the given object with data as specified in the fill-array-data |
| 217 | // instruction. Currently only used for non-reference and non-floating point |
| 218 | // arrays. |
| 219 | template <typename T> |
| 220 | void BuildFillArrayData(HInstruction* object, |
| 221 | const T* data, |
| 222 | uint32_t element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 223 | DataType::Type anticipated_type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 224 | uint32_t dex_pc); |
| 225 | |
| 226 | // Fills the given object with data as specified in the fill-array-data |
| 227 | // instruction. The data must be for long and double arrays. |
| 228 | void BuildFillWideArrayData(HInstruction* object, |
| 229 | const int64_t* data, |
| 230 | uint32_t element_count, |
| 231 | uint32_t dex_pc); |
| 232 | |
| 233 | // Builds a `HInstanceOf`, or a `HCheckCast` instruction. |
| 234 | void BuildTypeCheck(const Instruction& instruction, |
| 235 | uint8_t destination, |
| 236 | uint8_t reference, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 237 | dex::TypeIndex type_index, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 238 | uint32_t dex_pc); |
| 239 | |
| 240 | // Builds an instruction sequence for a switch statement. |
| 241 | void BuildSwitch(const Instruction& instruction, uint32_t dex_pc); |
| 242 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 243 | // Builds a `HLoadClass` loading the given `type_index`. If `outer` is true, |
| 244 | // this method will use the outer class's dex file to lookup the type at |
| 245 | // `type_index`. |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 246 | HLoadClass* BuildLoadClass(dex::TypeIndex type_index, uint32_t dex_pc); |
| 247 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 248 | HLoadClass* BuildLoadClass(dex::TypeIndex type_index, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 249 | const DexFile& dex_file, |
| 250 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 251 | uint32_t dex_pc, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 252 | bool needs_access_check) |
| 253 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 254 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 255 | // Returns the outer-most compiling method's class. |
| 256 | mirror::Class* GetOutermostCompilingClass() const; |
| 257 | |
| 258 | // Returns the class whose method is being compiled. |
| 259 | mirror::Class* GetCompilingClass() const; |
| 260 | |
| 261 | // Returns whether `type_index` points to the outer-most compiling method's class. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 262 | bool IsOutermostCompilingClass(dex::TypeIndex type_index) const; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 263 | |
| 264 | void PotentiallySimplifyFakeString(uint16_t original_dex_register, |
| 265 | uint32_t dex_pc, |
| 266 | HInvoke* invoke); |
| 267 | |
| 268 | bool SetupInvokeArguments(HInvoke* invoke, |
| 269 | uint32_t number_of_vreg_arguments, |
| 270 | uint32_t* args, |
| 271 | uint32_t register_index, |
| 272 | bool is_range, |
| 273 | const char* descriptor, |
| 274 | size_t start_index, |
| 275 | size_t* argument_index); |
| 276 | |
| 277 | bool HandleInvoke(HInvoke* invoke, |
| 278 | uint32_t number_of_vreg_arguments, |
| 279 | uint32_t* args, |
| 280 | uint32_t register_index, |
| 281 | bool is_range, |
| 282 | const char* descriptor, |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 283 | HClinitCheck* clinit_check, |
| 284 | bool is_unresolved); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 285 | |
| 286 | bool HandleStringInit(HInvoke* invoke, |
| 287 | uint32_t number_of_vreg_arguments, |
| 288 | uint32_t* args, |
| 289 | uint32_t register_index, |
| 290 | bool is_range, |
| 291 | const char* descriptor); |
| 292 | void HandleStringInitResult(HInvokeStaticOrDirect* invoke); |
| 293 | |
| 294 | HClinitCheck* ProcessClinitCheckForInvoke( |
| 295 | uint32_t dex_pc, |
| 296 | ArtMethod* method, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 297 | HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 298 | REQUIRES_SHARED(Locks::mutator_lock_); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 299 | |
| 300 | // Build a HNewInstance instruction. |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 301 | HNewInstance* BuildNewInstance(dex::TypeIndex type_index, uint32_t dex_pc); |
| 302 | |
| 303 | // Build a HConstructorFence for HNewInstance and HNewArray instructions. This ensures the |
| 304 | // happens-before ordering for default-initialization of the object referred to by new_instance. |
| 305 | void BuildConstructorFenceForAllocation(HInstruction* allocation); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 306 | |
| 307 | // Return whether the compiler can assume `cls` is initialized. |
| 308 | bool IsInitialized(Handle<mirror::Class> cls) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 309 | REQUIRES_SHARED(Locks::mutator_lock_); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 310 | |
| 311 | // Try to resolve a method using the class linker. Return null if a method could |
| 312 | // not be resolved. |
| 313 | ArtMethod* ResolveMethod(uint16_t method_idx, InvokeType invoke_type); |
| 314 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 315 | // Try to resolve a field using the class linker. Return null if it could not |
| 316 | // be found. |
| 317 | ArtField* ResolveField(uint16_t field_idx, bool is_static, bool is_put); |
| 318 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 319 | ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_index, |
| 320 | const DexCompilationUnit& compilation_unit) const |
| 321 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 322 | |
| 323 | ObjPtr<mirror::Class> LookupReferrerClass() const REQUIRES_SHARED(Locks::mutator_lock_); |
| 324 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 325 | ArenaAllocator* const allocator_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 326 | HGraph* const graph_; |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 327 | VariableSizedHandleScope* const handles_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 328 | |
| 329 | // The dex file where the method being compiled is, and the bytecode data. |
| 330 | const DexFile* const dex_file_; |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame^] | 331 | const DexFile::CodeItem* const code_item_; // null for intrinsic graph. |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 332 | |
| 333 | // The return type of the method being compiled. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 334 | const DataType::Type return_type_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 335 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 336 | HBasicBlockBuilder* const block_builder_; |
| 337 | SsaBuilder* const ssa_builder_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 338 | |
| 339 | CompilerDriver* const compiler_driver_; |
| 340 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 341 | CodeGenerator* const code_generator_; |
| 342 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 343 | // The compilation unit of the current method being compiled. Note that |
| 344 | // it can be an inlined method. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 345 | const DexCompilationUnit* const dex_compilation_unit_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 346 | |
| 347 | // The compilation unit of the outermost method being compiled. That is the |
| 348 | // method being compiled (and not inlined), and potentially inlining other |
| 349 | // methods. |
| 350 | const DexCompilationUnit* const outer_compilation_unit_; |
| 351 | |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 352 | // Original values kept after instruction quickening. |
| 353 | QuickenInfoTable quicken_info_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 354 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 355 | OptimizingCompilerStats* const compilation_stats_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 356 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 357 | ScopedArenaAllocator* const local_allocator_; |
| 358 | ScopedArenaVector<ScopedArenaVector<HInstruction*>> locals_for_; |
| 359 | HBasicBlock* current_block_; |
| 360 | ScopedArenaVector<HInstruction*>* current_locals_; |
| 361 | HInstruction* latest_result_; |
| 362 | // Current "this" parameter. |
| 363 | // Valid only after InitializeParameters() finishes. |
| 364 | // * Null for static methods. |
| 365 | // * Non-null for instance methods. |
| 366 | HParameterValue* current_this_parameter_; |
| 367 | |
| 368 | ScopedArenaVector<HBasicBlock*> loop_headers_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 369 | |
| 370 | static constexpr int kDefaultNumberOfLoops = 2; |
| 371 | |
| 372 | DISALLOW_COPY_AND_ASSIGN(HInstructionBuilder); |
| 373 | }; |
| 374 | |
| 375 | } // namespace art |
| 376 | |
| 377 | #endif // ART_COMPILER_OPTIMIZING_INSTRUCTION_BUILDER_H_ |