blob: 21667b0be354f89ecc97f2c5eba3b3fc7fa5220e [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_
18#define ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
20#include "dex/compiler_internals.h"
21#include "x86_lir.h"
22
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070023#include <map>
24
Brian Carlstrom7940e442013-07-12 13:46:57 -070025namespace art {
26
Mark Mendelle87f9b52014-04-30 14:13:18 -040027class X86Mir2Lir : public Mir2Lir {
Ian Rogers0f9b9c52014-06-09 01:32:12 -070028 protected:
29 class InToRegStorageMapper {
30 public:
Serguei Katkov407a9d22014-07-05 03:09:32 +070031 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref) = 0;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070032 virtual ~InToRegStorageMapper() {}
33 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070034
Ian Rogers0f9b9c52014-06-09 01:32:12 -070035 class InToRegStorageX86_64Mapper : public InToRegStorageMapper {
36 public:
Chao-ying Fua77ee512014-07-01 17:43:41 -070037 explicit InToRegStorageX86_64Mapper(Mir2Lir* ml) : ml_(ml), cur_core_reg_(0), cur_fp_reg_(0) {}
Ian Rogers0f9b9c52014-06-09 01:32:12 -070038 virtual ~InToRegStorageX86_64Mapper() {}
Serguei Katkov407a9d22014-07-05 03:09:32 +070039 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref);
Chao-ying Fua77ee512014-07-01 17:43:41 -070040 protected:
41 Mir2Lir* ml_;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070042 private:
43 int cur_core_reg_;
44 int cur_fp_reg_;
45 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070046
Ian Rogers0f9b9c52014-06-09 01:32:12 -070047 class InToRegStorageMapping {
48 public:
49 InToRegStorageMapping() : max_mapped_in_(0), is_there_stack_mapped_(false),
50 initialized_(false) {}
51 void Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper);
52 int GetMaxMappedIn() { return max_mapped_in_; }
53 bool IsThereStackMapped() { return is_there_stack_mapped_; }
54 RegStorage Get(int in_position);
55 bool IsInitialized() { return initialized_; }
56 private:
57 std::map<int, RegStorage> mapping_;
58 int max_mapped_in_;
59 bool is_there_stack_mapped_;
60 bool initialized_;
61 };
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +070062
Ian Rogers0f9b9c52014-06-09 01:32:12 -070063 public:
Elena Sayapinadd644502014-07-01 18:39:52 +070064 X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
Brian Carlstrom7940e442013-07-12 13:46:57 -070065
Ian Rogers0f9b9c52014-06-09 01:32:12 -070066 // Required for target - codegen helpers.
67 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +070068 RegLocation rl_dest, int lit) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070069 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
70 LIR* CheckSuspendUsingLoad() OVERRIDE;
Andreas Gampe98430592014-07-27 19:44:50 -070071 RegStorage LoadHelper(QuickEntrypointEnum trampoline) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070072 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
Andreas Gampe3c12c512014-06-24 18:46:29 +000073 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070074 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010075 OpSize size) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070076 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
77 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
Ian Rogers0f9b9c52014-06-09 01:32:12 -070078 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src,
Andreas Gampe3c12c512014-06-24 18:46:29 +000079 OpSize size, VolatileKind is_volatile) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -070080 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
81 OpSize size) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +070082 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg) OVERRIDE;
83 void GenImplicitNullCheck(RegStorage reg, int opt_flags) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -070084
Ian Rogers0f9b9c52014-06-09 01:32:12 -070085 // Required for target - register utilities.
Chao-ying Fua77ee512014-07-01 17:43:41 -070086 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
Andreas Gampeccc60262014-07-04 18:02:38 -070087 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
88 if (wide_kind == kWide) {
89 if (cu_->target64) {
90 return As64BitReg(TargetReg32(symbolic_reg));
91 } else {
92 // x86: construct a pair.
93 DCHECK((kArg0 <= symbolic_reg && symbolic_reg < kArg3) ||
94 (kFArg0 <= symbolic_reg && symbolic_reg < kFArg3) ||
95 (kRet0 == symbolic_reg));
96 return RegStorage::MakeRegPair(TargetReg32(symbolic_reg),
97 TargetReg32(static_cast<SpecialTargetRegister>(symbolic_reg + 1)));
98 }
99 } else if (wide_kind == kRef && cu_->target64) {
100 return As64BitReg(TargetReg32(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700101 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700102 return TargetReg32(symbolic_reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700103 }
104 }
Chao-ying Fua77ee512014-07-01 17:43:41 -0700105 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
Andreas Gampeccc60262014-07-04 18:02:38 -0700106 return TargetReg(symbolic_reg, cu_->target64 ? kWide : kNotWide);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700107 }
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700108
109 RegStorage GetArgMappingToPhysicalReg(int arg_num) OVERRIDE;
110
111 RegLocation GetReturnAlt() OVERRIDE;
112 RegLocation GetReturnWideAlt() OVERRIDE;
113 RegLocation LocCReturn() OVERRIDE;
114 RegLocation LocCReturnRef() OVERRIDE;
115 RegLocation LocCReturnDouble() OVERRIDE;
116 RegLocation LocCReturnFloat() OVERRIDE;
117 RegLocation LocCReturnWide() OVERRIDE;
118
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100119 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700120 void AdjustSpillMask() OVERRIDE;
121 void ClobberCallerSave() OVERRIDE;
122 void FreeCallTemps() OVERRIDE;
123 void LockCallTemps() OVERRIDE;
124
125 void CompilerInitializeRegAlloc() OVERRIDE;
126 int VectorRegisterSize() OVERRIDE;
127 int NumReservableVectorRegisters(bool fp_used) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700128
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700129 // Required for target - miscellaneous.
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700130 void AssembleLIR() OVERRIDE;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100131 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
132 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
133 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700134 const char* GetTargetInstFmt(int opcode) OVERRIDE;
135 const char* GetTargetInstName(int opcode) OVERRIDE;
136 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100137 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700138 uint64_t GetTargetInstFlags(int opcode) OVERRIDE;
Ian Rogers5aa6e042014-06-13 16:38:24 -0700139 size_t GetInsnSize(LIR* lir) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700140 bool IsUnconditionalBranch(LIR* lir) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700141
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700142 // Get the register class for load/store of a field.
143 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100144
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700145 // Required for target - Dalvik-level generators.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700146 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700147 RegLocation rl_dest, int scale) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700148 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700149 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark) OVERRIDE;
150
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700151 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700152 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700153 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700154 RegLocation rl_src2) OVERRIDE;
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700155 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700156 RegLocation rl_src2) OVERRIDE;
157 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
158
159 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE;
160 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE;
161 bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE;
162 bool GenInlinedSqrt(CallInfo* info) OVERRIDE;
Yixin Shou7071c8d2014-03-05 06:07:48 -0500163 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
164 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700165 bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE;
166 bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE;
Andreas Gampe98430592014-07-27 19:44:50 -0700167 bool GenInlinedCharAt(CallInfo* info) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700168
169 // Long instructions.
Andreas Gampec76c6142014-08-04 16:30:03 -0700170 void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
171 RegLocation rl_src2) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700172 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
173 RegLocation rl_src2) OVERRIDE;
174 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
175 RegLocation rl_src1, RegLocation rl_shift) OVERRIDE;
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700176 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE;
177 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
178 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
179 RegLocation rl_src1, RegLocation rl_shift) OVERRIDE;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800180
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700181 /*
182 * @brief Generate a two address long operation with a constant value
183 * @param rl_dest location of result
184 * @param rl_src constant source operand
185 * @param op Opcode to be generated
186 * @return success or not
187 */
188 bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700189
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700190 /*
191 * @brief Generate a three address long operation with a constant value
192 * @param rl_dest location of result
193 * @param rl_src1 source operand
194 * @param rl_src2 constant source operand
195 * @param op Opcode to be generated
196 * @return success or not
197 */
198 bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
199 Instruction::Code op);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700200 /**
201 * @brief Generate a long arithmetic operation.
202 * @param rl_dest The destination.
203 * @param rl_src1 First operand.
204 * @param rl_src2 Second operand.
205 * @param op The DEX opcode for the operation.
206 * @param is_commutative The sources can be swapped if needed.
207 */
208 virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
209 Instruction::Code op, bool is_commutative);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800210
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700211 /**
212 * @brief Generate a two operand long arithmetic operation.
213 * @param rl_dest The destination.
214 * @param rl_src Second operand.
215 * @param op The DEX opcode for the operation.
216 */
217 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800218
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700219 /**
220 * @brief Generate a long operation.
221 * @param rl_dest The destination. Must be in a register
222 * @param rl_src The other operand. May be in a register or in memory.
223 * @param op The DEX opcode for the operation.
224 */
225 virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700226
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700227
228 // TODO: collapse reg_lo, reg_hi
229 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div)
230 OVERRIDE;
231 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div) OVERRIDE;
232 void GenDivZeroCheckWide(RegStorage reg) OVERRIDE;
233 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
234 void GenExitSequence() OVERRIDE;
235 void GenSpecialExitSequence() OVERRIDE;
236 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src) OVERRIDE;
237 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE;
238 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE;
239 void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE;
240 void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
241 int32_t true_val, int32_t false_val, RegStorage rs_dest,
242 int dest_reg_class) OVERRIDE;
243 bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE;
244 void GenMoveException(RegLocation rl_dest) OVERRIDE;
245 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
246 int first_bit, int second_bit) OVERRIDE;
247 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
248 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
249 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
250 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
251
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700252 /**
253 * @brief Implement instanceof a final class with x86 specific code.
254 * @param use_declaring_class 'true' if we can use the class itself.
255 * @param type_idx Type index to use if use_declaring_class is 'false'.
256 * @param rl_dest Result to be set to 0 or 1.
257 * @param rl_src Object to be tested.
258 */
259 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700260 RegLocation rl_src) OVERRIDE;
Chao-ying Fua0147762014-06-06 18:38:49 -0700261
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700262 // Single operation generators.
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700263 LIR* OpUnconditionalBranch(LIR* target) OVERRIDE;
264 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE;
265 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE;
266 LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE;
267 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE;
268 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
269 LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE;
270 void OpEndIT(LIR* it) OVERRIDE;
271 LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE;
272 LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE;
273 LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE;
274 void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
275 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE;
276 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE;
277 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE;
278 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE;
279 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE;
280 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE;
281 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE;
282 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE;
283 LIR* OpTestSuspend(LIR* target) OVERRIDE;
284 LIR* OpVldm(RegStorage r_base, int count) OVERRIDE;
285 LIR* OpVstm(RegStorage r_base, int count) OVERRIDE;
286 void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE;
287 bool GenInlinedCurrentThread(CallInfo* info) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700288
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700289 bool InexpensiveConstantInt(int32_t value) OVERRIDE;
290 bool InexpensiveConstantFloat(int32_t value) OVERRIDE;
291 bool InexpensiveConstantLong(int64_t value) OVERRIDE;
292 bool InexpensiveConstantDouble(int64_t value) OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700293
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700294 /*
295 * @brief Should try to optimize for two address instructions?
296 * @return true if we try to avoid generating three operand instructions.
297 */
298 virtual bool GenerateTwoOperandInstructions() const { return true; }
Mark Mendelle87f9b52014-04-30 14:13:18 -0400299
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700300 /*
301 * @brief x86 specific codegen for int operations.
302 * @param opcode Operation to perform.
303 * @param rl_dest Destination for the result.
304 * @param rl_lhs Left hand operand.
305 * @param rl_rhs Right hand operand.
306 */
307 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700308 RegLocation rl_rhs) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800309
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700310 /*
311 * @brief Load the Method* of a dex method into the register.
312 * @param target_method The MethodReference of the method to be invoked.
313 * @param type How the method will be invoked.
314 * @param register that will contain the code address.
315 * @note register will be passed to TargetReg to get physical register.
316 */
317 void LoadMethodAddress(const MethodReference& target_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700318 SpecialTargetRegister symbolic_reg) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800319
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700320 /*
321 * @brief Load the Class* of a Dex Class type into the register.
Fred Shihe7f82e22014-08-06 10:46:37 -0700322 * @param dex DexFile that contains the class type.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700323 * @param type How the method will be invoked.
324 * @param register that will contain the code address.
325 * @note register will be passed to TargetReg to get physical register.
326 */
Fred Shihe7f82e22014-08-06 10:46:37 -0700327 void LoadClassType(const DexFile& dex_file, uint32_t type_idx,
328 SpecialTargetRegister symbolic_reg) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800329
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700330 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700331
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700332 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700333 NextCallInsn next_call_insn,
334 const MethodReference& target_method,
335 uint32_t vtable_idx,
336 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700337 bool skip_this) OVERRIDE;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700338
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700339 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
340 NextCallInsn next_call_insn,
341 const MethodReference& target_method,
342 uint32_t vtable_idx,
343 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700344 bool skip_this) OVERRIDE;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800345
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700346 /*
347 * @brief Generate a relative call to the method that will be patched at link time.
348 * @param target_method The MethodReference of the method to be invoked.
349 * @param type How the method will be invoked.
350 * @returns Call instruction
351 */
352 virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800353
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700354 /*
355 * @brief Handle x86 specific literals
356 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700357 void InstallLiteralPools() OVERRIDE;
Mark Mendellae9fd932014-02-10 16:14:35 -0800358
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700359 /*
360 * @brief Generate the debug_frame CFI information.
361 * @returns pointer to vector containing CFE information
362 */
Tong Shen35e1e6a2014-07-30 09:31:22 -0700363 static std::vector<uint8_t>* ReturnCommonCallFrameInformation(bool is_x86_64);
Mark Mendellae9fd932014-02-10 16:14:35 -0800364
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700365 /*
366 * @brief Generate the debug_frame FDE information.
367 * @returns pointer to vector containing CFE information
368 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700369 std::vector<uint8_t>* ReturnCallFrameInformation() OVERRIDE;
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800370
Andreas Gampe98430592014-07-27 19:44:50 -0700371 LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE;
372
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700373 protected:
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700374 RegStorage TargetReg32(SpecialTargetRegister reg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700375 // Casting of RegStorage
376 RegStorage As32BitReg(RegStorage reg) {
377 DCHECK(!reg.IsPair());
378 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
379 if (kFailOnSizeError) {
380 LOG(FATAL) << "Expected 64b register " << reg.GetReg();
381 } else {
382 LOG(WARNING) << "Expected 64b register " << reg.GetReg();
383 return reg;
384 }
385 }
386 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
387 reg.GetRawBits() & RegStorage::kRegTypeMask);
388 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
389 ->GetReg().GetReg(),
390 ret_val.GetReg());
391 return ret_val;
392 }
393
394 RegStorage As64BitReg(RegStorage reg) {
395 DCHECK(!reg.IsPair());
396 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
397 if (kFailOnSizeError) {
398 LOG(FATAL) << "Expected 32b register " << reg.GetReg();
399 } else {
400 LOG(WARNING) << "Expected 32b register " << reg.GetReg();
401 return reg;
402 }
403 }
404 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
405 reg.GetRawBits() & RegStorage::kRegTypeMask);
406 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
407 ->GetReg().GetReg(),
408 ret_val.GetReg());
409 return ret_val;
410 }
411
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700412 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
413 RegStorage r_dest, OpSize size);
414 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
415 RegStorage r_src, OpSize size);
416
417 RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num);
418
419 int AssignInsnOffsets();
420 void AssignOffsets();
421 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
422
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700423 size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700424 int32_t raw_base, int32_t displacement);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700425 void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg);
426 void EmitPrefix(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700427 int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700428 void EmitOpcode(const X86EncodingMap* entry);
429 void EmitPrefixAndOpcode(const X86EncodingMap* entry,
Ian Rogers5aa6e042014-06-13 16:38:24 -0700430 int32_t reg_r, int32_t reg_x, int32_t reg_b);
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700431 void EmitDisp(uint8_t base, int32_t disp);
432 void EmitModrmThread(uint8_t reg_or_opcode);
433 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp);
434 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale,
435 int32_t disp);
436 void EmitImm(const X86EncodingMap* entry, int64_t imm);
437 void EmitNullary(const X86EncodingMap* entry);
438 void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg);
439 void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg);
440 void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
441 void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
442 int32_t disp);
443 void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg);
444 void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp);
445 void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base,
446 int32_t raw_index, int scale, int32_t disp);
447 void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
448 int32_t disp, int32_t raw_reg);
449 void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
450 void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale,
451 int32_t raw_disp, int32_t imm);
452 void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp);
453 void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2);
454 void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm);
455 void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
456 int32_t imm);
457 void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1,
458 int32_t imm);
459 void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
460 void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm);
461 void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm);
462 void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm);
463 void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl);
464 void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl);
465 void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm);
466 void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc);
467 void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc);
468 void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc);
469 void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp,
470 int32_t cc);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800471
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700472 void EmitJmp(const X86EncodingMap* entry, int32_t rel);
473 void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc);
474 void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp);
475 void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp);
476 void EmitCallThread(const X86EncodingMap* entry, int32_t disp);
477 void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table,
478 int32_t raw_index, int scale, int32_t table_or_disp);
479 void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset);
480 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir);
481 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
482 int64_t val, ConditionCode ccode);
483 void GenConstWide(RegLocation rl_dest, int64_t value);
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700484 void GenMultiplyVectorSignedByte(BasicBlock *bb, MIR *mir);
485 void GenShiftByteVector(BasicBlock *bb, MIR *mir);
486 void AndMaskVectorRegister(RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
487 void MaskVectorRegister(X86OpCode opcode, RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4);
488 void AppendOpcodeWithConst(X86OpCode opcode, int reg, MIR* mir);
Mark Mendell2637f2e2014-04-30 10:10:47 -0400489
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700490 static bool ProvidesFullMemoryBarrier(X86OpCode opcode);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800491
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700492 /*
493 * @brief Ensure that a temporary register is byte addressable.
494 * @returns a temporary guarenteed to be byte addressable.
495 */
496 virtual RegStorage AllocateByteRegister();
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800497
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700498 /*
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700499 * @brief Use a wide temporary as a 128-bit register
500 * @returns a 128-bit temporary register.
501 */
502 virtual RegStorage Get128BitRegister(RegStorage reg);
503
504 /*
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700505 * @brief Check if a register is byte addressable.
506 * @returns true if a register is byte addressable.
507 */
508 bool IsByteRegister(RegStorage reg);
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700509
510 void GenDivRemLongLit(RegLocation rl_dest, RegLocation rl_src, int64_t imm, bool is_div);
511
DaniilSokolov70c4f062014-06-24 17:34:00 -0700512 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700513
514 /*
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700515 * @brief generate inline code for fast case of Strng.indexOf.
516 * @param info Call parameters
517 * @param zero_based 'true' if the index into the string is 0.
518 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be
519 * generated.
520 */
521 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
Mark Mendelle87f9b52014-04-30 14:13:18 -0400522
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700523 /**
524 * @brief Reserve a fixed number of vector registers from the register pool
525 * @details The mir->dalvikInsn.vA specifies an N such that vector registers
526 * [0..N-1] are removed from the temporary pool. The caller must call
527 * ReturnVectorRegisters before calling ReserveVectorRegisters again.
528 * Also sets the num_reserved_vector_regs_ to the specified value
529 * @param mir whose vA specifies the number of registers to reserve
530 */
531 void ReserveVectorRegisters(MIR* mir);
532
533 /**
534 * @brief Return all the reserved vector registers to the temp pool
535 * @details Returns [0..num_reserved_vector_regs_]
536 */
537 void ReturnVectorRegisters();
538
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700539 /*
540 * @brief Load 128 bit constant into vector register.
541 * @param bb The basic block in which the MIR is from.
542 * @param mir The MIR whose opcode is kMirConstVector
543 * @note vA is the TypeSize for the register.
544 * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values.
545 */
546 void GenConst128(BasicBlock* bb, MIR* mir);
Mark Mendell4028a6c2014-02-19 20:06:20 -0800547
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700548 /*
549 * @brief MIR to move a vectorized register to another.
550 * @param bb The basic block in which the MIR is from.
551 * @param mir The MIR whose opcode is kMirConstVector.
552 * @note vA: TypeSize
553 * @note vB: destination
554 * @note vC: source
555 */
556 void GenMoveVector(BasicBlock *bb, MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400557
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700558 /*
559 * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know the type of the vector.
560 * @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 /*
569 * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the type of the vector.
570 * @param bb The basic block in which the MIR is from.
571 * @param mir The MIR whose opcode is kMirConstVector.
572 * @note vA: TypeSize
573 * @note vB: destination and source
574 * @note vC: source
575 */
576 void GenAddVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400577
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700578 /*
579 * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the type of the vector.
580 * @param bb The basic block in which the MIR is from.
581 * @param mir The MIR whose opcode is kMirConstVector.
582 * @note vA: TypeSize
583 * @note vB: destination and source
584 * @note vC: source
585 */
586 void GenSubtractVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400587
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700588 /*
589 * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the type of the vector.
590 * @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: immediate
595 */
596 void GenShiftLeftVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400597
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700598 /*
599 * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to know the type of the vector.
600 * @param bb The basic block in which the MIR is from.
601 * @param mir The MIR whose opcode is kMirConstVector.
602 * @note vA: TypeSize
603 * @note vB: destination and source
604 * @note vC: immediate
605 */
606 void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400607
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700608 /*
609 * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA to know the type of the vector.
610 * @param bb The basic block in which the MIR is from..
611 * @param mir The MIR whose opcode is kMirConstVector.
612 * @note vA: TypeSize
613 * @note vB: destination and source
614 * @note vC: immediate
615 */
616 void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400617
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700618 /*
619 * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the type of the vector.
620 * @note vA: TypeSize
621 * @note vB: destination and source
622 * @note vC: source
623 */
624 void GenAndVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400625
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700626 /*
627 * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the type of the vector.
628 * @param bb The basic block in which the MIR is from.
629 * @param mir The MIR whose opcode is kMirConstVector.
630 * @note vA: TypeSize
631 * @note vB: destination and source
632 * @note vC: source
633 */
634 void GenOrVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400635
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700636 /*
637 * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the type of the vector.
638 * @param bb The basic block in which the MIR is from.
639 * @param mir The MIR whose opcode is kMirConstVector.
640 * @note vA: TypeSize
641 * @note vB: destination and source
642 * @note vC: source
643 */
644 void GenXorVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400645
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700646 /*
647 * @brief Reduce a 128-bit packed element into a single VR by taking lower bits
648 * @param bb The basic block in which the MIR is from.
649 * @param mir The MIR whose opcode is kMirConstVector.
650 * @details Instruction does a horizontal addition of the packed elements and then adds it to VR.
651 * @note vA: TypeSize
652 * @note vB: destination and source VR (not vector register)
653 * @note vC: source (vector register)
654 */
655 void GenAddReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400656
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700657 /*
658 * @brief Extract a packed element into a single VR.
659 * @param bb The basic block in which the MIR is from.
660 * @param mir The MIR whose opcode is kMirConstVector.
661 * @note vA: TypeSize
662 * @note vB: destination VR (not vector register)
663 * @note vC: source (vector register)
664 * @note arg[0]: The index to use for extraction from vector register (which packed element).
665 */
666 void GenReduceVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400667
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700668 /*
669 * @brief Create a vector value, with all TypeSize values equal to vC
670 * @param bb The basic block in which the MIR is from.
671 * @param mir The MIR whose opcode is kMirConstVector.
672 * @note vA: TypeSize.
673 * @note vB: destination vector register.
674 * @note vC: source VR (not vector register).
675 */
676 void GenSetVector(BasicBlock *bb, MIR *mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400677
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700678 /*
679 * @brief Generate code for a vector opcode.
680 * @param bb The basic block in which the MIR is from.
681 * @param mir The MIR whose opcode is a non-standard opcode.
682 */
683 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir);
Mark Mendellfe945782014-05-22 09:52:36 -0400684
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700685 /*
686 * @brief Return the correct x86 opcode for the Dex operation
687 * @param op Dex opcode for the operation
688 * @param loc Register location of the operand
689 * @param is_high_op 'true' if this is an operation on the high word
690 * @param value Immediate value for the operation. Used for byte variants
691 * @returns the correct x86 opcode to perform the operation
692 */
693 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400694
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700695 /*
696 * @brief Return the correct x86 opcode for the Dex operation
697 * @param op Dex opcode for the operation
698 * @param dest location of the destination. May be register or memory.
699 * @param rhs Location for the rhs of the operation. May be in register or memory.
700 * @param is_high_op 'true' if this is an operation on the high word
701 * @returns the correct x86 opcode to perform the operation
702 * @note at most one location may refer to memory
703 */
704 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs,
705 bool is_high_op);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800706
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700707 /*
708 * @brief Is this operation a no-op for this opcode and value
709 * @param op Dex opcode for the operation
710 * @param value Immediate value for the operation.
711 * @returns 'true' if the operation will have no effect
712 */
713 bool IsNoOp(Instruction::Code op, int32_t value);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800714
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700715 /**
716 * @brief Calculate magic number and shift for a given divisor
717 * @param divisor divisor number for calculation
718 * @param magic hold calculated magic number
719 * @param shift hold calculated shift
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700720 * @param is_long 'true' if divisor is jlong, 'false' for jint.
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700721 */
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700722 void CalculateMagicAndShift(int64_t divisor, int64_t& magic, int& shift, bool is_long);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800723
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700724 /*
725 * @brief Generate an integer div or rem operation.
726 * @param rl_dest Destination Location.
727 * @param rl_src1 Numerator Location.
728 * @param rl_src2 Divisor Location.
729 * @param is_div 'true' if this is a division, 'false' for a remainder.
730 * @param check_zero 'true' if an exception should be generated if the divisor is 0.
731 */
732 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
733 bool is_div, bool check_zero);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800734
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700735 /*
736 * @brief Generate an integer div or rem operation by a literal.
737 * @param rl_dest Destination Location.
738 * @param rl_src Numerator Location.
739 * @param lit Divisor.
740 * @param is_div 'true' if this is a division, 'false' for a remainder.
741 */
742 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800743
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700744 /*
745 * Generate code to implement long shift operations.
746 * @param opcode The DEX opcode to specify the shift type.
747 * @param rl_dest The destination.
748 * @param rl_src The value to be shifted.
749 * @param shift_amount How much to shift.
750 * @returns the RegLocation of the result.
751 */
752 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
753 RegLocation rl_src, int shift_amount);
754 /*
755 * Generate an imul of a register by a constant or a better sequence.
756 * @param dest Destination Register.
757 * @param src Source Register.
758 * @param val Constant multiplier.
759 */
760 void GenImulRegImm(RegStorage dest, RegStorage src, int val);
Mark Mendell4708dcd2014-01-22 09:05:18 -0800761
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700762 /*
763 * Generate an imul of a memory location by a constant or a better sequence.
764 * @param dest Destination Register.
765 * @param sreg Symbolic register.
766 * @param displacement Displacement on stack of Symbolic Register.
767 * @param val Constant multiplier.
768 */
769 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800770
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700771 /*
772 * @brief Compare memory to immediate, and branch if condition true.
773 * @param cond The condition code that when true will branch to the target.
774 * @param temp_reg A temporary register that can be used if compare memory is not
775 * supported by the architecture.
776 * @param base_reg The register holding the base address.
777 * @param offset The offset from the base.
778 * @param check_value The immediate to compare to.
Dave Allison69dfe512014-07-11 17:11:58 +0000779 * @param target branch target (or nullptr)
780 * @param compare output for getting LIR for comparison (or nullptr)
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700781 */
782 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
Dave Allison69dfe512014-07-11 17:11:58 +0000783 int offset, int check_value, LIR* target, LIR** compare);
Mark Mendell766e9292014-01-27 07:55:47 -0800784
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700785 void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double);
786
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700787 /*
788 * Can this operation be using core registers without temporaries?
789 * @param rl_lhs Left hand operand.
790 * @param rl_rhs Right hand operand.
791 * @returns 'true' if the operation can proceed without needing temporary regs.
792 */
793 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs);
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800794
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700795 /**
796 * @brief Generates inline code for conversion of long to FP by using x87/
797 * @param rl_dest The destination of the FP.
798 * @param rl_src The source of the long.
799 * @param is_double 'true' if dealing with double, 'false' for float.
800 */
801 virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double);
Mark Mendell67c39c42014-01-31 17:28:00 -0800802
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700803 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset);
804 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset);
805
806 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
807 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value);
808 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value);
809 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset);
810 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset);
811 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset);
812 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset);
813 void OpTlsCmp(ThreadOffset<4> offset, int val);
814 void OpTlsCmp(ThreadOffset<8> offset, int val);
815
816 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
817
Andreas Gampec76c6142014-08-04 16:30:03 -0700818 // Try to do a long multiplication where rl_src2 is a constant. This simplified setup might fail,
819 // in which case false will be returned.
820 bool GenMulLongConst(RegLocation rl_dest, RegLocation rl_src1, int64_t val);
821 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
822 RegLocation rl_src2);
823 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
824 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
825 void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1,
826 RegLocation rl_src2, bool is_div);
827
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700828 void SpillCoreRegs();
829 void UnSpillCoreRegs();
830 void UnSpillFPRegs();
831 void SpillFPRegs();
832
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700833 /*
834 * @brief Perform MIR analysis before compiling method.
835 * @note Invokes Mir2LiR::Materialize after analysis.
836 */
837 void Materialize();
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800838
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700839 /*
840 * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register
841 * without regard to data type. In practice, this can result in UpdateLoc returning a
842 * location record for a Dalvik float value in a core register, and vis-versa. For targets
843 * which can inexpensively move data between core and float registers, this can often be a win.
844 * However, for x86 this is generally not a win. These variants of UpdateLoc()
845 * take a register class argument - and will return an in-register location record only if
846 * the value is live in a temp register of the correct class. Additionally, if the value is in
847 * a temp register of the wrong register class, it will be clobbered.
848 */
849 RegLocation UpdateLocTyped(RegLocation loc, int reg_class);
850 RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class);
Mark Mendell67c39c42014-01-31 17:28:00 -0800851
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700852 /*
853 * @brief Analyze MIR before generating code, to prepare for the code generation.
854 */
855 void AnalyzeMIR();
buzbee30adc732014-05-09 15:10:18 -0700856
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700857 /*
858 * @brief Analyze one basic block.
859 * @param bb Basic block to analyze.
860 */
861 void AnalyzeBB(BasicBlock * bb);
Mark Mendell67c39c42014-01-31 17:28:00 -0800862
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700863 /*
864 * @brief Analyze one extended MIR instruction
865 * @param opcode MIR instruction opcode.
866 * @param bb Basic block containing instruction.
867 * @param mir Extended instruction to analyze.
868 */
869 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800870
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700871 /*
872 * @brief Analyze one MIR instruction
873 * @param opcode MIR instruction opcode.
874 * @param bb Basic block containing instruction.
875 * @param mir Instruction to analyze.
876 */
877 virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800878
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700879 /*
880 * @brief Analyze one MIR float/double instruction
881 * @param opcode MIR instruction opcode.
882 * @param bb Basic block containing instruction.
883 * @param mir Instruction to analyze.
884 */
885 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir);
Mark Mendell67c39c42014-01-31 17:28:00 -0800886
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700887 /*
888 * @brief Analyze one use of a double operand.
889 * @param rl_use Double RegLocation for the operand.
890 */
891 void AnalyzeDoubleUse(RegLocation rl_use);
Mark Mendell67c39c42014-01-31 17:28:00 -0800892
Yixin Shou7071c8d2014-03-05 06:07:48 -0500893 /*
894 * @brief Analyze one invoke-static MIR instruction
895 * @param opcode MIR instruction opcode.
896 * @param bb Basic block containing instruction.
897 * @param mir Instruction to analyze.
898 */
899 void AnalyzeInvokeStatic(int opcode, BasicBlock * bb, MIR *mir);
900
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700901 // Information derived from analysis of MIR
Dmitry Petrochenko9ee801f2014-05-12 11:31:37 +0700902
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700903 // The compiler temporary for the code address of the method.
904 CompilerTemp *base_of_code_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800905
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700906 // Have we decided to compute a ptr to code and store in temporary VR?
907 bool store_method_addr_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800908
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700909 // Have we used the stored method address?
910 bool store_method_addr_used_;
Mark Mendell67c39c42014-01-31 17:28:00 -0800911
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700912 // Instructions to remove if we didn't use the stored method address.
913 LIR* setup_method_address_[2];
Mark Mendell55d0eac2014-02-06 11:02:52 -0800914
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700915 // Instructions needing patching with Method* values.
916 GrowableArray<LIR*> method_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800917
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700918 // Instructions needing patching with Class Type* values.
919 GrowableArray<LIR*> class_type_address_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800920
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700921 // Instructions needing patching with PC relative code addresses.
922 GrowableArray<LIR*> call_method_insns_;
Mark Mendell55d0eac2014-02-06 11:02:52 -0800923
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700924 // Prologue decrement of stack pointer.
925 LIR* stack_decrement_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800926
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700927 // Epilogue increment of stack pointer.
928 LIR* stack_increment_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800929
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700930 // The list of const vector literals.
931 LIR *const_vectors_;
Mark Mendelld65c51a2014-04-29 16:55:20 -0400932
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700933 /*
934 * @brief Search for a matching vector literal
935 * @param mir A kMirOpConst128b MIR instruction to match.
936 * @returns pointer to matching LIR constant, or nullptr if not found.
937 */
938 LIR *ScanVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400939
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700940 /*
941 * @brief Add a constant vector literal
942 * @param mir A kMirOpConst128b MIR instruction to match.
943 */
944 LIR *AddVectorLiteral(MIR *mir);
Mark Mendelld65c51a2014-04-29 16:55:20 -0400945
Ian Rogers0f9b9c52014-06-09 01:32:12 -0700946 InToRegStorageMapping in_to_reg_storage_mapping_;
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700947
Serguei Katkov59a42af2014-07-05 00:55:46 +0700948 bool WideGPRsAreAliases() OVERRIDE {
949 return cu_->target64; // On 64b, we have 64b GPRs.
950 }
951 bool WideFPRsAreAliases() OVERRIDE {
952 return true; // xmm registers have 64b views even on x86.
953 }
954
Alexei Zavjalov6bbf0962014-07-15 02:19:41 +0700955 /*
956 * @brief Dump a RegLocation using printf
957 * @param loc Register location to dump
958 */
959 static void DumpRegLocation(RegLocation loc);
960
961 static const X86EncodingMap EncodingMap[kX86Last];
962
Udayan Banerji60bfe7b2014-07-08 19:59:43 -0700963 private:
964 // The number of vector registers [0..N] reserved by a call to ReserveVectorRegisters
965 int num_reserved_vector_regs_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700966};
967
968} // namespace art
969
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700970#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_