Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_ |
| 18 | #define ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | |
| 20 | #include "dex/compiler_internals.h" |
| 21 | #include "x86_lir.h" |
| 22 | |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 23 | #include <map> |
| 24 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 25 | namespace art { |
| 26 | |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 27 | class X86Mir2Lir : public Mir2Lir { |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 28 | protected: |
| 29 | class InToRegStorageMapper { |
| 30 | public: |
Serguei Katkov | 407a9d2 | 2014-07-05 03:09:32 +0700 | [diff] [blame] | 31 | virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref) = 0; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 32 | virtual ~InToRegStorageMapper() {} |
| 33 | }; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 34 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 35 | class InToRegStorageX86_64Mapper : public InToRegStorageMapper { |
| 36 | public: |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 37 | explicit InToRegStorageX86_64Mapper(Mir2Lir* ml) : ml_(ml), cur_core_reg_(0), cur_fp_reg_(0) {} |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 38 | virtual ~InToRegStorageX86_64Mapper() {} |
Serguei Katkov | 407a9d2 | 2014-07-05 03:09:32 +0700 | [diff] [blame] | 39 | virtual RegStorage GetNextReg(bool is_double_or_float, bool is_wide, bool is_ref); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 40 | protected: |
| 41 | Mir2Lir* ml_; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 42 | private: |
| 43 | int cur_core_reg_; |
| 44 | int cur_fp_reg_; |
| 45 | }; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 46 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 47 | class InToRegStorageMapping { |
| 48 | public: |
| 49 | InToRegStorageMapping() : max_mapped_in_(0), is_there_stack_mapped_(false), |
| 50 | initialized_(false) {} |
| 51 | void Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper); |
| 52 | int GetMaxMappedIn() { return max_mapped_in_; } |
| 53 | bool IsThereStackMapped() { return is_there_stack_mapped_; } |
| 54 | RegStorage Get(int in_position); |
| 55 | bool IsInitialized() { return initialized_; } |
| 56 | private: |
| 57 | std::map<int, RegStorage> mapping_; |
| 58 | int max_mapped_in_; |
| 59 | bool is_there_stack_mapped_; |
| 60 | bool initialized_; |
| 61 | }; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 62 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 63 | public: |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 64 | X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 65 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 66 | // Required for target - codegen helpers. |
| 67 | bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src, |
| 68 | RegLocation rl_dest, int lit); |
| 69 | bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE; |
| 70 | LIR* CheckSuspendUsingLoad() OVERRIDE; |
| 71 | RegStorage LoadHelper(ThreadOffset<4> offset) OVERRIDE; |
| 72 | RegStorage LoadHelper(ThreadOffset<8> offset) OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 73 | LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 74 | OpSize size, VolatileKind is_volatile) OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 75 | 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] | 76 | OpSize size) OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 77 | LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, |
| 78 | RegStorage r_dest, OpSize size) OVERRIDE; |
| 79 | LIR* LoadConstantNoClobber(RegStorage r_dest, int value); |
| 80 | LIR* LoadConstantWide(RegStorage r_dest, int64_t value); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 81 | LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 82 | OpSize size, VolatileKind is_volatile) OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 83 | LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale, |
| 84 | OpSize size) OVERRIDE; |
| 85 | LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, |
| 86 | RegStorage r_src, OpSize size) OVERRIDE; |
| 87 | void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 88 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 89 | // Required for target - register utilities. |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 90 | RegStorage TargetReg(SpecialTargetRegister reg) OVERRIDE; |
| 91 | RegStorage TargetReg32(SpecialTargetRegister reg); |
Andreas Gampe | ccc6026 | 2014-07-04 18:02:38 -0700 | [diff] [blame] | 92 | RegStorage TargetReg(SpecialTargetRegister symbolic_reg, WideKind wide_kind) OVERRIDE { |
| 93 | if (wide_kind == kWide) { |
| 94 | if (cu_->target64) { |
| 95 | return As64BitReg(TargetReg32(symbolic_reg)); |
| 96 | } else { |
| 97 | // x86: construct a pair. |
| 98 | DCHECK((kArg0 <= symbolic_reg && symbolic_reg < kArg3) || |
| 99 | (kFArg0 <= symbolic_reg && symbolic_reg < kFArg3) || |
| 100 | (kRet0 == symbolic_reg)); |
| 101 | return RegStorage::MakeRegPair(TargetReg32(symbolic_reg), |
| 102 | TargetReg32(static_cast<SpecialTargetRegister>(symbolic_reg + 1))); |
| 103 | } |
| 104 | } else if (wide_kind == kRef && cu_->target64) { |
| 105 | return As64BitReg(TargetReg32(symbolic_reg)); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 106 | } else { |
Andreas Gampe | ccc6026 | 2014-07-04 18:02:38 -0700 | [diff] [blame] | 107 | return TargetReg32(symbolic_reg); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 108 | } |
| 109 | } |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 110 | RegStorage TargetPtrReg(SpecialTargetRegister symbolic_reg) OVERRIDE { |
Andreas Gampe | ccc6026 | 2014-07-04 18:02:38 -0700 | [diff] [blame] | 111 | return TargetReg(symbolic_reg, cu_->target64 ? kWide : kNotWide); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 112 | } |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 113 | RegStorage GetArgMappingToPhysicalReg(int arg_num); |
| 114 | RegStorage GetCoreArgMappingToPhysicalReg(int core_arg_num); |
| 115 | RegLocation GetReturnAlt(); |
| 116 | RegLocation GetReturnWideAlt(); |
| 117 | RegLocation LocCReturn(); |
| 118 | RegLocation LocCReturnRef(); |
| 119 | RegLocation LocCReturnDouble(); |
| 120 | RegLocation LocCReturnFloat(); |
| 121 | RegLocation LocCReturnWide(); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 122 | ResourceMask GetRegMaskCommon(const RegStorage& reg) const OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 123 | void AdjustSpillMask(); |
| 124 | void ClobberCallerSave(); |
| 125 | void FreeCallTemps(); |
| 126 | void LockCallTemps(); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 127 | void CompilerInitializeRegAlloc(); |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 128 | int VectorRegisterSize(); |
| 129 | int NumReservableVectorRegisters(bool fp_used); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 130 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 131 | // Required for target - miscellaneous. |
| 132 | void AssembleLIR(); |
| 133 | int AssignInsnOffsets(); |
| 134 | void AssignOffsets(); |
| 135 | AssemblerStatus AssembleInstructions(CodeOffset start_addr); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 136 | void DumpResourceMask(LIR* lir, const ResourceMask& mask, const char* prefix) OVERRIDE; |
| 137 | void SetupTargetResourceMasks(LIR* lir, uint64_t flags, |
| 138 | ResourceMask* use_mask, ResourceMask* def_mask) OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 139 | const char* GetTargetInstFmt(int opcode); |
| 140 | const char* GetTargetInstName(int opcode); |
| 141 | std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 142 | ResourceMask GetPCUseDefEncoding() const OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 143 | uint64_t GetTargetInstFlags(int opcode); |
Ian Rogers | 5aa6e04 | 2014-06-13 16:38:24 -0700 | [diff] [blame] | 144 | size_t GetInsnSize(LIR* lir) OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 145 | bool IsUnconditionalBranch(LIR* lir); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 146 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 147 | // Check support for volatile load/store of a given size. |
| 148 | bool SupportsVolatileLoadStore(OpSize size) OVERRIDE; |
| 149 | // Get the register class for load/store of a field. |
| 150 | RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE; |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 151 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 152 | // Required for target - Dalvik-level generators. |
| 153 | void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 154 | RegLocation rl_src2); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 155 | void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index, |
| 156 | RegLocation rl_dest, int scale); |
| 157 | void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, |
| 158 | RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark); |
| 159 | void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 160 | RegLocation rl_src1, RegLocation rl_shift); |
| 161 | void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 162 | RegLocation rl_src2); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 163 | void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 164 | RegLocation rl_src2); |
| 165 | void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 166 | RegLocation rl_src2); |
| 167 | void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 168 | RegLocation rl_src2); |
| 169 | void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 170 | RegLocation rl_src2); |
Alexei Zavjalov | bd3682e | 2014-06-12 03:08:01 +0700 | [diff] [blame] | 171 | void GenRemFP(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_double); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 172 | void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 173 | RegLocation rl_src2); |
| 174 | void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src); |
| 175 | bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 176 | bool GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 177 | bool GenInlinedSqrt(CallInfo* info); |
Yixin Shou | 7071c8d | 2014-03-05 06:07:48 -0500 | [diff] [blame] | 178 | bool GenInlinedAbsFloat(CallInfo* info) OVERRIDE; |
| 179 | bool GenInlinedAbsDouble(CallInfo* info) OVERRIDE; |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 180 | bool GenInlinedPeek(CallInfo* info, OpSize size); |
| 181 | bool GenInlinedPoke(CallInfo* info, OpSize size); |
| 182 | void GenNotLong(RegLocation rl_dest, RegLocation rl_src); |
| 183 | void GenNegLong(RegLocation rl_dest, RegLocation rl_src); |
| 184 | void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 185 | RegLocation rl_src2); |
| 186 | void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 187 | RegLocation rl_src2); |
| 188 | void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 189 | RegLocation rl_src2); |
| 190 | void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1, |
| 191 | RegLocation rl_src2, bool is_div); |
| 192 | // TODO: collapse reg_lo, reg_hi |
| 193 | RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div); |
| 194 | RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div); |
| 195 | void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); |
| 196 | void GenDivZeroCheckWide(RegStorage reg); |
| 197 | void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset); |
| 198 | void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset); |
| 199 | void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method); |
| 200 | void GenExitSequence(); |
| 201 | void GenSpecialExitSequence(); |
| 202 | void GenFillArrayData(DexOffset table_offset, RegLocation rl_src); |
| 203 | void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double); |
| 204 | void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir); |
| 205 | void GenSelect(BasicBlock* bb, MIR* mir); |
| 206 | bool GenMemBarrier(MemBarrierKind barrier_kind); |
| 207 | void GenMoveException(RegLocation rl_dest); |
| 208 | void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit, |
| 209 | int first_bit, int second_bit); |
| 210 | void GenNegDouble(RegLocation rl_dest, RegLocation rl_src); |
| 211 | void GenNegFloat(RegLocation rl_dest, RegLocation rl_src); |
| 212 | void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src); |
| 213 | void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src); |
| 214 | void GenIntToLong(RegLocation rl_dest, RegLocation rl_src); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 215 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 216 | /* |
| 217 | * @brief Generate a two address long operation with a constant value |
| 218 | * @param rl_dest location of result |
| 219 | * @param rl_src constant source operand |
| 220 | * @param op Opcode to be generated |
| 221 | * @return success or not |
| 222 | */ |
| 223 | bool GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); |
| 224 | /* |
| 225 | * @brief Generate a three address long operation with a constant value |
| 226 | * @param rl_dest location of result |
| 227 | * @param rl_src1 source operand |
| 228 | * @param rl_src2 constant source operand |
| 229 | * @param op Opcode to be generated |
| 230 | * @return success or not |
| 231 | */ |
| 232 | bool GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 233 | Instruction::Code op); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 234 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 235 | /** |
| 236 | * @brief Generate a long arithmetic operation. |
| 237 | * @param rl_dest The destination. |
| 238 | * @param rl_src1 First operand. |
| 239 | * @param rl_src2 Second operand. |
| 240 | * @param op The DEX opcode for the operation. |
| 241 | * @param is_commutative The sources can be swapped if needed. |
| 242 | */ |
| 243 | virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 244 | Instruction::Code op, bool is_commutative); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 245 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 246 | /** |
| 247 | * @brief Generate a two operand long arithmetic operation. |
| 248 | * @param rl_dest The destination. |
| 249 | * @param rl_src Second operand. |
| 250 | * @param op The DEX opcode for the operation. |
| 251 | */ |
| 252 | void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 253 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 254 | /** |
| 255 | * @brief Generate a long operation. |
| 256 | * @param rl_dest The destination. Must be in a register |
| 257 | * @param rl_src The other operand. May be in a register or in memory. |
| 258 | * @param op The DEX opcode for the operation. |
| 259 | */ |
| 260 | virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 261 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 262 | /** |
| 263 | * @brief Implement instanceof a final class with x86 specific code. |
| 264 | * @param use_declaring_class 'true' if we can use the class itself. |
| 265 | * @param type_idx Type index to use if use_declaring_class is 'false'. |
| 266 | * @param rl_dest Result to be set to 0 or 1. |
| 267 | * @param rl_src Object to be tested. |
| 268 | */ |
| 269 | void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest, |
| 270 | RegLocation rl_src); |
| 271 | /* |
| 272 | * |
| 273 | * @brief Implement Set up instanceof a class with x86 specific code. |
| 274 | * @param needs_access_check 'true' if we must check the access. |
| 275 | * @param type_known_final 'true' if the type is known to be a final class. |
| 276 | * @param type_known_abstract 'true' if the type is known to be an abstract class. |
| 277 | * @param use_declaring_class 'true' if the type can be loaded off the current Method*. |
| 278 | * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache. |
| 279 | * @param type_idx Type index to use if use_declaring_class is 'false'. |
| 280 | * @param rl_dest Result to be set to 0 or 1. |
| 281 | * @param rl_src Object to be tested. |
| 282 | */ |
| 283 | void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final, |
| 284 | bool type_known_abstract, bool use_declaring_class, |
| 285 | bool can_assume_type_is_in_dex_cache, |
| 286 | uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src); |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 287 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 288 | void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 289 | RegLocation rl_src1, RegLocation rl_shift); |
Chao-ying Fu | a014776 | 2014-06-06 18:38:49 -0700 | [diff] [blame] | 290 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 291 | // Single operation generators. |
| 292 | LIR* OpUnconditionalBranch(LIR* target); |
| 293 | LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target); |
| 294 | LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target); |
| 295 | LIR* OpCondBranch(ConditionCode cc, LIR* target); |
| 296 | LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target); |
| 297 | LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src); |
| 298 | LIR* OpIT(ConditionCode cond, const char* guide); |
| 299 | void OpEndIT(LIR* it); |
| 300 | LIR* OpMem(OpKind op, RegStorage r_base, int disp); |
| 301 | LIR* OpPcRelLoad(RegStorage reg, LIR* target); |
| 302 | LIR* OpReg(OpKind op, RegStorage r_dest_src); |
| 303 | void OpRegCopy(RegStorage r_dest, RegStorage r_src); |
| 304 | LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src); |
| 305 | LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value); |
| 306 | LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset); |
| 307 | LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value); |
| 308 | LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value); |
| 309 | LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2); |
| 310 | LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type); |
| 311 | LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type); |
| 312 | LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src); |
| 313 | LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value); |
| 314 | LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2); |
| 315 | LIR* OpTestSuspend(LIR* target); |
| 316 | LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE; |
| 317 | LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE; |
| 318 | LIR* OpVldm(RegStorage r_base, int count); |
| 319 | LIR* OpVstm(RegStorage r_base, int count); |
| 320 | void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset); |
| 321 | void OpRegCopyWide(RegStorage dest, RegStorage src); |
| 322 | void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE; |
| 323 | void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 324 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 325 | void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset); |
| 326 | void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset); |
| 327 | void SpillCoreRegs(); |
| 328 | void UnSpillCoreRegs(); |
Serguei Katkov | c380191 | 2014-07-08 17:21:53 +0700 | [diff] [blame] | 329 | void UnSpillFPRegs(); |
| 330 | void SpillFPRegs(); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 331 | static const X86EncodingMap EncodingMap[kX86Last]; |
| 332 | bool InexpensiveConstantInt(int32_t value); |
| 333 | bool InexpensiveConstantFloat(int32_t value); |
| 334 | bool InexpensiveConstantLong(int64_t value); |
| 335 | bool InexpensiveConstantDouble(int64_t value); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 336 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 337 | /* |
| 338 | * @brief Should try to optimize for two address instructions? |
| 339 | * @return true if we try to avoid generating three operand instructions. |
| 340 | */ |
| 341 | virtual bool GenerateTwoOperandInstructions() const { return true; } |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 342 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 343 | /* |
| 344 | * @brief x86 specific codegen for int operations. |
| 345 | * @param opcode Operation to perform. |
| 346 | * @param rl_dest Destination for the result. |
| 347 | * @param rl_lhs Left hand operand. |
| 348 | * @param rl_rhs Right hand operand. |
| 349 | */ |
| 350 | void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs, |
| 351 | RegLocation rl_rhs); |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 352 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 353 | /* |
| 354 | * @brief Dump a RegLocation using printf |
| 355 | * @param loc Register location to dump |
| 356 | */ |
| 357 | static void DumpRegLocation(RegLocation loc); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 358 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 359 | /* |
| 360 | * @brief Load the Method* of a dex method into the register. |
| 361 | * @param target_method The MethodReference of the method to be invoked. |
| 362 | * @param type How the method will be invoked. |
| 363 | * @param register that will contain the code address. |
| 364 | * @note register will be passed to TargetReg to get physical register. |
| 365 | */ |
| 366 | void LoadMethodAddress(const MethodReference& target_method, InvokeType type, |
| 367 | SpecialTargetRegister symbolic_reg); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 368 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 369 | /* |
| 370 | * @brief Load the Class* of a Dex Class type into the register. |
| 371 | * @param type How the method will be invoked. |
| 372 | * @param register that will contain the code address. |
| 373 | * @note register will be passed to TargetReg to get physical register. |
| 374 | */ |
| 375 | void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 376 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 377 | void FlushIns(RegLocation* ArgLocs, RegLocation rl_method); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 378 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 379 | int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel, |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 380 | NextCallInsn next_call_insn, |
| 381 | const MethodReference& target_method, |
| 382 | uint32_t vtable_idx, |
| 383 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
| 384 | bool skip_this); |
| 385 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 386 | int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel, |
| 387 | NextCallInsn next_call_insn, |
| 388 | const MethodReference& target_method, |
| 389 | uint32_t vtable_idx, |
| 390 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
| 391 | bool skip_this); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 392 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 393 | /* |
| 394 | * @brief Generate a relative call to the method that will be patched at link time. |
| 395 | * @param target_method The MethodReference of the method to be invoked. |
| 396 | * @param type How the method will be invoked. |
| 397 | * @returns Call instruction |
| 398 | */ |
| 399 | virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 400 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 401 | /* |
| 402 | * @brief Handle x86 specific literals |
| 403 | */ |
| 404 | void InstallLiteralPools(); |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 405 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 406 | /* |
| 407 | * @brief Generate the debug_frame CFI information. |
| 408 | * @returns pointer to vector containing CFE information |
| 409 | */ |
| 410 | static std::vector<uint8_t>* ReturnCommonCallFrameInformation(); |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 411 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 412 | /* |
| 413 | * @brief Generate the debug_frame FDE information. |
| 414 | * @returns pointer to vector containing CFE information |
| 415 | */ |
| 416 | std::vector<uint8_t>* ReturnCallFrameInformation(); |
Razvan A Lupusoru | bd288c2 | 2013-12-20 17:27:23 -0800 | [diff] [blame] | 417 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 418 | protected: |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 419 | // Casting of RegStorage |
| 420 | RegStorage As32BitReg(RegStorage reg) { |
| 421 | DCHECK(!reg.IsPair()); |
| 422 | if ((kFailOnSizeError || kReportSizeError) && !reg.Is64Bit()) { |
| 423 | if (kFailOnSizeError) { |
| 424 | LOG(FATAL) << "Expected 64b register " << reg.GetReg(); |
| 425 | } else { |
| 426 | LOG(WARNING) << "Expected 64b register " << reg.GetReg(); |
| 427 | return reg; |
| 428 | } |
| 429 | } |
| 430 | RegStorage ret_val = RegStorage(RegStorage::k32BitSolo, |
| 431 | reg.GetRawBits() & RegStorage::kRegTypeMask); |
| 432 | DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k32SoloStorageMask) |
| 433 | ->GetReg().GetReg(), |
| 434 | ret_val.GetReg()); |
| 435 | return ret_val; |
| 436 | } |
| 437 | |
| 438 | RegStorage As64BitReg(RegStorage reg) { |
| 439 | DCHECK(!reg.IsPair()); |
| 440 | if ((kFailOnSizeError || kReportSizeError) && !reg.Is32Bit()) { |
| 441 | if (kFailOnSizeError) { |
| 442 | LOG(FATAL) << "Expected 32b register " << reg.GetReg(); |
| 443 | } else { |
| 444 | LOG(WARNING) << "Expected 32b register " << reg.GetReg(); |
| 445 | return reg; |
| 446 | } |
| 447 | } |
| 448 | RegStorage ret_val = RegStorage(RegStorage::k64BitSolo, |
| 449 | reg.GetRawBits() & RegStorage::kRegTypeMask); |
| 450 | DCHECK_EQ(GetRegInfo(reg)->FindMatchingView(RegisterInfo::k64SoloStorageMask) |
| 451 | ->GetReg().GetReg(), |
| 452 | ret_val.GetReg()); |
| 453 | return ret_val; |
| 454 | } |
| 455 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 456 | size_t ComputeSize(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_index, |
Ian Rogers | 5aa6e04 | 2014-06-13 16:38:24 -0700 | [diff] [blame] | 457 | int32_t raw_base, int32_t displacement); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 458 | void CheckValidByteRegister(const X86EncodingMap* entry, int32_t raw_reg); |
| 459 | void EmitPrefix(const X86EncodingMap* entry, |
Ian Rogers | 5aa6e04 | 2014-06-13 16:38:24 -0700 | [diff] [blame] | 460 | int32_t raw_reg_r, int32_t raw_reg_x, int32_t raw_reg_b); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 461 | void EmitOpcode(const X86EncodingMap* entry); |
| 462 | void EmitPrefixAndOpcode(const X86EncodingMap* entry, |
Ian Rogers | 5aa6e04 | 2014-06-13 16:38:24 -0700 | [diff] [blame] | 463 | int32_t reg_r, int32_t reg_x, int32_t reg_b); |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 464 | void EmitDisp(uint8_t base, int32_t disp); |
| 465 | void EmitModrmThread(uint8_t reg_or_opcode); |
| 466 | void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int32_t disp); |
| 467 | void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale, |
| 468 | int32_t disp); |
| 469 | void EmitImm(const X86EncodingMap* entry, int64_t imm); |
| 470 | void EmitNullary(const X86EncodingMap* entry); |
| 471 | void EmitOpRegOpcode(const X86EncodingMap* entry, int32_t raw_reg); |
| 472 | void EmitOpReg(const X86EncodingMap* entry, int32_t raw_reg); |
| 473 | void EmitOpMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp); |
| 474 | void EmitOpArray(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale, |
| 475 | int32_t disp); |
| 476 | void EmitMemReg(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_reg); |
| 477 | void EmitRegMem(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, int32_t disp); |
| 478 | void EmitRegArray(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base, |
| 479 | int32_t raw_index, int scale, int32_t disp); |
| 480 | void EmitArrayReg(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale, |
| 481 | int32_t disp, int32_t raw_reg); |
| 482 | void EmitMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm); |
| 483 | void EmitArrayImm(const X86EncodingMap* entry, int32_t raw_base, int32_t raw_index, int scale, |
| 484 | int32_t raw_disp, int32_t imm); |
| 485 | void EmitRegThread(const X86EncodingMap* entry, int32_t raw_reg, int32_t disp); |
| 486 | void EmitRegReg(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2); |
| 487 | void EmitRegRegImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t imm); |
| 488 | void EmitRegMemImm(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp, |
| 489 | int32_t imm); |
| 490 | void EmitMemRegImm(const X86EncodingMap* entry, int32_t base, int32_t disp, int32_t raw_reg1, |
| 491 | int32_t imm); |
| 492 | void EmitRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm); |
| 493 | void EmitThreadImm(const X86EncodingMap* entry, int32_t disp, int32_t imm); |
| 494 | void EmitMovRegImm(const X86EncodingMap* entry, int32_t raw_reg, int64_t imm); |
| 495 | void EmitShiftRegImm(const X86EncodingMap* entry, int32_t raw_reg, int32_t imm); |
| 496 | void EmitShiftRegCl(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_cl); |
| 497 | void EmitShiftMemCl(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t raw_cl); |
| 498 | void EmitShiftMemImm(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t imm); |
| 499 | void EmitRegCond(const X86EncodingMap* entry, int32_t raw_reg, int32_t cc); |
| 500 | void EmitMemCond(const X86EncodingMap* entry, int32_t raw_base, int32_t disp, int32_t cc); |
| 501 | void EmitRegRegCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_reg2, int32_t cc); |
| 502 | void EmitRegMemCond(const X86EncodingMap* entry, int32_t raw_reg1, int32_t raw_base, int32_t disp, |
| 503 | int32_t cc); |
Razvan A Lupusoru | bd288c2 | 2013-12-20 17:27:23 -0800 | [diff] [blame] | 504 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 505 | void EmitJmp(const X86EncodingMap* entry, int32_t rel); |
| 506 | void EmitJcc(const X86EncodingMap* entry, int32_t rel, int32_t cc); |
| 507 | void EmitCallMem(const X86EncodingMap* entry, int32_t raw_base, int32_t disp); |
| 508 | void EmitCallImmediate(const X86EncodingMap* entry, int32_t disp); |
| 509 | void EmitCallThread(const X86EncodingMap* entry, int32_t disp); |
| 510 | void EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t raw_base_or_table, |
| 511 | int32_t raw_index, int scale, int32_t table_or_disp); |
| 512 | void EmitMacro(const X86EncodingMap* entry, int32_t raw_reg, int32_t offset); |
| 513 | void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir); |
| 514 | void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, |
| 515 | int64_t val, ConditionCode ccode); |
| 516 | void GenConstWide(RegLocation rl_dest, int64_t value); |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 517 | void GenMultiplyVectorSignedByte(BasicBlock *bb, MIR *mir); |
| 518 | void GenShiftByteVector(BasicBlock *bb, MIR *mir); |
| 519 | void AndMaskVectorRegister(RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4); |
| 520 | void MaskVectorRegister(X86OpCode opcode, RegStorage rs_src1, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4); |
| 521 | void AppendOpcodeWithConst(X86OpCode opcode, int reg, MIR* mir); |
Mark Mendell | 2637f2e | 2014-04-30 10:10:47 -0400 | [diff] [blame] | 522 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 523 | static bool ProvidesFullMemoryBarrier(X86OpCode opcode); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 524 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 525 | /* |
| 526 | * @brief Ensure that a temporary register is byte addressable. |
| 527 | * @returns a temporary guarenteed to be byte addressable. |
| 528 | */ |
| 529 | virtual RegStorage AllocateByteRegister(); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 530 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 531 | /* |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 532 | * @brief Use a wide temporary as a 128-bit register |
| 533 | * @returns a 128-bit temporary register. |
| 534 | */ |
| 535 | virtual RegStorage Get128BitRegister(RegStorage reg); |
| 536 | |
| 537 | /* |
Chao-ying Fu | 7e399fd | 2014-06-10 18:11:11 -0700 | [diff] [blame] | 538 | * @brief Check if a register is byte addressable. |
| 539 | * @returns true if a register is byte addressable. |
| 540 | */ |
| 541 | bool IsByteRegister(RegStorage reg); |
DaniilSokolov | 70c4f06 | 2014-06-24 17:34:00 -0700 | [diff] [blame] | 542 | bool GenInlinedArrayCopyCharArray(CallInfo* info) OVERRIDE; |
Chao-ying Fu | 7e399fd | 2014-06-10 18:11:11 -0700 | [diff] [blame] | 543 | |
| 544 | /* |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 545 | * @brief generate inline code for fast case of Strng.indexOf. |
| 546 | * @param info Call parameters |
| 547 | * @param zero_based 'true' if the index into the string is 0. |
| 548 | * @returns 'true' if the call was inlined, 'false' if a regular call needs to be |
| 549 | * generated. |
| 550 | */ |
| 551 | bool GenInlinedIndexOf(CallInfo* info, bool zero_based); |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 552 | |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 553 | /** |
| 554 | * @brief Reserve a fixed number of vector registers from the register pool |
| 555 | * @details The mir->dalvikInsn.vA specifies an N such that vector registers |
| 556 | * [0..N-1] are removed from the temporary pool. The caller must call |
| 557 | * ReturnVectorRegisters before calling ReserveVectorRegisters again. |
| 558 | * Also sets the num_reserved_vector_regs_ to the specified value |
| 559 | * @param mir whose vA specifies the number of registers to reserve |
| 560 | */ |
| 561 | void ReserveVectorRegisters(MIR* mir); |
| 562 | |
| 563 | /** |
| 564 | * @brief Return all the reserved vector registers to the temp pool |
| 565 | * @details Returns [0..num_reserved_vector_regs_] |
| 566 | */ |
| 567 | void ReturnVectorRegisters(); |
| 568 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 569 | /* |
| 570 | * @brief Load 128 bit constant into vector register. |
| 571 | * @param bb The basic block in which the MIR is from. |
| 572 | * @param mir The MIR whose opcode is kMirConstVector |
| 573 | * @note vA is the TypeSize for the register. |
| 574 | * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values. |
| 575 | */ |
| 576 | void GenConst128(BasicBlock* bb, MIR* mir); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 577 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 578 | /* |
| 579 | * @brief MIR to move a vectorized register to another. |
| 580 | * @param bb The basic block in which the MIR is from. |
| 581 | * @param mir The MIR whose opcode is kMirConstVector. |
| 582 | * @note vA: TypeSize |
| 583 | * @note vB: destination |
| 584 | * @note vC: source |
| 585 | */ |
| 586 | void GenMoveVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 587 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 588 | /* |
| 589 | * @brief Packed multiply of units in two vector registers: vB = vB .* @note vC using vA to know the type of the vector. |
| 590 | * @param bb The basic block in which the MIR is from. |
| 591 | * @param mir The MIR whose opcode is kMirConstVector. |
| 592 | * @note vA: TypeSize |
| 593 | * @note vB: destination and source |
| 594 | * @note vC: source |
| 595 | */ |
| 596 | void GenMultiplyVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 597 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 598 | /* |
| 599 | * @brief Packed addition of units in two vector registers: vB = vB .+ vC using vA to know the type of the vector. |
| 600 | * @param bb The basic block in which the MIR is from. |
| 601 | * @param mir The MIR whose opcode is kMirConstVector. |
| 602 | * @note vA: TypeSize |
| 603 | * @note vB: destination and source |
| 604 | * @note vC: source |
| 605 | */ |
| 606 | void GenAddVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 607 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 608 | /* |
| 609 | * @brief Packed subtraction of units in two vector registers: vB = vB .- vC using vA to know the type of the vector. |
| 610 | * @param bb The basic block in which the MIR is from. |
| 611 | * @param mir The MIR whose opcode is kMirConstVector. |
| 612 | * @note vA: TypeSize |
| 613 | * @note vB: destination and source |
| 614 | * @note vC: source |
| 615 | */ |
| 616 | void GenSubtractVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 617 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 618 | /* |
| 619 | * @brief Packed shift left of units in two vector registers: vB = vB .<< vC using vA to know the type of the vector. |
| 620 | * @param bb The basic block in which the MIR is from. |
| 621 | * @param mir The MIR whose opcode is kMirConstVector. |
| 622 | * @note vA: TypeSize |
| 623 | * @note vB: destination and source |
| 624 | * @note vC: immediate |
| 625 | */ |
| 626 | void GenShiftLeftVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 627 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 628 | /* |
| 629 | * @brief Packed signed shift right of units in two vector registers: vB = vB .>> vC using vA to know the type of the vector. |
| 630 | * @param bb The basic block in which the MIR is from. |
| 631 | * @param mir The MIR whose opcode is kMirConstVector. |
| 632 | * @note vA: TypeSize |
| 633 | * @note vB: destination and source |
| 634 | * @note vC: immediate |
| 635 | */ |
| 636 | void GenSignedShiftRightVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 637 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 638 | /* |
| 639 | * @brief Packed unsigned shift right of units in two vector registers: vB = vB .>>> vC using vA to know the type of the vector. |
| 640 | * @param bb The basic block in which the MIR is from.. |
| 641 | * @param mir The MIR whose opcode is kMirConstVector. |
| 642 | * @note vA: TypeSize |
| 643 | * @note vB: destination and source |
| 644 | * @note vC: immediate |
| 645 | */ |
| 646 | void GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 647 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 648 | /* |
| 649 | * @brief Packed bitwise and of units in two vector registers: vB = vB .& vC using vA to know the type of the vector. |
| 650 | * @note vA: TypeSize |
| 651 | * @note vB: destination and source |
| 652 | * @note vC: source |
| 653 | */ |
| 654 | void GenAndVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 655 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 656 | /* |
| 657 | * @brief Packed bitwise or of units in two vector registers: vB = vB .| vC using vA to know the type of the vector. |
| 658 | * @param bb The basic block in which the MIR is from. |
| 659 | * @param mir The MIR whose opcode is kMirConstVector. |
| 660 | * @note vA: TypeSize |
| 661 | * @note vB: destination and source |
| 662 | * @note vC: source |
| 663 | */ |
| 664 | void GenOrVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 665 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 666 | /* |
| 667 | * @brief Packed bitwise xor of units in two vector registers: vB = vB .^ vC using vA to know the type of the vector. |
| 668 | * @param bb The basic block in which the MIR is from. |
| 669 | * @param mir The MIR whose opcode is kMirConstVector. |
| 670 | * @note vA: TypeSize |
| 671 | * @note vB: destination and source |
| 672 | * @note vC: source |
| 673 | */ |
| 674 | void GenXorVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 675 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 676 | /* |
| 677 | * @brief Reduce a 128-bit packed element into a single VR by taking lower bits |
| 678 | * @param bb The basic block in which the MIR is from. |
| 679 | * @param mir The MIR whose opcode is kMirConstVector. |
| 680 | * @details Instruction does a horizontal addition of the packed elements and then adds it to VR. |
| 681 | * @note vA: TypeSize |
| 682 | * @note vB: destination and source VR (not vector register) |
| 683 | * @note vC: source (vector register) |
| 684 | */ |
| 685 | void GenAddReduceVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 686 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 687 | /* |
| 688 | * @brief Extract a packed element into a single VR. |
| 689 | * @param bb The basic block in which the MIR is from. |
| 690 | * @param mir The MIR whose opcode is kMirConstVector. |
| 691 | * @note vA: TypeSize |
| 692 | * @note vB: destination VR (not vector register) |
| 693 | * @note vC: source (vector register) |
| 694 | * @note arg[0]: The index to use for extraction from vector register (which packed element). |
| 695 | */ |
| 696 | void GenReduceVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 697 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 698 | /* |
| 699 | * @brief Create a vector value, with all TypeSize values equal to vC |
| 700 | * @param bb The basic block in which the MIR is from. |
| 701 | * @param mir The MIR whose opcode is kMirConstVector. |
| 702 | * @note vA: TypeSize. |
| 703 | * @note vB: destination vector register. |
| 704 | * @note vC: source VR (not vector register). |
| 705 | */ |
| 706 | void GenSetVector(BasicBlock *bb, MIR *mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 707 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 708 | /* |
| 709 | * @brief Generate code for a vector opcode. |
| 710 | * @param bb The basic block in which the MIR is from. |
| 711 | * @param mir The MIR whose opcode is a non-standard opcode. |
| 712 | */ |
| 713 | void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 714 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 715 | /* |
| 716 | * @brief Return the correct x86 opcode for the Dex operation |
| 717 | * @param op Dex opcode for the operation |
| 718 | * @param loc Register location of the operand |
| 719 | * @param is_high_op 'true' if this is an operation on the high word |
| 720 | * @param value Immediate value for the operation. Used for byte variants |
| 721 | * @returns the correct x86 opcode to perform the operation |
| 722 | */ |
| 723 | X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value); |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 724 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 725 | /* |
| 726 | * @brief Return the correct x86 opcode for the Dex operation |
| 727 | * @param op Dex opcode for the operation |
| 728 | * @param dest location of the destination. May be register or memory. |
| 729 | * @param rhs Location for the rhs of the operation. May be in register or memory. |
| 730 | * @param is_high_op 'true' if this is an operation on the high word |
| 731 | * @returns the correct x86 opcode to perform the operation |
| 732 | * @note at most one location may refer to memory |
| 733 | */ |
| 734 | X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs, |
| 735 | bool is_high_op); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 736 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 737 | /* |
| 738 | * @brief Is this operation a no-op for this opcode and value |
| 739 | * @param op Dex opcode for the operation |
| 740 | * @param value Immediate value for the operation. |
| 741 | * @returns 'true' if the operation will have no effect |
| 742 | */ |
| 743 | bool IsNoOp(Instruction::Code op, int32_t value); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 744 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 745 | /** |
| 746 | * @brief Calculate magic number and shift for a given divisor |
| 747 | * @param divisor divisor number for calculation |
| 748 | * @param magic hold calculated magic number |
| 749 | * @param shift hold calculated shift |
| 750 | */ |
| 751 | void CalculateMagicAndShift(int divisor, int& magic, int& shift); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 752 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 753 | /* |
| 754 | * @brief Generate an integer div or rem operation. |
| 755 | * @param rl_dest Destination Location. |
| 756 | * @param rl_src1 Numerator Location. |
| 757 | * @param rl_src2 Divisor Location. |
| 758 | * @param is_div 'true' if this is a division, 'false' for a remainder. |
| 759 | * @param check_zero 'true' if an exception should be generated if the divisor is 0. |
| 760 | */ |
| 761 | RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 762 | bool is_div, bool check_zero); |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 763 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 764 | /* |
| 765 | * @brief Generate an integer div or rem operation by a literal. |
| 766 | * @param rl_dest Destination Location. |
| 767 | * @param rl_src Numerator Location. |
| 768 | * @param lit Divisor. |
| 769 | * @param is_div 'true' if this is a division, 'false' for a remainder. |
| 770 | */ |
| 771 | RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div); |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 772 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 773 | /* |
| 774 | * Generate code to implement long shift operations. |
| 775 | * @param opcode The DEX opcode to specify the shift type. |
| 776 | * @param rl_dest The destination. |
| 777 | * @param rl_src The value to be shifted. |
| 778 | * @param shift_amount How much to shift. |
| 779 | * @returns the RegLocation of the result. |
| 780 | */ |
| 781 | RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 782 | RegLocation rl_src, int shift_amount); |
| 783 | /* |
| 784 | * Generate an imul of a register by a constant or a better sequence. |
| 785 | * @param dest Destination Register. |
| 786 | * @param src Source Register. |
| 787 | * @param val Constant multiplier. |
| 788 | */ |
| 789 | void GenImulRegImm(RegStorage dest, RegStorage src, int val); |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 790 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 791 | /* |
| 792 | * Generate an imul of a memory location by a constant or a better sequence. |
| 793 | * @param dest Destination Register. |
| 794 | * @param sreg Symbolic register. |
| 795 | * @param displacement Displacement on stack of Symbolic Register. |
| 796 | * @param val Constant multiplier. |
| 797 | */ |
| 798 | void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val); |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 799 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 800 | /* |
| 801 | * @brief Compare memory to immediate, and branch if condition true. |
| 802 | * @param cond The condition code that when true will branch to the target. |
| 803 | * @param temp_reg A temporary register that can be used if compare memory is not |
| 804 | * supported by the architecture. |
| 805 | * @param base_reg The register holding the base address. |
| 806 | * @param offset The offset from the base. |
| 807 | * @param check_value The immediate to compare to. |
| 808 | */ |
| 809 | LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg, |
Nicolas Geoffray | 0025a86 | 2014-07-11 08:26:40 +0000 | [diff] [blame] | 810 | int offset, int check_value, LIR* target); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 811 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 812 | /* |
| 813 | * Can this operation be using core registers without temporaries? |
| 814 | * @param rl_lhs Left hand operand. |
| 815 | * @param rl_rhs Right hand operand. |
| 816 | * @returns 'true' if the operation can proceed without needing temporary regs. |
| 817 | */ |
| 818 | bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs); |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 819 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 820 | /** |
| 821 | * @brief Generates inline code for conversion of long to FP by using x87/ |
| 822 | * @param rl_dest The destination of the FP. |
| 823 | * @param rl_src The source of the long. |
| 824 | * @param is_double 'true' if dealing with double, 'false' for float. |
| 825 | */ |
| 826 | virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 827 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 828 | /* |
| 829 | * @brief Perform MIR analysis before compiling method. |
| 830 | * @note Invokes Mir2LiR::Materialize after analysis. |
| 831 | */ |
| 832 | void Materialize(); |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 833 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 834 | /* |
| 835 | * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register |
| 836 | * without regard to data type. In practice, this can result in UpdateLoc returning a |
| 837 | * location record for a Dalvik float value in a core register, and vis-versa. For targets |
| 838 | * which can inexpensively move data between core and float registers, this can often be a win. |
| 839 | * However, for x86 this is generally not a win. These variants of UpdateLoc() |
| 840 | * take a register class argument - and will return an in-register location record only if |
| 841 | * the value is live in a temp register of the correct class. Additionally, if the value is in |
| 842 | * a temp register of the wrong register class, it will be clobbered. |
| 843 | */ |
| 844 | RegLocation UpdateLocTyped(RegLocation loc, int reg_class); |
| 845 | RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 846 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 847 | /* |
| 848 | * @brief Analyze MIR before generating code, to prepare for the code generation. |
| 849 | */ |
| 850 | void AnalyzeMIR(); |
buzbee | 30adc73 | 2014-05-09 15:10:18 -0700 | [diff] [blame] | 851 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 852 | /* |
| 853 | * @brief Analyze one basic block. |
| 854 | * @param bb Basic block to analyze. |
| 855 | */ |
| 856 | void AnalyzeBB(BasicBlock * bb); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 857 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 858 | /* |
| 859 | * @brief Analyze one extended MIR instruction |
| 860 | * @param opcode MIR instruction opcode. |
| 861 | * @param bb Basic block containing instruction. |
| 862 | * @param mir Extended instruction to analyze. |
| 863 | */ |
| 864 | void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 865 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 866 | /* |
| 867 | * @brief Analyze one MIR instruction |
| 868 | * @param opcode MIR instruction opcode. |
| 869 | * @param bb Basic block containing instruction. |
| 870 | * @param mir Instruction to analyze. |
| 871 | */ |
| 872 | virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 873 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 874 | /* |
| 875 | * @brief Analyze one MIR float/double instruction |
| 876 | * @param opcode MIR instruction opcode. |
| 877 | * @param bb Basic block containing instruction. |
| 878 | * @param mir Instruction to analyze. |
| 879 | */ |
| 880 | void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 881 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 882 | /* |
| 883 | * @brief Analyze one use of a double operand. |
| 884 | * @param rl_use Double RegLocation for the operand. |
| 885 | */ |
| 886 | void AnalyzeDoubleUse(RegLocation rl_use); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 887 | |
Yixin Shou | 7071c8d | 2014-03-05 06:07:48 -0500 | [diff] [blame] | 888 | /* |
| 889 | * @brief Analyze one invoke-static MIR instruction |
| 890 | * @param opcode MIR instruction opcode. |
| 891 | * @param bb Basic block containing instruction. |
| 892 | * @param mir Instruction to analyze. |
| 893 | */ |
| 894 | void AnalyzeInvokeStatic(int opcode, BasicBlock * bb, MIR *mir); |
| 895 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 896 | // Information derived from analysis of MIR |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 897 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 898 | // The compiler temporary for the code address of the method. |
| 899 | CompilerTemp *base_of_code_; |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 900 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 901 | // Have we decided to compute a ptr to code and store in temporary VR? |
| 902 | bool store_method_addr_; |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 903 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 904 | // Have we used the stored method address? |
| 905 | bool store_method_addr_used_; |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 906 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 907 | // Instructions to remove if we didn't use the stored method address. |
| 908 | LIR* setup_method_address_[2]; |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 909 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 910 | // Instructions needing patching with Method* values. |
| 911 | GrowableArray<LIR*> method_address_insns_; |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 912 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 913 | // Instructions needing patching with Class Type* values. |
| 914 | GrowableArray<LIR*> class_type_address_insns_; |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 915 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 916 | // Instructions needing patching with PC relative code addresses. |
| 917 | GrowableArray<LIR*> call_method_insns_; |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 918 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 919 | // Prologue decrement of stack pointer. |
| 920 | LIR* stack_decrement_; |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 921 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 922 | // Epilogue increment of stack pointer. |
| 923 | LIR* stack_increment_; |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 924 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 925 | // The list of const vector literals. |
| 926 | LIR *const_vectors_; |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 927 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 928 | /* |
| 929 | * @brief Search for a matching vector literal |
| 930 | * @param mir A kMirOpConst128b MIR instruction to match. |
| 931 | * @returns pointer to matching LIR constant, or nullptr if not found. |
| 932 | */ |
| 933 | LIR *ScanVectorLiteral(MIR *mir); |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 934 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 935 | /* |
| 936 | * @brief Add a constant vector literal |
| 937 | * @param mir A kMirOpConst128b MIR instruction to match. |
| 938 | */ |
| 939 | LIR *AddVectorLiteral(MIR *mir); |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 940 | |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 941 | InToRegStorageMapping in_to_reg_storage_mapping_; |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 942 | |
Serguei Katkov | 59a42af | 2014-07-05 00:55:46 +0700 | [diff] [blame] | 943 | bool WideGPRsAreAliases() OVERRIDE { |
| 944 | return cu_->target64; // On 64b, we have 64b GPRs. |
| 945 | } |
| 946 | bool WideFPRsAreAliases() OVERRIDE { |
| 947 | return true; // xmm registers have 64b views even on x86. |
| 948 | } |
| 949 | |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 950 | private: |
| 951 | // The number of vector registers [0..N] reserved by a call to ReserveVectorRegisters |
| 952 | int num_reserved_vector_regs_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 953 | }; |
| 954 | |
| 955 | } // namespace art |
| 956 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 957 | #endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_ |