blob: 28ebe0e46027e48f90fc9692cfa873f57a086e49 [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_MIPS_CODEGEN_MIPS_H_
18#define ART_COMPILER_DEX_QUICK_MIPS_CODEGEN_MIPS_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
20#include "dex/compiler_internals.h"
21#include "mips_lir.h"
22
23namespace art {
24
25class MipsMir2Lir : public Mir2Lir {
26 public:
Brian Carlstrom7940e442013-07-12 13:46:57 -070027 MipsMir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
28
29 // Required for target - codegen utilities.
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 int AssignInsnOffsets();
78 void AssignOffsets();
buzbee0d829482013-10-11 15:24:55 -070079 AssemblerStatus AssembleInstructions(CodeOffset start_addr);
Brian Carlstrom7940e442013-07-12 13:46:57 -070080 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix);
buzbeeb48819d2013-09-14 16:15:25 -070081 void SetupTargetResourceMasks(LIR* lir, uint64_t flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -070082 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
90 // Required for target - Dalvik-level generators.
91 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
92 RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -070093 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -070094 RegLocation rl_index, RegLocation rl_dest, int scale);
Brian Carlstrom7940e442013-07-12 13:46:57 -070095 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -070096 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark);
Brian Carlstrom7940e442013-07-12 13:46:57 -070097 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
98 RegLocation rl_src1, RegLocation rl_shift);
Mark Mendelle02d48f2014-01-15 11:19:23 -080099 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
100 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
101 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700102 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest,
103 RegLocation rl_src1, RegLocation rl_src2);
104 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest,
105 RegLocation rl_src1, RegLocation rl_src2);
106 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
107 RegLocation rl_src2);
108 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src);
Vladimir Marko1c282e22013-11-21 14:49:47 +0000109 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700110 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min);
111 bool GenInlinedSqrt(CallInfo* info);
Vladimir Markoe508a202013-11-04 15:24:22 +0000112 bool GenInlinedPeek(CallInfo* info, OpSize size);
113 bool GenInlinedPoke(CallInfo* info, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700114 void GenNegLong(RegLocation rl_dest, RegLocation rl_src);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800115 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
116 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
117 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118 LIR* GenRegMemCheck(ConditionCode c_code, int reg1, int base, int offset,
119 ThrowKind kind);
120 RegLocation GenDivRem(RegLocation rl_dest, int reg_lo, int reg_hi, bool is_div);
121 RegLocation GenDivRemLit(RegLocation rl_dest, int reg_lo, int lit, bool is_div);
122 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2);
123 void GenDivZeroCheck(int reg_lo, int reg_hi);
124 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method);
125 void GenExitSequence();
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800126 void GenSpecialExitSequence();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700127 void GenFillArrayData(uint32_t table_offset, RegLocation rl_src);
128 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double);
129 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir);
130 void GenSelect(BasicBlock* bb, MIR* mir);
131 void GenMemBarrier(MemBarrierKind barrier_kind);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700132 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);
137 void GenPackedSwitch(MIR* mir, uint32_t table_offset, RegLocation rl_src);
138 void GenSparseSwitch(MIR* mir, uint32_t table_offset, RegLocation rl_src);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800139 bool 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 Lupusoru2c498d12014-01-29 16:02:57 -0800157 LIR* OpMovRegMem(int r_dest, int r_base, int offset, MoveType move_type);
158 LIR* OpMovMemReg(int r_base, int offset, int r_src, MoveType move_type);
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800159 LIR* OpCondRegReg(OpKind op, ConditionCode cc, int r_dest, int r_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700160 LIR* OpRegRegImm(OpKind op, int r_dest, int r_src1, int value);
161 LIR* OpRegRegReg(OpKind op, int r_dest, int r_src1, int r_src2);
162 LIR* OpTestSuspend(LIR* target);
Ian Rogers468532e2013-08-05 10:56:33 -0700163 LIR* OpThreadMem(OpKind op, ThreadOffset thread_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700164 LIR* OpVldm(int rBase, int count);
165 LIR* OpVstm(int rBase, int count);
166 void OpLea(int rBase, int reg1, int reg2, int scale, int offset);
167 void OpRegCopyWide(int dest_lo, int dest_hi, int src_lo, int src_hi);
Ian Rogers468532e2013-08-05 10:56:33 -0700168 void OpTlsCmp(ThreadOffset offset, int val);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700169
170 LIR* LoadBaseDispBody(int rBase, int displacement, int r_dest, int r_dest_hi, OpSize size,
171 int s_reg);
172 LIR* StoreBaseDispBody(int rBase, int displacement, int r_src, int r_src_hi, OpSize size);
173 void SpillCoreRegs();
174 void UnSpillCoreRegs();
175 static const MipsEncodingMap EncodingMap[kMipsLast];
176 bool InexpensiveConstantInt(int32_t value);
177 bool InexpensiveConstantFloat(int32_t value);
178 bool InexpensiveConstantLong(int64_t value);
179 bool InexpensiveConstantDouble(int64_t value);
180
181 private:
182 void ConvertShortToLongBranch(LIR* lir);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800183 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1,
184 RegLocation rl_src2, bool is_div, bool check_zero);
185 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700186};
187
188} // namespace art
189
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700190#endif // ART_COMPILER_DEX_QUICK_MIPS_CODEGEN_MIPS_H_