xref: /aosp_15_r20/art/compiler/optimizing/instruction_builder.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2016 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_COMPILER_OPTIMIZING_INSTRUCTION_BUILDER_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_COMPILER_OPTIMIZING_INSTRUCTION_BUILDER_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include "base/array_ref.h"
21*795d594fSAndroid Build Coastguard Worker #include "base/macros.h"
22*795d594fSAndroid Build Coastguard Worker #include "base/scoped_arena_allocator.h"
23*795d594fSAndroid Build Coastguard Worker #include "base/scoped_arena_containers.h"
24*795d594fSAndroid Build Coastguard Worker #include "data_type.h"
25*795d594fSAndroid Build Coastguard Worker #include "dex/code_item_accessors.h"
26*795d594fSAndroid Build Coastguard Worker #include "dex/dex_file.h"
27*795d594fSAndroid Build Coastguard Worker #include "dex/dex_file_types.h"
28*795d594fSAndroid Build Coastguard Worker #include "handle.h"
29*795d594fSAndroid Build Coastguard Worker #include "nodes.h"
30*795d594fSAndroid Build Coastguard Worker 
31*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
32*795d594fSAndroid Build Coastguard Worker 
33*795d594fSAndroid Build Coastguard Worker class ArenaBitVector;
34*795d594fSAndroid Build Coastguard Worker class ArtField;
35*795d594fSAndroid Build Coastguard Worker class ArtMethod;
36*795d594fSAndroid Build Coastguard Worker class CodeGenerator;
37*795d594fSAndroid Build Coastguard Worker class DexCompilationUnit;
38*795d594fSAndroid Build Coastguard Worker class HBasicBlockBuilder;
39*795d594fSAndroid Build Coastguard Worker class Instruction;
40*795d594fSAndroid Build Coastguard Worker class InstructionOperands;
41*795d594fSAndroid Build Coastguard Worker class OptimizingCompilerStats;
42*795d594fSAndroid Build Coastguard Worker class ScopedObjectAccess;
43*795d594fSAndroid Build Coastguard Worker class SsaBuilder;
44*795d594fSAndroid Build Coastguard Worker 
45*795d594fSAndroid Build Coastguard Worker namespace mirror {
46*795d594fSAndroid Build Coastguard Worker class Class;
47*795d594fSAndroid Build Coastguard Worker class MethodType;
48*795d594fSAndroid Build Coastguard Worker }  // namespace mirror
49*795d594fSAndroid Build Coastguard Worker 
50*795d594fSAndroid Build Coastguard Worker class HInstructionBuilder : public ValueObject {
51*795d594fSAndroid Build Coastguard Worker  public:
52*795d594fSAndroid Build Coastguard Worker   HInstructionBuilder(HGraph* graph,
53*795d594fSAndroid Build Coastguard Worker                       HBasicBlockBuilder* block_builder,
54*795d594fSAndroid Build Coastguard Worker                       SsaBuilder* ssa_builder,
55*795d594fSAndroid Build Coastguard Worker                       const DexFile* dex_file,
56*795d594fSAndroid Build Coastguard Worker                       const CodeItemDebugInfoAccessor& accessor,
57*795d594fSAndroid Build Coastguard Worker                       DataType::Type return_type,
58*795d594fSAndroid Build Coastguard Worker                       const DexCompilationUnit* dex_compilation_unit,
59*795d594fSAndroid Build Coastguard Worker                       const DexCompilationUnit* outer_compilation_unit,
60*795d594fSAndroid Build Coastguard Worker                       CodeGenerator* code_generator,
61*795d594fSAndroid Build Coastguard Worker                       OptimizingCompilerStats* compiler_stats,
62*795d594fSAndroid Build Coastguard Worker                       ScopedArenaAllocator* local_allocator);
63*795d594fSAndroid Build Coastguard Worker 
64*795d594fSAndroid Build Coastguard Worker   bool Build();
65*795d594fSAndroid Build Coastguard Worker   void BuildIntrinsic(ArtMethod* method);
66*795d594fSAndroid Build Coastguard Worker 
67*795d594fSAndroid Build Coastguard Worker  private:
68*795d594fSAndroid Build Coastguard Worker   void InitializeBlockLocals();
69*795d594fSAndroid Build Coastguard Worker   void PropagateLocalsToCatchBlocks();
70*795d594fSAndroid Build Coastguard Worker   void SetLoopHeaderPhiInputs();
71*795d594fSAndroid Build Coastguard Worker 
72*795d594fSAndroid Build Coastguard Worker   bool ProcessDexInstruction(const Instruction& instruction, uint32_t dex_pc);
73*795d594fSAndroid Build Coastguard Worker   ArenaBitVector* FindNativeDebugInfoLocations();
74*795d594fSAndroid Build Coastguard Worker 
75*795d594fSAndroid Build Coastguard Worker   HBasicBlock* FindBlockStartingAt(uint32_t dex_pc) const;
76*795d594fSAndroid Build Coastguard Worker 
77*795d594fSAndroid Build Coastguard Worker   ScopedArenaVector<HInstruction*>* GetLocalsFor(HBasicBlock* block);
78*795d594fSAndroid Build Coastguard Worker   // Out of line version of GetLocalsFor(), which has a fast path that is
79*795d594fSAndroid Build Coastguard Worker   // beneficial to get inlined by callers.
80*795d594fSAndroid Build Coastguard Worker   ScopedArenaVector<HInstruction*>* GetLocalsForWithAllocation(
81*795d594fSAndroid Build Coastguard Worker       HBasicBlock* block, ScopedArenaVector<HInstruction*>* locals, const size_t vregs);
82*795d594fSAndroid Build Coastguard Worker   HInstruction* ValueOfLocalAt(HBasicBlock* block, size_t local);
83*795d594fSAndroid Build Coastguard Worker   HInstruction* LoadLocal(uint32_t register_index, DataType::Type type) const;
84*795d594fSAndroid Build Coastguard Worker   HInstruction* LoadNullCheckedLocal(uint32_t register_index, uint32_t dex_pc);
85*795d594fSAndroid Build Coastguard Worker   void UpdateLocal(uint32_t register_index, HInstruction* instruction);
86*795d594fSAndroid Build Coastguard Worker 
87*795d594fSAndroid Build Coastguard Worker   void AppendInstruction(HInstruction* instruction);
88*795d594fSAndroid Build Coastguard Worker   void InsertInstructionAtTop(HInstruction* instruction);
89*795d594fSAndroid Build Coastguard Worker   void InitializeInstruction(HInstruction* instruction);
90*795d594fSAndroid Build Coastguard Worker 
91*795d594fSAndroid Build Coastguard Worker   void InitializeParameters();
92*795d594fSAndroid Build Coastguard Worker 
93*795d594fSAndroid Build Coastguard Worker   template<typename T>
94*795d594fSAndroid Build Coastguard Worker   void Unop_12x(const Instruction& instruction, DataType::Type type, uint32_t dex_pc);
95*795d594fSAndroid Build Coastguard Worker 
96*795d594fSAndroid Build Coastguard Worker   template<typename T>
97*795d594fSAndroid Build Coastguard Worker   void Binop_23x(const Instruction& instruction, DataType::Type type, uint32_t dex_pc);
98*795d594fSAndroid Build Coastguard Worker 
99*795d594fSAndroid Build Coastguard Worker   template<typename T>
100*795d594fSAndroid Build Coastguard Worker   void Binop_23x_shift(const Instruction& instruction, DataType::Type type, uint32_t dex_pc);
101*795d594fSAndroid Build Coastguard Worker 
102*795d594fSAndroid Build Coastguard Worker   void Binop_23x_cmp(const Instruction& instruction,
103*795d594fSAndroid Build Coastguard Worker                      DataType::Type type,
104*795d594fSAndroid Build Coastguard Worker                      ComparisonBias bias,
105*795d594fSAndroid Build Coastguard Worker                      uint32_t dex_pc);
106*795d594fSAndroid Build Coastguard Worker 
107*795d594fSAndroid Build Coastguard Worker   template<typename T>
108*795d594fSAndroid Build Coastguard Worker   void Binop_12x(const Instruction& instruction, DataType::Type type, uint32_t dex_pc);
109*795d594fSAndroid Build Coastguard Worker 
110*795d594fSAndroid Build Coastguard Worker   template<typename T>
111*795d594fSAndroid Build Coastguard Worker   void Binop_12x_shift(const Instruction& instruction, DataType::Type type, uint32_t dex_pc);
112*795d594fSAndroid Build Coastguard Worker 
113*795d594fSAndroid Build Coastguard Worker   template<typename T>
114*795d594fSAndroid Build Coastguard Worker   void Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc);
115*795d594fSAndroid Build Coastguard Worker 
116*795d594fSAndroid Build Coastguard Worker   template<typename T>
117*795d594fSAndroid Build Coastguard Worker   void Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc);
118*795d594fSAndroid Build Coastguard Worker 
119*795d594fSAndroid Build Coastguard Worker   template<typename T, bool kCompareWithZero>
120*795d594fSAndroid Build Coastguard Worker   void If_21_22t(const Instruction& instruction, uint32_t dex_pc);
121*795d594fSAndroid Build Coastguard Worker 
122*795d594fSAndroid Build Coastguard Worker   void Conversion_12x(const Instruction& instruction,
123*795d594fSAndroid Build Coastguard Worker                       DataType::Type input_type,
124*795d594fSAndroid Build Coastguard Worker                       DataType::Type result_type,
125*795d594fSAndroid Build Coastguard Worker                       uint32_t dex_pc);
126*795d594fSAndroid Build Coastguard Worker 
127*795d594fSAndroid Build Coastguard Worker   void BuildCheckedDivRem(uint16_t out_reg,
128*795d594fSAndroid Build Coastguard Worker                           uint16_t first_reg,
129*795d594fSAndroid Build Coastguard Worker                           int64_t second_reg_or_constant,
130*795d594fSAndroid Build Coastguard Worker                           uint32_t dex_pc,
131*795d594fSAndroid Build Coastguard Worker                           DataType::Type type,
132*795d594fSAndroid Build Coastguard Worker                           bool second_is_lit,
133*795d594fSAndroid Build Coastguard Worker                           bool is_div);
134*795d594fSAndroid Build Coastguard Worker 
135*795d594fSAndroid Build Coastguard Worker   template <DataType::Type type>
136*795d594fSAndroid Build Coastguard Worker   void BuildMove(uint32_t dest_reg, uint32_t src_reg);
137*795d594fSAndroid Build Coastguard Worker 
138*795d594fSAndroid Build Coastguard Worker   void BuildReturn(const Instruction& instruction, DataType::Type type, uint32_t dex_pc);
139*795d594fSAndroid Build Coastguard Worker 
140*795d594fSAndroid Build Coastguard Worker   // Builds an instance field access node and returns whether the instruction is supported.
141*795d594fSAndroid Build Coastguard Worker   bool BuildInstanceFieldAccess(const Instruction& instruction,
142*795d594fSAndroid Build Coastguard Worker                                 uint32_t dex_pc,
143*795d594fSAndroid Build Coastguard Worker                                 bool is_put);
144*795d594fSAndroid Build Coastguard Worker 
145*795d594fSAndroid Build Coastguard Worker   void BuildUnresolvedStaticFieldAccess(const Instruction& instruction,
146*795d594fSAndroid Build Coastguard Worker                                         uint32_t dex_pc,
147*795d594fSAndroid Build Coastguard Worker                                         bool is_put,
148*795d594fSAndroid Build Coastguard Worker                                         DataType::Type field_type);
149*795d594fSAndroid Build Coastguard Worker   // Builds a static field access node.
150*795d594fSAndroid Build Coastguard Worker   void BuildStaticFieldAccess(const Instruction& instruction, uint32_t dex_pc, bool is_put);
151*795d594fSAndroid Build Coastguard Worker 
152*795d594fSAndroid Build Coastguard Worker   void BuildArrayAccess(const Instruction& instruction,
153*795d594fSAndroid Build Coastguard Worker                         uint32_t dex_pc,
154*795d594fSAndroid Build Coastguard Worker                         bool is_get,
155*795d594fSAndroid Build Coastguard Worker                         DataType::Type anticipated_type);
156*795d594fSAndroid Build Coastguard Worker 
157*795d594fSAndroid Build Coastguard Worker   // Builds an invocation node and returns whether the instruction is supported.
158*795d594fSAndroid Build Coastguard Worker   bool BuildInvoke(const Instruction& instruction,
159*795d594fSAndroid Build Coastguard Worker                    uint32_t dex_pc,
160*795d594fSAndroid Build Coastguard Worker                    uint32_t method_idx,
161*795d594fSAndroid Build Coastguard Worker                    const InstructionOperands& operands);
162*795d594fSAndroid Build Coastguard Worker 
163*795d594fSAndroid Build Coastguard Worker   // Builds an invocation node for invoke-polymorphic and returns whether the
164*795d594fSAndroid Build Coastguard Worker   // instruction is supported.
165*795d594fSAndroid Build Coastguard Worker   bool BuildInvokePolymorphic(uint32_t dex_pc,
166*795d594fSAndroid Build Coastguard Worker                               uint32_t method_idx,
167*795d594fSAndroid Build Coastguard Worker                               dex::ProtoIndex proto_idx,
168*795d594fSAndroid Build Coastguard Worker                               const InstructionOperands& operands);
169*795d594fSAndroid Build Coastguard Worker 
170*795d594fSAndroid Build Coastguard Worker   // Builds an invocation node for invoke-custom and returns whether the
171*795d594fSAndroid Build Coastguard Worker   // instruction is supported.
172*795d594fSAndroid Build Coastguard Worker   bool BuildInvokeCustom(uint32_t dex_pc,
173*795d594fSAndroid Build Coastguard Worker                          uint32_t call_site_idx,
174*795d594fSAndroid Build Coastguard Worker                          const InstructionOperands& operands);
175*795d594fSAndroid Build Coastguard Worker 
176*795d594fSAndroid Build Coastguard Worker   // Builds a new array node.
177*795d594fSAndroid Build Coastguard Worker   HNewArray* BuildNewArray(uint32_t dex_pc, dex::TypeIndex type_index, HInstruction* length);
178*795d594fSAndroid Build Coastguard Worker 
179*795d594fSAndroid Build Coastguard Worker   // Builds a new array node and the instructions that fill it.
180*795d594fSAndroid Build Coastguard Worker   HNewArray* BuildFilledNewArray(uint32_t dex_pc,
181*795d594fSAndroid Build Coastguard Worker                                  dex::TypeIndex type_index,
182*795d594fSAndroid Build Coastguard Worker                                  const InstructionOperands& operands);
183*795d594fSAndroid Build Coastguard Worker 
184*795d594fSAndroid Build Coastguard Worker   void BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc);
185*795d594fSAndroid Build Coastguard Worker 
186*795d594fSAndroid Build Coastguard Worker   // Fills the given object with data as specified in the fill-array-data
187*795d594fSAndroid Build Coastguard Worker   // instruction. Currently only used for non-reference and non-floating point
188*795d594fSAndroid Build Coastguard Worker   // arrays.
189*795d594fSAndroid Build Coastguard Worker   template <typename T>
190*795d594fSAndroid Build Coastguard Worker   void BuildFillArrayData(HInstruction* object,
191*795d594fSAndroid Build Coastguard Worker                           const T* data,
192*795d594fSAndroid Build Coastguard Worker                           uint32_t element_count,
193*795d594fSAndroid Build Coastguard Worker                           DataType::Type anticipated_type,
194*795d594fSAndroid Build Coastguard Worker                           uint32_t dex_pc);
195*795d594fSAndroid Build Coastguard Worker 
196*795d594fSAndroid Build Coastguard Worker   // Fills the given object with data as specified in the fill-array-data
197*795d594fSAndroid Build Coastguard Worker   // instruction. The data must be for long and double arrays.
198*795d594fSAndroid Build Coastguard Worker   void BuildFillWideArrayData(HInstruction* object,
199*795d594fSAndroid Build Coastguard Worker                               const int64_t* data,
200*795d594fSAndroid Build Coastguard Worker                               uint32_t element_count,
201*795d594fSAndroid Build Coastguard Worker                               uint32_t dex_pc);
202*795d594fSAndroid Build Coastguard Worker 
203*795d594fSAndroid Build Coastguard Worker   // Builds a `HInstanceOf`, or a `HCheckCast` instruction.
204*795d594fSAndroid Build Coastguard Worker   void BuildTypeCheck(bool is_instance_of,
205*795d594fSAndroid Build Coastguard Worker                       HInstruction* object,
206*795d594fSAndroid Build Coastguard Worker                       dex::TypeIndex type_index,
207*795d594fSAndroid Build Coastguard Worker                       uint32_t dex_pc);
208*795d594fSAndroid Build Coastguard Worker   void BuildTypeCheck(const Instruction& instruction,
209*795d594fSAndroid Build Coastguard Worker                       uint8_t destination,
210*795d594fSAndroid Build Coastguard Worker                       uint8_t reference,
211*795d594fSAndroid Build Coastguard Worker                       dex::TypeIndex type_index,
212*795d594fSAndroid Build Coastguard Worker                       uint32_t dex_pc);
213*795d594fSAndroid Build Coastguard Worker 
214*795d594fSAndroid Build Coastguard Worker   // Builds an instruction sequence for a switch statement.
215*795d594fSAndroid Build Coastguard Worker   void BuildSwitch(const Instruction& instruction, uint32_t dex_pc);
216*795d594fSAndroid Build Coastguard Worker 
217*795d594fSAndroid Build Coastguard Worker   // Builds a `HLoadString` loading the given `string_index`.
218*795d594fSAndroid Build Coastguard Worker   void BuildLoadString(dex::StringIndex string_index, uint32_t dex_pc);
219*795d594fSAndroid Build Coastguard Worker 
220*795d594fSAndroid Build Coastguard Worker   // Builds a `HLoadClass` loading the given `type_index`.
221*795d594fSAndroid Build Coastguard Worker   HLoadClass* BuildLoadClass(dex::TypeIndex type_index, uint32_t dex_pc);
222*795d594fSAndroid Build Coastguard Worker 
223*795d594fSAndroid Build Coastguard Worker   HLoadClass* BuildLoadClass(dex::TypeIndex type_index,
224*795d594fSAndroid Build Coastguard Worker                              const DexFile& dex_file,
225*795d594fSAndroid Build Coastguard Worker                              Handle<mirror::Class> klass,
226*795d594fSAndroid Build Coastguard Worker                              uint32_t dex_pc,
227*795d594fSAndroid Build Coastguard Worker                              bool needs_access_check)
228*795d594fSAndroid Build Coastguard Worker       REQUIRES_SHARED(Locks::mutator_lock_);
229*795d594fSAndroid Build Coastguard Worker 
230*795d594fSAndroid Build Coastguard Worker   Handle<mirror::Class> ResolveClass(ScopedObjectAccess& soa, dex::TypeIndex type_index)
231*795d594fSAndroid Build Coastguard Worker       REQUIRES_SHARED(Locks::mutator_lock_);
232*795d594fSAndroid Build Coastguard Worker 
233*795d594fSAndroid Build Coastguard Worker   bool LoadClassNeedsAccessCheck(dex::TypeIndex type_index, ObjPtr<mirror::Class> klass)
234*795d594fSAndroid Build Coastguard Worker       REQUIRES_SHARED(Locks::mutator_lock_);
235*795d594fSAndroid Build Coastguard Worker 
236*795d594fSAndroid Build Coastguard Worker   // Builds a `HLoadMethodHandle` loading the given `method_handle_index`.
237*795d594fSAndroid Build Coastguard Worker   void BuildLoadMethodHandle(uint16_t method_handle_idx, uint32_t dex_pc);
238*795d594fSAndroid Build Coastguard Worker 
239*795d594fSAndroid Build Coastguard Worker   // Builds a `HLoadMethodType` loading the given `proto_index`.
240*795d594fSAndroid Build Coastguard Worker   void BuildLoadMethodType(dex::ProtoIndex proto_index, uint32_t dex_pc);
241*795d594fSAndroid Build Coastguard Worker 
242*795d594fSAndroid Build Coastguard Worker   void PotentiallySimplifyFakeString(uint16_t original_dex_register,
243*795d594fSAndroid Build Coastguard Worker                                      uint32_t dex_pc,
244*795d594fSAndroid Build Coastguard Worker                                      HInvoke* invoke);
245*795d594fSAndroid Build Coastguard Worker 
246*795d594fSAndroid Build Coastguard Worker   enum class ReceiverArg {
247*795d594fSAndroid Build Coastguard Worker     kNone,             // No receiver, static method.
248*795d594fSAndroid Build Coastguard Worker     kNullCheckedArg,   // Normal instance invoke, null check and pass the argument.
249*795d594fSAndroid Build Coastguard Worker     kNullCheckedOnly,  // Null check but do not use the arg, used for intrinsic replacements.
250*795d594fSAndroid Build Coastguard Worker     kPlainArg,         // Do not null check but pass the argument, used for unresolved methods.
251*795d594fSAndroid Build Coastguard Worker     kIgnored,          // No receiver despite allocated vreg, used for String.<init>.
252*795d594fSAndroid Build Coastguard Worker   };
253*795d594fSAndroid Build Coastguard Worker   bool SetupInvokeArguments(HInstruction* invoke,
254*795d594fSAndroid Build Coastguard Worker                             const InstructionOperands& operands,
255*795d594fSAndroid Build Coastguard Worker                             const char* shorty,
256*795d594fSAndroid Build Coastguard Worker                             ReceiverArg receiver_arg);
257*795d594fSAndroid Build Coastguard Worker 
258*795d594fSAndroid Build Coastguard Worker   bool HandleInvoke(HInvoke* invoke,
259*795d594fSAndroid Build Coastguard Worker                     const InstructionOperands& operands,
260*795d594fSAndroid Build Coastguard Worker                     const char* shorty,
261*795d594fSAndroid Build Coastguard Worker                     bool is_unresolved);
262*795d594fSAndroid Build Coastguard Worker 
263*795d594fSAndroid Build Coastguard Worker   bool HandleStringInit(HInvoke* invoke,
264*795d594fSAndroid Build Coastguard Worker                         const InstructionOperands& operands,
265*795d594fSAndroid Build Coastguard Worker                         const char* shorty);
266*795d594fSAndroid Build Coastguard Worker   void HandleStringInitResult(HInvokeStaticOrDirect* invoke);
267*795d594fSAndroid Build Coastguard Worker 
268*795d594fSAndroid Build Coastguard Worker   HClinitCheck* ProcessClinitCheckForInvoke(
269*795d594fSAndroid Build Coastguard Worker       uint32_t dex_pc,
270*795d594fSAndroid Build Coastguard Worker       ArtMethod* method,
271*795d594fSAndroid Build Coastguard Worker       HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement);
272*795d594fSAndroid Build Coastguard Worker 
273*795d594fSAndroid Build Coastguard Worker   // Try to build a replacement for an intrinsic invoke. Returns true on success,
274*795d594fSAndroid Build Coastguard Worker   // false on failure. Failure can be either lack of replacement HIR classes, or
275*795d594fSAndroid Build Coastguard Worker   // input register mismatch.
276*795d594fSAndroid Build Coastguard Worker   bool BuildSimpleIntrinsic(ArtMethod* method,
277*795d594fSAndroid Build Coastguard Worker                             uint32_t dex_pc,
278*795d594fSAndroid Build Coastguard Worker                             const InstructionOperands& operands,
279*795d594fSAndroid Build Coastguard Worker                             const char* shorty);
280*795d594fSAndroid Build Coastguard Worker 
281*795d594fSAndroid Build Coastguard Worker   // Build a HNewInstance instruction.
282*795d594fSAndroid Build Coastguard Worker   HNewInstance* BuildNewInstance(dex::TypeIndex type_index, uint32_t dex_pc);
283*795d594fSAndroid Build Coastguard Worker 
284*795d594fSAndroid Build Coastguard Worker   // Build a HConstructorFence for HNewInstance and HNewArray instructions. This ensures the
285*795d594fSAndroid Build Coastguard Worker   // happens-before ordering for default-initialization of the object referred to by new_instance.
286*795d594fSAndroid Build Coastguard Worker   void BuildConstructorFenceForAllocation(HInstruction* allocation);
287*795d594fSAndroid Build Coastguard Worker 
288*795d594fSAndroid Build Coastguard Worker   // Return whether the compiler can assume `cls` is initialized.
289*795d594fSAndroid Build Coastguard Worker   bool IsInitialized(ObjPtr<mirror::Class> cls) const
290*795d594fSAndroid Build Coastguard Worker       REQUIRES_SHARED(Locks::mutator_lock_);
291*795d594fSAndroid Build Coastguard Worker 
292*795d594fSAndroid Build Coastguard Worker   // Try to resolve a field using the class linker. Return null if it could not
293*795d594fSAndroid Build Coastguard Worker   // be found.
294*795d594fSAndroid Build Coastguard Worker   ArtField* ResolveField(uint16_t field_idx, bool is_static, bool is_put);
295*795d594fSAndroid Build Coastguard Worker 
296*795d594fSAndroid Build Coastguard Worker   ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_index,
297*795d594fSAndroid Build Coastguard Worker                                            const DexCompilationUnit& compilation_unit) const
298*795d594fSAndroid Build Coastguard Worker       REQUIRES_SHARED(Locks::mutator_lock_);
299*795d594fSAndroid Build Coastguard Worker 
300*795d594fSAndroid Build Coastguard Worker   ObjPtr<mirror::Class> LookupReferrerClass() const REQUIRES_SHARED(Locks::mutator_lock_);
301*795d594fSAndroid Build Coastguard Worker 
302*795d594fSAndroid Build Coastguard Worker   ArenaAllocator* const allocator_;
303*795d594fSAndroid Build Coastguard Worker   HGraph* const graph_;
304*795d594fSAndroid Build Coastguard Worker 
305*795d594fSAndroid Build Coastguard Worker   // The dex file where the method being compiled is, and the bytecode data.
306*795d594fSAndroid Build Coastguard Worker   const DexFile* const dex_file_;
307*795d594fSAndroid Build Coastguard Worker   const CodeItemDebugInfoAccessor code_item_accessor_;  // null for intrinsic graph.
308*795d594fSAndroid Build Coastguard Worker 
309*795d594fSAndroid Build Coastguard Worker   // The return type of the method being compiled.
310*795d594fSAndroid Build Coastguard Worker   const DataType::Type return_type_;
311*795d594fSAndroid Build Coastguard Worker 
312*795d594fSAndroid Build Coastguard Worker   HBasicBlockBuilder* const block_builder_;
313*795d594fSAndroid Build Coastguard Worker   SsaBuilder* const ssa_builder_;
314*795d594fSAndroid Build Coastguard Worker 
315*795d594fSAndroid Build Coastguard Worker   CodeGenerator* const code_generator_;
316*795d594fSAndroid Build Coastguard Worker 
317*795d594fSAndroid Build Coastguard Worker   // The compilation unit of the current method being compiled. Note that
318*795d594fSAndroid Build Coastguard Worker   // it can be an inlined method.
319*795d594fSAndroid Build Coastguard Worker   const DexCompilationUnit* const dex_compilation_unit_;
320*795d594fSAndroid Build Coastguard Worker 
321*795d594fSAndroid Build Coastguard Worker   // The compilation unit of the outermost method being compiled. That is the
322*795d594fSAndroid Build Coastguard Worker   // method being compiled (and not inlined), and potentially inlining other
323*795d594fSAndroid Build Coastguard Worker   // methods.
324*795d594fSAndroid Build Coastguard Worker   const DexCompilationUnit* const outer_compilation_unit_;
325*795d594fSAndroid Build Coastguard Worker 
326*795d594fSAndroid Build Coastguard Worker   OptimizingCompilerStats* const compilation_stats_;
327*795d594fSAndroid Build Coastguard Worker 
328*795d594fSAndroid Build Coastguard Worker   ScopedArenaAllocator* const local_allocator_;
329*795d594fSAndroid Build Coastguard Worker   ScopedArenaVector<ScopedArenaVector<HInstruction*>> locals_for_;
330*795d594fSAndroid Build Coastguard Worker   HBasicBlock* current_block_;
331*795d594fSAndroid Build Coastguard Worker   ScopedArenaVector<HInstruction*>* current_locals_;
332*795d594fSAndroid Build Coastguard Worker   HInstruction* latest_result_;
333*795d594fSAndroid Build Coastguard Worker   // Current "this" parameter.
334*795d594fSAndroid Build Coastguard Worker   // Valid only after InitializeParameters() finishes.
335*795d594fSAndroid Build Coastguard Worker   // * Null for static methods.
336*795d594fSAndroid Build Coastguard Worker   // * Non-null for instance methods.
337*795d594fSAndroid Build Coastguard Worker   HParameterValue* current_this_parameter_;
338*795d594fSAndroid Build Coastguard Worker 
339*795d594fSAndroid Build Coastguard Worker   ScopedArenaVector<HBasicBlock*> loop_headers_;
340*795d594fSAndroid Build Coastguard Worker 
341*795d594fSAndroid Build Coastguard Worker   // Cached resolved types for the current compilation unit's DexFile.
342*795d594fSAndroid Build Coastguard Worker   // Handle<>s reference entries in the `graph_->GetHandleCache()`.
343*795d594fSAndroid Build Coastguard Worker   ScopedArenaSafeMap<dex::TypeIndex, Handle<mirror::Class>> class_cache_;
344*795d594fSAndroid Build Coastguard Worker 
345*795d594fSAndroid Build Coastguard Worker   static constexpr int kDefaultNumberOfLoops = 2;
346*795d594fSAndroid Build Coastguard Worker 
347*795d594fSAndroid Build Coastguard Worker   DISALLOW_COPY_AND_ASSIGN(HInstructionBuilder);
348*795d594fSAndroid Build Coastguard Worker };
349*795d594fSAndroid Build Coastguard Worker 
350*795d594fSAndroid Build Coastguard Worker }  // namespace art
351*795d594fSAndroid Build Coastguard Worker 
352*795d594fSAndroid Build Coastguard Worker #endif  // ART_COMPILER_OPTIMIZING_INSTRUCTION_BUILDER_H_
353