blob: 1e80247996e09f66b842190245f1e3977cb91011 [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);
Brian Carlstrom7940e442013-07-12 13:46:57 -070088
Ian Rogers0f9b9c52014-06-09 01:32:12 -070089 // Required for target - register utilities.
Chao-ying Fua77ee512014-07-01 17:43:41 -070090 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
91 RegStorage TargetReg32(SpecialTargetRegister reg);
Andreas Gampeccc60262014-07-04 18:02:38 -070092 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
93 if (wide_kind == kWide) {
94 if (cu_->target64) {
95 return As64BitReg(TargetReg32(symbolic_reg));
96 } else {
97 // x86: construct a pair.
98 DCHECK((kArg0 <= symbolic_reg && symbolic_reg < kArg3) ||
99 (kFArg0 <= symbolic_reg && symbolic_reg < kFArg3) ||
100 (kRet0 == symbolic_reg));
101 return RegStorage::MakeRegPair(TargetReg32(symbolic_reg),
102 TargetReg32(static_cast<SpecialTargetRegister>(symbolic_reg + 1)));
103 }
104 } else if (wide_kind == kRef && cu_->target64) {
105 return As64BitReg(TargetReg32(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700106 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700107 return TargetReg32(symbolic_reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700108 }
109 }
Chao-ying Fua77ee512014-07-01 17:43:41 -0700110 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
Andreas Gampeccc60262014-07-04 18:02:38 -0700111 return TargetReg(symbolic_reg, cu_->target64 ? kWide : kNotWide);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700112 }
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700113 RegStorage GetArgMappingToPhysicalReg(int arg_num);
114 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
115 RegLocation GetReturnAlt();
116 RegLocation GetReturnWideAlt();
117 RegLocation LocCReturn();
118 RegLocation LocCReturnRef();
119 RegLocation LocCReturnDouble();
120 RegLocation LocCReturnFloat();
121 RegLocation LocCReturnWide();
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100122 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700123 void AdjustSpillMask();
124 void ClobberCallerSave();
125 void FreeCallTemps();
126 void LockCallTemps();
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700127 void CompilerInitializeRegAlloc();
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700128 int VectorRegisterSize();
129 int NumReservableVectorRegisters(bool fp_used);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700130
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700131 // Required for target - miscellaneous.
132 void AssembleLIR();
133 int AssignInsnOffsets();
134 void AssignOffsets();
135 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100136 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
137 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
138 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700139 const char* GetTargetInstFmt(int opcode);
140 const char* GetTargetInstName(int opcode);
141 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100142 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700143 uint64_t GetTargetInstFlags(int opcode);
Ian Rogers5aa6e042014-06-13 16:38:24 -0700144 size_t GetInsnSize(LIR* lir) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700145 bool IsUnconditionalBranch(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700146
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700147 // Get the register class for load/store of a field.
148 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100149
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700150 // Required for target - Dalvik-level generators.
151 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
buzbee2700f7e2014-03-07 09:46:20 -0800152 RegLocation rl_src2);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700153 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
154 RegLocation rl_dest, int scale);
155 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
156 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark);
157 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
158 RegLocation rl_src1, RegLocation rl_shift);
159 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
buzbee2700f7e2014-03-07 09:46:20 -0800160 RegLocation rl_src2);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700161 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
162 RegLocation rl_src2);
163 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
164 RegLocation rl_src2);
165 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
166 RegLocation rl_src2);
167 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
168 RegLocation rl_src2);
Alexei Zavjalovbd3682e2014-06-12 03:08:01 +0700169 void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700170 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
171 RegLocation rl_src2);
172 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
173 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100174 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700175 bool GenInlinedSqrt(CallInfo* info);
Yixin Shou7071c8d2014-03-05 06:07:48 -0500176 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
177 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700178 bool GenInlinedPeek(CallInfo* info, OpSize size);
179 bool GenInlinedPoke(CallInfo* info, OpSize size);
180 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
181 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
182 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
183 RegLocation rl_src2);
184 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
185 RegLocation rl_src2);
186 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
187 RegLocation rl_src2);
188 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
189 RegLocation rl_src2, bool is_div);
190 // TODO: collapse reg_lo, reg_hi
191 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
192 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
193 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
194 void GenDivZeroCheckWide(RegStorage reg);
195 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
196 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
197 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
198 void GenExitSequence();
199 void GenSpecialExitSequence();
200 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
201 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
202 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
203 void GenSelect(BasicBlock* bb, MIR* mir);
204 bool GenMemBarrier(MemBarrierKind barrier_kind);
205 void GenMoveException(RegLocation rl_dest);
206 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
207 int first_bit, int second_bit);
208 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
209 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
210 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
211 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
212 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800213
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700214 /*
215 * @brief Generate a two address long operation with a constant value
216 * @param rl_dest location of result
217 * @param rl_src constant source operand
218 * @param op Opcode to be generated
219 * @return success or not
220 */
221 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
222 /*
223 * @brief Generate a three address long operation with a constant value
224 * @param rl_dest location of result
225 * @param rl_src1 source operand
226 * @param rl_src2 constant source operand
227 * @param op Opcode to be generated
228 * @return success or not
229 */
230 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
231 Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800232
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700233 /**
234 * @brief Generate a long arithmetic operation.
235 * @param rl_dest The destination.
236 * @param rl_src1 First operand.
237 * @param rl_src2 Second operand.
238 * @param op The DEX opcode for the operation.
239 * @param is_commutative The sources can be swapped if needed.
240 */
241 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
242 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800243
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700244 /**
245 * @brief Generate a two operand long arithmetic operation.
246 * @param rl_dest The destination.
247 * @param rl_src Second operand.
248 * @param op The DEX opcode for the operation.
249 */
250 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800251
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700252 /**
253 * @brief Generate a long operation.
254 * @param rl_dest The destination. Must be in a register
255 * @param rl_src The other operand. May be in a register or in memory.
256 * @param op The DEX opcode for the operation.
257 */
258 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700259
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700260 /**
261 * @brief Implement instanceof a final class with x86 specific code.
262 * @param use_declaring_class 'true' if we can use the class itself.
263 * @param type_idx Type index to use if use_declaring_class is 'false'.
264 * @param rl_dest Result to be set to 0 or 1.
265 * @param rl_src Object to be tested.
266 */
267 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
268 RegLocation rl_src);
269 /*
270 *
271 * @brief Implement Set up instanceof a class with x86 specific code.
272 * @param needs_access_check 'true' if we must check the access.
273 * @param type_known_final 'true' if the type is known to be a final class.
274 * @param type_known_abstract 'true' if the type is known to be an abstract class.
275 * @param use_declaring_class 'true' if the type can be loaded off the current Method*.
276 * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache.
277 * @param type_idx Type index to use if use_declaring_class is 'false'.
278 * @param rl_dest Result to be set to 0 or 1.
279 * @param rl_src Object to be tested.
280 */
281 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
282 bool type_known_abstract, bool use_declaring_class,
283 bool can_assume_type_is_in_dex_cache,
284 uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src);
Mark Mendell6607d972014-02-10 06:54:18 -0800285
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700286 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
287 RegLocation rl_src1, RegLocation rl_shift);
Chao-ying Fua0147762014-06-06 18:38:49 -0700288
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700289 // Single operation generators.
290 LIR* OpUnconditionalBranch(LIR* target);
291 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
292 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
293 LIR* OpCondBranch(ConditionCode cc, LIR* target);
294 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
295 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
296 LIR* OpIT(ConditionCode cond, const char* guide);
297 void OpEndIT(LIR* it);
298 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
299 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
300 LIR* OpReg(OpKind op, RegStorage r_dest_src);
301 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
302 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
303 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
304 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
305 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
306 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
307 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
308 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
309 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
310 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
311 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
312 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
313 LIR* OpTestSuspend(LIR* target);
314 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
315 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
316 LIR* OpVldm(RegStorage r_base, int count);
317 LIR* OpVstm(RegStorage r_base, int count);
318 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
319 void OpRegCopyWide(RegStorage dest, RegStorage src);
320 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
321 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700322
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700323 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
324 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
325 void SpillCoreRegs();
326 void UnSpillCoreRegs();
Serguei Katkovc3801912014-07-08 17:21:53 +0700327 void UnSpillFPRegs();
328 void SpillFPRegs();
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700329 static const X86EncodingMap EncodingMap[kX86Last];
330 bool InexpensiveConstantInt(int32_t value);
331 bool InexpensiveConstantFloat(int32_t value);
332 bool InexpensiveConstantLong(int64_t value);
333 bool InexpensiveConstantDouble(int64_t value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700334
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700335 /*
336 * @brief Should try to optimize for two address instructions?
337 * @return true if we try to avoid generating three operand instructions.
338 */
339 virtual bool GenerateTwoOperandInstructions() const { return true; }
Mark Mendelle87f9b52014-04-30 14:13:18 -0400340
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700341 /*
342 * @brief x86 specific codegen for int operations.
343 * @param opcode Operation to perform.
344 * @param rl_dest Destination for the result.
345 * @param rl_lhs Left hand operand.
346 * @param rl_rhs Right hand operand.
347 */
348 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
349 RegLocation rl_rhs);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800350
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700351 /*
352 * @brief Dump a RegLocation using printf
353 * @param loc Register location to dump
354 */
355 static void DumpRegLocation(RegLocation loc);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800356
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700357 /*
358 * @brief Load the Method* of a dex method into the register.
359 * @param target_method The MethodReference of the method to be invoked.
360 * @param type How the method will be invoked.
361 * @param register that will contain the code address.
362 * @note register will be passed to TargetReg to get physical register.
363 */
364 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
365 SpecialTargetRegister symbolic_reg);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800366
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700367 /*
368 * @brief Load the Class* of a Dex Class type into the register.
369 * @param type How the method will be invoked.
370 * @param register that will contain the code address.
371 * @note register will be passed to TargetReg to get physical register.
372 */
373 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800374
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700375 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700376
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700377 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700378 NextCallInsn next_call_insn,
379 const MethodReference& target_method,
380 uint32_t vtable_idx,
381 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
382 bool skip_this);
383
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700384 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
385 NextCallInsn next_call_insn,
386 const MethodReference& target_method,
387 uint32_t vtable_idx,
388 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
389 bool skip_this);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800390
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700391 /*
392 * @brief Generate a relative call to the method that will be patched at link time.
393 * @param target_method The MethodReference of the method to be invoked.
394 * @param type How the method will be invoked.
395 * @returns Call instruction
396 */
397 virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800398
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700399 /*
400 * @brief Handle x86 specific literals
401 */
402 void InstallLiteralPools();
Mark Mendellae9fd932014-02-10 16:14:35 -0800403
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700404 /*
405 * @brief Generate the debug_frame CFI information.
406 * @returns pointer to vector containing CFE information
407 */
408 static std::vector<uint8_t>* ReturnCommonCallFrameInformation();
Mark Mendellae9fd932014-02-10 16:14:35 -0800409
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700410 /*
411 * @brief Generate the debug_frame FDE information.
412 * @returns pointer to vector containing CFE information
413 */
414 std::vector<uint8_t>* ReturnCallFrameInformation();
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800415
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700416 protected:
Chao-ying Fua77ee512014-07-01 17:43:41 -0700417 // Casting of RegStorage
418 RegStorage As32BitReg(RegStorage reg) {
419 DCHECK(!reg.IsPair());
420 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
421 if (kFailOnSizeError) {
422 LOG(FATAL) << "Expected 64b register " << reg.GetReg();
423 } else {
424 LOG(WARNING) << "Expected 64b register " << reg.GetReg();
425 return reg;
426 }
427 }
428 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
429 reg.GetRawBits() & RegStorage::kRegTypeMask);
430 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
431 ->GetReg().GetReg(),
432 ret_val.GetReg());
433 return ret_val;
434 }
435
436 RegStorage As64BitReg(RegStorage reg) {
437 DCHECK(!reg.IsPair());
438 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
439 if (kFailOnSizeError) {
440 LOG(FATAL) << "Expected 32b register " << reg.GetReg();
441 } else {
442 LOG(WARNING) << "Expected 32b register " << reg.GetReg();
443 return reg;
444 }
445 }
446 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
447 reg.GetRawBits() & RegStorage::kRegTypeMask);
448 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
449 ->GetReg().GetReg(),
450 ret_val.GetReg());
451 return ret_val;
452 }
453
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700454 size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700455 int32_t raw_base, int32_t displacement);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700456 void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg);
457 void EmitPrefix(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700458 int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700459 void EmitOpcode(const X86EncodingMap* entry);
460 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700461 int32_t reg_r, int32_t reg_x, int32_t reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700462 void EmitDisp(uint8_t base, int32_t disp);
463 void EmitModrmThread(uint8_t reg_or_opcode);
464 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp);
465 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale,
466 int32_t disp);
467 void EmitImm(const X86EncodingMap* entry, int64_t imm);
468 void EmitNullary(const X86EncodingMap* entry);
469 void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg);
470 void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg);
471 void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
472 void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
473 int32_t disp);
474 void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg);
475 void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp);
476 void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base,
477 int32_t raw_index, int scale, int32_t disp);
478 void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
479 int32_t disp, int32_t raw_reg);
480 void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
481 void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
482 int32_t raw_disp, int32_t imm);
483 void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp);
484 void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2);
485 void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm);
486 void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
487 int32_t imm);
488 void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1,
489 int32_t imm);
490 void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
491 void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm);
492 void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm);
493 void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
494 void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl);
495 void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl);
496 void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
497 void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc);
498 void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc);
499 void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc);
500 void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
501 int32_t cc);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800502
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700503 void EmitJmp(const X86EncodingMap* entry, int32_t rel);
504 void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc);
505 void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
506 void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp);
507 void EmitCallThread(const X86EncodingMap* entry, int32_t disp);
508 void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table,
509 int32_t raw_index, int scale, int32_t table_or_disp);
510 void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset);
511 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
512 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
513 int64_t val, ConditionCode ccode);
514 void GenConstWide(RegLocation rl_dest, int64_t value);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700515 void GenMultiplyVectorSignedByte(BasicBlock *bb, MIR *mir);
516 void GenShiftByteVector(BasicBlock *bb, MIR *mir);
517 void AndMaskVectorRegister(RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
518 void MaskVectorRegister(X86OpCode opcode, RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
519 void AppendOpcodeWithConst(X86OpCode opcode, int reg, MIR* mir);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400520
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700521 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800522
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700523 /*
524 * @brief Ensure that a temporary register is byte addressable.
525 * @returns a temporary guarenteed to be byte addressable.
526 */
527 virtual RegStorage AllocateByteRegister();
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800528
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700529 /*
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700530 * @brief Use a wide temporary as a 128-bit register
531 * @returns a 128-bit temporary register.
532 */
533 virtual RegStorage Get128BitRegister(RegStorage reg);
534
535 /*
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700536 * @brief Check if a register is byte addressable.
537 * @returns true if a register is byte addressable.
538 */
539 bool IsByteRegister(RegStorage reg);
DaniilSokolov70c4f062014-06-24 17:34:00 -0700540 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700541
542 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700543 * @brief generate inline code for fast case of Strng.indexOf.
544 * @param info Call parameters
545 * @param zero_based 'true' if the index into the string is 0.
546 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
547 * generated.
548 */
549 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
Mark Mendelle87f9b52014-04-30 14:13:18 -0400550
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700551 /**
552 * @brief Reserve a fixed number of vector registers from the register pool
553 * @details The mir->dalvikInsn.vA specifies an N such that vector registers
554 * [0..N-1] are removed from the temporary pool. The caller must call
555 * ReturnVectorRegisters before calling ReserveVectorRegisters again.
556 * Also sets the num_reserved_vector_regs_ to the specified value
557 * @param mir whose vA specifies the number of registers to reserve
558 */
559 void ReserveVectorRegisters(MIR* mir);
560
561 /**
562 * @brief Return all the reserved vector registers to the temp pool
563 * @details Returns [0..num_reserved_vector_regs_]
564 */
565 void ReturnVectorRegisters();
566
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700567 /*
568 * @brief Load 128 bit constant into vector register.
569 * @param bb The basic block in which the MIR is from.
570 * @param mir The MIR whose opcode is kMirConstVector
571 * @note vA is the TypeSize for the register.
572 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
573 */
574 void GenConst128(BasicBlock* bb, MIR* mir);
Mark Mendell4028a6c2014-02-19 20:06:20 -0800575
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700576 /*
577 * @brief MIR to move a vectorized register to another.
578 * @param bb The basic block in which the MIR is from.
579 * @param mir The MIR whose opcode is kMirConstVector.
580 * @note vA: TypeSize
581 * @note vB: destination
582 * @note vC: source
583 */
584 void GenMoveVector(BasicBlock *bb, MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400585
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700586 /*
587 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know the type of the vector.
588 * @param bb The basic block in which the MIR is from.
589 * @param mir The MIR whose opcode is kMirConstVector.
590 * @note vA: TypeSize
591 * @note vB: destination and source
592 * @note vC: source
593 */
594 void GenMultiplyVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400595
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700596 /*
597 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the type of the vector.
598 * @param bb The basic block in which the MIR is from.
599 * @param mir The MIR whose opcode is kMirConstVector.
600 * @note vA: TypeSize
601 * @note vB: destination and source
602 * @note vC: source
603 */
604 void GenAddVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400605
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700606 /*
607 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the type of the vector.
608 * @param bb The basic block in which the MIR is from.
609 * @param mir The MIR whose opcode is kMirConstVector.
610 * @note vA: TypeSize
611 * @note vB: destination and source
612 * @note vC: source
613 */
614 void GenSubtractVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400615
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700616 /*
617 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the type of the vector.
618 * @param bb The basic block in which the MIR is from.
619 * @param mir The MIR whose opcode is kMirConstVector.
620 * @note vA: TypeSize
621 * @note vB: destination and source
622 * @note vC: immediate
623 */
624 void GenShiftLeftVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400625
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700626 /*
627 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to know the type of the vector.
628 * @param bb The basic block in which the MIR is from.
629 * @param mir The MIR whose opcode is kMirConstVector.
630 * @note vA: TypeSize
631 * @note vB: destination and source
632 * @note vC: immediate
633 */
634 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400635
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700636 /*
637 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA to know the type of the vector.
638 * @param bb The basic block in which the MIR is from..
639 * @param mir The MIR whose opcode is kMirConstVector.
640 * @note vA: TypeSize
641 * @note vB: destination and source
642 * @note vC: immediate
643 */
644 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400645
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700646 /*
647 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the type of the vector.
648 * @note vA: TypeSize
649 * @note vB: destination and source
650 * @note vC: source
651 */
652 void GenAndVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400653
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700654 /*
655 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the type of the vector.
656 * @param bb The basic block in which the MIR is from.
657 * @param mir The MIR whose opcode is kMirConstVector.
658 * @note vA: TypeSize
659 * @note vB: destination and source
660 * @note vC: source
661 */
662 void GenOrVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400663
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700664 /*
665 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the type of the vector.
666 * @param bb The basic block in which the MIR is from.
667 * @param mir The MIR whose opcode is kMirConstVector.
668 * @note vA: TypeSize
669 * @note vB: destination and source
670 * @note vC: source
671 */
672 void GenXorVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400673
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700674 /*
675 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
676 * @param bb The basic block in which the MIR is from.
677 * @param mir The MIR whose opcode is kMirConstVector.
678 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
679 * @note vA: TypeSize
680 * @note vB: destination and source VR (not vector register)
681 * @note vC: source (vector register)
682 */
683 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400684
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700685 /*
686 * @brief Extract a packed element into a single VR.
687 * @param bb The basic block in which the MIR is from.
688 * @param mir The MIR whose opcode is kMirConstVector.
689 * @note vA: TypeSize
690 * @note vB: destination VR (not vector register)
691 * @note vC: source (vector register)
692 * @note arg[0]: The index to use for extraction from vector register (which packed element).
693 */
694 void GenReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400695
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700696 /*
697 * @brief Create a vector value, with all TypeSize values equal to vC
698 * @param bb The basic block in which the MIR is from.
699 * @param mir The MIR whose opcode is kMirConstVector.
700 * @note vA: TypeSize.
701 * @note vB: destination vector register.
702 * @note vC: source VR (not vector register).
703 */
704 void GenSetVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400705
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700706 /*
707 * @brief Generate code for a vector opcode.
708 * @param bb The basic block in which the MIR is from.
709 * @param mir The MIR whose opcode is a non-standard opcode.
710 */
711 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400712
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700713 /*
714 * @brief Return the correct x86 opcode for the Dex operation
715 * @param op Dex opcode for the operation
716 * @param loc Register location of the operand
717 * @param is_high_op 'true' if this is an operation on the high word
718 * @param value Immediate value for the operation. Used for byte variants
719 * @returns the correct x86 opcode to perform the operation
720 */
721 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400722
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700723 /*
724 * @brief Return the correct x86 opcode for the Dex operation
725 * @param op Dex opcode for the operation
726 * @param dest location of the destination. May be register or memory.
727 * @param rhs Location for the rhs of the operation. May be in register or memory.
728 * @param is_high_op 'true' if this is an operation on the high word
729 * @returns the correct x86 opcode to perform the operation
730 * @note at most one location may refer to memory
731 */
732 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
733 bool is_high_op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800734
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700735 /*
736 * @brief Is this operation a no-op for this opcode and value
737 * @param op Dex opcode for the operation
738 * @param value Immediate value for the operation.
739 * @returns 'true' if the operation will have no effect
740 */
741 bool IsNoOp(Instruction::Code op, int32_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800742
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700743 /**
744 * @brief Calculate magic number and shift for a given divisor
745 * @param divisor divisor number for calculation
746 * @param magic hold calculated magic number
747 * @param shift hold calculated shift
748 */
749 void CalculateMagicAndShift(int divisor, int& magic, int& shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800750
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700751 /*
752 * @brief Generate an integer div or rem operation.
753 * @param rl_dest Destination Location.
754 * @param rl_src1 Numerator Location.
755 * @param rl_src2 Divisor Location.
756 * @param is_div 'true' if this is a division, 'false' for a remainder.
757 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
758 */
759 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
760 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800761
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700762 /*
763 * @brief Generate an integer div or rem operation by a literal.
764 * @param rl_dest Destination Location.
765 * @param rl_src Numerator Location.
766 * @param lit Divisor.
767 * @param is_div 'true' if this is a division, 'false' for a remainder.
768 */
769 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800770
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700771 /*
772 * Generate code to implement long shift operations.
773 * @param opcode The DEX opcode to specify the shift type.
774 * @param rl_dest The destination.
775 * @param rl_src The value to be shifted.
776 * @param shift_amount How much to shift.
777 * @returns the RegLocation of the result.
778 */
779 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
780 RegLocation rl_src, int shift_amount);
781 /*
782 * Generate an imul of a register by a constant or a better sequence.
783 * @param dest Destination Register.
784 * @param src Source Register.
785 * @param val Constant multiplier.
786 */
787 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800788
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700789 /*
790 * Generate an imul of a memory location by a constant or a better sequence.
791 * @param dest Destination Register.
792 * @param sreg Symbolic register.
793 * @param displacement Displacement on stack of Symbolic Register.
794 * @param val Constant multiplier.
795 */
796 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800797
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700798 /*
799 * @brief Compare memory to immediate, and branch if condition true.
800 * @param cond The condition code that when true will branch to the target.
801 * @param temp_reg A temporary register that can be used if compare memory is not
802 * supported by the architecture.
803 * @param base_reg The register holding the base address.
804 * @param offset The offset from the base.
805 * @param check_value The immediate to compare to.
806 */
807 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
Nicolas Geoffray0025a862014-07-11 08:26:40 +0000808 int offset, int check_value, LIR* target);
Mark Mendell766e9292014-01-27 07:55:47 -0800809
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700810 /*
811 * Can this operation be using core registers without temporaries?
812 * @param rl_lhs Left hand operand.
813 * @param rl_rhs Right hand operand.
814 * @returns 'true' if the operation can proceed without needing temporary regs.
815 */
816 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800817
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700818 /**
819 * @brief Generates inline code for conversion of long to FP by using x87/
820 * @param rl_dest The destination of the FP.
821 * @param rl_src The source of the long.
822 * @param is_double 'true' if dealing with double, 'false' for float.
823 */
824 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Mark Mendell67c39c42014-01-31 17:28:00 -0800825
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700826 /*
827 * @brief Perform MIR analysis before compiling method.
828 * @note Invokes Mir2LiR::Materialize after analysis.
829 */
830 void Materialize();
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800831
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700832 /*
833 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
834 * without regard to data type. In practice, this can result in UpdateLoc returning a
835 * location record for a Dalvik float value in a core register, and vis-versa. For targets
836 * which can inexpensively move data between core and float registers, this can often be a win.
837 * However, for x86 this is generally not a win. These variants of UpdateLoc()
838 * take a register class argument - and will return an in-register location record only if
839 * the value is live in a temp register of the correct class. Additionally, if the value is in
840 * a temp register of the wrong register class, it will be clobbered.
841 */
842 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
843 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
Mark Mendell67c39c42014-01-31 17:28:00 -0800844
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700845 /*
846 * @brief Analyze MIR before generating code, to prepare for the code generation.
847 */
848 void AnalyzeMIR();
buzbee30adc732014-05-09 15:10:18 -0700849
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700850 /*
851 * @brief Analyze one basic block.
852 * @param bb Basic block to analyze.
853 */
854 void AnalyzeBB(BasicBlock * bb);
Mark Mendell67c39c42014-01-31 17:28:00 -0800855
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700856 /*
857 * @brief Analyze one extended MIR instruction
858 * @param opcode MIR instruction opcode.
859 * @param bb Basic block containing instruction.
860 * @param mir Extended instruction to analyze.
861 */
862 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800863
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700864 /*
865 * @brief Analyze one MIR instruction
866 * @param opcode MIR instruction opcode.
867 * @param bb Basic block containing instruction.
868 * @param mir Instruction to analyze.
869 */
870 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800871
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700872 /*
873 * @brief Analyze one MIR float/double instruction
874 * @param opcode MIR instruction opcode.
875 * @param bb Basic block containing instruction.
876 * @param mir Instruction to analyze.
877 */
878 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800879
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700880 /*
881 * @brief Analyze one use of a double operand.
882 * @param rl_use Double RegLocation for the operand.
883 */
884 void AnalyzeDoubleUse(RegLocation rl_use);
Mark Mendell67c39c42014-01-31 17:28:00 -0800885
Yixin Shou7071c8d2014-03-05 06:07:48 -0500886 /*
887 * @brief Analyze one invoke-static MIR instruction
888 * @param opcode MIR instruction opcode.
889 * @param bb Basic block containing instruction.
890 * @param mir Instruction to analyze.
891 */
892 void AnalyzeInvokeStatic(int opcode, BasicBlock * bb, MIR *mir);
893
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700894 // Information derived from analysis of MIR
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700895
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700896 // The compiler temporary for the code address of the method.
897 CompilerTemp *base_of_code_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800898
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700899 // Have we decided to compute a ptr to code and store in temporary VR?
900 bool store_method_addr_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800901
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700902 // Have we used the stored method address?
903 bool store_method_addr_used_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800904
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700905 // Instructions to remove if we didn't use the stored method address.
906 LIR* setup_method_address_[2];
Mark Mendell55d0eac2014-02-06 11:02:52 -0800907
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700908 // Instructions needing patching with Method* values.
909 GrowableArray<LIR*> method_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800910
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700911 // Instructions needing patching with Class Type* values.
912 GrowableArray<LIR*> class_type_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800913
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700914 // Instructions needing patching with PC relative code addresses.
915 GrowableArray<LIR*> call_method_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800916
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700917 // Prologue decrement of stack pointer.
918 LIR* stack_decrement_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800919
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700920 // Epilogue increment of stack pointer.
921 LIR* stack_increment_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800922
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700923 // The list of const vector literals.
924 LIR *const_vectors_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400925
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700926 /*
927 * @brief Search for a matching vector literal
928 * @param mir A kMirOpConst128b MIR instruction to match.
929 * @returns pointer to matching LIR constant, or nullptr if not found.
930 */
931 LIR *ScanVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400932
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700933 /*
934 * @brief Add a constant vector literal
935 * @param mir A kMirOpConst128b MIR instruction to match.
936 */
937 LIR *AddVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400938
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700939 InToRegStorageMapping in_to_reg_storage_mapping_;
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700940
Serguei Katkov59a42af2014-07-05 00:55:46 +0700941 bool WideGPRsAreAliases() OVERRIDE {
942 return cu_->target64; // On 64b, we have 64b GPRs.
943 }
944 bool WideFPRsAreAliases() OVERRIDE {
945 return true; // xmm registers have 64b views even on x86.
946 }
947
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700948 private:
949 // The number of vector registers [0..N] reserved by a call to ReserveVectorRegisters
950 int num_reserved_vector_regs_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700951};
952
953} // namespace art
954
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700955#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_