blob: f2654b9d74f7ffd0951deb8a2e8d007c795d715d [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
23namespace art {
24
25class X86Mir2Lir : public Mir2Lir {
26 public:
Brian Carlstrom7940e442013-07-12 13:46:57 -070027 X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
28
29 // Required for target - codegen helpers.
buzbee11b63d12013-08-27 07:34:17 -070030 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
Brian Carlstrom7940e442013-07-12 13:46:57 -070031 RegLocation rl_dest, int lit);
Ian Rogers468532e2013-08-05 10:56:33 -070032 int LoadHelper(ThreadOffset offset);
Dave Allisonb373e092014-02-20 16:06:36 -080033 LIR* CheckSuspendUsingLoad() OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -070034 LIR* LoadBaseDisp(int rBase, int displacement, int r_dest, OpSize size, int s_reg);
35 LIR* LoadBaseDispWide(int rBase, int displacement, int r_dest_lo, int r_dest_hi,
36 int s_reg);
37 LIR* LoadBaseIndexed(int rBase, int r_index, int r_dest, int scale, OpSize size);
38 LIR* LoadBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
39 int r_dest, int r_dest_hi, OpSize size, int s_reg);
40 LIR* LoadConstantNoClobber(int r_dest, int value);
41 LIR* LoadConstantWide(int r_dest_lo, int r_dest_hi, int64_t value);
42 LIR* StoreBaseDisp(int rBase, int displacement, int r_src, OpSize size);
43 LIR* StoreBaseDispWide(int rBase, int displacement, int r_src_lo, int r_src_hi);
44 LIR* StoreBaseIndexed(int rBase, int r_index, int r_src, int scale, OpSize size);
45 LIR* StoreBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
46 int r_src, int r_src_hi, OpSize size, int s_reg);
47 void MarkGCCard(int val_reg, int tgt_addr_reg);
48
49 // Required for target - register utilities.
50 bool IsFpReg(int reg);
51 bool SameRegType(int reg1, int reg2);
Bill Buzbee00e1ec62014-02-27 23:44:13 +000052 // TODO: for consistency, make this return a RegStorage as well?
Brian Carlstrom7940e442013-07-12 13:46:57 -070053 int AllocTypedTemp(bool fp_hint, int reg_class);
Bill Buzbee00e1ec62014-02-27 23:44:13 +000054 RegStorage AllocTypedTempWide(bool fp_hint, int reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -070055 int S2d(int low_reg, int high_reg);
56 int TargetReg(SpecialTargetRegister reg);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -080057 int GetArgMappingToPhysicalReg(int arg_num);
Brian Carlstrom7940e442013-07-12 13:46:57 -070058 RegLocation GetReturnAlt();
59 RegLocation GetReturnWideAlt();
60 RegLocation LocCReturn();
61 RegLocation LocCReturnDouble();
62 RegLocation LocCReturnFloat();
63 RegLocation LocCReturnWide();
64 uint32_t FpRegMask();
65 uint64_t GetRegMaskCommon(int reg);
66 void AdjustSpillMask();
Vladimir Marko31c2aac2013-12-09 16:31:19 +000067 void ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -070068 void FlushReg(int reg);
69 void FlushRegWide(int reg1, int reg2);
70 void FreeCallTemps();
71 void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free);
72 void LockCallTemps();
73 void MarkPreservedSingle(int v_reg, int reg);
74 void CompilerInitializeRegAlloc();
75
76 // Required for target - miscellaneous.
buzbeeb48819d2013-09-14 16:15:25 -070077 void AssembleLIR();
78 int AssignInsnOffsets();
79 void AssignOffsets();
buzbee0d829482013-10-11 15:24:55 -070080 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
Brian Carlstrom7940e442013-07-12 13:46:57 -070081 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
buzbeeb48819d2013-09-14 16:15:25 -070082 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -070083 const char* GetTargetInstFmt(int opcode);
84 const char* GetTargetInstName(int opcode);
85 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
86 uint64_t GetPCUseDefEncoding();
87 uint64_t GetTargetInstFlags(int opcode);
88 int GetInsnSize(LIR* lir);
89 bool IsUnconditionalBranch(LIR* lir);
90
91 // Required for target - Dalvik-level generators.
92 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
93 RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -070094 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
95 RegLocation rl_index, RegLocation rl_dest, int scale);
96 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -070097 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark);
Brian Carlstrom7940e442013-07-12 13:46:57 -070098 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
Ian Rogersa9a82542013-10-04 11:17:26 -070099 RegLocation rl_src1, RegLocation rl_shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800100 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
101 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
102 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700103 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest,
104 RegLocation rl_src1, RegLocation rl_src2);
105 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest,
106 RegLocation rl_src1, RegLocation rl_src2);
107 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
108 RegLocation rl_src2);
109 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
Vladimir Marko1c282e22013-11-21 14:49:47 +0000110 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700111 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
112 bool GenInlinedSqrt(CallInfo* info);
Vladimir Markoe508a202013-11-04 15:24:22 +0000113 bool GenInlinedPeek(CallInfo* info, OpSize size);
114 bool GenInlinedPoke(CallInfo* info, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700115 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800116 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
117 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
118 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700119 LIR* GenRegMemCheck(ConditionCode c_code, int reg1, int base, int offset,
120 ThrowKind kind);
Mark Mendell343adb52013-12-18 06:02:17 -0800121 LIR* GenMemImmedCheck(ConditionCode c_code, int base, int offset, int check_value,
122 ThrowKind kind);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700123 RegLocation GenDivRem(RegLocation rl_dest, int reg_lo, int reg_hi, bool is_div);
124 RegLocation GenDivRemLit(RegLocation rl_dest, int reg_lo, int lit, bool is_div);
125 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
126 void GenDivZeroCheck(int reg_lo, int reg_hi);
127 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
128 void GenExitSequence();
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800129 void GenSpecialExitSequence();
buzbee0d829482013-10-11 15:24:55 -0700130 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700131 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
132 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
133 void GenSelect(BasicBlock* bb, MIR* mir);
134 void GenMemBarrier(MemBarrierKind barrier_kind);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700135 void GenMoveException(RegLocation rl_dest);
136 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result,
137 int lit, int first_bit, int second_bit);
138 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
139 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
buzbee0d829482013-10-11 15:24:55 -0700140 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
141 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800142
Mark Mendelle02d48f2014-01-15 11:19:23 -0800143 /*
144 * @brief Generate a two address long operation with a constant value
145 * @param rl_dest location of result
146 * @param rl_src constant source operand
147 * @param op Opcode to be generated
148 */
149 void GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
150 /*
151 * @brief Generate a three address long operation with a constant value
152 * @param rl_dest location of result
153 * @param rl_src1 source operand
154 * @param rl_src2 constant source operand
155 * @param op Opcode to be generated
156 */
157 void GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1,
158 RegLocation rl_src2, Instruction::Code op);
159
160 /**
161 * @brief Generate a long arithmetic operation.
162 * @param rl_dest The destination.
163 * @param rl_src1 First operand.
164 * @param rl_src2 Second operand.
165 * @param op The DEX opcode for the operation.
166 * @param is_commutative The sources can be swapped if needed.
167 */
168 void GenLongArith(RegLocation rl_dest, RegLocation rl_src1,
169 RegLocation rl_src2, Instruction::Code op, bool is_commutative);
170
171 /**
172 * @brief Generate a two operand long arithmetic operation.
173 * @param rl_dest The destination.
174 * @param rl_src Second operand.
175 * @param op The DEX opcode for the operation.
176 */
177 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
178
179 /**
180 * @brief Generate a long operation.
181 * @param rl_dest The destination. Must be in a register
182 * @param rl_src The other operand. May be in a register or in memory.
183 * @param op The DEX opcode for the operation.
184 */
185 void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700186
Mark Mendelldf8ee2e2014-01-27 16:37:47 -0800187 /**
188 * @brief Implement instanceof a final class with x86 specific code.
189 * @param use_declaring_class 'true' if we can use the class itself.
190 * @param type_idx Type index to use if use_declaring_class is 'false'.
191 * @param rl_dest Result to be set to 0 or 1.
192 * @param rl_src Object to be tested.
193 */
194 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx,
195 RegLocation rl_dest, RegLocation rl_src);
Mark Mendell6607d972014-02-10 06:54:18 -0800196 /*
197 *
198 * @brief Implement Set up instanceof a class with x86 specific code.
199 * @param needs_access_check 'true' if we must check the access.
200 * @param type_known_final 'true' if the type is known to be a final class.
201 * @param type_known_abstract 'true' if the type is known to be an abstract class.
202 * @param use_declaring_class 'true' if the type can be loaded off the current Method*.
203 * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache.
204 * @param type_idx Type index to use if use_declaring_class is 'false'.
205 * @param rl_dest Result to be set to 0 or 1.
206 * @param rl_src Object to be tested.
207 */
208 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
209 bool type_known_abstract, bool use_declaring_class,
210 bool can_assume_type_is_in_dex_cache,
211 uint32_t type_idx, RegLocation rl_dest,
212 RegLocation rl_src);
213
Brian Carlstrom7940e442013-07-12 13:46:57 -0700214 // Single operation generators.
215 LIR* OpUnconditionalBranch(LIR* target);
216 LIR* OpCmpBranch(ConditionCode cond, int src1, int src2, LIR* target);
217 LIR* OpCmpImmBranch(ConditionCode cond, int reg, int check_value, LIR* target);
218 LIR* OpCondBranch(ConditionCode cc, LIR* target);
219 LIR* OpDecAndBranch(ConditionCode c_code, int reg, LIR* target);
220 LIR* OpFpRegCopy(int r_dest, int r_src);
221 LIR* OpIT(ConditionCode cond, const char* guide);
222 LIR* OpMem(OpKind op, int rBase, int disp);
223 LIR* OpPcRelLoad(int reg, LIR* target);
224 LIR* OpReg(OpKind op, int r_dest_src);
225 LIR* OpRegCopy(int r_dest, int r_src);
226 LIR* OpRegCopyNoInsert(int r_dest, int r_src);
227 LIR* OpRegImm(OpKind op, int r_dest_src1, int value);
228 LIR* OpRegMem(OpKind op, int r_dest, int rBase, int offset);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800229 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
230 LIR* OpRegMem(OpKind op, int r_dest, RegLocation value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700231 LIR* OpRegReg(OpKind op, int r_dest_src1, int r_src2);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800232 LIR* OpMovRegMem(int r_dest, int r_base, int offset, MoveType move_type);
233 LIR* OpMovMemReg(int r_base, int offset, int r_src, MoveType move_type);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800234 LIR* OpCondRegReg(OpKind op, ConditionCode cc, int r_dest, int r_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700235 LIR* OpRegRegImm(OpKind op, int r_dest, int r_src1, int value);
236 LIR* OpRegRegReg(OpKind op, int r_dest, int r_src1, int r_src2);
237 LIR* OpTestSuspend(LIR* target);
Ian Rogers468532e2013-08-05 10:56:33 -0700238 LIR* OpThreadMem(OpKind op, ThreadOffset thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700239 LIR* OpVldm(int rBase, int count);
240 LIR* OpVstm(int rBase, int count);
241 void OpLea(int rBase, int reg1, int reg2, int scale, int offset);
242 void OpRegCopyWide(int dest_lo, int dest_hi, int src_lo, int src_hi);
Ian Rogers468532e2013-08-05 10:56:33 -0700243 void OpTlsCmp(ThreadOffset offset, int val);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700244
Ian Rogers468532e2013-08-05 10:56:33 -0700245 void OpRegThreadMem(OpKind op, int r_dest, ThreadOffset thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700246 void SpillCoreRegs();
247 void UnSpillCoreRegs();
248 static const X86EncodingMap EncodingMap[kX86Last];
249 bool InexpensiveConstantInt(int32_t value);
250 bool InexpensiveConstantFloat(int32_t value);
251 bool InexpensiveConstantLong(int64_t value);
252 bool InexpensiveConstantDouble(int64_t value);
253
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000254 RegLocation UpdateLocWide(RegLocation loc);
255 RegLocation EvalLocWide(RegLocation loc, int reg_class, bool update);
256 RegLocation EvalLoc(RegLocation loc, int reg_class, bool update);
257 int AllocTempDouble();
258 void ResetDefLocWide(RegLocation rl);
259
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800260 /*
261 * @brief x86 specific codegen for int operations.
262 * @param opcode Operation to perform.
263 * @param rl_dest Destination for the result.
264 * @param rl_lhs Left hand operand.
265 * @param rl_rhs Right hand operand.
266 */
267 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest,
268 RegLocation rl_lhs, RegLocation rl_rhs);
269
Mark Mendell55d0eac2014-02-06 11:02:52 -0800270 /*
271 * @brief Dump a RegLocation using printf
272 * @param loc Register location to dump
273 */
274 static void DumpRegLocation(RegLocation loc);
275
276 /*
277 * @brief Load the Method* of a dex method into the register.
Jeff Hao49161ce2014-03-12 11:05:25 -0700278 * @param target_method The MethodReference of the method to be invoked.
Mark Mendell55d0eac2014-02-06 11:02:52 -0800279 * @param type How the method will be invoked.
280 * @param register that will contain the code address.
281 * @note register will be passed to TargetReg to get physical register.
282 */
Jeff Hao49161ce2014-03-12 11:05:25 -0700283 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
Mark Mendell55d0eac2014-02-06 11:02:52 -0800284 SpecialTargetRegister symbolic_reg);
285
286 /*
287 * @brief Load the Class* of a Dex Class type into the register.
288 * @param type How the method will be invoked.
289 * @param register that will contain the code address.
290 * @note register will be passed to TargetReg to get physical register.
291 */
292 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg);
293
294 /*
295 * @brief Generate a relative call to the method that will be patched at link time.
Jeff Hao49161ce2014-03-12 11:05:25 -0700296 * @param target_method The MethodReference of the method to be invoked.
Mark Mendell55d0eac2014-02-06 11:02:52 -0800297 * @param type How the method will be invoked.
298 * @returns Call instruction
299 */
Jeff Hao49161ce2014-03-12 11:05:25 -0700300 LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800301
302 /*
303 * @brief Handle x86 specific literals
304 */
305 void InstallLiteralPools();
306
Mark Mendellae9fd932014-02-10 16:14:35 -0800307 /*
308 * @brief Generate the debug_frame CFI information.
309 * @returns pointer to vector containing CFE information
310 */
311 static std::vector<uint8_t>* ReturnCommonCallFrameInformation();
312
313 /*
314 * @brief Generate the debug_frame FDE information.
315 * @returns pointer to vector containing CFE information
316 */
317 std::vector<uint8_t>* ReturnCallFrameInformation();
318
Brian Carlstrom7940e442013-07-12 13:46:57 -0700319 private:
Vladimir Marko057c74a2013-12-03 15:20:45 +0000320 void EmitPrefix(const X86EncodingMap* entry);
321 void EmitOpcode(const X86EncodingMap* entry);
322 void EmitPrefixAndOpcode(const X86EncodingMap* entry);
323 void EmitDisp(uint8_t base, int disp);
324 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int disp);
325 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale, int disp);
326 void EmitImm(const X86EncodingMap* entry, int imm);
Vladimir Markoa8b4caf2013-10-24 15:08:57 +0100327 void EmitOpRegOpcode(const X86EncodingMap* entry, uint8_t reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700328 void EmitOpReg(const X86EncodingMap* entry, uint8_t reg);
329 void EmitOpMem(const X86EncodingMap* entry, uint8_t base, int disp);
Vladimir Marko057c74a2013-12-03 15:20:45 +0000330 void EmitOpArray(const X86EncodingMap* entry, uint8_t base, uint8_t index,
331 int scale, int disp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700332 void EmitMemReg(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg);
Mark Mendell343adb52013-12-18 06:02:17 -0800333 void EmitMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700334 void EmitRegMem(const X86EncodingMap* entry, uint8_t reg, uint8_t base, int disp);
335 void EmitRegArray(const X86EncodingMap* entry, uint8_t reg, uint8_t base, uint8_t index,
336 int scale, int disp);
337 void EmitArrayReg(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp,
338 uint8_t reg);
339 void EmitRegThread(const X86EncodingMap* entry, uint8_t reg, int disp);
340 void EmitRegReg(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2);
341 void EmitRegRegImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800342 void EmitRegRegImmRev(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm);
343 void EmitRegMemImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int disp, int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700344 void EmitRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
345 void EmitThreadImm(const X86EncodingMap* entry, int disp, int imm);
346 void EmitMovRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
347 void EmitShiftRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800348 void EmitShiftMemCl(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t cl);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700349 void EmitShiftRegCl(const X86EncodingMap* entry, uint8_t reg, uint8_t cl);
350 void EmitRegCond(const X86EncodingMap* entry, uint8_t reg, uint8_t condition);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800351
352 /**
353 * @brief Used for encoding conditional register to register operation.
354 * @param entry The entry in the encoding map for the opcode.
355 * @param reg1 The first physical register.
356 * @param reg2 The second physical register.
357 * @param condition The condition code for operation.
358 */
359 void EmitRegRegCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, uint8_t condition);
360
Brian Carlstrom7940e442013-07-12 13:46:57 -0700361 void EmitJmp(const X86EncodingMap* entry, int rel);
362 void EmitJcc(const X86EncodingMap* entry, int rel, uint8_t cc);
363 void EmitCallMem(const X86EncodingMap* entry, uint8_t base, int disp);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800364 void EmitCallImmediate(const X86EncodingMap* entry, int disp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700365 void EmitCallThread(const X86EncodingMap* entry, int disp);
366 void EmitPcRel(const X86EncodingMap* entry, uint8_t reg, int base_or_table, uint8_t index,
367 int scale, int table_or_disp);
368 void EmitMacro(const X86EncodingMap* entry, uint8_t reg, int offset);
369 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
Mark Mendell412d4f82013-12-18 13:32:36 -0800370 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
371 int64_t val, ConditionCode ccode);
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000372 void OpVectorRegCopyWide(uint8_t fp_reg, uint8_t low_reg, uint8_t high_reg);
373 void GenConstWide(RegLocation rl_dest, int64_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800374
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800375 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
376
Mark Mendelle02d48f2014-01-15 11:19:23 -0800377 /*
Mark Mendell4028a6c2014-02-19 20:06:20 -0800378 * @brief generate inline code for fast case of Strng.indexOf.
379 * @param info Call parameters
380 * @param zero_based 'true' if the index into the string is 0.
381 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
382 * generated.
383 */
384 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
385
386 /*
Mark Mendelle02d48f2014-01-15 11:19:23 -0800387 * @brief Return the correct x86 opcode for the Dex operation
388 * @param op Dex opcode for the operation
389 * @param loc Register location of the operand
390 * @param is_high_op 'true' if this is an operation on the high word
391 * @param value Immediate value for the operation. Used for byte variants
392 * @returns the correct x86 opcode to perform the operation
393 */
394 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
395
396 /*
397 * @brief Return the correct x86 opcode for the Dex operation
398 * @param op Dex opcode for the operation
399 * @param dest location of the destination. May be register or memory.
400 * @param rhs Location for the rhs of the operation. May be in register or memory.
401 * @param is_high_op 'true' if this is an operation on the high word
402 * @returns the correct x86 opcode to perform the operation
403 * @note at most one location may refer to memory
404 */
405 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
406 bool is_high_op);
407
408 /*
409 * @brief Is this operation a no-op for this opcode and value
410 * @param op Dex opcode for the operation
411 * @param value Immediate value for the operation.
412 * @returns 'true' if the operation will have no effect
413 */
414 bool IsNoOp(Instruction::Code op, int32_t value);
415
Mark Mendell2bf31e62014-01-23 12:13:40 -0800416 /**
417 * @brief Calculate magic number and shift for a given divisor
418 * @param divisor divisor number for calculation
419 * @param magic hold calculated magic number
420 * @param shift hold calculated shift
421 */
422 void CalculateMagicAndShift(int divisor, int& magic, int& shift);
423
424 /*
425 * @brief Generate an integer div or rem operation.
426 * @param rl_dest Destination Location.
427 * @param rl_src1 Numerator Location.
428 * @param rl_src2 Divisor Location.
429 * @param is_div 'true' if this is a division, 'false' for a remainder.
430 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
431 */
432 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1,
433 RegLocation rl_src2, bool is_div, bool check_zero);
434
435 /*
436 * @brief Generate an integer div or rem operation by a literal.
437 * @param rl_dest Destination Location.
438 * @param rl_src Numerator Location.
439 * @param lit Divisor.
440 * @param is_div 'true' if this is a division, 'false' for a remainder.
441 */
442 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800443
444 /*
445 * Generate code to implement long shift operations.
446 * @param opcode The DEX opcode to specify the shift type.
447 * @param rl_dest The destination.
448 * @param rl_src The value to be shifted.
449 * @param shift_amount How much to shift.
450 * @returns the RegLocation of the result.
451 */
452 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
453 RegLocation rl_src, int shift_amount);
454 /*
455 * Generate an imul of a register by a constant or a better sequence.
456 * @param dest Destination Register.
457 * @param src Source Register.
458 * @param val Constant multiplier.
459 */
460 void GenImulRegImm(int dest, int src, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800461
Mark Mendell4708dcd2014-01-22 09:05:18 -0800462 /*
463 * Generate an imul of a memory location by a constant or a better sequence.
464 * @param dest Destination Register.
465 * @param sreg Symbolic register.
466 * @param displacement Displacement on stack of Symbolic Register.
467 * @param val Constant multiplier.
468 */
469 void GenImulMemImm(int dest, int sreg, int displacement, int val);
Mark Mendell766e9292014-01-27 07:55:47 -0800470
471 /*
472 * @brief Compare memory to immediate, and branch if condition true.
473 * @param cond The condition code that when true will branch to the target.
474 * @param temp_reg A temporary register that can be used if compare memory is not
475 * supported by the architecture.
476 * @param base_reg The register holding the base address.
477 * @param offset The offset from the base.
478 * @param check_value The immediate to compare to.
479 */
480 LIR* OpCmpMemImmBranch(ConditionCode cond, int temp_reg, int base_reg,
481 int offset, int check_value, LIR* target);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800482
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800483 /*
484 * Can this operation be using core registers without temporaries?
485 * @param rl_lhs Left hand operand.
486 * @param rl_rhs Right hand operand.
487 * @returns 'true' if the operation can proceed without needing temporary regs.
488 */
489 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Mark Mendell67c39c42014-01-31 17:28:00 -0800490
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800491 /**
492 * @brief Generates inline code for conversion of long to FP by using x87/
493 * @param rl_dest The destination of the FP.
494 * @param rl_src The source of the long.
495 * @param is_double 'true' if dealing with double, 'false' for float.
496 */
497 void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
498
Mark Mendell67c39c42014-01-31 17:28:00 -0800499 /*
500 * @brief Perform MIR analysis before compiling method.
501 * @note Invokes Mir2LiR::Materialize after analysis.
502 */
503 void Materialize();
504
505 /*
506 * @brief Analyze MIR before generating code, to prepare for the code generation.
507 */
508 void AnalyzeMIR();
509
510 /*
511 * @brief Analyze one basic block.
512 * @param bb Basic block to analyze.
513 */
514 void AnalyzeBB(BasicBlock * bb);
515
516 /*
517 * @brief Analyze one extended MIR instruction
518 * @param opcode MIR instruction opcode.
519 * @param bb Basic block containing instruction.
520 * @param mir Extended instruction to analyze.
521 */
522 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
523
524 /*
525 * @brief Analyze one MIR instruction
526 * @param opcode MIR instruction opcode.
527 * @param bb Basic block containing instruction.
528 * @param mir Instruction to analyze.
529 */
530 void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
531
532 /*
533 * @brief Analyze one MIR float/double instruction
534 * @param opcode MIR instruction opcode.
535 * @param bb Basic block containing instruction.
536 * @param mir Instruction to analyze.
537 */
538 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
539
540 /*
541 * @brief Analyze one use of a double operand.
542 * @param rl_use Double RegLocation for the operand.
543 */
544 void AnalyzeDoubleUse(RegLocation rl_use);
545
546 // Information derived from analysis of MIR
547
Mark Mendell55d0eac2014-02-06 11:02:52 -0800548 // The compiler temporary for the code address of the method.
549 CompilerTemp *base_of_code_;
550
Mark Mendell67c39c42014-01-31 17:28:00 -0800551 // Have we decided to compute a ptr to code and store in temporary VR?
552 bool store_method_addr_;
553
Mark Mendell55d0eac2014-02-06 11:02:52 -0800554 // Have we used the stored method address?
555 bool store_method_addr_used_;
556
557 // Instructions to remove if we didn't use the stored method address.
558 LIR* setup_method_address_[2];
559
560 // Instructions needing patching with Method* values.
561 GrowableArray<LIR*> method_address_insns_;
562
563 // Instructions needing patching with Class Type* values.
564 GrowableArray<LIR*> class_type_address_insns_;
565
566 // Instructions needing patching with PC relative code addresses.
567 GrowableArray<LIR*> call_method_insns_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800568
569 // Prologue decrement of stack pointer.
570 LIR* stack_decrement_;
571
572 // Epilogue increment of stack pointer.
573 LIR* stack_increment_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700574};
575
576} // namespace art
577
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700578#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_