blob: 38d60d2b542ab7d92e9077df957b72962c2271c9 [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 {
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070028 protected:
29 class InToRegStorageMapper {
30 public:
31 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide) = 0;
32 virtual ~InToRegStorageMapper() {}
33 };
34
35 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 };
44
45 class InToRegStorageMapping {
46 public:
47 InToRegStorageMapping() : initialized_(false) {}
48 void Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper);
49 int GetMaxMappedIn() { return max_mapped_in_; }
50 bool IsThereStackMapped() { return is_there_stack_mapped_; }
51 RegStorage Get(int in_position);
52 bool IsInitialized() { return initialized_; }
53 private:
54 std::map<int, RegStorage> mapping_;
55 int max_mapped_in_;
56 bool is_there_stack_mapped_;
57 bool initialized_;
58 };
59
Brian Carlstrom7940e442013-07-12 13:46:57 -070060 public:
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +070061 X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena, bool gen64bit);
Brian Carlstrom7940e442013-07-12 13:46:57 -070062
63 // Required for target - codegen helpers.
buzbee11b63d12013-08-27 07:34:17 -070064 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
buzbee2700f7e2014-03-07 09:46:20 -080065 RegLocation rl_dest, int lit);
Ian Rogerse2143c02014-03-28 08:47:16 -070066 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
Dave Allisonb373e092014-02-20 16:06:36 -080067 LIR* CheckSuspendUsingLoad() OVERRIDE;
Andreas Gampe2f244e92014-05-08 03:35:25 -070068 RegStorage LoadHelper(ThreadOffset<4> offset) OVERRIDE;
69 RegStorage LoadHelper(ThreadOffset<8> offset) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +010070 LIR* LoadBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest,
71 OpSize size) OVERRIDE;
Vladimir Marko3bf7c602014-05-07 14:55:43 +010072 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
73 OpSize size) OVERRIDE;
buzbee2700f7e2014-03-07 09:46:20 -080074 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010075 OpSize size) OVERRIDE;
buzbee2700f7e2014-03-07 09:46:20 -080076 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010077 RegStorage r_dest, OpSize size) OVERRIDE;
buzbee2700f7e2014-03-07 09:46:20 -080078 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
79 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
Vladimir Marko674744e2014-04-24 15:18:26 +010080 LIR* StoreBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_src,
81 OpSize size) OVERRIDE;
Vladimir Marko3bf7c602014-05-07 14:55:43 +010082 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src,
83 OpSize size) OVERRIDE;
buzbee2700f7e2014-03-07 09:46:20 -080084 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010085 OpSize size) OVERRIDE;
buzbee2700f7e2014-03-07 09:46:20 -080086 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010087 RegStorage r_src, OpSize size) OVERRIDE;
buzbee2700f7e2014-03-07 09:46:20 -080088 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070089
90 // Required for target - register utilities.
buzbee2700f7e2014-03-07 09:46:20 -080091 RegStorage TargetReg(SpecialTargetRegister reg);
92 RegStorage GetArgMappingToPhysicalReg(int arg_num);
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070093 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
Brian Carlstrom7940e442013-07-12 13:46:57 -070094 RegLocation GetReturnAlt();
95 RegLocation GetReturnWideAlt();
96 RegLocation LocCReturn();
buzbeea0cd2d72014-06-01 09:33:49 -070097 RegLocation LocCReturnRef();
Brian Carlstrom7940e442013-07-12 13:46:57 -070098 RegLocation LocCReturnDouble();
99 RegLocation LocCReturnFloat();
100 RegLocation LocCReturnWide();
buzbee091cc402014-03-31 10:14:40 -0700101 uint64_t GetRegMaskCommon(RegStorage reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700102 void AdjustSpillMask();
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000103 void ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104 void FreeCallTemps();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700105 void LockCallTemps();
buzbee091cc402014-03-31 10:14:40 -0700106 void MarkPreservedSingle(int v_reg, RegStorage reg);
107 void MarkPreservedDouble(int v_reg, RegStorage reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700108 void CompilerInitializeRegAlloc();
109
110 // Required for target - miscellaneous.
buzbeeb48819d2013-09-14 16:15:25 -0700111 void AssembleLIR();
112 int AssignInsnOffsets();
113 void AssignOffsets();
buzbee0d829482013-10-11 15:24:55 -0700114 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700115 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
buzbeeb48819d2013-09-14 16:15:25 -0700116 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700117 const char* GetTargetInstFmt(int opcode);
118 const char* GetTargetInstName(int opcode);
119 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
120 uint64_t GetPCUseDefEncoding();
121 uint64_t GetTargetInstFlags(int opcode);
122 int GetInsnSize(LIR* lir);
123 bool IsUnconditionalBranch(LIR* lir);
124
Vladimir Marko674744e2014-04-24 15:18:26 +0100125 // Check support for volatile load/store of a given size.
126 bool SupportsVolatileLoadStore(OpSize size) OVERRIDE;
127 // Get the register class for load/store of a field.
128 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
129
Brian Carlstrom7940e442013-07-12 13:46:57 -0700130 // Required for target - Dalvik-level generators.
buzbee2700f7e2014-03-07 09:46:20 -0800131 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
132 RegLocation rl_src2);
133 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
134 RegLocation rl_dest, int scale);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700135 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -0700136 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700137 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
Ian Rogersa9a82542013-10-04 11:17:26 -0700138 RegLocation rl_src1, RegLocation rl_shift);
buzbee2700f7e2014-03-07 09:46:20 -0800139 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
140 RegLocation rl_src2);
141 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
142 RegLocation rl_src2);
143 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
144 RegLocation rl_src2);
145 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700146 RegLocation rl_src2);
buzbee2700f7e2014-03-07 09:46:20 -0800147 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
148 RegLocation rl_src2);
149 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
150 RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700151 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
Vladimir Marko1c282e22013-11-21 14:49:47 +0000152 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700153 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
154 bool GenInlinedSqrt(CallInfo* info);
Vladimir Markoe508a202013-11-04 15:24:22 +0000155 bool GenInlinedPeek(CallInfo* info, OpSize size);
156 bool GenInlinedPoke(CallInfo* info, OpSize size);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100157 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700158 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
buzbee2700f7e2014-03-07 09:46:20 -0800159 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
160 RegLocation rl_src2);
161 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
162 RegLocation rl_src2);
163 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
164 RegLocation rl_src2);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100165 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
166 RegLocation rl_src2, bool is_div);
buzbee2700f7e2014-03-07 09:46:20 -0800167 // TODO: collapse reg_lo, reg_hi
168 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
169 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700170 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Mingyao Yange643a172014-04-08 11:02:52 -0700171 void GenDivZeroCheckWide(RegStorage reg);
Mingyao Yang80365d92014-04-18 12:10:58 -0700172 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
173 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700174 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
175 void GenExitSequence();
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800176 void GenSpecialExitSequence();
buzbee0d829482013-10-11 15:24:55 -0700177 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700178 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
179 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
180 void GenSelect(BasicBlock* bb, MIR* mir);
Andreas Gampeb14329f2014-05-15 11:16:06 -0700181 bool GenMemBarrier(MemBarrierKind barrier_kind);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700182 void GenMoveException(RegLocation rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800183 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
184 int first_bit, int second_bit);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700185 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
186 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
buzbee0d829482013-10-11 15:24:55 -0700187 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
188 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Chao-ying Fua0147762014-06-06 18:38:49 -0700189 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800190
Mark Mendelle02d48f2014-01-15 11:19:23 -0800191 /*
192 * @brief Generate a two address long operation with a constant value
193 * @param rl_dest location of result
194 * @param rl_src constant source operand
195 * @param op Opcode to be generated
Chao-ying Fua0147762014-06-06 18:38:49 -0700196 * @return success or not
Mark Mendelle02d48f2014-01-15 11:19:23 -0800197 */
Chao-ying Fua0147762014-06-06 18:38:49 -0700198 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800199 /*
200 * @brief Generate a three address long operation with a constant value
201 * @param rl_dest location of result
202 * @param rl_src1 source operand
203 * @param rl_src2 constant source operand
204 * @param op Opcode to be generated
Chao-ying Fua0147762014-06-06 18:38:49 -0700205 * @return success or not
Mark Mendelle02d48f2014-01-15 11:19:23 -0800206 */
Chao-ying Fua0147762014-06-06 18:38:49 -0700207 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
buzbee2700f7e2014-03-07 09:46:20 -0800208 Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800209
210 /**
211 * @brief Generate a long arithmetic operation.
212 * @param rl_dest The destination.
213 * @param rl_src1 First operand.
214 * @param rl_src2 Second operand.
215 * @param op The DEX opcode for the operation.
216 * @param is_commutative The sources can be swapped if needed.
217 */
Mark Mendelle87f9b52014-04-30 14:13:18 -0400218 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
219 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800220
221 /**
222 * @brief Generate a two operand long arithmetic operation.
223 * @param rl_dest The destination.
224 * @param rl_src Second operand.
225 * @param op The DEX opcode for the operation.
226 */
227 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
228
229 /**
230 * @brief Generate a long operation.
231 * @param rl_dest The destination. Must be in a register
232 * @param rl_src The other operand. May be in a register or in memory.
233 * @param op The DEX opcode for the operation.
234 */
Mark Mendelle87f9b52014-04-30 14:13:18 -0400235 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700236
Mark Mendelldf8ee2e2014-01-27 16:37:47 -0800237 /**
238 * @brief Implement instanceof a final class with x86 specific code.
239 * @param use_declaring_class 'true' if we can use the class itself.
240 * @param type_idx Type index to use if use_declaring_class is 'false'.
241 * @param rl_dest Result to be set to 0 or 1.
242 * @param rl_src Object to be tested.
243 */
buzbee2700f7e2014-03-07 09:46:20 -0800244 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
245 RegLocation rl_src);
Mark Mendell6607d972014-02-10 06:54:18 -0800246 /*
247 *
248 * @brief Implement Set up instanceof a class with x86 specific code.
249 * @param needs_access_check 'true' if we must check the access.
250 * @param type_known_final 'true' if the type is known to be a final class.
251 * @param type_known_abstract 'true' if the type is known to be an abstract class.
252 * @param use_declaring_class 'true' if the type can be loaded off the current Method*.
253 * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache.
254 * @param type_idx Type index to use if use_declaring_class is 'false'.
255 * @param rl_dest Result to be set to 0 or 1.
256 * @param rl_src Object to be tested.
257 */
258 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
259 bool type_known_abstract, bool use_declaring_class,
260 bool can_assume_type_is_in_dex_cache,
buzbee2700f7e2014-03-07 09:46:20 -0800261 uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src);
Mark Mendell6607d972014-02-10 06:54:18 -0800262
Chao-ying Fua0147762014-06-06 18:38:49 -0700263 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
264 RegLocation rl_src1, RegLocation rl_shift);
265
Brian Carlstrom7940e442013-07-12 13:46:57 -0700266 // Single operation generators.
267 LIR* OpUnconditionalBranch(LIR* target);
buzbee2700f7e2014-03-07 09:46:20 -0800268 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
269 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700270 LIR* OpCondBranch(ConditionCode cc, LIR* target);
buzbee2700f7e2014-03-07 09:46:20 -0800271 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
272 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700273 LIR* OpIT(ConditionCode cond, const char* guide);
Dave Allison3da67a52014-04-02 17:03:45 -0700274 void OpEndIT(LIR* it);
buzbee2700f7e2014-03-07 09:46:20 -0800275 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
276 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
277 LIR* OpReg(OpKind op, RegStorage r_dest_src);
buzbee7a11ab02014-04-28 20:02:38 -0700278 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
buzbee2700f7e2014-03-07 09:46:20 -0800279 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
280 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
281 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
282 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800283 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
buzbee2700f7e2014-03-07 09:46:20 -0800284 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
285 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
286 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
287 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
288 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
289 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700290 LIR* OpTestSuspend(LIR* target);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700291 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
292 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
buzbee2700f7e2014-03-07 09:46:20 -0800293 LIR* OpVldm(RegStorage r_base, int count);
294 LIR* OpVstm(RegStorage r_base, int count);
295 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
296 void OpRegCopyWide(RegStorage dest, RegStorage src);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700297 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
298 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700299
buzbee091cc402014-03-31 10:14:40 -0700300 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700301 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700302 void SpillCoreRegs();
303 void UnSpillCoreRegs();
304 static const X86EncodingMap EncodingMap[kX86Last];
305 bool InexpensiveConstantInt(int32_t value);
306 bool InexpensiveConstantFloat(int32_t value);
307 bool InexpensiveConstantLong(int64_t value);
308 bool InexpensiveConstantDouble(int64_t value);
309
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800310 /*
Mark Mendelle87f9b52014-04-30 14:13:18 -0400311 * @brief Should try to optimize for two address instructions?
312 * @return true if we try to avoid generating three operand instructions.
313 */
314 virtual bool GenerateTwoOperandInstructions() const { return true; }
315
316 /*
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800317 * @brief x86 specific codegen for int operations.
318 * @param opcode Operation to perform.
319 * @param rl_dest Destination for the result.
320 * @param rl_lhs Left hand operand.
321 * @param rl_rhs Right hand operand.
322 */
buzbee2700f7e2014-03-07 09:46:20 -0800323 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
324 RegLocation rl_rhs);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800325
Mark Mendell55d0eac2014-02-06 11:02:52 -0800326 /*
327 * @brief Dump a RegLocation using printf
328 * @param loc Register location to dump
329 */
330 static void DumpRegLocation(RegLocation loc);
331
332 /*
333 * @brief Load the Method* of a dex method into the register.
Jeff Hao49161ce2014-03-12 11:05:25 -0700334 * @param target_method The MethodReference of the method to be invoked.
Mark Mendell55d0eac2014-02-06 11:02:52 -0800335 * @param type How the method will be invoked.
336 * @param register that will contain the code address.
337 * @note register will be passed to TargetReg to get physical register.
338 */
Jeff Hao49161ce2014-03-12 11:05:25 -0700339 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
Mark Mendell55d0eac2014-02-06 11:02:52 -0800340 SpecialTargetRegister symbolic_reg);
341
342 /*
343 * @brief Load the Class* of a Dex Class type into the register.
344 * @param type How the method will be invoked.
345 * @param register that will contain the code address.
346 * @note register will be passed to TargetReg to get physical register.
347 */
348 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg);
349
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700350 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
351
352 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
353 NextCallInsn next_call_insn,
354 const MethodReference& target_method,
355 uint32_t vtable_idx,
356 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
357 bool skip_this);
358
359 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
360 NextCallInsn next_call_insn,
361 const MethodReference& target_method,
362 uint32_t vtable_idx,
363 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
364 bool skip_this);
365
Mark Mendell55d0eac2014-02-06 11:02:52 -0800366 /*
367 * @brief Generate a relative call to the method that will be patched at link time.
Jeff Hao49161ce2014-03-12 11:05:25 -0700368 * @param target_method The MethodReference of the method to be invoked.
Mark Mendell55d0eac2014-02-06 11:02:52 -0800369 * @param type How the method will be invoked.
370 * @returns Call instruction
371 */
Mark Mendelle87f9b52014-04-30 14:13:18 -0400372 virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800373
374 /*
375 * @brief Handle x86 specific literals
376 */
377 void InstallLiteralPools();
378
Mark Mendellae9fd932014-02-10 16:14:35 -0800379 /*
380 * @brief Generate the debug_frame CFI information.
381 * @returns pointer to vector containing CFE information
382 */
383 static std::vector<uint8_t>* ReturnCommonCallFrameInformation();
384
385 /*
386 * @brief Generate the debug_frame FDE information.
387 * @returns pointer to vector containing CFE information
388 */
389 std::vector<uint8_t>* ReturnCallFrameInformation();
390
Mark Mendelle87f9b52014-04-30 14:13:18 -0400391 protected:
Dmitry Petrochenkoa20468c2014-04-30 13:40:19 +0700392 size_t ComputeSize(const X86EncodingMap* entry, int base, int displacement,
393 int reg_r, int reg_x, bool has_sib);
394 uint8_t LowRegisterBits(uint8_t reg);
395 bool NeedsRex(uint8_t reg);
Vladimir Marko057c74a2013-12-03 15:20:45 +0000396 void EmitPrefix(const X86EncodingMap* entry);
Dmitry Petrochenkoa20468c2014-04-30 13:40:19 +0700397 void EmitPrefix(const X86EncodingMap* entry, uint8_t reg_r, uint8_t reg_x, uint8_t reg_b);
Vladimir Marko057c74a2013-12-03 15:20:45 +0000398 void EmitOpcode(const X86EncodingMap* entry);
399 void EmitPrefixAndOpcode(const X86EncodingMap* entry);
Dmitry Petrochenkoa20468c2014-04-30 13:40:19 +0700400 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
401 uint8_t reg_r, uint8_t reg_x, uint8_t reg_b);
Vladimir Marko057c74a2013-12-03 15:20:45 +0000402 void EmitDisp(uint8_t base, int disp);
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700403 void EmitModrmThread(uint8_t reg_or_opcode);
Vladimir Marko057c74a2013-12-03 15:20:45 +0000404 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int disp);
405 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale, int disp);
Dmitry Petrochenko96992e82014-05-20 04:03:46 +0700406 void EmitImm(const X86EncodingMap* entry, int64_t imm);
Vladimir Markoa8b4caf2013-10-24 15:08:57 +0100407 void EmitOpRegOpcode(const X86EncodingMap* entry, uint8_t reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700408 void EmitOpReg(const X86EncodingMap* entry, uint8_t reg);
409 void EmitOpMem(const X86EncodingMap* entry, uint8_t base, int disp);
buzbee2700f7e2014-03-07 09:46:20 -0800410 void EmitOpArray(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700411 void EmitMemReg(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg);
Mark Mendell343adb52013-12-18 06:02:17 -0800412 void EmitMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700413 void EmitRegMem(const X86EncodingMap* entry, uint8_t reg, uint8_t base, int disp);
414 void EmitRegArray(const X86EncodingMap* entry, uint8_t reg, uint8_t base, uint8_t index,
415 int scale, int disp);
416 void EmitArrayReg(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp,
417 uint8_t reg);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400418 void EmitArrayImm(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp,
419 int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700420 void EmitRegThread(const X86EncodingMap* entry, uint8_t reg, int disp);
421 void EmitRegReg(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2);
422 void EmitRegRegImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800423 void EmitRegRegImmRev(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm);
buzbee2700f7e2014-03-07 09:46:20 -0800424 void EmitRegMemImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int disp,
425 int32_t imm);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400426 void EmitMemRegImm(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg1, int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700427 void EmitRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
428 void EmitThreadImm(const X86EncodingMap* entry, int disp, int imm);
Dmitry Petrochenko96992e82014-05-20 04:03:46 +0700429 void EmitMovRegImm(const X86EncodingMap* entry, uint8_t reg, int64_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700430 void EmitShiftRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400431 void EmitShiftMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int imm);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800432 void EmitShiftMemCl(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t cl);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700433 void EmitShiftRegCl(const X86EncodingMap* entry, uint8_t reg, uint8_t cl);
434 void EmitRegCond(const X86EncodingMap* entry, uint8_t reg, uint8_t condition);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400435 void EmitMemCond(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t condition);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800436
437 /**
438 * @brief Used for encoding conditional register to register operation.
439 * @param entry The entry in the encoding map for the opcode.
440 * @param reg1 The first physical register.
441 * @param reg2 The second physical register.
442 * @param condition The condition code for operation.
443 */
444 void EmitRegRegCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, uint8_t condition);
445
Mark Mendell2637f2e2014-04-30 10:10:47 -0400446 /**
447 * @brief Used for encoding conditional register to memory operation.
448 * @param entry The entry in the encoding map for the opcode.
449 * @param reg1 The first physical register.
450 * @param base The memory base register.
451 * @param displacement The memory displacement.
452 * @param condition The condition code for operation.
453 */
454 void EmitRegMemCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int displacement, uint8_t condition);
455
Brian Carlstrom7940e442013-07-12 13:46:57 -0700456 void EmitJmp(const X86EncodingMap* entry, int rel);
457 void EmitJcc(const X86EncodingMap* entry, int rel, uint8_t cc);
458 void EmitCallMem(const X86EncodingMap* entry, uint8_t base, int disp);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800459 void EmitCallImmediate(const X86EncodingMap* entry, int disp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700460 void EmitCallThread(const X86EncodingMap* entry, int disp);
461 void EmitPcRel(const X86EncodingMap* entry, uint8_t reg, int base_or_table, uint8_t index,
462 int scale, int table_or_disp);
463 void EmitMacro(const X86EncodingMap* entry, uint8_t reg, int offset);
464 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
Mark Mendell412d4f82013-12-18 13:32:36 -0800465 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
466 int64_t val, ConditionCode ccode);
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000467 void GenConstWide(RegLocation rl_dest, int64_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800468
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800469 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
470
Mark Mendelle02d48f2014-01-15 11:19:23 -0800471 /*
Mark Mendelle87f9b52014-04-30 14:13:18 -0400472 * @brief Ensure that a temporary register is byte addressable.
473 * @returns a temporary guarenteed to be byte addressable.
474 */
475 virtual RegStorage AllocateByteRegister();
476
477 /*
Mark Mendell4028a6c2014-02-19 20:06:20 -0800478 * @brief generate inline code for fast case of Strng.indexOf.
479 * @param info Call parameters
480 * @param zero_based 'true' if the index into the string is 0.
481 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
482 * generated.
483 */
484 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
485
486 /*
Mark Mendelld65c51a2014-04-29 16:55:20 -0400487 * @brief Load 128 bit constant into vector register.
488 * @param bb The basic block in which the MIR is from.
489 * @param mir The MIR whose opcode is kMirConstVector
490 * @note vA is the TypeSize for the register.
491 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
492 */
493 void GenConst128(BasicBlock* bb, MIR* mir);
494
495 /*
Mark Mendellfe945782014-05-22 09:52:36 -0400496 * @brief MIR to move a vectorized register to another.
497 * @param bb The basic block in which the MIR is from.
498 * @param mir The MIR whose opcode is kMirConstVector.
499 * @note vA: TypeSize
500 * @note vB: destination
501 * @note vC: source
502 */
503 void GenMoveVector(BasicBlock *bb, MIR *mir);
504
505 /*
506 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know the type of the vector.
507 * @param bb The basic block in which the MIR is from.
508 * @param mir The MIR whose opcode is kMirConstVector.
509 * @note vA: TypeSize
510 * @note vB: destination and source
511 * @note vC: source
512 */
513 void GenMultiplyVector(BasicBlock *bb, MIR *mir);
514
515 /*
516 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the type of the vector.
517 * @param bb The basic block in which the MIR is from.
518 * @param mir The MIR whose opcode is kMirConstVector.
519 * @note vA: TypeSize
520 * @note vB: destination and source
521 * @note vC: source
522 */
523 void GenAddVector(BasicBlock *bb, MIR *mir);
524
525 /*
526 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the type of the vector.
527 * @param bb The basic block in which the MIR is from.
528 * @param mir The MIR whose opcode is kMirConstVector.
529 * @note vA: TypeSize
530 * @note vB: destination and source
531 * @note vC: source
532 */
533 void GenSubtractVector(BasicBlock *bb, MIR *mir);
534
535 /*
536 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the type of the vector.
537 * @param bb The basic block in which the MIR is from.
538 * @param mir The MIR whose opcode is kMirConstVector.
539 * @note vA: TypeSize
540 * @note vB: destination and source
541 * @note vC: immediate
542 */
543 void GenShiftLeftVector(BasicBlock *bb, MIR *mir);
544
545 /*
546 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to know the type of the vector.
547 * @param bb The basic block in which the MIR is from.
548 * @param mir The MIR whose opcode is kMirConstVector.
549 * @note vA: TypeSize
550 * @note vB: destination and source
551 * @note vC: immediate
552 */
553 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
554
555 /*
556 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA to know the type of the vector.
557 * @param bb The basic block in which the MIR is from..
558 * @param mir The MIR whose opcode is kMirConstVector.
559 * @note vA: TypeSize
560 * @note vB: destination and source
561 * @note vC: immediate
562 */
563 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
564
565 /*
566 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the type of the vector.
567 * @note vA: TypeSize
568 * @note vB: destination and source
569 * @note vC: source
570 */
571 void GenAndVector(BasicBlock *bb, MIR *mir);
572
573 /*
574 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the type of the vector.
575 * @param bb The basic block in which the MIR is from.
576 * @param mir The MIR whose opcode is kMirConstVector.
577 * @note vA: TypeSize
578 * @note vB: destination and source
579 * @note vC: source
580 */
581 void GenOrVector(BasicBlock *bb, MIR *mir);
582
583 /*
584 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the type of the vector.
585 * @param bb The basic block in which the MIR is from.
586 * @param mir The MIR whose opcode is kMirConstVector.
587 * @note vA: TypeSize
588 * @note vB: destination and source
589 * @note vC: source
590 */
591 void GenXorVector(BasicBlock *bb, MIR *mir);
592
593 /*
594 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
595 * @param bb The basic block in which the MIR is from.
596 * @param mir The MIR whose opcode is kMirConstVector.
597 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
598 * @note vA: TypeSize
599 * @note vB: destination and source VR (not vector register)
600 * @note vC: source (vector register)
601 */
602 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
603
604 /*
605 * @brief Extract a packed element into a single VR.
606 * @param bb The basic block in which the MIR is from.
607 * @param mir The MIR whose opcode is kMirConstVector.
608 * @note vA: TypeSize
609 * @note vB: destination VR (not vector register)
610 * @note vC: source (vector register)
611 * @note arg[0]: The index to use for extraction from vector register (which packed element).
612 */
613 void GenReduceVector(BasicBlock *bb, MIR *mir);
614
615 /*
616 * @brief Create a vector value, with all TypeSize values equal to vC
617 * @param bb The basic block in which the MIR is from.
618 * @param mir The MIR whose opcode is kMirConstVector.
619 * @note vA: TypeSize.
620 * @note vB: destination vector register.
621 * @note vC: source VR (not vector register).
622 */
623 void GenSetVector(BasicBlock *bb, MIR *mir);
624
625 /*
Mark Mendelld65c51a2014-04-29 16:55:20 -0400626 * @brief Generate code for a vector opcode.
627 * @param bb The basic block in which the MIR is from.
628 * @param mir The MIR whose opcode is a non-standard opcode.
629 */
630 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
631
632 /*
Mark Mendelle02d48f2014-01-15 11:19:23 -0800633 * @brief Return the correct x86 opcode for the Dex operation
634 * @param op Dex opcode for the operation
635 * @param loc Register location of the operand
636 * @param is_high_op 'true' if this is an operation on the high word
637 * @param value Immediate value for the operation. Used for byte variants
638 * @returns the correct x86 opcode to perform the operation
639 */
640 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
641
642 /*
643 * @brief Return the correct x86 opcode for the Dex operation
644 * @param op Dex opcode for the operation
645 * @param dest location of the destination. May be register or memory.
646 * @param rhs Location for the rhs of the operation. May be in register or memory.
647 * @param is_high_op 'true' if this is an operation on the high word
648 * @returns the correct x86 opcode to perform the operation
649 * @note at most one location may refer to memory
650 */
651 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
652 bool is_high_op);
653
654 /*
655 * @brief Is this operation a no-op for this opcode and value
656 * @param op Dex opcode for the operation
657 * @param value Immediate value for the operation.
658 * @returns 'true' if the operation will have no effect
659 */
660 bool IsNoOp(Instruction::Code op, int32_t value);
661
Mark Mendell2bf31e62014-01-23 12:13:40 -0800662 /**
663 * @brief Calculate magic number and shift for a given divisor
664 * @param divisor divisor number for calculation
665 * @param magic hold calculated magic number
666 * @param shift hold calculated shift
667 */
668 void CalculateMagicAndShift(int divisor, int& magic, int& shift);
669
670 /*
671 * @brief Generate an integer div or rem operation.
672 * @param rl_dest Destination Location.
673 * @param rl_src1 Numerator Location.
674 * @param rl_src2 Divisor Location.
675 * @param is_div 'true' if this is a division, 'false' for a remainder.
676 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
677 */
buzbee2700f7e2014-03-07 09:46:20 -0800678 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
679 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800680
681 /*
682 * @brief Generate an integer div or rem operation by a literal.
683 * @param rl_dest Destination Location.
684 * @param rl_src Numerator Location.
685 * @param lit Divisor.
686 * @param is_div 'true' if this is a division, 'false' for a remainder.
687 */
688 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800689
690 /*
691 * Generate code to implement long shift operations.
692 * @param opcode The DEX opcode to specify the shift type.
693 * @param rl_dest The destination.
694 * @param rl_src The value to be shifted.
695 * @param shift_amount How much to shift.
696 * @returns the RegLocation of the result.
697 */
698 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
699 RegLocation rl_src, int shift_amount);
700 /*
701 * Generate an imul of a register by a constant or a better sequence.
702 * @param dest Destination Register.
703 * @param src Source Register.
704 * @param val Constant multiplier.
705 */
buzbee2700f7e2014-03-07 09:46:20 -0800706 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800707
Mark Mendell4708dcd2014-01-22 09:05:18 -0800708 /*
709 * Generate an imul of a memory location by a constant or a better sequence.
710 * @param dest Destination Register.
711 * @param sreg Symbolic register.
712 * @param displacement Displacement on stack of Symbolic Register.
713 * @param val Constant multiplier.
714 */
buzbee2700f7e2014-03-07 09:46:20 -0800715 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendell766e9292014-01-27 07:55:47 -0800716
717 /*
718 * @brief Compare memory to immediate, and branch if condition true.
719 * @param cond The condition code that when true will branch to the target.
720 * @param temp_reg A temporary register that can be used if compare memory is not
721 * supported by the architecture.
722 * @param base_reg The register holding the base address.
723 * @param offset The offset from the base.
724 * @param check_value The immediate to compare to.
725 */
buzbee2700f7e2014-03-07 09:46:20 -0800726 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
Mark Mendell766e9292014-01-27 07:55:47 -0800727 int offset, int check_value, LIR* target);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800728
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800729 /*
730 * Can this operation be using core registers without temporaries?
731 * @param rl_lhs Left hand operand.
732 * @param rl_rhs Right hand operand.
733 * @returns 'true' if the operation can proceed without needing temporary regs.
734 */
735 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Mark Mendell67c39c42014-01-31 17:28:00 -0800736
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800737 /**
738 * @brief Generates inline code for conversion of long to FP by using x87/
739 * @param rl_dest The destination of the FP.
740 * @param rl_src The source of the long.
741 * @param is_double 'true' if dealing with double, 'false' for float.
742 */
Mark Mendelle87f9b52014-04-30 14:13:18 -0400743 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800744
Mark Mendell67c39c42014-01-31 17:28:00 -0800745 /*
746 * @brief Perform MIR analysis before compiling method.
747 * @note Invokes Mir2LiR::Materialize after analysis.
748 */
749 void Materialize();
750
751 /*
buzbee30adc732014-05-09 15:10:18 -0700752 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
753 * without regard to data type. In practice, this can result in UpdateLoc returning a
754 * location record for a Dalvik float value in a core register, and vis-versa. For targets
755 * which can inexpensively move data between core and float registers, this can often be a win.
756 * However, for x86 this is generally not a win. These variants of UpdateLoc()
757 * take a register class argument - and will return an in-register location record only if
758 * the value is live in a temp register of the correct class. Additionally, if the value is in
759 * a temp register of the wrong register class, it will be clobbered.
760 */
761 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
762 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
763
764 /*
Mark Mendell67c39c42014-01-31 17:28:00 -0800765 * @brief Analyze MIR before generating code, to prepare for the code generation.
766 */
767 void AnalyzeMIR();
768
769 /*
770 * @brief Analyze one basic block.
771 * @param bb Basic block to analyze.
772 */
773 void AnalyzeBB(BasicBlock * bb);
774
775 /*
776 * @brief Analyze one extended MIR instruction
777 * @param opcode MIR instruction opcode.
778 * @param bb Basic block containing instruction.
779 * @param mir Extended instruction to analyze.
780 */
781 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
782
783 /*
784 * @brief Analyze one MIR instruction
785 * @param opcode MIR instruction opcode.
786 * @param bb Basic block containing instruction.
787 * @param mir Instruction to analyze.
788 */
Mark Mendelle87f9b52014-04-30 14:13:18 -0400789 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800790
791 /*
792 * @brief Analyze one MIR float/double instruction
793 * @param opcode MIR instruction opcode.
794 * @param bb Basic block containing instruction.
795 * @param mir Instruction to analyze.
796 */
797 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
798
799 /*
800 * @brief Analyze one use of a double operand.
801 * @param rl_use Double RegLocation for the operand.
802 */
803 void AnalyzeDoubleUse(RegLocation rl_use);
804
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700805 bool Gen64Bit() const { return gen64bit_; }
806
Mark Mendell67c39c42014-01-31 17:28:00 -0800807 // Information derived from analysis of MIR
808
Mark Mendell55d0eac2014-02-06 11:02:52 -0800809 // The compiler temporary for the code address of the method.
810 CompilerTemp *base_of_code_;
811
Mark Mendell67c39c42014-01-31 17:28:00 -0800812 // Have we decided to compute a ptr to code and store in temporary VR?
813 bool store_method_addr_;
814
Mark Mendell55d0eac2014-02-06 11:02:52 -0800815 // Have we used the stored method address?
816 bool store_method_addr_used_;
817
818 // Instructions to remove if we didn't use the stored method address.
819 LIR* setup_method_address_[2];
820
821 // Instructions needing patching with Method* values.
822 GrowableArray<LIR*> method_address_insns_;
823
824 // Instructions needing patching with Class Type* values.
825 GrowableArray<LIR*> class_type_address_insns_;
826
827 // Instructions needing patching with PC relative code addresses.
828 GrowableArray<LIR*> call_method_insns_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800829
830 // Prologue decrement of stack pointer.
831 LIR* stack_decrement_;
832
833 // Epilogue increment of stack pointer.
834 LIR* stack_increment_;
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700835
836 // 64-bit mode
837 bool gen64bit_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400838
839 // The list of const vector literals.
840 LIR *const_vectors_;
841
842 /*
843 * @brief Search for a matching vector literal
844 * @param mir A kMirOpConst128b MIR instruction to match.
845 * @returns pointer to matching LIR constant, or nullptr if not found.
846 */
847 LIR *ScanVectorLiteral(MIR *mir);
848
849 /*
850 * @brief Add a constant vector literal
851 * @param mir A kMirOpConst128b MIR instruction to match.
852 */
853 LIR *AddVectorLiteral(MIR *mir);
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700854
855 InToRegStorageMapping in_to_reg_storage_mapping_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700856};
857
858} // namespace art
859
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700860#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_