blob: e40d45e99a4d63444122027f57e2fe2a17af451c [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_
18#define ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
20#include "dex/compiler_internals.h"
21#include "x86_lir.h"
22
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070023#include <map>
24
Brian Carlstrom7940e442013-07-12 13:46:57 -070025namespace art {
26
Mark Mendelle87f9b52014-04-30 14:13:18 -040027class X86Mir2Lir : public Mir2Lir {
Ian Rogers0f9b9c52014-06-09 01:32:12 -070028 protected:
29 class InToRegStorageMapper {
30 public:
Serguei Katkov407a9d22014-07-05 03:09:32 +070031 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref) = 0;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070032 virtual ~InToRegStorageMapper() {}
33 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070034
Ian Rogers0f9b9c52014-06-09 01:32:12 -070035 class InToRegStorageX86_64Mapper : public InToRegStorageMapper {
36 public:
Chao-ying Fua77ee512014-07-01 17:43:41 -070037 explicit InToRegStorageX86_64Mapper(Mir2Lir* ml) : ml_(ml), cur_core_reg_(0), cur_fp_reg_(0) {}
Ian Rogers0f9b9c52014-06-09 01:32:12 -070038 virtual ~InToRegStorageX86_64Mapper() {}
Serguei Katkov407a9d22014-07-05 03:09:32 +070039 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref);
Chao-ying Fua77ee512014-07-01 17:43:41 -070040 protected:
41 Mir2Lir* ml_;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070042 private:
43 int cur_core_reg_;
44 int cur_fp_reg_;
45 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070046
Ian Rogers0f9b9c52014-06-09 01:32:12 -070047 class InToRegStorageMapping {
48 public:
49 InToRegStorageMapping() : max_mapped_in_(0), is_there_stack_mapped_(false),
50 initialized_(false) {}
51 void Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper);
52 int GetMaxMappedIn() { return max_mapped_in_; }
53 bool IsThereStackMapped() { return is_there_stack_mapped_; }
54 RegStorage Get(int in_position);
55 bool IsInitialized() { return initialized_; }
56 private:
57 std::map<int, RegStorage> mapping_;
58 int max_mapped_in_;
59 bool is_there_stack_mapped_;
60 bool initialized_;
61 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070062
Ian Rogers0f9b9c52014-06-09 01:32:12 -070063 public:
Elena Sayapinadd644502014-07-01 18:39:52 +070064 X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
Brian Carlstrom7940e442013-07-12 13:46:57 -070065
Ian Rogers0f9b9c52014-06-09 01:32:12 -070066 // Required for target - codegen helpers.
67 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
68 RegLocation rl_dest, int lit);
69 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
70 LIR* CheckSuspendUsingLoad() OVERRIDE;
71 RegStorage LoadHelper(ThreadOffset<4> offset) OVERRIDE;
72 RegStorage LoadHelper(ThreadOffset<8> offset) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070073 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
Andreas Gampe3c12c512014-06-24 18:46:29 +000074 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070075 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010076 OpSize size) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070077 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
78 RegStorage r_dest, OpSize size) OVERRIDE;
79 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
80 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
Ian Rogers0f9b9c52014-06-09 01:32:12 -070081 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src,
Andreas Gampe3c12c512014-06-24 18:46:29 +000082 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070083 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
84 OpSize size) OVERRIDE;
85 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
86 RegStorage r_src, OpSize size) OVERRIDE;
87 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg);
Dave Allison7fb36de2014-07-10 02:05:10 +000088 void GenImplicitNullCheck(RegStorage reg, int opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -070089
Ian Rogers0f9b9c52014-06-09 01:32:12 -070090 // Required for target - register utilities.
Chao-ying Fua77ee512014-07-01 17:43:41 -070091 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
92 RegStorage TargetReg32(SpecialTargetRegister reg);
93 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, bool is_wide) OVERRIDE {
94 RegStorage reg = TargetReg32(symbolic_reg);
95 if (is_wide) {
96 return (reg.Is64Bit()) ? reg : As64BitReg(reg);
97 } else {
98 return (reg.Is32Bit()) ? reg : As32BitReg(reg);
99 }
100 }
101 RegStorage TargetRefReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
102 return TargetReg(symbolic_reg, cu_->target64);
103 }
104 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
105 return TargetReg(symbolic_reg, cu_->target64);
106 }
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700107 RegStorage GetArgMappingToPhysicalReg(int arg_num);
108 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
109 RegLocation GetReturnAlt();
110 RegLocation GetReturnWideAlt();
111 RegLocation LocCReturn();
112 RegLocation LocCReturnRef();
113 RegLocation LocCReturnDouble();
114 RegLocation LocCReturnFloat();
115 RegLocation LocCReturnWide();
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100116 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700117 void AdjustSpillMask();
118 void ClobberCallerSave();
119 void FreeCallTemps();
120 void LockCallTemps();
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700121 void CompilerInitializeRegAlloc();
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700122 int VectorRegisterSize();
123 int NumReservableVectorRegisters(bool fp_used);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700124
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700125 // Required for target - miscellaneous.
126 void AssembleLIR();
127 int AssignInsnOffsets();
128 void AssignOffsets();
129 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100130 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
131 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
132 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700133 const char* GetTargetInstFmt(int opcode);
134 const char* GetTargetInstName(int opcode);
135 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100136 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700137 uint64_t GetTargetInstFlags(int opcode);
Ian Rogers5aa6e042014-06-13 16:38:24 -0700138 size_t GetInsnSize(LIR* lir) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700139 bool IsUnconditionalBranch(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700141 // Check support for volatile load/store of a given size.
142 bool SupportsVolatileLoadStore(OpSize size) OVERRIDE;
143 // Get the register class for load/store of a field.
144 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100145
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700146 // Required for target - Dalvik-level generators.
147 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
buzbee2700f7e2014-03-07 09:46:20 -0800148 RegLocation rl_src2);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700149 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
150 RegLocation rl_dest, int scale);
151 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
152 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark);
153 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
154 RegLocation rl_src1, RegLocation rl_shift);
155 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
buzbee2700f7e2014-03-07 09:46:20 -0800156 RegLocation rl_src2);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700157 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
158 RegLocation rl_src2);
159 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
160 RegLocation rl_src2);
161 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
162 RegLocation rl_src2);
163 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
164 RegLocation rl_src2);
Alexei Zavjalovbd3682e2014-06-12 03:08:01 +0700165 void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700166 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
167 RegLocation rl_src2);
168 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
169 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100170 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700171 bool GenInlinedSqrt(CallInfo* info);
Yixin Shou7071c8d2014-03-05 06:07:48 -0500172 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
173 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700174 bool GenInlinedPeek(CallInfo* info, OpSize size);
175 bool GenInlinedPoke(CallInfo* info, OpSize size);
176 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
177 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
178 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
179 RegLocation rl_src2);
180 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
181 RegLocation rl_src2);
182 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
183 RegLocation rl_src2);
184 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
185 RegLocation rl_src2, bool is_div);
186 // TODO: collapse reg_lo, reg_hi
187 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
188 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
189 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
190 void GenDivZeroCheckWide(RegStorage reg);
191 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
192 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
193 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
194 void GenExitSequence();
195 void GenSpecialExitSequence();
196 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
197 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
198 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
199 void GenSelect(BasicBlock* bb, MIR* mir);
200 bool GenMemBarrier(MemBarrierKind barrier_kind);
201 void GenMoveException(RegLocation rl_dest);
202 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
203 int first_bit, int second_bit);
204 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
205 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
206 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
207 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
208 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800209
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700210 /*
211 * @brief Generate a two address long operation with a constant value
212 * @param rl_dest location of result
213 * @param rl_src constant source operand
214 * @param op Opcode to be generated
215 * @return success or not
216 */
217 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
218 /*
219 * @brief Generate a three address long operation with a constant value
220 * @param rl_dest location of result
221 * @param rl_src1 source operand
222 * @param rl_src2 constant source operand
223 * @param op Opcode to be generated
224 * @return success or not
225 */
226 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
227 Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800228
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700229 /**
230 * @brief Generate a long arithmetic operation.
231 * @param rl_dest The destination.
232 * @param rl_src1 First operand.
233 * @param rl_src2 Second operand.
234 * @param op The DEX opcode for the operation.
235 * @param is_commutative The sources can be swapped if needed.
236 */
237 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
238 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800239
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700240 /**
241 * @brief Generate a two operand long arithmetic operation.
242 * @param rl_dest The destination.
243 * @param rl_src Second operand.
244 * @param op The DEX opcode for the operation.
245 */
246 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800247
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700248 /**
249 * @brief Generate a long operation.
250 * @param rl_dest The destination. Must be in a register
251 * @param rl_src The other operand. May be in a register or in memory.
252 * @param op The DEX opcode for the operation.
253 */
254 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700255
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700256 /**
257 * @brief Implement instanceof a final class with x86 specific code.
258 * @param use_declaring_class 'true' if we can use the class itself.
259 * @param type_idx Type index to use if use_declaring_class is 'false'.
260 * @param rl_dest Result to be set to 0 or 1.
261 * @param rl_src Object to be tested.
262 */
263 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
264 RegLocation rl_src);
265 /*
266 *
267 * @brief Implement Set up instanceof a class with x86 specific code.
268 * @param needs_access_check 'true' if we must check the access.
269 * @param type_known_final 'true' if the type is known to be a final class.
270 * @param type_known_abstract 'true' if the type is known to be an abstract class.
271 * @param use_declaring_class 'true' if the type can be loaded off the current Method*.
272 * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache.
273 * @param type_idx Type index to use if use_declaring_class is 'false'.
274 * @param rl_dest Result to be set to 0 or 1.
275 * @param rl_src Object to be tested.
276 */
277 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
278 bool type_known_abstract, bool use_declaring_class,
279 bool can_assume_type_is_in_dex_cache,
280 uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src);
Mark Mendell6607d972014-02-10 06:54:18 -0800281
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700282 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
283 RegLocation rl_src1, RegLocation rl_shift);
Chao-ying Fua0147762014-06-06 18:38:49 -0700284
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700285 // Single operation generators.
286 LIR* OpUnconditionalBranch(LIR* target);
287 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
288 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
289 LIR* OpCondBranch(ConditionCode cc, LIR* target);
290 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
291 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
292 LIR* OpIT(ConditionCode cond, const char* guide);
293 void OpEndIT(LIR* it);
294 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
295 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
296 LIR* OpReg(OpKind op, RegStorage r_dest_src);
297 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
298 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
299 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
300 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
301 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
302 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
303 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
304 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
305 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
306 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
307 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
308 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
309 LIR* OpTestSuspend(LIR* target);
310 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
311 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
312 LIR* OpVldm(RegStorage r_base, int count);
313 LIR* OpVstm(RegStorage r_base, int count);
314 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
315 void OpRegCopyWide(RegStorage dest, RegStorage src);
316 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
317 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700318
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700319 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
320 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
321 void SpillCoreRegs();
322 void UnSpillCoreRegs();
Serguei Katkovc3801912014-07-08 17:21:53 +0700323 void UnSpillFPRegs();
324 void SpillFPRegs();
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700325 static const X86EncodingMap EncodingMap[kX86Last];
326 bool InexpensiveConstantInt(int32_t value);
327 bool InexpensiveConstantFloat(int32_t value);
328 bool InexpensiveConstantLong(int64_t value);
329 bool InexpensiveConstantDouble(int64_t value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700330
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700331 /*
332 * @brief Should try to optimize for two address instructions?
333 * @return true if we try to avoid generating three operand instructions.
334 */
335 virtual bool GenerateTwoOperandInstructions() const { return true; }
Mark Mendelle87f9b52014-04-30 14:13:18 -0400336
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700337 /*
338 * @brief x86 specific codegen for int operations.
339 * @param opcode Operation to perform.
340 * @param rl_dest Destination for the result.
341 * @param rl_lhs Left hand operand.
342 * @param rl_rhs Right hand operand.
343 */
344 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
345 RegLocation rl_rhs);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800346
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700347 /*
348 * @brief Dump a RegLocation using printf
349 * @param loc Register location to dump
350 */
351 static void DumpRegLocation(RegLocation loc);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800352
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700353 /*
354 * @brief Load the Method* of a dex method into the register.
355 * @param target_method The MethodReference of the method to be invoked.
356 * @param type How the method will be invoked.
357 * @param register that will contain the code address.
358 * @note register will be passed to TargetReg to get physical register.
359 */
360 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
361 SpecialTargetRegister symbolic_reg);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800362
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700363 /*
364 * @brief Load the Class* of a Dex Class type into the register.
365 * @param type How the method will be invoked.
366 * @param register that will contain the code address.
367 * @note register will be passed to TargetReg to get physical register.
368 */
369 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800370
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700371 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700372
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700373 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700374 NextCallInsn next_call_insn,
375 const MethodReference& target_method,
376 uint32_t vtable_idx,
377 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
378 bool skip_this);
379
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700380 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
381 NextCallInsn next_call_insn,
382 const MethodReference& target_method,
383 uint32_t vtable_idx,
384 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
385 bool skip_this);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800386
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700387 /*
388 * @brief Generate a relative call to the method that will be patched at link time.
389 * @param target_method The MethodReference of the method to be invoked.
390 * @param type How the method will be invoked.
391 * @returns Call instruction
392 */
393 virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800394
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700395 /*
396 * @brief Handle x86 specific literals
397 */
398 void InstallLiteralPools();
Mark Mendellae9fd932014-02-10 16:14:35 -0800399
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700400 /*
401 * @brief Generate the debug_frame CFI information.
402 * @returns pointer to vector containing CFE information
403 */
404 static std::vector<uint8_t>* ReturnCommonCallFrameInformation();
Mark Mendellae9fd932014-02-10 16:14:35 -0800405
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700406 /*
407 * @brief Generate the debug_frame FDE information.
408 * @returns pointer to vector containing CFE information
409 */
410 std::vector<uint8_t>* ReturnCallFrameInformation();
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800411
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700412 protected:
Chao-ying Fua77ee512014-07-01 17:43:41 -0700413 // Casting of RegStorage
414 RegStorage As32BitReg(RegStorage reg) {
415 DCHECK(!reg.IsPair());
416 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
417 if (kFailOnSizeError) {
418 LOG(FATAL) << "Expected 64b register " << reg.GetReg();
419 } else {
420 LOG(WARNING) << "Expected 64b register " << reg.GetReg();
421 return reg;
422 }
423 }
424 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
425 reg.GetRawBits() & RegStorage::kRegTypeMask);
426 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
427 ->GetReg().GetReg(),
428 ret_val.GetReg());
429 return ret_val;
430 }
431
432 RegStorage As64BitReg(RegStorage reg) {
433 DCHECK(!reg.IsPair());
434 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
435 if (kFailOnSizeError) {
436 LOG(FATAL) << "Expected 32b register " << reg.GetReg();
437 } else {
438 LOG(WARNING) << "Expected 32b register " << reg.GetReg();
439 return reg;
440 }
441 }
442 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
443 reg.GetRawBits() & RegStorage::kRegTypeMask);
444 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
445 ->GetReg().GetReg(),
446 ret_val.GetReg());
447 return ret_val;
448 }
449
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700450 size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700451 int32_t raw_base, int32_t displacement);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700452 void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg);
453 void EmitPrefix(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700454 int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700455 void EmitOpcode(const X86EncodingMap* entry);
456 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700457 int32_t reg_r, int32_t reg_x, int32_t reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700458 void EmitDisp(uint8_t base, int32_t disp);
459 void EmitModrmThread(uint8_t reg_or_opcode);
460 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp);
461 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale,
462 int32_t disp);
463 void EmitImm(const X86EncodingMap* entry, int64_t imm);
464 void EmitNullary(const X86EncodingMap* entry);
465 void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg);
466 void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg);
467 void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
468 void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
469 int32_t disp);
470 void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg);
471 void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp);
472 void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base,
473 int32_t raw_index, int scale, int32_t disp);
474 void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
475 int32_t disp, int32_t raw_reg);
476 void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
477 void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
478 int32_t raw_disp, int32_t imm);
479 void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp);
480 void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2);
481 void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm);
482 void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
483 int32_t imm);
484 void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1,
485 int32_t imm);
486 void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
487 void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm);
488 void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm);
489 void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
490 void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl);
491 void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl);
492 void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
493 void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc);
494 void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc);
495 void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc);
496 void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
497 int32_t cc);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800498
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700499 void EmitJmp(const X86EncodingMap* entry, int32_t rel);
500 void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc);
501 void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
502 void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp);
503 void EmitCallThread(const X86EncodingMap* entry, int32_t disp);
504 void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table,
505 int32_t raw_index, int scale, int32_t table_or_disp);
506 void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset);
507 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
508 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
509 int64_t val, ConditionCode ccode);
510 void GenConstWide(RegLocation rl_dest, int64_t value);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700511 void GenMultiplyVectorSignedByte(BasicBlock *bb, MIR *mir);
512 void GenShiftByteVector(BasicBlock *bb, MIR *mir);
513 void AndMaskVectorRegister(RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
514 void MaskVectorRegister(X86OpCode opcode, RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
515 void AppendOpcodeWithConst(X86OpCode opcode, int reg, MIR* mir);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400516
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700517 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800518
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700519 /*
520 * @brief Ensure that a temporary register is byte addressable.
521 * @returns a temporary guarenteed to be byte addressable.
522 */
523 virtual RegStorage AllocateByteRegister();
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800524
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700525 /*
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700526 * @brief Use a wide temporary as a 128-bit register
527 * @returns a 128-bit temporary register.
528 */
529 virtual RegStorage Get128BitRegister(RegStorage reg);
530
531 /*
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700532 * @brief Check if a register is byte addressable.
533 * @returns true if a register is byte addressable.
534 */
535 bool IsByteRegister(RegStorage reg);
DaniilSokolov70c4f062014-06-24 17:34:00 -0700536 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700537
538 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700539 * @brief generate inline code for fast case of Strng.indexOf.
540 * @param info Call parameters
541 * @param zero_based 'true' if the index into the string is 0.
542 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
543 * generated.
544 */
545 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
Mark Mendelle87f9b52014-04-30 14:13:18 -0400546
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700547 /**
548 * @brief Reserve a fixed number of vector registers from the register pool
549 * @details The mir->dalvikInsn.vA specifies an N such that vector registers
550 * [0..N-1] are removed from the temporary pool. The caller must call
551 * ReturnVectorRegisters before calling ReserveVectorRegisters again.
552 * Also sets the num_reserved_vector_regs_ to the specified value
553 * @param mir whose vA specifies the number of registers to reserve
554 */
555 void ReserveVectorRegisters(MIR* mir);
556
557 /**
558 * @brief Return all the reserved vector registers to the temp pool
559 * @details Returns [0..num_reserved_vector_regs_]
560 */
561 void ReturnVectorRegisters();
562
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700563 /*
564 * @brief Load 128 bit constant into vector register.
565 * @param bb The basic block in which the MIR is from.
566 * @param mir The MIR whose opcode is kMirConstVector
567 * @note vA is the TypeSize for the register.
568 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
569 */
570 void GenConst128(BasicBlock* bb, MIR* mir);
Mark Mendell4028a6c2014-02-19 20:06:20 -0800571
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700572 /*
573 * @brief MIR to move a vectorized register to another.
574 * @param bb The basic block in which the MIR is from.
575 * @param mir The MIR whose opcode is kMirConstVector.
576 * @note vA: TypeSize
577 * @note vB: destination
578 * @note vC: source
579 */
580 void GenMoveVector(BasicBlock *bb, MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400581
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700582 /*
583 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know the type of the vector.
584 * @param bb The basic block in which the MIR is from.
585 * @param mir The MIR whose opcode is kMirConstVector.
586 * @note vA: TypeSize
587 * @note vB: destination and source
588 * @note vC: source
589 */
590 void GenMultiplyVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400591
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700592 /*
593 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the type of the vector.
594 * @param bb The basic block in which the MIR is from.
595 * @param mir The MIR whose opcode is kMirConstVector.
596 * @note vA: TypeSize
597 * @note vB: destination and source
598 * @note vC: source
599 */
600 void GenAddVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400601
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700602 /*
603 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the type of the vector.
604 * @param bb The basic block in which the MIR is from.
605 * @param mir The MIR whose opcode is kMirConstVector.
606 * @note vA: TypeSize
607 * @note vB: destination and source
608 * @note vC: source
609 */
610 void GenSubtractVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400611
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700612 /*
613 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the type of the vector.
614 * @param bb The basic block in which the MIR is from.
615 * @param mir The MIR whose opcode is kMirConstVector.
616 * @note vA: TypeSize
617 * @note vB: destination and source
618 * @note vC: immediate
619 */
620 void GenShiftLeftVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400621
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700622 /*
623 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to know the type of the vector.
624 * @param bb The basic block in which the MIR is from.
625 * @param mir The MIR whose opcode is kMirConstVector.
626 * @note vA: TypeSize
627 * @note vB: destination and source
628 * @note vC: immediate
629 */
630 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400631
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700632 /*
633 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA to know the type of the vector.
634 * @param bb The basic block in which the MIR is from..
635 * @param mir The MIR whose opcode is kMirConstVector.
636 * @note vA: TypeSize
637 * @note vB: destination and source
638 * @note vC: immediate
639 */
640 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400641
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700642 /*
643 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the type of the vector.
644 * @note vA: TypeSize
645 * @note vB: destination and source
646 * @note vC: source
647 */
648 void GenAndVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400649
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700650 /*
651 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the type of the vector.
652 * @param bb The basic block in which the MIR is from.
653 * @param mir The MIR whose opcode is kMirConstVector.
654 * @note vA: TypeSize
655 * @note vB: destination and source
656 * @note vC: source
657 */
658 void GenOrVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400659
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700660 /*
661 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the type of the vector.
662 * @param bb The basic block in which the MIR is from.
663 * @param mir The MIR whose opcode is kMirConstVector.
664 * @note vA: TypeSize
665 * @note vB: destination and source
666 * @note vC: source
667 */
668 void GenXorVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400669
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700670 /*
671 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
672 * @param bb The basic block in which the MIR is from.
673 * @param mir The MIR whose opcode is kMirConstVector.
674 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
675 * @note vA: TypeSize
676 * @note vB: destination and source VR (not vector register)
677 * @note vC: source (vector register)
678 */
679 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400680
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700681 /*
682 * @brief Extract a packed element into a single VR.
683 * @param bb The basic block in which the MIR is from.
684 * @param mir The MIR whose opcode is kMirConstVector.
685 * @note vA: TypeSize
686 * @note vB: destination VR (not vector register)
687 * @note vC: source (vector register)
688 * @note arg[0]: The index to use for extraction from vector register (which packed element).
689 */
690 void GenReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400691
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700692 /*
693 * @brief Create a vector value, with all TypeSize values equal to vC
694 * @param bb The basic block in which the MIR is from.
695 * @param mir The MIR whose opcode is kMirConstVector.
696 * @note vA: TypeSize.
697 * @note vB: destination vector register.
698 * @note vC: source VR (not vector register).
699 */
700 void GenSetVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400701
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700702 /*
703 * @brief Generate code for a vector opcode.
704 * @param bb The basic block in which the MIR is from.
705 * @param mir The MIR whose opcode is a non-standard opcode.
706 */
707 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400708
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700709 /*
710 * @brief Return the correct x86 opcode for the Dex operation
711 * @param op Dex opcode for the operation
712 * @param loc Register location of the operand
713 * @param is_high_op 'true' if this is an operation on the high word
714 * @param value Immediate value for the operation. Used for byte variants
715 * @returns the correct x86 opcode to perform the operation
716 */
717 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400718
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700719 /*
720 * @brief Return the correct x86 opcode for the Dex operation
721 * @param op Dex opcode for the operation
722 * @param dest location of the destination. May be register or memory.
723 * @param rhs Location for the rhs of the operation. May be in register or memory.
724 * @param is_high_op 'true' if this is an operation on the high word
725 * @returns the correct x86 opcode to perform the operation
726 * @note at most one location may refer to memory
727 */
728 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
729 bool is_high_op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800730
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700731 /*
732 * @brief Is this operation a no-op for this opcode and value
733 * @param op Dex opcode for the operation
734 * @param value Immediate value for the operation.
735 * @returns 'true' if the operation will have no effect
736 */
737 bool IsNoOp(Instruction::Code op, int32_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800738
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700739 /**
740 * @brief Calculate magic number and shift for a given divisor
741 * @param divisor divisor number for calculation
742 * @param magic hold calculated magic number
743 * @param shift hold calculated shift
744 */
745 void CalculateMagicAndShift(int divisor, int& magic, int& shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800746
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700747 /*
748 * @brief Generate an integer div or rem operation.
749 * @param rl_dest Destination Location.
750 * @param rl_src1 Numerator Location.
751 * @param rl_src2 Divisor Location.
752 * @param is_div 'true' if this is a division, 'false' for a remainder.
753 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
754 */
755 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
756 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800757
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700758 /*
759 * @brief Generate an integer div or rem operation by a literal.
760 * @param rl_dest Destination Location.
761 * @param rl_src Numerator Location.
762 * @param lit Divisor.
763 * @param is_div 'true' if this is a division, 'false' for a remainder.
764 */
765 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800766
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700767 /*
768 * Generate code to implement long shift operations.
769 * @param opcode The DEX opcode to specify the shift type.
770 * @param rl_dest The destination.
771 * @param rl_src The value to be shifted.
772 * @param shift_amount How much to shift.
773 * @returns the RegLocation of the result.
774 */
775 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
776 RegLocation rl_src, int shift_amount);
777 /*
778 * Generate an imul of a register by a constant or a better sequence.
779 * @param dest Destination Register.
780 * @param src Source Register.
781 * @param val Constant multiplier.
782 */
783 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800784
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700785 /*
786 * Generate an imul of a memory location by a constant or a better sequence.
787 * @param dest Destination Register.
788 * @param sreg Symbolic register.
789 * @param displacement Displacement on stack of Symbolic Register.
790 * @param val Constant multiplier.
791 */
792 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800793
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700794 /*
795 * @brief Compare memory to immediate, and branch if condition true.
796 * @param cond The condition code that when true will branch to the target.
797 * @param temp_reg A temporary register that can be used if compare memory is not
798 * supported by the architecture.
799 * @param base_reg The register holding the base address.
800 * @param offset The offset from the base.
801 * @param check_value The immediate to compare to.
Dave Allison7fb36de2014-07-10 02:05:10 +0000802 * @param target branch target (or nullptr)
803 * @param compare output for getting LIR for comparison (or nullptr)
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700804 */
805 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
Dave Allison7fb36de2014-07-10 02:05:10 +0000806 int offset, int check_value, LIR* target, LIR** compare);
Mark Mendell766e9292014-01-27 07:55:47 -0800807
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700808 /*
809 * Can this operation be using core registers without temporaries?
810 * @param rl_lhs Left hand operand.
811 * @param rl_rhs Right hand operand.
812 * @returns 'true' if the operation can proceed without needing temporary regs.
813 */
814 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800815
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700816 /**
817 * @brief Generates inline code for conversion of long to FP by using x87/
818 * @param rl_dest The destination of the FP.
819 * @param rl_src The source of the long.
820 * @param is_double 'true' if dealing with double, 'false' for float.
821 */
822 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Mark Mendell67c39c42014-01-31 17:28:00 -0800823
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700824 /*
825 * @brief Perform MIR analysis before compiling method.
826 * @note Invokes Mir2LiR::Materialize after analysis.
827 */
828 void Materialize();
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800829
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700830 /*
831 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
832 * without regard to data type. In practice, this can result in UpdateLoc returning a
833 * location record for a Dalvik float value in a core register, and vis-versa. For targets
834 * which can inexpensively move data between core and float registers, this can often be a win.
835 * However, for x86 this is generally not a win. These variants of UpdateLoc()
836 * take a register class argument - and will return an in-register location record only if
837 * the value is live in a temp register of the correct class. Additionally, if the value is in
838 * a temp register of the wrong register class, it will be clobbered.
839 */
840 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
841 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
Mark Mendell67c39c42014-01-31 17:28:00 -0800842
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700843 /*
844 * @brief Analyze MIR before generating code, to prepare for the code generation.
845 */
846 void AnalyzeMIR();
buzbee30adc732014-05-09 15:10:18 -0700847
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700848 /*
849 * @brief Analyze one basic block.
850 * @param bb Basic block to analyze.
851 */
852 void AnalyzeBB(BasicBlock * bb);
Mark Mendell67c39c42014-01-31 17:28:00 -0800853
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700854 /*
855 * @brief Analyze one extended MIR instruction
856 * @param opcode MIR instruction opcode.
857 * @param bb Basic block containing instruction.
858 * @param mir Extended instruction to analyze.
859 */
860 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800861
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700862 /*
863 * @brief Analyze one MIR instruction
864 * @param opcode MIR instruction opcode.
865 * @param bb Basic block containing instruction.
866 * @param mir Instruction to analyze.
867 */
868 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800869
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700870 /*
871 * @brief Analyze one MIR float/double instruction
872 * @param opcode MIR instruction opcode.
873 * @param bb Basic block containing instruction.
874 * @param mir Instruction to analyze.
875 */
876 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800877
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700878 /*
879 * @brief Analyze one use of a double operand.
880 * @param rl_use Double RegLocation for the operand.
881 */
882 void AnalyzeDoubleUse(RegLocation rl_use);
Mark Mendell67c39c42014-01-31 17:28:00 -0800883
Yixin Shou7071c8d2014-03-05 06:07:48 -0500884 /*
885 * @brief Analyze one invoke-static MIR instruction
886 * @param opcode MIR instruction opcode.
887 * @param bb Basic block containing instruction.
888 * @param mir Instruction to analyze.
889 */
890 void AnalyzeInvokeStatic(int opcode, BasicBlock * bb, MIR *mir);
891
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700892 // Information derived from analysis of MIR
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700893
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700894 // The compiler temporary for the code address of the method.
895 CompilerTemp *base_of_code_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800896
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700897 // Have we decided to compute a ptr to code and store in temporary VR?
898 bool store_method_addr_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800899
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700900 // Have we used the stored method address?
901 bool store_method_addr_used_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800902
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700903 // Instructions to remove if we didn't use the stored method address.
904 LIR* setup_method_address_[2];
Mark Mendell55d0eac2014-02-06 11:02:52 -0800905
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700906 // Instructions needing patching with Method* values.
907 GrowableArray<LIR*> method_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800908
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700909 // Instructions needing patching with Class Type* values.
910 GrowableArray<LIR*> class_type_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800911
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700912 // Instructions needing patching with PC relative code addresses.
913 GrowableArray<LIR*> call_method_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800914
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700915 // Prologue decrement of stack pointer.
916 LIR* stack_decrement_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800917
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700918 // Epilogue increment of stack pointer.
919 LIR* stack_increment_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800920
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700921 // The list of const vector literals.
922 LIR *const_vectors_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400923
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700924 /*
925 * @brief Search for a matching vector literal
926 * @param mir A kMirOpConst128b MIR instruction to match.
927 * @returns pointer to matching LIR constant, or nullptr if not found.
928 */
929 LIR *ScanVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400930
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700931 /*
932 * @brief Add a constant vector literal
933 * @param mir A kMirOpConst128b MIR instruction to match.
934 */
935 LIR *AddVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400936
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700937 InToRegStorageMapping in_to_reg_storage_mapping_;
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700938
939 private:
940 // The number of vector registers [0..N] reserved by a call to ReserveVectorRegisters
941 int num_reserved_vector_regs_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700942};
943
944} // namespace art
945
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700946#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_