blob: 40621b15dd542ee202d93b33c4082d52a719e4b8 [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,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +070068 RegLocation rl_dest, int lit) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070069 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
70 LIR* CheckSuspendUsingLoad() OVERRIDE;
Andreas Gampe98430592014-07-27 19:44:50 -070071 RegStorage LoadHelper(QuickEntrypointEnum trampoline) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070072 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
Andreas Gampe3c12c512014-06-24 18:46:29 +000073 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070074 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010075 OpSize size) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070076 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
77 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
Ian Rogers0f9b9c52014-06-09 01:32:12 -070078 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src,
Andreas Gampe3c12c512014-06-24 18:46:29 +000079 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070080 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
81 OpSize size) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +070082 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg) OVERRIDE;
83 void GenImplicitNullCheck(RegStorage reg, int opt_flags) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -070084
Ian Rogers0f9b9c52014-06-09 01:32:12 -070085 // Required for target - register utilities.
Chao-ying Fua77ee512014-07-01 17:43:41 -070086 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
Andreas Gampeccc60262014-07-04 18:02:38 -070087 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
88 if (wide_kind == kWide) {
89 if (cu_->target64) {
90 return As64BitReg(TargetReg32(symbolic_reg));
91 } else {
92 // x86: construct a pair.
93 DCHECK((kArg0 <= symbolic_reg && symbolic_reg < kArg3) ||
94 (kFArg0 <= symbolic_reg && symbolic_reg < kFArg3) ||
95 (kRet0 == symbolic_reg));
96 return RegStorage::MakeRegPair(TargetReg32(symbolic_reg),
97 TargetReg32(static_cast<SpecialTargetRegister>(symbolic_reg + 1)));
98 }
99 } else if (wide_kind == kRef && cu_->target64) {
100 return As64BitReg(TargetReg32(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700101 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700102 return TargetReg32(symbolic_reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700103 }
104 }
Chao-ying Fua77ee512014-07-01 17:43:41 -0700105 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
Andreas Gampeccc60262014-07-04 18:02:38 -0700106 return TargetReg(symbolic_reg, cu_->target64 ? kWide : kNotWide);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700107 }
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700108
109 RegStorage GetArgMappingToPhysicalReg(int arg_num) OVERRIDE;
110
111 RegLocation GetReturnAlt() OVERRIDE;
112 RegLocation GetReturnWideAlt() OVERRIDE;
113 RegLocation LocCReturn() OVERRIDE;
114 RegLocation LocCReturnRef() OVERRIDE;
115 RegLocation LocCReturnDouble() OVERRIDE;
116 RegLocation LocCReturnFloat() OVERRIDE;
117 RegLocation LocCReturnWide() OVERRIDE;
118
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100119 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700120 void AdjustSpillMask() OVERRIDE;
121 void ClobberCallerSave() OVERRIDE;
122 void FreeCallTemps() OVERRIDE;
123 void LockCallTemps() OVERRIDE;
124
125 void CompilerInitializeRegAlloc() OVERRIDE;
126 int VectorRegisterSize() OVERRIDE;
127 int NumReservableVectorRegisters(bool fp_used) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700128
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700129 // Required for target - miscellaneous.
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700130 void AssembleLIR() OVERRIDE;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100131 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
132 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
133 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700134 const char* GetTargetInstFmt(int opcode) OVERRIDE;
135 const char* GetTargetInstName(int opcode) OVERRIDE;
136 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100137 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700138 uint64_t GetTargetInstFlags(int opcode) OVERRIDE;
Ian Rogers5aa6e042014-06-13 16:38:24 -0700139 size_t GetInsnSize(LIR* lir) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700140 bool IsUnconditionalBranch(LIR* lir) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700141
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700142 // Get the register class for load/store of a field.
143 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100144
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700145 // Required for target - Dalvik-level generators.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700146 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700147 RegLocation rl_dest, int scale) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700148 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700149 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark) OVERRIDE;
150
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700151 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700152 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700153 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700154 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700155 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700156 RegLocation rl_src2) OVERRIDE;
157 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
158
159 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE;
160 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE;
161 bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE;
162 bool GenInlinedSqrt(CallInfo* info) OVERRIDE;
Yixin Shou7071c8d2014-03-05 06:07:48 -0500163 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
164 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700165 bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE;
166 bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE;
Andreas Gampe98430592014-07-27 19:44:50 -0700167 bool GenInlinedCharAt(CallInfo* info) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700168
169 // Long instructions.
170 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
171 RegLocation rl_src2) OVERRIDE;
172 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
173 RegLocation rl_src1, RegLocation rl_shift) OVERRIDE;
174 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
175 RegLocation rl_src2) OVERRIDE;
176 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
177 RegLocation rl_src2) OVERRIDE;
178 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
179 RegLocation rl_src2) OVERRIDE;
180 void GenNotLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
181 void GenNegLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700182 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700183 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700184 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700185 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700186 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700187 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700188 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700189 RegLocation rl_src2, bool is_div) OVERRIDE;
190 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE;
191 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
192 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
193 RegLocation rl_src1, RegLocation rl_shift) OVERRIDE;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800194
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700195 /*
196 * @brief Generate a two address long operation with a constant value
197 * @param rl_dest location of result
198 * @param rl_src constant source operand
199 * @param op Opcode to be generated
200 * @return success or not
201 */
202 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700203
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700204 /*
205 * @brief Generate a three address long operation with a constant value
206 * @param rl_dest location of result
207 * @param rl_src1 source operand
208 * @param rl_src2 constant source operand
209 * @param op Opcode to be generated
210 * @return success or not
211 */
212 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
213 Instruction::Code op);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700214 /**
215 * @brief Generate a long arithmetic operation.
216 * @param rl_dest The destination.
217 * @param rl_src1 First operand.
218 * @param rl_src2 Second operand.
219 * @param op The DEX opcode for the operation.
220 * @param is_commutative The sources can be swapped if needed.
221 */
222 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
223 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800224
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700225 /**
226 * @brief Generate a two operand long arithmetic operation.
227 * @param rl_dest The destination.
228 * @param rl_src Second operand.
229 * @param op The DEX opcode for the operation.
230 */
231 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800232
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700233 /**
234 * @brief Generate a long operation.
235 * @param rl_dest The destination. Must be in a register
236 * @param rl_src The other operand. May be in a register or in memory.
237 * @param op The DEX opcode for the operation.
238 */
239 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700240
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700241
242 // TODO: collapse reg_lo, reg_hi
243 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div)
244 OVERRIDE;
245 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div) OVERRIDE;
246 void GenDivZeroCheckWide(RegStorage reg) OVERRIDE;
247 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
248 void GenExitSequence() OVERRIDE;
249 void GenSpecialExitSequence() OVERRIDE;
250 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src) OVERRIDE;
251 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE;
252 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE;
253 void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE;
254 void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
255 int32_t true_val, int32_t false_val, RegStorage rs_dest,
256 int dest_reg_class) OVERRIDE;
257 bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE;
258 void GenMoveException(RegLocation rl_dest) OVERRIDE;
259 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
260 int first_bit, int second_bit) OVERRIDE;
261 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
262 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
263 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
264 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
265
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700266 /**
267 * @brief Implement instanceof a final class with x86 specific code.
268 * @param use_declaring_class 'true' if we can use the class itself.
269 * @param type_idx Type index to use if use_declaring_class is 'false'.
270 * @param rl_dest Result to be set to 0 or 1.
271 * @param rl_src Object to be tested.
272 */
273 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700274 RegLocation rl_src) OVERRIDE;
Chao-ying Fua0147762014-06-06 18:38:49 -0700275
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700276 // Single operation generators.
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700277 LIR* OpUnconditionalBranch(LIR* target) OVERRIDE;
278 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE;
279 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE;
280 LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE;
281 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE;
282 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
283 LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE;
284 void OpEndIT(LIR* it) OVERRIDE;
285 LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE;
286 LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE;
287 LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE;
288 void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
289 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE;
290 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE;
291 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE;
292 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE;
293 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE;
294 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE;
295 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE;
296 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE;
297 LIR* OpTestSuspend(LIR* target) OVERRIDE;
298 LIR* OpVldm(RegStorage r_base, int count) OVERRIDE;
299 LIR* OpVstm(RegStorage r_base, int count) OVERRIDE;
300 void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE;
301 bool GenInlinedCurrentThread(CallInfo* info) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700302
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700303 bool InexpensiveConstantInt(int32_t value) OVERRIDE;
304 bool InexpensiveConstantFloat(int32_t value) OVERRIDE;
305 bool InexpensiveConstantLong(int64_t value) OVERRIDE;
306 bool InexpensiveConstantDouble(int64_t value) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700307
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700308 /*
309 * @brief Should try to optimize for two address instructions?
310 * @return true if we try to avoid generating three operand instructions.
311 */
312 virtual bool GenerateTwoOperandInstructions() const { return true; }
Mark Mendelle87f9b52014-04-30 14:13:18 -0400313
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700314 /*
315 * @brief x86 specific codegen for int operations.
316 * @param opcode Operation to perform.
317 * @param rl_dest Destination for the result.
318 * @param rl_lhs Left hand operand.
319 * @param rl_rhs Right hand operand.
320 */
321 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700322 RegLocation rl_rhs) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800323
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700324 /*
325 * @brief Load the Method* of a dex method into the register.
326 * @param target_method The MethodReference of the method to be invoked.
327 * @param type How the method will be invoked.
328 * @param register that will contain the code address.
329 * @note register will be passed to TargetReg to get physical register.
330 */
331 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700332 SpecialTargetRegister symbolic_reg) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800333
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700334 /*
335 * @brief Load the Class* of a Dex Class type into the register.
336 * @param type How the method will be invoked.
337 * @param register that will contain the code address.
338 * @note register will be passed to TargetReg to get physical register.
339 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700340 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800341
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700342 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700343
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700344 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700345 NextCallInsn next_call_insn,
346 const MethodReference& target_method,
347 uint32_t vtable_idx,
348 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700349 bool skip_this) OVERRIDE;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700350
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700351 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
352 NextCallInsn next_call_insn,
353 const MethodReference& target_method,
354 uint32_t vtable_idx,
355 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700356 bool skip_this) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800357
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700358 /*
359 * @brief Generate a relative call to the method that will be patched at link time.
360 * @param target_method The MethodReference of the method to be invoked.
361 * @param type How the method will be invoked.
362 * @returns Call instruction
363 */
364 virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800365
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700366 /*
367 * @brief Handle x86 specific literals
368 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700369 void InstallLiteralPools() OVERRIDE;
Mark Mendellae9fd932014-02-10 16:14:35 -0800370
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700371 /*
372 * @brief Generate the debug_frame CFI information.
373 * @returns pointer to vector containing CFE information
374 */
Tong Shen35e1e6a2014-07-30 09:31:22 -0700375 static std::vector<uint8_t>* ReturnCommonCallFrameInformation(bool is_x86_64);
Mark Mendellae9fd932014-02-10 16:14:35 -0800376
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700377 /*
378 * @brief Generate the debug_frame FDE information.
379 * @returns pointer to vector containing CFE information
380 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700381 std::vector<uint8_t>* ReturnCallFrameInformation() OVERRIDE;
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800382
Andreas Gampe98430592014-07-27 19:44:50 -0700383 LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE;
384
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700385 protected:
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700386 RegStorage TargetReg32(SpecialTargetRegister reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700387 // Casting of RegStorage
388 RegStorage As32BitReg(RegStorage reg) {
389 DCHECK(!reg.IsPair());
390 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
391 if (kFailOnSizeError) {
392 LOG(FATAL) << "Expected 64b register " << reg.GetReg();
393 } else {
394 LOG(WARNING) << "Expected 64b register " << reg.GetReg();
395 return reg;
396 }
397 }
398 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
399 reg.GetRawBits() & RegStorage::kRegTypeMask);
400 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
401 ->GetReg().GetReg(),
402 ret_val.GetReg());
403 return ret_val;
404 }
405
406 RegStorage As64BitReg(RegStorage reg) {
407 DCHECK(!reg.IsPair());
408 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
409 if (kFailOnSizeError) {
410 LOG(FATAL) << "Expected 32b register " << reg.GetReg();
411 } else {
412 LOG(WARNING) << "Expected 32b register " << reg.GetReg();
413 return reg;
414 }
415 }
416 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
417 reg.GetRawBits() & RegStorage::kRegTypeMask);
418 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
419 ->GetReg().GetReg(),
420 ret_val.GetReg());
421 return ret_val;
422 }
423
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700424 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
425 RegStorage r_dest, OpSize size);
426 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
427 RegStorage r_src, OpSize size);
428
429 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
430
431 int AssignInsnOffsets();
432 void AssignOffsets();
433 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
434
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700435 size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700436 int32_t raw_base, int32_t displacement);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700437 void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg);
438 void EmitPrefix(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700439 int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700440 void EmitOpcode(const X86EncodingMap* entry);
441 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700442 int32_t reg_r, int32_t reg_x, int32_t reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700443 void EmitDisp(uint8_t base, int32_t disp);
444 void EmitModrmThread(uint8_t reg_or_opcode);
445 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp);
446 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale,
447 int32_t disp);
448 void EmitImm(const X86EncodingMap* entry, int64_t imm);
449 void EmitNullary(const X86EncodingMap* entry);
450 void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg);
451 void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg);
452 void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
453 void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
454 int32_t disp);
455 void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg);
456 void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp);
457 void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base,
458 int32_t raw_index, int scale, int32_t disp);
459 void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
460 int32_t disp, int32_t raw_reg);
461 void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
462 void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
463 int32_t raw_disp, int32_t imm);
464 void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp);
465 void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2);
466 void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm);
467 void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
468 int32_t imm);
469 void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1,
470 int32_t imm);
471 void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
472 void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm);
473 void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm);
474 void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
475 void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl);
476 void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl);
477 void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
478 void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc);
479 void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc);
480 void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc);
481 void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
482 int32_t cc);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800483
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700484 void EmitJmp(const X86EncodingMap* entry, int32_t rel);
485 void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc);
486 void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
487 void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp);
488 void EmitCallThread(const X86EncodingMap* entry, int32_t disp);
489 void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table,
490 int32_t raw_index, int scale, int32_t table_or_disp);
491 void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset);
492 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
493 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
494 int64_t val, ConditionCode ccode);
495 void GenConstWide(RegLocation rl_dest, int64_t value);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700496 void GenMultiplyVectorSignedByte(BasicBlock *bb, MIR *mir);
497 void GenShiftByteVector(BasicBlock *bb, MIR *mir);
498 void AndMaskVectorRegister(RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
499 void MaskVectorRegister(X86OpCode opcode, RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
500 void AppendOpcodeWithConst(X86OpCode opcode, int reg, MIR* mir);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400501
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700502 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800503
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700504 /*
505 * @brief Ensure that a temporary register is byte addressable.
506 * @returns a temporary guarenteed to be byte addressable.
507 */
508 virtual RegStorage AllocateByteRegister();
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800509
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700510 /*
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700511 * @brief Use a wide temporary as a 128-bit register
512 * @returns a 128-bit temporary register.
513 */
514 virtual RegStorage Get128BitRegister(RegStorage reg);
515
516 /*
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700517 * @brief Check if a register is byte addressable.
518 * @returns true if a register is byte addressable.
519 */
520 bool IsByteRegister(RegStorage reg);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700521
522 void GenDivRemLongLit(RegLocation rl_dest, RegLocation rl_src, int64_t imm, bool is_div);
523
DaniilSokolov70c4f062014-06-24 17:34:00 -0700524 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700525
526 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700527 * @brief generate inline code for fast case of Strng.indexOf.
528 * @param info Call parameters
529 * @param zero_based 'true' if the index into the string is 0.
530 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
531 * generated.
532 */
533 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
Mark Mendelle87f9b52014-04-30 14:13:18 -0400534
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700535 /**
536 * @brief Reserve a fixed number of vector registers from the register pool
537 * @details The mir->dalvikInsn.vA specifies an N such that vector registers
538 * [0..N-1] are removed from the temporary pool. The caller must call
539 * ReturnVectorRegisters before calling ReserveVectorRegisters again.
540 * Also sets the num_reserved_vector_regs_ to the specified value
541 * @param mir whose vA specifies the number of registers to reserve
542 */
543 void ReserveVectorRegisters(MIR* mir);
544
545 /**
546 * @brief Return all the reserved vector registers to the temp pool
547 * @details Returns [0..num_reserved_vector_regs_]
548 */
549 void ReturnVectorRegisters();
550
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700551 /*
552 * @brief Load 128 bit constant into vector register.
553 * @param bb The basic block in which the MIR is from.
554 * @param mir The MIR whose opcode is kMirConstVector
555 * @note vA is the TypeSize for the register.
556 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
557 */
558 void GenConst128(BasicBlock* bb, MIR* mir);
Mark Mendell4028a6c2014-02-19 20:06:20 -0800559
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700560 /*
561 * @brief MIR to move a vectorized register to another.
562 * @param bb The basic block in which the MIR is from.
563 * @param mir The MIR whose opcode is kMirConstVector.
564 * @note vA: TypeSize
565 * @note vB: destination
566 * @note vC: source
567 */
568 void GenMoveVector(BasicBlock *bb, MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400569
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700570 /*
571 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know the type of the vector.
572 * @param bb The basic block in which the MIR is from.
573 * @param mir The MIR whose opcode is kMirConstVector.
574 * @note vA: TypeSize
575 * @note vB: destination and source
576 * @note vC: source
577 */
578 void GenMultiplyVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400579
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700580 /*
581 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the type of the vector.
582 * @param bb The basic block in which the MIR is from.
583 * @param mir The MIR whose opcode is kMirConstVector.
584 * @note vA: TypeSize
585 * @note vB: destination and source
586 * @note vC: source
587 */
588 void GenAddVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400589
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700590 /*
591 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the type of the vector.
592 * @param bb The basic block in which the MIR is from.
593 * @param mir The MIR whose opcode is kMirConstVector.
594 * @note vA: TypeSize
595 * @note vB: destination and source
596 * @note vC: source
597 */
598 void GenSubtractVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400599
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700600 /*
601 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the type of the vector.
602 * @param bb The basic block in which the MIR is from.
603 * @param mir The MIR whose opcode is kMirConstVector.
604 * @note vA: TypeSize
605 * @note vB: destination and source
606 * @note vC: immediate
607 */
608 void GenShiftLeftVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400609
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700610 /*
611 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to know the type of the vector.
612 * @param bb The basic block in which the MIR is from.
613 * @param mir The MIR whose opcode is kMirConstVector.
614 * @note vA: TypeSize
615 * @note vB: destination and source
616 * @note vC: immediate
617 */
618 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400619
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700620 /*
621 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA to know the type of the vector.
622 * @param bb The basic block in which the MIR is from..
623 * @param mir The MIR whose opcode is kMirConstVector.
624 * @note vA: TypeSize
625 * @note vB: destination and source
626 * @note vC: immediate
627 */
628 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400629
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700630 /*
631 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the type of the vector.
632 * @note vA: TypeSize
633 * @note vB: destination and source
634 * @note vC: source
635 */
636 void GenAndVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400637
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700638 /*
639 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the type of the vector.
640 * @param bb The basic block in which the MIR is from.
641 * @param mir The MIR whose opcode is kMirConstVector.
642 * @note vA: TypeSize
643 * @note vB: destination and source
644 * @note vC: source
645 */
646 void GenOrVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400647
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700648 /*
649 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the type of the vector.
650 * @param bb The basic block in which the MIR is from.
651 * @param mir The MIR whose opcode is kMirConstVector.
652 * @note vA: TypeSize
653 * @note vB: destination and source
654 * @note vC: source
655 */
656 void GenXorVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400657
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700658 /*
659 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
660 * @param bb The basic block in which the MIR is from.
661 * @param mir The MIR whose opcode is kMirConstVector.
662 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
663 * @note vA: TypeSize
664 * @note vB: destination and source VR (not vector register)
665 * @note vC: source (vector register)
666 */
667 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400668
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700669 /*
670 * @brief Extract a packed element into a single VR.
671 * @param bb The basic block in which the MIR is from.
672 * @param mir The MIR whose opcode is kMirConstVector.
673 * @note vA: TypeSize
674 * @note vB: destination VR (not vector register)
675 * @note vC: source (vector register)
676 * @note arg[0]: The index to use for extraction from vector register (which packed element).
677 */
678 void GenReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400679
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700680 /*
681 * @brief Create a vector value, with all TypeSize values equal to vC
682 * @param bb The basic block in which the MIR is from.
683 * @param mir The MIR whose opcode is kMirConstVector.
684 * @note vA: TypeSize.
685 * @note vB: destination vector register.
686 * @note vC: source VR (not vector register).
687 */
688 void GenSetVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400689
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700690 /*
691 * @brief Generate code for a vector opcode.
692 * @param bb The basic block in which the MIR is from.
693 * @param mir The MIR whose opcode is a non-standard opcode.
694 */
695 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400696
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700697 /*
698 * @brief Return the correct x86 opcode for the Dex operation
699 * @param op Dex opcode for the operation
700 * @param loc Register location of the operand
701 * @param is_high_op 'true' if this is an operation on the high word
702 * @param value Immediate value for the operation. Used for byte variants
703 * @returns the correct x86 opcode to perform the operation
704 */
705 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400706
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700707 /*
708 * @brief Return the correct x86 opcode for the Dex operation
709 * @param op Dex opcode for the operation
710 * @param dest location of the destination. May be register or memory.
711 * @param rhs Location for the rhs of the operation. May be in register or memory.
712 * @param is_high_op 'true' if this is an operation on the high word
713 * @returns the correct x86 opcode to perform the operation
714 * @note at most one location may refer to memory
715 */
716 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
717 bool is_high_op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800718
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700719 /*
720 * @brief Is this operation a no-op for this opcode and value
721 * @param op Dex opcode for the operation
722 * @param value Immediate value for the operation.
723 * @returns 'true' if the operation will have no effect
724 */
725 bool IsNoOp(Instruction::Code op, int32_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800726
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700727 /**
728 * @brief Calculate magic number and shift for a given divisor
729 * @param divisor divisor number for calculation
730 * @param magic hold calculated magic number
731 * @param shift hold calculated shift
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700732 * @param is_long 'true' if divisor is jlong, 'false' for jint.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700733 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700734 void CalculateMagicAndShift(int64_t divisor, int64_t& magic, int& shift, bool is_long);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800735
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700736 /*
737 * @brief Generate an integer div or rem operation.
738 * @param rl_dest Destination Location.
739 * @param rl_src1 Numerator Location.
740 * @param rl_src2 Divisor Location.
741 * @param is_div 'true' if this is a division, 'false' for a remainder.
742 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
743 */
744 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
745 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800746
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700747 /*
748 * @brief Generate an integer div or rem operation by a literal.
749 * @param rl_dest Destination Location.
750 * @param rl_src Numerator Location.
751 * @param lit Divisor.
752 * @param is_div 'true' if this is a division, 'false' for a remainder.
753 */
754 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800755
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700756 /*
757 * Generate code to implement long shift operations.
758 * @param opcode The DEX opcode to specify the shift type.
759 * @param rl_dest The destination.
760 * @param rl_src The value to be shifted.
761 * @param shift_amount How much to shift.
762 * @returns the RegLocation of the result.
763 */
764 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
765 RegLocation rl_src, int shift_amount);
766 /*
767 * Generate an imul of a register by a constant or a better sequence.
768 * @param dest Destination Register.
769 * @param src Source Register.
770 * @param val Constant multiplier.
771 */
772 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800773
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700774 /*
775 * Generate an imul of a memory location by a constant or a better sequence.
776 * @param dest Destination Register.
777 * @param sreg Symbolic register.
778 * @param displacement Displacement on stack of Symbolic Register.
779 * @param val Constant multiplier.
780 */
781 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800782
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700783 /*
784 * @brief Compare memory to immediate, and branch if condition true.
785 * @param cond The condition code that when true will branch to the target.
786 * @param temp_reg A temporary register that can be used if compare memory is not
787 * supported by the architecture.
788 * @param base_reg The register holding the base address.
789 * @param offset The offset from the base.
790 * @param check_value The immediate to compare to.
Dave Allison69dfe512014-07-11 17:11:58 +0000791 * @param target branch target (or nullptr)
792 * @param compare output for getting LIR for comparison (or nullptr)
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700793 */
794 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
Dave Allison69dfe512014-07-11 17:11:58 +0000795 int offset, int check_value, LIR* target, LIR** compare);
Mark Mendell766e9292014-01-27 07:55:47 -0800796
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700797 void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double);
798
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700799 /*
800 * Can this operation be using core registers without temporaries?
801 * @param rl_lhs Left hand operand.
802 * @param rl_rhs Right hand operand.
803 * @returns 'true' if the operation can proceed without needing temporary regs.
804 */
805 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800806
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700807 /**
808 * @brief Generates inline code for conversion of long to FP by using x87/
809 * @param rl_dest The destination of the FP.
810 * @param rl_src The source of the long.
811 * @param is_double 'true' if dealing with double, 'false' for float.
812 */
813 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Mark Mendell67c39c42014-01-31 17:28:00 -0800814
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700815 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
816 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
817
818 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
819 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
820 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
821 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset);
822 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset);
823 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
824 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
825 void OpTlsCmp(ThreadOffset<4> offset, int val);
826 void OpTlsCmp(ThreadOffset<8> offset, int val);
827
828 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
829
830 void SpillCoreRegs();
831 void UnSpillCoreRegs();
832 void UnSpillFPRegs();
833 void SpillFPRegs();
834
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700835 /*
836 * @brief Perform MIR analysis before compiling method.
837 * @note Invokes Mir2LiR::Materialize after analysis.
838 */
839 void Materialize();
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800840
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700841 /*
842 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
843 * without regard to data type. In practice, this can result in UpdateLoc returning a
844 * location record for a Dalvik float value in a core register, and vis-versa. For targets
845 * which can inexpensively move data between core and float registers, this can often be a win.
846 * However, for x86 this is generally not a win. These variants of UpdateLoc()
847 * take a register class argument - and will return an in-register location record only if
848 * the value is live in a temp register of the correct class. Additionally, if the value is in
849 * a temp register of the wrong register class, it will be clobbered.
850 */
851 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
852 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
Mark Mendell67c39c42014-01-31 17:28:00 -0800853
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700854 /*
855 * @brief Analyze MIR before generating code, to prepare for the code generation.
856 */
857 void AnalyzeMIR();
buzbee30adc732014-05-09 15:10:18 -0700858
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700859 /*
860 * @brief Analyze one basic block.
861 * @param bb Basic block to analyze.
862 */
863 void AnalyzeBB(BasicBlock * bb);
Mark Mendell67c39c42014-01-31 17:28:00 -0800864
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700865 /*
866 * @brief Analyze one extended MIR instruction
867 * @param opcode MIR instruction opcode.
868 * @param bb Basic block containing instruction.
869 * @param mir Extended instruction to analyze.
870 */
871 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800872
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700873 /*
874 * @brief Analyze one MIR instruction
875 * @param opcode MIR instruction opcode.
876 * @param bb Basic block containing instruction.
877 * @param mir Instruction to analyze.
878 */
879 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800880
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700881 /*
882 * @brief Analyze one MIR float/double instruction
883 * @param opcode MIR instruction opcode.
884 * @param bb Basic block containing instruction.
885 * @param mir Instruction to analyze.
886 */
887 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800888
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700889 /*
890 * @brief Analyze one use of a double operand.
891 * @param rl_use Double RegLocation for the operand.
892 */
893 void AnalyzeDoubleUse(RegLocation rl_use);
Mark Mendell67c39c42014-01-31 17:28:00 -0800894
Yixin Shou7071c8d2014-03-05 06:07:48 -0500895 /*
896 * @brief Analyze one invoke-static MIR instruction
897 * @param opcode MIR instruction opcode.
898 * @param bb Basic block containing instruction.
899 * @param mir Instruction to analyze.
900 */
901 void AnalyzeInvokeStatic(int opcode, BasicBlock * bb, MIR *mir);
902
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700903 // Information derived from analysis of MIR
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700904
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700905 // The compiler temporary for the code address of the method.
906 CompilerTemp *base_of_code_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800907
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700908 // Have we decided to compute a ptr to code and store in temporary VR?
909 bool store_method_addr_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800910
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700911 // Have we used the stored method address?
912 bool store_method_addr_used_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800913
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700914 // Instructions to remove if we didn't use the stored method address.
915 LIR* setup_method_address_[2];
Mark Mendell55d0eac2014-02-06 11:02:52 -0800916
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700917 // Instructions needing patching with Method* values.
918 GrowableArray<LIR*> method_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800919
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700920 // Instructions needing patching with Class Type* values.
921 GrowableArray<LIR*> class_type_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800922
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700923 // Instructions needing patching with PC relative code addresses.
924 GrowableArray<LIR*> call_method_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800925
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700926 // Prologue decrement of stack pointer.
927 LIR* stack_decrement_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800928
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700929 // Epilogue increment of stack pointer.
930 LIR* stack_increment_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800931
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700932 // The list of const vector literals.
933 LIR *const_vectors_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400934
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700935 /*
936 * @brief Search for a matching vector literal
937 * @param mir A kMirOpConst128b MIR instruction to match.
938 * @returns pointer to matching LIR constant, or nullptr if not found.
939 */
940 LIR *ScanVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400941
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700942 /*
943 * @brief Add a constant vector literal
944 * @param mir A kMirOpConst128b MIR instruction to match.
945 */
946 LIR *AddVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400947
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700948 InToRegStorageMapping in_to_reg_storage_mapping_;
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700949
Serguei Katkov59a42af2014-07-05 00:55:46 +0700950 bool WideGPRsAreAliases() OVERRIDE {
951 return cu_->target64; // On 64b, we have 64b GPRs.
952 }
953 bool WideFPRsAreAliases() OVERRIDE {
954 return true; // xmm registers have 64b views even on x86.
955 }
956
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700957 /*
958 * @brief Dump a RegLocation using printf
959 * @param loc Register location to dump
960 */
961 static void DumpRegLocation(RegLocation loc);
962
963 static const X86EncodingMap EncodingMap[kX86Last];
964
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700965 private:
966 // The number of vector registers [0..N] reserved by a call to ReserveVectorRegisters
967 int num_reserved_vector_regs_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700968};
969
970} // namespace art
971
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700972#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_