blob: fddbfd79ac3cc4c104457a22e71b6d6d39b49dfc [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();
62 RegLocation LocCReturnDouble();
63 RegLocation LocCReturnFloat();
64 RegLocation LocCReturnWide();
65 uint64_t GetRegMaskCommon(RegStorage reg);
66 void AdjustSpillMask();
67 void ClobberCallerSave();
68 void FreeCallTemps();
Matteo Franchin43ec8732014-03-31 15:00:14 +010069 void LockCallTemps();
70 void MarkPreservedSingle(int v_reg, RegStorage reg);
71 void MarkPreservedDouble(int v_reg, RegStorage reg);
72 void CompilerInitializeRegAlloc();
Matteo Franchin43ec8732014-03-31 15:00:14 +010073
74 // Required for target - miscellaneous.
75 void AssembleLIR();
76 uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset);
77 int AssignInsnOffsets();
78 void AssignOffsets();
Matteo Franchine45fb9e2014-05-06 10:10:30 +010079 uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir);
Matteo Franchin43ec8732014-03-31 15:00:14 +010080 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
81 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
82 const char* GetTargetInstFmt(int opcode);
83 const char* GetTargetInstName(int opcode);
84 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
85 uint64_t GetPCUseDefEncoding();
86 uint64_t GetTargetInstFlags(int opcode);
87 int GetInsnSize(LIR* lir);
88 bool IsUnconditionalBranch(LIR* lir);
89
Vladimir Marko674744e2014-04-24 15:18:26 +010090 // Check support for volatile load/store of a given size.
91 bool SupportsVolatileLoadStore(OpSize size) OVERRIDE;
92 // Get the register class for load/store of a field.
93 RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE;
94
Matteo Franchin43ec8732014-03-31 15:00:14 +010095 // Required for target - Dalvik-level generators.
Serban Constantinescued65c5e2014-05-22 15:10:18 +010096 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
97 RegLocation lr_shift);
Matteo Franchin43ec8732014-03-31 15:00:14 +010098 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
99 RegLocation rl_src1, RegLocation rl_src2);
100 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
101 RegLocation rl_index, RegLocation rl_dest, int scale);
102 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
103 RegLocation rl_src, int scale, bool card_mark);
104 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
105 RegLocation rl_src1, RegLocation rl_shift);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100106 void GenLongOp(OpKind op, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100107 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
108 RegLocation rl_src2);
109 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
110 RegLocation rl_src2);
111 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
112 RegLocation rl_src2);
113 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
114 RegLocation rl_src2);
115 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
116 RegLocation rl_src2);
117 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
118 RegLocation rl_src2);
119 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
120 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
121 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
122 bool GenInlinedSqrt(CallInfo* info);
123 bool GenInlinedPeek(CallInfo* info, OpSize size);
124 bool GenInlinedPoke(CallInfo* info, OpSize size);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100125 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
126 void GenNotLong(RegLocation rl_dest, RegLocation rl_src);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100127 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);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100134 void GenDivRemLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
135 RegLocation rl_src2, bool is_div);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100136 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
137 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
138 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
139 void GenDivZeroCheckWide(RegStorage reg);
140 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
141 void GenExitSequence();
142 void GenSpecialExitSequence();
143 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
144 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
145 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
146 void GenSelect(BasicBlock* bb, MIR* mir);
Andreas Gampeb14329f2014-05-15 11:16:06 -0700147 bool GenMemBarrier(MemBarrierKind barrier_kind);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100148 void GenMonitorEnter(int opt_flags, RegLocation rl_src);
149 void GenMonitorExit(int opt_flags, RegLocation rl_src);
150 void GenMoveException(RegLocation rl_dest);
151 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
152 int first_bit, int second_bit);
153 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
154 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
155 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
156 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100157 bool GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special);
158
159 uint32_t GenPairWise(uint32_t reg_mask, int* reg1, int* reg2);
160 void UnSpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask);
161 void SpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100162 void UnSpillFPRegs(RegStorage base, int offset, uint32_t reg_mask);
163 void SpillFPRegs(RegStorage base, int offset, uint32_t reg_mask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100164
165 // Required for target - single operation generators.
166 LIR* OpUnconditionalBranch(LIR* target);
167 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
168 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
169 LIR* OpCondBranch(ConditionCode cc, LIR* target);
170 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
171 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
172 LIR* OpIT(ConditionCode cond, const char* guide);
173 void OpEndIT(LIR* it);
174 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
175 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
176 LIR* OpReg(OpKind op, RegStorage r_dest_src);
177 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
178 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100179 LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100180 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
181 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
182 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
183 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
184 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
185 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
186 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
187 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
188 LIR* OpTestSuspend(LIR* target);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700189 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE;
190 LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100191 LIR* OpVldm(RegStorage r_base, int count);
192 LIR* OpVstm(RegStorage r_base, int count);
193 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
194 void OpRegCopyWide(RegStorage dest, RegStorage src);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700195 void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE;
196 void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100197
Vladimir Marko3bf7c602014-05-07 14:55:43 +0100198 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100199 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100200 LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
201 int shift);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100202 LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100203 static const ArmEncodingMap EncodingMap[kA64Last];
Matteo Franchin43ec8732014-03-31 15:00:14 +0100204 int EncodeShift(int code, int amount);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100205 int EncodeExtend(int extend_type, int amount);
206 bool IsExtendEncoding(int encoded_value);
207 int EncodeLogicalImmediate(bool is_wide, uint64_t value);
208 uint64_t DecodeLogicalImmediate(bool is_wide, int value);
209
Matteo Franchin43ec8732014-03-31 15:00:14 +0100210 ArmConditionCode ArmConditionEncoding(ConditionCode code);
211 bool InexpensiveConstantInt(int32_t value);
212 bool InexpensiveConstantFloat(int32_t value);
213 bool InexpensiveConstantLong(int64_t value);
214 bool InexpensiveConstantDouble(int64_t value);
215
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100216 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
217 int LoadArgRegs(CallInfo* info, int call_state,
218 NextCallInsn next_call_insn,
219 const MethodReference& target_method,
220 uint32_t vtable_idx,
221 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
222 bool skip_this);
223
Matteo Franchin43ec8732014-03-31 15:00:14 +0100224 private:
225 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, int64_t val,
226 ConditionCode ccode);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100227 LIR* LoadFPConstantValue(int r_dest, int32_t value);
228 LIR* LoadFPConstantValueWide(int r_dest, int64_t value);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100229 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
230 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
231 void AssignDataOffsets();
232 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
233 bool is_div, bool check_zero);
234 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100235};
236
237} // namespace art
238
239#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_