blob: 4e784c6b38807f71bd6411bcdf91ed9fef29b4a4 [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
25class Arm64Mir2Lir FINAL : public Mir2Lir {
26 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;
34 RegStorage LoadHelper(ThreadOffset<4> offset);
35 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size,
36 int s_reg);
Matteo Franchin43ec8732014-03-31 15:00:14 +010037 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale,
38 OpSize size);
39 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
40 RegStorage r_dest, OpSize size, int s_reg);
41 LIR* LoadConstantNoClobber(RegStorage r_dest, int value);
42 LIR* LoadConstantWide(RegStorage r_dest, int64_t value);
43 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
Matteo Franchin43ec8732014-03-31 15:00:14 +010044 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale,
45 OpSize size);
46 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement,
47 RegStorage r_src, OpSize size, int s_reg);
48 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg);
49
50 // Required for target - register utilities.
51 RegStorage AllocTypedTemp(bool fp_hint, int reg_class);
52 RegStorage AllocTypedTempWide(bool fp_hint, int reg_class);
53 RegStorage TargetReg(SpecialTargetRegister reg);
54 RegStorage GetArgMappingToPhysicalReg(int arg_num);
55 RegLocation GetReturnAlt();
56 RegLocation GetReturnWideAlt();
57 RegLocation LocCReturn();
58 RegLocation LocCReturnDouble();
59 RegLocation LocCReturnFloat();
60 RegLocation LocCReturnWide();
61 uint64_t GetRegMaskCommon(RegStorage reg);
62 void AdjustSpillMask();
63 void ClobberCallerSave();
64 void FreeCallTemps();
65 void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free);
66 void LockCallTemps();
67 void MarkPreservedSingle(int v_reg, RegStorage reg);
68 void MarkPreservedDouble(int v_reg, RegStorage reg);
69 void CompilerInitializeRegAlloc();
70 RegStorage AllocPreservedDouble(int s_reg);
71
72 // Required for target - miscellaneous.
73 void AssembleLIR();
74 uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset);
75 int AssignInsnOffsets();
76 void AssignOffsets();
77 static uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir);
78 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
79 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
80 const char* GetTargetInstFmt(int opcode);
81 const char* GetTargetInstName(int opcode);
82 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
83 uint64_t GetPCUseDefEncoding();
84 uint64_t GetTargetInstFlags(int opcode);
85 int GetInsnSize(LIR* lir);
86 bool IsUnconditionalBranch(LIR* lir);
87
88 // Required for target - Dalvik-level generators.
89 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
90 RegLocation rl_src1, RegLocation rl_src2);
91 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
92 RegLocation rl_index, RegLocation rl_dest, int scale);
93 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
94 RegLocation rl_src, int scale, bool card_mark);
95 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
96 RegLocation rl_src1, RegLocation rl_shift);
97 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
98 RegLocation rl_src2);
99 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
100 RegLocation rl_src2);
101 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
102 RegLocation rl_src2);
103 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
104 RegLocation rl_src2);
105 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
106 RegLocation rl_src2);
107 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
108 RegLocation rl_src2);
109 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
110 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
111 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
112 bool GenInlinedSqrt(CallInfo* info);
113 bool GenInlinedPeek(CallInfo* info, OpSize size);
114 bool GenInlinedPoke(CallInfo* info, OpSize size);
115 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
116 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
117 RegLocation rl_src2);
118 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
119 RegLocation rl_src2);
120 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
121 RegLocation rl_src2);
122 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div);
123 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div);
124 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
125 void GenDivZeroCheckWide(RegStorage reg);
126 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
127 void GenExitSequence();
128 void GenSpecialExitSequence();
129 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
130 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
131 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
132 void GenSelect(BasicBlock* bb, MIR* mir);
133 void GenMemBarrier(MemBarrierKind barrier_kind);
134 void GenMonitorEnter(int opt_flags, RegLocation rl_src);
135 void GenMonitorExit(int opt_flags, RegLocation rl_src);
136 void GenMoveException(RegLocation rl_dest);
137 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
138 int first_bit, int second_bit);
139 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
140 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
141 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
142 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
143
144 // Required for target - single operation generators.
145 LIR* OpUnconditionalBranch(LIR* target);
146 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target);
147 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target);
148 LIR* OpCondBranch(ConditionCode cc, LIR* target);
149 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target);
150 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src);
151 LIR* OpIT(ConditionCode cond, const char* guide);
152 void OpEndIT(LIR* it);
153 LIR* OpMem(OpKind op, RegStorage r_base, int disp);
154 LIR* OpPcRelLoad(RegStorage reg, LIR* target);
155 LIR* OpReg(OpKind op, RegStorage r_dest_src);
156 void OpRegCopy(RegStorage r_dest, RegStorage r_src);
157 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src);
158 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value);
159 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset);
160 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2);
161 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type);
162 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type);
163 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src);
164 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value);
165 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2);
166 LIR* OpTestSuspend(LIR* target);
167 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset);
168 LIR* OpVldm(RegStorage r_base, int count);
169 LIR* OpVstm(RegStorage r_base, int count);
170 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset);
171 void OpRegCopyWide(RegStorage dest, RegStorage src);
172 void OpTlsCmp(ThreadOffset<4> offset, int val);
173
174 LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size,
175 int s_reg);
176 LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size);
177 LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2,
178 int shift);
179 LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift);
180 static const ArmEncodingMap EncodingMap[kArmLast];
181 int EncodeShift(int code, int amount);
182 int ModifiedImmediate(uint32_t value);
183 ArmConditionCode ArmConditionEncoding(ConditionCode code);
184 bool InexpensiveConstantInt(int32_t value);
185 bool InexpensiveConstantFloat(int32_t value);
186 bool InexpensiveConstantLong(int64_t value);
187 bool InexpensiveConstantDouble(int64_t value);
188
189 private:
190 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, int64_t val,
191 ConditionCode ccode);
192 LIR* LoadFPConstantValue(int r_dest, int value);
193 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
194 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
195 void AssignDataOffsets();
196 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
197 bool is_div, bool check_zero);
198 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div);
199 typedef struct {
200 OpKind op;
201 uint32_t shift;
202 } EasyMultiplyOp;
203 bool GetEasyMultiplyOp(int lit, EasyMultiplyOp* op);
204 bool GetEasyMultiplyTwoOps(int lit, EasyMultiplyOp* ops);
205 void GenEasyMultiplyTwoOps(RegStorage r_dest, RegStorage r_src, EasyMultiplyOp* ops);
206};
207
208} // namespace art
209
210#endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_