blob: bf09b8610e99e82a2eb5f06661473aa459a57d98 [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"
22
23namespace art {
24
Matteo Franchine45fb9e2014-05-06 10:10:30 +010025class Arm64Mir2Lir : public Mir2Lir {
Matteo Franchin43ec8732014-03-31 15:00:14 +010026 public:
27 Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
28
29 // Required for target - codegen helpers.
30 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
31 RegLocation rl_dest, int lit);
32 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE;
33 LIR* CheckSuspendUsingLoad() OVERRIDE;
Andreas Gampe2f244e92014-05-08 03:35:25 -070034 RegStorage LoadHelper(ThreadOffset<4> offset) OVERRIDE;
35 RegStorage LoadHelper(ThreadOffset<8> offset) OVERRIDE;
Vladimir Marko674744e2014-04-24 15:18:26 +010036 LIR* LoadBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest,
37 OpSize size) OVERRIDE;
Vladimir Marko3bf7c602014-05-07 14:55:43 +010038 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest,
39 OpSize size) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010040 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010041 OpSize size) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010042 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010043 RegStorage r_dest, OpSize size) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010044 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
45 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
Vladimir Marko674744e2014-04-24 15:18:26 +010046 LIR* StoreBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest,
47 OpSize size) OVERRIDE;
Vladimir Marko3bf7c602014-05-07 14:55:43 +010048 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src,
49 OpSize size) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010050 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010051 OpSize size) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010052 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
Vladimir Marko3bf7c602014-05-07 14:55:43 +010053 RegStorage r_src, OpSize size) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010054 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg);
55
56 // Required for target - register utilities.
Matteo Franchin43ec8732014-03-31 15:00:14 +010057 RegStorage TargetReg(SpecialTargetRegister reg);
58 RegStorage GetArgMappingToPhysicalReg(int arg_num);
59 RegLocation GetReturnAlt();
60 RegLocation GetReturnWideAlt();
61 RegLocation LocCReturn();
buzbeea0cd2d72014-06-01 09:33:49 -070062 RegLocation LocCReturnRef();
Matteo Franchin43ec8732014-03-31 15:00:14 +010063 RegLocation LocCReturnDouble();
64 RegLocation LocCReturnFloat();
65 RegLocation LocCReturnWide();
Vladimir Marko8dea81c2014-06-06 14:50:36 +010066 ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010067 void AdjustSpillMask();
68 void ClobberCallerSave();
69 void FreeCallTemps();
Matteo Franchin43ec8732014-03-31 15:00:14 +010070 void LockCallTemps();
71 void MarkPreservedSingle(int v_reg, RegStorage reg);
72 void MarkPreservedDouble(int v_reg, RegStorage reg);
73 void CompilerInitializeRegAlloc();
Matteo Franchin43ec8732014-03-31 15:00:14 +010074
75 // Required for target - miscellaneous.
76 void AssembleLIR();
77 uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset);
78 int AssignInsnOffsets();
79 void AssignOffsets();
Matteo Franchine45fb9e2014-05-06 10:10:30 +010080 uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir);
Vladimir Marko8dea81c2014-06-06 14:50:36 +010081 void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE;
82 void SetupTargetResourceMasks(LIR* lir, uint64_t flags,
83 ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010084 const char* GetTargetInstFmt(int opcode);
85 const char* GetTargetInstName(int opcode);
86 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
Vladimir Marko8dea81c2014-06-06 14:50:36 +010087 ResourceMask GetPCUseDefEncoding() const OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +010088 uint64_t GetTargetInstFlags(int opcode);
89 int GetInsnSize(LIR* lir);
90 bool IsUnconditionalBranch(LIR* lir);
91
Vladimir Marko674744e2014-04-24 15:18:26 +010092 // Check support for volatile load/store of a given size.
93 bool SupportsVolatileLoadStore(OpSize size) OVERRIDE;
94 // Get the register class for load/store of a field.
95 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
96
Matteo Franchin43ec8732014-03-31 15:00:14 +010097 // Required for target - Dalvik-level generators.
Serban Constantinescued65c5e2014-05-22 15:10:18 +010098 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
99 RegLocation lr_shift);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100100 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
101 RegLocation rl_src1, RegLocation rl_src2);
102 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
103 RegLocation rl_index, RegLocation rl_dest, int scale);
104 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
105 RegLocation rl_src, int scale, bool card_mark);
106 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
107 RegLocation rl_src1, RegLocation rl_shift);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100108 void GenLongOp(OpKind op, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100109 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
110 RegLocation rl_src2);
111 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
112 RegLocation rl_src2);
113 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
114 RegLocation rl_src2);
115 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
116 RegLocation rl_src2);
117 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
118 RegLocation rl_src2);
119 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
120 RegLocation rl_src2);
121 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
122 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
123 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
124 bool GenInlinedSqrt(CallInfo* info);
125 bool GenInlinedPeek(CallInfo* info, OpSize size);
126 bool GenInlinedPoke(CallInfo* info, OpSize size);
Serban Constantinescu169489b2014-06-11 16:43:35 +0100127 bool GenInlinedAbsLong(CallInfo* info);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100128 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
129 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100130 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
131 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
132 RegLocation rl_src2);
133 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
134 RegLocation rl_src2);
135 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
136 RegLocation rl_src2);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100137 void GenDivRemLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
138 RegLocation rl_src2, bool is_div);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100139 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
140 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
141 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
142 void GenDivZeroCheckWide(RegStorage reg);
143 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
144 void GenExitSequence();
145 void GenSpecialExitSequence();
146 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
147 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
148 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
149 void GenSelect(BasicBlock* bb, MIR* mir);
Andreas Gampeb14329f2014-05-15 11:16:06 -0700150 bool GenMemBarrier(MemBarrierKind barrier_kind);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100151 void GenMonitorEnter(int opt_flags, RegLocation rl_src);
152 void GenMonitorExit(int opt_flags, RegLocation rl_src);
153 void GenMoveException(RegLocation rl_dest);
154 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
155 int first_bit, int second_bit);
156 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
157 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
158 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
159 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100160 bool GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special);
161
162 uint32_t GenPairWise(uint32_t reg_mask, int* reg1, int* reg2);
163 void UnSpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask);
164 void SpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100165 void UnSpillFPRegs(RegStorage base, int offset, uint32_t reg_mask);
166 void SpillFPRegs(RegStorage base, int offset, uint32_t reg_mask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100167
168 // Required for target - single operation generators.
169 LIR* OpUnconditionalBranch(LIR* target);
170 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
171 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
172 LIR* OpCondBranch(ConditionCode cc, LIR* target);
173 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
174 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
175 LIR* OpIT(ConditionCode cond, const char* guide);
176 void OpEndIT(LIR* it);
177 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
178 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
179 LIR* OpReg(OpKind op, RegStorage r_dest_src);
180 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
181 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100182 LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100183 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
184 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
185 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
186 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
187 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
188 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
Zheng Xue2eb29e2014-06-12 10:22:33 +0800189 LIR* OpRegRegImm64(OpKind op, RegStorage r_dest, RegStorage r_src1, int64_t value);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100190 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
191 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
192 LIR* OpTestSuspend(LIR* target);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700193 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
194 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100195 LIR* OpVldm(RegStorage r_base, int count);
196 LIR* OpVstm(RegStorage r_base, int count);
197 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
198 void OpRegCopyWide(RegStorage dest, RegStorage src);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700199 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
200 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100201
Vladimir Marko3bf7c602014-05-07 14:55:43 +0100202 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100203 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100204 LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
205 int shift);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100206 LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
Stuart Monteithf8ec48e2014-06-06 17:05:08 +0100207 LIR* OpRegRegExtend(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100208 static const ArmEncodingMap EncodingMap[kA64Last];
Matteo Franchin43ec8732014-03-31 15:00:14 +0100209 int EncodeShift(int code, int amount);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100210 int EncodeExtend(int extend_type, int amount);
211 bool IsExtendEncoding(int encoded_value);
212 int EncodeLogicalImmediate(bool is_wide, uint64_t value);
213 uint64_t DecodeLogicalImmediate(bool is_wide, int value);
214
Matteo Franchin43ec8732014-03-31 15:00:14 +0100215 ArmConditionCode ArmConditionEncoding(ConditionCode code);
216 bool InexpensiveConstantInt(int32_t value);
217 bool InexpensiveConstantFloat(int32_t value);
218 bool InexpensiveConstantLong(int64_t value);
219 bool InexpensiveConstantDouble(int64_t value);
220
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100221 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
222 int LoadArgRegs(CallInfo* info, int call_state,
223 NextCallInsn next_call_insn,
224 const MethodReference& target_method,
225 uint32_t vtable_idx,
226 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
227 bool skip_this);
228
Matteo Franchin43ec8732014-03-31 15:00:14 +0100229 private:
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100230 /**
231 * @brief Given register xNN (dNN), returns register wNN (sNN).
232 * @param reg #RegStorage containing a Solo64 input register (e.g. @c x1 or @c d2).
233 * @return A Solo32 with the same register number as the @p reg (e.g. @c w1 or @c s2).
234 * @see As64BitReg
235 */
236 RegStorage As32BitReg(RegStorage reg) {
237 DCHECK(reg.Is64Bit());
238 DCHECK(!reg.IsPair());
239 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
240 reg.GetRawBits() & RegStorage::kRegTypeMask);
241 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
242 ->GetReg().GetReg(),
243 ret_val.GetReg());
244 return ret_val;
245 }
246
247 /**
248 * @brief Given register wNN (sNN), returns register xNN (dNN).
249 * @param reg #RegStorage containing a Solo32 input register (e.g. @c w1 or @c s2).
250 * @return A Solo64 with the same register number as the @p reg (e.g. @c x1 or @c d2).
251 * @see As32BitReg
252 */
253 RegStorage As64BitReg(RegStorage reg) {
254 DCHECK(reg.Is32Bit());
255 DCHECK(!reg.IsPair());
256 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
257 reg.GetRawBits() & RegStorage::kRegTypeMask);
258 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
259 ->GetReg().GetReg(),
260 ret_val.GetReg());
261 return ret_val;
262 }
263
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100264 LIR* LoadFPConstantValue(int r_dest, int32_t value);
265 LIR* LoadFPConstantValueWide(int r_dest, int64_t value);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100266 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
267 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
268 void AssignDataOffsets();
269 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
270 bool is_div, bool check_zero);
271 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100272};
273
274} // namespace art
275
276#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_