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; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 34 | RegStorage LoadHelper(A64ThreadOffset offset); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame^] | 35 | LIR* LoadBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest, |
| 36 | OpSize size) OVERRIDE; |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 37 | LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, |
| 38 | OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 39 | 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] | 40 | OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 41 | LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 42 | RegStorage r_dest, OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 43 | LIR* LoadConstantNoClobber(RegStorage r_dest, int value); |
| 44 | LIR* LoadConstantWide(RegStorage r_dest, int64_t value); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame^] | 45 | LIR* StoreBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest, |
| 46 | OpSize size) OVERRIDE; |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 47 | LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, |
| 48 | OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 49 | 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] | 50 | OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 51 | LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 52 | RegStorage r_src, OpSize size) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 53 | void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg); |
| 54 | |
| 55 | // Required for target - register utilities. |
| 56 | RegStorage AllocTypedTemp(bool fp_hint, int reg_class); |
| 57 | RegStorage AllocTypedTempWide(bool fp_hint, int reg_class); |
| 58 | RegStorage TargetReg(SpecialTargetRegister reg); |
| 59 | RegStorage GetArgMappingToPhysicalReg(int arg_num); |
| 60 | RegLocation GetReturnAlt(); |
| 61 | RegLocation GetReturnWideAlt(); |
| 62 | RegLocation LocCReturn(); |
| 63 | RegLocation LocCReturnDouble(); |
| 64 | RegLocation LocCReturnFloat(); |
| 65 | RegLocation LocCReturnWide(); |
| 66 | uint64_t GetRegMaskCommon(RegStorage reg); |
| 67 | void AdjustSpillMask(); |
| 68 | void ClobberCallerSave(); |
| 69 | void FreeCallTemps(); |
| 70 | void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free); |
| 71 | void LockCallTemps(); |
| 72 | void MarkPreservedSingle(int v_reg, RegStorage reg); |
| 73 | void MarkPreservedDouble(int v_reg, RegStorage reg); |
| 74 | void CompilerInitializeRegAlloc(); |
| 75 | RegStorage AllocPreservedDouble(int s_reg); |
| 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); |
| 144 | void GenMemBarrier(MemBarrierKind barrier_kind); |
| 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 | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 159 | |
| 160 | // Required for target - single operation generators. |
| 161 | LIR* OpUnconditionalBranch(LIR* target); |
| 162 | LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target); |
| 163 | LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target); |
| 164 | LIR* OpCondBranch(ConditionCode cc, LIR* target); |
| 165 | LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target); |
| 166 | LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src); |
| 167 | LIR* OpIT(ConditionCode cond, const char* guide); |
| 168 | void OpEndIT(LIR* it); |
| 169 | LIR* OpMem(OpKind op, RegStorage r_base, int disp); |
| 170 | LIR* OpPcRelLoad(RegStorage reg, LIR* target); |
| 171 | LIR* OpReg(OpKind op, RegStorage r_dest_src); |
| 172 | void OpRegCopy(RegStorage r_dest, RegStorage r_src); |
| 173 | LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 174 | 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] | 175 | LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value); |
| 176 | LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset); |
| 177 | LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2); |
| 178 | LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type); |
| 179 | LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type); |
| 180 | LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src); |
| 181 | LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value); |
| 182 | LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2); |
| 183 | LIR* OpTestSuspend(LIR* target); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 184 | LIR* OpThreadMem(OpKind op, A64ThreadOffset thread_offset); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 185 | LIR* OpVldm(RegStorage r_base, int count); |
| 186 | LIR* OpVstm(RegStorage r_base, int count); |
| 187 | void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset); |
| 188 | void OpRegCopyWide(RegStorage dest, RegStorage src); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 189 | void OpTlsCmp(A64ThreadOffset offset, int val); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 190 | |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 191 | LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 192 | LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 193 | LIR* OpRegRegRegShift(OpKind op, int r_dest, int r_src1, int r_src2, int shift, |
| 194 | bool is_wide = false); |
| 195 | LIR* OpRegRegShift(OpKind op, int r_dest_src1, int r_src2, int shift, bool is_wide = false); |
| 196 | static const ArmEncodingMap EncodingMap[kA64Last]; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 197 | int EncodeShift(int code, int amount); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 198 | int EncodeExtend(int extend_type, int amount); |
| 199 | bool IsExtendEncoding(int encoded_value); |
| 200 | int EncodeLogicalImmediate(bool is_wide, uint64_t value); |
| 201 | uint64_t DecodeLogicalImmediate(bool is_wide, int value); |
| 202 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 203 | ArmConditionCode ArmConditionEncoding(ConditionCode code); |
| 204 | bool InexpensiveConstantInt(int32_t value); |
| 205 | bool InexpensiveConstantFloat(int32_t value); |
| 206 | bool InexpensiveConstantLong(int64_t value); |
| 207 | bool InexpensiveConstantDouble(int64_t value); |
| 208 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 209 | void FlushIns(RegLocation* ArgLocs, RegLocation rl_method); |
| 210 | int LoadArgRegs(CallInfo* info, int call_state, |
| 211 | NextCallInsn next_call_insn, |
| 212 | const MethodReference& target_method, |
| 213 | uint32_t vtable_idx, |
| 214 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
| 215 | bool skip_this); |
| 216 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 217 | private: |
| 218 | void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, int64_t val, |
| 219 | ConditionCode ccode); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 220 | LIR* LoadFPConstantValue(int r_dest, int32_t value); |
| 221 | LIR* LoadFPConstantValueWide(int r_dest, int64_t value); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 222 | void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir); |
| 223 | void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir); |
| 224 | void AssignDataOffsets(); |
| 225 | RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 226 | bool is_div, bool check_zero); |
| 227 | 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] | 228 | }; |
| 229 | |
| 230 | } // namespace art |
| 231 | |
| 232 | #endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_ |