blob: 766ac23ef91d8749b13202d4d000725c0a475195 [file] [log] [blame]
Matteo Franchin43ec8732014-03-31 15:00:14 +01001/*
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
17#ifndef ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_
18#define ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_
19
20#include "arm64_lir.h"
21#include "dex/compiler_internals.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070022#include "dex/quick/mir_to_lir.h"
Matteo Franchin43ec8732014-03-31 15:00:14 +010023
buzbee33ae5582014-06-12 14:56:32 -070024#include <map>
25
Matteo Franchin43ec8732014-03-31 15:00:14 +010026namespace art {
27
Andreas Gampe4b537a82014-06-30 22:24:53 -070028class Arm64Mir2Lir FINAL : public Mir2Lir {
buzbee33ae5582014-06-12 14:56:32 -070029 protected:
buzbee33ae5582014-06-12 14:56:32 -070030 class InToRegStorageArm64Mapper : public InToRegStorageMapper {
31 public:
32 InToRegStorageArm64Mapper() : cur_core_reg_(0), cur_fp_reg_(0) {}
33 virtual ~InToRegStorageArm64Mapper() {}
Serguei Katkov717a3e42014-11-13 17:19:42 +060034 virtual RegStorage GetNextReg(ShortyArg arg);
35 virtual void Reset() OVERRIDE {
36 cur_core_reg_ = 0;
37 cur_fp_reg_ = 0;
38 }
buzbee33ae5582014-06-12 14:56:32 -070039 private:
Serguei Katkov717a3e42014-11-13 17:19:42 +060040 size_t cur_core_reg_;
41 size_t cur_fp_reg_;
buzbee33ae5582014-06-12 14:56:32 -070042 };
43
Serguei Katkov717a3e42014-11-13 17:19:42 +060044 InToRegStorageArm64Mapper in_to_reg_storage_arm64_mapper_;
45 InToRegStorageMapper* GetResetedInToRegStorageMapper() OVERRIDE {
46 in_to_reg_storage_arm64_mapper_.Reset();
47 return &in_to_reg_storage_arm64_mapper_;
48 }
buzbee33ae5582014-06-12 14:56:32 -070049
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010050 public:
51 Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
Matteo Franchin43ec8732014-03-31 15:00:14 +010052
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010053 // Required for target - codegen helpers.
54 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
55 RegLocation rl_dest, int lit) OVERRIDE;
56 bool HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div,
57 RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
58 bool HandleEasyDivRem64(Instruction::Code dalvik_opcode, bool is_div,
59 RegLocation rl_src, RegLocation rl_dest, int64_t lit);
60 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
Ningsheng Jian675e09b2014-10-23 13:48:36 +080061 void GenMultiplyByConstantFloat(RegLocation rl_dest, RegLocation rl_src1,
62 int32_t constant) OVERRIDE;
63 void GenMultiplyByConstantDouble(RegLocation rl_dest, RegLocation rl_src1,
64 int64_t constant) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010065 LIR* CheckSuspendUsingLoad() OVERRIDE;
66 RegStorage LoadHelper(QuickEntrypointEnum trampoline) OVERRIDE;
67 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
68 OpSize size, VolatileKind is_volatile) OVERRIDE;
69 LIR* LoadRefDisp(RegStorage r_base, int displacement, RegStorage r_dest,
70 VolatileKind is_volatile) OVERRIDE;
71 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
72 OpSize size) OVERRIDE;
73 LIR* LoadRefIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale)
74 OVERRIDE;
75 LIR* LoadConstantNoClobber(RegStorage r_dest, int value) OVERRIDE;
76 LIR* LoadConstantWide(RegStorage r_dest, int64_t value) OVERRIDE;
77 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size,
78 VolatileKind is_volatile) OVERRIDE;
79 LIR* StoreRefDisp(RegStorage r_base, int displacement, RegStorage r_src, VolatileKind is_volatile)
80 OVERRIDE;
81 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
82 OpSize size) OVERRIDE;
83 LIR* StoreRefIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale) OVERRIDE;
Vladimir Markobf535be2014-11-19 18:52:35 +000084
85 /// @copydoc Mir2Lir::UnconditionallyMarkGCCard(RegStorage)
86 void UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) OVERRIDE;
87
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010088 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
89 int offset, int check_value, LIR* target, LIR** compare) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010090
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010091 // Required for target - register utilities.
92 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
93 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
94 if (wide_kind == kWide || wide_kind == kRef) {
Matteo Franchined7a0f22014-06-10 19:23:45 +010095 return As64BitReg(TargetReg(symbolic_reg));
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010096 } else {
97 return Check32BitReg(TargetReg(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -070098 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010099 }
100 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
101 return As64BitReg(TargetReg(symbolic_reg));
102 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100103 RegLocation GetReturnAlt() OVERRIDE;
104 RegLocation GetReturnWideAlt() OVERRIDE;
105 RegLocation LocCReturn() OVERRIDE;
106 RegLocation LocCReturnRef() OVERRIDE;
107 RegLocation LocCReturnDouble() OVERRIDE;
108 RegLocation LocCReturnFloat() OVERRIDE;
109 RegLocation LocCReturnWide() OVERRIDE;
110 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
111 void AdjustSpillMask() OVERRIDE;
112 void ClobberCallerSave() OVERRIDE;
113 void FreeCallTemps() OVERRIDE;
114 void LockCallTemps() OVERRIDE;
115 void CompilerInitializeRegAlloc() OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100116
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100117 // Required for target - miscellaneous.
118 void AssembleLIR() OVERRIDE;
119 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
120 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
121 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
122 const char* GetTargetInstFmt(int opcode) OVERRIDE;
123 const char* GetTargetInstName(int opcode) OVERRIDE;
124 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE;
125 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
126 uint64_t GetTargetInstFlags(int opcode) OVERRIDE;
127 size_t GetInsnSize(LIR* lir) OVERRIDE;
128 bool IsUnconditionalBranch(LIR* lir) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100129
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100130 // Get the register class for load/store of a field.
131 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100132
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100133 // Required for target - Dalvik-level generators.
134 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
135 RegLocation lr_shift) OVERRIDE;
136 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700137 RegLocation rl_src2, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100138 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
139 RegLocation rl_dest, int scale) OVERRIDE;
140 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
141 RegLocation rl_src, int scale, bool card_mark) OVERRIDE;
142 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700143 RegLocation rl_shift, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100144 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
145 RegLocation rl_src2) OVERRIDE;
146 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
147 RegLocation rl_src2) OVERRIDE;
148 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
149 RegLocation rl_src2) OVERRIDE;
150 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
151 bool GenInlinedReverseBits(CallInfo* info, OpSize size) OVERRIDE;
152 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
153 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
154 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE;
155 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE;
156 bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE;
157 bool GenInlinedSqrt(CallInfo* info) OVERRIDE;
158 bool GenInlinedCeil(CallInfo* info) OVERRIDE;
159 bool GenInlinedFloor(CallInfo* info) OVERRIDE;
160 bool GenInlinedRint(CallInfo* info) OVERRIDE;
161 bool GenInlinedRound(CallInfo* info, bool is_double) OVERRIDE;
162 bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE;
163 bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE;
Martyn Capewell9a8a5062014-08-07 11:31:48 +0100164 bool GenInlinedAbsInt(CallInfo* info) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100165 bool GenInlinedAbsLong(CallInfo* info) OVERRIDE;
Zheng Xu947717a2014-08-07 14:05:23 +0800166 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100167 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampec76c6142014-08-04 16:30:03 -0700168 void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700169 RegLocation rl_src2, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100170 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div)
171 OVERRIDE;
172 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div)
173 OVERRIDE;
174 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE;
175 void GenDivZeroCheckWide(RegStorage reg) OVERRIDE;
176 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
177 void GenExitSequence() OVERRIDE;
178 void GenSpecialExitSequence() OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100179 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE;
180 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE;
181 void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE;
182 void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
183 int32_t true_val, int32_t false_val, RegStorage rs_dest,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700184 RegisterClass dest_reg_class) OVERRIDE;
Andreas Gampe90969af2014-07-15 23:02:11 -0700185
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100186 bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE;
187 void GenMonitorEnter(int opt_flags, RegLocation rl_src) OVERRIDE;
188 void GenMonitorExit(int opt_flags, RegLocation rl_src) OVERRIDE;
189 void GenMoveException(RegLocation rl_dest) OVERRIDE;
190 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
191 int first_bit, int second_bit) OVERRIDE;
192 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
193 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampe48971b32014-08-06 10:09:01 -0700194 void GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
195 void GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100196
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100197 // Required for target - single operation generators.
198 LIR* OpUnconditionalBranch(LIR* target) OVERRIDE;
199 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE;
200 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE;
201 LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE;
202 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE;
203 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
204 LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE;
205 void OpEndIT(LIR* it) OVERRIDE;
206 LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE;
207 LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE;
208 LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE;
209 void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
210 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE;
211 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE;
212 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE;
213 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE;
214 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE;
215 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE;
216 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE;
217 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE;
218 LIR* OpTestSuspend(LIR* target) OVERRIDE;
219 LIR* OpVldm(RegStorage r_base, int count) OVERRIDE;
220 LIR* OpVstm(RegStorage r_base, int count) OVERRIDE;
221 void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE;
Andreas Gampef29ecd62014-07-29 00:35:00 -0700222
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100223 bool InexpensiveConstantInt(int32_t value) OVERRIDE;
Matteo Franchinc763e352014-07-04 12:53:27 +0100224 bool InexpensiveConstantInt(int32_t value, Instruction::Code opcode) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100225 bool InexpensiveConstantFloat(int32_t value) OVERRIDE;
226 bool InexpensiveConstantLong(int64_t value) OVERRIDE;
227 bool InexpensiveConstantDouble(int64_t value) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100228
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700229 bool WideGPRsAreAliases() const OVERRIDE {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100230 return true; // 64b architecture.
231 }
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700232 bool WideFPRsAreAliases() const OVERRIDE {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100233 return true; // 64b architecture.
234 }
Andreas Gampe98430592014-07-27 19:44:50 -0700235
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100236 size_t GetInstructionOffset(LIR* lir) OVERRIDE;
237
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100238 NextCallInsn GetNextSDCallInsn() OVERRIDE;
239
240 /*
241 * @brief Generate a relative call to the method that will be patched at link time.
242 * @param target_method The MethodReference of the method to be invoked.
243 * @param type How the method will be invoked.
244 * @returns Call instruction
245 */
246 LIR* CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
247
248 /*
249 * @brief Generate the actual call insn based on the method info.
250 * @param method_info the lowering info for the method call.
251 * @returns Call instruction
252 */
253 virtual LIR* GenCallInsn(const MirMethodLoweringInfo& method_info) OVERRIDE;
254
255 /*
256 * @brief Handle ARM specific literals.
257 */
258 void InstallLiteralPools() OVERRIDE;
259
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100260 LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE;
261
262 private:
263 /**
264 * @brief Given register xNN (dNN), returns register wNN (sNN).
265 * @param reg #RegStorage containing a Solo64 input register (e.g. @c x1 or @c d2).
266 * @return A Solo32 with the same register number as the @p reg (e.g. @c w1 or @c s2).
267 * @see As64BitReg
268 */
269 RegStorage As32BitReg(RegStorage reg) {
270 DCHECK(!reg.IsPair());
271 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
272 if (kFailOnSizeError) {
273 LOG(FATAL) << "Expected 64b register";
274 } else {
275 LOG(WARNING) << "Expected 64b register";
276 return reg;
Andreas Gampe3c12c512014-06-24 18:46:29 +0000277 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100278 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100279 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
280 reg.GetRawBits() & RegStorage::kRegTypeMask);
281 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
282 ->GetReg().GetReg(),
283 ret_val.GetReg());
284 return ret_val;
285 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100286
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100287 RegStorage Check32BitReg(RegStorage reg) {
288 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
289 if (kFailOnSizeError) {
290 LOG(FATAL) << "Checked for 32b register";
291 } else {
292 LOG(WARNING) << "Checked for 32b register";
293 return As32BitReg(reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000294 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000295 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100296 return reg;
297 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000298
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100299 /**
300 * @brief Given register wNN (sNN), returns register xNN (dNN).
301 * @param reg #RegStorage containing a Solo32 input register (e.g. @c w1 or @c s2).
302 * @return A Solo64 with the same register number as the @p reg (e.g. @c x1 or @c d2).
303 * @see As32BitReg
304 */
305 RegStorage As64BitReg(RegStorage reg) {
306 DCHECK(!reg.IsPair());
307 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
308 if (kFailOnSizeError) {
309 LOG(FATAL) << "Expected 32b register";
310 } else {
311 LOG(WARNING) << "Expected 32b register";
312 return reg;
Andreas Gampe3c12c512014-06-24 18:46:29 +0000313 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100314 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100315 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
316 reg.GetRawBits() & RegStorage::kRegTypeMask);
317 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
318 ->GetReg().GetReg(),
319 ret_val.GetReg());
320 return ret_val;
321 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100322
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100323 RegStorage Check64BitReg(RegStorage reg) {
324 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
325 if (kFailOnSizeError) {
326 LOG(FATAL) << "Checked for 64b register";
327 } else {
328 LOG(WARNING) << "Checked for 64b register";
329 return As64BitReg(reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000330 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000331 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100332 return reg;
333 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000334
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100335 int32_t EncodeImmSingle(uint32_t bits);
336 int32_t EncodeImmDouble(uint64_t bits);
337 LIR* LoadFPConstantValue(RegStorage r_dest, int32_t value);
338 LIR* LoadFPConstantValueWide(RegStorage r_dest, int64_t value);
339 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
340 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
341 void AssignDataOffsets();
342 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700343 bool is_div, int flags) OVERRIDE;
344 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100345 size_t GetLoadStoreSize(LIR* lir);
346
347 bool SmallLiteralDivRem64(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
348 RegLocation rl_dest, int64_t lit);
349
350 uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset);
351 int AssignInsnOffsets();
352 void AssignOffsets();
353 uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir);
354
355 // Spill core and FP registers. Returns the SP difference: either spill size, or whole
356 // frame size.
357 int SpillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size);
358
359 // Unspill core and FP registers.
360 void UnspillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size);
361
362 void GenLongOp(OpKind op, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
363
364 LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value);
365 LIR* OpRegRegImm64(OpKind op, RegStorage r_dest, RegStorage r_src1, int64_t value);
366
367 LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
368 LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
369 int shift);
370 int EncodeShift(int code, int amount);
371
372 LIR* OpRegRegExtend(OpKind op, RegStorage r_dest_src1, RegStorage r_src2,
373 A64RegExtEncodings ext, uint8_t amount);
374 LIR* OpRegRegRegExtend(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
375 A64RegExtEncodings ext, uint8_t amount);
376 int EncodeExtend(int extend_type, int amount);
377 bool IsExtendEncoding(int encoded_value);
378
379 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size);
380 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
381
382 int EncodeLogicalImmediate(bool is_wide, uint64_t value);
383 uint64_t DecodeLogicalImmediate(bool is_wide, int value);
384 ArmConditionCode ArmConditionEncoding(ConditionCode code);
385
386 // Helper used in the two GenSelect variants.
387 void GenSelect(int32_t left, int32_t right, ConditionCode code, RegStorage rs_dest,
388 int result_reg_class);
389
Andreas Gampec76c6142014-08-04 16:30:03 -0700390 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
391 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
392 void GenDivRemLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700393 RegLocation rl_src2, bool is_div, int flags);
Andreas Gampec76c6142014-08-04 16:30:03 -0700394
Matteo Franchin4163c532014-07-15 15:20:27 +0100395 static const A64EncodingMap EncodingMap[kA64Last];
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100396
397 ArenaVector<LIR*> call_method_insns_;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600398
399 int GenDalvikArgsBulkCopy(CallInfo* info, int first, int count) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100400};
401
402} // namespace art
403
404#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_