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