blob: 421d51e4fd40e045a1795458d5f4711418b8d010 [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);
52 int AllocTypedTempPair(bool fp_hint, int reg_class);
53 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
Brian Carlstrom7940e442013-07-12 13:46:57 -0700305 private:
Vladimir Marko057c74a2013-12-03 15:20:45 +0000306 void EmitPrefix(const X86EncodingMap* entry);
307 void EmitOpcode(const X86EncodingMap* entry);
308 void EmitPrefixAndOpcode(const X86EncodingMap* entry);
309 void EmitDisp(uint8_t base, int disp);
310 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int disp);
311 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale, int disp);
312 void EmitImm(const X86EncodingMap* entry, int imm);
Vladimir Markoa8b4caf2013-10-24 15:08:57 +0100313 void EmitOpRegOpcode(const X86EncodingMap* entry, uint8_t reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700314 void EmitOpReg(const X86EncodingMap* entry, uint8_t reg);
315 void EmitOpMem(const X86EncodingMap* entry, uint8_t base, int disp);
Vladimir Marko057c74a2013-12-03 15:20:45 +0000316 void EmitOpArray(const X86EncodingMap* entry, uint8_t base, uint8_t index,
317 int scale, int disp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700318 void EmitMemReg(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg);
Mark Mendell343adb52013-12-18 06:02:17 -0800319 void EmitMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700320 void EmitRegMem(const X86EncodingMap* entry, uint8_t reg, uint8_t base, int disp);
321 void EmitRegArray(const X86EncodingMap* entry, uint8_t reg, uint8_t base, uint8_t index,
322 int scale, int disp);
323 void EmitArrayReg(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp,
324 uint8_t reg);
325 void EmitRegThread(const X86EncodingMap* entry, uint8_t reg, int disp);
326 void EmitRegReg(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2);
327 void EmitRegRegImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800328 void EmitRegRegImmRev(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm);
329 void EmitRegMemImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int disp, int32_t imm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700330 void EmitRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
331 void EmitThreadImm(const X86EncodingMap* entry, int disp, int imm);
332 void EmitMovRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
333 void EmitShiftRegImm(const X86EncodingMap* entry, uint8_t reg, int imm);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800334 void EmitShiftMemCl(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t cl);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700335 void EmitShiftRegCl(const X86EncodingMap* entry, uint8_t reg, uint8_t cl);
336 void EmitRegCond(const X86EncodingMap* entry, uint8_t reg, uint8_t condition);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800337
338 /**
339 * @brief Used for encoding conditional register to register operation.
340 * @param entry The entry in the encoding map for the opcode.
341 * @param reg1 The first physical register.
342 * @param reg2 The second physical register.
343 * @param condition The condition code for operation.
344 */
345 void EmitRegRegCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, uint8_t condition);
346
Brian Carlstrom7940e442013-07-12 13:46:57 -0700347 void EmitJmp(const X86EncodingMap* entry, int rel);
348 void EmitJcc(const X86EncodingMap* entry, int rel, uint8_t cc);
349 void EmitCallMem(const X86EncodingMap* entry, uint8_t base, int disp);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800350 void EmitCallImmediate(const X86EncodingMap* entry, int disp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700351 void EmitCallThread(const X86EncodingMap* entry, int disp);
352 void EmitPcRel(const X86EncodingMap* entry, uint8_t reg, int base_or_table, uint8_t index,
353 int scale, int table_or_disp);
354 void EmitMacro(const X86EncodingMap* entry, uint8_t reg, int offset);
355 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
Mark Mendell412d4f82013-12-18 13:32:36 -0800356 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
357 int64_t val, ConditionCode ccode);
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000358 void OpVectorRegCopyWide(uint8_t fp_reg, uint8_t low_reg, uint8_t high_reg);
359 void GenConstWide(RegLocation rl_dest, int64_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800360
361 /*
Mark Mendell4028a6c2014-02-19 20:06:20 -0800362 * @brief generate inline code for fast case of Strng.indexOf.
363 * @param info Call parameters
364 * @param zero_based 'true' if the index into the string is 0.
365 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
366 * generated.
367 */
368 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
369
370 /*
Mark Mendelle02d48f2014-01-15 11:19:23 -0800371 * @brief Return the correct x86 opcode for the Dex operation
372 * @param op Dex opcode for the operation
373 * @param loc Register location of the operand
374 * @param is_high_op 'true' if this is an operation on the high word
375 * @param value Immediate value for the operation. Used for byte variants
376 * @returns the correct x86 opcode to perform the operation
377 */
378 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
379
380 /*
381 * @brief Return the correct x86 opcode for the Dex operation
382 * @param op Dex opcode for the operation
383 * @param dest location of the destination. May be register or memory.
384 * @param rhs Location for the rhs of the operation. May be in register or memory.
385 * @param is_high_op 'true' if this is an operation on the high word
386 * @returns the correct x86 opcode to perform the operation
387 * @note at most one location may refer to memory
388 */
389 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
390 bool is_high_op);
391
392 /*
393 * @brief Is this operation a no-op for this opcode and value
394 * @param op Dex opcode for the operation
395 * @param value Immediate value for the operation.
396 * @returns 'true' if the operation will have no effect
397 */
398 bool IsNoOp(Instruction::Code op, int32_t value);
399
Mark Mendell2bf31e62014-01-23 12:13:40 -0800400 /**
401 * @brief Calculate magic number and shift for a given divisor
402 * @param divisor divisor number for calculation
403 * @param magic hold calculated magic number
404 * @param shift hold calculated shift
405 */
406 void CalculateMagicAndShift(int divisor, int& magic, int& shift);
407
408 /*
409 * @brief Generate an integer div or rem operation.
410 * @param rl_dest Destination Location.
411 * @param rl_src1 Numerator Location.
412 * @param rl_src2 Divisor Location.
413 * @param is_div 'true' if this is a division, 'false' for a remainder.
414 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
415 */
416 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1,
417 RegLocation rl_src2, bool is_div, bool check_zero);
418
419 /*
420 * @brief Generate an integer div or rem operation by a literal.
421 * @param rl_dest Destination Location.
422 * @param rl_src Numerator Location.
423 * @param lit Divisor.
424 * @param is_div 'true' if this is a division, 'false' for a remainder.
425 */
426 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800427
428 /*
429 * Generate code to implement long shift operations.
430 * @param opcode The DEX opcode to specify the shift type.
431 * @param rl_dest The destination.
432 * @param rl_src The value to be shifted.
433 * @param shift_amount How much to shift.
434 * @returns the RegLocation of the result.
435 */
436 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
437 RegLocation rl_src, int shift_amount);
438 /*
439 * Generate an imul of a register by a constant or a better sequence.
440 * @param dest Destination Register.
441 * @param src Source Register.
442 * @param val Constant multiplier.
443 */
444 void GenImulRegImm(int dest, int src, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800445
Mark Mendell4708dcd2014-01-22 09:05:18 -0800446 /*
447 * Generate an imul of a memory location by a constant or a better sequence.
448 * @param dest Destination Register.
449 * @param sreg Symbolic register.
450 * @param displacement Displacement on stack of Symbolic Register.
451 * @param val Constant multiplier.
452 */
453 void GenImulMemImm(int dest, int sreg, int displacement, int val);
Mark Mendell766e9292014-01-27 07:55:47 -0800454
455 /*
456 * @brief Compare memory to immediate, and branch if condition true.
457 * @param cond The condition code that when true will branch to the target.
458 * @param temp_reg A temporary register that can be used if compare memory is not
459 * supported by the architecture.
460 * @param base_reg The register holding the base address.
461 * @param offset The offset from the base.
462 * @param check_value The immediate to compare to.
463 */
464 LIR* OpCmpMemImmBranch(ConditionCode cond, int temp_reg, int base_reg,
465 int offset, int check_value, LIR* target);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800466
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800467 /*
468 * Can this operation be using core registers without temporaries?
469 * @param rl_lhs Left hand operand.
470 * @param rl_rhs Right hand operand.
471 * @returns 'true' if the operation can proceed without needing temporary regs.
472 */
473 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Mark Mendell67c39c42014-01-31 17:28:00 -0800474
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800475 /**
476 * @brief Generates inline code for conversion of long to FP by using x87/
477 * @param rl_dest The destination of the FP.
478 * @param rl_src The source of the long.
479 * @param is_double 'true' if dealing with double, 'false' for float.
480 */
481 void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
482
Mark Mendell67c39c42014-01-31 17:28:00 -0800483 /*
484 * @brief Perform MIR analysis before compiling method.
485 * @note Invokes Mir2LiR::Materialize after analysis.
486 */
487 void Materialize();
488
489 /*
490 * @brief Analyze MIR before generating code, to prepare for the code generation.
491 */
492 void AnalyzeMIR();
493
494 /*
495 * @brief Analyze one basic block.
496 * @param bb Basic block to analyze.
497 */
498 void AnalyzeBB(BasicBlock * bb);
499
500 /*
501 * @brief Analyze one extended MIR instruction
502 * @param opcode MIR instruction opcode.
503 * @param bb Basic block containing instruction.
504 * @param mir Extended instruction to analyze.
505 */
506 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
507
508 /*
509 * @brief Analyze one MIR instruction
510 * @param opcode MIR instruction opcode.
511 * @param bb Basic block containing instruction.
512 * @param mir Instruction to analyze.
513 */
514 void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
515
516 /*
517 * @brief Analyze one MIR float/double instruction
518 * @param opcode MIR instruction opcode.
519 * @param bb Basic block containing instruction.
520 * @param mir Instruction to analyze.
521 */
522 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
523
524 /*
525 * @brief Analyze one use of a double operand.
526 * @param rl_use Double RegLocation for the operand.
527 */
528 void AnalyzeDoubleUse(RegLocation rl_use);
529
530 // Information derived from analysis of MIR
531
Mark Mendell55d0eac2014-02-06 11:02:52 -0800532 // The compiler temporary for the code address of the method.
533 CompilerTemp *base_of_code_;
534
Mark Mendell67c39c42014-01-31 17:28:00 -0800535 // Have we decided to compute a ptr to code and store in temporary VR?
536 bool store_method_addr_;
537
Mark Mendell55d0eac2014-02-06 11:02:52 -0800538 // Have we used the stored method address?
539 bool store_method_addr_used_;
540
541 // Instructions to remove if we didn't use the stored method address.
542 LIR* setup_method_address_[2];
543
544 // Instructions needing patching with Method* values.
545 GrowableArray<LIR*> method_address_insns_;
546
547 // Instructions needing patching with Class Type* values.
548 GrowableArray<LIR*> class_type_address_insns_;
549
550 // Instructions needing patching with PC relative code addresses.
551 GrowableArray<LIR*> call_method_insns_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700552};
553
554} // namespace art
555
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700556#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_