blob: 75e24feb03f01cc7737852839f06fa1999d4fb3e [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 Constantinescued65c5e2014-05-22 15:10:18 +0100127 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
128 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100129 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
130 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
131 RegLocation rl_src2);
132 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
133 RegLocation rl_src2);
134 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
135 RegLocation rl_src2);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100136 void GenDivRemLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
137 RegLocation rl_src2, bool is_div);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100138 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
139 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
140 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
141 void GenDivZeroCheckWide(RegStorage reg);
142 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
143 void GenExitSequence();
144 void GenSpecialExitSequence();
145 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
146 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
147 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
148 void GenSelect(BasicBlock* bb, MIR* mir);
Andreas Gampeb14329f2014-05-15 11:16:06 -0700149 bool GenMemBarrier(MemBarrierKind barrier_kind);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100150 void GenMonitorEnter(int opt_flags, RegLocation rl_src);
151 void GenMonitorExit(int opt_flags, RegLocation rl_src);
152 void GenMoveException(RegLocation rl_dest);
153 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
154 int first_bit, int second_bit);
155 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
156 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
157 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
158 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100159 bool GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special);
160
161 uint32_t GenPairWise(uint32_t reg_mask, int* reg1, int* reg2);
162 void UnSpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask);
163 void SpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100164 void UnSpillFPRegs(RegStorage base, int offset, uint32_t reg_mask);
165 void SpillFPRegs(RegStorage base, int offset, uint32_t reg_mask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100166
167 // Required for target - single operation generators.
168 LIR* OpUnconditionalBranch(LIR* target);
169 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
170 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
171 LIR* OpCondBranch(ConditionCode cc, LIR* target);
172 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
173 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
174 LIR* OpIT(ConditionCode cond, const char* guide);
175 void OpEndIT(LIR* it);
176 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
177 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
178 LIR* OpReg(OpKind op, RegStorage r_dest_src);
179 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
180 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100181 LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100182 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
183 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
184 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
185 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
186 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
187 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
188 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
189 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
190 LIR* OpTestSuspend(LIR* target);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700191 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
192 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100193 LIR* OpVldm(RegStorage r_base, int count);
194 LIR* OpVstm(RegStorage r_base, int count);
195 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
196 void OpRegCopyWide(RegStorage dest, RegStorage src);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700197 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
198 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100199
Vladimir Marko3bf7c602014-05-07 14:55:43 +0100200 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100201 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100202 LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
203 int shift);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100204 LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100205 static const ArmEncodingMap EncodingMap[kA64Last];
Matteo Franchin43ec8732014-03-31 15:00:14 +0100206 int EncodeShift(int code, int amount);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100207 int EncodeExtend(int extend_type, int amount);
208 bool IsExtendEncoding(int encoded_value);
209 int EncodeLogicalImmediate(bool is_wide, uint64_t value);
210 uint64_t DecodeLogicalImmediate(bool is_wide, int value);
211
Matteo Franchin43ec8732014-03-31 15:00:14 +0100212 ArmConditionCode ArmConditionEncoding(ConditionCode code);
213 bool InexpensiveConstantInt(int32_t value);
214 bool InexpensiveConstantFloat(int32_t value);
215 bool InexpensiveConstantLong(int64_t value);
216 bool InexpensiveConstantDouble(int64_t value);
217
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100218 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
219 int LoadArgRegs(CallInfo* info, int call_state,
220 NextCallInsn next_call_insn,
221 const MethodReference& target_method,
222 uint32_t vtable_idx,
223 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
224 bool skip_this);
225
Matteo Franchin43ec8732014-03-31 15:00:14 +0100226 private:
Matteo Franchin5acc8b02014-06-05 15:10:35 +0100227 /**
228 * @brief Given register xNN (dNN), returns register wNN (sNN).
229 * @param reg #RegStorage containing a Solo64 input register (e.g. @c x1 or @c d2).
230 * @return A Solo32 with the same register number as the @p reg (e.g. @c w1 or @c s2).
231 * @see As64BitReg
232 */
233 RegStorage As32BitReg(RegStorage reg) {
234 DCHECK(reg.Is64Bit());
235 DCHECK(!reg.IsPair());
236 RegStorage ret_val = RegStorage(RegStorage::k32BitSolo,
237 reg.GetRawBits() & RegStorage::kRegTypeMask);
238 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask)
239 ->GetReg().GetReg(),
240 ret_val.GetReg());
241 return ret_val;
242 }
243
244 /**
245 * @brief Given register wNN (sNN), returns register xNN (dNN).
246 * @param reg #RegStorage containing a Solo32 input register (e.g. @c w1 or @c s2).
247 * @return A Solo64 with the same register number as the @p reg (e.g. @c x1 or @c d2).
248 * @see As32BitReg
249 */
250 RegStorage As64BitReg(RegStorage reg) {
251 DCHECK(reg.Is32Bit());
252 DCHECK(!reg.IsPair());
253 RegStorage ret_val = RegStorage(RegStorage::k64BitSolo,
254 reg.GetRawBits() & RegStorage::kRegTypeMask);
255 DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask)
256 ->GetReg().GetReg(),
257 ret_val.GetReg());
258 return ret_val;
259 }
260
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100261 LIR* LoadFPConstantValue(int r_dest, int32_t value);
262 LIR* LoadFPConstantValueWide(int r_dest, int64_t value);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100263 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
264 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
265 void AssignDataOffsets();
266 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
267 bool is_div, bool check_zero);
268 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100269};
270
271} // namespace art
272
273#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_