blob: d5f05366914aad622dc898f1ca99c9100c5e4600 [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
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010081 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
82 int offset, int check_value, LIR* target, LIR** compare) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010083
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010084 // Required for target - register utilities.
85 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
86 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
87 if (wide_kind == kWide || wide_kind == kRef) {
Matteo Franchined7a0f22014-06-10 19:23:45 +010088 return As64BitReg(TargetReg(symbolic_reg));
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010089 } else {
90 return Check32BitReg(TargetReg(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -070091 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010092 }
93 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
94 return As64BitReg(TargetReg(symbolic_reg));
95 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010096 RegLocation GetReturnAlt() OVERRIDE;
97 RegLocation GetReturnWideAlt() OVERRIDE;
98 RegLocation LocCReturn() OVERRIDE;
99 RegLocation LocCReturnRef() OVERRIDE;
100 RegLocation LocCReturnDouble() OVERRIDE;
101 RegLocation LocCReturnFloat() OVERRIDE;
102 RegLocation LocCReturnWide() OVERRIDE;
103 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
104 void AdjustSpillMask() OVERRIDE;
105 void ClobberCallerSave() OVERRIDE;
106 void FreeCallTemps() OVERRIDE;
107 void LockCallTemps() OVERRIDE;
108 void CompilerInitializeRegAlloc() OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100109
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100110 // Required for target - miscellaneous.
111 void AssembleLIR() OVERRIDE;
112 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
113 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
114 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
115 const char* GetTargetInstFmt(int opcode) OVERRIDE;
116 const char* GetTargetInstName(int opcode) OVERRIDE;
117 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE;
118 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
119 uint64_t GetTargetInstFlags(int opcode) OVERRIDE;
120 size_t GetInsnSize(LIR* lir) OVERRIDE;
121 bool IsUnconditionalBranch(LIR* lir) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100122
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100123 // Get the register class for load/store of a field.
124 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100125
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100126 // Required for target - Dalvik-level generators.
127 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
128 RegLocation lr_shift) OVERRIDE;
129 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700130 RegLocation rl_src2, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100131 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
132 RegLocation rl_dest, int scale) OVERRIDE;
133 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
134 RegLocation rl_src, int scale, bool card_mark) OVERRIDE;
135 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700136 RegLocation rl_shift, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100137 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
138 RegLocation rl_src2) OVERRIDE;
139 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
140 RegLocation rl_src2) OVERRIDE;
141 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
142 RegLocation rl_src2) OVERRIDE;
143 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
144 bool GenInlinedReverseBits(CallInfo* info, OpSize size) OVERRIDE;
145 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
146 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
147 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE;
148 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE;
149 bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE;
150 bool GenInlinedSqrt(CallInfo* info) OVERRIDE;
151 bool GenInlinedCeil(CallInfo* info) OVERRIDE;
152 bool GenInlinedFloor(CallInfo* info) OVERRIDE;
153 bool GenInlinedRint(CallInfo* info) OVERRIDE;
154 bool GenInlinedRound(CallInfo* info, bool is_double) OVERRIDE;
155 bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE;
156 bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE;
Martyn Capewell9a8a5062014-08-07 11:31:48 +0100157 bool GenInlinedAbsInt(CallInfo* info) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100158 bool GenInlinedAbsLong(CallInfo* info) OVERRIDE;
Zheng Xu947717a2014-08-07 14:05:23 +0800159 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100160 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampec76c6142014-08-04 16:30:03 -0700161 void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700162 RegLocation rl_src2, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100163 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div)
164 OVERRIDE;
165 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div)
166 OVERRIDE;
167 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE;
168 void GenDivZeroCheckWide(RegStorage reg) OVERRIDE;
169 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
170 void GenExitSequence() OVERRIDE;
171 void GenSpecialExitSequence() OVERRIDE;
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000172 void GenSpecialEntryForSuspend() OVERRIDE;
173 void GenSpecialExitForSuspend() OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100174 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE;
175 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE;
176 void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE;
177 void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
178 int32_t true_val, int32_t false_val, RegStorage rs_dest,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700179 RegisterClass dest_reg_class) OVERRIDE;
Andreas Gampe90969af2014-07-15 23:02:11 -0700180
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100181 bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE;
182 void GenMonitorEnter(int opt_flags, RegLocation rl_src) OVERRIDE;
183 void GenMonitorExit(int opt_flags, RegLocation rl_src) OVERRIDE;
184 void GenMoveException(RegLocation rl_dest) OVERRIDE;
185 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
186 int first_bit, int second_bit) OVERRIDE;
187 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
188 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampe48971b32014-08-06 10:09:01 -0700189 void GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
190 void GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
Ningsheng Jiana262f772014-11-25 16:48:07 +0800191 void GenMaddMsubInt(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
192 RegLocation rl_src3, bool is_sub);
193 void GenMaddMsubLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
194 RegLocation rl_src3, bool is_sub);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100195
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100196 // Required for target - single operation generators.
197 LIR* OpUnconditionalBranch(LIR* target) OVERRIDE;
198 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE;
199 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE;
200 LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE;
201 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE;
202 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
203 LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE;
204 void OpEndIT(LIR* it) OVERRIDE;
205 LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE;
206 LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE;
207 LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE;
208 void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
209 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE;
210 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE;
211 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE;
212 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE;
213 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE;
214 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE;
215 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE;
216 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE;
217 LIR* OpTestSuspend(LIR* target) OVERRIDE;
218 LIR* OpVldm(RegStorage r_base, int count) OVERRIDE;
219 LIR* OpVstm(RegStorage r_base, int count) OVERRIDE;
220 void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE;
Andreas Gampef29ecd62014-07-29 00:35:00 -0700221
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100222 bool InexpensiveConstantInt(int32_t value) OVERRIDE;
Matteo Franchinc763e352014-07-04 12:53:27 +0100223 bool InexpensiveConstantInt(int32_t value, Instruction::Code opcode) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100224 bool InexpensiveConstantFloat(int32_t value) OVERRIDE;
225 bool InexpensiveConstantLong(int64_t value) OVERRIDE;
226 bool InexpensiveConstantDouble(int64_t value) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100227
Ningsheng Jiana262f772014-11-25 16:48:07 +0800228 void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir) OVERRIDE;
229
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700230 bool WideGPRsAreAliases() const OVERRIDE {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100231 return true; // 64b architecture.
232 }
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700233 bool WideFPRsAreAliases() const OVERRIDE {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100234 return true; // 64b architecture.
235 }
Andreas Gampe98430592014-07-27 19:44:50 -0700236
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100237 size_t GetInstructionOffset(LIR* lir) OVERRIDE;
238
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100239 NextCallInsn GetNextSDCallInsn() OVERRIDE;
240
241 /*
242 * @brief Generate a relative call to the method that will be patched at link time.
243 * @param target_method The MethodReference of the method to be invoked.
244 * @param type How the method will be invoked.
245 * @returns Call instruction
246 */
247 LIR* CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
248
249 /*
250 * @brief Generate the actual call insn based on the method info.
251 * @param method_info the lowering info for the method call.
252 * @returns Call instruction
253 */
254 virtual LIR* GenCallInsn(const MirMethodLoweringInfo& method_info) OVERRIDE;
255
256 /*
257 * @brief Handle ARM specific literals.
258 */
259 void InstallLiteralPools() OVERRIDE;
260
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100261 LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE;
262
263 private:
264 /**
265 * @brief Given register xNN (dNN), returns register wNN (sNN).
266 * @param reg #RegStorage containing a Solo64 input register (e.g. @c x1 or @c d2).
267 * @return A Solo32 with the same register number as the @p reg (e.g. @c w1 or @c s2).
268 * @see As64BitReg
269 */
270 RegStorage As32BitReg(RegStorage reg) {
271 DCHECK(!reg.IsPair());
272 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
273 if (kFailOnSizeError) {
274 LOG(FATAL) << "Expected 64b register";
275 } else {
276 LOG(WARNING) << "Expected 64b register";
277 return reg;
Andreas Gampe3c12c512014-06-24 18:46:29 +0000278 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100279 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100280 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
281 reg.GetRawBits() & RegStorage::kRegTypeMask);
282 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
283 ->GetReg().GetReg(),
284 ret_val.GetReg());
285 return ret_val;
286 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100287
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100288 RegStorage Check32BitReg(RegStorage reg) {
289 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
290 if (kFailOnSizeError) {
291 LOG(FATAL) << "Checked for 32b register";
292 } else {
293 LOG(WARNING) << "Checked for 32b register";
294 return As32BitReg(reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000295 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000296 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100297 return reg;
298 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000299
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100300 /**
301 * @brief Given register wNN (sNN), returns register xNN (dNN).
302 * @param reg #RegStorage containing a Solo32 input register (e.g. @c w1 or @c s2).
303 * @return A Solo64 with the same register number as the @p reg (e.g. @c x1 or @c d2).
304 * @see As32BitReg
305 */
306 RegStorage As64BitReg(RegStorage reg) {
307 DCHECK(!reg.IsPair());
308 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
309 if (kFailOnSizeError) {
310 LOG(FATAL) << "Expected 32b register";
311 } else {
312 LOG(WARNING) << "Expected 32b register";
313 return reg;
Andreas Gampe3c12c512014-06-24 18:46:29 +0000314 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100315 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100316 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
317 reg.GetRawBits() & RegStorage::kRegTypeMask);
318 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
319 ->GetReg().GetReg(),
320 ret_val.GetReg());
321 return ret_val;
322 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100323
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100324 RegStorage Check64BitReg(RegStorage reg) {
325 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
326 if (kFailOnSizeError) {
327 LOG(FATAL) << "Checked for 64b register";
328 } else {
329 LOG(WARNING) << "Checked for 64b register";
330 return As64BitReg(reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000331 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000332 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100333 return reg;
334 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000335
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100336 int32_t EncodeImmSingle(uint32_t bits);
337 int32_t EncodeImmDouble(uint64_t bits);
338 LIR* LoadFPConstantValue(RegStorage r_dest, int32_t value);
339 LIR* LoadFPConstantValueWide(RegStorage r_dest, int64_t value);
340 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
341 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
342 void AssignDataOffsets();
343 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700344 bool is_div, int flags) OVERRIDE;
345 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100346 size_t GetLoadStoreSize(LIR* lir);
347
348 bool SmallLiteralDivRem64(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
349 RegLocation rl_dest, int64_t lit);
350
351 uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset);
352 int AssignInsnOffsets();
353 void AssignOffsets();
354 uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir);
355
356 // Spill core and FP registers. Returns the SP difference: either spill size, or whole
357 // frame size.
358 int SpillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size);
359
360 // Unspill core and FP registers.
361 void UnspillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size);
362
363 void GenLongOp(OpKind op, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
364
365 LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value);
366 LIR* OpRegRegImm64(OpKind op, RegStorage r_dest, RegStorage r_src1, int64_t value);
367
368 LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
369 LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
370 int shift);
371 int EncodeShift(int code, int amount);
372
373 LIR* OpRegRegExtend(OpKind op, RegStorage r_dest_src1, RegStorage r_src2,
374 A64RegExtEncodings ext, uint8_t amount);
375 LIR* OpRegRegRegExtend(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
376 A64RegExtEncodings ext, uint8_t amount);
377 int EncodeExtend(int extend_type, int amount);
378 bool IsExtendEncoding(int encoded_value);
379
380 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size);
381 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
382
383 int EncodeLogicalImmediate(bool is_wide, uint64_t value);
384 uint64_t DecodeLogicalImmediate(bool is_wide, int value);
385 ArmConditionCode ArmConditionEncoding(ConditionCode code);
386
387 // Helper used in the two GenSelect variants.
388 void GenSelect(int32_t left, int32_t right, ConditionCode code, RegStorage rs_dest,
389 int result_reg_class);
390
Andreas Gampec76c6142014-08-04 16:30:03 -0700391 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
392 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
393 void GenDivRemLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700394 RegLocation rl_src2, bool is_div, int flags);
Andreas Gampec76c6142014-08-04 16:30:03 -0700395
Matteo Franchin4163c532014-07-15 15:20:27 +0100396 static const A64EncodingMap EncodingMap[kA64Last];
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100397
398 ArenaVector<LIR*> call_method_insns_;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600399
400 int GenDalvikArgsBulkCopy(CallInfo* info, int first, int count) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100401};
402
403} // namespace art
404
405#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_