blob: af0029c1a621968baa96c45ea5b310c00d2e48a1 [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.
57 RegStorage AllocTypedTemp(bool fp_hint, int reg_class);
58 RegStorage AllocTypedTempWide(bool fp_hint, int reg_class);
59 RegStorage TargetReg(SpecialTargetRegister reg);
60 RegStorage GetArgMappingToPhysicalReg(int arg_num);
61 RegLocation GetReturnAlt();
62 RegLocation GetReturnWideAlt();
63 RegLocation LocCReturn();
64 RegLocation LocCReturnDouble();
65 RegLocation LocCReturnFloat();
66 RegLocation LocCReturnWide();
67 uint64_t GetRegMaskCommon(RegStorage reg);
68 void AdjustSpillMask();
69 void ClobberCallerSave();
70 void FreeCallTemps();
71 void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free);
72 void LockCallTemps();
73 void MarkPreservedSingle(int v_reg, RegStorage reg);
74 void MarkPreservedDouble(int v_reg, RegStorage reg);
75 void CompilerInitializeRegAlloc();
76 RegStorage AllocPreservedDouble(int s_reg);
77
78 // Required for target - miscellaneous.
79 void AssembleLIR();
80 uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset);
81 int AssignInsnOffsets();
82 void AssignOffsets();
Matteo Franchine45fb9e2014-05-06 10:10:30 +010083 uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir);
Matteo Franchin43ec8732014-03-31 15:00:14 +010084 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
85 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
86 const char* GetTargetInstFmt(int opcode);
87 const char* GetTargetInstName(int opcode);
88 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
89 uint64_t GetPCUseDefEncoding();
90 uint64_t GetTargetInstFlags(int opcode);
91 int GetInsnSize(LIR* lir);
92 bool IsUnconditionalBranch(LIR* lir);
93
Vladimir Marko674744e2014-04-24 15:18:26 +010094 // Check support for volatile load/store of a given size.
95 bool SupportsVolatileLoadStore(OpSize size) OVERRIDE;
96 // Get the register class for load/store of a field.
97 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
98
Matteo Franchin43ec8732014-03-31 15:00:14 +010099 // Required for target - Dalvik-level generators.
100 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);
127 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
128 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
129 RegLocation rl_src2);
130 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
131 RegLocation rl_src2);
132 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
133 RegLocation rl_src2);
134 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
135 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
136 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
137 void GenDivZeroCheckWide(RegStorage reg);
138 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
139 void GenExitSequence();
140 void GenSpecialExitSequence();
141 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
142 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
143 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
144 void GenSelect(BasicBlock* bb, MIR* mir);
145 void GenMemBarrier(MemBarrierKind barrier_kind);
146 void GenMonitorEnter(int opt_flags, RegLocation rl_src);
147 void GenMonitorExit(int opt_flags, RegLocation rl_src);
148 void GenMoveException(RegLocation rl_dest);
149 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
150 int first_bit, int second_bit);
151 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
152 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
153 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
154 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100155 bool GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special);
156
157 uint32_t GenPairWise(uint32_t reg_mask, int* reg1, int* reg2);
158 void UnSpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask);
159 void SpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100160
161 // Required for target - single operation generators.
162 LIR* OpUnconditionalBranch(LIR* target);
163 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
164 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
165 LIR* OpCondBranch(ConditionCode cc, LIR* target);
166 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
167 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
168 LIR* OpIT(ConditionCode cond, const char* guide);
169 void OpEndIT(LIR* it);
170 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
171 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
172 LIR* OpReg(OpKind op, RegStorage r_dest_src);
173 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
174 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100175 LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value, bool is_wide);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100176 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
177 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
178 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
179 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
180 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
181 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
182 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
183 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
184 LIR* OpTestSuspend(LIR* target);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700185 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
186 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100187 LIR* OpVldm(RegStorage r_base, int count);
188 LIR* OpVstm(RegStorage r_base, int count);
189 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
190 void OpRegCopyWide(RegStorage dest, RegStorage src);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700191 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
192 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100193
Vladimir Marko3bf7c602014-05-07 14:55:43 +0100194 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100195 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100196 LIR* OpRegRegRegShift(OpKind op, int r_dest, int r_src1, int r_src2, int shift,
197 bool is_wide = false);
198 LIR* OpRegRegShift(OpKind op, int r_dest_src1, int r_src2, int shift, bool is_wide = false);
199 static const ArmEncodingMap EncodingMap[kA64Last];
Matteo Franchin43ec8732014-03-31 15:00:14 +0100200 int EncodeShift(int code, int amount);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100201 int EncodeExtend(int extend_type, int amount);
202 bool IsExtendEncoding(int encoded_value);
203 int EncodeLogicalImmediate(bool is_wide, uint64_t value);
204 uint64_t DecodeLogicalImmediate(bool is_wide, int value);
205
Matteo Franchin43ec8732014-03-31 15:00:14 +0100206 ArmConditionCode ArmConditionEncoding(ConditionCode code);
207 bool InexpensiveConstantInt(int32_t value);
208 bool InexpensiveConstantFloat(int32_t value);
209 bool InexpensiveConstantLong(int64_t value);
210 bool InexpensiveConstantDouble(int64_t value);
211
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100212 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
213 int LoadArgRegs(CallInfo* info, int call_state,
214 NextCallInsn next_call_insn,
215 const MethodReference& target_method,
216 uint32_t vtable_idx,
217 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
218 bool skip_this);
219
Matteo Franchin43ec8732014-03-31 15:00:14 +0100220 private:
221 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, int64_t val,
222 ConditionCode ccode);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100223 LIR* LoadFPConstantValue(int r_dest, int32_t value);
224 LIR* LoadFPConstantValueWide(int r_dest, int64_t value);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100225 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
226 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
227 void AssignDataOffsets();
228 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
229 bool is_div, bool check_zero);
230 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100231};
232
233} // namespace art
234
235#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_