blob: 6e72c80e8a2ee5e4e8d16a2bd1dbffb59f5910fc [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_QUICK_ARM_CODEGEN_ARM_H_
18#define ART_COMPILER_DEX_QUICK_ARM_CODEGEN_ARM_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
Ian Rogers107c31e2014-01-23 20:55:29 -080020#include "arm_lir.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070021#include "dex/compiler_internals.h"
22
23namespace art {
24
25class ArmMir2Lir : public Mir2Lir {
26 public:
27 ArmMir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
28
29 // Required for target - codegen helpers.
buzbee11b63d12013-08-27 07:34:17 -070030 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
Brian Carlstrom7940e442013-07-12 13:46:57 -070031 RegLocation rl_dest, int lit);
Ian Rogers468532e2013-08-05 10:56:33 -070032 int LoadHelper(ThreadOffset offset);
Dave Allisonb373e092014-02-20 16:06:36 -080033 LIR* CheckSuspendUsingLoad() OVERRIDE;
Brian Carlstrom7940e442013-07-12 13:46:57 -070034 LIR* LoadBaseDisp(int rBase, int displacement, int r_dest, OpSize size, int s_reg);
35 LIR* LoadBaseDispWide(int rBase, int displacement, int r_dest_lo, int r_dest_hi,
36 int s_reg);
37 LIR* LoadBaseIndexed(int rBase, int r_index, int r_dest, int scale, OpSize size);
38 LIR* LoadBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
39 int r_dest, int r_dest_hi, OpSize size, int s_reg);
40 LIR* LoadConstantNoClobber(int r_dest, int value);
41 LIR* LoadConstantWide(int r_dest_lo, int r_dest_hi, int64_t value);
42 LIR* StoreBaseDisp(int rBase, int displacement, int r_src, OpSize size);
43 LIR* StoreBaseDispWide(int rBase, int displacement, int r_src_lo, int r_src_hi);
44 LIR* StoreBaseIndexed(int rBase, int r_index, int r_src, int scale, OpSize size);
45 LIR* StoreBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
46 int r_src, int r_src_hi, OpSize size, int s_reg);
47 void MarkGCCard(int val_reg, int tgt_addr_reg);
48
49 // Required for target - register utilities.
50 bool IsFpReg(int reg);
51 bool SameRegType(int reg1, int reg2);
52 int AllocTypedTemp(bool fp_hint, int reg_class);
Bill Buzbee00e1ec62014-02-27 23:44:13 +000053 RegStorage AllocTypedTempWide(bool fp_hint, int reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -070054 int S2d(int low_reg, int high_reg);
55 int TargetReg(SpecialTargetRegister reg);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -080056 int GetArgMappingToPhysicalReg(int arg_num);
Brian Carlstrom7940e442013-07-12 13:46:57 -070057 RegLocation GetReturnAlt();
58 RegLocation GetReturnWideAlt();
59 RegLocation LocCReturn();
60 RegLocation LocCReturnDouble();
61 RegLocation LocCReturnFloat();
62 RegLocation LocCReturnWide();
63 uint32_t FpRegMask();
64 uint64_t GetRegMaskCommon(int reg);
65 void AdjustSpillMask();
Vladimir Marko31c2aac2013-12-09 16:31:19 +000066 void ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -070067 void FlushReg(int reg);
68 void FlushRegWide(int reg1, int reg2);
69 void FreeCallTemps();
70 void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free);
71 void LockCallTemps();
72 void MarkPreservedSingle(int v_reg, int reg);
73 void CompilerInitializeRegAlloc();
74
75 // Required for target - miscellaneous.
buzbeeb48819d2013-09-14 16:15:25 -070076 void AssembleLIR();
77 uint32_t EncodeRange(LIR* head_lir, LIR* tail_lir, uint32_t starting_offset);
78 int AssignInsnOffsets();
79 void AssignOffsets();
buzbeeb48819d2013-09-14 16:15:25 -070080 void EncodeLIR(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -070081 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
buzbeeb48819d2013-09-14 16:15:25 -070082 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -070083 const char* GetTargetInstFmt(int opcode);
84 const char* GetTargetInstName(int opcode);
85 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
86 uint64_t GetPCUseDefEncoding();
87 uint64_t GetTargetInstFlags(int opcode);
88 int GetInsnSize(LIR* lir);
89 bool IsUnconditionalBranch(LIR* lir);
90
91 // Required for target - Dalvik-level generators.
92 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
93 RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -070094 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
95 RegLocation rl_index, RegLocation rl_dest, int scale);
Ian Rogersa9a82542013-10-04 11:17:26 -070096 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
97 RegLocation rl_src, int scale, bool card_mark);
Brian Carlstrom7940e442013-07-12 13:46:57 -070098 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
99 RegLocation rl_src1, RegLocation rl_shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800100 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
101 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
102 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700103 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest,
104 RegLocation rl_src1, RegLocation rl_src2);
105 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest,
106 RegLocation rl_src1, 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);
Vladimir Marko1c282e22013-11-21 14:49:47 +0000110 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700111 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
112 bool GenInlinedSqrt(CallInfo* info);
Vladimir Markoe508a202013-11-04 15:24:22 +0000113 bool GenInlinedPeek(CallInfo* info, OpSize size);
114 bool GenInlinedPoke(CallInfo* info, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700115 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800116 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
117 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
118 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700119 LIR* GenRegMemCheck(ConditionCode c_code, int reg1, int base, int offset,
120 ThrowKind kind);
121 RegLocation GenDivRem(RegLocation rl_dest, int reg_lo, int reg_hi, bool is_div);
122 RegLocation GenDivRemLit(RegLocation rl_dest, int reg_lo, int lit, bool is_div);
123 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
124 void GenDivZeroCheck(int reg_lo, int reg_hi);
125 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
126 void GenExitSequence();
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800127 void GenSpecialExitSequence();
buzbee0d829482013-10-11 15:24:55 -0700128 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700129 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
130 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
131 void GenSelect(BasicBlock* bb, MIR* mir);
132 void GenMemBarrier(MemBarrierKind barrier_kind);
133 void GenMonitorEnter(int opt_flags, RegLocation rl_src);
134 void GenMonitorExit(int opt_flags, RegLocation rl_src);
135 void GenMoveException(RegLocation rl_dest);
136 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
137 int first_bit, int second_bit);
138 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
139 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
buzbee0d829482013-10-11 15:24:55 -0700140 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
141 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700142
143 // Required for target - single operation generators.
144 LIR* OpUnconditionalBranch(LIR* target);
145 LIR* OpCmpBranch(ConditionCode cond, int src1, int src2, LIR* target);
146 LIR* OpCmpImmBranch(ConditionCode cond, int reg, int check_value, LIR* target);
147 LIR* OpCondBranch(ConditionCode cc, LIR* target);
148 LIR* OpDecAndBranch(ConditionCode c_code, int reg, LIR* target);
149 LIR* OpFpRegCopy(int r_dest, int r_src);
150 LIR* OpIT(ConditionCode cond, const char* guide);
151 LIR* OpMem(OpKind op, int rBase, int disp);
152 LIR* OpPcRelLoad(int reg, LIR* target);
153 LIR* OpReg(OpKind op, int r_dest_src);
154 LIR* OpRegCopy(int r_dest, int r_src);
155 LIR* OpRegCopyNoInsert(int r_dest, int r_src);
156 LIR* OpRegImm(OpKind op, int r_dest_src1, int value);
157 LIR* OpRegMem(OpKind op, int r_dest, int rBase, int offset);
158 LIR* OpRegReg(OpKind op, int r_dest_src1, int r_src2);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800159 LIR* OpMovRegMem(int r_dest, int r_base, int offset, MoveType move_type);
160 LIR* OpMovMemReg(int r_base, int offset, int r_src, MoveType move_type);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800161 LIR* OpCondRegReg(OpKind op, ConditionCode cc, int r_dest, int r_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 LIR* OpRegRegImm(OpKind op, int r_dest, int r_src1, int value);
163 LIR* OpRegRegReg(OpKind op, int r_dest, int r_src1, int r_src2);
164 LIR* OpTestSuspend(LIR* target);
Ian Rogers468532e2013-08-05 10:56:33 -0700165 LIR* OpThreadMem(OpKind op, ThreadOffset thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700166 LIR* OpVldm(int rBase, int count);
167 LIR* OpVstm(int rBase, int count);
168 void OpLea(int rBase, int reg1, int reg2, int scale, int offset);
169 void OpRegCopyWide(int dest_lo, int dest_hi, int src_lo, int src_hi);
Ian Rogers468532e2013-08-05 10:56:33 -0700170 void OpTlsCmp(ThreadOffset offset, int val);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700171
Brian Carlstrom7940e442013-07-12 13:46:57 -0700172 LIR* LoadBaseDispBody(int rBase, int displacement, int r_dest, int r_dest_hi, OpSize size,
173 int s_reg);
174 LIR* StoreBaseDispBody(int rBase, int displacement, int r_src, int r_src_hi, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700175 LIR* OpRegRegRegShift(OpKind op, int r_dest, int r_src1, int r_src2, int shift);
176 LIR* OpRegRegShift(OpKind op, int r_dest_src1, int r_src2, int shift);
177 static const ArmEncodingMap EncodingMap[kArmLast];
178 int EncodeShift(int code, int amount);
179 int ModifiedImmediate(uint32_t value);
180 ArmConditionCode ArmConditionEncoding(ConditionCode code);
181 bool InexpensiveConstantInt(int32_t value);
182 bool InexpensiveConstantFloat(int32_t value);
183 bool InexpensiveConstantLong(int64_t value);
184 bool InexpensiveConstantDouble(int64_t value);
185
186 private:
187 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, int64_t val,
188 ConditionCode ccode);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700189 LIR* LoadFPConstantValue(int r_dest, int value);
buzbeeb48819d2013-09-14 16:15:25 -0700190 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
191 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
192 void AssignDataOffsets();
Mark Mendell2bf31e62014-01-23 12:13:40 -0800193 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1,
194 RegLocation rl_src2, bool is_div, bool check_zero);
195 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700196};
197
198} // namespace art
199
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700200#endif // ART_COMPILER_DEX_QUICK_ARM_CODEGEN_ARM_H_