blob: 32673db41e65c1ad96fe9098f014d82e733cef92 [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);
Brian Carlstrom7940e442013-07-12 13:46:57 -070033 LIR* LoadBaseDisp(int rBase, int displacement, int r_dest, OpSize size, int s_reg);
34 LIR* LoadBaseDispWide(int rBase, int displacement, int r_dest_lo, int r_dest_hi,
35 int s_reg);
36 LIR* LoadBaseIndexed(int rBase, int r_index, int r_dest, int scale, OpSize size);
37 LIR* LoadBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
38 int r_dest, int r_dest_hi, OpSize size, int s_reg);
39 LIR* LoadConstantNoClobber(int r_dest, int value);
40 LIR* LoadConstantWide(int r_dest_lo, int r_dest_hi, int64_t value);
41 LIR* StoreBaseDisp(int rBase, int displacement, int r_src, OpSize size);
42 LIR* StoreBaseDispWide(int rBase, int displacement, int r_src_lo, int r_src_hi);
43 LIR* StoreBaseIndexed(int rBase, int r_index, int r_src, int scale, OpSize size);
44 LIR* StoreBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
45 int r_src, int r_src_hi, OpSize size, int s_reg);
46 void MarkGCCard(int val_reg, int tgt_addr_reg);
47
48 // Required for target - register utilities.
49 bool IsFpReg(int reg);
50 bool SameRegType(int reg1, int reg2);
51 int AllocTypedTemp(bool fp_hint, int reg_class);
52 int AllocTypedTempPair(bool fp_hint, int reg_class);
53 int S2d(int low_reg, int high_reg);
54 int TargetReg(SpecialTargetRegister reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070055 RegLocation GetReturnAlt();
56 RegLocation GetReturnWideAlt();
57 RegLocation LocCReturn();
58 RegLocation LocCReturnDouble();
59 RegLocation LocCReturnFloat();
60 RegLocation LocCReturnWide();
61 uint32_t FpRegMask();
62 uint64_t GetRegMaskCommon(int reg);
63 void AdjustSpillMask();
Vladimir Marko31c2aac2013-12-09 16:31:19 +000064 void ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -070065 void FlushReg(int reg);
66 void FlushRegWide(int reg1, int reg2);
67 void FreeCallTemps();
68 void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free);
69 void LockCallTemps();
70 void MarkPreservedSingle(int v_reg, int reg);
71 void CompilerInitializeRegAlloc();
72
73 // Required for target - miscellaneous.
buzbeeb48819d2013-09-14 16:15:25 -070074 void AssembleLIR();
75 uint32_t EncodeRange(LIR* head_lir, LIR* tail_lir, uint32_t starting_offset);
76 int AssignInsnOffsets();
77 void AssignOffsets();
buzbeeb48819d2013-09-14 16:15:25 -070078 void EncodeLIR(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -070079 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
buzbeeb48819d2013-09-14 16:15:25 -070080 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -070081 const char* GetTargetInstFmt(int opcode);
82 const char* GetTargetInstName(int opcode);
83 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr);
84 uint64_t GetPCUseDefEncoding();
85 uint64_t GetTargetInstFlags(int opcode);
86 int GetInsnSize(LIR* lir);
87 bool IsUnconditionalBranch(LIR* lir);
88
89 // Required for target - Dalvik-level generators.
90 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
91 RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -070092 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
93 RegLocation rl_index, RegLocation rl_dest, int scale);
Ian Rogersa9a82542013-10-04 11:17:26 -070094 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
95 RegLocation rl_src, int scale, bool card_mark);
Brian Carlstrom7940e442013-07-12 13:46:57 -070096 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
97 RegLocation rl_src1, RegLocation rl_shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -080098 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
99 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
100 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700101 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest,
102 RegLocation rl_src1, RegLocation rl_src2);
103 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest,
104 RegLocation rl_src1, RegLocation rl_src2);
105 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
106 RegLocation rl_src2);
107 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
Vladimir Marko1c282e22013-11-21 14:49:47 +0000108 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700109 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
110 bool GenInlinedSqrt(CallInfo* info);
Vladimir Markoe508a202013-11-04 15:24:22 +0000111 bool GenInlinedPeek(CallInfo* info, OpSize size);
112 bool GenInlinedPoke(CallInfo* info, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700113 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800114 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
115 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
116 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700117 LIR* GenRegMemCheck(ConditionCode c_code, int reg1, int base, int offset,
118 ThrowKind kind);
119 RegLocation GenDivRem(RegLocation rl_dest, int reg_lo, int reg_hi, bool is_div);
120 RegLocation GenDivRemLit(RegLocation rl_dest, int reg_lo, int lit, bool is_div);
121 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
122 void GenDivZeroCheck(int reg_lo, int reg_hi);
123 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
124 void GenExitSequence();
buzbee0d829482013-10-11 15:24:55 -0700125 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700126 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
127 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
128 void GenSelect(BasicBlock* bb, MIR* mir);
129 void GenMemBarrier(MemBarrierKind barrier_kind);
130 void GenMonitorEnter(int opt_flags, RegLocation rl_src);
131 void GenMonitorExit(int opt_flags, RegLocation rl_src);
132 void GenMoveException(RegLocation rl_dest);
133 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
134 int first_bit, int second_bit);
135 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
136 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
buzbee0d829482013-10-11 15:24:55 -0700137 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
138 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Vladimir Marko5816ed42013-11-27 17:04:20 +0000139 void GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140
141 // Required for target - single operation generators.
142 LIR* OpUnconditionalBranch(LIR* target);
143 LIR* OpCmpBranch(ConditionCode cond, int src1, int src2, LIR* target);
144 LIR* OpCmpImmBranch(ConditionCode cond, int reg, int check_value, LIR* target);
145 LIR* OpCondBranch(ConditionCode cc, LIR* target);
146 LIR* OpDecAndBranch(ConditionCode c_code, int reg, LIR* target);
147 LIR* OpFpRegCopy(int r_dest, int r_src);
148 LIR* OpIT(ConditionCode cond, const char* guide);
149 LIR* OpMem(OpKind op, int rBase, int disp);
150 LIR* OpPcRelLoad(int reg, LIR* target);
151 LIR* OpReg(OpKind op, int r_dest_src);
152 LIR* OpRegCopy(int r_dest, int r_src);
153 LIR* OpRegCopyNoInsert(int r_dest, int r_src);
154 LIR* OpRegImm(OpKind op, int r_dest_src1, int value);
155 LIR* OpRegMem(OpKind op, int r_dest, int rBase, int offset);
156 LIR* OpRegReg(OpKind op, int r_dest_src1, int r_src2);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800157 LIR* OpCondRegReg(OpKind op, ConditionCode cc, int r_dest, int r_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700158 LIR* OpRegRegImm(OpKind op, int r_dest, int r_src1, int value);
159 LIR* OpRegRegReg(OpKind op, int r_dest, int r_src1, int r_src2);
160 LIR* OpTestSuspend(LIR* target);
Ian Rogers468532e2013-08-05 10:56:33 -0700161 LIR* OpThreadMem(OpKind op, ThreadOffset thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 LIR* OpVldm(int rBase, int count);
163 LIR* OpVstm(int rBase, int count);
164 void OpLea(int rBase, int reg1, int reg2, int scale, int offset);
165 void OpRegCopyWide(int dest_lo, int dest_hi, int src_lo, int src_hi);
Ian Rogers468532e2013-08-05 10:56:33 -0700166 void OpTlsCmp(ThreadOffset offset, int val);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700167
168 RegLocation ArgLoc(RegLocation loc);
169 LIR* LoadBaseDispBody(int rBase, int displacement, int r_dest, int r_dest_hi, OpSize size,
170 int s_reg);
171 LIR* StoreBaseDispBody(int rBase, int displacement, int r_src, int r_src_hi, OpSize size);
172 void GenPrintLabel(MIR* mir);
173 LIR* OpRegRegRegShift(OpKind op, int r_dest, int r_src1, int r_src2, int shift);
174 LIR* OpRegRegShift(OpKind op, int r_dest_src1, int r_src2, int shift);
175 static const ArmEncodingMap EncodingMap[kArmLast];
176 int EncodeShift(int code, int amount);
177 int ModifiedImmediate(uint32_t value);
178 ArmConditionCode ArmConditionEncoding(ConditionCode code);
179 bool InexpensiveConstantInt(int32_t value);
180 bool InexpensiveConstantFloat(int32_t value);
181 bool InexpensiveConstantLong(int64_t value);
182 bool InexpensiveConstantDouble(int64_t value);
183
184 private:
185 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, int64_t val,
186 ConditionCode ccode);
187 int InPosition(int s_reg);
188 RegLocation LoadArg(RegLocation loc);
189 void LockLiveArgs(MIR* mir);
190 MIR* GetNextMir(BasicBlock** p_bb, MIR* mir);
191 MIR* SpecialIGet(BasicBlock** bb, MIR* mir, OpSize size, bool long_or_double, bool is_object);
192 MIR* SpecialIPut(BasicBlock** bb, MIR* mir, OpSize size, bool long_or_double, bool is_object);
193 MIR* SpecialIdentity(MIR* mir);
194 LIR* LoadFPConstantValue(int r_dest, int value);
buzbeeb48819d2013-09-14 16:15:25 -0700195 void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
196 void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir);
197 void AssignDataOffsets();
Mark Mendell2bf31e62014-01-23 12:13:40 -0800198 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1,
199 RegLocation rl_src2, bool is_div, bool check_zero);
200 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700201};
202
203} // namespace art
204
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700205#endif // ART_COMPILER_DEX_QUICK_ARM_CODEGEN_ARM_H_