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 | |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 23 | #include <map> |
| 24 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 25 | namespace art { |
| 26 | |
Andreas Gampe | 4b537a8 | 2014-06-30 22:24:53 -0700 | [diff] [blame] | 27 | class Arm64Mir2Lir FINAL : public Mir2Lir { |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 28 | protected: |
| 29 | // TODO: consolidate 64-bit target support. |
| 30 | class InToRegStorageMapper { |
| 31 | public: |
Zheng Xu | 949cd97 | 2014-06-23 18:33:08 +0800 | [diff] [blame] | 32 | virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref) = 0; |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 33 | virtual ~InToRegStorageMapper() {} |
| 34 | }; |
| 35 | |
| 36 | class InToRegStorageArm64Mapper : public InToRegStorageMapper { |
| 37 | public: |
| 38 | InToRegStorageArm64Mapper() : cur_core_reg_(0), cur_fp_reg_(0) {} |
| 39 | virtual ~InToRegStorageArm64Mapper() {} |
Zheng Xu | 949cd97 | 2014-06-23 18:33:08 +0800 | [diff] [blame] | 40 | virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 41 | private: |
| 42 | int cur_core_reg_; |
| 43 | int cur_fp_reg_; |
| 44 | }; |
| 45 | |
| 46 | class InToRegStorageMapping { |
| 47 | public: |
| 48 | InToRegStorageMapping() : max_mapped_in_(0), is_there_stack_mapped_(false), |
| 49 | initialized_(false) {} |
| 50 | void Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper); |
| 51 | int GetMaxMappedIn() { return max_mapped_in_; } |
| 52 | bool IsThereStackMapped() { return is_there_stack_mapped_; } |
| 53 | RegStorage Get(int in_position); |
| 54 | bool IsInitialized() { return initialized_; } |
| 55 | private: |
| 56 | std::map<int, RegStorage> mapping_; |
| 57 | int max_mapped_in_; |
| 58 | bool is_there_stack_mapped_; |
| 59 | bool initialized_; |
| 60 | }; |
| 61 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 62 | public: |
| 63 | Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 64 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 65 | // Required for target - codegen helpers. |
| 66 | bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src, |
| 67 | RegLocation rl_dest, int lit) OVERRIDE; |
| 68 | bool HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div, |
| 69 | RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE; |
| 70 | bool HandleEasyDivRem64(Instruction::Code dalvik_opcode, bool is_div, |
| 71 | RegLocation rl_src, RegLocation rl_dest, int64_t lit); |
| 72 | bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE; |
| 73 | LIR* CheckSuspendUsingLoad() OVERRIDE; |
| 74 | RegStorage LoadHelper(QuickEntrypointEnum trampoline) OVERRIDE; |
| 75 | LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, |
| 76 | OpSize size, VolatileKind is_volatile) OVERRIDE; |
| 77 | LIR* LoadRefDisp(RegStorage r_base, int displacement, RegStorage r_dest, |
| 78 | VolatileKind is_volatile) OVERRIDE; |
| 79 | LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale, |
| 80 | OpSize size) OVERRIDE; |
| 81 | LIR* LoadRefIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale) |
| 82 | OVERRIDE; |
| 83 | LIR* LoadConstantNoClobber(RegStorage r_dest, int value) OVERRIDE; |
| 84 | LIR* LoadConstantWide(RegStorage r_dest, int64_t value) OVERRIDE; |
| 85 | LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size, |
| 86 | VolatileKind is_volatile) OVERRIDE; |
| 87 | LIR* StoreRefDisp(RegStorage r_base, int displacement, RegStorage r_src, VolatileKind is_volatile) |
| 88 | OVERRIDE; |
| 89 | LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale, |
| 90 | OpSize size) OVERRIDE; |
| 91 | LIR* StoreRefIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale) OVERRIDE; |
| 92 | void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg) OVERRIDE; |
| 93 | LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg, |
| 94 | int offset, int check_value, LIR* target, LIR** compare) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 95 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 96 | // Required for target - register utilities. |
| 97 | RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE; |
| 98 | RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE { |
| 99 | if (wide_kind == kWide || wide_kind == kRef) { |
Matteo Franchin | ed7a0f2 | 2014-06-10 19:23:45 +0100 | [diff] [blame] | 100 | return As64BitReg(TargetReg(symbolic_reg)); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 101 | } else { |
| 102 | return Check32BitReg(TargetReg(symbolic_reg)); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 103 | } |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 104 | } |
| 105 | RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE { |
| 106 | return As64BitReg(TargetReg(symbolic_reg)); |
| 107 | } |
| 108 | RegStorage GetArgMappingToPhysicalReg(int arg_num) OVERRIDE; |
| 109 | RegLocation GetReturnAlt() OVERRIDE; |
| 110 | RegLocation GetReturnWideAlt() OVERRIDE; |
| 111 | RegLocation LocCReturn() OVERRIDE; |
| 112 | RegLocation LocCReturnRef() OVERRIDE; |
| 113 | RegLocation LocCReturnDouble() OVERRIDE; |
| 114 | RegLocation LocCReturnFloat() OVERRIDE; |
| 115 | RegLocation LocCReturnWide() OVERRIDE; |
| 116 | ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE; |
| 117 | void AdjustSpillMask() OVERRIDE; |
| 118 | void ClobberCallerSave() OVERRIDE; |
| 119 | void FreeCallTemps() OVERRIDE; |
| 120 | void LockCallTemps() OVERRIDE; |
| 121 | void CompilerInitializeRegAlloc() OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 122 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 123 | // Required for target - miscellaneous. |
| 124 | void AssembleLIR() OVERRIDE; |
| 125 | void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE; |
| 126 | void SetupTargetResourceMasks(LIR* lir, uint64_t flags, |
| 127 | ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE; |
| 128 | const char* GetTargetInstFmt(int opcode) OVERRIDE; |
| 129 | const char* GetTargetInstName(int opcode) OVERRIDE; |
| 130 | std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) OVERRIDE; |
| 131 | ResourceMask GetPCUseDefEncoding() const OVERRIDE; |
| 132 | uint64_t GetTargetInstFlags(int opcode) OVERRIDE; |
| 133 | size_t GetInsnSize(LIR* lir) OVERRIDE; |
| 134 | bool IsUnconditionalBranch(LIR* lir) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 135 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 136 | // Get the register class for load/store of a field. |
| 137 | RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE; |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 138 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 139 | // Required for target - Dalvik-level generators. |
| 140 | void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 141 | RegLocation lr_shift) OVERRIDE; |
| 142 | void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 143 | RegLocation rl_src2) OVERRIDE; |
| 144 | void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index, |
| 145 | RegLocation rl_dest, int scale) OVERRIDE; |
| 146 | void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index, |
| 147 | RegLocation rl_src, int scale, bool card_mark) OVERRIDE; |
| 148 | void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 149 | RegLocation rl_shift) OVERRIDE; |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 150 | void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 151 | RegLocation rl_src2) OVERRIDE; |
| 152 | void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 153 | RegLocation rl_src2) OVERRIDE; |
| 154 | void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 155 | RegLocation rl_src2) OVERRIDE; |
| 156 | void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src) OVERRIDE; |
| 157 | bool GenInlinedReverseBits(CallInfo* info, OpSize size) OVERRIDE; |
| 158 | bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE; |
| 159 | bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE; |
| 160 | bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object) OVERRIDE; |
| 161 | bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) OVERRIDE; |
| 162 | bool GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) OVERRIDE; |
| 163 | bool GenInlinedSqrt(CallInfo* info) OVERRIDE; |
| 164 | bool GenInlinedCeil(CallInfo* info) OVERRIDE; |
| 165 | bool GenInlinedFloor(CallInfo* info) OVERRIDE; |
| 166 | bool GenInlinedRint(CallInfo* info) OVERRIDE; |
| 167 | bool GenInlinedRound(CallInfo* info, bool is_double) OVERRIDE; |
| 168 | bool GenInlinedPeek(CallInfo* info, OpSize size) OVERRIDE; |
| 169 | bool GenInlinedPoke(CallInfo* info, OpSize size) OVERRIDE; |
| 170 | bool GenInlinedAbsLong(CallInfo* info) OVERRIDE; |
Zheng Xu | 947717a | 2014-08-07 14:05:23 +0800 | [diff] [blame^] | 171 | bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE; |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 172 | void GenIntToLong(RegLocation rl_dest, RegLocation rl_src) OVERRIDE; |
Andreas Gampe | c76c614 | 2014-08-04 16:30:03 -0700 | [diff] [blame] | 173 | void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 174 | RegLocation rl_src2) OVERRIDE; |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 175 | RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div) |
| 176 | OVERRIDE; |
| 177 | RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div) |
| 178 | OVERRIDE; |
| 179 | void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) OVERRIDE; |
| 180 | void GenDivZeroCheckWide(RegStorage reg) OVERRIDE; |
| 181 | void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE; |
| 182 | void GenExitSequence() OVERRIDE; |
| 183 | void GenSpecialExitSequence() OVERRIDE; |
| 184 | void GenFillArrayData(DexOffset table_offset, RegLocation rl_src) OVERRIDE; |
| 185 | void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double) OVERRIDE; |
| 186 | void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) OVERRIDE; |
| 187 | void GenSelect(BasicBlock* bb, MIR* mir) OVERRIDE; |
| 188 | void GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code, |
| 189 | int32_t true_val, int32_t false_val, RegStorage rs_dest, |
| 190 | int dest_reg_class) OVERRIDE; |
Andreas Gampe | 90969af | 2014-07-15 23:02:11 -0700 | [diff] [blame] | 191 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 192 | bool GenMemBarrier(MemBarrierKind barrier_kind) OVERRIDE; |
| 193 | void GenMonitorEnter(int opt_flags, RegLocation rl_src) OVERRIDE; |
| 194 | void GenMonitorExit(int opt_flags, RegLocation rl_src) OVERRIDE; |
| 195 | void GenMoveException(RegLocation rl_dest) OVERRIDE; |
| 196 | void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit, |
| 197 | int first_bit, int second_bit) OVERRIDE; |
| 198 | void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) OVERRIDE; |
| 199 | void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) OVERRIDE; |
Andreas Gampe | 48971b3 | 2014-08-06 10:09:01 -0700 | [diff] [blame] | 200 | void GenLargePackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE; |
| 201 | void GenLargeSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) OVERRIDE; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 202 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 203 | // Required for target - single operation generators. |
| 204 | LIR* OpUnconditionalBranch(LIR* target) OVERRIDE; |
| 205 | LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) OVERRIDE; |
| 206 | LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) OVERRIDE; |
| 207 | LIR* OpCondBranch(ConditionCode cc, LIR* target) OVERRIDE; |
| 208 | LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) OVERRIDE; |
| 209 | LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE; |
| 210 | LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE; |
| 211 | void OpEndIT(LIR* it) OVERRIDE; |
| 212 | LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE; |
| 213 | LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE; |
| 214 | LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE; |
| 215 | void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE; |
| 216 | LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE; |
| 217 | LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value) OVERRIDE; |
| 218 | LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) OVERRIDE; |
| 219 | LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) OVERRIDE; |
| 220 | LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) OVERRIDE; |
| 221 | LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) OVERRIDE; |
| 222 | LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value) OVERRIDE; |
| 223 | LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2) OVERRIDE; |
| 224 | LIR* OpTestSuspend(LIR* target) OVERRIDE; |
| 225 | LIR* OpVldm(RegStorage r_base, int count) OVERRIDE; |
| 226 | LIR* OpVstm(RegStorage r_base, int count) OVERRIDE; |
| 227 | void OpRegCopyWide(RegStorage dest, RegStorage src) OVERRIDE; |
Andreas Gampe | f29ecd6 | 2014-07-29 00:35:00 -0700 | [diff] [blame] | 228 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 229 | bool InexpensiveConstantInt(int32_t value) OVERRIDE; |
Matteo Franchin | c763e35 | 2014-07-04 12:53:27 +0100 | [diff] [blame] | 230 | bool InexpensiveConstantInt(int32_t value, Instruction::Code opcode) OVERRIDE; |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 231 | bool InexpensiveConstantFloat(int32_t value) OVERRIDE; |
| 232 | bool InexpensiveConstantLong(int64_t value) OVERRIDE; |
| 233 | bool InexpensiveConstantDouble(int64_t value) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 234 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 235 | void FlushIns(RegLocation* ArgLocs, RegLocation rl_method) OVERRIDE; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 236 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 237 | int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel, |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 238 | NextCallInsn next_call_insn, |
| 239 | const MethodReference& target_method, |
| 240 | uint32_t vtable_idx, |
| 241 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 242 | bool skip_this) OVERRIDE; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 243 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 244 | int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel, |
| 245 | NextCallInsn next_call_insn, |
| 246 | const MethodReference& target_method, |
| 247 | uint32_t vtable_idx, |
| 248 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
| 249 | bool skip_this) OVERRIDE; |
Serguei Katkov | 59a42af | 2014-07-05 00:55:46 +0700 | [diff] [blame] | 250 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 251 | bool WideGPRsAreAliases() OVERRIDE { |
| 252 | return true; // 64b architecture. |
| 253 | } |
| 254 | bool WideFPRsAreAliases() OVERRIDE { |
| 255 | return true; // 64b architecture. |
| 256 | } |
Andreas Gampe | 9843059 | 2014-07-27 19:44:50 -0700 | [diff] [blame] | 257 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 258 | size_t GetInstructionOffset(LIR* lir) OVERRIDE; |
| 259 | |
| 260 | LIR* InvokeTrampoline(OpKind op, RegStorage r_tgt, QuickEntrypointEnum trampoline) OVERRIDE; |
| 261 | |
| 262 | private: |
| 263 | /** |
| 264 | * @brief Given register xNN (dNN), returns register wNN (sNN). |
| 265 | * @param reg #RegStorage containing a Solo64 input register (e.g. @c x1 or @c d2). |
| 266 | * @return A Solo32 with the same register number as the @p reg (e.g. @c w1 or @c s2). |
| 267 | * @see As64BitReg |
| 268 | */ |
| 269 | RegStorage As32BitReg(RegStorage reg) { |
| 270 | DCHECK(!reg.IsPair()); |
| 271 | if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) { |
| 272 | if (kFailOnSizeError) { |
| 273 | LOG(FATAL) << "Expected 64b register"; |
| 274 | } else { |
| 275 | LOG(WARNING) << "Expected 64b register"; |
| 276 | return reg; |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 277 | } |
Matteo Franchin | 5acc8b0 | 2014-06-05 15:10:35 +0100 | [diff] [blame] | 278 | } |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 279 | RegStorage ret_val = RegStorage(RegStorage::k32BitSolo, |
| 280 | reg.GetRawBits() & RegStorage::kRegTypeMask); |
| 281 | DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask) |
| 282 | ->GetReg().GetReg(), |
| 283 | ret_val.GetReg()); |
| 284 | return ret_val; |
| 285 | } |
Matteo Franchin | 5acc8b0 | 2014-06-05 15:10:35 +0100 | [diff] [blame] | 286 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 287 | RegStorage Check32BitReg(RegStorage reg) { |
| 288 | if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) { |
| 289 | if (kFailOnSizeError) { |
| 290 | LOG(FATAL) << "Checked for 32b register"; |
| 291 | } else { |
| 292 | LOG(WARNING) << "Checked for 32b register"; |
| 293 | return As32BitReg(reg); |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 294 | } |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 295 | } |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 296 | return reg; |
| 297 | } |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 298 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 299 | /** |
| 300 | * @brief Given register wNN (sNN), returns register xNN (dNN). |
| 301 | * @param reg #RegStorage containing a Solo32 input register (e.g. @c w1 or @c s2). |
| 302 | * @return A Solo64 with the same register number as the @p reg (e.g. @c x1 or @c d2). |
| 303 | * @see As32BitReg |
| 304 | */ |
| 305 | RegStorage As64BitReg(RegStorage reg) { |
| 306 | DCHECK(!reg.IsPair()); |
| 307 | if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) { |
| 308 | if (kFailOnSizeError) { |
| 309 | LOG(FATAL) << "Expected 32b register"; |
| 310 | } else { |
| 311 | LOG(WARNING) << "Expected 32b register"; |
| 312 | return reg; |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 313 | } |
Matteo Franchin | 5acc8b0 | 2014-06-05 15:10:35 +0100 | [diff] [blame] | 314 | } |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 315 | RegStorage ret_val = RegStorage(RegStorage::k64BitSolo, |
| 316 | reg.GetRawBits() & RegStorage::kRegTypeMask); |
| 317 | DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask) |
| 318 | ->GetReg().GetReg(), |
| 319 | ret_val.GetReg()); |
| 320 | return ret_val; |
| 321 | } |
Matteo Franchin | 5acc8b0 | 2014-06-05 15:10:35 +0100 | [diff] [blame] | 322 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 323 | RegStorage Check64BitReg(RegStorage reg) { |
| 324 | if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) { |
| 325 | if (kFailOnSizeError) { |
| 326 | LOG(FATAL) << "Checked for 64b register"; |
| 327 | } else { |
| 328 | LOG(WARNING) << "Checked for 64b register"; |
| 329 | return As64BitReg(reg); |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 330 | } |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 331 | } |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 332 | return reg; |
| 333 | } |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 334 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 335 | int32_t EncodeImmSingle(uint32_t bits); |
| 336 | int32_t EncodeImmDouble(uint64_t bits); |
| 337 | LIR* LoadFPConstantValue(RegStorage r_dest, int32_t value); |
| 338 | LIR* LoadFPConstantValueWide(RegStorage r_dest, int64_t value); |
| 339 | void ReplaceFixup(LIR* prev_lir, LIR* orig_lir, LIR* new_lir); |
| 340 | void InsertFixupBefore(LIR* prev_lir, LIR* orig_lir, LIR* new_lir); |
| 341 | void AssignDataOffsets(); |
| 342 | RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 343 | bool is_div, bool check_zero); |
| 344 | RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div); |
| 345 | size_t GetLoadStoreSize(LIR* lir); |
| 346 | |
| 347 | bool SmallLiteralDivRem64(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src, |
| 348 | RegLocation rl_dest, int64_t lit); |
| 349 | |
| 350 | uint32_t LinkFixupInsns(LIR* head_lir, LIR* tail_lir, CodeOffset offset); |
| 351 | int AssignInsnOffsets(); |
| 352 | void AssignOffsets(); |
| 353 | uint8_t* EncodeLIRs(uint8_t* write_pos, LIR* lir); |
| 354 | |
| 355 | // Spill core and FP registers. Returns the SP difference: either spill size, or whole |
| 356 | // frame size. |
| 357 | int SpillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size); |
| 358 | |
| 359 | // Unspill core and FP registers. |
| 360 | void UnspillRegs(RegStorage base, uint32_t core_reg_mask, uint32_t fp_reg_mask, int frame_size); |
| 361 | |
| 362 | void GenLongOp(OpKind op, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); |
| 363 | |
| 364 | LIR* OpRegImm64(OpKind op, RegStorage r_dest_src1, int64_t value); |
| 365 | LIR* OpRegRegImm64(OpKind op, RegStorage r_dest, RegStorage r_src1, int64_t value); |
| 366 | |
| 367 | LIR* OpRegRegShift(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, int shift); |
| 368 | LIR* OpRegRegRegShift(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2, |
| 369 | int shift); |
| 370 | int EncodeShift(int code, int amount); |
| 371 | |
| 372 | LIR* OpRegRegExtend(OpKind op, RegStorage r_dest_src1, RegStorage r_src2, |
| 373 | A64RegExtEncodings ext, uint8_t amount); |
| 374 | LIR* OpRegRegRegExtend(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2, |
| 375 | A64RegExtEncodings ext, uint8_t amount); |
| 376 | int EncodeExtend(int extend_type, int amount); |
| 377 | bool IsExtendEncoding(int encoded_value); |
| 378 | |
| 379 | LIR* LoadBaseDispBody(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size); |
| 380 | LIR* StoreBaseDispBody(RegStorage r_base, int displacement, RegStorage r_src, OpSize size); |
| 381 | |
| 382 | int EncodeLogicalImmediate(bool is_wide, uint64_t value); |
| 383 | uint64_t DecodeLogicalImmediate(bool is_wide, int value); |
| 384 | ArmConditionCode ArmConditionEncoding(ConditionCode code); |
| 385 | |
| 386 | // Helper used in the two GenSelect variants. |
| 387 | void GenSelect(int32_t left, int32_t right, ConditionCode code, RegStorage rs_dest, |
| 388 | int result_reg_class); |
| 389 | |
Andreas Gampe | c76c614 | 2014-08-04 16:30:03 -0700 | [diff] [blame] | 390 | void GenNotLong(RegLocation rl_dest, RegLocation rl_src); |
| 391 | void GenNegLong(RegLocation rl_dest, RegLocation rl_src); |
| 392 | void GenDivRemLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 393 | RegLocation rl_src2, bool is_div); |
| 394 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 395 | InToRegStorageMapping in_to_reg_storage_mapping_; |
| 396 | static const ArmEncodingMap EncodingMap[kA64Last]; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 397 | }; |
| 398 | |
| 399 | } // namespace art |
| 400 | |
| 401 | #endif // ART_COMPILER_DEX_QUICK_ARM64_CODEGEN_ARM64_H_ |