blob: d874aaa829123e1ad28c29771f0d505bc85b240e [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_
18#define ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
20#include "dex/compiler_internals.h"
21#include "x86_lir.h"
22
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070023#include <map>
24
Brian Carlstrom7940e442013-07-12 13:46:57 -070025namespace art {
26
Mark Mendelle87f9b52014-04-30 14:13:18 -040027class X86Mir2Lir : public Mir2Lir {
Ian Rogers0f9b9c52014-06-09 01:32:12 -070028 protected:
29 class InToRegStorageMapper {
30 public:
31 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide) = 0;
32 virtual ~InToRegStorageMapper() {}
33 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070034
Ian Rogers0f9b9c52014-06-09 01:32:12 -070035 class InToRegStorageX86_64Mapper : public InToRegStorageMapper {
36 public:
37 InToRegStorageX86_64Mapper() : cur_core_reg_(0), cur_fp_reg_(0) {}
38 virtual ~InToRegStorageX86_64Mapper() {}
39 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide);
40 private:
41 int cur_core_reg_;
42 int cur_fp_reg_;
43 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070044
Ian Rogers0f9b9c52014-06-09 01:32:12 -070045 class InToRegStorageMapping {
46 public:
47 InToRegStorageMapping() : max_mapped_in_(0), is_there_stack_mapped_(false),
48 initialized_(false) {}
49 void Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper);
50 int GetMaxMappedIn() { return max_mapped_in_; }
51 bool IsThereStackMapped() { return is_there_stack_mapped_; }
52 RegStorage Get(int in_position);
53 bool IsInitialized() { return initialized_; }
54 private:
55 std::map<int, RegStorage> mapping_;
56 int max_mapped_in_;
57 bool is_there_stack_mapped_;
58 bool initialized_;
59 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070060
Ian Rogers0f9b9c52014-06-09 01:32:12 -070061 public:
62 X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena, bool gen64bit);
Brian Carlstrom7940e442013-07-12 13:46:57 -070063
Ian Rogers0f9b9c52014-06-09 01:32:12 -070064 // Required for target - codegen helpers.
65 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
66 RegLocation rl_dest, int lit);
67 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
68 LIR* CheckSuspendUsingLoad() OVERRIDE;
69 RegStorage LoadHelper(ThreadOffset<4> offset) OVERRIDE;
70 RegStorage LoadHelper(ThreadOffset<8> offset) OVERRIDE;
71 LIR* LoadBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest,
72 OpSize size) OVERRIDE;
73 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
74 OpSize size) OVERRIDE;
75 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010076 OpSize size) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070077 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
78 RegStorage r_dest, OpSize size) OVERRIDE;
79 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
80 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
81 LIR* StoreBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_src,
82 OpSize size) OVERRIDE;
83 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src,
84 OpSize size) OVERRIDE;
85 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
86 OpSize size) OVERRIDE;
87 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
88 RegStorage r_src, OpSize size) OVERRIDE;
89 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070090
Ian Rogers0f9b9c52014-06-09 01:32:12 -070091 // Required for target - register utilities.
92 RegStorage TargetReg(SpecialTargetRegister reg);
93 RegStorage GetArgMappingToPhysicalReg(int arg_num);
94 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
95 RegLocation GetReturnAlt();
96 RegLocation GetReturnWideAlt();
97 RegLocation LocCReturn();
98 RegLocation LocCReturnRef();
99 RegLocation LocCReturnDouble();
100 RegLocation LocCReturnFloat();
101 RegLocation LocCReturnWide();
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100102 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700103 void AdjustSpillMask();
104 void ClobberCallerSave();
105 void FreeCallTemps();
106 void LockCallTemps();
107 void MarkPreservedSingle(int v_reg, RegStorage reg);
108 void MarkPreservedDouble(int v_reg, RegStorage reg);
109 void CompilerInitializeRegAlloc();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700110
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700111 // Required for target - miscellaneous.
112 void AssembleLIR();
113 int AssignInsnOffsets();
114 void AssignOffsets();
115 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100116 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
117 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
118 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700119 const char* GetTargetInstFmt(int opcode);
120 const char* GetTargetInstName(int opcode);
121 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100122 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700123 uint64_t GetTargetInstFlags(int opcode);
Ian Rogers5aa6e042014-06-13 16:38:24 -0700124 size_t GetInsnSize(LIR* lir) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700125 bool IsUnconditionalBranch(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700126
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700127 // Check support for volatile load/store of a given size.
128 bool SupportsVolatileLoadStore(OpSize size) OVERRIDE;
129 // Get the register class for load/store of a field.
130 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100131
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700132 // Required for target - Dalvik-level generators.
133 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
buzbee2700f7e2014-03-07 09:46:20 -0800134 RegLocation rl_src2);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700135 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
136 RegLocation rl_dest, int scale);
137 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
138 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark);
139 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
140 RegLocation rl_src1, RegLocation rl_shift);
141 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
buzbee2700f7e2014-03-07 09:46:20 -0800142 RegLocation rl_src2);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700143 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
144 RegLocation rl_src2);
145 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
146 RegLocation rl_src2);
147 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
148 RegLocation rl_src2);
149 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
150 RegLocation rl_src2);
Alexei Zavjalovbd3682e2014-06-12 03:08:01 +0700151 void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700152 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
153 RegLocation rl_src2);
154 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
155 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
156 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
157 bool GenInlinedSqrt(CallInfo* info);
158 bool GenInlinedPeek(CallInfo* info, OpSize size);
159 bool GenInlinedPoke(CallInfo* info, OpSize size);
160 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
161 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
162 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
163 RegLocation rl_src2);
164 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
165 RegLocation rl_src2);
166 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
167 RegLocation rl_src2);
168 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
169 RegLocation rl_src2, bool is_div);
170 // TODO: collapse reg_lo, reg_hi
171 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
172 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
173 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
174 void GenDivZeroCheckWide(RegStorage reg);
175 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
176 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
177 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
178 void GenExitSequence();
179 void GenSpecialExitSequence();
180 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
181 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
182 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
183 void GenSelect(BasicBlock* bb, MIR* mir);
184 bool GenMemBarrier(MemBarrierKind barrier_kind);
185 void GenMoveException(RegLocation rl_dest);
186 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
187 int first_bit, int second_bit);
188 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
189 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
190 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
191 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
192 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800193
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700194 /*
195 * @brief Generate a two address long operation with a constant value
196 * @param rl_dest location of result
197 * @param rl_src constant source operand
198 * @param op Opcode to be generated
199 * @return success or not
200 */
201 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
202 /*
203 * @brief Generate a three address long operation with a constant value
204 * @param rl_dest location of result
205 * @param rl_src1 source operand
206 * @param rl_src2 constant source operand
207 * @param op Opcode to be generated
208 * @return success or not
209 */
210 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
211 Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800212
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700213 /**
214 * @brief Generate a long arithmetic operation.
215 * @param rl_dest The destination.
216 * @param rl_src1 First operand.
217 * @param rl_src2 Second operand.
218 * @param op The DEX opcode for the operation.
219 * @param is_commutative The sources can be swapped if needed.
220 */
221 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
222 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800223
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700224 /**
225 * @brief Generate a two operand long arithmetic operation.
226 * @param rl_dest The destination.
227 * @param rl_src Second operand.
228 * @param op The DEX opcode for the operation.
229 */
230 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800231
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700232 /**
233 * @brief Generate a long operation.
234 * @param rl_dest The destination. Must be in a register
235 * @param rl_src The other operand. May be in a register or in memory.
236 * @param op The DEX opcode for the operation.
237 */
238 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700239
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700240 /**
241 * @brief Implement instanceof a final class with x86 specific code.
242 * @param use_declaring_class 'true' if we can use the class itself.
243 * @param type_idx Type index to use if use_declaring_class is 'false'.
244 * @param rl_dest Result to be set to 0 or 1.
245 * @param rl_src Object to be tested.
246 */
247 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
248 RegLocation rl_src);
249 /*
250 *
251 * @brief Implement Set up instanceof a class with x86 specific code.
252 * @param needs_access_check 'true' if we must check the access.
253 * @param type_known_final 'true' if the type is known to be a final class.
254 * @param type_known_abstract 'true' if the type is known to be an abstract class.
255 * @param use_declaring_class 'true' if the type can be loaded off the current Method*.
256 * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache.
257 * @param type_idx Type index to use if use_declaring_class is 'false'.
258 * @param rl_dest Result to be set to 0 or 1.
259 * @param rl_src Object to be tested.
260 */
261 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
262 bool type_known_abstract, bool use_declaring_class,
263 bool can_assume_type_is_in_dex_cache,
264 uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src);
Mark Mendell6607d972014-02-10 06:54:18 -0800265
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700266 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
267 RegLocation rl_src1, RegLocation rl_shift);
Chao-ying Fua0147762014-06-06 18:38:49 -0700268
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700269 // Single operation generators.
270 LIR* OpUnconditionalBranch(LIR* target);
271 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
272 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
273 LIR* OpCondBranch(ConditionCode cc, LIR* target);
274 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
275 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
276 LIR* OpIT(ConditionCode cond, const char* guide);
277 void OpEndIT(LIR* it);
278 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
279 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
280 LIR* OpReg(OpKind op, RegStorage r_dest_src);
281 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
282 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
283 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
284 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
285 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
286 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
287 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
288 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
289 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
290 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
291 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
292 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
293 LIR* OpTestSuspend(LIR* target);
294 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
295 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
296 LIR* OpVldm(RegStorage r_base, int count);
297 LIR* OpVstm(RegStorage r_base, int count);
298 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
299 void OpRegCopyWide(RegStorage dest, RegStorage src);
300 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
301 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700302
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700303 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
304 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
305 void SpillCoreRegs();
306 void UnSpillCoreRegs();
307 static const X86EncodingMap EncodingMap[kX86Last];
308 bool InexpensiveConstantInt(int32_t value);
309 bool InexpensiveConstantFloat(int32_t value);
310 bool InexpensiveConstantLong(int64_t value);
311 bool InexpensiveConstantDouble(int64_t value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700312
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700313 /*
314 * @brief Should try to optimize for two address instructions?
315 * @return true if we try to avoid generating three operand instructions.
316 */
317 virtual bool GenerateTwoOperandInstructions() const { return true; }
Mark Mendelle87f9b52014-04-30 14:13:18 -0400318
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700319 /*
320 * @brief x86 specific codegen for int operations.
321 * @param opcode Operation to perform.
322 * @param rl_dest Destination for the result.
323 * @param rl_lhs Left hand operand.
324 * @param rl_rhs Right hand operand.
325 */
326 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
327 RegLocation rl_rhs);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800328
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700329 /*
330 * @brief Dump a RegLocation using printf
331 * @param loc Register location to dump
332 */
333 static void DumpRegLocation(RegLocation loc);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800334
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700335 /*
336 * @brief Load the Method* of a dex method into the register.
337 * @param target_method The MethodReference of the method to be invoked.
338 * @param type How the method will be invoked.
339 * @param register that will contain the code address.
340 * @note register will be passed to TargetReg to get physical register.
341 */
342 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
343 SpecialTargetRegister symbolic_reg);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800344
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700345 /*
346 * @brief Load the Class* of a Dex Class type into the register.
347 * @param type How the method will be invoked.
348 * @param register that will contain the code address.
349 * @note register will be passed to TargetReg to get physical register.
350 */
351 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800352
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700353 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700354
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700355 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700356 NextCallInsn next_call_insn,
357 const MethodReference& target_method,
358 uint32_t vtable_idx,
359 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
360 bool skip_this);
361
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700362 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
363 NextCallInsn next_call_insn,
364 const MethodReference& target_method,
365 uint32_t vtable_idx,
366 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
367 bool skip_this);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800368
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700369 /*
370 * @brief Generate a relative call to the method that will be patched at link time.
371 * @param target_method The MethodReference of the method to be invoked.
372 * @param type How the method will be invoked.
373 * @returns Call instruction
374 */
375 virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800376
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700377 /*
378 * @brief Handle x86 specific literals
379 */
380 void InstallLiteralPools();
Mark Mendellae9fd932014-02-10 16:14:35 -0800381
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700382 /*
383 * @brief Generate the debug_frame CFI information.
384 * @returns pointer to vector containing CFE information
385 */
386 static std::vector<uint8_t>* ReturnCommonCallFrameInformation();
Mark Mendellae9fd932014-02-10 16:14:35 -0800387
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700388 /*
389 * @brief Generate the debug_frame FDE information.
390 * @returns pointer to vector containing CFE information
391 */
392 std::vector<uint8_t>* ReturnCallFrameInformation();
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800393
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700394 protected:
395 size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700396 int32_t raw_base, int32_t displacement);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700397 void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg);
398 void EmitPrefix(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700399 int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700400 void EmitOpcode(const X86EncodingMap* entry);
401 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700402 int32_t reg_r, int32_t reg_x, int32_t reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700403 void EmitDisp(uint8_t base, int32_t disp);
404 void EmitModrmThread(uint8_t reg_or_opcode);
405 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp);
406 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale,
407 int32_t disp);
408 void EmitImm(const X86EncodingMap* entry, int64_t imm);
409 void EmitNullary(const X86EncodingMap* entry);
410 void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg);
411 void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg);
412 void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
413 void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
414 int32_t disp);
415 void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg);
416 void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp);
417 void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base,
418 int32_t raw_index, int scale, int32_t disp);
419 void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
420 int32_t disp, int32_t raw_reg);
421 void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
422 void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
423 int32_t raw_disp, int32_t imm);
424 void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp);
425 void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2);
426 void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm);
427 void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
428 int32_t imm);
429 void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1,
430 int32_t imm);
431 void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
432 void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm);
433 void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm);
434 void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
435 void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl);
436 void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl);
437 void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
438 void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc);
439 void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc);
440 void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc);
441 void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
442 int32_t cc);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800443
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700444 void EmitJmp(const X86EncodingMap* entry, int32_t rel);
445 void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc);
446 void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
447 void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp);
448 void EmitCallThread(const X86EncodingMap* entry, int32_t disp);
449 void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table,
450 int32_t raw_index, int scale, int32_t table_or_disp);
451 void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset);
452 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
453 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
454 int64_t val, ConditionCode ccode);
455 void GenConstWide(RegLocation rl_dest, int64_t value);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400456
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700457 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800458
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700459 /*
460 * @brief Ensure that a temporary register is byte addressable.
461 * @returns a temporary guarenteed to be byte addressable.
462 */
463 virtual RegStorage AllocateByteRegister();
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800464
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700465 /*
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700466 * @brief Check if a register is byte addressable.
467 * @returns true if a register is byte addressable.
468 */
469 bool IsByteRegister(RegStorage reg);
470
471 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700472 * @brief generate inline code for fast case of Strng.indexOf.
473 * @param info Call parameters
474 * @param zero_based 'true' if the index into the string is 0.
475 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
476 * generated.
477 */
478 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
Mark Mendelle87f9b52014-04-30 14:13:18 -0400479
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700480 /*
481 * @brief Load 128 bit constant into vector register.
482 * @param bb The basic block in which the MIR is from.
483 * @param mir The MIR whose opcode is kMirConstVector
484 * @note vA is the TypeSize for the register.
485 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
486 */
487 void GenConst128(BasicBlock* bb, MIR* mir);
Mark Mendell4028a6c2014-02-19 20:06:20 -0800488
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700489 /*
490 * @brief MIR to move a vectorized register to another.
491 * @param bb The basic block in which the MIR is from.
492 * @param mir The MIR whose opcode is kMirConstVector.
493 * @note vA: TypeSize
494 * @note vB: destination
495 * @note vC: source
496 */
497 void GenMoveVector(BasicBlock *bb, MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400498
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700499 /*
500 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know the type of the vector.
501 * @param bb The basic block in which the MIR is from.
502 * @param mir The MIR whose opcode is kMirConstVector.
503 * @note vA: TypeSize
504 * @note vB: destination and source
505 * @note vC: source
506 */
507 void GenMultiplyVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400508
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700509 /*
510 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the type of the vector.
511 * @param bb The basic block in which the MIR is from.
512 * @param mir The MIR whose opcode is kMirConstVector.
513 * @note vA: TypeSize
514 * @note vB: destination and source
515 * @note vC: source
516 */
517 void GenAddVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400518
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700519 /*
520 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the type of the vector.
521 * @param bb The basic block in which the MIR is from.
522 * @param mir The MIR whose opcode is kMirConstVector.
523 * @note vA: TypeSize
524 * @note vB: destination and source
525 * @note vC: source
526 */
527 void GenSubtractVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400528
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700529 /*
530 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the type of the vector.
531 * @param bb The basic block in which the MIR is from.
532 * @param mir The MIR whose opcode is kMirConstVector.
533 * @note vA: TypeSize
534 * @note vB: destination and source
535 * @note vC: immediate
536 */
537 void GenShiftLeftVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400538
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700539 /*
540 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to know the type of the vector.
541 * @param bb The basic block in which the MIR is from.
542 * @param mir The MIR whose opcode is kMirConstVector.
543 * @note vA: TypeSize
544 * @note vB: destination and source
545 * @note vC: immediate
546 */
547 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400548
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700549 /*
550 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA to know the type of the vector.
551 * @param bb The basic block in which the MIR is from..
552 * @param mir The MIR whose opcode is kMirConstVector.
553 * @note vA: TypeSize
554 * @note vB: destination and source
555 * @note vC: immediate
556 */
557 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400558
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700559 /*
560 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the type of the vector.
561 * @note vA: TypeSize
562 * @note vB: destination and source
563 * @note vC: source
564 */
565 void GenAndVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400566
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700567 /*
568 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the type of the vector.
569 * @param bb The basic block in which the MIR is from.
570 * @param mir The MIR whose opcode is kMirConstVector.
571 * @note vA: TypeSize
572 * @note vB: destination and source
573 * @note vC: source
574 */
575 void GenOrVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400576
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700577 /*
578 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the type of the vector.
579 * @param bb The basic block in which the MIR is from.
580 * @param mir The MIR whose opcode is kMirConstVector.
581 * @note vA: TypeSize
582 * @note vB: destination and source
583 * @note vC: source
584 */
585 void GenXorVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400586
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700587 /*
588 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
589 * @param bb The basic block in which the MIR is from.
590 * @param mir The MIR whose opcode is kMirConstVector.
591 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
592 * @note vA: TypeSize
593 * @note vB: destination and source VR (not vector register)
594 * @note vC: source (vector register)
595 */
596 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400597
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700598 /*
599 * @brief Extract a packed element into a single VR.
600 * @param bb The basic block in which the MIR is from.
601 * @param mir The MIR whose opcode is kMirConstVector.
602 * @note vA: TypeSize
603 * @note vB: destination VR (not vector register)
604 * @note vC: source (vector register)
605 * @note arg[0]: The index to use for extraction from vector register (which packed element).
606 */
607 void GenReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400608
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700609 /*
610 * @brief Create a vector value, with all TypeSize values equal to vC
611 * @param bb The basic block in which the MIR is from.
612 * @param mir The MIR whose opcode is kMirConstVector.
613 * @note vA: TypeSize.
614 * @note vB: destination vector register.
615 * @note vC: source VR (not vector register).
616 */
617 void GenSetVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400618
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700619 /*
620 * @brief Generate code for a vector opcode.
621 * @param bb The basic block in which the MIR is from.
622 * @param mir The MIR whose opcode is a non-standard opcode.
623 */
624 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400625
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700626 /*
627 * @brief Return the correct x86 opcode for the Dex operation
628 * @param op Dex opcode for the operation
629 * @param loc Register location of the operand
630 * @param is_high_op 'true' if this is an operation on the high word
631 * @param value Immediate value for the operation. Used for byte variants
632 * @returns the correct x86 opcode to perform the operation
633 */
634 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400635
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700636 /*
637 * @brief Return the correct x86 opcode for the Dex operation
638 * @param op Dex opcode for the operation
639 * @param dest location of the destination. May be register or memory.
640 * @param rhs Location for the rhs of the operation. May be in register or memory.
641 * @param is_high_op 'true' if this is an operation on the high word
642 * @returns the correct x86 opcode to perform the operation
643 * @note at most one location may refer to memory
644 */
645 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
646 bool is_high_op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800647
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700648 /*
649 * @brief Is this operation a no-op for this opcode and value
650 * @param op Dex opcode for the operation
651 * @param value Immediate value for the operation.
652 * @returns 'true' if the operation will have no effect
653 */
654 bool IsNoOp(Instruction::Code op, int32_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800655
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700656 /**
657 * @brief Calculate magic number and shift for a given divisor
658 * @param divisor divisor number for calculation
659 * @param magic hold calculated magic number
660 * @param shift hold calculated shift
661 */
662 void CalculateMagicAndShift(int divisor, int& magic, int& shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800663
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700664 /*
665 * @brief Generate an integer div or rem operation.
666 * @param rl_dest Destination Location.
667 * @param rl_src1 Numerator Location.
668 * @param rl_src2 Divisor Location.
669 * @param is_div 'true' if this is a division, 'false' for a remainder.
670 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
671 */
672 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
673 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800674
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700675 /*
676 * @brief Generate an integer div or rem operation by a literal.
677 * @param rl_dest Destination Location.
678 * @param rl_src Numerator Location.
679 * @param lit Divisor.
680 * @param is_div 'true' if this is a division, 'false' for a remainder.
681 */
682 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800683
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700684 /*
685 * Generate code to implement long shift operations.
686 * @param opcode The DEX opcode to specify the shift type.
687 * @param rl_dest The destination.
688 * @param rl_src The value to be shifted.
689 * @param shift_amount How much to shift.
690 * @returns the RegLocation of the result.
691 */
692 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
693 RegLocation rl_src, int shift_amount);
694 /*
695 * Generate an imul of a register by a constant or a better sequence.
696 * @param dest Destination Register.
697 * @param src Source Register.
698 * @param val Constant multiplier.
699 */
700 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800701
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700702 /*
703 * Generate an imul of a memory location by a constant or a better sequence.
704 * @param dest Destination Register.
705 * @param sreg Symbolic register.
706 * @param displacement Displacement on stack of Symbolic Register.
707 * @param val Constant multiplier.
708 */
709 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800710
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700711 /*
712 * @brief Compare memory to immediate, and branch if condition true.
713 * @param cond The condition code that when true will branch to the target.
714 * @param temp_reg A temporary register that can be used if compare memory is not
715 * supported by the architecture.
716 * @param base_reg The register holding the base address.
717 * @param offset The offset from the base.
718 * @param check_value The immediate to compare to.
719 */
720 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
721 int offset, int check_value, LIR* target);
Mark Mendell766e9292014-01-27 07:55:47 -0800722
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700723 /*
724 * Can this operation be using core registers without temporaries?
725 * @param rl_lhs Left hand operand.
726 * @param rl_rhs Right hand operand.
727 * @returns 'true' if the operation can proceed without needing temporary regs.
728 */
729 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800730
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700731 /**
732 * @brief Generates inline code for conversion of long to FP by using x87/
733 * @param rl_dest The destination of the FP.
734 * @param rl_src The source of the long.
735 * @param is_double 'true' if dealing with double, 'false' for float.
736 */
737 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Mark Mendell67c39c42014-01-31 17:28:00 -0800738
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700739 /*
740 * @brief Perform MIR analysis before compiling method.
741 * @note Invokes Mir2LiR::Materialize after analysis.
742 */
743 void Materialize();
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800744
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700745 /*
746 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
747 * without regard to data type. In practice, this can result in UpdateLoc returning a
748 * location record for a Dalvik float value in a core register, and vis-versa. For targets
749 * which can inexpensively move data between core and float registers, this can often be a win.
750 * However, for x86 this is generally not a win. These variants of UpdateLoc()
751 * take a register class argument - and will return an in-register location record only if
752 * the value is live in a temp register of the correct class. Additionally, if the value is in
753 * a temp register of the wrong register class, it will be clobbered.
754 */
755 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
756 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
Mark Mendell67c39c42014-01-31 17:28:00 -0800757
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700758 /*
759 * @brief Analyze MIR before generating code, to prepare for the code generation.
760 */
761 void AnalyzeMIR();
buzbee30adc732014-05-09 15:10:18 -0700762
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700763 /*
764 * @brief Analyze one basic block.
765 * @param bb Basic block to analyze.
766 */
767 void AnalyzeBB(BasicBlock * bb);
Mark Mendell67c39c42014-01-31 17:28:00 -0800768
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700769 /*
770 * @brief Analyze one extended MIR instruction
771 * @param opcode MIR instruction opcode.
772 * @param bb Basic block containing instruction.
773 * @param mir Extended instruction to analyze.
774 */
775 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800776
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700777 /*
778 * @brief Analyze one MIR instruction
779 * @param opcode MIR instruction opcode.
780 * @param bb Basic block containing instruction.
781 * @param mir Instruction to analyze.
782 */
783 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800784
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700785 /*
786 * @brief Analyze one MIR float/double instruction
787 * @param opcode MIR instruction opcode.
788 * @param bb Basic block containing instruction.
789 * @param mir Instruction to analyze.
790 */
791 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800792
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700793 /*
794 * @brief Analyze one use of a double operand.
795 * @param rl_use Double RegLocation for the operand.
796 */
797 void AnalyzeDoubleUse(RegLocation rl_use);
Mark Mendell67c39c42014-01-31 17:28:00 -0800798
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700799 bool Gen64Bit() const { return gen64bit_; }
Mark Mendell67c39c42014-01-31 17:28:00 -0800800
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700801 // Information derived from analysis of MIR
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700802
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700803 // The compiler temporary for the code address of the method.
804 CompilerTemp *base_of_code_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800805
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700806 // Have we decided to compute a ptr to code and store in temporary VR?
807 bool store_method_addr_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800808
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700809 // Have we used the stored method address?
810 bool store_method_addr_used_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800811
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700812 // Instructions to remove if we didn't use the stored method address.
813 LIR* setup_method_address_[2];
Mark Mendell55d0eac2014-02-06 11:02:52 -0800814
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700815 // Instructions needing patching with Method* values.
816 GrowableArray<LIR*> method_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800817
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700818 // Instructions needing patching with Class Type* values.
819 GrowableArray<LIR*> class_type_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800820
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700821 // Instructions needing patching with PC relative code addresses.
822 GrowableArray<LIR*> call_method_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800823
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700824 // Prologue decrement of stack pointer.
825 LIR* stack_decrement_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800826
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700827 // Epilogue increment of stack pointer.
828 LIR* stack_increment_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800829
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700830 // 64-bit mode
831 bool gen64bit_;
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700832
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700833 // The list of const vector literals.
834 LIR *const_vectors_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400835
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700836 /*
837 * @brief Search for a matching vector literal
838 * @param mir A kMirOpConst128b MIR instruction to match.
839 * @returns pointer to matching LIR constant, or nullptr if not found.
840 */
841 LIR *ScanVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400842
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700843 /*
844 * @brief Add a constant vector literal
845 * @param mir A kMirOpConst128b MIR instruction to match.
846 */
847 LIR *AddVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400848
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700849 InToRegStorageMapping in_to_reg_storage_mapping_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700850};
851
852} // namespace art
853
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700854#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_