blob: 5182a89474d2a499678c2e13c8bcf7a857e76f7a [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:
30 // TODO: consolidate 64-bit target support.
31 class InToRegStorageMapper {
32 public:
Zheng Xu949cd972014-06-23 18:33:08 +080033 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref) = 0;
buzbee33ae5582014-06-12 14:56:32 -070034 virtual ~InToRegStorageMapper() {}
35 };
36
37 class InToRegStorageArm64Mapper : public InToRegStorageMapper {
38 public:
39 InToRegStorageArm64Mapper() : cur_core_reg_(0), cur_fp_reg_(0) {}
40 virtual ~InToRegStorageArm64Mapper() {}
Zheng Xu949cd972014-06-23 18:33:08 +080041 virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref);
buzbee33ae5582014-06-12 14:56:32 -070042 private:
43 int cur_core_reg_;
44 int cur_fp_reg_;
45 };
46
47 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 };
62
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010063 public:
64 Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
Matteo Franchin43ec8732014-03-31 15:00:14 +010065
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010066 // Required for target - codegen helpers.
67 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
68 RegLocation rl_dest, int lit) OVERRIDE;
69 bool HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div,
70 RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
71 bool HandleEasyDivRem64(Instruction::Code dalvik_opcode, bool is_div,
72 RegLocation rl_src, RegLocation rl_dest, int64_t lit);
73 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
Ningsheng Jian675e09b2014-10-23 13:48:36 +080074 void GenMultiplyByConstantFloat(RegLocation rl_dest, RegLocation rl_src1,
75 int32_t constant) OVERRIDE;
76 void GenMultiplyByConstantDouble(RegLocation rl_dest, RegLocation rl_src1,
77 int64_t constant) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010078 LIR* CheckSuspendUsingLoad() OVERRIDE;
79 RegStorage LoadHelper(QuickEntrypointEnum trampoline) OVERRIDE;
80 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
81 OpSize size, VolatileKind is_volatile) OVERRIDE;
82 LIR* LoadRefDisp(RegStorage r_base, int displacement, RegStorage r_dest,
83 VolatileKind is_volatile) OVERRIDE;
84 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
85 OpSize size) OVERRIDE;
86 LIR* LoadRefIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale)
87 OVERRIDE;
88 LIR* LoadConstantNoClobber(RegStorage r_dest, int value) OVERRIDE;
89 LIR* LoadConstantWide(RegStorage r_dest, int64_t value) OVERRIDE;
90 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size,
91 VolatileKind is_volatile) OVERRIDE;
92 LIR* StoreRefDisp(RegStorage r_base, int displacement, RegStorage r_src, VolatileKind is_volatile)
93 OVERRIDE;
94 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
95 OpSize size) OVERRIDE;
96 LIR* StoreRefIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale) OVERRIDE;
97 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg) OVERRIDE;
98 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg,
99 int offset, int check_value, LIR* target, LIR** compare) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100100
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100101 // Required for target - register utilities.
102 RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE;
103 RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE {
104 if (wide_kind == kWide || wide_kind == kRef) {
Matteo Franchined7a0f22014-06-10 19:23:45 +0100105 return As64BitReg(TargetReg(symbolic_reg));
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100106 } else {
107 return Check32BitReg(TargetReg(symbolic_reg));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700108 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100109 }
110 RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE {
111 return As64BitReg(TargetReg(symbolic_reg));
112 }
113 RegStorage GetArgMappingToPhysicalReg(int arg_num) OVERRIDE;
114 RegLocation GetReturnAlt() OVERRIDE;
115 RegLocation GetReturnWideAlt() OVERRIDE;
116 RegLocation LocCReturn() OVERRIDE;
117 RegLocation LocCReturnRef() OVERRIDE;
118 RegLocation LocCReturnDouble() OVERRIDE;
119 RegLocation LocCReturnFloat() OVERRIDE;
120 RegLocation LocCReturnWide() OVERRIDE;
121 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
122 void AdjustSpillMask() OVERRIDE;
123 void ClobberCallerSave() OVERRIDE;
124 void FreeCallTemps() OVERRIDE;
125 void LockCallTemps() OVERRIDE;
126 void CompilerInitializeRegAlloc() OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100127
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100128 // Required for target - miscellaneous.
129 void AssembleLIR() OVERRIDE;
130 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
131 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
132 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
133 const char* GetTargetInstFmt(int opcode) OVERRIDE;
134 const char* GetTargetInstName(int opcode) OVERRIDE;
135 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE;
136 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
137 uint64_t GetTargetInstFlags(int opcode) OVERRIDE;
138 size_t GetInsnSize(LIR* lir) OVERRIDE;
139 bool IsUnconditionalBranch(LIR* lir) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100140
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100141 // Get the register class for load/store of a field.
142 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +0100143
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100144 // Required for target - Dalvik-level generators.
145 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
146 RegLocation lr_shift) OVERRIDE;
147 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700148 RegLocation rl_src2, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100149 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
150 RegLocation rl_dest, int scale) OVERRIDE;
151 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
152 RegLocation rl_src, int scale, bool card_mark) OVERRIDE;
153 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700154 RegLocation rl_shift, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100155 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
156 RegLocation rl_src2) OVERRIDE;
157 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
158 RegLocation rl_src2) OVERRIDE;
159 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
160 RegLocation rl_src2) OVERRIDE;
161 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
162 bool GenInlinedReverseBits(CallInfo* info, OpSize size) OVERRIDE;
163 bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE;
164 bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE;
165 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE;
166 bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE;
167 bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE;
168 bool GenInlinedSqrt(CallInfo* info) OVERRIDE;
169 bool GenInlinedCeil(CallInfo* info) OVERRIDE;
170 bool GenInlinedFloor(CallInfo* info) OVERRIDE;
171 bool GenInlinedRint(CallInfo* info) OVERRIDE;
172 bool GenInlinedRound(CallInfo* info, bool is_double) OVERRIDE;
173 bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE;
174 bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE;
Martyn Capewell9a8a5062014-08-07 11:31:48 +0100175 bool GenInlinedAbsInt(CallInfo* info) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100176 bool GenInlinedAbsLong(CallInfo* info) OVERRIDE;
Zheng Xu947717a2014-08-07 14:05:23 +0800177 bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100178 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampec76c6142014-08-04 16:30:03 -0700179 void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700180 RegLocation rl_src2, int flags) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100181 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div)
182 OVERRIDE;
183 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div)
184 OVERRIDE;
185 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE;
186 void GenDivZeroCheckWide(RegStorage reg) OVERRIDE;
187 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
188 void GenExitSequence() OVERRIDE;
189 void GenSpecialExitSequence() OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100190 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE;
191 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE;
192 void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE;
193 void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
194 int32_t true_val, int32_t false_val, RegStorage rs_dest,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700195 RegisterClass dest_reg_class) OVERRIDE;
Andreas Gampe90969af2014-07-15 23:02:11 -0700196
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100197 bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE;
198 void GenMonitorEnter(int opt_flags, RegLocation rl_src) OVERRIDE;
199 void GenMonitorExit(int opt_flags, RegLocation rl_src) OVERRIDE;
200 void GenMoveException(RegLocation rl_dest) OVERRIDE;
201 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
202 int first_bit, int second_bit) OVERRIDE;
203 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
204 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE;
Andreas Gampe48971b32014-08-06 10:09:01 -0700205 void GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
206 void GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100207
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100208 // Required for target - single operation generators.
209 LIR* OpUnconditionalBranch(LIR* target) OVERRIDE;
210 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE;
211 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE;
212 LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE;
213 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE;
214 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
215 LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE;
216 void OpEndIT(LIR* it) OVERRIDE;
217 LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE;
218 LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE;
219 LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE;
220 void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE;
221 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE;
222 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE;
223 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE;
224 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE;
225 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE;
226 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE;
227 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE;
228 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE;
229 LIR* OpTestSuspend(LIR* target) OVERRIDE;
230 LIR* OpVldm(RegStorage r_base, int count) OVERRIDE;
231 LIR* OpVstm(RegStorage r_base, int count) OVERRIDE;
232 void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE;
Andreas Gampef29ecd62014-07-29 00:35:00 -0700233
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100234 bool InexpensiveConstantInt(int32_t value) OVERRIDE;
Matteo Franchinc763e352014-07-04 12:53:27 +0100235 bool InexpensiveConstantInt(int32_t value, Instruction::Code opcode) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100236 bool InexpensiveConstantFloat(int32_t value) OVERRIDE;
237 bool InexpensiveConstantLong(int64_t value) OVERRIDE;
238 bool InexpensiveConstantDouble(int64_t value) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100239
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100240 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100241
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100242 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
buzbee33ae5582014-06-12 14:56:32 -0700243 NextCallInsn next_call_insn,
244 const MethodReference& target_method,
245 uint32_t vtable_idx,
246 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100247 bool skip_this) OVERRIDE;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100248
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100249 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
250 NextCallInsn next_call_insn,
251 const MethodReference& target_method,
252 uint32_t vtable_idx,
253 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
254 bool skip_this) OVERRIDE;
Serguei Katkov59a42af2014-07-05 00:55:46 +0700255
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700256 bool WideGPRsAreAliases() const OVERRIDE {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100257 return true; // 64b architecture.
258 }
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700259 bool WideFPRsAreAliases() const OVERRIDE {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100260 return true; // 64b architecture.
261 }
Andreas Gampe98430592014-07-27 19:44:50 -0700262
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100263 size_t GetInstructionOffset(LIR* lir) OVERRIDE;
264
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100265 NextCallInsn GetNextSDCallInsn() OVERRIDE;
266
267 /*
268 * @brief Generate a relative call to the method that will be patched at link time.
269 * @param target_method The MethodReference of the method to be invoked.
270 * @param type How the method will be invoked.
271 * @returns Call instruction
272 */
273 LIR* CallWithLinkerFixup(const MethodReference& target_method, InvokeType type);
274
275 /*
276 * @brief Generate the actual call insn based on the method info.
277 * @param method_info the lowering info for the method call.
278 * @returns Call instruction
279 */
280 virtual LIR* GenCallInsn(const MirMethodLoweringInfo& method_info) OVERRIDE;
281
282 /*
283 * @brief Handle ARM specific literals.
284 */
285 void InstallLiteralPools() OVERRIDE;
286
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100287 LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE;
288
289 private:
290 /**
291 * @brief Given register xNN (dNN), returns register wNN (sNN).
292 * @param reg #RegStorage containing a Solo64 input register (e.g. @c x1 or @c d2).
293 * @return A Solo32 with the same register number as the @p reg (e.g. @c w1 or @c s2).
294 * @see As64BitReg
295 */
296 RegStorage As32BitReg(RegStorage reg) {
297 DCHECK(!reg.IsPair());
298 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
299 if (kFailOnSizeError) {
300 LOG(FATAL) << "Expected 64b register";
301 } else {
302 LOG(WARNING) << "Expected 64b register";
303 return reg;
Andreas Gampe3c12c512014-06-24 18:46:29 +0000304 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100305 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100306 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
307 reg.GetRawBits() & RegStorage::kRegTypeMask);
308 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
309 ->GetReg().GetReg(),
310 ret_val.GetReg());
311 return ret_val;
312 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100313
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100314 RegStorage Check32BitReg(RegStorage reg) {
315 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
316 if (kFailOnSizeError) {
317 LOG(FATAL) << "Checked for 32b register";
318 } else {
319 LOG(WARNING) << "Checked for 32b register";
320 return As32BitReg(reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000321 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000322 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100323 return reg;
324 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000325
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100326 /**
327 * @brief Given register wNN (sNN), returns register xNN (dNN).
328 * @param reg #RegStorage containing a Solo32 input register (e.g. @c w1 or @c s2).
329 * @return A Solo64 with the same register number as the @p reg (e.g. @c x1 or @c d2).
330 * @see As32BitReg
331 */
332 RegStorage As64BitReg(RegStorage reg) {
333 DCHECK(!reg.IsPair());
334 if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) {
335 if (kFailOnSizeError) {
336 LOG(FATAL) << "Expected 32b register";
337 } else {
338 LOG(WARNING) << "Expected 32b register";
339 return reg;
Andreas Gampe3c12c512014-06-24 18:46:29 +0000340 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100341 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100342 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
343 reg.GetRawBits() & RegStorage::kRegTypeMask);
344 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
345 ->GetReg().GetReg(),
346 ret_val.GetReg());
347 return ret_val;
348 }
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100349
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100350 RegStorage Check64BitReg(RegStorage reg) {
351 if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) {
352 if (kFailOnSizeError) {
353 LOG(FATAL) << "Checked for 64b register";
354 } else {
355 LOG(WARNING) << "Checked for 64b register";
356 return As64BitReg(reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000357 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000358 }
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100359 return reg;
360 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000361
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100362 int32_t EncodeImmSingle(uint32_t bits);
363 int32_t EncodeImmDouble(uint64_t bits);
364 LIR* LoadFPConstantValue(RegStorage r_dest, int32_t value);
365 LIR* LoadFPConstantValueWide(RegStorage r_dest, int64_t value);
366 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
367 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
368 void AssignDataOffsets();
369 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700370 bool is_div, int flags) OVERRIDE;
371 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div) OVERRIDE;
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100372 size_t GetLoadStoreSize(LIR* lir);
373
374 bool SmallLiteralDivRem64(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
375 RegLocation rl_dest, int64_t lit);
376
377 uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset);
378 int AssignInsnOffsets();
379 void AssignOffsets();
380 uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir);
381
382 // Spill core and FP registers. Returns the SP difference: either spill size, or whole
383 // frame size.
384 int SpillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size);
385
386 // Unspill core and FP registers.
387 void UnspillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size);
388
389 void GenLongOp(OpKind op, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
390
391 LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value);
392 LIR* OpRegRegImm64(OpKind op, RegStorage r_dest, RegStorage r_src1, int64_t value);
393
394 LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
395 LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
396 int shift);
397 int EncodeShift(int code, int amount);
398
399 LIR* OpRegRegExtend(OpKind op, RegStorage r_dest_src1, RegStorage r_src2,
400 A64RegExtEncodings ext, uint8_t amount);
401 LIR* OpRegRegRegExtend(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
402 A64RegExtEncodings ext, uint8_t amount);
403 int EncodeExtend(int extend_type, int amount);
404 bool IsExtendEncoding(int encoded_value);
405
406 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size);
407 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
408
409 int EncodeLogicalImmediate(bool is_wide, uint64_t value);
410 uint64_t DecodeLogicalImmediate(bool is_wide, int value);
411 ArmConditionCode ArmConditionEncoding(ConditionCode code);
412
413 // Helper used in the two GenSelect variants.
414 void GenSelect(int32_t left, int32_t right, ConditionCode code, RegStorage rs_dest,
415 int result_reg_class);
416
Andreas Gampec76c6142014-08-04 16:30:03 -0700417 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
418 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
419 void GenDivRemLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -0700420 RegLocation rl_src2, bool is_div, int flags);
Andreas Gampec76c6142014-08-04 16:30:03 -0700421
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100422 InToRegStorageMapping in_to_reg_storage_mapping_;
Matteo Franchin4163c532014-07-15 15:20:27 +0100423 static const A64EncodingMap EncodingMap[kA64Last];
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100424
425 ArenaVector<LIR*> call_method_insns_;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100426};
427
428} // namespace art
429
430#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_