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 | |
| 23 | namespace art { |
| 24 | |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 25 | class X86Mir2Lir : public Mir2Lir { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 26 | public: |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 27 | X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena, bool gen64bit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 28 | |
| 29 | // Required for target - codegen helpers. |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 30 | bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 31 | RegLocation rl_dest, int lit); |
Ian Rogers | e2143c0 | 2014-03-28 08:47:16 -0700 | [diff] [blame] | 32 | bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE; |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 33 | LIR* CheckSuspendUsingLoad() OVERRIDE; |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 34 | RegStorage LoadHelper(ThreadOffset<4> offset) OVERRIDE; |
| 35 | RegStorage LoadHelper(ThreadOffset<8> offset) OVERRIDE; |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 36 | LIR* LoadBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_dest, |
| 37 | OpSize size) OVERRIDE; |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 38 | LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, |
| 39 | OpSize size) OVERRIDE; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 40 | LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 41 | OpSize size) OVERRIDE; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 42 | LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 43 | RegStorage r_dest, OpSize size) OVERRIDE; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 44 | LIR* LoadConstantNoClobber(RegStorage r_dest, int value); |
| 45 | LIR* LoadConstantWide(RegStorage r_dest, int64_t value); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 46 | LIR* StoreBaseDispVolatile(RegStorage r_base, int displacement, RegStorage r_src, |
| 47 | OpSize size) OVERRIDE; |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 48 | LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, |
| 49 | OpSize size) OVERRIDE; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 50 | LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 51 | OpSize size) OVERRIDE; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 52 | LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 53 | RegStorage r_src, OpSize size) OVERRIDE; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 54 | void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 55 | |
| 56 | // Required for target - register utilities. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 57 | RegStorage TargetReg(SpecialTargetRegister reg); |
| 58 | RegStorage GetArgMappingToPhysicalReg(int arg_num); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 59 | RegLocation GetReturnAlt(); |
| 60 | RegLocation GetReturnWideAlt(); |
| 61 | RegLocation LocCReturn(); |
| 62 | RegLocation LocCReturnDouble(); |
| 63 | RegLocation LocCReturnFloat(); |
| 64 | RegLocation LocCReturnWide(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 65 | uint64_t GetRegMaskCommon(RegStorage reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 66 | void AdjustSpillMask(); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 67 | void ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 68 | void FreeCallTemps(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 69 | void LockCallTemps(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 70 | void MarkPreservedSingle(int v_reg, RegStorage reg); |
| 71 | void MarkPreservedDouble(int v_reg, RegStorage reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 72 | void CompilerInitializeRegAlloc(); |
| 73 | |
| 74 | // Required for target - miscellaneous. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 75 | void AssembleLIR(); |
| 76 | int AssignInsnOffsets(); |
| 77 | void AssignOffsets(); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 78 | AssemblerStatus AssembleInstructions(CodeOffset start_addr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 79 | void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix); |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 80 | void SetupTargetResourceMasks(LIR* lir, uint64_t flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 81 | const char* GetTargetInstFmt(int opcode); |
| 82 | const char* GetTargetInstName(int opcode); |
| 83 | std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr); |
| 84 | uint64_t GetPCUseDefEncoding(); |
| 85 | uint64_t GetTargetInstFlags(int opcode); |
| 86 | int GetInsnSize(LIR* lir); |
| 87 | bool IsUnconditionalBranch(LIR* lir); |
| 88 | |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 89 | // Check support for volatile load/store of a given size. |
| 90 | bool SupportsVolatileLoadStore(OpSize size) OVERRIDE; |
| 91 | // Get the register class for load/store of a field. |
| 92 | RegisterClass RegClassForFieldLoadStore(OpSize size, bool is_volatile) OVERRIDE; |
| 93 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 94 | // Required for target - Dalvik-level generators. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 95 | void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 96 | RegLocation rl_src2); |
| 97 | void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index, |
| 98 | RegLocation rl_dest, int scale); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 99 | void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 100 | RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 101 | void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 102 | RegLocation rl_src1, RegLocation rl_shift); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 103 | void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 104 | RegLocation rl_src2); |
| 105 | void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 106 | RegLocation rl_src2); |
| 107 | void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 108 | RegLocation rl_src2); |
| 109 | void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 110 | RegLocation rl_src2); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 111 | void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 112 | RegLocation rl_src2); |
| 113 | void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 114 | RegLocation rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 115 | void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src); |
Vladimir Marko | 1c282e2 | 2013-11-21 14:49:47 +0000 | [diff] [blame] | 116 | bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 117 | bool GenInlinedMinMaxInt(CallInfo* info, bool is_min); |
| 118 | bool GenInlinedSqrt(CallInfo* info); |
Vladimir Marko | e508a20 | 2013-11-04 15:24:22 +0000 | [diff] [blame] | 119 | bool GenInlinedPeek(CallInfo* info, OpSize size); |
| 120 | bool GenInlinedPoke(CallInfo* info, OpSize size); |
Serban Constantinescu | ed65c5e | 2014-05-22 15:10:18 +0100 | [diff] [blame] | 121 | void GenNotLong(RegLocation rl_dest, RegLocation rl_src); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 122 | void GenNegLong(RegLocation rl_dest, RegLocation rl_src); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 123 | void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 124 | RegLocation rl_src2); |
| 125 | void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 126 | RegLocation rl_src2); |
| 127 | void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, |
| 128 | RegLocation rl_src2); |
Serban Constantinescu | ed65c5e | 2014-05-22 15:10:18 +0100 | [diff] [blame] | 129 | void GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1, |
| 130 | RegLocation rl_src2, bool is_div); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 131 | // TODO: collapse reg_lo, reg_hi |
| 132 | RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div); |
| 133 | RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 134 | void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 135 | void GenDivZeroCheckWide(RegStorage reg); |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 136 | void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset); |
| 137 | void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 138 | void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method); |
| 139 | void GenExitSequence(); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 140 | void GenSpecialExitSequence(); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 141 | void GenFillArrayData(DexOffset table_offset, RegLocation rl_src); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 142 | void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double); |
| 143 | void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir); |
| 144 | void GenSelect(BasicBlock* bb, MIR* mir); |
Andreas Gampe | b14329f | 2014-05-15 11:16:06 -0700 | [diff] [blame] | 145 | bool GenMemBarrier(MemBarrierKind barrier_kind); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 146 | void GenMoveException(RegLocation rl_dest); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 147 | void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit, |
| 148 | int first_bit, int second_bit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 149 | void GenNegDouble(RegLocation rl_dest, RegLocation rl_src); |
| 150 | void GenNegFloat(RegLocation rl_dest, RegLocation rl_src); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 151 | void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src); |
| 152 | void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 153 | |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 154 | /* |
| 155 | * @brief Generate a two address long operation with a constant value |
| 156 | * @param rl_dest location of result |
| 157 | * @param rl_src constant source operand |
| 158 | * @param op Opcode to be generated |
| 159 | */ |
| 160 | void GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); |
| 161 | /* |
| 162 | * @brief Generate a three address long operation with a constant value |
| 163 | * @param rl_dest location of result |
| 164 | * @param rl_src1 source operand |
| 165 | * @param rl_src2 constant source operand |
| 166 | * @param op Opcode to be generated |
| 167 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 168 | void GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 169 | Instruction::Code op); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * @brief Generate a long arithmetic operation. |
| 173 | * @param rl_dest The destination. |
| 174 | * @param rl_src1 First operand. |
| 175 | * @param rl_src2 Second operand. |
| 176 | * @param op The DEX opcode for the operation. |
| 177 | * @param is_commutative The sources can be swapped if needed. |
| 178 | */ |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 179 | virtual void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 180 | Instruction::Code op, bool is_commutative); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * @brief Generate a two operand long arithmetic operation. |
| 184 | * @param rl_dest The destination. |
| 185 | * @param rl_src Second operand. |
| 186 | * @param op The DEX opcode for the operation. |
| 187 | */ |
| 188 | void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); |
| 189 | |
| 190 | /** |
| 191 | * @brief Generate a long operation. |
| 192 | * @param rl_dest The destination. Must be in a register |
| 193 | * @param rl_src The other operand. May be in a register or in memory. |
| 194 | * @param op The DEX opcode for the operation. |
| 195 | */ |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 196 | virtual void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 197 | |
Mark Mendell | df8ee2e | 2014-01-27 16:37:47 -0800 | [diff] [blame] | 198 | /** |
| 199 | * @brief Implement instanceof a final class with x86 specific code. |
| 200 | * @param use_declaring_class 'true' if we can use the class itself. |
| 201 | * @param type_idx Type index to use if use_declaring_class is 'false'. |
| 202 | * @param rl_dest Result to be set to 0 or 1. |
| 203 | * @param rl_src Object to be tested. |
| 204 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 205 | void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest, |
| 206 | RegLocation rl_src); |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 207 | /* |
| 208 | * |
| 209 | * @brief Implement Set up instanceof a class with x86 specific code. |
| 210 | * @param needs_access_check 'true' if we must check the access. |
| 211 | * @param type_known_final 'true' if the type is known to be a final class. |
| 212 | * @param type_known_abstract 'true' if the type is known to be an abstract class. |
| 213 | * @param use_declaring_class 'true' if the type can be loaded off the current Method*. |
| 214 | * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache. |
| 215 | * @param type_idx Type index to use if use_declaring_class is 'false'. |
| 216 | * @param rl_dest Result to be set to 0 or 1. |
| 217 | * @param rl_src Object to be tested. |
| 218 | */ |
| 219 | void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final, |
| 220 | bool type_known_abstract, bool use_declaring_class, |
| 221 | bool can_assume_type_is_in_dex_cache, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 222 | uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src); |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 223 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 224 | // Single operation generators. |
| 225 | LIR* OpUnconditionalBranch(LIR* target); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 226 | LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target); |
| 227 | LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 228 | LIR* OpCondBranch(ConditionCode cc, LIR* target); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 229 | LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target); |
| 230 | LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 231 | LIR* OpIT(ConditionCode cond, const char* guide); |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 232 | void OpEndIT(LIR* it); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 233 | LIR* OpMem(OpKind op, RegStorage r_base, int disp); |
| 234 | LIR* OpPcRelLoad(RegStorage reg, LIR* target); |
| 235 | LIR* OpReg(OpKind op, RegStorage r_dest_src); |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 236 | void OpRegCopy(RegStorage r_dest, RegStorage r_src); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 237 | LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src); |
| 238 | LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value); |
| 239 | LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset); |
| 240 | LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value); |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 241 | LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 242 | LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2); |
| 243 | LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type); |
| 244 | LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type); |
| 245 | LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src); |
| 246 | LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value); |
| 247 | LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 248 | LIR* OpTestSuspend(LIR* target); |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 249 | LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) OVERRIDE; |
| 250 | LIR* OpThreadMem(OpKind op, ThreadOffset<8> thread_offset) OVERRIDE; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 251 | LIR* OpVldm(RegStorage r_base, int count); |
| 252 | LIR* OpVstm(RegStorage r_base, int count); |
| 253 | void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset); |
| 254 | void OpRegCopyWide(RegStorage dest, RegStorage src); |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 255 | void OpTlsCmp(ThreadOffset<4> offset, int val) OVERRIDE; |
| 256 | void OpTlsCmp(ThreadOffset<8> offset, int val) OVERRIDE; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 257 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 258 | void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset); |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 259 | void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<8> thread_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 260 | void SpillCoreRegs(); |
| 261 | void UnSpillCoreRegs(); |
| 262 | static const X86EncodingMap EncodingMap[kX86Last]; |
| 263 | bool InexpensiveConstantInt(int32_t value); |
| 264 | bool InexpensiveConstantFloat(int32_t value); |
| 265 | bool InexpensiveConstantLong(int64_t value); |
| 266 | bool InexpensiveConstantDouble(int64_t value); |
| 267 | |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 268 | /* |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 269 | * @brief Should try to optimize for two address instructions? |
| 270 | * @return true if we try to avoid generating three operand instructions. |
| 271 | */ |
| 272 | virtual bool GenerateTwoOperandInstructions() const { return true; } |
| 273 | |
| 274 | /* |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 275 | * @brief x86 specific codegen for int operations. |
| 276 | * @param opcode Operation to perform. |
| 277 | * @param rl_dest Destination for the result. |
| 278 | * @param rl_lhs Left hand operand. |
| 279 | * @param rl_rhs Right hand operand. |
| 280 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 281 | void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs, |
| 282 | RegLocation rl_rhs); |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 283 | |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 284 | /* |
| 285 | * @brief Dump a RegLocation using printf |
| 286 | * @param loc Register location to dump |
| 287 | */ |
| 288 | static void DumpRegLocation(RegLocation loc); |
| 289 | |
| 290 | /* |
| 291 | * @brief Load the Method* of a dex method into the register. |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 292 | * @param target_method The MethodReference of the method to be invoked. |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 293 | * @param type How the method will be invoked. |
| 294 | * @param register that will contain the code address. |
| 295 | * @note register will be passed to TargetReg to get physical register. |
| 296 | */ |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 297 | void LoadMethodAddress(const MethodReference& target_method, InvokeType type, |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 298 | SpecialTargetRegister symbolic_reg); |
| 299 | |
| 300 | /* |
| 301 | * @brief Load the Class* of a Dex Class type into the register. |
| 302 | * @param type How the method will be invoked. |
| 303 | * @param register that will contain the code address. |
| 304 | * @note register will be passed to TargetReg to get physical register. |
| 305 | */ |
| 306 | void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg); |
| 307 | |
| 308 | /* |
| 309 | * @brief Generate a relative call to the method that will be patched at link time. |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 310 | * @param target_method The MethodReference of the method to be invoked. |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 311 | * @param type How the method will be invoked. |
| 312 | * @returns Call instruction |
| 313 | */ |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 314 | virtual LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 315 | |
| 316 | /* |
| 317 | * @brief Handle x86 specific literals |
| 318 | */ |
| 319 | void InstallLiteralPools(); |
| 320 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 321 | /* |
| 322 | * @brief Generate the debug_frame CFI information. |
| 323 | * @returns pointer to vector containing CFE information |
| 324 | */ |
| 325 | static std::vector<uint8_t>* ReturnCommonCallFrameInformation(); |
| 326 | |
| 327 | /* |
| 328 | * @brief Generate the debug_frame FDE information. |
| 329 | * @returns pointer to vector containing CFE information |
| 330 | */ |
| 331 | std::vector<uint8_t>* ReturnCallFrameInformation(); |
| 332 | |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 333 | protected: |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 334 | size_t ComputeSize(const X86EncodingMap* entry, int base, int displacement, bool has_sib); |
Vladimir Marko | 057c74a | 2013-12-03 15:20:45 +0000 | [diff] [blame] | 335 | void EmitPrefix(const X86EncodingMap* entry); |
| 336 | void EmitOpcode(const X86EncodingMap* entry); |
| 337 | void EmitPrefixAndOpcode(const X86EncodingMap* entry); |
| 338 | void EmitDisp(uint8_t base, int disp); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 339 | void EmitModrmThread(uint8_t reg_or_opcode); |
Vladimir Marko | 057c74a | 2013-12-03 15:20:45 +0000 | [diff] [blame] | 340 | void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int disp); |
| 341 | void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale, int disp); |
| 342 | void EmitImm(const X86EncodingMap* entry, int imm); |
Vladimir Marko | a8b4caf | 2013-10-24 15:08:57 +0100 | [diff] [blame] | 343 | void EmitOpRegOpcode(const X86EncodingMap* entry, uint8_t reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 344 | void EmitOpReg(const X86EncodingMap* entry, uint8_t reg); |
| 345 | void EmitOpMem(const X86EncodingMap* entry, uint8_t base, int disp); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 346 | void EmitOpArray(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 347 | void EmitMemReg(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg); |
Mark Mendell | 343adb5 | 2013-12-18 06:02:17 -0800 | [diff] [blame] | 348 | void EmitMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int32_t imm); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 349 | void EmitRegMem(const X86EncodingMap* entry, uint8_t reg, uint8_t base, int disp); |
| 350 | void EmitRegArray(const X86EncodingMap* entry, uint8_t reg, uint8_t base, uint8_t index, |
| 351 | int scale, int disp); |
| 352 | void EmitArrayReg(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp, |
| 353 | uint8_t reg); |
Mark Mendell | 2637f2e | 2014-04-30 10:10:47 -0400 | [diff] [blame] | 354 | void EmitArrayImm(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp, |
| 355 | int32_t imm); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 356 | void EmitRegThread(const X86EncodingMap* entry, uint8_t reg, int disp); |
| 357 | void EmitRegReg(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2); |
| 358 | void EmitRegRegImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm); |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 359 | void EmitRegRegImmRev(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 360 | void EmitRegMemImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int disp, |
| 361 | int32_t imm); |
Mark Mendell | 2637f2e | 2014-04-30 10:10:47 -0400 | [diff] [blame] | 362 | void EmitMemRegImm(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg1, int32_t imm); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 363 | void EmitRegImm(const X86EncodingMap* entry, uint8_t reg, int imm); |
| 364 | void EmitThreadImm(const X86EncodingMap* entry, int disp, int imm); |
| 365 | void EmitMovRegImm(const X86EncodingMap* entry, uint8_t reg, int imm); |
| 366 | void EmitShiftRegImm(const X86EncodingMap* entry, uint8_t reg, int imm); |
Mark Mendell | 2637f2e | 2014-04-30 10:10:47 -0400 | [diff] [blame] | 367 | void EmitShiftMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int imm); |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 368 | void EmitShiftMemCl(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t cl); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 369 | void EmitShiftRegCl(const X86EncodingMap* entry, uint8_t reg, uint8_t cl); |
| 370 | void EmitRegCond(const X86EncodingMap* entry, uint8_t reg, uint8_t condition); |
Mark Mendell | 2637f2e | 2014-04-30 10:10:47 -0400 | [diff] [blame] | 371 | void EmitMemCond(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t condition); |
Razvan A Lupusoru | bd288c2 | 2013-12-20 17:27:23 -0800 | [diff] [blame] | 372 | |
| 373 | /** |
| 374 | * @brief Used for encoding conditional register to register operation. |
| 375 | * @param entry The entry in the encoding map for the opcode. |
| 376 | * @param reg1 The first physical register. |
| 377 | * @param reg2 The second physical register. |
| 378 | * @param condition The condition code for operation. |
| 379 | */ |
| 380 | void EmitRegRegCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, uint8_t condition); |
| 381 | |
Mark Mendell | 2637f2e | 2014-04-30 10:10:47 -0400 | [diff] [blame] | 382 | /** |
| 383 | * @brief Used for encoding conditional register to memory operation. |
| 384 | * @param entry The entry in the encoding map for the opcode. |
| 385 | * @param reg1 The first physical register. |
| 386 | * @param base The memory base register. |
| 387 | * @param displacement The memory displacement. |
| 388 | * @param condition The condition code for operation. |
| 389 | */ |
| 390 | void EmitRegMemCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int displacement, uint8_t condition); |
| 391 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 392 | void EmitJmp(const X86EncodingMap* entry, int rel); |
| 393 | void EmitJcc(const X86EncodingMap* entry, int rel, uint8_t cc); |
| 394 | void EmitCallMem(const X86EncodingMap* entry, uint8_t base, int disp); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 395 | void EmitCallImmediate(const X86EncodingMap* entry, int disp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 396 | void EmitCallThread(const X86EncodingMap* entry, int disp); |
| 397 | void EmitPcRel(const X86EncodingMap* entry, uint8_t reg, int base_or_table, uint8_t index, |
| 398 | int scale, int table_or_disp); |
| 399 | void EmitMacro(const X86EncodingMap* entry, uint8_t reg, int offset); |
| 400 | void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir); |
Mark Mendell | 412d4f8 | 2013-12-18 13:32:36 -0800 | [diff] [blame] | 401 | void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, |
| 402 | int64_t val, ConditionCode ccode); |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 403 | void GenConstWide(RegLocation rl_dest, int64_t value); |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 404 | |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 405 | static bool ProvidesFullMemoryBarrier(X86OpCode opcode); |
| 406 | |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 407 | /* |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 408 | * @brief Ensure that a temporary register is byte addressable. |
| 409 | * @returns a temporary guarenteed to be byte addressable. |
| 410 | */ |
| 411 | virtual RegStorage AllocateByteRegister(); |
| 412 | |
| 413 | /* |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 414 | * @brief generate inline code for fast case of Strng.indexOf. |
| 415 | * @param info Call parameters |
| 416 | * @param zero_based 'true' if the index into the string is 0. |
| 417 | * @returns 'true' if the call was inlined, 'false' if a regular call needs to be |
| 418 | * generated. |
| 419 | */ |
| 420 | bool GenInlinedIndexOf(CallInfo* info, bool zero_based); |
| 421 | |
| 422 | /* |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 423 | * @brief Load 128 bit constant into vector register. |
| 424 | * @param bb The basic block in which the MIR is from. |
| 425 | * @param mir The MIR whose opcode is kMirConstVector |
| 426 | * @note vA is the TypeSize for the register. |
| 427 | * @note vB is the destination XMM register. arg[0..3] are 32 bit constant values. |
| 428 | */ |
| 429 | void GenConst128(BasicBlock* bb, MIR* mir); |
| 430 | |
| 431 | /* |
| 432 | * @brief Generate code for a vector opcode. |
| 433 | * @param bb The basic block in which the MIR is from. |
| 434 | * @param mir The MIR whose opcode is a non-standard opcode. |
| 435 | */ |
| 436 | void GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir); |
| 437 | |
| 438 | /* |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 439 | * @brief Return the correct x86 opcode for the Dex operation |
| 440 | * @param op Dex opcode for the operation |
| 441 | * @param loc Register location of the operand |
| 442 | * @param is_high_op 'true' if this is an operation on the high word |
| 443 | * @param value Immediate value for the operation. Used for byte variants |
| 444 | * @returns the correct x86 opcode to perform the operation |
| 445 | */ |
| 446 | X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value); |
| 447 | |
| 448 | /* |
| 449 | * @brief Return the correct x86 opcode for the Dex operation |
| 450 | * @param op Dex opcode for the operation |
| 451 | * @param dest location of the destination. May be register or memory. |
| 452 | * @param rhs Location for the rhs of the operation. May be in register or memory. |
| 453 | * @param is_high_op 'true' if this is an operation on the high word |
| 454 | * @returns the correct x86 opcode to perform the operation |
| 455 | * @note at most one location may refer to memory |
| 456 | */ |
| 457 | X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs, |
| 458 | bool is_high_op); |
| 459 | |
| 460 | /* |
| 461 | * @brief Is this operation a no-op for this opcode and value |
| 462 | * @param op Dex opcode for the operation |
| 463 | * @param value Immediate value for the operation. |
| 464 | * @returns 'true' if the operation will have no effect |
| 465 | */ |
| 466 | bool IsNoOp(Instruction::Code op, int32_t value); |
| 467 | |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 468 | /** |
| 469 | * @brief Calculate magic number and shift for a given divisor |
| 470 | * @param divisor divisor number for calculation |
| 471 | * @param magic hold calculated magic number |
| 472 | * @param shift hold calculated shift |
| 473 | */ |
| 474 | void CalculateMagicAndShift(int divisor, int& magic, int& shift); |
| 475 | |
| 476 | /* |
| 477 | * @brief Generate an integer div or rem operation. |
| 478 | * @param rl_dest Destination Location. |
| 479 | * @param rl_src1 Numerator Location. |
| 480 | * @param rl_src2 Divisor Location. |
| 481 | * @param is_div 'true' if this is a division, 'false' for a remainder. |
| 482 | * @param check_zero 'true' if an exception should be generated if the divisor is 0. |
| 483 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 484 | RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, |
| 485 | bool is_div, bool check_zero); |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 486 | |
| 487 | /* |
| 488 | * @brief Generate an integer div or rem operation by a literal. |
| 489 | * @param rl_dest Destination Location. |
| 490 | * @param rl_src Numerator Location. |
| 491 | * @param lit Divisor. |
| 492 | * @param is_div 'true' if this is a division, 'false' for a remainder. |
| 493 | */ |
| 494 | RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div); |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | * Generate code to implement long shift operations. |
| 498 | * @param opcode The DEX opcode to specify the shift type. |
| 499 | * @param rl_dest The destination. |
| 500 | * @param rl_src The value to be shifted. |
| 501 | * @param shift_amount How much to shift. |
| 502 | * @returns the RegLocation of the result. |
| 503 | */ |
| 504 | RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 505 | RegLocation rl_src, int shift_amount); |
| 506 | /* |
| 507 | * Generate an imul of a register by a constant or a better sequence. |
| 508 | * @param dest Destination Register. |
| 509 | * @param src Source Register. |
| 510 | * @param val Constant multiplier. |
| 511 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 512 | void GenImulRegImm(RegStorage dest, RegStorage src, int val); |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 513 | |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 514 | /* |
| 515 | * Generate an imul of a memory location by a constant or a better sequence. |
| 516 | * @param dest Destination Register. |
| 517 | * @param sreg Symbolic register. |
| 518 | * @param displacement Displacement on stack of Symbolic Register. |
| 519 | * @param val Constant multiplier. |
| 520 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 521 | void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 522 | |
| 523 | /* |
| 524 | * @brief Compare memory to immediate, and branch if condition true. |
| 525 | * @param cond The condition code that when true will branch to the target. |
| 526 | * @param temp_reg A temporary register that can be used if compare memory is not |
| 527 | * supported by the architecture. |
| 528 | * @param base_reg The register holding the base address. |
| 529 | * @param offset The offset from the base. |
| 530 | * @param check_value The immediate to compare to. |
| 531 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 532 | LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg, |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 533 | int offset, int check_value, LIR* target); |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 534 | |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 535 | /* |
| 536 | * Can this operation be using core registers without temporaries? |
| 537 | * @param rl_lhs Left hand operand. |
| 538 | * @param rl_rhs Right hand operand. |
| 539 | * @returns 'true' if the operation can proceed without needing temporary regs. |
| 540 | */ |
| 541 | bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 542 | |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 543 | /** |
| 544 | * @brief Generates inline code for conversion of long to FP by using x87/ |
| 545 | * @param rl_dest The destination of the FP. |
| 546 | * @param rl_src The source of the long. |
| 547 | * @param is_double 'true' if dealing with double, 'false' for float. |
| 548 | */ |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 549 | virtual void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double); |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 550 | |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 551 | /* |
| 552 | * @brief Perform MIR analysis before compiling method. |
| 553 | * @note Invokes Mir2LiR::Materialize after analysis. |
| 554 | */ |
| 555 | void Materialize(); |
| 556 | |
| 557 | /* |
buzbee | 30adc73 | 2014-05-09 15:10:18 -0700 | [diff] [blame] | 558 | * Mir2Lir's UpdateLoc() looks to see if the Dalvik value is currently live in any temp register |
| 559 | * without regard to data type. In practice, this can result in UpdateLoc returning a |
| 560 | * location record for a Dalvik float value in a core register, and vis-versa. For targets |
| 561 | * which can inexpensively move data between core and float registers, this can often be a win. |
| 562 | * However, for x86 this is generally not a win. These variants of UpdateLoc() |
| 563 | * take a register class argument - and will return an in-register location record only if |
| 564 | * the value is live in a temp register of the correct class. Additionally, if the value is in |
| 565 | * a temp register of the wrong register class, it will be clobbered. |
| 566 | */ |
| 567 | RegLocation UpdateLocTyped(RegLocation loc, int reg_class); |
| 568 | RegLocation UpdateLocWideTyped(RegLocation loc, int reg_class); |
| 569 | |
| 570 | /* |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 571 | * @brief Analyze MIR before generating code, to prepare for the code generation. |
| 572 | */ |
| 573 | void AnalyzeMIR(); |
| 574 | |
| 575 | /* |
| 576 | * @brief Analyze one basic block. |
| 577 | * @param bb Basic block to analyze. |
| 578 | */ |
| 579 | void AnalyzeBB(BasicBlock * bb); |
| 580 | |
| 581 | /* |
| 582 | * @brief Analyze one extended MIR instruction |
| 583 | * @param opcode MIR instruction opcode. |
| 584 | * @param bb Basic block containing instruction. |
| 585 | * @param mir Extended instruction to analyze. |
| 586 | */ |
| 587 | void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir); |
| 588 | |
| 589 | /* |
| 590 | * @brief Analyze one MIR instruction |
| 591 | * @param opcode MIR instruction opcode. |
| 592 | * @param bb Basic block containing instruction. |
| 593 | * @param mir Instruction to analyze. |
| 594 | */ |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 595 | virtual void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 596 | |
| 597 | /* |
| 598 | * @brief Analyze one MIR float/double instruction |
| 599 | * @param opcode MIR instruction opcode. |
| 600 | * @param bb Basic block containing instruction. |
| 601 | * @param mir Instruction to analyze. |
| 602 | */ |
| 603 | void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir); |
| 604 | |
| 605 | /* |
| 606 | * @brief Analyze one use of a double operand. |
| 607 | * @param rl_use Double RegLocation for the operand. |
| 608 | */ |
| 609 | void AnalyzeDoubleUse(RegLocation rl_use); |
| 610 | |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 611 | bool Gen64Bit() const { return gen64bit_; } |
| 612 | |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 613 | // Information derived from analysis of MIR |
| 614 | |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 615 | // The compiler temporary for the code address of the method. |
| 616 | CompilerTemp *base_of_code_; |
| 617 | |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 618 | // Have we decided to compute a ptr to code and store in temporary VR? |
| 619 | bool store_method_addr_; |
| 620 | |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 621 | // Have we used the stored method address? |
| 622 | bool store_method_addr_used_; |
| 623 | |
| 624 | // Instructions to remove if we didn't use the stored method address. |
| 625 | LIR* setup_method_address_[2]; |
| 626 | |
| 627 | // Instructions needing patching with Method* values. |
| 628 | GrowableArray<LIR*> method_address_insns_; |
| 629 | |
| 630 | // Instructions needing patching with Class Type* values. |
| 631 | GrowableArray<LIR*> class_type_address_insns_; |
| 632 | |
| 633 | // Instructions needing patching with PC relative code addresses. |
| 634 | GrowableArray<LIR*> call_method_insns_; |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 635 | |
| 636 | // Prologue decrement of stack pointer. |
| 637 | LIR* stack_decrement_; |
| 638 | |
| 639 | // Epilogue increment of stack pointer. |
| 640 | LIR* stack_increment_; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 641 | |
| 642 | // 64-bit mode |
| 643 | bool gen64bit_; |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 644 | |
| 645 | // The list of const vector literals. |
| 646 | LIR *const_vectors_; |
| 647 | |
| 648 | /* |
| 649 | * @brief Search for a matching vector literal |
| 650 | * @param mir A kMirOpConst128b MIR instruction to match. |
| 651 | * @returns pointer to matching LIR constant, or nullptr if not found. |
| 652 | */ |
| 653 | LIR *ScanVectorLiteral(MIR *mir); |
| 654 | |
| 655 | /* |
| 656 | * @brief Add a constant vector literal |
| 657 | * @param mir A kMirOpConst128b MIR instruction to match. |
| 658 | */ |
| 659 | LIR *AddVectorLiteral(MIR *mir); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 660 | }; |
| 661 | |
| 662 | } // namespace art |
| 663 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 664 | #endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_ |