blob: 1f974296fc0099062518fca79f5c06884b185baf [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 Allison69dfe512014-07-11 17:11:58 +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);
Andreas Gampeccc60262014-07-04 18:02:38 -070093 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
94 if (wide_kind == kWide) {
95 if (cu_->target64) {
96 return As64BitReg(TargetReg32(symbolic_reg));
97 } else {
98 // x86: construct a pair.
99 DCHECK((kArg0 <= symbolic_reg && symbolic_reg < kArg3) ||
100 (kFArg0 <= symbolic_reg && symbolic_reg < kFArg3) ||
101 (kRet0 == symbolic_reg));
102 return RegStorage::MakeRegPair(TargetReg32(symbolic_reg),
103 TargetReg32(static_cast<SpecialTargetRegister>(symbolic_reg + 1)));
104 }
105 } else if (wide_kind == kRef && cu_->target64) {
106 return As64BitReg(TargetReg32(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700107 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700108 return TargetReg32(symbolic_reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700109 }
110 }
Chao-ying Fua77ee512014-07-01 17:43:41 -0700111 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
Andreas Gampeccc60262014-07-04 18:02:38 -0700112 return TargetReg(symbolic_reg, cu_->target64 ? kWide : kNotWide);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700113 }
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700114 RegStorage GetArgMappingToPhysicalReg(int arg_num);
115 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
116 RegLocation GetReturnAlt();
117 RegLocation GetReturnWideAlt();
118 RegLocation LocCReturn();
119 RegLocation LocCReturnRef();
120 RegLocation LocCReturnDouble();
121 RegLocation LocCReturnFloat();
122 RegLocation LocCReturnWide();
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100123 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700124 void AdjustSpillMask();
125 void ClobberCallerSave();
126 void FreeCallTemps();
127 void LockCallTemps();
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700128 void CompilerInitializeRegAlloc();
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700129 int VectorRegisterSize();
130 int NumReservableVectorRegisters(bool fp_used);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700131
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700132 // Required for target - miscellaneous.
133 void AssembleLIR();
134 int AssignInsnOffsets();
135 void AssignOffsets();
136 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100137 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
138 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
139 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700140 const char* GetTargetInstFmt(int opcode);
141 const char* GetTargetInstName(int opcode);
142 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100143 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700144 uint64_t GetTargetInstFlags(int opcode);
Ian Rogers5aa6e042014-06-13 16:38:24 -0700145 size_t GetInsnSize(LIR* lir) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700146 bool IsUnconditionalBranch(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700147
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700148 // Check support for volatile load/store of a given size.
149 bool SupportsVolatileLoadStore(OpSize size) OVERRIDE;
150 // Get the register class for load/store of a field.
151 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100152
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700153 // Required for target - Dalvik-level generators.
154 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
buzbee2700f7e2014-03-07 09:46:20 -0800155 RegLocation rl_src2);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700156 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
157 RegLocation rl_dest, int scale);
158 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
159 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark);
160 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
161 RegLocation rl_src1, RegLocation rl_shift);
162 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
buzbee2700f7e2014-03-07 09:46:20 -0800163 RegLocation rl_src2);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700164 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
165 RegLocation rl_src2);
166 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
167 RegLocation rl_src2);
168 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
169 RegLocation rl_src2);
170 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
171 RegLocation rl_src2);
Alexei Zavjalovbd3682e2014-06-12 03:08:01 +0700172 void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700173 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
174 RegLocation rl_src2);
175 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
176 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100177 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700178 bool GenInlinedSqrt(CallInfo* info);
Yixin Shou7071c8d2014-03-05 06:07:48 -0500179 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
180 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700181 bool GenInlinedPeek(CallInfo* info, OpSize size);
182 bool GenInlinedPoke(CallInfo* info, OpSize size);
183 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
184 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
185 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
186 RegLocation rl_src2);
187 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
188 RegLocation rl_src2);
189 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
190 RegLocation rl_src2);
191 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
192 RegLocation rl_src2, bool is_div);
193 // TODO: collapse reg_lo, reg_hi
194 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
195 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
196 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
197 void GenDivZeroCheckWide(RegStorage reg);
198 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
199 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
200 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
201 void GenExitSequence();
202 void GenSpecialExitSequence();
203 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
204 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
205 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
206 void GenSelect(BasicBlock* bb, MIR* mir);
207 bool GenMemBarrier(MemBarrierKind barrier_kind);
208 void GenMoveException(RegLocation rl_dest);
209 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
210 int first_bit, int second_bit);
211 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
212 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
213 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
214 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
215 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800216
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700217 /*
218 * @brief Generate a two address long operation with a constant value
219 * @param rl_dest location of result
220 * @param rl_src constant source operand
221 * @param op Opcode to be generated
222 * @return success or not
223 */
224 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
225 /*
226 * @brief Generate a three address long operation with a constant value
227 * @param rl_dest location of result
228 * @param rl_src1 source operand
229 * @param rl_src2 constant source operand
230 * @param op Opcode to be generated
231 * @return success or not
232 */
233 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
234 Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800235
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700236 /**
237 * @brief Generate a long arithmetic operation.
238 * @param rl_dest The destination.
239 * @param rl_src1 First operand.
240 * @param rl_src2 Second operand.
241 * @param op The DEX opcode for the operation.
242 * @param is_commutative The sources can be swapped if needed.
243 */
244 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
245 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800246
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700247 /**
248 * @brief Generate a two operand long arithmetic operation.
249 * @param rl_dest The destination.
250 * @param rl_src Second operand.
251 * @param op The DEX opcode for the operation.
252 */
253 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800254
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700255 /**
256 * @brief Generate a long operation.
257 * @param rl_dest The destination. Must be in a register
258 * @param rl_src The other operand. May be in a register or in memory.
259 * @param op The DEX opcode for the operation.
260 */
261 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700262
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700263 /**
264 * @brief Implement instanceof a final class with x86 specific code.
265 * @param use_declaring_class 'true' if we can use the class itself.
266 * @param type_idx Type index to use if use_declaring_class is 'false'.
267 * @param rl_dest Result to be set to 0 or 1.
268 * @param rl_src Object to be tested.
269 */
270 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
271 RegLocation rl_src);
272 /*
273 *
274 * @brief Implement Set up instanceof a class with x86 specific code.
275 * @param needs_access_check 'true' if we must check the access.
276 * @param type_known_final 'true' if the type is known to be a final class.
277 * @param type_known_abstract 'true' if the type is known to be an abstract class.
278 * @param use_declaring_class 'true' if the type can be loaded off the current Method*.
279 * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache.
280 * @param type_idx Type index to use if use_declaring_class is 'false'.
281 * @param rl_dest Result to be set to 0 or 1.
282 * @param rl_src Object to be tested.
283 */
284 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
285 bool type_known_abstract, bool use_declaring_class,
286 bool can_assume_type_is_in_dex_cache,
287 uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src);
Mark Mendell6607d972014-02-10 06:54:18 -0800288
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700289 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
290 RegLocation rl_src1, RegLocation rl_shift);
Chao-ying Fua0147762014-06-06 18:38:49 -0700291
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700292 // Single operation generators.
293 LIR* OpUnconditionalBranch(LIR* target);
294 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
295 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
296 LIR* OpCondBranch(ConditionCode cc, LIR* target);
297 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
298 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
299 LIR* OpIT(ConditionCode cond, const char* guide);
300 void OpEndIT(LIR* it);
301 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
302 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
303 LIR* OpReg(OpKind op, RegStorage r_dest_src);
304 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
305 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
306 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
307 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
308 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
309 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
310 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
311 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
312 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
313 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
314 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
315 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
316 LIR* OpTestSuspend(LIR* target);
317 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
318 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
319 LIR* OpVldm(RegStorage r_base, int count);
320 LIR* OpVstm(RegStorage r_base, int count);
321 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
322 void OpRegCopyWide(RegStorage dest, RegStorage src);
323 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
324 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700325
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700326 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
327 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
328 void SpillCoreRegs();
329 void UnSpillCoreRegs();
Serguei Katkovc3801912014-07-08 17:21:53 +0700330 void UnSpillFPRegs();
331 void SpillFPRegs();
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700332 static const X86EncodingMap EncodingMap[kX86Last];
333 bool InexpensiveConstantInt(int32_t value);
334 bool InexpensiveConstantFloat(int32_t value);
335 bool InexpensiveConstantLong(int64_t value);
336 bool InexpensiveConstantDouble(int64_t value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700337
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700338 /*
339 * @brief Should try to optimize for two address instructions?
340 * @return true if we try to avoid generating three operand instructions.
341 */
342 virtual bool GenerateTwoOperandInstructions() const { return true; }
Mark Mendelle87f9b52014-04-30 14:13:18 -0400343
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700344 /*
345 * @brief x86 specific codegen for int operations.
346 * @param opcode Operation to perform.
347 * @param rl_dest Destination for the result.
348 * @param rl_lhs Left hand operand.
349 * @param rl_rhs Right hand operand.
350 */
351 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
352 RegLocation rl_rhs);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800353
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700354 /*
355 * @brief Dump a RegLocation using printf
356 * @param loc Register location to dump
357 */
358 static void DumpRegLocation(RegLocation loc);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800359
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700360 /*
361 * @brief Load the Method* of a dex method into the register.
362 * @param target_method The MethodReference of the method to be invoked.
363 * @param type How the method will be invoked.
364 * @param register that will contain the code address.
365 * @note register will be passed to TargetReg to get physical register.
366 */
367 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
368 SpecialTargetRegister symbolic_reg);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800369
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700370 /*
371 * @brief Load the Class* of a Dex Class type into the register.
372 * @param type How the method will be invoked.
373 * @param register that will contain the code address.
374 * @note register will be passed to TargetReg to get physical register.
375 */
376 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800377
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700378 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700379
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700380 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700381 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);
386
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700387 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
388 NextCallInsn next_call_insn,
389 const MethodReference& target_method,
390 uint32_t vtable_idx,
391 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
392 bool skip_this);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800393
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700394 /*
395 * @brief Generate a relative call to the method that will be patched at link time.
396 * @param target_method The MethodReference of the method to be invoked.
397 * @param type How the method will be invoked.
398 * @returns Call instruction
399 */
400 virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800401
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700402 /*
403 * @brief Handle x86 specific literals
404 */
405 void InstallLiteralPools();
Mark Mendellae9fd932014-02-10 16:14:35 -0800406
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700407 /*
408 * @brief Generate the debug_frame CFI information.
409 * @returns pointer to vector containing CFE information
410 */
411 static std::vector<uint8_t>* ReturnCommonCallFrameInformation();
Mark Mendellae9fd932014-02-10 16:14:35 -0800412
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700413 /*
414 * @brief Generate the debug_frame FDE information.
415 * @returns pointer to vector containing CFE information
416 */
417 std::vector<uint8_t>* ReturnCallFrameInformation();
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800418
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700419 protected:
Chao-ying Fua77ee512014-07-01 17:43:41 -0700420 // Casting of RegStorage
421 RegStorage As32BitReg(RegStorage reg) {
422 DCHECK(!reg.IsPair());
423 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
424 if (kFailOnSizeError) {
425 LOG(FATAL) << "Expected 64b register " << reg.GetReg();
426 } else {
427 LOG(WARNING) << "Expected 64b register " << reg.GetReg();
428 return reg;
429 }
430 }
431 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
432 reg.GetRawBits() & RegStorage::kRegTypeMask);
433 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
434 ->GetReg().GetReg(),
435 ret_val.GetReg());
436 return ret_val;
437 }
438
439 RegStorage As64BitReg(RegStorage reg) {
440 DCHECK(!reg.IsPair());
441 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
442 if (kFailOnSizeError) {
443 LOG(FATAL) << "Expected 32b register " << reg.GetReg();
444 } else {
445 LOG(WARNING) << "Expected 32b register " << reg.GetReg();
446 return reg;
447 }
448 }
449 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
450 reg.GetRawBits() & RegStorage::kRegTypeMask);
451 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
452 ->GetReg().GetReg(),
453 ret_val.GetReg());
454 return ret_val;
455 }
456
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700457 size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700458 int32_t raw_base, int32_t displacement);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700459 void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg);
460 void EmitPrefix(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700461 int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700462 void EmitOpcode(const X86EncodingMap* entry);
463 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700464 int32_t reg_r, int32_t reg_x, int32_t reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700465 void EmitDisp(uint8_t base, int32_t disp);
466 void EmitModrmThread(uint8_t reg_or_opcode);
467 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp);
468 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale,
469 int32_t disp);
470 void EmitImm(const X86EncodingMap* entry, int64_t imm);
471 void EmitNullary(const X86EncodingMap* entry);
472 void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg);
473 void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg);
474 void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
475 void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
476 int32_t disp);
477 void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg);
478 void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp);
479 void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base,
480 int32_t raw_index, int scale, int32_t disp);
481 void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
482 int32_t disp, int32_t raw_reg);
483 void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
484 void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
485 int32_t raw_disp, int32_t imm);
486 void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp);
487 void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2);
488 void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm);
489 void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
490 int32_t imm);
491 void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1,
492 int32_t imm);
493 void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
494 void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm);
495 void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm);
496 void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
497 void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl);
498 void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl);
499 void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
500 void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc);
501 void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc);
502 void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc);
503 void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
504 int32_t cc);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800505
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700506 void EmitJmp(const X86EncodingMap* entry, int32_t rel);
507 void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc);
508 void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
509 void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp);
510 void EmitCallThread(const X86EncodingMap* entry, int32_t disp);
511 void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table,
512 int32_t raw_index, int scale, int32_t table_or_disp);
513 void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset);
514 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
515 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
516 int64_t val, ConditionCode ccode);
517 void GenConstWide(RegLocation rl_dest, int64_t value);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700518 void GenMultiplyVectorSignedByte(BasicBlock *bb, MIR *mir);
519 void GenShiftByteVector(BasicBlock *bb, MIR *mir);
520 void AndMaskVectorRegister(RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
521 void MaskVectorRegister(X86OpCode opcode, RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
522 void AppendOpcodeWithConst(X86OpCode opcode, int reg, MIR* mir);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400523
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700524 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800525
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700526 /*
527 * @brief Ensure that a temporary register is byte addressable.
528 * @returns a temporary guarenteed to be byte addressable.
529 */
530 virtual RegStorage AllocateByteRegister();
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800531
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700532 /*
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700533 * @brief Use a wide temporary as a 128-bit register
534 * @returns a 128-bit temporary register.
535 */
536 virtual RegStorage Get128BitRegister(RegStorage reg);
537
538 /*
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700539 * @brief Check if a register is byte addressable.
540 * @returns true if a register is byte addressable.
541 */
542 bool IsByteRegister(RegStorage reg);
DaniilSokolov70c4f062014-06-24 17:34:00 -0700543 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700544
545 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700546 * @brief generate inline code for fast case of Strng.indexOf.
547 * @param info Call parameters
548 * @param zero_based 'true' if the index into the string is 0.
549 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
550 * generated.
551 */
552 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
Mark Mendelle87f9b52014-04-30 14:13:18 -0400553
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700554 /**
555 * @brief Reserve a fixed number of vector registers from the register pool
556 * @details The mir->dalvikInsn.vA specifies an N such that vector registers
557 * [0..N-1] are removed from the temporary pool. The caller must call
558 * ReturnVectorRegisters before calling ReserveVectorRegisters again.
559 * Also sets the num_reserved_vector_regs_ to the specified value
560 * @param mir whose vA specifies the number of registers to reserve
561 */
562 void ReserveVectorRegisters(MIR* mir);
563
564 /**
565 * @brief Return all the reserved vector registers to the temp pool
566 * @details Returns [0..num_reserved_vector_regs_]
567 */
568 void ReturnVectorRegisters();
569
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700570 /*
571 * @brief Load 128 bit constant into vector register.
572 * @param bb The basic block in which the MIR is from.
573 * @param mir The MIR whose opcode is kMirConstVector
574 * @note vA is the TypeSize for the register.
575 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
576 */
577 void GenConst128(BasicBlock* bb, MIR* mir);
Mark Mendell4028a6c2014-02-19 20:06:20 -0800578
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700579 /*
580 * @brief MIR to move a vectorized register to another.
581 * @param bb The basic block in which the MIR is from.
582 * @param mir The MIR whose opcode is kMirConstVector.
583 * @note vA: TypeSize
584 * @note vB: destination
585 * @note vC: source
586 */
587 void GenMoveVector(BasicBlock *bb, MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400588
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700589 /*
590 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know the type of the vector.
591 * @param bb The basic block in which the MIR is from.
592 * @param mir The MIR whose opcode is kMirConstVector.
593 * @note vA: TypeSize
594 * @note vB: destination and source
595 * @note vC: source
596 */
597 void GenMultiplyVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400598
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700599 /*
600 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the type of the vector.
601 * @param bb The basic block in which the MIR is from.
602 * @param mir The MIR whose opcode is kMirConstVector.
603 * @note vA: TypeSize
604 * @note vB: destination and source
605 * @note vC: source
606 */
607 void GenAddVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400608
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700609 /*
610 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the type of the vector.
611 * @param bb The basic block in which the MIR is from.
612 * @param mir The MIR whose opcode is kMirConstVector.
613 * @note vA: TypeSize
614 * @note vB: destination and source
615 * @note vC: source
616 */
617 void GenSubtractVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400618
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700619 /*
620 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the type of the vector.
621 * @param bb The basic block in which the MIR is from.
622 * @param mir The MIR whose opcode is kMirConstVector.
623 * @note vA: TypeSize
624 * @note vB: destination and source
625 * @note vC: immediate
626 */
627 void GenShiftLeftVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400628
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700629 /*
630 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to know the type of the vector.
631 * @param bb The basic block in which the MIR is from.
632 * @param mir The MIR whose opcode is kMirConstVector.
633 * @note vA: TypeSize
634 * @note vB: destination and source
635 * @note vC: immediate
636 */
637 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400638
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700639 /*
640 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA to know the type of the vector.
641 * @param bb The basic block in which the MIR is from..
642 * @param mir The MIR whose opcode is kMirConstVector.
643 * @note vA: TypeSize
644 * @note vB: destination and source
645 * @note vC: immediate
646 */
647 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400648
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700649 /*
650 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the type of the vector.
651 * @note vA: TypeSize
652 * @note vB: destination and source
653 * @note vC: source
654 */
655 void GenAndVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400656
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700657 /*
658 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the type of the vector.
659 * @param bb The basic block in which the MIR is from.
660 * @param mir The MIR whose opcode is kMirConstVector.
661 * @note vA: TypeSize
662 * @note vB: destination and source
663 * @note vC: source
664 */
665 void GenOrVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400666
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700667 /*
668 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the type of the vector.
669 * @param bb The basic block in which the MIR is from.
670 * @param mir The MIR whose opcode is kMirConstVector.
671 * @note vA: TypeSize
672 * @note vB: destination and source
673 * @note vC: source
674 */
675 void GenXorVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400676
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700677 /*
678 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
679 * @param bb The basic block in which the MIR is from.
680 * @param mir The MIR whose opcode is kMirConstVector.
681 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
682 * @note vA: TypeSize
683 * @note vB: destination and source VR (not vector register)
684 * @note vC: source (vector register)
685 */
686 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400687
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700688 /*
689 * @brief Extract a packed element into a single VR.
690 * @param bb The basic block in which the MIR is from.
691 * @param mir The MIR whose opcode is kMirConstVector.
692 * @note vA: TypeSize
693 * @note vB: destination VR (not vector register)
694 * @note vC: source (vector register)
695 * @note arg[0]: The index to use for extraction from vector register (which packed element).
696 */
697 void GenReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400698
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700699 /*
700 * @brief Create a vector value, with all TypeSize values equal to vC
701 * @param bb The basic block in which the MIR is from.
702 * @param mir The MIR whose opcode is kMirConstVector.
703 * @note vA: TypeSize.
704 * @note vB: destination vector register.
705 * @note vC: source VR (not vector register).
706 */
707 void GenSetVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400708
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700709 /*
710 * @brief Generate code for a vector opcode.
711 * @param bb The basic block in which the MIR is from.
712 * @param mir The MIR whose opcode is a non-standard opcode.
713 */
714 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400715
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700716 /*
717 * @brief Return the correct x86 opcode for the Dex operation
718 * @param op Dex opcode for the operation
719 * @param loc Register location of the operand
720 * @param is_high_op 'true' if this is an operation on the high word
721 * @param value Immediate value for the operation. Used for byte variants
722 * @returns the correct x86 opcode to perform the operation
723 */
724 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400725
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700726 /*
727 * @brief Return the correct x86 opcode for the Dex operation
728 * @param op Dex opcode for the operation
729 * @param dest location of the destination. May be register or memory.
730 * @param rhs Location for the rhs of the operation. May be in register or memory.
731 * @param is_high_op 'true' if this is an operation on the high word
732 * @returns the correct x86 opcode to perform the operation
733 * @note at most one location may refer to memory
734 */
735 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
736 bool is_high_op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800737
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700738 /*
739 * @brief Is this operation a no-op for this opcode and value
740 * @param op Dex opcode for the operation
741 * @param value Immediate value for the operation.
742 * @returns 'true' if the operation will have no effect
743 */
744 bool IsNoOp(Instruction::Code op, int32_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800745
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700746 /**
747 * @brief Calculate magic number and shift for a given divisor
748 * @param divisor divisor number for calculation
749 * @param magic hold calculated magic number
750 * @param shift hold calculated shift
751 */
752 void CalculateMagicAndShift(int divisor, int& magic, int& shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800753
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700754 /*
755 * @brief Generate an integer div or rem operation.
756 * @param rl_dest Destination Location.
757 * @param rl_src1 Numerator Location.
758 * @param rl_src2 Divisor Location.
759 * @param is_div 'true' if this is a division, 'false' for a remainder.
760 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
761 */
762 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
763 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800764
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700765 /*
766 * @brief Generate an integer div or rem operation by a literal.
767 * @param rl_dest Destination Location.
768 * @param rl_src Numerator Location.
769 * @param lit Divisor.
770 * @param is_div 'true' if this is a division, 'false' for a remainder.
771 */
772 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800773
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700774 /*
775 * Generate code to implement long shift operations.
776 * @param opcode The DEX opcode to specify the shift type.
777 * @param rl_dest The destination.
778 * @param rl_src The value to be shifted.
779 * @param shift_amount How much to shift.
780 * @returns the RegLocation of the result.
781 */
782 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
783 RegLocation rl_src, int shift_amount);
784 /*
785 * Generate an imul of a register by a constant or a better sequence.
786 * @param dest Destination Register.
787 * @param src Source Register.
788 * @param val Constant multiplier.
789 */
790 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800791
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700792 /*
793 * Generate an imul of a memory location by a constant or a better sequence.
794 * @param dest Destination Register.
795 * @param sreg Symbolic register.
796 * @param displacement Displacement on stack of Symbolic Register.
797 * @param val Constant multiplier.
798 */
799 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800800
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700801 /*
802 * @brief Compare memory to immediate, and branch if condition true.
803 * @param cond The condition code that when true will branch to the target.
804 * @param temp_reg A temporary register that can be used if compare memory is not
805 * supported by the architecture.
806 * @param base_reg The register holding the base address.
807 * @param offset The offset from the base.
808 * @param check_value The immediate to compare to.
Dave Allison69dfe512014-07-11 17:11:58 +0000809 * @param target branch target (or nullptr)
810 * @param compare output for getting LIR for comparison (or nullptr)
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700811 */
812 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
Dave Allison69dfe512014-07-11 17:11:58 +0000813 int offset, int check_value, LIR* target, LIR** compare);
Mark Mendell766e9292014-01-27 07:55:47 -0800814
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700815 /*
816 * Can this operation be using core registers without temporaries?
817 * @param rl_lhs Left hand operand.
818 * @param rl_rhs Right hand operand.
819 * @returns 'true' if the operation can proceed without needing temporary regs.
820 */
821 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800822
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700823 /**
824 * @brief Generates inline code for conversion of long to FP by using x87/
825 * @param rl_dest The destination of the FP.
826 * @param rl_src The source of the long.
827 * @param is_double 'true' if dealing with double, 'false' for float.
828 */
829 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Mark Mendell67c39c42014-01-31 17:28:00 -0800830
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700831 /*
832 * @brief Perform MIR analysis before compiling method.
833 * @note Invokes Mir2LiR::Materialize after analysis.
834 */
835 void Materialize();
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800836
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700837 /*
838 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
839 * without regard to data type. In practice, this can result in UpdateLoc returning a
840 * location record for a Dalvik float value in a core register, and vis-versa. For targets
841 * which can inexpensively move data between core and float registers, this can often be a win.
842 * However, for x86 this is generally not a win. These variants of UpdateLoc()
843 * take a register class argument - and will return an in-register location record only if
844 * the value is live in a temp register of the correct class. Additionally, if the value is in
845 * a temp register of the wrong register class, it will be clobbered.
846 */
847 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
848 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
Mark Mendell67c39c42014-01-31 17:28:00 -0800849
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700850 /*
851 * @brief Analyze MIR before generating code, to prepare for the code generation.
852 */
853 void AnalyzeMIR();
buzbee30adc732014-05-09 15:10:18 -0700854
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700855 /*
856 * @brief Analyze one basic block.
857 * @param bb Basic block to analyze.
858 */
859 void AnalyzeBB(BasicBlock * bb);
Mark Mendell67c39c42014-01-31 17:28:00 -0800860
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700861 /*
862 * @brief Analyze one extended MIR instruction
863 * @param opcode MIR instruction opcode.
864 * @param bb Basic block containing instruction.
865 * @param mir Extended instruction to analyze.
866 */
867 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800868
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700869 /*
870 * @brief Analyze one MIR instruction
871 * @param opcode MIR instruction opcode.
872 * @param bb Basic block containing instruction.
873 * @param mir Instruction to analyze.
874 */
875 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800876
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700877 /*
878 * @brief Analyze one MIR float/double instruction
879 * @param opcode MIR instruction opcode.
880 * @param bb Basic block containing instruction.
881 * @param mir Instruction to analyze.
882 */
883 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800884
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700885 /*
886 * @brief Analyze one use of a double operand.
887 * @param rl_use Double RegLocation for the operand.
888 */
889 void AnalyzeDoubleUse(RegLocation rl_use);
Mark Mendell67c39c42014-01-31 17:28:00 -0800890
Yixin Shou7071c8d2014-03-05 06:07:48 -0500891 /*
892 * @brief Analyze one invoke-static MIR instruction
893 * @param opcode MIR instruction opcode.
894 * @param bb Basic block containing instruction.
895 * @param mir Instruction to analyze.
896 */
897 void AnalyzeInvokeStatic(int opcode, BasicBlock * bb, MIR *mir);
898
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700899 // Information derived from analysis of MIR
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700900
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700901 // The compiler temporary for the code address of the method.
902 CompilerTemp *base_of_code_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800903
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700904 // Have we decided to compute a ptr to code and store in temporary VR?
905 bool store_method_addr_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800906
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700907 // Have we used the stored method address?
908 bool store_method_addr_used_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800909
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700910 // Instructions to remove if we didn't use the stored method address.
911 LIR* setup_method_address_[2];
Mark Mendell55d0eac2014-02-06 11:02:52 -0800912
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700913 // Instructions needing patching with Method* values.
914 GrowableArray<LIR*> method_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800915
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700916 // Instructions needing patching with Class Type* values.
917 GrowableArray<LIR*> class_type_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800918
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700919 // Instructions needing patching with PC relative code addresses.
920 GrowableArray<LIR*> call_method_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800921
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700922 // Prologue decrement of stack pointer.
923 LIR* stack_decrement_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800924
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700925 // Epilogue increment of stack pointer.
926 LIR* stack_increment_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800927
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700928 // The list of const vector literals.
929 LIR *const_vectors_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400930
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700931 /*
932 * @brief Search for a matching vector literal
933 * @param mir A kMirOpConst128b MIR instruction to match.
934 * @returns pointer to matching LIR constant, or nullptr if not found.
935 */
936 LIR *ScanVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400937
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700938 /*
939 * @brief Add a constant vector literal
940 * @param mir A kMirOpConst128b MIR instruction to match.
941 */
942 LIR *AddVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400943
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700944 InToRegStorageMapping in_to_reg_storage_mapping_;
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700945
Serguei Katkov59a42af2014-07-05 00:55:46 +0700946 bool WideGPRsAreAliases() OVERRIDE {
947 return cu_->target64; // On 64b, we have 64b GPRs.
948 }
949 bool WideFPRsAreAliases() OVERRIDE {
950 return true; // xmm registers have 64b views even on x86.
951 }
952
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700953 private:
954 // The number of vector registers [0..N] reserved by a call to ReserveVectorRegisters
955 int num_reserved_vector_regs_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700956};
957
958} // namespace art
959
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700960#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_