blob: bf85d9163ebcc6c4efc24cd7a23d2e8dc55fc7a5 [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
20#include "dex/compiler_internals.h"
21
22namespace art {
23
24class ArmMir2Lir : public Mir2Lir {
25 public:
26 ArmMir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
27
28 // Required for target - codegen helpers.
buzbee11b63d12013-08-27 07:34:17 -070029 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src,
Brian Carlstrom7940e442013-07-12 13:46:57 -070030 RegLocation rl_dest, int lit);
Ian Rogers468532e2013-08-05 10:56:33 -070031 int LoadHelper(ThreadOffset offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -070032 LIR* LoadBaseDisp(int rBase, int displacement, int r_dest, OpSize size, int s_reg);
33 LIR* LoadBaseDispWide(int rBase, int displacement, int r_dest_lo, int r_dest_hi,
34 int s_reg);
35 LIR* LoadBaseIndexed(int rBase, int r_index, int r_dest, int scale, OpSize size);
36 LIR* LoadBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
37 int r_dest, int r_dest_hi, OpSize size, int s_reg);
38 LIR* LoadConstantNoClobber(int r_dest, int value);
39 LIR* LoadConstantWide(int r_dest_lo, int r_dest_hi, int64_t value);
40 LIR* StoreBaseDisp(int rBase, int displacement, int r_src, OpSize size);
41 LIR* StoreBaseDispWide(int rBase, int displacement, int r_src_lo, int r_src_hi);
42 LIR* StoreBaseIndexed(int rBase, int r_index, int r_src, int scale, OpSize size);
43 LIR* StoreBaseIndexedDisp(int rBase, int r_index, int scale, int displacement,
44 int r_src, int r_src_hi, OpSize size, int s_reg);
45 void MarkGCCard(int val_reg, int tgt_addr_reg);
46
47 // Required for target - register utilities.
48 bool IsFpReg(int reg);
49 bool SameRegType(int reg1, int reg2);
50 int AllocTypedTemp(bool fp_hint, int reg_class);
51 int AllocTypedTempPair(bool fp_hint, int reg_class);
52 int S2d(int low_reg, int high_reg);
53 int TargetReg(SpecialTargetRegister reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070054 RegLocation GetReturnAlt();
55 RegLocation GetReturnWideAlt();
56 RegLocation LocCReturn();
57 RegLocation LocCReturnDouble();
58 RegLocation LocCReturnFloat();
59 RegLocation LocCReturnWide();
60 uint32_t FpRegMask();
61 uint64_t GetRegMaskCommon(int reg);
62 void AdjustSpillMask();
Vladimir Marko31c2aac2013-12-09 16:31:19 +000063 void ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -070064 void FlushReg(int reg);
65 void FlushRegWide(int reg1, int reg2);
66 void FreeCallTemps();
67 void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free);
68 void LockCallTemps();
69 void MarkPreservedSingle(int v_reg, int reg);
70 void CompilerInitializeRegAlloc();
71
72 // Required for target - miscellaneous.
buzbeeb48819d2013-09-14 16:15:25 -070073 void AssembleLIR();
74 uint32_t EncodeRange(LIR* head_lir, LIR* tail_lir, uint32_t starting_offset);
75 int AssignInsnOffsets();
76 void AssignOffsets();
buzbeeb48819d2013-09-14 16:15:25 -070077 void EncodeLIR(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -070078 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
buzbeeb48819d2013-09-14 16:15:25 -070079 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -070080 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);
Brian Carlstrom7940e442013-07-12 13:46:57 -070091 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
92 RegLocation rl_index, RegLocation rl_dest, int scale);
Ian Rogersa9a82542013-10-04 11:17:26 -070093 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index,
94 RegLocation rl_src, int scale, bool card_mark);
Brian Carlstrom7940e442013-07-12 13:46:57 -070095 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
96 RegLocation rl_src1, RegLocation rl_shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -080097 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
98 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
99 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700100 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest,
101 RegLocation rl_src1, RegLocation rl_src2);
102 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest,
103 RegLocation rl_src1, RegLocation rl_src2);
104 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
105 RegLocation rl_src2);
106 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
Vladimir Marko1c282e22013-11-21 14:49:47 +0000107 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700108 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
109 bool GenInlinedSqrt(CallInfo* info);
Vladimir Markoe508a202013-11-04 15:24:22 +0000110 bool GenInlinedPeek(CallInfo* info, OpSize size);
111 bool GenInlinedPoke(CallInfo* info, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700112 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800113 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
114 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
115 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700116 LIR* GenRegMemCheck(ConditionCode c_code, int reg1, int base, int offset,
117 ThrowKind kind);
118 RegLocation GenDivRem(RegLocation rl_dest, int reg_lo, int reg_hi, bool is_div);
119 RegLocation GenDivRemLit(RegLocation rl_dest, int reg_lo, int lit, bool is_div);
120 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
121 void GenDivZeroCheck(int reg_lo, int reg_hi);
122 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
123 void GenExitSequence();
buzbee0d829482013-10-11 15:24:55 -0700124 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700125 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
126 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
127 void GenSelect(BasicBlock* bb, MIR* mir);
128 void GenMemBarrier(MemBarrierKind barrier_kind);
129 void GenMonitorEnter(int opt_flags, RegLocation rl_src);
130 void GenMonitorExit(int opt_flags, RegLocation rl_src);
131 void GenMoveException(RegLocation rl_dest);
132 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit,
133 int first_bit, int second_bit);
134 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src);
135 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src);
buzbee0d829482013-10-11 15:24:55 -0700136 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
137 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src);
Vladimir Marko5816ed42013-11-27 17:04:20 +0000138 void GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700139
140 // Required for target - single operation generators.
141 LIR* OpUnconditionalBranch(LIR* target);
142 LIR* OpCmpBranch(ConditionCode cond, int src1, int src2, LIR* target);
143 LIR* OpCmpImmBranch(ConditionCode cond, int reg, int check_value, LIR* target);
144 LIR* OpCondBranch(ConditionCode cc, LIR* target);
145 LIR* OpDecAndBranch(ConditionCode c_code, int reg, LIR* target);
146 LIR* OpFpRegCopy(int r_dest, int r_src);
147 LIR* OpIT(ConditionCode cond, const char* guide);
148 LIR* OpMem(OpKind op, int rBase, int disp);
149 LIR* OpPcRelLoad(int reg, LIR* target);
150 LIR* OpReg(OpKind op, int r_dest_src);
151 LIR* OpRegCopy(int r_dest, int r_src);
152 LIR* OpRegCopyNoInsert(int r_dest, int r_src);
153 LIR* OpRegImm(OpKind op, int r_dest_src1, int value);
154 LIR* OpRegMem(OpKind op, int r_dest, int rBase, int offset);
155 LIR* OpRegReg(OpKind op, int r_dest_src1, int r_src2);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800156 LIR* OpCondRegReg(OpKind op, ConditionCode cc, int r_dest, int r_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700157 LIR* OpRegRegImm(OpKind op, int r_dest, int r_src1, int value);
158 LIR* OpRegRegReg(OpKind op, int r_dest, int r_src1, int r_src2);
159 LIR* OpTestSuspend(LIR* target);
Ian Rogers468532e2013-08-05 10:56:33 -0700160 LIR* OpThreadMem(OpKind op, ThreadOffset thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700161 LIR* OpVldm(int rBase, int count);
162 LIR* OpVstm(int rBase, int count);
163 void OpLea(int rBase, int reg1, int reg2, int scale, int offset);
164 void OpRegCopyWide(int dest_lo, int dest_hi, int src_lo, int src_hi);
Ian Rogers468532e2013-08-05 10:56:33 -0700165 void OpTlsCmp(ThreadOffset offset, int val);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700166
167 RegLocation ArgLoc(RegLocation loc);
168 LIR* LoadBaseDispBody(int rBase, int displacement, int r_dest, int r_dest_hi, OpSize size,
169 int s_reg);
170 LIR* StoreBaseDispBody(int rBase, int displacement, int r_src, int r_src_hi, OpSize size);
171 void GenPrintLabel(MIR* mir);
172 LIR* OpRegRegRegShift(OpKind op, int r_dest, int r_src1, int r_src2, int shift);
173 LIR* OpRegRegShift(OpKind op, int r_dest_src1, int r_src2, int shift);
174 static const ArmEncodingMap EncodingMap[kArmLast];
175 int EncodeShift(int code, int amount);
176 int ModifiedImmediate(uint32_t value);
177 ArmConditionCode ArmConditionEncoding(ConditionCode code);
178 bool InexpensiveConstantInt(int32_t value);
179 bool InexpensiveConstantFloat(int32_t value);
180 bool InexpensiveConstantLong(int64_t value);
181 bool InexpensiveConstantDouble(int64_t value);
182
183 private:
184 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, int64_t val,
185 ConditionCode ccode);
186 int InPosition(int s_reg);
187 RegLocation LoadArg(RegLocation loc);
188 void LockLiveArgs(MIR* mir);
189 MIR* GetNextMir(BasicBlock** p_bb, MIR* mir);
190 MIR* SpecialIGet(BasicBlock** bb, MIR* mir, OpSize size, bool long_or_double, bool is_object);
191 MIR* SpecialIPut(BasicBlock** bb, MIR* mir, OpSize size, bool long_or_double, bool is_object);
192 MIR* SpecialIdentity(MIR* mir);
193 LIR* LoadFPConstantValue(int r_dest, int value);
194 bool BadOverlap(RegLocation rl_src, RegLocation rl_dest);
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();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700198};
199
200} // namespace art
201
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700202#endif // ART_COMPILER_DEX_QUICK_ARM_CODEGEN_ARM_H_