codegen_x86.h revision 2637f2e9bf4fc5591994b7c0158afead88321a7c
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_ 18#define ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_ 19 20#include "dex/compiler_internals.h" 21#include "x86_lir.h" 22 23namespace art { 24 25class X86Mir2Lir FINAL : public Mir2Lir { 26 public: 27 X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena); 28 29 // Required for target - codegen helpers. 30 bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src, 31 RegLocation rl_dest, int lit); 32 bool EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) OVERRIDE; 33 LIR* CheckSuspendUsingLoad() OVERRIDE; 34 RegStorage LoadHelper(ThreadOffset<4> offset); 35 LIR* LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size, 36 int s_reg); 37 LIR* LoadBaseDispWide(RegStorage r_base, int displacement, RegStorage r_dest, int s_reg); 38 LIR* LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, int scale, 39 OpSize size); 40 LIR* LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, 41 RegStorage r_dest, OpSize size, int s_reg); 42 LIR* LoadConstantNoClobber(RegStorage r_dest, int value); 43 LIR* LoadConstantWide(RegStorage r_dest, int64_t value); 44 LIR* StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size); 45 LIR* StoreBaseDispWide(RegStorage r_base, int displacement, RegStorage r_src); 46 LIR* StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, int scale, 47 OpSize size); 48 LIR* StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, int displacement, 49 RegStorage r_src, OpSize size, int s_reg); 50 void MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg); 51 52 // Required for target - register utilities. 53 RegStorage AllocTypedTemp(bool fp_hint, int reg_class); 54 RegStorage AllocTypedTempWide(bool fp_hint, int reg_class); 55 RegStorage TargetReg(SpecialTargetRegister reg); 56 RegStorage GetArgMappingToPhysicalReg(int arg_num); 57 RegLocation GetReturnAlt(); 58 RegLocation GetReturnWideAlt(); 59 RegLocation LocCReturn(); 60 RegLocation LocCReturnDouble(); 61 RegLocation LocCReturnFloat(); 62 RegLocation LocCReturnWide(); 63 uint64_t GetRegMaskCommon(RegStorage reg); 64 void AdjustSpillMask(); 65 void ClobberCallerSave(); 66 void FreeCallTemps(); 67 void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free); 68 void LockCallTemps(); 69 void MarkPreservedSingle(int v_reg, RegStorage reg); 70 void MarkPreservedDouble(int v_reg, RegStorage reg); 71 void CompilerInitializeRegAlloc(); 72 73 // Required for target - miscellaneous. 74 void AssembleLIR(); 75 int AssignInsnOffsets(); 76 void AssignOffsets(); 77 AssemblerStatus AssembleInstructions(CodeOffset start_addr); 78 void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix); 79 void SetupTargetResourceMasks(LIR* lir, uint64_t flags); 80 const char* GetTargetInstFmt(int opcode); 81 const char* GetTargetInstName(int opcode); 82 std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr); 83 uint64_t GetPCUseDefEncoding(); 84 uint64_t GetTargetInstFlags(int opcode); 85 int GetInsnSize(LIR* lir); 86 bool IsUnconditionalBranch(LIR* lir); 87 88 // Required for target - Dalvik-level generators. 89 void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 90 RegLocation rl_src2); 91 void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, RegLocation rl_index, 92 RegLocation rl_dest, int scale); 93 void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, 94 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark); 95 void GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, 96 RegLocation rl_src1, RegLocation rl_shift); 97 void GenMulLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 98 RegLocation rl_src2); 99 void GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 100 RegLocation rl_src2); 101 void GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 102 RegLocation rl_src2); 103 void GenArithOpDouble(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 104 RegLocation rl_src2); 105 void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 106 RegLocation rl_src2); 107 void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 108 RegLocation rl_src2); 109 void GenConversion(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src); 110 bool GenInlinedCas(CallInfo* info, bool is_long, bool is_object); 111 bool GenInlinedMinMaxInt(CallInfo* info, bool is_min); 112 bool GenInlinedSqrt(CallInfo* info); 113 bool GenInlinedPeek(CallInfo* info, OpSize size); 114 bool GenInlinedPoke(CallInfo* info, OpSize size); 115 void GenNegLong(RegLocation rl_dest, RegLocation rl_src); 116 void GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 117 RegLocation rl_src2); 118 void GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 119 RegLocation rl_src2); 120 void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, 121 RegLocation rl_src2); 122 // TODO: collapse reg_lo, reg_hi 123 RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div); 124 RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div); 125 void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); 126 void GenDivZeroCheckWide(RegStorage reg); 127 void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset); 128 void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset); 129 void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method); 130 void GenExitSequence(); 131 void GenSpecialExitSequence(); 132 void GenFillArrayData(DexOffset table_offset, RegLocation rl_src); 133 void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, bool is_double); 134 void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir); 135 void GenSelect(BasicBlock* bb, MIR* mir); 136 void GenMemBarrier(MemBarrierKind barrier_kind); 137 void GenMoveException(RegLocation rl_dest); 138 void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, RegLocation rl_result, int lit, 139 int first_bit, int second_bit); 140 void GenNegDouble(RegLocation rl_dest, RegLocation rl_src); 141 void GenNegFloat(RegLocation rl_dest, RegLocation rl_src); 142 void GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src); 143 void GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src); 144 145 /* 146 * @brief Generate a two address long operation with a constant value 147 * @param rl_dest location of result 148 * @param rl_src constant source operand 149 * @param op Opcode to be generated 150 */ 151 void GenLongImm(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); 152 /* 153 * @brief Generate a three address long operation with a constant value 154 * @param rl_dest location of result 155 * @param rl_src1 source operand 156 * @param rl_src2 constant source operand 157 * @param op Opcode to be generated 158 */ 159 void GenLongLongImm(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, 160 Instruction::Code op); 161 162 /** 163 * @brief Generate a long arithmetic operation. 164 * @param rl_dest The destination. 165 * @param rl_src1 First operand. 166 * @param rl_src2 Second operand. 167 * @param op The DEX opcode for the operation. 168 * @param is_commutative The sources can be swapped if needed. 169 */ 170 void GenLongArith(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, 171 Instruction::Code op, bool is_commutative); 172 173 /** 174 * @brief Generate a two operand long arithmetic operation. 175 * @param rl_dest The destination. 176 * @param rl_src Second operand. 177 * @param op The DEX opcode for the operation. 178 */ 179 void GenLongArith(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); 180 181 /** 182 * @brief Generate a long operation. 183 * @param rl_dest The destination. Must be in a register 184 * @param rl_src The other operand. May be in a register or in memory. 185 * @param op The DEX opcode for the operation. 186 */ 187 void GenLongRegOrMemOp(RegLocation rl_dest, RegLocation rl_src, Instruction::Code op); 188 189 /** 190 * @brief Implement instanceof a final class with x86 specific code. 191 * @param use_declaring_class 'true' if we can use the class itself. 192 * @param type_idx Type index to use if use_declaring_class is 'false'. 193 * @param rl_dest Result to be set to 0 or 1. 194 * @param rl_src Object to be tested. 195 */ 196 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest, 197 RegLocation rl_src); 198 /* 199 * 200 * @brief Implement Set up instanceof a class with x86 specific code. 201 * @param needs_access_check 'true' if we must check the access. 202 * @param type_known_final 'true' if the type is known to be a final class. 203 * @param type_known_abstract 'true' if the type is known to be an abstract class. 204 * @param use_declaring_class 'true' if the type can be loaded off the current Method*. 205 * @param can_assume_type_is_in_dex_cache 'true' if the type is known to be in the cache. 206 * @param type_idx Type index to use if use_declaring_class is 'false'. 207 * @param rl_dest Result to be set to 0 or 1. 208 * @param rl_src Object to be tested. 209 */ 210 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final, 211 bool type_known_abstract, bool use_declaring_class, 212 bool can_assume_type_is_in_dex_cache, 213 uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src); 214 215 // Single operation generators. 216 LIR* OpUnconditionalBranch(LIR* target); 217 LIR* OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target); 218 LIR* OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target); 219 LIR* OpCondBranch(ConditionCode cc, LIR* target); 220 LIR* OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target); 221 LIR* OpFpRegCopy(RegStorage r_dest, RegStorage r_src); 222 LIR* OpIT(ConditionCode cond, const char* guide); 223 void OpEndIT(LIR* it); 224 LIR* OpMem(OpKind op, RegStorage r_base, int disp); 225 LIR* OpPcRelLoad(RegStorage reg, LIR* target); 226 LIR* OpReg(OpKind op, RegStorage r_dest_src); 227 void OpRegCopy(RegStorage r_dest, RegStorage r_src); 228 LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src); 229 LIR* OpRegImm(OpKind op, RegStorage r_dest_src1, int value); 230 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset); 231 LIR* OpRegMem(OpKind op, RegStorage r_dest, RegLocation value); 232 LIR* OpMemReg(OpKind op, RegLocation rl_dest, int value); 233 LIR* OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2); 234 LIR* OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type); 235 LIR* OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type); 236 LIR* OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src); 237 LIR* OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src1, int value); 238 LIR* OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, RegStorage r_src2); 239 LIR* OpTestSuspend(LIR* target); 240 LIR* OpThreadMem(OpKind op, ThreadOffset<4> thread_offset); 241 LIR* OpVldm(RegStorage r_base, int count); 242 LIR* OpVstm(RegStorage r_base, int count); 243 void OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset); 244 void OpRegCopyWide(RegStorage dest, RegStorage src); 245 void OpTlsCmp(ThreadOffset<4> offset, int val); 246 247 void OpRegThreadMem(OpKind op, RegStorage r_dest, ThreadOffset<4> thread_offset); 248 void SpillCoreRegs(); 249 void UnSpillCoreRegs(); 250 static const X86EncodingMap EncodingMap[kX86Last]; 251 bool InexpensiveConstantInt(int32_t value); 252 bool InexpensiveConstantFloat(int32_t value); 253 bool InexpensiveConstantLong(int64_t value); 254 bool InexpensiveConstantDouble(int64_t value); 255 256 /* 257 * @brief x86 specific codegen for int operations. 258 * @param opcode Operation to perform. 259 * @param rl_dest Destination for the result. 260 * @param rl_lhs Left hand operand. 261 * @param rl_rhs Right hand operand. 262 */ 263 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_lhs, 264 RegLocation rl_rhs); 265 266 /* 267 * @brief Dump a RegLocation using printf 268 * @param loc Register location to dump 269 */ 270 static void DumpRegLocation(RegLocation loc); 271 272 /* 273 * @brief Load the Method* of a dex method into the register. 274 * @param target_method The MethodReference of the method to be invoked. 275 * @param type How the method will be invoked. 276 * @param register that will contain the code address. 277 * @note register will be passed to TargetReg to get physical register. 278 */ 279 void LoadMethodAddress(const MethodReference& target_method, InvokeType type, 280 SpecialTargetRegister symbolic_reg); 281 282 /* 283 * @brief Load the Class* of a Dex Class type into the register. 284 * @param type How the method will be invoked. 285 * @param register that will contain the code address. 286 * @note register will be passed to TargetReg to get physical register. 287 */ 288 void LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg); 289 290 /* 291 * @brief Generate a relative call to the method that will be patched at link time. 292 * @param target_method The MethodReference of the method to be invoked. 293 * @param type How the method will be invoked. 294 * @returns Call instruction 295 */ 296 LIR * CallWithLinkerFixup(const MethodReference& target_method, InvokeType type); 297 298 /* 299 * @brief Handle x86 specific literals 300 */ 301 void InstallLiteralPools(); 302 303 /* 304 * @brief Generate the debug_frame CFI information. 305 * @returns pointer to vector containing CFE information 306 */ 307 static std::vector<uint8_t>* ReturnCommonCallFrameInformation(); 308 309 /* 310 * @brief Generate the debug_frame FDE information. 311 * @returns pointer to vector containing CFE information 312 */ 313 std::vector<uint8_t>* ReturnCallFrameInformation(); 314 315 private: 316 void EmitPrefix(const X86EncodingMap* entry); 317 void EmitOpcode(const X86EncodingMap* entry); 318 void EmitPrefixAndOpcode(const X86EncodingMap* entry); 319 void EmitDisp(uint8_t base, int disp); 320 void EmitModrmDisp(uint8_t reg_or_opcode, uint8_t base, int disp); 321 void EmitModrmSibDisp(uint8_t reg_or_opcode, uint8_t base, uint8_t index, int scale, int disp); 322 void EmitImm(const X86EncodingMap* entry, int imm); 323 void EmitOpRegOpcode(const X86EncodingMap* entry, uint8_t reg); 324 void EmitOpReg(const X86EncodingMap* entry, uint8_t reg); 325 void EmitOpMem(const X86EncodingMap* entry, uint8_t base, int disp); 326 void EmitOpArray(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp); 327 void EmitMemReg(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg); 328 void EmitMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int32_t imm); 329 void EmitRegMem(const X86EncodingMap* entry, uint8_t reg, uint8_t base, int disp); 330 void EmitRegArray(const X86EncodingMap* entry, uint8_t reg, uint8_t base, uint8_t index, 331 int scale, int disp); 332 void EmitArrayReg(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp, 333 uint8_t reg); 334 void EmitArrayImm(const X86EncodingMap* entry, uint8_t base, uint8_t index, int scale, int disp, 335 int32_t imm); 336 void EmitRegThread(const X86EncodingMap* entry, uint8_t reg, int disp); 337 void EmitRegReg(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2); 338 void EmitRegRegImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm); 339 void EmitRegRegImmRev(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, int32_t imm); 340 void EmitRegMemImm(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int disp, 341 int32_t imm); 342 void EmitMemRegImm(const X86EncodingMap* entry, uint8_t base, int disp, uint8_t reg1, int32_t imm); 343 void EmitRegImm(const X86EncodingMap* entry, uint8_t reg, int imm); 344 void EmitThreadImm(const X86EncodingMap* entry, int disp, int imm); 345 void EmitMovRegImm(const X86EncodingMap* entry, uint8_t reg, int imm); 346 void EmitShiftRegImm(const X86EncodingMap* entry, uint8_t reg, int imm); 347 void EmitShiftMemImm(const X86EncodingMap* entry, uint8_t base, int disp, int imm); 348 void EmitShiftMemCl(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t cl); 349 void EmitShiftRegCl(const X86EncodingMap* entry, uint8_t reg, uint8_t cl); 350 void EmitRegCond(const X86EncodingMap* entry, uint8_t reg, uint8_t condition); 351 void EmitMemCond(const X86EncodingMap* entry, uint8_t base, int displacement, uint8_t condition); 352 353 /** 354 * @brief Used for encoding conditional register to register operation. 355 * @param entry The entry in the encoding map for the opcode. 356 * @param reg1 The first physical register. 357 * @param reg2 The second physical register. 358 * @param condition The condition code for operation. 359 */ 360 void EmitRegRegCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t reg2, uint8_t condition); 361 362 /** 363 * @brief Used for encoding conditional register to memory operation. 364 * @param entry The entry in the encoding map for the opcode. 365 * @param reg1 The first physical register. 366 * @param base The memory base register. 367 * @param displacement The memory displacement. 368 * @param condition The condition code for operation. 369 */ 370 void EmitRegMemCond(const X86EncodingMap* entry, uint8_t reg1, uint8_t base, int displacement, uint8_t condition); 371 372 void EmitJmp(const X86EncodingMap* entry, int rel); 373 void EmitJcc(const X86EncodingMap* entry, int rel, uint8_t cc); 374 void EmitCallMem(const X86EncodingMap* entry, uint8_t base, int disp); 375 void EmitCallImmediate(const X86EncodingMap* entry, int disp); 376 void EmitCallThread(const X86EncodingMap* entry, int disp); 377 void EmitPcRel(const X86EncodingMap* entry, uint8_t reg, int base_or_table, uint8_t index, 378 int scale, int table_or_disp); 379 void EmitMacro(const X86EncodingMap* entry, uint8_t reg, int offset); 380 void EmitUnimplemented(const X86EncodingMap* entry, LIR* lir); 381 void GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1, 382 int64_t val, ConditionCode ccode); 383 void GenConstWide(RegLocation rl_dest, int64_t value); 384 385 static bool ProvidesFullMemoryBarrier(X86OpCode opcode); 386 387 /* 388 * @brief generate inline code for fast case of Strng.indexOf. 389 * @param info Call parameters 390 * @param zero_based 'true' if the index into the string is 0. 391 * @returns 'true' if the call was inlined, 'false' if a regular call needs to be 392 * generated. 393 */ 394 bool GenInlinedIndexOf(CallInfo* info, bool zero_based); 395 396 /* 397 * @brief Return the correct x86 opcode for the Dex operation 398 * @param op Dex opcode for the operation 399 * @param loc Register location of the operand 400 * @param is_high_op 'true' if this is an operation on the high word 401 * @param value Immediate value for the operation. Used for byte variants 402 * @returns the correct x86 opcode to perform the operation 403 */ 404 X86OpCode GetOpcode(Instruction::Code op, RegLocation loc, bool is_high_op, int32_t value); 405 406 /* 407 * @brief Return the correct x86 opcode for the Dex operation 408 * @param op Dex opcode for the operation 409 * @param dest location of the destination. May be register or memory. 410 * @param rhs Location for the rhs of the operation. May be in register or memory. 411 * @param is_high_op 'true' if this is an operation on the high word 412 * @returns the correct x86 opcode to perform the operation 413 * @note at most one location may refer to memory 414 */ 415 X86OpCode GetOpcode(Instruction::Code op, RegLocation dest, RegLocation rhs, 416 bool is_high_op); 417 418 /* 419 * @brief Is this operation a no-op for this opcode and value 420 * @param op Dex opcode for the operation 421 * @param value Immediate value for the operation. 422 * @returns 'true' if the operation will have no effect 423 */ 424 bool IsNoOp(Instruction::Code op, int32_t value); 425 426 /** 427 * @brief Calculate magic number and shift for a given divisor 428 * @param divisor divisor number for calculation 429 * @param magic hold calculated magic number 430 * @param shift hold calculated shift 431 */ 432 void CalculateMagicAndShift(int divisor, int& magic, int& shift); 433 434 /* 435 * @brief Generate an integer div or rem operation. 436 * @param rl_dest Destination Location. 437 * @param rl_src1 Numerator Location. 438 * @param rl_src2 Divisor Location. 439 * @param is_div 'true' if this is a division, 'false' for a remainder. 440 * @param check_zero 'true' if an exception should be generated if the divisor is 0. 441 */ 442 RegLocation GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, 443 bool is_div, bool check_zero); 444 445 /* 446 * @brief Generate an integer div or rem operation by a literal. 447 * @param rl_dest Destination Location. 448 * @param rl_src Numerator Location. 449 * @param lit Divisor. 450 * @param is_div 'true' if this is a division, 'false' for a remainder. 451 */ 452 RegLocation GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, int lit, bool is_div); 453 454 /* 455 * Generate code to implement long shift operations. 456 * @param opcode The DEX opcode to specify the shift type. 457 * @param rl_dest The destination. 458 * @param rl_src The value to be shifted. 459 * @param shift_amount How much to shift. 460 * @returns the RegLocation of the result. 461 */ 462 RegLocation GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, 463 RegLocation rl_src, int shift_amount); 464 /* 465 * Generate an imul of a register by a constant or a better sequence. 466 * @param dest Destination Register. 467 * @param src Source Register. 468 * @param val Constant multiplier. 469 */ 470 void GenImulRegImm(RegStorage dest, RegStorage src, int val); 471 472 /* 473 * Generate an imul of a memory location by a constant or a better sequence. 474 * @param dest Destination Register. 475 * @param sreg Symbolic register. 476 * @param displacement Displacement on stack of Symbolic Register. 477 * @param val Constant multiplier. 478 */ 479 void GenImulMemImm(RegStorage dest, int sreg, int displacement, int val); 480 481 /* 482 * @brief Compare memory to immediate, and branch if condition true. 483 * @param cond The condition code that when true will branch to the target. 484 * @param temp_reg A temporary register that can be used if compare memory is not 485 * supported by the architecture. 486 * @param base_reg The register holding the base address. 487 * @param offset The offset from the base. 488 * @param check_value The immediate to compare to. 489 */ 490 LIR* OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg, 491 int offset, int check_value, LIR* target); 492 493 /* 494 * Can this operation be using core registers without temporaries? 495 * @param rl_lhs Left hand operand. 496 * @param rl_rhs Right hand operand. 497 * @returns 'true' if the operation can proceed without needing temporary regs. 498 */ 499 bool IsOperationSafeWithoutTemps(RegLocation rl_lhs, RegLocation rl_rhs); 500 501 /** 502 * @brief Generates inline code for conversion of long to FP by using x87/ 503 * @param rl_dest The destination of the FP. 504 * @param rl_src The source of the long. 505 * @param is_double 'true' if dealing with double, 'false' for float. 506 */ 507 void GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_double); 508 509 /* 510 * @brief Perform MIR analysis before compiling method. 511 * @note Invokes Mir2LiR::Materialize after analysis. 512 */ 513 void Materialize(); 514 515 /* 516 * @brief Analyze MIR before generating code, to prepare for the code generation. 517 */ 518 void AnalyzeMIR(); 519 520 /* 521 * @brief Analyze one basic block. 522 * @param bb Basic block to analyze. 523 */ 524 void AnalyzeBB(BasicBlock * bb); 525 526 /* 527 * @brief Analyze one extended MIR instruction 528 * @param opcode MIR instruction opcode. 529 * @param bb Basic block containing instruction. 530 * @param mir Extended instruction to analyze. 531 */ 532 void AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir); 533 534 /* 535 * @brief Analyze one MIR instruction 536 * @param opcode MIR instruction opcode. 537 * @param bb Basic block containing instruction. 538 * @param mir Instruction to analyze. 539 */ 540 void AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir); 541 542 /* 543 * @brief Analyze one MIR float/double instruction 544 * @param opcode MIR instruction opcode. 545 * @param bb Basic block containing instruction. 546 * @param mir Instruction to analyze. 547 */ 548 void AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir); 549 550 /* 551 * @brief Analyze one use of a double operand. 552 * @param rl_use Double RegLocation for the operand. 553 */ 554 void AnalyzeDoubleUse(RegLocation rl_use); 555 556 // Information derived from analysis of MIR 557 558 // The compiler temporary for the code address of the method. 559 CompilerTemp *base_of_code_; 560 561 // Have we decided to compute a ptr to code and store in temporary VR? 562 bool store_method_addr_; 563 564 // Have we used the stored method address? 565 bool store_method_addr_used_; 566 567 // Instructions to remove if we didn't use the stored method address. 568 LIR* setup_method_address_[2]; 569 570 // Instructions needing patching with Method* values. 571 GrowableArray<LIR*> method_address_insns_; 572 573 // Instructions needing patching with Class Type* values. 574 GrowableArray<LIR*> class_type_address_insns_; 575 576 // Instructions needing patching with PC relative code addresses. 577 GrowableArray<LIR*> call_method_insns_; 578 579 // Prologue decrement of stack pointer. 580 LIR* stack_decrement_; 581 582 // Epilogue increment of stack pointer. 583 LIR* stack_increment_; 584}; 585 586} // namespace art 587 588#endif // ART_COMPILER_DEX_QUICK_X86_CODEGEN_X86_H_ 589