Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace art { |
| 24 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 25 | class Arm64Mir2Lir : public Mir2Lir { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 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; |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 34 | RegStorage LoadHelper(ThreadOffset<4> offset) OVERRIDE; |
| 35 | RegStorage LoadHelper(ThreadOffset<8> offset) OVERRIDE; |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 36 | LIR* LoadBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest, |
| 37 | OpSize size) OVERRIDE; |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 38 | LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, |
| 39 | OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 40 | LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 41 | OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 42 | LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 43 | RegStorage r_dest, OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 44 | LIR* LoadConstantNoClobber(RegStorage r_dest, int value); |
| 45 | LIR* LoadConstantWide(RegStorage r_dest, int64_t value); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 46 | LIR* StoreBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest, |
| 47 | OpSize size) OVERRIDE; |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 48 | LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, |
| 49 | OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 50 | LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 51 | OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 52 | LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 53 | RegStorage r_src, OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 54 | void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg); |
| 55 | |
| 56 | // Required for target - register utilities. |
| 57 | RegStorage AllocTypedTemp(bool fp_hint, int reg_class); |
| 58 | RegStorage AllocTypedTempWide(bool fp_hint, int reg_class); |
| 59 | RegStorage TargetReg(SpecialTargetRegister reg); |
| 60 | RegStorage GetArgMappingToPhysicalReg(int arg_num); |
| 61 | RegLocation GetReturnAlt(); |
| 62 | RegLocation GetReturnWideAlt(); |
| 63 | RegLocation LocCReturn(); |
| 64 | RegLocation LocCReturnDouble(); |
| 65 | RegLocation LocCReturnFloat(); |
| 66 | RegLocation LocCReturnWide(); |
| 67 | uint64_t GetRegMaskCommon(RegStorage reg); |
| 68 | void AdjustSpillMask(); |
| 69 | void ClobberCallerSave(); |
| 70 | void FreeCallTemps(); |
| 71 | void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free); |
| 72 | void LockCallTemps(); |
| 73 | void MarkPreservedSingle(int v_reg, RegStorage reg); |
| 74 | void MarkPreservedDouble(int v_reg, RegStorage reg); |
| 75 | void CompilerInitializeRegAlloc(); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 76 | |
| 77 | // Required for target - miscellaneous. |
| 78 | void AssembleLIR(); |
| 79 | uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset); |
| 80 | int AssignInsnOffsets(); |
| 81 | void AssignOffsets(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 82 | uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 83 | void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix); |
| 84 | void SetupTargetResourceMasks(LIR* lir, uint64_t flags); |
| 85 | const char* GetTargetInstFmt(int opcode); |
| 86 | const char* GetTargetInstName(int opcode); |
| 87 | std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr); |
| 88 | uint64_t GetPCUseDefEncoding(); |
| 89 | uint64_t GetTargetInstFlags(int opcode); |
| 90 | int GetInsnSize(LIR* lir); |
| 91 | bool IsUnconditionalBranch(LIR* lir); |
| 92 | |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 93 | // Check support for volatile load/store of a given size. |
| 94 | bool SupportsVolatileLoadStore(OpSize size) OVERRIDE; |
| 95 | // Get the register class for load/store of a field. |
| 96 | RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE; |
| 97 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 98 | // Required for target - Dalvik-level generators. |
| 99 | void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 100 | RegLocation rl_src1, RegLocation rl_src2); |
| 101 | void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, |
| 102 | RegLocation rl_index, RegLocation rl_dest, int scale); |
| 103 | void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index, |
| 104 | RegLocation rl_src, int scale, bool card_mark); |
| 105 | void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 106 | RegLocation rl_src1, RegLocation rl_shift); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 107 | void GenLongOp(OpKind op, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 108 | void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 109 | RegLocation rl_src2); |
| 110 | void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 111 | RegLocation rl_src2); |
| 112 | void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 113 | RegLocation rl_src2); |
| 114 | void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 115 | RegLocation rl_src2); |
| 116 | void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 117 | RegLocation rl_src2); |
| 118 | void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 119 | RegLocation rl_src2); |
| 120 | void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src); |
| 121 | bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object); |
| 122 | bool GenInlinedMinMaxInt(CallInfo* info, bool is_min); |
| 123 | bool GenInlinedSqrt(CallInfo* info); |
| 124 | bool GenInlinedPeek(CallInfo* info, OpSize size); |
| 125 | bool GenInlinedPoke(CallInfo* info, OpSize size); |
| 126 | void GenNegLong(RegLocation rl_dest, RegLocation rl_src); |
| 127 | void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 128 | RegLocation rl_src2); |
| 129 | void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 130 | RegLocation rl_src2); |
| 131 | void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 132 | RegLocation rl_src2); |
| 133 | RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div); |
| 134 | RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div); |
| 135 | void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); |
| 136 | void GenDivZeroCheckWide(RegStorage reg); |
| 137 | void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method); |
| 138 | void GenExitSequence(); |
| 139 | void GenSpecialExitSequence(); |
| 140 | void GenFillArrayData(DexOffset table_offset, RegLocation rl_src); |
| 141 | void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double); |
| 142 | void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir); |
| 143 | void GenSelect(BasicBlock* bb, MIR* mir); |
Andreas Gampe | b14329f | 2014-05-15 11:16:06 -0700 | [diff] [blame] | 144 | bool GenMemBarrier(MemBarrierKind barrier_kind); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 145 | void GenMonitorEnter(int opt_flags, RegLocation rl_src); |
| 146 | void GenMonitorExit(int opt_flags, RegLocation rl_src); |
| 147 | void GenMoveException(RegLocation rl_dest); |
| 148 | void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit, |
| 149 | int first_bit, int second_bit); |
| 150 | void GenNegDouble(RegLocation rl_dest, RegLocation rl_src); |
| 151 | void GenNegFloat(RegLocation rl_dest, RegLocation rl_src); |
| 152 | void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src); |
| 153 | void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 154 | bool GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special); |
| 155 | |
| 156 | uint32_t GenPairWise(uint32_t reg_mask, int* reg1, int* reg2); |
| 157 | void UnSpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask); |
| 158 | void SpillCoreRegs(RegStorage base, int offset, uint32_t reg_mask); |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame^] | 159 | void UnSpillFPRegs(RegStorage base, int offset, uint32_t reg_mask); |
| 160 | void SpillFPRegs(RegStorage base, int offset, uint32_t reg_mask); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 161 | |
| 162 | // Required for target - single operation generators. |
| 163 | LIR* OpUnconditionalBranch(LIR* target); |
| 164 | LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target); |
| 165 | LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target); |
| 166 | LIR* OpCondBranch(ConditionCode cc, LIR* target); |
| 167 | LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target); |
| 168 | LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src); |
| 169 | LIR* OpIT(ConditionCode cond, const char* guide); |
| 170 | void OpEndIT(LIR* it); |
| 171 | LIR* OpMem(OpKind op, RegStorage r_base, int disp); |
| 172 | LIR* OpPcRelLoad(RegStorage reg, LIR* target); |
| 173 | LIR* OpReg(OpKind op, RegStorage r_dest_src); |
| 174 | void OpRegCopy(RegStorage r_dest, RegStorage r_src); |
| 175 | LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 176 | LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value, bool is_wide); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 177 | LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value); |
| 178 | LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset); |
| 179 | LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2); |
| 180 | LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type); |
| 181 | LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type); |
| 182 | LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src); |
| 183 | LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value); |
| 184 | LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2); |
| 185 | LIR* OpTestSuspend(LIR* target); |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 186 | LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE; |
| 187 | LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 188 | LIR* OpVldm(RegStorage r_base, int count); |
| 189 | LIR* OpVstm(RegStorage r_base, int count); |
| 190 | void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset); |
| 191 | void OpRegCopyWide(RegStorage dest, RegStorage src); |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 192 | void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE; |
| 193 | void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 194 | |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 195 | LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 196 | LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 197 | LIR* OpRegRegRegShift(OpKind op, int r_dest, int r_src1, int r_src2, int shift, |
| 198 | bool is_wide = false); |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame^] | 199 | LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 200 | static const ArmEncodingMap EncodingMap[kA64Last]; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 201 | int EncodeShift(int code, int amount); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 202 | int EncodeExtend(int extend_type, int amount); |
| 203 | bool IsExtendEncoding(int encoded_value); |
| 204 | int EncodeLogicalImmediate(bool is_wide, uint64_t value); |
| 205 | uint64_t DecodeLogicalImmediate(bool is_wide, int value); |
| 206 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 207 | ArmConditionCode ArmConditionEncoding(ConditionCode code); |
| 208 | bool InexpensiveConstantInt(int32_t value); |
| 209 | bool InexpensiveConstantFloat(int32_t value); |
| 210 | bool InexpensiveConstantLong(int64_t value); |
| 211 | bool InexpensiveConstantDouble(int64_t value); |
| 212 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 213 | void FlushIns(RegLocation* ArgLocs, RegLocation rl_method); |
| 214 | int LoadArgRegs(CallInfo* info, int call_state, |
| 215 | NextCallInsn next_call_insn, |
| 216 | const MethodReference& target_method, |
| 217 | uint32_t vtable_idx, |
| 218 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
| 219 | bool skip_this); |
| 220 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 221 | private: |
| 222 | void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, int64_t val, |
| 223 | ConditionCode ccode); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 224 | LIR* LoadFPConstantValue(int r_dest, int32_t value); |
| 225 | LIR* LoadFPConstantValueWide(int r_dest, int64_t value); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 226 | void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir); |
| 227 | void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir); |
| 228 | void AssignDataOffsets(); |
| 229 | RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 230 | bool is_div, bool check_zero); |
| 231 | RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | } // namespace art |
| 235 | |
| 236 | #endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_ |