blob: b3544dafba6f14eec39b93e783ba0b516d551d4e [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"
Andreas Gampe53c913b2014-08-12 23:19:23 -070021#include "dex/quick/mir_to_lir.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070022#include "x86_lir.h"
23
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070024#include <map>
Maxim Kazantsev6dccdc22014-08-18 18:43:55 +070025#include <vector>
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070026
Brian Carlstrom7940e442013-07-12 13:46:57 -070027namespace art {
28
Mark Mendelle87f9b52014-04-30 14:13:18 -040029class X86Mir2Lir : public Mir2Lir {
Ian Rogers0f9b9c52014-06-09 01:32:12 -070030 protected:
31 class InToRegStorageMapper {
32 public:
Serguei Katkov407a9d22014-07-05 03:09:32 +070033 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref) = 0;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070034 virtual ~InToRegStorageMapper() {}
35 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070036
Ian Rogers0f9b9c52014-06-09 01:32:12 -070037 class InToRegStorageX86_64Mapper : public InToRegStorageMapper {
38 public:
Chao-ying Fua77ee512014-07-01 17:43:41 -070039 explicit InToRegStorageX86_64Mapper(Mir2Lir* ml) : ml_(ml), cur_core_reg_(0), cur_fp_reg_(0) {}
Ian Rogers0f9b9c52014-06-09 01:32:12 -070040 virtual ~InToRegStorageX86_64Mapper() {}
Serguei Katkov407a9d22014-07-05 03:09:32 +070041 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref);
Chao-ying Fua77ee512014-07-01 17:43:41 -070042 protected:
43 Mir2Lir* ml_;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070044 private:
45 int cur_core_reg_;
46 int cur_fp_reg_;
47 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070048
Ian Rogers0f9b9c52014-06-09 01:32:12 -070049 class InToRegStorageMapping {
50 public:
51 InToRegStorageMapping() : max_mapped_in_(0), is_there_stack_mapped_(false),
52 initialized_(false) {}
53 void Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper);
54 int GetMaxMappedIn() { return max_mapped_in_; }
55 bool IsThereStackMapped() { return is_there_stack_mapped_; }
56 RegStorage Get(int in_position);
57 bool IsInitialized() { return initialized_; }
58 private:
59 std::map<int, RegStorage> mapping_;
60 int max_mapped_in_;
61 bool is_there_stack_mapped_;
62 bool initialized_;
63 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070064
Maxim Kazantsev6dccdc22014-08-18 18:43:55 +070065 class ExplicitTempRegisterLock {
66 public:
67 ExplicitTempRegisterLock(X86Mir2Lir* mir_to_lir, int n_regs, ...);
68 ~ExplicitTempRegisterLock();
69 protected:
70 std::vector<RegStorage> temp_regs_;
71 X86Mir2Lir* const mir_to_lir_;
72 };
73
Ian Rogers0f9b9c52014-06-09 01:32:12 -070074 public:
Elena Sayapinadd644502014-07-01 18:39:52 +070075 X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
Brian Carlstrom7940e442013-07-12 13:46:57 -070076
Ian Rogers0f9b9c52014-06-09 01:32:12 -070077 // Required for target - codegen helpers.
78 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +070079 RegLocation rl_dest, int lit) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070080 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
81 LIR* CheckSuspendUsingLoad() OVERRIDE;
Andreas Gampe98430592014-07-27 19:44:50 -070082 RegStorage LoadHelper(QuickEntrypointEnum trampoline) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070083 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
Andreas Gampe3c12c512014-06-24 18:46:29 +000084 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070085 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010086 OpSize size) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070087 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
88 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
Ian Rogers0f9b9c52014-06-09 01:32:12 -070089 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src,
Andreas Gampe3c12c512014-06-24 18:46:29 +000090 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070091 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
92 OpSize size) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +070093 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg) OVERRIDE;
94 void GenImplicitNullCheck(RegStorage reg, int opt_flags) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -070095
Ian Rogers0f9b9c52014-06-09 01:32:12 -070096 // Required for target - register utilities.
Chao-ying Fua77ee512014-07-01 17:43:41 -070097 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
Andreas Gampeccc60262014-07-04 18:02:38 -070098 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
99 if (wide_kind == kWide) {
100 if (cu_->target64) {
101 return As64BitReg(TargetReg32(symbolic_reg));
102 } else {
103 // x86: construct a pair.
104 DCHECK((kArg0 <= symbolic_reg && symbolic_reg < kArg3) ||
105 (kFArg0 <= symbolic_reg && symbolic_reg < kFArg3) ||
106 (kRet0 == symbolic_reg));
107 return RegStorage::MakeRegPair(TargetReg32(symbolic_reg),
108 TargetReg32(static_cast<SpecialTargetRegister>(symbolic_reg + 1)));
109 }
110 } else if (wide_kind == kRef && cu_->target64) {
111 return As64BitReg(TargetReg32(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700112 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700113 return TargetReg32(symbolic_reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700114 }
115 }
Chao-ying Fua77ee512014-07-01 17:43:41 -0700116 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
Andreas Gampeccc60262014-07-04 18:02:38 -0700117 return TargetReg(symbolic_reg, cu_->target64 ? kWide : kNotWide);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700118 }
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700119
120 RegStorage GetArgMappingToPhysicalReg(int arg_num) OVERRIDE;
121
122 RegLocation GetReturnAlt() OVERRIDE;
123 RegLocation GetReturnWideAlt() OVERRIDE;
124 RegLocation LocCReturn() OVERRIDE;
125 RegLocation LocCReturnRef() OVERRIDE;
126 RegLocation LocCReturnDouble() OVERRIDE;
127 RegLocation LocCReturnFloat() OVERRIDE;
128 RegLocation LocCReturnWide() OVERRIDE;
129
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100130 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700131 void AdjustSpillMask() OVERRIDE;
132 void ClobberCallerSave() OVERRIDE;
133 void FreeCallTemps() OVERRIDE;
134 void LockCallTemps() OVERRIDE;
135
136 void CompilerInitializeRegAlloc() OVERRIDE;
137 int VectorRegisterSize() OVERRIDE;
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700138 int NumReservableVectorRegisters(bool long_or_fp) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700139
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700140 // Required for target - miscellaneous.
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700141 void AssembleLIR() OVERRIDE;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100142 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
143 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
144 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700145 const char* GetTargetInstFmt(int opcode) OVERRIDE;
146 const char* GetTargetInstName(int opcode) OVERRIDE;
147 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100148 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700149 uint64_t GetTargetInstFlags(int opcode) OVERRIDE;
Ian Rogers5aa6e042014-06-13 16:38:24 -0700150 size_t GetInsnSize(LIR* lir) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700151 bool IsUnconditionalBranch(LIR* lir) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700152
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700153 // Get the register class for load/store of a field.
154 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100155
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700156 // Required for target - Dalvik-level generators.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700157 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700158 RegLocation rl_dest, int scale) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700159 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700160 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark) OVERRIDE;
161
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700162 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700163 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700164 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700165 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700166 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700167 RegLocation rl_src2) OVERRIDE;
168 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
169
170 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE;
171 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE;
172 bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE;
Yixin Shou8c914c02014-07-28 14:17:09 -0400173 bool GenInlinedReverseBits(CallInfo* info, OpSize size) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700174 bool GenInlinedSqrt(CallInfo* info) OVERRIDE;
Yixin Shou7071c8d2014-03-05 06:07:48 -0500175 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
176 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700177 bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE;
178 bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE;
Andreas Gampe98430592014-07-27 19:44:50 -0700179 bool GenInlinedCharAt(CallInfo* info) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700180
181 // Long instructions.
Andreas Gampec76c6142014-08-04 16:30:03 -0700182 void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
183 RegLocation rl_src2) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700184 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
185 RegLocation rl_src2) OVERRIDE;
186 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
187 RegLocation rl_src1, RegLocation rl_shift) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700188 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE;
189 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
190 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
191 RegLocation rl_src1, RegLocation rl_shift) OVERRIDE;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800192
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700193 /*
194 * @brief Generate a two address long operation with a constant value
195 * @param rl_dest location of result
196 * @param rl_src constant source operand
197 * @param op Opcode to be generated
198 * @return success or not
199 */
200 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700201
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700202 /*
203 * @brief Generate a three address long operation with a constant value
204 * @param rl_dest location of result
205 * @param rl_src1 source operand
206 * @param rl_src2 constant source operand
207 * @param op Opcode to be generated
208 * @return success or not
209 */
210 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
211 Instruction::Code op);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700212 /**
213 * @brief Generate a long arithmetic operation.
214 * @param rl_dest The destination.
215 * @param rl_src1 First operand.
216 * @param rl_src2 Second operand.
217 * @param op The DEX opcode for the operation.
218 * @param is_commutative The sources can be swapped if needed.
219 */
220 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
221 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800222
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700223 /**
224 * @brief Generate a two operand long arithmetic operation.
225 * @param rl_dest The destination.
226 * @param rl_src Second operand.
227 * @param op The DEX opcode for the operation.
228 */
229 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800230
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700231 /**
232 * @brief Generate a long operation.
233 * @param rl_dest The destination. Must be in a register
234 * @param rl_src The other operand. May be in a register or in memory.
235 * @param op The DEX opcode for the operation.
236 */
237 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700238
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700239
240 // TODO: collapse reg_lo, reg_hi
241 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div)
242 OVERRIDE;
243 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div) OVERRIDE;
244 void GenDivZeroCheckWide(RegStorage reg) OVERRIDE;
245 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
246 void GenExitSequence() OVERRIDE;
247 void GenSpecialExitSequence() OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700248 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE;
249 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE;
250 void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE;
251 void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
252 int32_t true_val, int32_t false_val, RegStorage rs_dest,
253 int dest_reg_class) OVERRIDE;
254 bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE;
255 void GenMoveException(RegLocation rl_dest) OVERRIDE;
256 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
257 int first_bit, int second_bit) OVERRIDE;
258 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
259 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampe48971b32014-08-06 10:09:01 -0700260 void GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
261 void GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700262
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700263 /**
264 * @brief Implement instanceof a final class with x86 specific code.
265 * @param use_declaring_class 'true' if we can use the class itself.
266 * @param type_idx Type index to use if use_declaring_class is 'false'.
267 * @param rl_dest Result to be set to 0 or 1.
268 * @param rl_src Object to be tested.
269 */
270 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700271 RegLocation rl_src) OVERRIDE;
Chao-ying Fua0147762014-06-06 18:38:49 -0700272
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700273 // Single operation generators.
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700274 LIR* OpUnconditionalBranch(LIR* target) OVERRIDE;
275 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE;
276 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE;
277 LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE;
278 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE;
279 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
280 LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE;
281 void OpEndIT(LIR* it) OVERRIDE;
282 LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE;
283 LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE;
284 LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE;
285 void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
286 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE;
287 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE;
288 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE;
289 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE;
290 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE;
291 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE;
292 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE;
293 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE;
294 LIR* OpTestSuspend(LIR* target) OVERRIDE;
295 LIR* OpVldm(RegStorage r_base, int count) OVERRIDE;
296 LIR* OpVstm(RegStorage r_base, int count) OVERRIDE;
297 void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE;
298 bool GenInlinedCurrentThread(CallInfo* info) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700299
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700300 bool InexpensiveConstantInt(int32_t value) OVERRIDE;
301 bool InexpensiveConstantFloat(int32_t value) OVERRIDE;
302 bool InexpensiveConstantLong(int64_t value) OVERRIDE;
303 bool InexpensiveConstantDouble(int64_t value) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700304
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700305 /*
306 * @brief Should try to optimize for two address instructions?
307 * @return true if we try to avoid generating three operand instructions.
308 */
309 virtual bool GenerateTwoOperandInstructions() const { return true; }
Mark Mendelle87f9b52014-04-30 14:13:18 -0400310
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700311 /*
312 * @brief x86 specific codegen for int operations.
313 * @param opcode Operation to perform.
314 * @param rl_dest Destination for the result.
315 * @param rl_lhs Left hand operand.
316 * @param rl_rhs Right hand operand.
317 */
318 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700319 RegLocation rl_rhs) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800320
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700321 /*
322 * @brief Load the Method* of a dex method into the register.
323 * @param target_method The MethodReference of the method to be invoked.
324 * @param type How the method will be invoked.
325 * @param register that will contain the code address.
326 * @note register will be passed to TargetReg to get physical register.
327 */
328 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700329 SpecialTargetRegister symbolic_reg) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800330
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700331 /*
332 * @brief Load the Class* of a Dex Class type into the register.
Fred Shihe7f82e22014-08-06 10:46:37 -0700333 * @param dex DexFile that contains the class type.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700334 * @param type How the method will be invoked.
335 * @param register that will contain the code address.
336 * @note register will be passed to TargetReg to get physical register.
337 */
Fred Shihe7f82e22014-08-06 10:46:37 -0700338 void LoadClassType(const DexFile& dex_file, uint32_t type_idx,
339 SpecialTargetRegister symbolic_reg) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800340
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700341 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700342
Vladimir Markof4da6752014-08-01 19:04:18 +0100343 NextCallInsn GetNextSDCallInsn() OVERRIDE;
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 */
Vladimir Markof4da6752014-08-01 19:04:18 +0100364 LIR* CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
365
366 /*
367 * @brief Generate the actual call insn based on the method info.
368 * @param method_info the lowering info for the method call.
369 * @returns Call instruction
370 */
371 LIR* GenCallInsn(const MirMethodLoweringInfo& method_info) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800372
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700373 /*
374 * @brief Handle x86 specific literals
375 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700376 void InstallLiteralPools() OVERRIDE;
Mark Mendellae9fd932014-02-10 16:14:35 -0800377
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700378 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700379 * @brief Generate the debug_frame FDE information.
380 * @returns pointer to vector containing CFE information
381 */
Tong Shen547cdfd2014-08-05 01:54:19 -0700382 std::vector<uint8_t>* ReturnFrameDescriptionEntry() OVERRIDE;
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800383
Andreas Gampe98430592014-07-27 19:44:50 -0700384 LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE;
385
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700386 protected:
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700387 RegStorage TargetReg32(SpecialTargetRegister reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700388 // Casting of RegStorage
389 RegStorage As32BitReg(RegStorage reg) {
390 DCHECK(!reg.IsPair());
391 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
392 if (kFailOnSizeError) {
393 LOG(FATAL) << "Expected 64b register " << reg.GetReg();
394 } else {
395 LOG(WARNING) << "Expected 64b register " << reg.GetReg();
396 return reg;
397 }
398 }
399 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
400 reg.GetRawBits() & RegStorage::kRegTypeMask);
401 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
402 ->GetReg().GetReg(),
403 ret_val.GetReg());
404 return ret_val;
405 }
406
407 RegStorage As64BitReg(RegStorage reg) {
408 DCHECK(!reg.IsPair());
409 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
410 if (kFailOnSizeError) {
411 LOG(FATAL) << "Expected 32b register " << reg.GetReg();
412 } else {
413 LOG(WARNING) << "Expected 32b register " << reg.GetReg();
414 return reg;
415 }
416 }
417 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
418 reg.GetRawBits() & RegStorage::kRegTypeMask);
419 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
420 ->GetReg().GetReg(),
421 ret_val.GetReg());
422 return ret_val;
423 }
424
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700425 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
426 RegStorage r_dest, OpSize size);
427 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
Jean Christophe Beylerb5bce7c2014-07-25 12:32:18 -0700428 RegStorage r_src, OpSize size, int opt_flags = 0);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700429
430 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
431
432 int AssignInsnOffsets();
433 void AssignOffsets();
434 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
435
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700436 size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700437 int32_t raw_base, int32_t displacement);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700438 void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg);
439 void EmitPrefix(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700440 int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700441 void EmitOpcode(const X86EncodingMap* entry);
442 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700443 int32_t reg_r, int32_t reg_x, int32_t reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700444 void EmitDisp(uint8_t base, int32_t disp);
445 void EmitModrmThread(uint8_t reg_or_opcode);
446 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp);
447 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale,
448 int32_t disp);
449 void EmitImm(const X86EncodingMap* entry, int64_t imm);
450 void EmitNullary(const X86EncodingMap* entry);
451 void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg);
452 void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg);
453 void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
454 void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
455 int32_t disp);
456 void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg);
457 void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp);
458 void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base,
459 int32_t raw_index, int scale, int32_t disp);
460 void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
461 int32_t disp, int32_t raw_reg);
462 void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
463 void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
464 int32_t raw_disp, int32_t imm);
465 void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp);
466 void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2);
467 void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm);
468 void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
469 int32_t imm);
470 void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1,
471 int32_t imm);
472 void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
473 void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm);
474 void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm);
475 void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
476 void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl);
477 void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl);
Yixin Shouf40f8902014-08-14 14:10:32 -0400478 void EmitShiftRegRegCl(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2,
479 int32_t raw_cl);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700480 void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
481 void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc);
482 void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc);
483 void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc);
484 void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
485 int32_t cc);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800486
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700487 void EmitJmp(const X86EncodingMap* entry, int32_t rel);
488 void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc);
489 void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
490 void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp);
491 void EmitCallThread(const X86EncodingMap* entry, int32_t disp);
492 void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table,
493 int32_t raw_index, int scale, int32_t table_or_disp);
494 void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset);
495 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
496 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
497 int64_t val, ConditionCode ccode);
498 void GenConstWide(RegLocation rl_dest, int64_t value);
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700499 void GenMultiplyVectorSignedByte(RegStorage rs_dest_src1, RegStorage rs_src2);
500 void GenMultiplyVectorLong(RegStorage rs_dest_src1, RegStorage rs_src2);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700501 void GenShiftByteVector(BasicBlock *bb, MIR *mir);
Yixin Shouf40f8902014-08-14 14:10:32 -0400502 void AndMaskVectorRegister(RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3,
503 uint32_t m4);
504 void MaskVectorRegister(X86OpCode opcode, RegStorage rs_src1, uint32_t m1, uint32_t m2,
505 uint32_t m3, uint32_t m4);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700506 void AppendOpcodeWithConst(X86OpCode opcode, int reg, MIR* mir);
Mark Mendell0a1174e2014-09-11 14:51:02 -0400507 virtual void LoadVectorRegister(RegStorage rs_dest, RegStorage rs_src, OpSize opsize,
508 int op_mov);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400509
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700510 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800511
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700512 /*
513 * @brief Ensure that a temporary register is byte addressable.
514 * @returns a temporary guarenteed to be byte addressable.
515 */
516 virtual RegStorage AllocateByteRegister();
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800517
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700518 /*
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700519 * @brief Use a wide temporary as a 128-bit register
520 * @returns a 128-bit temporary register.
521 */
522 virtual RegStorage Get128BitRegister(RegStorage reg);
523
524 /*
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700525 * @brief Check if a register is byte addressable.
526 * @returns true if a register is byte addressable.
527 */
528 bool IsByteRegister(RegStorage reg);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700529
530 void GenDivRemLongLit(RegLocation rl_dest, RegLocation rl_src, int64_t imm, bool is_div);
531
DaniilSokolov70c4f062014-06-24 17:34:00 -0700532 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700533
534 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700535 * @brief generate inline code for fast case of Strng.indexOf.
536 * @param info Call parameters
537 * @param zero_based 'true' if the index into the string is 0.
538 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
539 * generated.
540 */
541 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
Mark Mendelle87f9b52014-04-30 14:13:18 -0400542
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700543 /**
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700544 * @brief Used to reserve a range of vector registers.
545 * @see kMirOpReserveVectorRegisters
546 * @param mir The extended MIR for reservation.
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700547 */
548 void ReserveVectorRegisters(MIR* mir);
549
550 /**
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700551 * @brief Used to return a range of vector registers.
552 * @see kMirOpReturnVectorRegisters
553 * @param mir The extended MIR for returning vector regs.
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700554 */
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700555 void ReturnVectorRegisters(MIR* mir);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700556
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700557 /*
558 * @brief Load 128 bit constant into vector register.
559 * @param bb The basic block in which the MIR is from.
560 * @param mir The MIR whose opcode is kMirConstVector
561 * @note vA is the TypeSize for the register.
562 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
563 */
564 void GenConst128(BasicBlock* bb, MIR* mir);
Mark Mendell4028a6c2014-02-19 20:06:20 -0800565
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700566 /*
567 * @brief MIR to move a vectorized register to another.
568 * @param bb The basic block in which the MIR is from.
569 * @param mir The MIR whose opcode is kMirConstVector.
570 * @note vA: TypeSize
571 * @note vB: destination
572 * @note vC: source
573 */
574 void GenMoveVector(BasicBlock *bb, MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400575
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700576 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400577 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know
578 * the type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700579 * @param bb The basic block in which the MIR is from.
580 * @param mir The MIR whose opcode is kMirConstVector.
581 * @note vA: TypeSize
582 * @note vB: destination and source
583 * @note vC: source
584 */
585 void GenMultiplyVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400586
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700587 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400588 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the
589 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700590 * @param bb The basic block in which the MIR is from.
591 * @param mir The MIR whose opcode is kMirConstVector.
592 * @note vA: TypeSize
593 * @note vB: destination and source
594 * @note vC: source
595 */
596 void GenAddVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400597
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700598 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400599 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the
600 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700601 * @param bb The basic block in which the MIR is from.
602 * @param mir The MIR whose opcode is kMirConstVector.
603 * @note vA: TypeSize
604 * @note vB: destination and source
605 * @note vC: source
606 */
607 void GenSubtractVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400608
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700609 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400610 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the
611 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700612 * @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 GenShiftLeftVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400619
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700620 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400621 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to
622 * know the type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700623 * @param bb The basic block in which the MIR is from.
624 * @param mir The MIR whose opcode is kMirConstVector.
625 * @note vA: TypeSize
626 * @note vB: destination and source
627 * @note vC: immediate
628 */
629 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400630
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700631 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400632 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA
633 * to know the type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700634 * @param bb The basic block in which the MIR is from..
635 * @param mir The MIR whose opcode is kMirConstVector.
636 * @note vA: TypeSize
637 * @note vB: destination and source
638 * @note vC: immediate
639 */
640 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400641
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700642 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400643 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the
644 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700645 * @note vA: TypeSize
646 * @note vB: destination and source
647 * @note vC: source
648 */
649 void GenAndVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400650
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700651 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400652 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the
653 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700654 * @param bb The basic block in which the MIR is from.
655 * @param mir The MIR whose opcode is kMirConstVector.
656 * @note vA: TypeSize
657 * @note vB: destination and source
658 * @note vC: source
659 */
660 void GenOrVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400661
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700662 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400663 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the
664 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700665 * @param bb The basic block in which the MIR is from.
666 * @param mir The MIR whose opcode is kMirConstVector.
667 * @note vA: TypeSize
668 * @note vB: destination and source
669 * @note vC: source
670 */
671 void GenXorVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400672
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700673 /*
674 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
675 * @param bb The basic block in which the MIR is from.
676 * @param mir The MIR whose opcode is kMirConstVector.
677 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
678 * @note vA: TypeSize
679 * @note vB: destination and source VR (not vector register)
680 * @note vC: source (vector register)
681 */
682 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400683
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700684 /*
685 * @brief Extract a packed element into a single VR.
686 * @param bb The basic block in which the MIR is from.
687 * @param mir The MIR whose opcode is kMirConstVector.
688 * @note vA: TypeSize
689 * @note vB: destination VR (not vector register)
690 * @note vC: source (vector register)
691 * @note arg[0]: The index to use for extraction from vector register (which packed element).
692 */
693 void GenReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400694
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700695 /*
696 * @brief Create a vector value, with all TypeSize values equal to vC
697 * @param bb The basic block in which the MIR is from.
698 * @param mir The MIR whose opcode is kMirConstVector.
699 * @note vA: TypeSize.
700 * @note vB: destination vector register.
701 * @note vC: source VR (not vector register).
702 */
703 void GenSetVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400704
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700705 /**
706 * @brief Used to generate code for kMirOpPackedArrayGet.
707 * @param bb The basic block of MIR.
708 * @param mir The mir whose opcode is kMirOpPackedArrayGet.
709 */
710 void GenPackedArrayGet(BasicBlock *bb, MIR *mir);
711
712 /**
713 * @brief Used to generate code for kMirOpPackedArrayPut.
714 * @param bb The basic block of MIR.
715 * @param mir The mir whose opcode is kMirOpPackedArrayPut.
716 */
717 void GenPackedArrayPut(BasicBlock *bb, MIR *mir);
718
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700719 /*
720 * @brief Generate code for a vector opcode.
721 * @param bb The basic block in which the MIR is from.
722 * @param mir The MIR whose opcode is a non-standard opcode.
723 */
724 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400725
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700726 /*
727 * @brief Return the correct x86 opcode for the Dex operation
728 * @param op Dex opcode for the operation
729 * @param loc Register location of the operand
730 * @param is_high_op 'true' if this is an operation on the high word
731 * @param value Immediate value for the operation. Used for byte variants
732 * @returns the correct x86 opcode to perform the operation
733 */
734 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400735
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700736 /*
737 * @brief Return the correct x86 opcode for the Dex operation
738 * @param op Dex opcode for the operation
739 * @param dest location of the destination. May be register or memory.
740 * @param rhs Location for the rhs of the operation. May be in register or memory.
741 * @param is_high_op 'true' if this is an operation on the high word
742 * @returns the correct x86 opcode to perform the operation
743 * @note at most one location may refer to memory
744 */
745 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
746 bool is_high_op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800747
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700748 /*
749 * @brief Is this operation a no-op for this opcode and value
750 * @param op Dex opcode for the operation
751 * @param value Immediate value for the operation.
752 * @returns 'true' if the operation will have no effect
753 */
754 bool IsNoOp(Instruction::Code op, int32_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800755
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700756 /**
757 * @brief Calculate magic number and shift for a given divisor
758 * @param divisor divisor number for calculation
759 * @param magic hold calculated magic number
760 * @param shift hold calculated shift
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700761 * @param is_long 'true' if divisor is jlong, 'false' for jint.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700762 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700763 void CalculateMagicAndShift(int64_t divisor, int64_t& magic, int& shift, bool is_long);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800764
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700765 /*
766 * @brief Generate an integer div or rem operation.
767 * @param rl_dest Destination Location.
768 * @param rl_src1 Numerator Location.
769 * @param rl_src2 Divisor Location.
770 * @param is_div 'true' if this is a division, 'false' for a remainder.
771 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
772 */
773 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
774 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800775
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700776 /*
777 * @brief Generate an integer div or rem operation by a literal.
778 * @param rl_dest Destination Location.
779 * @param rl_src Numerator Location.
780 * @param lit Divisor.
781 * @param is_div 'true' if this is a division, 'false' for a remainder.
782 */
783 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800784
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700785 /*
786 * Generate code to implement long shift operations.
787 * @param opcode The DEX opcode to specify the shift type.
788 * @param rl_dest The destination.
789 * @param rl_src The value to be shifted.
790 * @param shift_amount How much to shift.
791 * @returns the RegLocation of the result.
792 */
793 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
794 RegLocation rl_src, int shift_amount);
795 /*
796 * Generate an imul of a register by a constant or a better sequence.
797 * @param dest Destination Register.
798 * @param src Source Register.
799 * @param val Constant multiplier.
800 */
801 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800802
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700803 /*
804 * Generate an imul of a memory location by a constant or a better sequence.
805 * @param dest Destination Register.
806 * @param sreg Symbolic register.
807 * @param displacement Displacement on stack of Symbolic Register.
808 * @param val Constant multiplier.
809 */
810 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800811
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700812 /*
813 * @brief Compare memory to immediate, and branch if condition true.
814 * @param cond The condition code that when true will branch to the target.
815 * @param temp_reg A temporary register that can be used if compare memory is not
816 * supported by the architecture.
817 * @param base_reg The register holding the base address.
818 * @param offset The offset from the base.
819 * @param check_value The immediate to compare to.
Dave Allison69dfe512014-07-11 17:11:58 +0000820 * @param target branch target (or nullptr)
821 * @param compare output for getting LIR for comparison (or nullptr)
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700822 */
823 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
Dave Allison69dfe512014-07-11 17:11:58 +0000824 int offset, int check_value, LIR* target, LIR** compare);
Mark Mendell766e9292014-01-27 07:55:47 -0800825
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700826 void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double);
827
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700828 /*
829 * Can this operation be using core registers without temporaries?
830 * @param rl_lhs Left hand operand.
831 * @param rl_rhs Right hand operand.
832 * @returns 'true' if the operation can proceed without needing temporary regs.
833 */
834 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800835
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700836 /**
837 * @brief Generates inline code for conversion of long to FP by using x87/
838 * @param rl_dest The destination of the FP.
839 * @param rl_src The source of the long.
840 * @param is_double 'true' if dealing with double, 'false' for float.
841 */
842 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Mark Mendell67c39c42014-01-31 17:28:00 -0800843
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700844 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
845 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
846
847 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
848 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
849 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
850 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset);
851 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset);
852 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
853 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
854 void OpTlsCmp(ThreadOffset<4> offset, int val);
855 void OpTlsCmp(ThreadOffset<8> offset, int val);
856
857 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
858
Andreas Gampec76c6142014-08-04 16:30:03 -0700859 // Try to do a long multiplication where rl_src2 is a constant. This simplified setup might fail,
860 // in which case false will be returned.
861 bool GenMulLongConst(RegLocation rl_dest, RegLocation rl_src1, int64_t val);
862 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
863 RegLocation rl_src2);
864 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
865 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
866 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
867 RegLocation rl_src2, bool is_div);
868
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700869 void SpillCoreRegs();
870 void UnSpillCoreRegs();
871 void UnSpillFPRegs();
872 void SpillFPRegs();
873
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700874 /*
875 * @brief Perform MIR analysis before compiling method.
876 * @note Invokes Mir2LiR::Materialize after analysis.
877 */
878 void Materialize();
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800879
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700880 /*
881 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
882 * without regard to data type. In practice, this can result in UpdateLoc returning a
883 * location record for a Dalvik float value in a core register, and vis-versa. For targets
884 * which can inexpensively move data between core and float registers, this can often be a win.
885 * However, for x86 this is generally not a win. These variants of UpdateLoc()
886 * take a register class argument - and will return an in-register location record only if
887 * the value is live in a temp register of the correct class. Additionally, if the value is in
888 * a temp register of the wrong register class, it will be clobbered.
889 */
890 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
891 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
Mark Mendell67c39c42014-01-31 17:28:00 -0800892
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700893 /*
894 * @brief Analyze MIR before generating code, to prepare for the code generation.
895 */
896 void AnalyzeMIR();
buzbee30adc732014-05-09 15:10:18 -0700897
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700898 /*
899 * @brief Analyze one basic block.
900 * @param bb Basic block to analyze.
901 */
902 void AnalyzeBB(BasicBlock * bb);
Mark Mendell67c39c42014-01-31 17:28:00 -0800903
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700904 /*
905 * @brief Analyze one extended MIR instruction
906 * @param opcode MIR instruction opcode.
907 * @param bb Basic block containing instruction.
908 * @param mir Extended instruction to analyze.
909 */
910 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800911
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700912 /*
913 * @brief Analyze one MIR instruction
914 * @param opcode MIR instruction opcode.
915 * @param bb Basic block containing instruction.
916 * @param mir Instruction to analyze.
917 */
918 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800919
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700920 /*
921 * @brief Analyze one MIR float/double instruction
922 * @param opcode MIR instruction opcode.
923 * @param bb Basic block containing instruction.
924 * @param mir Instruction to analyze.
925 */
Mark Mendell0a1174e2014-09-11 14:51:02 -0400926 virtual void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800927
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700928 /*
929 * @brief Analyze one use of a double operand.
930 * @param rl_use Double RegLocation for the operand.
931 */
932 void AnalyzeDoubleUse(RegLocation rl_use);
Mark Mendell67c39c42014-01-31 17:28:00 -0800933
Yixin Shou7071c8d2014-03-05 06:07:48 -0500934 /*
935 * @brief Analyze one invoke-static MIR instruction
936 * @param opcode MIR instruction opcode.
937 * @param bb Basic block containing instruction.
938 * @param mir Instruction to analyze.
939 */
940 void AnalyzeInvokeStatic(int opcode, BasicBlock * bb, MIR *mir);
941
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700942 // Information derived from analysis of MIR
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700943
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700944 // The compiler temporary for the code address of the method.
945 CompilerTemp *base_of_code_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800946
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700947 // Have we decided to compute a ptr to code and store in temporary VR?
948 bool store_method_addr_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800949
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700950 // Have we used the stored method address?
951 bool store_method_addr_used_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800952
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700953 // Instructions to remove if we didn't use the stored method address.
954 LIR* setup_method_address_[2];
Mark Mendell55d0eac2014-02-06 11:02:52 -0800955
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700956 // Instructions needing patching with Method* values.
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100957 ArenaVector<LIR*> method_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800958
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700959 // Instructions needing patching with Class Type* values.
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100960 ArenaVector<LIR*> class_type_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800961
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700962 // Instructions needing patching with PC relative code addresses.
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100963 ArenaVector<LIR*> call_method_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800964
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700965 // Prologue decrement of stack pointer.
966 LIR* stack_decrement_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800967
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700968 // Epilogue increment of stack pointer.
969 LIR* stack_increment_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800970
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700971 // The list of const vector literals.
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700972 LIR* const_vectors_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400973
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700974 /*
975 * @brief Search for a matching vector literal
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700976 * @param constants An array of size 4 which contains all of 32-bit constants.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700977 * @returns pointer to matching LIR constant, or nullptr if not found.
978 */
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700979 LIR* ScanVectorLiteral(int32_t* constants);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400980
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700981 /*
982 * @brief Add a constant vector literal
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700983 * @param constants An array of size 4 which contains all of 32-bit constants.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700984 */
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700985 LIR* AddVectorLiteral(int32_t* constants);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400986
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700987 InToRegStorageMapping in_to_reg_storage_mapping_;
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700988
Serguei Katkov59a42af2014-07-05 00:55:46 +0700989 bool WideGPRsAreAliases() OVERRIDE {
990 return cu_->target64; // On 64b, we have 64b GPRs.
991 }
992 bool WideFPRsAreAliases() OVERRIDE {
993 return true; // xmm registers have 64b views even on x86.
994 }
995
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700996 /*
997 * @brief Dump a RegLocation using printf
998 * @param loc Register location to dump
999 */
1000 static void DumpRegLocation(RegLocation loc);
1001
1002 static const X86EncodingMap EncodingMap[kX86Last];
1003
Udayan Banerji60bfe7b2014-07-08 19:59:43 -07001004 private:
Yixin Shou8c914c02014-07-28 14:17:09 -04001005 void SwapBits(RegStorage result_reg, int shift, int32_t value);
1006 void SwapBits64(RegStorage result_reg, int shift, int64_t value);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001007};
1008
1009} // namespace art
1010
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001011#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_