blob: 8184f022871e2248ba8e060dfa22888bd2688eb3 [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"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080021#include "base/logging.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;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010069 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
70 OpSize size) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010071 LIR* LoadConstantNoClobber(RegStorage r_dest, int value) OVERRIDE;
72 LIR* LoadConstantWide(RegStorage r_dest, int64_t value) OVERRIDE;
73 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size,
74 VolatileKind is_volatile) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010075 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
76 OpSize size) OVERRIDE;
Vladimir Markobf535be2014-11-19 18:52:35 +000077
78 /// @copydoc Mir2Lir::UnconditionallyMarkGCCard(RegStorage)
79 void UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) OVERRIDE;
80
Vladimir Marko20f85592015-03-19 10:07:02 +000081 bool CanUseOpPcRelDexCacheArrayLoad() const OVERRIDE;
82 void OpPcRelDexCacheArrayLoad(const DexFile* dex_file, int offset, RegStorage r_dest) OVERRIDE;
83
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010084 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
85 int offset, int check_value, LIR* target, LIR** compare) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010086
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010087 // Required for target - register utilities.
88 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
89 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
90 if (wide_kind == kWide || wide_kind == kRef) {
Matteo Franchined7a0f22014-06-10 19:23:45 +010091 return As64BitReg(TargetReg(symbolic_reg));
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010092 } else {
93 return Check32BitReg(TargetReg(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -070094 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010095 }
96 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
97 return As64BitReg(TargetReg(symbolic_reg));
98 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010099 RegLocation GetReturnAlt() OVERRIDE;
100 RegLocation GetReturnWideAlt() OVERRIDE;
101 RegLocation LocCReturn() OVERRIDE;
102 RegLocation LocCReturnRef() OVERRIDE;
103 RegLocation LocCReturnDouble() OVERRIDE;
104 RegLocation LocCReturnFloat() OVERRIDE;
105 RegLocation LocCReturnWide() OVERRIDE;
106 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
107 void AdjustSpillMask() OVERRIDE;
108 void ClobberCallerSave() OVERRIDE;
109 void FreeCallTemps() OVERRIDE;
110 void LockCallTemps() OVERRIDE;
111 void CompilerInitializeRegAlloc() OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100112
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100113 // Required for target - miscellaneous.
114 void AssembleLIR() OVERRIDE;
115 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
116 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
117 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
118 const char* GetTargetInstFmt(int opcode) OVERRIDE;
119 const char* GetTargetInstName(int opcode) OVERRIDE;
120 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE;
121 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
122 uint64_t GetTargetInstFlags(int opcode) OVERRIDE;
123 size_t GetInsnSize(LIR* lir) OVERRIDE;
124 bool IsUnconditionalBranch(LIR* lir) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100125
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100126 // Get the register class for load/store of a field.
127 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100128
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100129 // Required for target - Dalvik-level generators.
130 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
131 RegLocation lr_shift) OVERRIDE;
132 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700133 RegLocation rl_src2, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100134 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
135 RegLocation rl_dest, int scale) OVERRIDE;
136 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
137 RegLocation rl_src, int scale, bool card_mark) OVERRIDE;
138 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700139 RegLocation rl_shift, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100140 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
141 RegLocation rl_src2) OVERRIDE;
142 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
143 RegLocation rl_src2) OVERRIDE;
144 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
145 RegLocation rl_src2) OVERRIDE;
146 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
147 bool GenInlinedReverseBits(CallInfo* info, OpSize size) OVERRIDE;
148 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
149 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
150 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE;
151 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE;
152 bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE;
153 bool GenInlinedSqrt(CallInfo* info) OVERRIDE;
154 bool GenInlinedCeil(CallInfo* info) OVERRIDE;
155 bool GenInlinedFloor(CallInfo* info) OVERRIDE;
156 bool GenInlinedRint(CallInfo* info) OVERRIDE;
157 bool GenInlinedRound(CallInfo* info, bool is_double) OVERRIDE;
158 bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE;
159 bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE;
Martyn Capewell9a8a5062014-08-07 11:31:48 +0100160 bool GenInlinedAbsInt(CallInfo* info) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100161 bool GenInlinedAbsLong(CallInfo* info) OVERRIDE;
Zheng Xu947717a2014-08-07 14:05:23 +0800162 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100163 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampec76c6142014-08-04 16:30:03 -0700164 void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700165 RegLocation rl_src2, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100166 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div)
167 OVERRIDE;
168 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div)
169 OVERRIDE;
170 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE;
171 void GenDivZeroCheckWide(RegStorage reg) OVERRIDE;
172 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
173 void GenExitSequence() OVERRIDE;
174 void GenSpecialExitSequence() OVERRIDE;
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000175 void GenSpecialEntryForSuspend() OVERRIDE;
176 void GenSpecialExitForSuspend() OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100177 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE;
178 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE;
179 void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE;
180 void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
181 int32_t true_val, int32_t false_val, RegStorage rs_dest,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700182 RegisterClass dest_reg_class) OVERRIDE;
Andreas Gampe90969af2014-07-15 23:02:11 -0700183
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100184 bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE;
185 void GenMonitorEnter(int opt_flags, RegLocation rl_src) OVERRIDE;
186 void GenMonitorExit(int opt_flags, RegLocation rl_src) OVERRIDE;
187 void GenMoveException(RegLocation rl_dest) OVERRIDE;
188 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
189 int first_bit, int second_bit) OVERRIDE;
190 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
191 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampe48971b32014-08-06 10:09:01 -0700192 void GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
193 void GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
Ningsheng Jiana262f772014-11-25 16:48:07 +0800194 void GenMaddMsubInt(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
195 RegLocation rl_src3, bool is_sub);
196 void GenMaddMsubLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
197 RegLocation rl_src3, bool is_sub);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100198
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100199 // Required for target - single operation generators.
200 LIR* OpUnconditionalBranch(LIR* target) OVERRIDE;
201 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE;
202 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE;
203 LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE;
204 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE;
205 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
206 LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE;
207 void OpEndIT(LIR* it) OVERRIDE;
208 LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE;
Vladimir Markof6737f72015-03-23 17:05:14 +0000209 void OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100210 LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE;
211 void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
212 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE;
213 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE;
214 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE;
215 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE;
216 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE;
217 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE;
218 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE;
219 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE;
220 LIR* OpTestSuspend(LIR* target) OVERRIDE;
221 LIR* OpVldm(RegStorage r_base, int count) OVERRIDE;
222 LIR* OpVstm(RegStorage r_base, int count) OVERRIDE;
223 void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE;
Andreas Gampef29ecd62014-07-29 00:35:00 -0700224
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100225 bool InexpensiveConstantInt(int32_t value) OVERRIDE;
Matteo Franchinc763e352014-07-04 12:53:27 +0100226 bool InexpensiveConstantInt(int32_t value, Instruction::Code opcode) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100227 bool InexpensiveConstantFloat(int32_t value) OVERRIDE;
228 bool InexpensiveConstantLong(int64_t value) OVERRIDE;
229 bool InexpensiveConstantDouble(int64_t value) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100230
Ningsheng Jiana262f772014-11-25 16:48:07 +0800231 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir) OVERRIDE;
232
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700233 bool WideGPRsAreAliases() const OVERRIDE {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100234 return true; // 64b architecture.
235 }
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700236 bool WideFPRsAreAliases() const OVERRIDE {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100237 return true; // 64b architecture.
238 }
Andreas Gampe98430592014-07-27 19:44:50 -0700239
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100240 size_t GetInstructionOffset(LIR* lir) OVERRIDE;
241
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100242 NextCallInsn GetNextSDCallInsn() OVERRIDE;
243
244 /*
245 * @brief Generate a relative call to the method that will be patched at link time.
246 * @param target_method The MethodReference of the method to be invoked.
247 * @param type How the method will be invoked.
248 * @returns Call instruction
249 */
250 LIR* CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
251
252 /*
253 * @brief Generate the actual call insn based on the method info.
254 * @param method_info the lowering info for the method call.
255 * @returns Call instruction
256 */
257 virtual LIR* GenCallInsn(const MirMethodLoweringInfo& method_info) OVERRIDE;
258
259 /*
260 * @brief Handle ARM specific literals.
261 */
262 void InstallLiteralPools() OVERRIDE;
263
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100264 LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE;
265
266 private:
267 /**
268 * @brief Given register xNN (dNN), returns register wNN (sNN).
269 * @param reg #RegStorage containing a Solo64 input register (e.g. @c x1 or @c d2).
270 * @return A Solo32 with the same register number as the @p reg (e.g. @c w1 or @c s2).
271 * @see As64BitReg
272 */
273 RegStorage As32BitReg(RegStorage reg) {
274 DCHECK(!reg.IsPair());
275 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
276 if (kFailOnSizeError) {
277 LOG(FATAL) << "Expected 64b register";
278 } else {
279 LOG(WARNING) << "Expected 64b register";
280 return reg;
Andreas Gampe3c12c512014-06-24 18:46:29 +0000281 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100282 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100283 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
284 reg.GetRawBits() & RegStorage::kRegTypeMask);
285 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
286 ->GetReg().GetReg(),
287 ret_val.GetReg());
288 return ret_val;
289 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100290
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100291 RegStorage Check32BitReg(RegStorage reg) {
292 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
293 if (kFailOnSizeError) {
294 LOG(FATAL) << "Checked for 32b register";
295 } else {
296 LOG(WARNING) << "Checked for 32b register";
297 return As32BitReg(reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000298 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000299 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100300 return reg;
301 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000302
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100303 /**
304 * @brief Given register wNN (sNN), returns register xNN (dNN).
305 * @param reg #RegStorage containing a Solo32 input register (e.g. @c w1 or @c s2).
306 * @return A Solo64 with the same register number as the @p reg (e.g. @c x1 or @c d2).
307 * @see As32BitReg
308 */
309 RegStorage As64BitReg(RegStorage reg) {
310 DCHECK(!reg.IsPair());
311 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
312 if (kFailOnSizeError) {
313 LOG(FATAL) << "Expected 32b register";
314 } else {
315 LOG(WARNING) << "Expected 32b register";
316 return reg;
Andreas Gampe3c12c512014-06-24 18:46:29 +0000317 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100318 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100319 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
320 reg.GetRawBits() & RegStorage::kRegTypeMask);
321 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
322 ->GetReg().GetReg(),
323 ret_val.GetReg());
324 return ret_val;
325 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100326
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100327 RegStorage Check64BitReg(RegStorage reg) {
328 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
329 if (kFailOnSizeError) {
330 LOG(FATAL) << "Checked for 64b register";
331 } else {
332 LOG(WARNING) << "Checked for 64b register";
333 return As64BitReg(reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000334 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000335 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100336 return reg;
337 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000338
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100339 int32_t EncodeImmSingle(uint32_t bits);
340 int32_t EncodeImmDouble(uint64_t bits);
341 LIR* LoadFPConstantValue(RegStorage r_dest, int32_t value);
342 LIR* LoadFPConstantValueWide(RegStorage r_dest, int64_t value);
343 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
344 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
345 void AssignDataOffsets();
346 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700347 bool is_div, int flags) OVERRIDE;
348 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100349 size_t GetLoadStoreSize(LIR* lir);
350
351 bool SmallLiteralDivRem64(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
352 RegLocation rl_dest, int64_t lit);
353
354 uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset);
355 int AssignInsnOffsets();
356 void AssignOffsets();
357 uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir);
358
359 // Spill core and FP registers. Returns the SP difference: either spill size, or whole
360 // frame size.
361 int SpillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size);
362
363 // Unspill core and FP registers.
364 void UnspillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size);
365
366 void GenLongOp(OpKind op, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
367
368 LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value);
369 LIR* OpRegRegImm64(OpKind op, RegStorage r_dest, RegStorage r_src1, int64_t value);
370
371 LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
372 LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
373 int shift);
374 int EncodeShift(int code, int amount);
375
376 LIR* OpRegRegExtend(OpKind op, RegStorage r_dest_src1, RegStorage r_src2,
377 A64RegExtEncodings ext, uint8_t amount);
378 LIR* OpRegRegRegExtend(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
379 A64RegExtEncodings ext, uint8_t amount);
380 int EncodeExtend(int extend_type, int amount);
381 bool IsExtendEncoding(int encoded_value);
382
383 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size);
384 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
385
386 int EncodeLogicalImmediate(bool is_wide, uint64_t value);
387 uint64_t DecodeLogicalImmediate(bool is_wide, int value);
388 ArmConditionCode ArmConditionEncoding(ConditionCode code);
389
390 // Helper used in the two GenSelect variants.
391 void GenSelect(int32_t left, int32_t right, ConditionCode code, RegStorage rs_dest,
392 int result_reg_class);
393
Andreas Gampec76c6142014-08-04 16:30:03 -0700394 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
395 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
396 void GenDivRemLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700397 RegLocation rl_src2, bool is_div, int flags);
Andreas Gampec76c6142014-08-04 16:30:03 -0700398
Vladimir Marko20f85592015-03-19 10:07:02 +0000399 static int Arm64NextSDCallInsn(CompilationUnit* cu, CallInfo* info,
400 int state, const MethodReference& target_method,
401 uint32_t unused_idx,
402 uintptr_t direct_code, uintptr_t direct_method,
403 InvokeType type);
404
Matteo Franchin4163c532014-07-15 15:20:27 +0100405 static const A64EncodingMap EncodingMap[kA64Last];
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100406
407 ArenaVector<LIR*> call_method_insns_;
Vladimir Marko20f85592015-03-19 10:07:02 +0000408 ArenaVector<LIR*> dex_cache_access_insns_;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600409
410 int GenDalvikArgsBulkCopy(CallInfo* info, int first, int count) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100411};
412
413} // namespace art
414
415#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_