blob: c97d0e6f4dbab59beaa019d53986e0a2195aeedb [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);
Brian Carlstrom7940e442013-07-12 13:46:57 -070033 LIR* LoadBaseDisp(int rBase, int displacement, int r_dest, OpSize size, int s_reg);
34 LIR* LoadBaseDispWide(int rBase, int displacement, int r_dest_lo, int r_dest_hi,
35 int s_reg);
36 LIR* LoadBaseIndexed(int rBase, int r_index, int r_dest, int scale, OpSize size);
37 LIR* LoadBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
38 int r_dest, int r_dest_hi, OpSize size, int s_reg);
39 LIR* LoadConstantNoClobber(int r_dest, int value);
40 LIR* LoadConstantWide(int r_dest_lo, int r_dest_hi, int64_t value);
41 LIR* StoreBaseDisp(int rBase, int displacement, int r_src, OpSize size);
42 LIR* StoreBaseDispWide(int rBase, int displacement, int r_src_lo, int r_src_hi);
43 LIR* StoreBaseIndexed(int rBase, int r_index, int r_src, int scale, OpSize size);
44 LIR* StoreBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
45 int r_src, int r_src_hi, OpSize size, int s_reg);
46 void MarkGCCard(int val_reg, int tgt_addr_reg);
47
48 // Required for target - register utilities.
49 bool IsFpReg(int reg);
50 bool SameRegType(int reg1, int reg2);
51 int AllocTypedTemp(bool fp_hint, int reg_class);
Bill Buzbee86ec5202014-02-26 19:03:09 +000052 int AllocTypedTempPair(bool fp_hint, int reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -070053 int S2d(int low_reg, int high_reg);
54 int TargetReg(SpecialTargetRegister reg);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -080055 int GetArgMappingToPhysicalReg(int arg_num);
Brian Carlstrom7940e442013-07-12 13:46:57 -070056 RegLocation GetReturnAlt();
57 RegLocation GetReturnWideAlt();
58 RegLocation LocCReturn();
59 RegLocation LocCReturnDouble();
60 RegLocation LocCReturnFloat();
61 RegLocation LocCReturnWide();
62 uint32_t FpRegMask();
63 uint64_t GetRegMaskCommon(int reg);
64 void AdjustSpillMask();
Vladimir Marko31c2aac2013-12-09 16:31:19 +000065 void ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -070066 void FlushReg(int reg);
67 void FlushRegWide(int reg1, int reg2);
68 void FreeCallTemps();
69 void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free);
70 void LockCallTemps();
71 void MarkPreservedSingle(int v_reg, int reg);
72 void CompilerInitializeRegAlloc();
73
74 // Required for target - miscellaneous.
buzbeeb48819d2013-09-14 16:15:25 -070075 void AssembleLIR();
76 int AssignInsnOffsets();
77 void AssignOffsets();
buzbee0d829482013-10-11 15:24:55 -070078 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
Brian Carlstrom7940e442013-07-12 13:46:57 -070079 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
buzbeeb48819d2013-09-14 16:15:25 -070080 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -070081 const char* GetTargetInstFmt(int opcode);
82 const char* GetTargetInstName(int opcode);
83 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
84 uint64_t GetPCUseDefEncoding();
85 uint64_t GetTargetInstFlags(int opcode);
86 int GetInsnSize(LIR* lir);
87 bool IsUnconditionalBranch(LIR* lir);
88
89 // Required for target - Dalvik-level generators.
90 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
91 RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -070092 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
93 RegLocation rl_index, RegLocation rl_dest, int scale);
94 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -070095 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark);
Brian Carlstrom7940e442013-07-12 13:46:57 -070096 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
Ian Rogersa9a82542013-10-04 11:17:26 -070097 RegLocation rl_src1, RegLocation rl_shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -080098 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
99 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
100 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700101 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest,
102 RegLocation rl_src1, RegLocation rl_src2);
103 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest,
104 RegLocation rl_src1, RegLocation rl_src2);
105 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
106 RegLocation rl_src2);
107 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
Vladimir Marko1c282e22013-11-21 14:49:47 +0000108 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700109 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
110 bool GenInlinedSqrt(CallInfo* info);
Vladimir Markoe508a202013-11-04 15:24:22 +0000111 bool GenInlinedPeek(CallInfo* info, OpSize size);
112 bool GenInlinedPoke(CallInfo* info, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700113 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800114 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
115 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
116 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700117 LIR* GenRegMemCheck(ConditionCode c_code, int reg1, int base, int offset,
118 ThrowKind kind);
Mark Mendell343adb52013-12-18 06:02:17 -0800119 LIR* GenMemImmedCheck(ConditionCode c_code, int base, int offset, int check_value,
120 ThrowKind kind);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700121 RegLocation GenDivRem(RegLocation rl_dest, int reg_lo, int reg_hi, bool is_div);
122 RegLocation GenDivRemLit(RegLocation rl_dest, int reg_lo, int lit, bool is_div);
123 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
124 void GenDivZeroCheck(int reg_lo, int reg_hi);
125 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
126 void GenExitSequence();
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800127 void GenSpecialExitSequence();
buzbee0d829482013-10-11 15:24:55 -0700128 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700129 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
130 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
131 void GenSelect(BasicBlock* bb, MIR* mir);
132 void GenMemBarrier(MemBarrierKind barrier_kind);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700133 void GenMoveException(RegLocation rl_dest);
134 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result,
135 int lit, int first_bit, int second_bit);
136 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
137 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
buzbee0d829482013-10-11 15:24:55 -0700138 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
139 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800140
Mark Mendelle02d48f2014-01-15 11:19:23 -0800141 /*
142 * @brief Generate a two address long operation with a constant value
143 * @param rl_dest location of result
144 * @param rl_src constant source operand
145 * @param op Opcode to be generated
146 */
147 void GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
148 /*
149 * @brief Generate a three address long operation with a constant value
150 * @param rl_dest location of result
151 * @param rl_src1 source operand
152 * @param rl_src2 constant source operand
153 * @param op Opcode to be generated
154 */
155 void GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1,
156 RegLocation rl_src2, Instruction::Code op);
157
158 /**
159 * @brief Generate a long arithmetic operation.
160 * @param rl_dest The destination.
161 * @param rl_src1 First operand.
162 * @param rl_src2 Second operand.
163 * @param op The DEX opcode for the operation.
164 * @param is_commutative The sources can be swapped if needed.
165 */
166 void GenLongArith(RegLocation rl_dest, RegLocation rl_src1,
167 RegLocation rl_src2, Instruction::Code op, bool is_commutative);
168
169 /**
170 * @brief Generate a two operand long arithmetic operation.
171 * @param rl_dest The destination.
172 * @param rl_src Second operand.
173 * @param op The DEX opcode for the operation.
174 */
175 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
176
177 /**
178 * @brief Generate a long operation.
179 * @param rl_dest The destination. Must be in a register
180 * @param rl_src The other operand. May be in a register or in memory.
181 * @param op The DEX opcode for the operation.
182 */
183 void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700184
Mark Mendelldf8ee2e2014-01-27 16:37:47 -0800185 /**
186 * @brief Implement instanceof a final class with x86 specific code.
187 * @param use_declaring_class 'true' if we can use the class itself.
188 * @param type_idx Type index to use if use_declaring_class is 'false'.
189 * @param rl_dest Result to be set to 0 or 1.
190 * @param rl_src Object to be tested.
191 */
192 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx,
193 RegLocation rl_dest, RegLocation rl_src);
Mark Mendell6607d972014-02-10 06:54:18 -0800194 /*
195 *
196 * @brief Implement Set up instanceof a class with x86 specific code.
197 * @param needs_access_check 'true' if we must check the access.
198 * @param type_known_final 'true' if the type is known to be a final class.
199 * @param type_known_abstract 'true' if the type is known to be an abstract class.
200 * @param use_declaring_class 'true' if the type can be loaded off the current Method*.
201 * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache.
202 * @param type_idx Type index to use if use_declaring_class is 'false'.
203 * @param rl_dest Result to be set to 0 or 1.
204 * @param rl_src Object to be tested.
205 */
206 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
207 bool type_known_abstract, bool use_declaring_class,
208 bool can_assume_type_is_in_dex_cache,
209 uint32_t type_idx, RegLocation rl_dest,
210 RegLocation rl_src);
211
Brian Carlstrom7940e442013-07-12 13:46:57 -0700212 // Single operation generators.
213 LIR* OpUnconditionalBranch(LIR* target);
214 LIR* OpCmpBranch(ConditionCode cond, int src1, int src2, LIR* target);
215 LIR* OpCmpImmBranch(ConditionCode cond, int reg, int check_value, LIR* target);
216 LIR* OpCondBranch(ConditionCode cc, LIR* target);
217 LIR* OpDecAndBranch(ConditionCode c_code, int reg, LIR* target);
218 LIR* OpFpRegCopy(int r_dest, int r_src);
219 LIR* OpIT(ConditionCode cond, const char* guide);
220 LIR* OpMem(OpKind op, int rBase, int disp);
221 LIR* OpPcRelLoad(int reg, LIR* target);
222 LIR* OpReg(OpKind op, int r_dest_src);
223 LIR* OpRegCopy(int r_dest, int r_src);
224 LIR* OpRegCopyNoInsert(int r_dest, int r_src);
225 LIR* OpRegImm(OpKind op, int r_dest_src1, int value);
226 LIR* OpRegMem(OpKind op, int r_dest, int rBase, int offset);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800227 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
228 LIR* OpRegMem(OpKind op, int r_dest, RegLocation value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700229 LIR* OpRegReg(OpKind op, int r_dest_src1, int r_src2);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800230 LIR* OpMovRegMem(int r_dest, int r_base, int offset, MoveType move_type);
231 LIR* OpMovMemReg(int r_base, int offset, int r_src, MoveType move_type);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800232 LIR* OpCondRegReg(OpKind op, ConditionCode cc, int r_dest, int r_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700233 LIR* OpRegRegImm(OpKind op, int r_dest, int r_src1, int value);
234 LIR* OpRegRegReg(OpKind op, int r_dest, int r_src1, int r_src2);
235 LIR* OpTestSuspend(LIR* target);
Ian Rogers468532e2013-08-05 10:56:33 -0700236 LIR* OpThreadMem(OpKind op, ThreadOffset thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700237 LIR* OpVldm(int rBase, int count);
238 LIR* OpVstm(int rBase, int count);
239 void OpLea(int rBase, int reg1, int reg2, int scale, int offset);
240 void OpRegCopyWide(int dest_lo, int dest_hi, int src_lo, int src_hi);
Ian Rogers468532e2013-08-05 10:56:33 -0700241 void OpTlsCmp(ThreadOffset offset, int val);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700242
Ian Rogers468532e2013-08-05 10:56:33 -0700243 void OpRegThreadMem(OpKind op, int r_dest, ThreadOffset thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700244 void SpillCoreRegs();
245 void UnSpillCoreRegs();
246 static const X86EncodingMap EncodingMap[kX86Last];
247 bool InexpensiveConstantInt(int32_t value);
248 bool InexpensiveConstantFloat(int32_t value);
249 bool InexpensiveConstantLong(int64_t value);
250 bool InexpensiveConstantDouble(int64_t value);
251
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000252 RegLocation UpdateLocWide(RegLocation loc);
253 RegLocation EvalLocWide(RegLocation loc, int reg_class, bool update);
254 RegLocation EvalLoc(RegLocation loc, int reg_class, bool update);
255 int AllocTempDouble();
256 void ResetDefLocWide(RegLocation rl);
257
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800258 /*
259 * @brief x86 specific codegen for int operations.
260 * @param opcode Operation to perform.
261 * @param rl_dest Destination for the result.
262 * @param rl_lhs Left hand operand.
263 * @param rl_rhs Right hand operand.
264 */
265 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest,
266 RegLocation rl_lhs, RegLocation rl_rhs);
267
Mark Mendell55d0eac2014-02-06 11:02:52 -0800268 /*
269 * @brief Dump a RegLocation using printf
270 * @param loc Register location to dump
271 */
272 static void DumpRegLocation(RegLocation loc);
273
274 /*
275 * @brief Load the Method* of a dex method into the register.
276 * @param dex_method_index The index of the method to be invoked.
277 * @param type How the method will be invoked.
278 * @param register that will contain the code address.
279 * @note register will be passed to TargetReg to get physical register.
280 */
281 void LoadMethodAddress(int dex_method_index, InvokeType type,
282 SpecialTargetRegister symbolic_reg);
283
284 /*
285 * @brief Load the Class* of a Dex Class type into the register.
286 * @param type How the method will be invoked.
287 * @param register that will contain the code address.
288 * @note register will be passed to TargetReg to get physical register.
289 */
290 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg);
291
292 /*
293 * @brief Generate a relative call to the method that will be patched at link time.
294 * @param dex_method_index The index of the method to be invoked.
295 * @param type How the method will be invoked.
296 * @returns Call instruction
297 */
298 LIR * CallWithLinkerFixup(int dex_method_index, InvokeType type);
299
300 /*
301 * @brief Handle x86 specific literals
302 */
303 void InstallLiteralPools();
304
Mark Mendellae9fd932014-02-10 16:14:35 -0800305 /*
306 * @brief Generate the debug_frame CFI information.
307 * @returns pointer to vector containing CFE information
308 */
309 static std::vector<uint8_t>* ReturnCommonCallFrameInformation();
310
311 /*
312 * @brief Generate the debug_frame FDE information.
313 * @returns pointer to vector containing CFE information
314 */
315 std::vector<uint8_t>* ReturnCallFrameInformation();
316
Brian Carlstrom7940e442013-07-12 13:46:57 -0700317 private:
Vladimir Marko057c74a2013-12-03 15:20:45 +0000318 void EmitPrefix(const X86EncodingMap* entry);
319 void EmitOpcode(const X86EncodingMap* entry);
320 void EmitPrefixAndOpcode(const X86EncodingMap* entry);
321 void EmitDisp(uint8_t base, int disp);
322 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int disp);
323 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale, int disp);
324 void EmitImm(const X86EncodingMap* entry, int imm);
Vladimir Markoa8b4caf2013-10-24 15:08:57 +0100325 void EmitOpRegOpcode(const X86EncodingMap* entry, uint8_t reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700326 void EmitOpReg(const X86EncodingMap* entry, uint8_t reg);
327 void EmitOpMem(const X86EncodingMap* entry, uint8_t base, int disp);
Vladimir Marko057c74a2013-12-03 15:20:45 +0000328 void EmitOpArray(const X86EncodingMap* entry, uint8_t base, uint8_t index,
329 int scale, int disp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700330 void EmitMemReg(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg);
Mark Mendell343adb52013-12-18 06:02:17 -0800331 void EmitMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700332 void EmitRegMem(const X86EncodingMap* entry, uint8_t reg, uint8_t base, int disp);
333 void EmitRegArray(const X86EncodingMap* entry, uint8_t reg, uint8_t base, uint8_t index,
334 int scale, int disp);
335 void EmitArrayReg(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp,
336 uint8_t reg);
337 void EmitRegThread(const X86EncodingMap* entry, uint8_t reg, int disp);
338 void EmitRegReg(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2);
339 void EmitRegRegImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800340 void EmitRegRegImmRev(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm);
341 void EmitRegMemImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int disp, int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700342 void EmitRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
343 void EmitThreadImm(const X86EncodingMap* entry, int disp, int imm);
344 void EmitMovRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
345 void EmitShiftRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800346 void EmitShiftMemCl(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t cl);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700347 void EmitShiftRegCl(const X86EncodingMap* entry, uint8_t reg, uint8_t cl);
348 void EmitRegCond(const X86EncodingMap* entry, uint8_t reg, uint8_t condition);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800349
350 /**
351 * @brief Used for encoding conditional register to register operation.
352 * @param entry The entry in the encoding map for the opcode.
353 * @param reg1 The first physical register.
354 * @param reg2 The second physical register.
355 * @param condition The condition code for operation.
356 */
357 void EmitRegRegCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, uint8_t condition);
358
Brian Carlstrom7940e442013-07-12 13:46:57 -0700359 void EmitJmp(const X86EncodingMap* entry, int rel);
360 void EmitJcc(const X86EncodingMap* entry, int rel, uint8_t cc);
361 void EmitCallMem(const X86EncodingMap* entry, uint8_t base, int disp);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800362 void EmitCallImmediate(const X86EncodingMap* entry, int disp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700363 void EmitCallThread(const X86EncodingMap* entry, int disp);
364 void EmitPcRel(const X86EncodingMap* entry, uint8_t reg, int base_or_table, uint8_t index,
365 int scale, int table_or_disp);
366 void EmitMacro(const X86EncodingMap* entry, uint8_t reg, int offset);
367 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
Mark Mendell412d4f82013-12-18 13:32:36 -0800368 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
369 int64_t val, ConditionCode ccode);
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000370 void OpVectorRegCopyWide(uint8_t fp_reg, uint8_t low_reg, uint8_t high_reg);
371 void GenConstWide(RegLocation rl_dest, int64_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800372
373 /*
Mark Mendell4028a6c2014-02-19 20:06:20 -0800374 * @brief generate inline code for fast case of Strng.indexOf.
375 * @param info Call parameters
376 * @param zero_based 'true' if the index into the string is 0.
377 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
378 * generated.
379 */
380 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
381
382 /*
Mark Mendelle02d48f2014-01-15 11:19:23 -0800383 * @brief Return the correct x86 opcode for the Dex operation
384 * @param op Dex opcode for the operation
385 * @param loc Register location of the operand
386 * @param is_high_op 'true' if this is an operation on the high word
387 * @param value Immediate value for the operation. Used for byte variants
388 * @returns the correct x86 opcode to perform the operation
389 */
390 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
391
392 /*
393 * @brief Return the correct x86 opcode for the Dex operation
394 * @param op Dex opcode for the operation
395 * @param dest location of the destination. May be register or memory.
396 * @param rhs Location for the rhs of the operation. May be in register or memory.
397 * @param is_high_op 'true' if this is an operation on the high word
398 * @returns the correct x86 opcode to perform the operation
399 * @note at most one location may refer to memory
400 */
401 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
402 bool is_high_op);
403
404 /*
405 * @brief Is this operation a no-op for this opcode and value
406 * @param op Dex opcode for the operation
407 * @param value Immediate value for the operation.
408 * @returns 'true' if the operation will have no effect
409 */
410 bool IsNoOp(Instruction::Code op, int32_t value);
411
Mark Mendell2bf31e62014-01-23 12:13:40 -0800412 /**
413 * @brief Calculate magic number and shift for a given divisor
414 * @param divisor divisor number for calculation
415 * @param magic hold calculated magic number
416 * @param shift hold calculated shift
417 */
418 void CalculateMagicAndShift(int divisor, int& magic, int& shift);
419
420 /*
421 * @brief Generate an integer div or rem operation.
422 * @param rl_dest Destination Location.
423 * @param rl_src1 Numerator Location.
424 * @param rl_src2 Divisor Location.
425 * @param is_div 'true' if this is a division, 'false' for a remainder.
426 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
427 */
428 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1,
429 RegLocation rl_src2, bool is_div, bool check_zero);
430
431 /*
432 * @brief Generate an integer div or rem operation by a literal.
433 * @param rl_dest Destination Location.
434 * @param rl_src Numerator Location.
435 * @param lit Divisor.
436 * @param is_div 'true' if this is a division, 'false' for a remainder.
437 */
438 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800439
440 /*
441 * Generate code to implement long shift operations.
442 * @param opcode The DEX opcode to specify the shift type.
443 * @param rl_dest The destination.
444 * @param rl_src The value to be shifted.
445 * @param shift_amount How much to shift.
446 * @returns the RegLocation of the result.
447 */
448 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
449 RegLocation rl_src, int shift_amount);
450 /*
451 * Generate an imul of a register by a constant or a better sequence.
452 * @param dest Destination Register.
453 * @param src Source Register.
454 * @param val Constant multiplier.
455 */
456 void GenImulRegImm(int dest, int src, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800457
Mark Mendell4708dcd2014-01-22 09:05:18 -0800458 /*
459 * Generate an imul of a memory location by a constant or a better sequence.
460 * @param dest Destination Register.
461 * @param sreg Symbolic register.
462 * @param displacement Displacement on stack of Symbolic Register.
463 * @param val Constant multiplier.
464 */
465 void GenImulMemImm(int dest, int sreg, int displacement, int val);
Mark Mendell766e9292014-01-27 07:55:47 -0800466
467 /*
468 * @brief Compare memory to immediate, and branch if condition true.
469 * @param cond The condition code that when true will branch to the target.
470 * @param temp_reg A temporary register that can be used if compare memory is not
471 * supported by the architecture.
472 * @param base_reg The register holding the base address.
473 * @param offset The offset from the base.
474 * @param check_value The immediate to compare to.
475 */
476 LIR* OpCmpMemImmBranch(ConditionCode cond, int temp_reg, int base_reg,
477 int offset, int check_value, LIR* target);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800478
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800479 /*
480 * Can this operation be using core registers without temporaries?
481 * @param rl_lhs Left hand operand.
482 * @param rl_rhs Right hand operand.
483 * @returns 'true' if the operation can proceed without needing temporary regs.
484 */
485 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Mark Mendell67c39c42014-01-31 17:28:00 -0800486
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800487 /**
488 * @brief Generates inline code for conversion of long to FP by using x87/
489 * @param rl_dest The destination of the FP.
490 * @param rl_src The source of the long.
491 * @param is_double 'true' if dealing with double, 'false' for float.
492 */
493 void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
494
Mark Mendell67c39c42014-01-31 17:28:00 -0800495 /*
496 * @brief Perform MIR analysis before compiling method.
497 * @note Invokes Mir2LiR::Materialize after analysis.
498 */
499 void Materialize();
500
501 /*
502 * @brief Analyze MIR before generating code, to prepare for the code generation.
503 */
504 void AnalyzeMIR();
505
506 /*
507 * @brief Analyze one basic block.
508 * @param bb Basic block to analyze.
509 */
510 void AnalyzeBB(BasicBlock * bb);
511
512 /*
513 * @brief Analyze one extended MIR instruction
514 * @param opcode MIR instruction opcode.
515 * @param bb Basic block containing instruction.
516 * @param mir Extended instruction to analyze.
517 */
518 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
519
520 /*
521 * @brief Analyze one MIR instruction
522 * @param opcode MIR instruction opcode.
523 * @param bb Basic block containing instruction.
524 * @param mir Instruction to analyze.
525 */
526 void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
527
528 /*
529 * @brief Analyze one MIR float/double instruction
530 * @param opcode MIR instruction opcode.
531 * @param bb Basic block containing instruction.
532 * @param mir Instruction to analyze.
533 */
534 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
535
536 /*
537 * @brief Analyze one use of a double operand.
538 * @param rl_use Double RegLocation for the operand.
539 */
540 void AnalyzeDoubleUse(RegLocation rl_use);
541
542 // Information derived from analysis of MIR
543
Mark Mendell55d0eac2014-02-06 11:02:52 -0800544 // The compiler temporary for the code address of the method.
545 CompilerTemp *base_of_code_;
546
Mark Mendell67c39c42014-01-31 17:28:00 -0800547 // Have we decided to compute a ptr to code and store in temporary VR?
548 bool store_method_addr_;
549
Mark Mendell55d0eac2014-02-06 11:02:52 -0800550 // Have we used the stored method address?
551 bool store_method_addr_used_;
552
553 // Instructions to remove if we didn't use the stored method address.
554 LIR* setup_method_address_[2];
555
556 // Instructions needing patching with Method* values.
557 GrowableArray<LIR*> method_address_insns_;
558
559 // Instructions needing patching with Class Type* values.
560 GrowableArray<LIR*> class_type_address_insns_;
561
562 // Instructions needing patching with PC relative code addresses.
563 GrowableArray<LIR*> call_method_insns_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800564
565 // Prologue decrement of stack pointer.
566 LIR* stack_decrement_;
567
568 // Epilogue increment of stack pointer.
569 LIR* stack_increment_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700570};
571
572} // namespace art
573
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700574#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_