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