LLVM API Documentation
00001 //===-- X86ISelLowering.h - X86 DAG Lowering Interface ----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the interfaces that X86 uses to lower LLVM code into a 00011 // selection DAG. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_LIB_TARGET_X86_X86ISELLOWERING_H 00016 #define LLVM_LIB_TARGET_X86_X86ISELLOWERING_H 00017 00018 #include "llvm/CodeGen/CallingConvLower.h" 00019 #include "llvm/CodeGen/SelectionDAG.h" 00020 #include "llvm/Target/TargetLowering.h" 00021 #include "llvm/Target/TargetOptions.h" 00022 00023 namespace llvm { 00024 class X86Subtarget; 00025 class X86TargetMachine; 00026 00027 namespace X86ISD { 00028 // X86 Specific DAG Nodes 00029 enum NodeType { 00030 // Start the numbering where the builtin ops leave off. 00031 FIRST_NUMBER = ISD::BUILTIN_OP_END, 00032 00033 /// BSF - Bit scan forward. 00034 /// BSR - Bit scan reverse. 00035 BSF, 00036 BSR, 00037 00038 /// SHLD, SHRD - Double shift instructions. These correspond to 00039 /// X86::SHLDxx and X86::SHRDxx instructions. 00040 SHLD, 00041 SHRD, 00042 00043 /// FAND - Bitwise logical AND of floating point values. This corresponds 00044 /// to X86::ANDPS or X86::ANDPD. 00045 FAND, 00046 00047 /// FOR - Bitwise logical OR of floating point values. This corresponds 00048 /// to X86::ORPS or X86::ORPD. 00049 FOR, 00050 00051 /// FXOR - Bitwise logical XOR of floating point values. This corresponds 00052 /// to X86::XORPS or X86::XORPD. 00053 FXOR, 00054 00055 /// FANDN - Bitwise logical ANDNOT of floating point values. This 00056 /// corresponds to X86::ANDNPS or X86::ANDNPD. 00057 FANDN, 00058 00059 /// FSRL - Bitwise logical right shift of floating point values. These 00060 /// corresponds to X86::PSRLDQ. 00061 FSRL, 00062 00063 /// CALL - These operations represent an abstract X86 call 00064 /// instruction, which includes a bunch of information. In particular the 00065 /// operands of these node are: 00066 /// 00067 /// #0 - The incoming token chain 00068 /// #1 - The callee 00069 /// #2 - The number of arg bytes the caller pushes on the stack. 00070 /// #3 - The number of arg bytes the callee pops off the stack. 00071 /// #4 - The value to pass in AL/AX/EAX (optional) 00072 /// #5 - The value to pass in DL/DX/EDX (optional) 00073 /// 00074 /// The result values of these nodes are: 00075 /// 00076 /// #0 - The outgoing token chain 00077 /// #1 - The first register result value (optional) 00078 /// #2 - The second register result value (optional) 00079 /// 00080 CALL, 00081 00082 /// RDTSC_DAG - This operation implements the lowering for 00083 /// readcyclecounter 00084 RDTSC_DAG, 00085 00086 /// X86 Read Time-Stamp Counter and Processor ID. 00087 RDTSCP_DAG, 00088 00089 /// X86 Read Performance Monitoring Counters. 00090 RDPMC_DAG, 00091 00092 /// X86 compare and logical compare instructions. 00093 CMP, COMI, UCOMI, 00094 00095 /// X86 bit-test instructions. 00096 BT, 00097 00098 /// X86 SetCC. Operand 0 is condition code, and operand 1 is the EFLAGS 00099 /// operand, usually produced by a CMP instruction. 00100 SETCC, 00101 00102 /// X86 Select 00103 SELECT, 00104 00105 // Same as SETCC except it's materialized with a sbb and the value is all 00106 // one's or all zero's. 00107 SETCC_CARRY, // R = carry_bit ? ~0 : 0 00108 00109 /// X86 FP SETCC, implemented with CMP{cc}SS/CMP{cc}SD. 00110 /// Operands are two FP values to compare; result is a mask of 00111 /// 0s or 1s. Generally DTRT for C/C++ with NaNs. 00112 FSETCC, 00113 00114 /// X86 MOVMSK{pd|ps}, extracts sign bits of two or four FP values, 00115 /// result in an integer GPR. Needs masking for scalar result. 00116 FGETSIGNx86, 00117 00118 /// X86 conditional moves. Operand 0 and operand 1 are the two values 00119 /// to select from. Operand 2 is the condition code, and operand 3 is the 00120 /// flag operand produced by a CMP or TEST instruction. It also writes a 00121 /// flag result. 00122 CMOV, 00123 00124 /// X86 conditional branches. Operand 0 is the chain operand, operand 1 00125 /// is the block to branch if condition is true, operand 2 is the 00126 /// condition code, and operand 3 is the flag operand produced by a CMP 00127 /// or TEST instruction. 00128 BRCOND, 00129 00130 /// Return with a flag operand. Operand 0 is the chain operand, operand 00131 /// 1 is the number of bytes of stack to pop. 00132 RET_FLAG, 00133 00134 /// REP_STOS - Repeat fill, corresponds to X86::REP_STOSx. 00135 REP_STOS, 00136 00137 /// REP_MOVS - Repeat move, corresponds to X86::REP_MOVSx. 00138 REP_MOVS, 00139 00140 /// GlobalBaseReg - On Darwin, this node represents the result of the popl 00141 /// at function entry, used for PIC code. 00142 GlobalBaseReg, 00143 00144 /// Wrapper - A wrapper node for TargetConstantPool, 00145 /// TargetExternalSymbol, and TargetGlobalAddress. 00146 Wrapper, 00147 00148 /// WrapperRIP - Special wrapper used under X86-64 PIC mode for RIP 00149 /// relative displacements. 00150 WrapperRIP, 00151 00152 /// MOVDQ2Q - Copies a 64-bit value from the low word of an XMM vector 00153 /// to an MMX vector. If you think this is too close to the previous 00154 /// mnemonic, so do I; blame Intel. 00155 MOVDQ2Q, 00156 00157 /// MMX_MOVD2W - Copies a 32-bit value from the low word of a MMX 00158 /// vector to a GPR. 00159 MMX_MOVD2W, 00160 00161 /// PEXTRB - Extract an 8-bit value from a vector and zero extend it to 00162 /// i32, corresponds to X86::PEXTRB. 00163 PEXTRB, 00164 00165 /// PEXTRW - Extract a 16-bit value from a vector and zero extend it to 00166 /// i32, corresponds to X86::PEXTRW. 00167 PEXTRW, 00168 00169 /// INSERTPS - Insert any element of a 4 x float vector into any element 00170 /// of a destination 4 x floatvector. 00171 INSERTPS, 00172 00173 /// PINSRB - Insert the lower 8-bits of a 32-bit value to a vector, 00174 /// corresponds to X86::PINSRB. 00175 PINSRB, 00176 00177 /// PINSRW - Insert the lower 16-bits of a 32-bit value to a vector, 00178 /// corresponds to X86::PINSRW. 00179 PINSRW, MMX_PINSRW, 00180 00181 /// PSHUFB - Shuffle 16 8-bit values within a vector. 00182 PSHUFB, 00183 00184 /// ANDNP - Bitwise Logical AND NOT of Packed FP values. 00185 ANDNP, 00186 00187 /// PSIGN - Copy integer sign. 00188 PSIGN, 00189 00190 /// BLENDV - Blend where the selector is a register. 00191 BLENDV, 00192 00193 /// BLENDI - Blend where the selector is an immediate. 00194 BLENDI, 00195 00196 /// ADDSUB - Combined add and sub on an FP vector. 00197 ADDSUB, 00198 00199 // SUBUS - Integer sub with unsigned saturation. 00200 SUBUS, 00201 00202 /// HADD - Integer horizontal add. 00203 HADD, 00204 00205 /// HSUB - Integer horizontal sub. 00206 HSUB, 00207 00208 /// FHADD - Floating point horizontal add. 00209 FHADD, 00210 00211 /// FHSUB - Floating point horizontal sub. 00212 FHSUB, 00213 00214 /// UMAX, UMIN - Unsigned integer max and min. 00215 UMAX, UMIN, 00216 00217 /// SMAX, SMIN - Signed integer max and min. 00218 SMAX, SMIN, 00219 00220 /// FMAX, FMIN - Floating point max and min. 00221 /// 00222 FMAX, FMIN, 00223 00224 /// FMAXC, FMINC - Commutative FMIN and FMAX. 00225 FMAXC, FMINC, 00226 00227 /// FRSQRT, FRCP - Floating point reciprocal-sqrt and reciprocal 00228 /// approximation. Note that these typically require refinement 00229 /// in order to obtain suitable precision. 00230 FRSQRT, FRCP, 00231 00232 // TLSADDR - Thread Local Storage. 00233 TLSADDR, 00234 00235 // TLSBASEADDR - Thread Local Storage. A call to get the start address 00236 // of the TLS block for the current module. 00237 TLSBASEADDR, 00238 00239 // TLSCALL - Thread Local Storage. When calling to an OS provided 00240 // thunk at the address from an earlier relocation. 00241 TLSCALL, 00242 00243 // EH_RETURN - Exception Handling helpers. 00244 EH_RETURN, 00245 00246 // EH_SJLJ_SETJMP - SjLj exception handling setjmp. 00247 EH_SJLJ_SETJMP, 00248 00249 // EH_SJLJ_LONGJMP - SjLj exception handling longjmp. 00250 EH_SJLJ_LONGJMP, 00251 00252 /// TC_RETURN - Tail call return. See X86TargetLowering::LowerCall for 00253 /// the list of operands. 00254 TC_RETURN, 00255 00256 // VZEXT_MOVL - Vector move to low scalar and zero higher vector elements. 00257 VZEXT_MOVL, 00258 00259 // VZEXT - Vector integer zero-extend. 00260 VZEXT, 00261 00262 // VSEXT - Vector integer signed-extend. 00263 VSEXT, 00264 00265 // VTRUNC - Vector integer truncate. 00266 VTRUNC, 00267 00268 // VTRUNC - Vector integer truncate with mask. 00269 VTRUNCM, 00270 00271 // VFPEXT - Vector FP extend. 00272 VFPEXT, 00273 00274 // VFPROUND - Vector FP round. 00275 VFPROUND, 00276 00277 // VSHL, VSRL - 128-bit vector logical left / right shift 00278 VSHLDQ, VSRLDQ, 00279 00280 // VSHL, VSRL, VSRA - Vector shift elements 00281 VSHL, VSRL, VSRA, 00282 00283 // VSHLI, VSRLI, VSRAI - Vector shift elements by immediate 00284 VSHLI, VSRLI, VSRAI, 00285 00286 // CMPP - Vector packed double/float comparison. 00287 CMPP, 00288 00289 // PCMP* - Vector integer comparisons. 00290 PCMPEQ, PCMPGT, 00291 // PCMP*M - Vector integer comparisons, the result is in a mask vector. 00292 PCMPEQM, PCMPGTM, 00293 00294 /// CMPM, CMPMU - Vector comparison generating mask bits for fp and 00295 /// integer signed and unsigned data types. 00296 CMPM, 00297 CMPMU, 00298 00299 // ADD, SUB, SMUL, etc. - Arithmetic operations with FLAGS results. 00300 ADD, SUB, ADC, SBB, SMUL, 00301 INC, DEC, OR, XOR, AND, 00302 00303 BEXTR, // BEXTR - Bit field extract 00304 00305 UMUL, // LOW, HI, FLAGS = umul LHS, RHS 00306 00307 // MUL_IMM - X86 specific multiply by immediate. 00308 MUL_IMM, 00309 00310 // PTEST - Vector bitwise comparisons. 00311 PTEST, 00312 00313 // TESTP - Vector packed fp sign bitwise comparisons. 00314 TESTP, 00315 00316 // TESTM, TESTNM - Vector "test" in AVX-512, the result is in a mask vector. 00317 TESTM, 00318 TESTNM, 00319 00320 // OR/AND test for masks 00321 KORTEST, 00322 00323 // Several flavors of instructions with vector shuffle behaviors. 00324 PACKSS, 00325 PACKUS, 00326 // Intra-lane alignr 00327 PALIGNR, 00328 // AVX512 inter-lane alignr 00329 VALIGN, 00330 PSHUFD, 00331 PSHUFHW, 00332 PSHUFLW, 00333 SHUFP, 00334 MOVDDUP, 00335 MOVSHDUP, 00336 MOVSLDUP, 00337 MOVLHPS, 00338 MOVLHPD, 00339 MOVHLPS, 00340 MOVLPS, 00341 MOVLPD, 00342 MOVSD, 00343 MOVSS, 00344 UNPCKL, 00345 UNPCKH, 00346 VPERMILP, 00347 VPERMV, 00348 VPERMV3, 00349 VPERMIV3, 00350 VPERMI, 00351 VPERM2X128, 00352 VBROADCAST, 00353 // masked broadcast 00354 VBROADCASTM, 00355 // Insert/Extract vector element 00356 VINSERT, 00357 VEXTRACT, 00358 00359 // PMULUDQ - Vector multiply packed unsigned doubleword integers 00360 PMULUDQ, 00361 // PMULUDQ - Vector multiply packed signed doubleword integers 00362 PMULDQ, 00363 00364 // FMA nodes 00365 FMADD, 00366 FNMADD, 00367 FMSUB, 00368 FNMSUB, 00369 FMADDSUB, 00370 FMSUBADD, 00371 00372 // VASTART_SAVE_XMM_REGS - Save xmm argument registers to the stack, 00373 // according to %al. An operator is needed so that this can be expanded 00374 // with control flow. 00375 VASTART_SAVE_XMM_REGS, 00376 00377 // WIN_ALLOCA - Windows's _chkstk call to do stack probing. 00378 WIN_ALLOCA, 00379 00380 // SEG_ALLOCA - For allocating variable amounts of stack space when using 00381 // segmented stacks. Check if the current stacklet has enough space, and 00382 // falls back to heap allocation if not. 00383 SEG_ALLOCA, 00384 00385 // WIN_FTOL - Windows's _ftol2 runtime routine to do fptoui. 00386 WIN_FTOL, 00387 00388 // Memory barrier 00389 MEMBARRIER, 00390 MFENCE, 00391 SFENCE, 00392 LFENCE, 00393 00394 // FNSTSW16r - Store FP status word into i16 register. 00395 FNSTSW16r, 00396 00397 // SAHF - Store contents of %ah into %eflags. 00398 SAHF, 00399 00400 // RDRAND - Get a random integer and indicate whether it is valid in CF. 00401 RDRAND, 00402 00403 // RDSEED - Get a NIST SP800-90B & C compliant random integer and 00404 // indicate whether it is valid in CF. 00405 RDSEED, 00406 00407 // PCMP*STRI 00408 PCMPISTRI, 00409 PCMPESTRI, 00410 00411 // XTEST - Test if in transactional execution. 00412 XTEST, 00413 00414 // LCMPXCHG_DAG, LCMPXCHG8_DAG, LCMPXCHG16_DAG - Compare and swap. 00415 LCMPXCHG_DAG = ISD::FIRST_TARGET_MEMORY_OPCODE, 00416 LCMPXCHG8_DAG, 00417 LCMPXCHG16_DAG, 00418 00419 // VZEXT_LOAD - Load, scalar_to_vector, and zero extend. 00420 VZEXT_LOAD, 00421 00422 // FNSTCW16m - Store FP control world into i16 memory. 00423 FNSTCW16m, 00424 00425 /// FP_TO_INT*_IN_MEM - This instruction implements FP_TO_SINT with the 00426 /// integer destination in memory and a FP reg source. This corresponds 00427 /// to the X86::FIST*m instructions and the rounding mode change stuff. It 00428 /// has two inputs (token chain and address) and two outputs (int value 00429 /// and token chain). 00430 FP_TO_INT16_IN_MEM, 00431 FP_TO_INT32_IN_MEM, 00432 FP_TO_INT64_IN_MEM, 00433 00434 /// FILD, FILD_FLAG - This instruction implements SINT_TO_FP with the 00435 /// integer source in memory and FP reg result. This corresponds to the 00436 /// X86::FILD*m instructions. It has three inputs (token chain, address, 00437 /// and source type) and two outputs (FP value and token chain). FILD_FLAG 00438 /// also produces a flag). 00439 FILD, 00440 FILD_FLAG, 00441 00442 /// FLD - This instruction implements an extending load to FP stack slots. 00443 /// This corresponds to the X86::FLD32m / X86::FLD64m. It takes a chain 00444 /// operand, ptr to load from, and a ValueType node indicating the type 00445 /// to load to. 00446 FLD, 00447 00448 /// FST - This instruction implements a truncating store to FP stack 00449 /// slots. This corresponds to the X86::FST32m / X86::FST64m. It takes a 00450 /// chain operand, value to store, address, and a ValueType to store it 00451 /// as. 00452 FST, 00453 00454 /// VAARG_64 - This instruction grabs the address of the next argument 00455 /// from a va_list. (reads and modifies the va_list in memory) 00456 VAARG_64 00457 00458 // WARNING: Do not add anything in the end unless you want the node to 00459 // have memop! In fact, starting from ATOMADD64_DAG all opcodes will be 00460 // thought as target memory ops! 00461 }; 00462 } 00463 00464 /// Define some predicates that are used for node matching. 00465 namespace X86 { 00466 /// isVEXTRACT128Index - Return true if the specified 00467 /// EXTRACT_SUBVECTOR operand specifies a vector extract that is 00468 /// suitable for input to VEXTRACTF128, VEXTRACTI128 instructions. 00469 bool isVEXTRACT128Index(SDNode *N); 00470 00471 /// isVINSERT128Index - Return true if the specified 00472 /// INSERT_SUBVECTOR operand specifies a subvector insert that is 00473 /// suitable for input to VINSERTF128, VINSERTI128 instructions. 00474 bool isVINSERT128Index(SDNode *N); 00475 00476 /// isVEXTRACT256Index - Return true if the specified 00477 /// EXTRACT_SUBVECTOR operand specifies a vector extract that is 00478 /// suitable for input to VEXTRACTF64X4, VEXTRACTI64X4 instructions. 00479 bool isVEXTRACT256Index(SDNode *N); 00480 00481 /// isVINSERT256Index - Return true if the specified 00482 /// INSERT_SUBVECTOR operand specifies a subvector insert that is 00483 /// suitable for input to VINSERTF64X4, VINSERTI64X4 instructions. 00484 bool isVINSERT256Index(SDNode *N); 00485 00486 /// getExtractVEXTRACT128Immediate - Return the appropriate 00487 /// immediate to extract the specified EXTRACT_SUBVECTOR index 00488 /// with VEXTRACTF128, VEXTRACTI128 instructions. 00489 unsigned getExtractVEXTRACT128Immediate(SDNode *N); 00490 00491 /// getInsertVINSERT128Immediate - Return the appropriate 00492 /// immediate to insert at the specified INSERT_SUBVECTOR index 00493 /// with VINSERTF128, VINSERT128 instructions. 00494 unsigned getInsertVINSERT128Immediate(SDNode *N); 00495 00496 /// getExtractVEXTRACT256Immediate - Return the appropriate 00497 /// immediate to extract the specified EXTRACT_SUBVECTOR index 00498 /// with VEXTRACTF64X4, VEXTRACTI64x4 instructions. 00499 unsigned getExtractVEXTRACT256Immediate(SDNode *N); 00500 00501 /// getInsertVINSERT256Immediate - Return the appropriate 00502 /// immediate to insert at the specified INSERT_SUBVECTOR index 00503 /// with VINSERTF64x4, VINSERTI64x4 instructions. 00504 unsigned getInsertVINSERT256Immediate(SDNode *N); 00505 00506 /// isZeroNode - Returns true if Elt is a constant zero or a floating point 00507 /// constant +0.0. 00508 bool isZeroNode(SDValue Elt); 00509 00510 /// isOffsetSuitableForCodeModel - Returns true of the given offset can be 00511 /// fit into displacement field of the instruction. 00512 bool isOffsetSuitableForCodeModel(int64_t Offset, CodeModel::Model M, 00513 bool hasSymbolicDisplacement = true); 00514 00515 00516 /// isCalleePop - Determines whether the callee is required to pop its 00517 /// own arguments. Callee pop is necessary to support tail calls. 00518 bool isCalleePop(CallingConv::ID CallingConv, 00519 bool is64Bit, bool IsVarArg, bool TailCallOpt); 00520 00521 /// AVX512 static rounding constants. These need to match the values in 00522 /// avx512fintrin.h. 00523 enum STATIC_ROUNDING { 00524 TO_NEAREST_INT = 0, 00525 TO_NEG_INF = 1, 00526 TO_POS_INF = 2, 00527 TO_ZERO = 3, 00528 CUR_DIRECTION = 4 00529 }; 00530 } 00531 00532 //===--------------------------------------------------------------------===// 00533 // X86TargetLowering - X86 Implementation of the TargetLowering interface 00534 class X86TargetLowering final : public TargetLowering { 00535 public: 00536 explicit X86TargetLowering(X86TargetMachine &TM); 00537 00538 unsigned getJumpTableEncoding() const override; 00539 00540 MVT getScalarShiftAmountTy(EVT LHSTy) const override { return MVT::i8; } 00541 00542 const MCExpr * 00543 LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI, 00544 const MachineBasicBlock *MBB, unsigned uid, 00545 MCContext &Ctx) const override; 00546 00547 /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC 00548 /// jumptable. 00549 SDValue getPICJumpTableRelocBase(SDValue Table, 00550 SelectionDAG &DAG) const override; 00551 const MCExpr * 00552 getPICJumpTableRelocBaseExpr(const MachineFunction *MF, 00553 unsigned JTI, MCContext &Ctx) const override; 00554 00555 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate 00556 /// function arguments in the caller parameter area. For X86, aggregates 00557 /// that contains are placed at 16-byte boundaries while the rest are at 00558 /// 4-byte boundaries. 00559 unsigned getByValTypeAlignment(Type *Ty) const override; 00560 00561 /// getOptimalMemOpType - Returns the target specific optimal type for load 00562 /// and store operations as a result of memset, memcpy, and memmove 00563 /// lowering. If DstAlign is zero that means it's safe to destination 00564 /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it 00565 /// means there isn't a need to check it against alignment requirement, 00566 /// probably because the source does not need to be loaded. If 'IsMemset' is 00567 /// true, that means it's expanding a memset. If 'ZeroMemset' is true, that 00568 /// means it's a memset of zero. 'MemcpyStrSrc' indicates whether the memcpy 00569 /// source is constant so it does not need to be loaded. 00570 /// It returns EVT::Other if the type should be determined using generic 00571 /// target-independent logic. 00572 EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign, 00573 bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc, 00574 MachineFunction &MF) const override; 00575 00576 /// isSafeMemOpType - Returns true if it's safe to use load / store of the 00577 /// specified type to expand memcpy / memset inline. This is mostly true 00578 /// for all types except for some special cases. For example, on X86 00579 /// targets without SSE2 f64 load / store are done with fldl / fstpl which 00580 /// also does type conversion. Note the specified type doesn't have to be 00581 /// legal as the hook is used before type legalization. 00582 bool isSafeMemOpType(MVT VT) const override; 00583 00584 /// allowsMisalignedMemoryAccesses - Returns true if the target allows 00585 /// unaligned memory accesses. of the specified type. Returns whether it 00586 /// is "fast" by reference in the second argument. 00587 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, unsigned Align, 00588 bool *Fast) const override; 00589 00590 /// LowerOperation - Provide custom lowering hooks for some operations. 00591 /// 00592 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; 00593 00594 /// ReplaceNodeResults - Replace the results of node with an illegal result 00595 /// type with new values built out of custom code. 00596 /// 00597 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, 00598 SelectionDAG &DAG) const override; 00599 00600 00601 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override; 00602 00603 /// isTypeDesirableForOp - Return true if the target has native support for 00604 /// the specified value type and it is 'desirable' to use the type for the 00605 /// given node type. e.g. On x86 i16 is legal, but undesirable since i16 00606 /// instruction encodings are longer and some i16 instructions are slow. 00607 bool isTypeDesirableForOp(unsigned Opc, EVT VT) const override; 00608 00609 /// isTypeDesirable - Return true if the target has native support for the 00610 /// specified value type and it is 'desirable' to use the type. e.g. On x86 00611 /// i16 is legal, but undesirable since i16 instruction encodings are longer 00612 /// and some i16 instructions are slow. 00613 bool IsDesirableToPromoteOp(SDValue Op, EVT &PVT) const override; 00614 00615 MachineBasicBlock * 00616 EmitInstrWithCustomInserter(MachineInstr *MI, 00617 MachineBasicBlock *MBB) const override; 00618 00619 00620 /// getTargetNodeName - This method returns the name of a target specific 00621 /// DAG node. 00622 const char *getTargetNodeName(unsigned Opcode) const override; 00623 00624 /// getSetCCResultType - Return the value type to use for ISD::SETCC. 00625 EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override; 00626 00627 /// computeKnownBitsForTargetNode - Determine which of the bits specified 00628 /// in Mask are known to be either zero or one and return them in the 00629 /// KnownZero/KnownOne bitsets. 00630 void computeKnownBitsForTargetNode(const SDValue Op, 00631 APInt &KnownZero, 00632 APInt &KnownOne, 00633 const SelectionDAG &DAG, 00634 unsigned Depth = 0) const override; 00635 00636 // ComputeNumSignBitsForTargetNode - Determine the number of bits in the 00637 // operation that are sign bits. 00638 unsigned ComputeNumSignBitsForTargetNode(SDValue Op, 00639 const SelectionDAG &DAG, 00640 unsigned Depth) const override; 00641 00642 bool isGAPlusOffset(SDNode *N, const GlobalValue* &GA, 00643 int64_t &Offset) const override; 00644 00645 SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const; 00646 00647 bool ExpandInlineAsm(CallInst *CI) const override; 00648 00649 ConstraintType 00650 getConstraintType(const std::string &Constraint) const override; 00651 00652 /// Examine constraint string and operand type and determine a weight value. 00653 /// The operand object must already have been set up with the operand type. 00654 ConstraintWeight 00655 getSingleConstraintMatchWeight(AsmOperandInfo &info, 00656 const char *constraint) const override; 00657 00658 const char *LowerXConstraint(EVT ConstraintVT) const override; 00659 00660 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops 00661 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is 00662 /// true it means one of the asm constraint of the inline asm instruction 00663 /// being processed is 'm'. 00664 void LowerAsmOperandForConstraint(SDValue Op, 00665 std::string &Constraint, 00666 std::vector<SDValue> &Ops, 00667 SelectionDAG &DAG) const override; 00668 00669 /// getRegForInlineAsmConstraint - Given a physical register constraint 00670 /// (e.g. {edx}), return the register number and the register class for the 00671 /// register. This should only be used for C_Register constraints. On 00672 /// error, this returns a register number of 0. 00673 std::pair<unsigned, const TargetRegisterClass*> 00674 getRegForInlineAsmConstraint(const std::string &Constraint, 00675 MVT VT) const override; 00676 00677 /// isLegalAddressingMode - Return true if the addressing mode represented 00678 /// by AM is legal for this target, for a load/store of the specified type. 00679 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override; 00680 00681 /// isLegalICmpImmediate - Return true if the specified immediate is legal 00682 /// icmp immediate, that is the target has icmp instructions which can 00683 /// compare a register against the immediate without having to materialize 00684 /// the immediate into a register. 00685 bool isLegalICmpImmediate(int64_t Imm) const override; 00686 00687 /// isLegalAddImmediate - Return true if the specified immediate is legal 00688 /// add immediate, that is the target has add instructions which can 00689 /// add a register and the immediate without having to materialize 00690 /// the immediate into a register. 00691 bool isLegalAddImmediate(int64_t Imm) const override; 00692 00693 /// \brief Return the cost of the scaling factor used in the addressing 00694 /// mode represented by AM for this target, for a load/store 00695 /// of the specified type. 00696 /// If the AM is supported, the return value must be >= 0. 00697 /// If the AM is not supported, it returns a negative value. 00698 int getScalingFactorCost(const AddrMode &AM, Type *Ty) const override; 00699 00700 bool isVectorShiftByScalarCheap(Type *Ty) const override; 00701 00702 /// isTruncateFree - Return true if it's free to truncate a value of 00703 /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in 00704 /// register EAX to i16 by referencing its sub-register AX. 00705 bool isTruncateFree(Type *Ty1, Type *Ty2) const override; 00706 bool isTruncateFree(EVT VT1, EVT VT2) const override; 00707 00708 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override; 00709 00710 /// isZExtFree - Return true if any actual instruction that defines a 00711 /// value of type Ty1 implicit zero-extends the value to Ty2 in the result 00712 /// register. This does not necessarily include registers defined in 00713 /// unknown ways, such as incoming arguments, or copies from unknown 00714 /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this 00715 /// does not necessarily apply to truncate instructions. e.g. on x86-64, 00716 /// all instructions that define 32-bit values implicit zero-extend the 00717 /// result out to 64 bits. 00718 bool isZExtFree(Type *Ty1, Type *Ty2) const override; 00719 bool isZExtFree(EVT VT1, EVT VT2) const override; 00720 bool isZExtFree(SDValue Val, EVT VT2) const override; 00721 00722 /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster 00723 /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be 00724 /// expanded to FMAs when this method returns true, otherwise fmuladd is 00725 /// expanded to fmul + fadd. 00726 bool isFMAFasterThanFMulAndFAdd(EVT VT) const override; 00727 00728 /// isNarrowingProfitable - Return true if it's profitable to narrow 00729 /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow 00730 /// from i32 to i8 but not from i32 to i16. 00731 bool isNarrowingProfitable(EVT VT1, EVT VT2) const override; 00732 00733 /// isFPImmLegal - Returns true if the target can instruction select the 00734 /// specified FP immediate natively. If false, the legalizer will 00735 /// materialize the FP immediate as a load from a constant pool. 00736 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override; 00737 00738 /// isShuffleMaskLegal - Targets can use this to indicate that they only 00739 /// support *some* VECTOR_SHUFFLE operations, those with specific masks. 00740 /// By default, if a target supports the VECTOR_SHUFFLE node, all mask 00741 /// values are assumed to be legal. 00742 bool isShuffleMaskLegal(const SmallVectorImpl<int> &Mask, 00743 EVT VT) const override; 00744 00745 /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is 00746 /// used by Targets can use this to indicate if there is a suitable 00747 /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant 00748 /// pool entry. 00749 bool isVectorClearMaskLegal(const SmallVectorImpl<int> &Mask, 00750 EVT VT) const override; 00751 00752 /// ShouldShrinkFPConstant - If true, then instruction selection should 00753 /// seek to shrink the FP constant of the specified type to a smaller type 00754 /// in order to save space and / or reduce runtime. 00755 bool ShouldShrinkFPConstant(EVT VT) const override { 00756 // Don't shrink FP constpool if SSE2 is available since cvtss2sd is more 00757 // expensive than a straight movsd. On the other hand, it's important to 00758 // shrink long double fp constant since fldt is very slow. 00759 return !X86ScalarSSEf64 || VT == MVT::f80; 00760 } 00761 00762 const X86Subtarget* getSubtarget() const { 00763 return Subtarget; 00764 } 00765 00766 /// isScalarFPTypeInSSEReg - Return true if the specified scalar FP type is 00767 /// computed in an SSE register, not on the X87 floating point stack. 00768 bool isScalarFPTypeInSSEReg(EVT VT) const { 00769 return (VT == MVT::f64 && X86ScalarSSEf64) || // f64 is when SSE2 00770 (VT == MVT::f32 && X86ScalarSSEf32); // f32 is when SSE1 00771 } 00772 00773 /// isTargetFTOL - Return true if the target uses the MSVC _ftol2 routine 00774 /// for fptoui. 00775 bool isTargetFTOL() const; 00776 00777 /// isIntegerTypeFTOL - Return true if the MSVC _ftol2 routine should be 00778 /// used for fptoui to the given type. 00779 bool isIntegerTypeFTOL(EVT VT) const { 00780 return isTargetFTOL() && VT == MVT::i64; 00781 } 00782 00783 /// \brief Returns true if it is beneficial to convert a load of a constant 00784 /// to just the constant itself. 00785 bool shouldConvertConstantLoadToIntImm(const APInt &Imm, 00786 Type *Ty) const override; 00787 00788 /// Intel processors have a unified instruction and data cache 00789 const char * getClearCacheBuiltinName() const override { 00790 return nullptr; // nothing to do, move along. 00791 } 00792 00793 unsigned getRegisterByName(const char* RegName, EVT VT) const override; 00794 00795 /// createFastISel - This method returns a target specific FastISel object, 00796 /// or null if the target does not support "fast" ISel. 00797 FastISel *createFastISel(FunctionLoweringInfo &funcInfo, 00798 const TargetLibraryInfo *libInfo) const override; 00799 00800 /// getStackCookieLocation - Return true if the target stores stack 00801 /// protector cookies at a fixed offset in some non-standard address 00802 /// space, and populates the address space and offset as 00803 /// appropriate. 00804 bool getStackCookieLocation(unsigned &AddressSpace, 00805 unsigned &Offset) const override; 00806 00807 SDValue BuildFILD(SDValue Op, EVT SrcVT, SDValue Chain, SDValue StackSlot, 00808 SelectionDAG &DAG) const; 00809 00810 bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override; 00811 00812 /// \brief Reset the operation actions based on target options. 00813 void resetOperationActions() override; 00814 00815 bool useLoadStackGuardNode() const override; 00816 /// \brief Customize the preferred legalization strategy for certain types. 00817 LegalizeTypeAction getPreferredVectorAction(EVT VT) const override; 00818 00819 protected: 00820 std::pair<const TargetRegisterClass*, uint8_t> 00821 findRepresentativeClass(MVT VT) const override; 00822 00823 private: 00824 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can 00825 /// make the right decision when generating code for different targets. 00826 const X86Subtarget *Subtarget; 00827 const DataLayout *TD; 00828 00829 /// Used to store the TargetOptions so that we don't waste time resetting 00830 /// the operation actions unless we have to. 00831 TargetOptions TO; 00832 00833 /// X86ScalarSSEf32, X86ScalarSSEf64 - Select between SSE or x87 00834 /// floating point ops. 00835 /// When SSE is available, use it for f32 operations. 00836 /// When SSE2 is available, use it for f64 operations. 00837 bool X86ScalarSSEf32; 00838 bool X86ScalarSSEf64; 00839 00840 /// LegalFPImmediates - A list of legal fp immediates. 00841 std::vector<APFloat> LegalFPImmediates; 00842 00843 /// addLegalFPImmediate - Indicate that this x86 target can instruction 00844 /// select the specified FP immediate natively. 00845 void addLegalFPImmediate(const APFloat& Imm) { 00846 LegalFPImmediates.push_back(Imm); 00847 } 00848 00849 SDValue LowerCallResult(SDValue Chain, SDValue InFlag, 00850 CallingConv::ID CallConv, bool isVarArg, 00851 const SmallVectorImpl<ISD::InputArg> &Ins, 00852 SDLoc dl, SelectionDAG &DAG, 00853 SmallVectorImpl<SDValue> &InVals) const; 00854 SDValue LowerMemArgument(SDValue Chain, 00855 CallingConv::ID CallConv, 00856 const SmallVectorImpl<ISD::InputArg> &ArgInfo, 00857 SDLoc dl, SelectionDAG &DAG, 00858 const CCValAssign &VA, MachineFrameInfo *MFI, 00859 unsigned i) const; 00860 SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg, 00861 SDLoc dl, SelectionDAG &DAG, 00862 const CCValAssign &VA, 00863 ISD::ArgFlagsTy Flags) const; 00864 00865 // Call lowering helpers. 00866 00867 /// IsEligibleForTailCallOptimization - Check whether the call is eligible 00868 /// for tail call optimization. Targets which want to do tail call 00869 /// optimization should implement this function. 00870 bool IsEligibleForTailCallOptimization(SDValue Callee, 00871 CallingConv::ID CalleeCC, 00872 bool isVarArg, 00873 bool isCalleeStructRet, 00874 bool isCallerStructRet, 00875 Type *RetTy, 00876 const SmallVectorImpl<ISD::OutputArg> &Outs, 00877 const SmallVectorImpl<SDValue> &OutVals, 00878 const SmallVectorImpl<ISD::InputArg> &Ins, 00879 SelectionDAG& DAG) const; 00880 bool IsCalleePop(bool isVarArg, CallingConv::ID CallConv) const; 00881 SDValue EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr, 00882 SDValue Chain, bool IsTailCall, bool Is64Bit, 00883 int FPDiff, SDLoc dl) const; 00884 00885 unsigned GetAlignedArgumentStackSize(unsigned StackSize, 00886 SelectionDAG &DAG) const; 00887 00888 std::pair<SDValue,SDValue> FP_TO_INTHelper(SDValue Op, SelectionDAG &DAG, 00889 bool isSigned, 00890 bool isReplace) const; 00891 00892 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const; 00893 SDValue LowerBUILD_VECTORvXi1(SDValue Op, SelectionDAG &DAG) const; 00894 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const; 00895 SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const; 00896 SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const; 00897 SDValue ExtractBitFromMaskVector(SDValue Op, SelectionDAG &DAG) const; 00898 SDValue InsertBitToMaskVector(SDValue Op, SelectionDAG &DAG) const; 00899 00900 SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const; 00901 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; 00902 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; 00903 SDValue LowerGlobalAddress(const GlobalValue *GV, SDLoc dl, 00904 int64_t Offset, SelectionDAG &DAG) const; 00905 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; 00906 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const; 00907 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const; 00908 SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) const; 00909 SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const; 00910 SDValue LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) const; 00911 SDValue LowerUINT_TO_FP_i32(SDValue Op, SelectionDAG &DAG) const; 00912 SDValue lowerUINT_TO_FP_vec(SDValue Op, SelectionDAG &DAG) const; 00913 SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const; 00914 SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const; 00915 SDValue LowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG) const; 00916 SDValue LowerToBT(SDValue And, ISD::CondCode CC, 00917 SDLoc dl, SelectionDAG &DAG) const; 00918 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const; 00919 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const; 00920 SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const; 00921 SDValue LowerMEMSET(SDValue Op, SelectionDAG &DAG) const; 00922 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const; 00923 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const; 00924 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; 00925 SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const; 00926 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const; 00927 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; 00928 SDValue LowerFRAME_TO_ARGS_OFFSET(SDValue Op, SelectionDAG &DAG) const; 00929 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const; 00930 SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const; 00931 SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const; 00932 SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const; 00933 SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const; 00934 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const; 00935 SDValue LowerWin64_i128OP(SDValue Op, SelectionDAG &DAG) const; 00936 00937 SDValue 00938 LowerFormalArguments(SDValue Chain, 00939 CallingConv::ID CallConv, bool isVarArg, 00940 const SmallVectorImpl<ISD::InputArg> &Ins, 00941 SDLoc dl, SelectionDAG &DAG, 00942 SmallVectorImpl<SDValue> &InVals) const override; 00943 SDValue LowerCall(CallLoweringInfo &CLI, 00944 SmallVectorImpl<SDValue> &InVals) const override; 00945 00946 SDValue LowerReturn(SDValue Chain, 00947 CallingConv::ID CallConv, bool isVarArg, 00948 const SmallVectorImpl<ISD::OutputArg> &Outs, 00949 const SmallVectorImpl<SDValue> &OutVals, 00950 SDLoc dl, SelectionDAG &DAG) const override; 00951 00952 bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const override; 00953 00954 bool mayBeEmittedAsTailCall(CallInst *CI) const override; 00955 00956 EVT getTypeForExtArgOrReturn(LLVMContext &Context, EVT VT, 00957 ISD::NodeType ExtendKind) const override; 00958 00959 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, 00960 bool isVarArg, 00961 const SmallVectorImpl<ISD::OutputArg> &Outs, 00962 LLVMContext &Context) const override; 00963 00964 const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override; 00965 00966 bool shouldExpandAtomicLoadInIR(LoadInst *SI) const override; 00967 bool shouldExpandAtomicStoreInIR(StoreInst *SI) const override; 00968 bool shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override; 00969 00970 bool needsCmpXchgNb(const Type *MemType) const; 00971 00972 /// Utility function to emit atomic-load-arith operations (and, or, xor, 00973 /// nand, max, min, umax, umin). It takes the corresponding instruction to 00974 /// expand, the associated machine basic block, and the associated X86 00975 /// opcodes for reg/reg. 00976 MachineBasicBlock *EmitAtomicLoadArith(MachineInstr *MI, 00977 MachineBasicBlock *MBB) const; 00978 00979 /// Utility function to emit atomic-load-arith operations (and, or, xor, 00980 /// nand, add, sub, swap) for 64-bit operands on 32-bit target. 00981 MachineBasicBlock *EmitAtomicLoadArith6432(MachineInstr *MI, 00982 MachineBasicBlock *MBB) const; 00983 00984 // Utility function to emit the low-level va_arg code for X86-64. 00985 MachineBasicBlock *EmitVAARG64WithCustomInserter( 00986 MachineInstr *MI, 00987 MachineBasicBlock *MBB) const; 00988 00989 /// Utility function to emit the xmm reg save portion of va_start. 00990 MachineBasicBlock *EmitVAStartSaveXMMRegsWithCustomInserter( 00991 MachineInstr *BInstr, 00992 MachineBasicBlock *BB) const; 00993 00994 MachineBasicBlock *EmitLoweredSelect(MachineInstr *I, 00995 MachineBasicBlock *BB) const; 00996 00997 MachineBasicBlock *EmitLoweredWinAlloca(MachineInstr *MI, 00998 MachineBasicBlock *BB) const; 00999 01000 MachineBasicBlock *EmitLoweredSegAlloca(MachineInstr *MI, 01001 MachineBasicBlock *BB, 01002 bool Is64Bit) const; 01003 01004 MachineBasicBlock *EmitLoweredTLSCall(MachineInstr *MI, 01005 MachineBasicBlock *BB) const; 01006 01007 MachineBasicBlock *emitLoweredTLSAddr(MachineInstr *MI, 01008 MachineBasicBlock *BB) const; 01009 01010 MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr *MI, 01011 MachineBasicBlock *MBB) const; 01012 01013 MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr *MI, 01014 MachineBasicBlock *MBB) const; 01015 01016 MachineBasicBlock *emitFMA3Instr(MachineInstr *MI, 01017 MachineBasicBlock *MBB) const; 01018 01019 /// Emit nodes that will be selected as "test Op0,Op0", or something 01020 /// equivalent, for use with the given x86 condition code. 01021 SDValue EmitTest(SDValue Op0, unsigned X86CC, SDLoc dl, 01022 SelectionDAG &DAG) const; 01023 01024 /// Emit nodes that will be selected as "cmp Op0,Op1", or something 01025 /// equivalent, for use with the given x86 condition code. 01026 SDValue EmitCmp(SDValue Op0, SDValue Op1, unsigned X86CC, SDLoc dl, 01027 SelectionDAG &DAG) const; 01028 01029 /// Convert a comparison if required by the subtarget. 01030 SDValue ConvertCmpIfNecessary(SDValue Cmp, SelectionDAG &DAG) const; 01031 }; 01032 01033 namespace X86 { 01034 FastISel *createFastISel(FunctionLoweringInfo &funcInfo, 01035 const TargetLibraryInfo *libInfo); 01036 } 01037 } 01038 01039 #endif // X86ISELLOWERING_H