blob: a85e02fa7a17543b38419c734751d8b3405bcf7d [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>
25
Brian Carlstrom7940e442013-07-12 13:46:57 -070026namespace art {
27
Mark Mendelle87f9b52014-04-30 14:13:18 -040028class X86Mir2Lir : public Mir2Lir {
Ian Rogers0f9b9c52014-06-09 01:32:12 -070029 protected:
30 class InToRegStorageMapper {
31 public:
Serguei Katkov407a9d22014-07-05 03:09:32 +070032 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref) = 0;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070033 virtual ~InToRegStorageMapper() {}
34 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070035
Ian Rogers0f9b9c52014-06-09 01:32:12 -070036 class InToRegStorageX86_64Mapper : public InToRegStorageMapper {
37 public:
Chao-ying Fua77ee512014-07-01 17:43:41 -070038 explicit InToRegStorageX86_64Mapper(Mir2Lir* ml) : ml_(ml), cur_core_reg_(0), cur_fp_reg_(0) {}
Ian Rogers0f9b9c52014-06-09 01:32:12 -070039 virtual ~InToRegStorageX86_64Mapper() {}
Serguei Katkov407a9d22014-07-05 03:09:32 +070040 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref);
Chao-ying Fua77ee512014-07-01 17:43:41 -070041 protected:
42 Mir2Lir* ml_;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070043 private:
44 int cur_core_reg_;
45 int cur_fp_reg_;
46 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070047
Ian Rogers0f9b9c52014-06-09 01:32:12 -070048 class InToRegStorageMapping {
49 public:
50 InToRegStorageMapping() : max_mapped_in_(0), is_there_stack_mapped_(false),
51 initialized_(false) {}
52 void Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper);
53 int GetMaxMappedIn() { return max_mapped_in_; }
54 bool IsThereStackMapped() { return is_there_stack_mapped_; }
55 RegStorage Get(int in_position);
56 bool IsInitialized() { return initialized_; }
57 private:
58 std::map<int, RegStorage> mapping_;
59 int max_mapped_in_;
60 bool is_there_stack_mapped_;
61 bool initialized_;
62 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070063
Ian Rogers0f9b9c52014-06-09 01:32:12 -070064 public:
Elena Sayapinadd644502014-07-01 18:39:52 +070065 X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
Brian Carlstrom7940e442013-07-12 13:46:57 -070066
Ian Rogers0f9b9c52014-06-09 01:32:12 -070067 // Required for target - codegen helpers.
68 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +070069 RegLocation rl_dest, int lit) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070070 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
71 LIR* CheckSuspendUsingLoad() OVERRIDE;
Andreas Gampe98430592014-07-27 19:44:50 -070072 RegStorage LoadHelper(QuickEntrypointEnum trampoline) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070073 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
Andreas Gampe3c12c512014-06-24 18:46:29 +000074 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070075 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010076 OpSize size) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070077 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
78 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
Ian Rogers0f9b9c52014-06-09 01:32:12 -070079 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src,
Andreas Gampe3c12c512014-06-24 18:46:29 +000080 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070081 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
82 OpSize size) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +070083 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg) OVERRIDE;
84 void GenImplicitNullCheck(RegStorage reg, int opt_flags) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -070085
Ian Rogers0f9b9c52014-06-09 01:32:12 -070086 // Required for target - register utilities.
Chao-ying Fua77ee512014-07-01 17:43:41 -070087 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
Andreas Gampeccc60262014-07-04 18:02:38 -070088 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
89 if (wide_kind == kWide) {
90 if (cu_->target64) {
91 return As64BitReg(TargetReg32(symbolic_reg));
92 } else {
93 // x86: construct a pair.
94 DCHECK((kArg0 <= symbolic_reg && symbolic_reg < kArg3) ||
95 (kFArg0 <= symbolic_reg && symbolic_reg < kFArg3) ||
96 (kRet0 == symbolic_reg));
97 return RegStorage::MakeRegPair(TargetReg32(symbolic_reg),
98 TargetReg32(static_cast<SpecialTargetRegister>(symbolic_reg + 1)));
99 }
100 } else if (wide_kind == kRef && cu_->target64) {
101 return As64BitReg(TargetReg32(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700102 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700103 return TargetReg32(symbolic_reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700104 }
105 }
Chao-ying Fua77ee512014-07-01 17:43:41 -0700106 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
Andreas Gampeccc60262014-07-04 18:02:38 -0700107 return TargetReg(symbolic_reg, cu_->target64 ? kWide : kNotWide);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700108 }
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700109
110 RegStorage GetArgMappingToPhysicalReg(int arg_num) OVERRIDE;
111
112 RegLocation GetReturnAlt() OVERRIDE;
113 RegLocation GetReturnWideAlt() OVERRIDE;
114 RegLocation LocCReturn() OVERRIDE;
115 RegLocation LocCReturnRef() OVERRIDE;
116 RegLocation LocCReturnDouble() OVERRIDE;
117 RegLocation LocCReturnFloat() OVERRIDE;
118 RegLocation LocCReturnWide() OVERRIDE;
119
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100120 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700121 void AdjustSpillMask() OVERRIDE;
122 void ClobberCallerSave() OVERRIDE;
123 void FreeCallTemps() OVERRIDE;
124 void LockCallTemps() OVERRIDE;
125
126 void CompilerInitializeRegAlloc() OVERRIDE;
127 int VectorRegisterSize() OVERRIDE;
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700128 int NumReservableVectorRegisters(bool long_or_fp) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700129
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700130 // Required for target - miscellaneous.
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700131 void AssembleLIR() OVERRIDE;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100132 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
133 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
134 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700135 const char* GetTargetInstFmt(int opcode) OVERRIDE;
136 const char* GetTargetInstName(int opcode) OVERRIDE;
137 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100138 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700139 uint64_t GetTargetInstFlags(int opcode) OVERRIDE;
Ian Rogers5aa6e042014-06-13 16:38:24 -0700140 size_t GetInsnSize(LIR* lir) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700141 bool IsUnconditionalBranch(LIR* lir) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700142
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700143 // Get the register class for load/store of a field.
144 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100145
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700146 // Required for target - Dalvik-level generators.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700147 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700148 RegLocation rl_dest, int scale) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700149 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700150 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark) OVERRIDE;
151
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700152 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700153 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700154 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700155 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700156 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700157 RegLocation rl_src2) OVERRIDE;
158 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
159
160 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE;
161 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE;
162 bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE;
Yixin Shou8c914c02014-07-28 14:17:09 -0400163 bool GenInlinedReverseBits(CallInfo* info, OpSize size) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700164 bool GenInlinedSqrt(CallInfo* info) OVERRIDE;
Yixin Shou7071c8d2014-03-05 06:07:48 -0500165 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
166 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700167 bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE;
168 bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE;
Andreas Gampe98430592014-07-27 19:44:50 -0700169 bool GenInlinedCharAt(CallInfo* info) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700170
171 // Long instructions.
Andreas Gampec76c6142014-08-04 16:30:03 -0700172 void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
173 RegLocation rl_src2) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700174 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
175 RegLocation rl_src2) OVERRIDE;
176 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
177 RegLocation rl_src1, RegLocation rl_shift) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700178 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE;
179 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
180 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
181 RegLocation rl_src1, RegLocation rl_shift) OVERRIDE;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800182
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700183 /*
184 * @brief Generate a two address long operation with a constant value
185 * @param rl_dest location of result
186 * @param rl_src constant source operand
187 * @param op Opcode to be generated
188 * @return success or not
189 */
190 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700191
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700192 /*
193 * @brief Generate a three address long operation with a constant value
194 * @param rl_dest location of result
195 * @param rl_src1 source operand
196 * @param rl_src2 constant source operand
197 * @param op Opcode to be generated
198 * @return success or not
199 */
200 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
201 Instruction::Code op);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700202 /**
203 * @brief Generate a long arithmetic operation.
204 * @param rl_dest The destination.
205 * @param rl_src1 First operand.
206 * @param rl_src2 Second operand.
207 * @param op The DEX opcode for the operation.
208 * @param is_commutative The sources can be swapped if needed.
209 */
210 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
211 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800212
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700213 /**
214 * @brief Generate a two operand long arithmetic operation.
215 * @param rl_dest The destination.
216 * @param rl_src Second operand.
217 * @param op The DEX opcode for the operation.
218 */
219 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800220
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700221 /**
222 * @brief Generate a long operation.
223 * @param rl_dest The destination. Must be in a register
224 * @param rl_src The other operand. May be in a register or in memory.
225 * @param op The DEX opcode for the operation.
226 */
227 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700229
230 // TODO: collapse reg_lo, reg_hi
231 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div)
232 OVERRIDE;
233 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div) OVERRIDE;
234 void GenDivZeroCheckWide(RegStorage reg) OVERRIDE;
235 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
236 void GenExitSequence() OVERRIDE;
237 void GenSpecialExitSequence() OVERRIDE;
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700238 void GenFillArrayData(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700239 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE;
240 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE;
241 void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE;
242 void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
243 int32_t true_val, int32_t false_val, RegStorage rs_dest,
244 int dest_reg_class) OVERRIDE;
245 bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE;
246 void GenMoveException(RegLocation rl_dest) OVERRIDE;
247 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
248 int first_bit, int second_bit) OVERRIDE;
249 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
250 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampe48971b32014-08-06 10:09:01 -0700251 void GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
252 void GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700253
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700254 /**
255 * @brief Implement instanceof a final class with x86 specific code.
256 * @param use_declaring_class 'true' if we can use the class itself.
257 * @param type_idx Type index to use if use_declaring_class is 'false'.
258 * @param rl_dest Result to be set to 0 or 1.
259 * @param rl_src Object to be tested.
260 */
261 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700262 RegLocation rl_src) OVERRIDE;
Chao-ying Fua0147762014-06-06 18:38:49 -0700263
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700264 // Single operation generators.
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700265 LIR* OpUnconditionalBranch(LIR* target) OVERRIDE;
266 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE;
267 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE;
268 LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE;
269 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE;
270 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
271 LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE;
272 void OpEndIT(LIR* it) OVERRIDE;
273 LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE;
274 LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE;
275 LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE;
276 void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
277 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE;
278 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE;
279 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE;
280 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE;
281 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE;
282 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE;
283 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE;
284 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE;
285 LIR* OpTestSuspend(LIR* target) OVERRIDE;
286 LIR* OpVldm(RegStorage r_base, int count) OVERRIDE;
287 LIR* OpVstm(RegStorage r_base, int count) OVERRIDE;
288 void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE;
289 bool GenInlinedCurrentThread(CallInfo* info) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700290
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700291 bool InexpensiveConstantInt(int32_t value) OVERRIDE;
292 bool InexpensiveConstantFloat(int32_t value) OVERRIDE;
293 bool InexpensiveConstantLong(int64_t value) OVERRIDE;
294 bool InexpensiveConstantDouble(int64_t value) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700295
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700296 /*
297 * @brief Should try to optimize for two address instructions?
298 * @return true if we try to avoid generating three operand instructions.
299 */
300 virtual bool GenerateTwoOperandInstructions() const { return true; }
Mark Mendelle87f9b52014-04-30 14:13:18 -0400301
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700302 /*
303 * @brief x86 specific codegen for int operations.
304 * @param opcode Operation to perform.
305 * @param rl_dest Destination for the result.
306 * @param rl_lhs Left hand operand.
307 * @param rl_rhs Right hand operand.
308 */
309 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700310 RegLocation rl_rhs) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800311
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700312 /*
313 * @brief Load the Method* of a dex method into the register.
314 * @param target_method The MethodReference of the method to be invoked.
315 * @param type How the method will be invoked.
316 * @param register that will contain the code address.
317 * @note register will be passed to TargetReg to get physical register.
318 */
319 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700320 SpecialTargetRegister symbolic_reg) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800321
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700322 /*
323 * @brief Load the Class* of a Dex Class type into the register.
Fred Shihe7f82e22014-08-06 10:46:37 -0700324 * @param dex DexFile that contains the class type.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700325 * @param type How the method will be invoked.
326 * @param register that will contain the code address.
327 * @note register will be passed to TargetReg to get physical register.
328 */
Fred Shihe7f82e22014-08-06 10:46:37 -0700329 void LoadClassType(const DexFile& dex_file, uint32_t type_idx,
330 SpecialTargetRegister symbolic_reg) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800331
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700332 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700333
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700334 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700335 NextCallInsn next_call_insn,
336 const MethodReference& target_method,
337 uint32_t vtable_idx,
338 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700339 bool skip_this) OVERRIDE;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700340
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700341 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
342 NextCallInsn next_call_insn,
343 const MethodReference& target_method,
344 uint32_t vtable_idx,
345 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700346 bool skip_this) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800347
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700348 /*
349 * @brief Generate a relative call to the method that will be patched at link time.
350 * @param target_method The MethodReference of the method to be invoked.
351 * @param type How the method will be invoked.
352 * @returns Call instruction
353 */
354 virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800355
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700356 /*
357 * @brief Handle x86 specific literals
358 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700359 void InstallLiteralPools() OVERRIDE;
Mark Mendellae9fd932014-02-10 16:14:35 -0800360
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700361 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700362 * @brief Generate the debug_frame FDE information.
363 * @returns pointer to vector containing CFE information
364 */
Tong Shen547cdfd2014-08-05 01:54:19 -0700365 std::vector<uint8_t>* ReturnFrameDescriptionEntry() OVERRIDE;
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800366
Andreas Gampe98430592014-07-27 19:44:50 -0700367 LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE;
368
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700369 protected:
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700370 RegStorage TargetReg32(SpecialTargetRegister reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700371 // Casting of RegStorage
372 RegStorage As32BitReg(RegStorage reg) {
373 DCHECK(!reg.IsPair());
374 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
375 if (kFailOnSizeError) {
376 LOG(FATAL) << "Expected 64b register " << reg.GetReg();
377 } else {
378 LOG(WARNING) << "Expected 64b register " << reg.GetReg();
379 return reg;
380 }
381 }
382 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
383 reg.GetRawBits() & RegStorage::kRegTypeMask);
384 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
385 ->GetReg().GetReg(),
386 ret_val.GetReg());
387 return ret_val;
388 }
389
390 RegStorage As64BitReg(RegStorage reg) {
391 DCHECK(!reg.IsPair());
392 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
393 if (kFailOnSizeError) {
394 LOG(FATAL) << "Expected 32b register " << reg.GetReg();
395 } else {
396 LOG(WARNING) << "Expected 32b register " << reg.GetReg();
397 return reg;
398 }
399 }
400 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
401 reg.GetRawBits() & RegStorage::kRegTypeMask);
402 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
403 ->GetReg().GetReg(),
404 ret_val.GetReg());
405 return ret_val;
406 }
407
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700408 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
409 RegStorage r_dest, OpSize size);
410 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
Jean Christophe Beylerb5bce7c2014-07-25 12:32:18 -0700411 RegStorage r_src, OpSize size, int opt_flags = 0);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700412
413 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
414
415 int AssignInsnOffsets();
416 void AssignOffsets();
417 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
418
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700419 size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700420 int32_t raw_base, int32_t displacement);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700421 void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg);
422 void EmitPrefix(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700423 int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700424 void EmitOpcode(const X86EncodingMap* entry);
425 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700426 int32_t reg_r, int32_t reg_x, int32_t reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700427 void EmitDisp(uint8_t base, int32_t disp);
428 void EmitModrmThread(uint8_t reg_or_opcode);
429 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp);
430 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale,
431 int32_t disp);
432 void EmitImm(const X86EncodingMap* entry, int64_t imm);
433 void EmitNullary(const X86EncodingMap* entry);
434 void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg);
435 void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg);
436 void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
437 void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
438 int32_t disp);
439 void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg);
440 void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp);
441 void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base,
442 int32_t raw_index, int scale, int32_t disp);
443 void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
444 int32_t disp, int32_t raw_reg);
445 void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
446 void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
447 int32_t raw_disp, int32_t imm);
448 void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp);
449 void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2);
450 void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm);
451 void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
452 int32_t imm);
453 void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1,
454 int32_t imm);
455 void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
456 void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm);
457 void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm);
458 void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
459 void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl);
460 void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl);
Yixin Shouf40f8902014-08-14 14:10:32 -0400461 void EmitShiftRegRegCl(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2,
462 int32_t raw_cl);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700463 void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
464 void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc);
465 void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc);
466 void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc);
467 void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
468 int32_t cc);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800469
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700470 void EmitJmp(const X86EncodingMap* entry, int32_t rel);
471 void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc);
472 void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
473 void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp);
474 void EmitCallThread(const X86EncodingMap* entry, int32_t disp);
475 void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table,
476 int32_t raw_index, int scale, int32_t table_or_disp);
477 void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset);
478 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
479 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
480 int64_t val, ConditionCode ccode);
481 void GenConstWide(RegLocation rl_dest, int64_t value);
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700482 void GenMultiplyVectorSignedByte(RegStorage rs_dest_src1, RegStorage rs_src2);
483 void GenMultiplyVectorLong(RegStorage rs_dest_src1, RegStorage rs_src2);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700484 void GenShiftByteVector(BasicBlock *bb, MIR *mir);
Yixin Shouf40f8902014-08-14 14:10:32 -0400485 void AndMaskVectorRegister(RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3,
486 uint32_t m4);
487 void MaskVectorRegister(X86OpCode opcode, RegStorage rs_src1, uint32_t m1, uint32_t m2,
488 uint32_t m3, uint32_t m4);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700489 void AppendOpcodeWithConst(X86OpCode opcode, int reg, MIR* mir);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400490
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700491 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800492
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700493 /*
494 * @brief Ensure that a temporary register is byte addressable.
495 * @returns a temporary guarenteed to be byte addressable.
496 */
497 virtual RegStorage AllocateByteRegister();
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800498
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700499 /*
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700500 * @brief Use a wide temporary as a 128-bit register
501 * @returns a 128-bit temporary register.
502 */
503 virtual RegStorage Get128BitRegister(RegStorage reg);
504
505 /*
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700506 * @brief Check if a register is byte addressable.
507 * @returns true if a register is byte addressable.
508 */
509 bool IsByteRegister(RegStorage reg);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700510
511 void GenDivRemLongLit(RegLocation rl_dest, RegLocation rl_src, int64_t imm, bool is_div);
512
DaniilSokolov70c4f062014-06-24 17:34:00 -0700513 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700514
515 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700516 * @brief generate inline code for fast case of Strng.indexOf.
517 * @param info Call parameters
518 * @param zero_based 'true' if the index into the string is 0.
519 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
520 * generated.
521 */
522 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
Mark Mendelle87f9b52014-04-30 14:13:18 -0400523
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700524 /**
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700525 * @brief Used to reserve a range of vector registers.
526 * @see kMirOpReserveVectorRegisters
527 * @param mir The extended MIR for reservation.
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700528 */
529 void ReserveVectorRegisters(MIR* mir);
530
531 /**
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700532 * @brief Used to return a range of vector registers.
533 * @see kMirOpReturnVectorRegisters
534 * @param mir The extended MIR for returning vector regs.
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700535 */
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700536 void ReturnVectorRegisters(MIR* mir);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700537
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700538 /*
539 * @brief Load 128 bit constant into vector register.
540 * @param bb The basic block in which the MIR is from.
541 * @param mir The MIR whose opcode is kMirConstVector
542 * @note vA is the TypeSize for the register.
543 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
544 */
545 void GenConst128(BasicBlock* bb, MIR* mir);
Mark Mendell4028a6c2014-02-19 20:06:20 -0800546
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700547 /*
548 * @brief MIR to move a vectorized register to another.
549 * @param bb The basic block in which the MIR is from.
550 * @param mir The MIR whose opcode is kMirConstVector.
551 * @note vA: TypeSize
552 * @note vB: destination
553 * @note vC: source
554 */
555 void GenMoveVector(BasicBlock *bb, MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400556
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700557 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400558 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know
559 * the type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700560 * @param bb The basic block in which the MIR is from.
561 * @param mir The MIR whose opcode is kMirConstVector.
562 * @note vA: TypeSize
563 * @note vB: destination and source
564 * @note vC: source
565 */
566 void GenMultiplyVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400567
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700568 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400569 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the
570 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700571 * @param bb The basic block in which the MIR is from.
572 * @param mir The MIR whose opcode is kMirConstVector.
573 * @note vA: TypeSize
574 * @note vB: destination and source
575 * @note vC: source
576 */
577 void GenAddVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400578
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700579 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400580 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the
581 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700582 * @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 GenSubtractVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400589
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700590 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400591 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the
592 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700593 * @param bb The basic block in which the MIR is from.
594 * @param mir The MIR whose opcode is kMirConstVector.
595 * @note vA: TypeSize
596 * @note vB: destination and source
597 * @note vC: immediate
598 */
599 void GenShiftLeftVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400600
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700601 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400602 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to
603 * know the type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700604 * @param bb The basic block in which the MIR is from.
605 * @param mir The MIR whose opcode is kMirConstVector.
606 * @note vA: TypeSize
607 * @note vB: destination and source
608 * @note vC: immediate
609 */
610 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400611
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700612 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400613 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA
614 * to know the type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700615 * @param bb The basic block in which the MIR is from..
616 * @param mir The MIR whose opcode is kMirConstVector.
617 * @note vA: TypeSize
618 * @note vB: destination and source
619 * @note vC: immediate
620 */
621 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400622
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700623 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400624 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the
625 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700626 * @note vA: TypeSize
627 * @note vB: destination and source
628 * @note vC: source
629 */
630 void GenAndVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400631
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700632 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400633 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the
634 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700635 * @param bb The basic block in which the MIR is from.
636 * @param mir The MIR whose opcode is kMirConstVector.
637 * @note vA: TypeSize
638 * @note vB: destination and source
639 * @note vC: source
640 */
641 void GenOrVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400642
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700643 /*
Yixin Shouf40f8902014-08-14 14:10:32 -0400644 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the
645 * type of the vector.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700646 * @param bb The basic block in which the MIR is from.
647 * @param mir The MIR whose opcode is kMirConstVector.
648 * @note vA: TypeSize
649 * @note vB: destination and source
650 * @note vC: source
651 */
652 void GenXorVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400653
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700654 /*
655 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
656 * @param bb The basic block in which the MIR is from.
657 * @param mir The MIR whose opcode is kMirConstVector.
658 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
659 * @note vA: TypeSize
660 * @note vB: destination and source VR (not vector register)
661 * @note vC: source (vector register)
662 */
663 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400664
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700665 /*
666 * @brief Extract a packed element into a single VR.
667 * @param bb The basic block in which the MIR is from.
668 * @param mir The MIR whose opcode is kMirConstVector.
669 * @note vA: TypeSize
670 * @note vB: destination VR (not vector register)
671 * @note vC: source (vector register)
672 * @note arg[0]: The index to use for extraction from vector register (which packed element).
673 */
674 void GenReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400675
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700676 /*
677 * @brief Create a vector value, with all TypeSize values equal to vC
678 * @param bb The basic block in which the MIR is from.
679 * @param mir The MIR whose opcode is kMirConstVector.
680 * @note vA: TypeSize.
681 * @note vB: destination vector register.
682 * @note vC: source VR (not vector register).
683 */
684 void GenSetVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400685
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700686 /**
687 * @brief Used to generate code for kMirOpPackedArrayGet.
688 * @param bb The basic block of MIR.
689 * @param mir The mir whose opcode is kMirOpPackedArrayGet.
690 */
691 void GenPackedArrayGet(BasicBlock *bb, MIR *mir);
692
693 /**
694 * @brief Used to generate code for kMirOpPackedArrayPut.
695 * @param bb The basic block of MIR.
696 * @param mir The mir whose opcode is kMirOpPackedArrayPut.
697 */
698 void GenPackedArrayPut(BasicBlock *bb, MIR *mir);
699
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700700 /*
701 * @brief Generate code for a vector opcode.
702 * @param bb The basic block in which the MIR is from.
703 * @param mir The MIR whose opcode is a non-standard opcode.
704 */
705 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
Mark Mendellfe945782014-05-22 09:52:36 -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 loc Register location of the operand
711 * @param is_high_op 'true' if this is an operation on the high word
712 * @param value Immediate value for the operation. Used for byte variants
713 * @returns the correct x86 opcode to perform the operation
714 */
715 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400716
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700717 /*
718 * @brief Return the correct x86 opcode for the Dex operation
719 * @param op Dex opcode for the operation
720 * @param dest location of the destination. May be register or memory.
721 * @param rhs Location for the rhs of the operation. May be in register or memory.
722 * @param is_high_op 'true' if this is an operation on the high word
723 * @returns the correct x86 opcode to perform the operation
724 * @note at most one location may refer to memory
725 */
726 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
727 bool is_high_op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800728
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700729 /*
730 * @brief Is this operation a no-op for this opcode and value
731 * @param op Dex opcode for the operation
732 * @param value Immediate value for the operation.
733 * @returns 'true' if the operation will have no effect
734 */
735 bool IsNoOp(Instruction::Code op, int32_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800736
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700737 /**
738 * @brief Calculate magic number and shift for a given divisor
739 * @param divisor divisor number for calculation
740 * @param magic hold calculated magic number
741 * @param shift hold calculated shift
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700742 * @param is_long 'true' if divisor is jlong, 'false' for jint.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700743 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700744 void CalculateMagicAndShift(int64_t divisor, int64_t& magic, int& shift, bool is_long);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800745
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700746 /*
747 * @brief Generate an integer div or rem operation.
748 * @param rl_dest Destination Location.
749 * @param rl_src1 Numerator Location.
750 * @param rl_src2 Divisor Location.
751 * @param is_div 'true' if this is a division, 'false' for a remainder.
752 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
753 */
754 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
755 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800756
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700757 /*
758 * @brief Generate an integer div or rem operation by a literal.
759 * @param rl_dest Destination Location.
760 * @param rl_src Numerator Location.
761 * @param lit Divisor.
762 * @param is_div 'true' if this is a division, 'false' for a remainder.
763 */
764 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800765
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700766 /*
767 * Generate code to implement long shift operations.
768 * @param opcode The DEX opcode to specify the shift type.
769 * @param rl_dest The destination.
770 * @param rl_src The value to be shifted.
771 * @param shift_amount How much to shift.
772 * @returns the RegLocation of the result.
773 */
774 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
775 RegLocation rl_src, int shift_amount);
776 /*
777 * Generate an imul of a register by a constant or a better sequence.
778 * @param dest Destination Register.
779 * @param src Source Register.
780 * @param val Constant multiplier.
781 */
782 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800783
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700784 /*
785 * Generate an imul of a memory location by a constant or a better sequence.
786 * @param dest Destination Register.
787 * @param sreg Symbolic register.
788 * @param displacement Displacement on stack of Symbolic Register.
789 * @param val Constant multiplier.
790 */
791 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800792
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700793 /*
794 * @brief Compare memory to immediate, and branch if condition true.
795 * @param cond The condition code that when true will branch to the target.
796 * @param temp_reg A temporary register that can be used if compare memory is not
797 * supported by the architecture.
798 * @param base_reg The register holding the base address.
799 * @param offset The offset from the base.
800 * @param check_value The immediate to compare to.
Dave Allison69dfe512014-07-11 17:11:58 +0000801 * @param target branch target (or nullptr)
802 * @param compare output for getting LIR for comparison (or nullptr)
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700803 */
804 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
Dave Allison69dfe512014-07-11 17:11:58 +0000805 int offset, int check_value, LIR* target, LIR** compare);
Mark Mendell766e9292014-01-27 07:55:47 -0800806
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700807 void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double);
808
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700809 /*
810 * Can this operation be using core registers without temporaries?
811 * @param rl_lhs Left hand operand.
812 * @param rl_rhs Right hand operand.
813 * @returns 'true' if the operation can proceed without needing temporary regs.
814 */
815 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800816
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700817 /**
818 * @brief Generates inline code for conversion of long to FP by using x87/
819 * @param rl_dest The destination of the FP.
820 * @param rl_src The source of the long.
821 * @param is_double 'true' if dealing with double, 'false' for float.
822 */
823 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Mark Mendell67c39c42014-01-31 17:28:00 -0800824
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700825 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
826 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
827
828 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
829 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
830 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
831 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset);
832 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset);
833 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
834 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
835 void OpTlsCmp(ThreadOffset<4> offset, int val);
836 void OpTlsCmp(ThreadOffset<8> offset, int val);
837
838 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
839
Andreas Gampec76c6142014-08-04 16:30:03 -0700840 // Try to do a long multiplication where rl_src2 is a constant. This simplified setup might fail,
841 // in which case false will be returned.
842 bool GenMulLongConst(RegLocation rl_dest, RegLocation rl_src1, int64_t val);
843 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
844 RegLocation rl_src2);
845 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
846 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
847 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
848 RegLocation rl_src2, bool is_div);
849
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700850 void SpillCoreRegs();
851 void UnSpillCoreRegs();
852 void UnSpillFPRegs();
853 void SpillFPRegs();
854
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700855 /*
856 * @brief Perform MIR analysis before compiling method.
857 * @note Invokes Mir2LiR::Materialize after analysis.
858 */
859 void Materialize();
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800860
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700861 /*
862 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
863 * without regard to data type. In practice, this can result in UpdateLoc returning a
864 * location record for a Dalvik float value in a core register, and vis-versa. For targets
865 * which can inexpensively move data between core and float registers, this can often be a win.
866 * However, for x86 this is generally not a win. These variants of UpdateLoc()
867 * take a register class argument - and will return an in-register location record only if
868 * the value is live in a temp register of the correct class. Additionally, if the value is in
869 * a temp register of the wrong register class, it will be clobbered.
870 */
871 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
872 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
Mark Mendell67c39c42014-01-31 17:28:00 -0800873
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700874 /*
875 * @brief Analyze MIR before generating code, to prepare for the code generation.
876 */
877 void AnalyzeMIR();
buzbee30adc732014-05-09 15:10:18 -0700878
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700879 /*
880 * @brief Analyze one basic block.
881 * @param bb Basic block to analyze.
882 */
883 void AnalyzeBB(BasicBlock * bb);
Mark Mendell67c39c42014-01-31 17:28:00 -0800884
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700885 /*
886 * @brief Analyze one extended MIR instruction
887 * @param opcode MIR instruction opcode.
888 * @param bb Basic block containing instruction.
889 * @param mir Extended instruction to analyze.
890 */
891 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800892
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700893 /*
894 * @brief Analyze one MIR instruction
895 * @param opcode MIR instruction opcode.
896 * @param bb Basic block containing instruction.
897 * @param mir Instruction to analyze.
898 */
899 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800900
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700901 /*
902 * @brief Analyze one MIR float/double instruction
903 * @param opcode MIR instruction opcode.
904 * @param bb Basic block containing instruction.
905 * @param mir Instruction to analyze.
906 */
907 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800908
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700909 /*
910 * @brief Analyze one use of a double operand.
911 * @param rl_use Double RegLocation for the operand.
912 */
913 void AnalyzeDoubleUse(RegLocation rl_use);
Mark Mendell67c39c42014-01-31 17:28:00 -0800914
Yixin Shou7071c8d2014-03-05 06:07:48 -0500915 /*
916 * @brief Analyze one invoke-static MIR instruction
917 * @param opcode MIR instruction opcode.
918 * @param bb Basic block containing instruction.
919 * @param mir Instruction to analyze.
920 */
921 void AnalyzeInvokeStatic(int opcode, BasicBlock * bb, MIR *mir);
922
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700923 // Information derived from analysis of MIR
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700924
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700925 // The compiler temporary for the code address of the method.
926 CompilerTemp *base_of_code_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800927
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700928 // Have we decided to compute a ptr to code and store in temporary VR?
929 bool store_method_addr_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800930
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700931 // Have we used the stored method address?
932 bool store_method_addr_used_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800933
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700934 // Instructions to remove if we didn't use the stored method address.
935 LIR* setup_method_address_[2];
Mark Mendell55d0eac2014-02-06 11:02:52 -0800936
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700937 // Instructions needing patching with Method* values.
938 GrowableArray<LIR*> method_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800939
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700940 // Instructions needing patching with Class Type* values.
941 GrowableArray<LIR*> class_type_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800942
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700943 // Instructions needing patching with PC relative code addresses.
944 GrowableArray<LIR*> call_method_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800945
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700946 // Prologue decrement of stack pointer.
947 LIR* stack_decrement_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800948
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700949 // Epilogue increment of stack pointer.
950 LIR* stack_increment_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800951
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700952 // The list of const vector literals.
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700953 LIR* const_vectors_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400954
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700955 /*
956 * @brief Search for a matching vector literal
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700957 * @param constants An array of size 4 which contains all of 32-bit constants.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700958 * @returns pointer to matching LIR constant, or nullptr if not found.
959 */
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700960 LIR* ScanVectorLiteral(int32_t* constants);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400961
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700962 /*
963 * @brief Add a constant vector literal
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700964 * @param constants An array of size 4 which contains all of 32-bit constants.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700965 */
Lupusoru, Razvan Ab3a84e22014-07-28 14:11:01 -0700966 LIR* AddVectorLiteral(int32_t* constants);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400967
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700968 InToRegStorageMapping in_to_reg_storage_mapping_;
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700969
Serguei Katkov59a42af2014-07-05 00:55:46 +0700970 bool WideGPRsAreAliases() OVERRIDE {
971 return cu_->target64; // On 64b, we have 64b GPRs.
972 }
973 bool WideFPRsAreAliases() OVERRIDE {
974 return true; // xmm registers have 64b views even on x86.
975 }
976
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700977 /*
978 * @brief Dump a RegLocation using printf
979 * @param loc Register location to dump
980 */
981 static void DumpRegLocation(RegLocation loc);
982
983 static const X86EncodingMap EncodingMap[kX86Last];
984
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700985 private:
Yixin Shou8c914c02014-07-28 14:17:09 -0400986 void SwapBits(RegStorage result_reg, int shift, int32_t value);
987 void SwapBits64(RegStorage result_reg, int shift, int64_t value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700988};
989
990} // namespace art
991
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700992#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_