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