1 //===-- X86ISelLowering.h - X86 DAG Lowering Interface ----------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the interfaces that X86 uses to lower LLVM code into a
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_X86_X86ISELLOWERING_H
15 #define LLVM_LIB_TARGET_X86_X86ISELLOWERING_H
17 #include "llvm/CodeGen/TargetLowering.h"
21 class X86TargetMachine;
24 // X86 Specific DAG Nodes
25 enum NodeType : unsigned {
26 // Start the numbering where the builtin ops leave off.
27 FIRST_NUMBER = ISD::BUILTIN_OP_END,
34 /// X86 funnel/double shift i16 instructions. These correspond to
35 /// X86::SHLDW and X86::SHRDW instructions which have different amt
36 /// modulo rules to generic funnel shifts.
37 /// NOTE: The operand order matches ISD::FSHL/FSHR not SHLD/SHRD.
41 /// Bitwise logical AND of floating point values. This corresponds
42 /// to X86::ANDPS or X86::ANDPD.
45 /// Bitwise logical OR of floating point values. This corresponds
46 /// to X86::ORPS or X86::ORPD.
49 /// Bitwise logical XOR of floating point values. This corresponds
50 /// to X86::XORPS or X86::XORPD.
53 /// Bitwise logical ANDNOT of floating point values. This
54 /// corresponds to X86::ANDNPS or X86::ANDNPD.
57 /// These operations represent an abstract X86 call
58 /// instruction, which includes a bunch of information. In particular the
59 /// operands of these node are:
61 /// #0 - The incoming token chain
63 /// #2 - The number of arg bytes the caller pushes on the stack.
64 /// #3 - The number of arg bytes the callee pops off the stack.
65 /// #4 - The value to pass in AL/AX/EAX (optional)
66 /// #5 - The value to pass in DL/DX/EDX (optional)
68 /// The result values of these nodes are:
70 /// #0 - The outgoing token chain
71 /// #1 - The first register result value (optional)
72 /// #2 - The second register result value (optional)
76 /// Same as call except it adds the NoTrack prefix.
79 // Pseudo for a OBJC call that gets emitted together with a special
80 // marker instruction.
83 /// X86 compare and logical compare instructions.
89 /// X86 bit-test instructions.
92 /// X86 SetCC. Operand 0 is condition code, and operand 1 is the EFLAGS
93 /// operand, usually produced by a CMP instruction.
99 // Same as SETCC except it's materialized with a sbb and the value is all
100 // one's or all zero's.
101 SETCC_CARRY, // R = carry_bit ? ~0 : 0
103 /// X86 FP SETCC, implemented with CMP{cc}SS/CMP{cc}SD.
104 /// Operands are two FP values to compare; result is a mask of
105 /// 0s or 1s. Generally DTRT for C/C++ with NaNs.
108 /// X86 FP SETCC, similar to above, but with output as an i1 mask and
109 /// and a version with SAE.
113 /// X86 conditional moves. Operand 0 and operand 1 are the two values
114 /// to select from. Operand 2 is the condition code, and operand 3 is the
115 /// flag operand produced by a CMP or TEST instruction.
118 /// X86 conditional branches. Operand 0 is the chain operand, operand 1
119 /// is the block to branch if condition is true, operand 2 is the
120 /// condition code, and operand 3 is the flag operand produced by a CMP
121 /// or TEST instruction.
124 /// BRIND node with NoTrack prefix. Operand 0 is the chain operand and
125 /// operand 1 is the target address.
128 /// Return with a flag operand. Operand 0 is the chain operand, operand
129 /// 1 is the number of bytes of stack to pop.
132 /// Return from interrupt. Operand 0 is the number of bytes to pop.
135 /// Repeat fill, corresponds to X86::REP_STOSx.
138 /// Repeat move, corresponds to X86::REP_MOVSx.
141 /// On Darwin, this node represents the result of the popl
142 /// at function entry, used for PIC code.
145 /// A wrapper node for TargetConstantPool, TargetJumpTable,
146 /// TargetExternalSymbol, TargetGlobalAddress, TargetGlobalTLSAddress,
147 /// MCSymbol and TargetBlockAddress.
150 /// Special wrapper used under X86-64 PIC mode for RIP
151 /// relative displacements.
154 /// Copies a 64-bit value from an MMX vector to the low word
155 /// of an XMM vector, with the high word zero filled.
158 /// Copies a 64-bit value from the low word of an XMM vector
159 /// to an MMX vector.
162 /// Copies a 32-bit value from the low word of a MMX
166 /// Copies a GPR into the low 32-bit word of a MMX vector
167 /// and zero out the high word.
170 /// Extract an 8-bit value from a vector and zero extend it to
171 /// i32, corresponds to X86::PEXTRB.
174 /// Extract a 16-bit value from a vector and zero extend it to
175 /// i32, corresponds to X86::PEXTRW.
178 /// Insert any element of a 4 x float vector into any element
179 /// of a destination 4 x floatvector.
182 /// Insert the lower 8-bits of a 32-bit value to a vector,
183 /// corresponds to X86::PINSRB.
186 /// Insert the lower 16-bits of a 32-bit value to a vector,
187 /// corresponds to X86::PINSRW.
190 /// Shuffle 16 8-bit values within a vector.
193 /// Compute Sum of Absolute Differences.
195 /// Compute Double Block Packed Sum-Absolute-Differences
198 /// Bitwise Logical AND NOT of Packed FP values.
201 /// Blend where the selector is an immediate.
204 /// Dynamic (non-constant condition) vector blend where only the sign bits
205 /// of the condition elements are used. This is used to enforce that the
206 /// condition mask is not valid for generic VSELECT optimizations. This
207 /// is also used to implement the intrinsics.
208 /// Operands are in VSELECT order: MASK, TRUE, FALSE
211 /// Combined add and sub on an FP vector.
214 // FP vector ops with rounding mode.
235 // FP vector get exponent.
240 // Extract Normalized Mantissas.
251 // Unsigned Integer average.
254 /// Integer horizontal add/sub.
258 /// Floating point horizontal add/sub.
262 // Detect Conflicts Within a Vector
265 /// Floating point max and min.
269 /// Commutative FMIN and FMAX.
273 /// Scalar intrinsic floating point max and min.
277 /// Floating point reciprocal-sqrt and reciprocal approximation.
278 /// Note that these typically require refinement
279 /// in order to obtain suitable precision.
283 // AVX-512 reciprocal approximations with a little more precision.
289 // Thread Local Storage.
292 // Thread Local Storage. A call to get the start address
293 // of the TLS block for the current module.
296 // Thread Local Storage. When calling to an OS provided
297 // thunk at the address from an earlier relocation.
300 // Exception Handling helpers.
303 // SjLj exception handling setjmp.
306 // SjLj exception handling longjmp.
309 // SjLj exception handling dispatch.
310 EH_SJLJ_SETUP_DISPATCH,
312 /// Tail call return. See X86TargetLowering::LowerCall for
313 /// the list of operands.
316 // Vector move to low scalar and zero higher vector elements.
319 // Vector integer truncate.
321 // Vector integer truncate with unsigned/signed saturation.
325 // Masked version of the above. Used when less than a 128-bit result is
326 // produced since the mask only applies to the lower elements and can't
327 // be represented by a select.
328 // SRC, PASSTHRU, MASK
345 // Masked version of above. Used for v2f64->v4f32.
346 // SRC, PASSTHRU, MASK
349 // 128-bit vector logical left / right shift
353 // Vector shift elements
358 // Vector variable shift
363 // Vector shift elements by immediate
368 // Shifts of mask registers.
372 // Bit rotate by immediate
376 // Vector packed double/float comparison.
379 // Vector integer comparisons.
383 // v8i16 Horizontal minimum and position.
388 /// Vector comparison generating mask bits for fp and
389 /// integer signed and unsigned data types.
391 // Vector mask comparison generating mask bits for FP values.
393 // Vector mask comparison with SAE for FP values.
396 // Arithmetic operations with FLAGS results.
407 // Bit field extract.
411 // Zero High Bits Starting with Specified Bit Position.
414 // Parallel extract and deposit.
418 // X86-specific multiply by immediate.
421 // Vector sign bit extraction.
424 // Vector bitwise comparisons.
427 // Vector packed fp sign bitwise comparisons.
430 // OR/AND test for masks.
437 // Several flavors of instructions with vector shuffle behaviors.
438 // Saturated signed/unnsigned packing.
441 // Intra-lane alignr.
443 // AVX512 inter-lane alignr.
449 // VBMI2 Concat & Shift.
454 // Shuffle Packed Values at 128-bit granularity.
470 // Variable Permute (VPERM).
471 // Res = VPERMV MaskV, V0
474 // 3-op Variable Permute (VPERMT2).
475 // Res = VPERMV3 V0, MaskV, V1
478 // Bitwise ternary logic.
480 // Fix Up Special Packed Float32/64 values.
485 // Range Restriction Calculation For Packed Pairs of Float32/64 values.
490 // Reduce - Perform Reduction Transformation on scalar\packed FP.
495 // RndScale - Round FP Values To Include A Given Number Of Fraction Bits.
496 // Also used by the legacy (V)ROUND intrinsics where we mask out the
497 // scaling part of the immediate.
502 // Tests Types Of a FP Values for packed types.
504 // Tests Types Of a FP Values for scalar types.
507 // Broadcast (splat) scalar or element 0 of a vector. If the operand is
508 // a vector, this node may change the vector length as part of the splat.
510 // Broadcast mask to vector.
513 /// SSE4A Extraction and Insertion.
517 // XOP arithmetic/logical shifts.
520 // XOP signed/unsigned integer comparisons.
523 // XOP packed permute bytes.
525 // XOP two source permutation.
528 // Vector multiply packed unsigned doubleword integers.
530 // Vector multiply packed signed doubleword integers.
532 // Vector Multiply Packed UnsignedIntegers with Round and Scale.
535 // Multiply and Add Packed Integers.
539 // AVX512IFMA multiply and add.
540 // NOTE: These are different than the instruction and perform
552 // We use the target independent ISD::FMA for the non-inverted case.
559 // FMA with rounding mode.
567 // Compress and expand.
574 // Convert Unsigned/Integer to Floating-Point Value with rounding mode.
579 SCALAR_SINT_TO_FP_RND,
580 SCALAR_UINT_TO_FP_RND,
582 // Vector float/double to signed/unsigned integer.
587 // Scalar float/double to signed/unsigned integer.
593 // Vector float/double to signed/unsigned integer with truncation.
598 // Scalar float/double to signed/unsigned integer with truncation.
604 // Vector signed/unsigned integer to float/double.
608 // Masked versions of above. Used for v2f64->v4f32.
609 // SRC, PASSTHRU, MASK
617 // Vector float to bfloat16.
618 // Convert TWO packed single data to one packed BF16 data
620 // Convert packed single data to packed BF16 data
622 // Masked version of above.
623 // SRC, PASSTHRU, MASK
626 // Dot product of BF16 pairs to accumulated into
627 // packed single precision.
630 // Save xmm argument registers to the stack, according to %al. An operator
631 // is needed so that this can be expanded with control flow.
632 VASTART_SAVE_XMM_REGS,
634 // Windows's _chkstk call to do stack probing.
637 // For allocating variable amounts of stack space when using
638 // segmented stacks. Check if the current stacklet has enough space, and
639 // falls back to heap allocation if not.
642 // For allocating stack space when using stack clash protector.
643 // Allocation is performed by block, and each block is probed.
650 // Get a random integer and indicate whether it is valid in CF.
653 // Get a NIST SP800-90B & C compliant random integer and
654 // indicate whether it is valid in CF.
658 // RDPKRU - Operand 0 is chain. Operand 1 is value for ECX.
659 // WRPKRU - Operand 0 is chain. Operand 1 is value for EDX. Operand 2 is
664 // SSE42 string comparisons.
665 // These nodes produce 3 results, index, mask, and flags. X86ISelDAGToDAG
666 // will emit one or two instructions based on which results are used. If
667 // flags and index/mask this allows us to use a single instruction since
668 // we won't have to pick and opcode for flags. Instead we can rely on the
669 // DAG to CSE everything and decide at isel.
673 // Test if in transactional execution.
688 // Conversions between float and half-float.
693 // Masked version of above.
694 // SRC, RND, PASSTHRU, MASK
697 // Galois Field Arithmetic Instructions
702 // LWP insert record.
709 // Enqueue Stores Instructions
713 // For avx512-vp2intersect
716 // User level interrupts - testui
719 /// X86 strict FP compare instructions.
720 STRICT_FCMP = ISD::FIRST_TARGET_STRICTFP_OPCODE,
723 // Vector packed double/float comparison.
726 /// Vector comparison generating mask bits for fp and
727 /// integer signed and unsigned data types.
730 // Vector float/double to signed/unsigned integer with truncation.
740 // RndScale - Round FP Values To Include A Given Number Of Fraction Bits.
741 // Also used by the legacy (V)ROUND intrinsics where we mask out the
742 // scaling part of the immediate.
745 // Vector signed/unsigned integer to float/double.
754 // Conversions between float and half-float.
758 // WARNING: Only add nodes here if they are stric FP nodes. Non-memory and
759 // non-strict FP nodes should be above FIRST_TARGET_STRICTFP_OPCODE.
762 LCMPXCHG_DAG = ISD::FIRST_TARGET_MEMORY_OPCODE,
765 LCMPXCHG16_SAVE_RBX_DAG,
767 /// LOCK-prefixed arithmetic read-modify-write instructions.
768 /// EFLAGS, OUTCHAIN = LADD(INCHAIN, PTR, RHS)
775 // Load, scalar_to_vector, and zero extend.
778 // extract_vector_elt, store.
781 // scalar broadcast from memory.
784 // subvector broadcast from memory.
787 // Store FP control word into i16 memory.
790 // Load FP control word from i16 memory.
793 /// This instruction implements FP_TO_SINT with the
794 /// integer destination in memory and a FP reg source. This corresponds
795 /// to the X86::FIST*m instructions and the rounding mode change stuff. It
796 /// has two inputs (token chain and address) and two outputs (int value
797 /// and token chain). Memory VT specifies the type to store to.
800 /// This instruction implements SINT_TO_FP with the
801 /// integer source in memory and FP reg result. This corresponds to the
802 /// X86::FILD*m instructions. It has two inputs (token chain and address)
803 /// and two outputs (FP value and token chain). The integer source type is
804 /// specified by the memory VT.
807 /// This instruction implements a fp->int store from FP stack
808 /// slots. This corresponds to the fist instruction. It takes a
809 /// chain operand, value to store, address, and glue. The memory VT
810 /// specifies the type to store as.
813 /// This instruction implements an extending load to FP stack slots.
814 /// This corresponds to the X86::FLD32m / X86::FLD64m. It takes a chain
815 /// operand, and ptr to load from. The memory VT specifies the type to
819 /// This instruction implements a truncating store from FP stack
820 /// slots. This corresponds to the X86::FST32m / X86::FST64m. It takes a
821 /// chain operand, value to store, address, and glue. The memory VT
822 /// specifies the type to store as.
825 /// These instructions grab the address of the next argument
826 /// from a va_list. (reads and modifies the va_list in memory)
830 // Vector truncating store with unsigned/signed saturation
833 // Vector truncating masked store with unsigned/signed saturation
837 // X86 specific gather and scatter
841 // Key locker nodes that produce flags.
851 // WARNING: Do not add anything in the end unless you want the node to
852 // have memop! In fact, starting from FIRST_TARGET_MEMORY_OPCODE all
853 // opcodes will be thought as target memory ops!
855 } // end namespace X86ISD
858 /// Current rounding mode is represented in bits 11:10 of FPSR. These
859 /// values are same as corresponding constants for rounding mode used
862 rmToNearest = 0, // FE_TONEAREST
863 rmDownward = 1 << 10, // FE_DOWNWARD
864 rmUpward = 2 << 10, // FE_UPWARD
865 rmTowardZero = 3 << 10, // FE_TOWARDZERO
866 rmMask = 3 << 10 // Bit mask selecting rounding mode
870 /// Define some predicates that are used for node matching.
872 /// Returns true if Elt is a constant zero or floating point constant +0.0.
873 bool isZeroNode(SDValue Elt);
875 /// Returns true of the given offset can be
876 /// fit into displacement field of the instruction.
877 bool isOffsetSuitableForCodeModel(int64_t Offset, CodeModel::Model M,
878 bool hasSymbolicDisplacement);
880 /// Determines whether the callee is required to pop its
881 /// own arguments. Callee pop is necessary to support tail calls.
882 bool isCalleePop(CallingConv::ID CallingConv,
883 bool is64Bit, bool IsVarArg, bool GuaranteeTCO);
885 /// If Op is a constant whose elements are all the same constant or
886 /// undefined, return true and return the constant value in \p SplatVal.
887 /// If we have undef bits that don't cover an entire element, we treat these
888 /// as zero if AllowPartialUndefs is set, else we fail and return false.
889 bool isConstantSplat(SDValue Op, APInt &SplatVal,
890 bool AllowPartialUndefs = true);
891 } // end namespace X86
893 //===--------------------------------------------------------------------===//
894 // X86 Implementation of the TargetLowering interface
895 class X86TargetLowering final : public TargetLowering {
897 explicit X86TargetLowering(const X86TargetMachine &TM,
898 const X86Subtarget &STI);
900 unsigned getJumpTableEncoding() const override;
901 bool useSoftFloat() const override;
903 void markLibCallAttributes(MachineFunction *MF, unsigned CC,
904 ArgListTy &Args) const override;
906 MVT getScalarShiftAmountTy(const DataLayout &, EVT VT) const override {
911 LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI,
912 const MachineBasicBlock *MBB, unsigned uid,
913 MCContext &Ctx) const override;
915 /// Returns relocation base for the given PIC jumptable.
916 SDValue getPICJumpTableRelocBase(SDValue Table,
917 SelectionDAG &DAG) const override;
919 getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
920 unsigned JTI, MCContext &Ctx) const override;
922 /// Return the desired alignment for ByVal aggregate
923 /// function arguments in the caller parameter area. For X86, aggregates
924 /// that contains are placed at 16-byte boundaries while the rest are at
925 /// 4-byte boundaries.
926 unsigned getByValTypeAlignment(Type *Ty,
927 const DataLayout &DL) const override;
929 EVT getOptimalMemOpType(const MemOp &Op,
930 const AttributeList &FuncAttributes) const override;
932 /// Returns true if it's safe to use load / store of the
933 /// specified type to expand memcpy / memset inline. This is mostly true
934 /// for all types except for some special cases. For example, on X86
935 /// targets without SSE2 f64 load / store are done with fldl / fstpl which
936 /// also does type conversion. Note the specified type doesn't have to be
937 /// legal as the hook is used before type legalization.
938 bool isSafeMemOpType(MVT VT) const override;
940 /// Returns true if the target allows unaligned memory accesses of the
941 /// specified type. Returns whether it is "fast" in the last argument.
942 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, Align Alignment,
943 MachineMemOperand::Flags Flags,
944 bool *Fast) const override;
946 /// Provide custom lowering hooks for some operations.
948 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
950 /// Replace the results of node with an illegal result
951 /// type with new values built out of custom code.
953 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
954 SelectionDAG &DAG) const override;
956 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
958 /// Return true if the target has native support for
959 /// the specified value type and it is 'desirable' to use the type for the
960 /// given node type. e.g. On x86 i16 is legal, but undesirable since i16
961 /// instruction encodings are longer and some i16 instructions are slow.
962 bool isTypeDesirableForOp(unsigned Opc, EVT VT) const override;
964 /// Return true if the target has native support for the
965 /// specified value type and it is 'desirable' to use the type. e.g. On x86
966 /// i16 is legal, but undesirable since i16 instruction encodings are longer
967 /// and some i16 instructions are slow.
968 bool IsDesirableToPromoteOp(SDValue Op, EVT &PVT) const override;
970 /// Return the newly negated expression if the cost is not expensive and
971 /// set the cost in \p Cost to indicate that if it is cheaper or neutral to
973 SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG,
974 bool LegalOperations, bool ForCodeSize,
976 unsigned Depth) const override;
979 EmitInstrWithCustomInserter(MachineInstr &MI,
980 MachineBasicBlock *MBB) const override;
982 /// This method returns the name of a target specific DAG node.
983 const char *getTargetNodeName(unsigned Opcode) const override;
985 /// Do not merge vector stores after legalization because that may conflict
986 /// with x86-specific store splitting optimizations.
987 bool mergeStoresAfterLegalization(EVT MemVT) const override {
988 return !MemVT.isVector();
991 bool canMergeStoresTo(unsigned AddressSpace, EVT MemVT,
992 const SelectionDAG &DAG) const override;
994 bool isCheapToSpeculateCttz() const override;
996 bool isCheapToSpeculateCtlz() const override;
998 bool isCtlzFast() const override;
1000 bool hasBitPreservingFPLogic(EVT VT) const override {
1001 return VT == MVT::f32 || VT == MVT::f64 || VT.isVector();
1004 bool isMultiStoresCheaperThanBitsMerge(EVT LTy, EVT HTy) const override {
1005 // If the pair to store is a mixture of float and int values, we will
1006 // save two bitwise instructions and one float-to-int instruction and
1007 // increase one store instruction. There is potentially a more
1008 // significant benefit because it avoids the float->int domain switch
1009 // for input value. So It is more likely a win.
1010 if ((LTy.isFloatingPoint() && HTy.isInteger()) ||
1011 (LTy.isInteger() && HTy.isFloatingPoint()))
1013 // If the pair only contains int values, we will save two bitwise
1014 // instructions and increase one store instruction (costing one more
1015 // store buffer). Since the benefit is more blurred so we leave
1016 // such pair out until we get testcase to prove it is a win.
1020 bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override;
1022 bool hasAndNotCompare(SDValue Y) const override;
1024 bool hasAndNot(SDValue Y) const override;
1026 bool hasBitTest(SDValue X, SDValue Y) const override;
1028 bool shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(
1029 SDValue X, ConstantSDNode *XC, ConstantSDNode *CC, SDValue Y,
1030 unsigned OldShiftOpcode, unsigned NewShiftOpcode,
1031 SelectionDAG &DAG) const override;
1033 bool shouldFoldConstantShiftPairToMask(const SDNode *N,
1034 CombineLevel Level) const override;
1036 bool shouldFoldMaskToVariableShiftPair(SDValue Y) const override;
1039 shouldTransformSignedTruncationCheck(EVT XVT,
1040 unsigned KeptBits) const override {
1041 // For vectors, we don't have a preference..
1045 auto VTIsOk = [](EVT VT) -> bool {
1046 return VT == MVT::i8 || VT == MVT::i16 || VT == MVT::i32 ||
1050 // We are ok with KeptBitsVT being byte/word/dword, what MOVS supports.
1051 // XVT will be larger than KeptBitsVT.
1052 MVT KeptBitsVT = MVT::getIntegerVT(KeptBits);
1053 return VTIsOk(XVT) && VTIsOk(KeptBitsVT);
1056 bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const override;
1058 bool shouldSplatInsEltVarIndex(EVT VT) const override;
1060 bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
1061 return VT.isScalarInteger();
1064 /// Vector-sized comparisons are fast using PCMPEQ + PMOVMSK or PTEST.
1065 MVT hasFastEqualityCompare(unsigned NumBits) const override;
1067 /// Return the value type to use for ISD::SETCC.
1068 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
1069 EVT VT) const override;
1071 bool targetShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits,
1072 const APInt &DemandedElts,
1073 TargetLoweringOpt &TLO) const override;
1075 /// Determine which of the bits specified in Mask are known to be either
1076 /// zero or one and return them in the KnownZero/KnownOne bitsets.
1077 void computeKnownBitsForTargetNode(const SDValue Op,
1079 const APInt &DemandedElts,
1080 const SelectionDAG &DAG,
1081 unsigned Depth = 0) const override;
1083 /// Determine the number of bits in the operation that are sign bits.
1084 unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
1085 const APInt &DemandedElts,
1086 const SelectionDAG &DAG,
1087 unsigned Depth) const override;
1089 bool SimplifyDemandedVectorEltsForTargetNode(SDValue Op,
1090 const APInt &DemandedElts,
1093 TargetLoweringOpt &TLO,
1094 unsigned Depth) const override;
1096 bool SimplifyDemandedVectorEltsForTargetShuffle(SDValue Op,
1097 const APInt &DemandedElts,
1099 TargetLoweringOpt &TLO,
1100 unsigned Depth) const;
1102 bool SimplifyDemandedBitsForTargetNode(SDValue Op,
1103 const APInt &DemandedBits,
1104 const APInt &DemandedElts,
1106 TargetLoweringOpt &TLO,
1107 unsigned Depth) const override;
1109 SDValue SimplifyMultipleUseDemandedBitsForTargetNode(
1110 SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
1111 SelectionDAG &DAG, unsigned Depth) const override;
1113 const Constant *getTargetConstantFromLoad(LoadSDNode *LD) const override;
1115 SDValue unwrapAddress(SDValue N) const override;
1117 SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const;
1119 bool ExpandInlineAsm(CallInst *CI) const override;
1121 ConstraintType getConstraintType(StringRef Constraint) const override;
1123 /// Examine constraint string and operand type and determine a weight value.
1124 /// The operand object must already have been set up with the operand type.
1126 getSingleConstraintMatchWeight(AsmOperandInfo &info,
1127 const char *constraint) const override;
1129 const char *LowerXConstraint(EVT ConstraintVT) const override;
1131 /// Lower the specified operand into the Ops vector. If it is invalid, don't
1132 /// add anything to Ops. If hasMemory is true it means one of the asm
1133 /// constraint of the inline asm instruction being processed is 'm'.
1134 void LowerAsmOperandForConstraint(SDValue Op,
1135 std::string &Constraint,
1136 std::vector<SDValue> &Ops,
1137 SelectionDAG &DAG) const override;
1140 getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
1141 if (ConstraintCode == "v")
1142 return InlineAsm::Constraint_v;
1143 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
1146 /// Handle Lowering flag assembly outputs.
1147 SDValue LowerAsmOutputForConstraint(SDValue &Chain, SDValue &Flag,
1149 const AsmOperandInfo &Constraint,
1150 SelectionDAG &DAG) const override;
1152 /// Given a physical register constraint
1153 /// (e.g. {edx}), return the register number and the register class for the
1154 /// register. This should only be used for C_Register constraints. On
1155 /// error, this returns a register number of 0.
1156 std::pair<unsigned, const TargetRegisterClass *>
1157 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
1158 StringRef Constraint, MVT VT) const override;
1160 /// Return true if the addressing mode represented
1161 /// by AM is legal for this target, for a load/store of the specified type.
1162 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
1163 Type *Ty, unsigned AS,
1164 Instruction *I = nullptr) const override;
1166 /// Return true if the specified immediate is legal
1167 /// icmp immediate, that is the target has icmp instructions which can
1168 /// compare a register against the immediate without having to materialize
1169 /// the immediate into a register.
1170 bool isLegalICmpImmediate(int64_t Imm) const override;
1172 /// Return true if the specified immediate is legal
1173 /// add immediate, that is the target has add instructions which can
1174 /// add a register and the immediate without having to materialize
1175 /// the immediate into a register.
1176 bool isLegalAddImmediate(int64_t Imm) const override;
1178 bool isLegalStoreImmediate(int64_t Imm) const override;
1180 /// Return the cost of the scaling factor used in the addressing
1181 /// mode represented by AM for this target, for a load/store
1182 /// of the specified type.
1183 /// If the AM is supported, the return value must be >= 0.
1184 /// If the AM is not supported, it returns a negative value.
1185 InstructionCost getScalingFactorCost(const DataLayout &DL,
1186 const AddrMode &AM, Type *Ty,
1187 unsigned AS) const override;
1189 /// This is used to enable splatted operand transforms for vector shifts
1190 /// and vector funnel shifts.
1191 bool isVectorShiftByScalarCheap(Type *Ty) const override;
1193 /// Add x86-specific opcodes to the default list.
1194 bool isBinOp(unsigned Opcode) const override;
1196 /// Returns true if the opcode is a commutative binary operation.
1197 bool isCommutativeBinOp(unsigned Opcode) const override;
1199 /// Return true if it's free to truncate a value of
1200 /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
1201 /// register EAX to i16 by referencing its sub-register AX.
1202 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
1203 bool isTruncateFree(EVT VT1, EVT VT2) const override;
1205 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
1207 /// Return true if any actual instruction that defines a
1208 /// value of type Ty1 implicit zero-extends the value to Ty2 in the result
1209 /// register. This does not necessarily include registers defined in
1210 /// unknown ways, such as incoming arguments, or copies from unknown
1211 /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this
1212 /// does not necessarily apply to truncate instructions. e.g. on x86-64,
1213 /// all instructions that define 32-bit values implicit zero-extend the
1214 /// result out to 64 bits.
1215 bool isZExtFree(Type *Ty1, Type *Ty2) const override;
1216 bool isZExtFree(EVT VT1, EVT VT2) const override;
1217 bool isZExtFree(SDValue Val, EVT VT2) const override;
1219 bool shouldSinkOperands(Instruction *I,
1220 SmallVectorImpl<Use *> &Ops) const override;
1221 bool shouldConvertPhiType(Type *From, Type *To) const override;
1223 /// Return true if folding a vector load into ExtVal (a sign, zero, or any
1224 /// extend node) is profitable.
1225 bool isVectorLoadExtDesirable(SDValue) const override;
1227 /// Return true if an FMA operation is faster than a pair of fmul and fadd
1228 /// instructions. fmuladd intrinsics will be expanded to FMAs when this
1229 /// method returns true, otherwise fmuladd is expanded to fmul + fadd.
1230 bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
1231 EVT VT) const override;
1233 /// Return true if it's profitable to narrow
1234 /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow
1235 /// from i32 to i8 but not from i32 to i16.
1236 bool isNarrowingProfitable(EVT VT1, EVT VT2) const override;
1238 /// Given an intrinsic, checks if on the target the intrinsic will need to map
1239 /// to a MemIntrinsicNode (touches memory). If this is the case, it returns
1240 /// true and stores the intrinsic information into the IntrinsicInfo that was
1241 /// passed to the function.
1242 bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
1243 MachineFunction &MF,
1244 unsigned Intrinsic) const override;
1246 /// Returns true if the target can instruction select the
1247 /// specified FP immediate natively. If false, the legalizer will
1248 /// materialize the FP immediate as a load from a constant pool.
1249 bool isFPImmLegal(const APFloat &Imm, EVT VT,
1250 bool ForCodeSize) const override;
1252 /// Targets can use this to indicate that they only support *some*
1253 /// VECTOR_SHUFFLE operations, those with specific masks. By default, if a
1254 /// target supports the VECTOR_SHUFFLE node, all mask values are assumed to
1256 bool isShuffleMaskLegal(ArrayRef<int> Mask, EVT VT) const override;
1258 /// Similar to isShuffleMaskLegal. Targets can use this to indicate if there
1259 /// is a suitable VECTOR_SHUFFLE that can be used to replace a VAND with a
1260 /// constant pool entry.
1261 bool isVectorClearMaskLegal(ArrayRef<int> Mask, EVT VT) const override;
1263 /// Returns true if lowering to a jump table is allowed.
1264 bool areJTsAllowed(const Function *Fn) const override;
1266 /// If true, then instruction selection should
1267 /// seek to shrink the FP constant of the specified type to a smaller type
1268 /// in order to save space and / or reduce runtime.
1269 bool ShouldShrinkFPConstant(EVT VT) const override {
1270 // Don't shrink FP constpool if SSE2 is available since cvtss2sd is more
1271 // expensive than a straight movsd. On the other hand, it's important to
1272 // shrink long double fp constant since fldt is very slow.
1273 return !X86ScalarSSEf64 || VT == MVT::f80;
1276 /// Return true if we believe it is correct and profitable to reduce the
1277 /// load node to a smaller type.
1278 bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy,
1279 EVT NewVT) const override;
1281 /// Return true if the specified scalar FP type is computed in an SSE
1282 /// register, not on the X87 floating point stack.
1283 bool isScalarFPTypeInSSEReg(EVT VT) const {
1284 return (VT == MVT::f64 && X86ScalarSSEf64) || // f64 is when SSE2
1285 (VT == MVT::f32 && X86ScalarSSEf32); // f32 is when SSE1
1288 /// Returns true if it is beneficial to convert a load of a constant
1289 /// to just the constant itself.
1290 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
1291 Type *Ty) const override;
1293 bool reduceSelectOfFPConstantLoads(EVT CmpOpVT) const override;
1295 bool convertSelectOfConstantsToMath(EVT VT) const override;
1297 bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
1298 SDValue C) const override;
1300 /// Return true if EXTRACT_SUBVECTOR is cheap for this result type
1301 /// with this index.
1302 bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
1303 unsigned Index) const override;
1305 /// Scalar ops always have equal or better analysis/performance/power than
1306 /// the vector equivalent, so this always makes sense if the scalar op is
1308 bool shouldScalarizeBinop(SDValue) const override;
1310 /// Extract of a scalar FP value from index 0 of a vector is free.
1311 bool isExtractVecEltCheap(EVT VT, unsigned Index) const override {
1312 EVT EltVT = VT.getScalarType();
1313 return (EltVT == MVT::f32 || EltVT == MVT::f64) && Index == 0;
1316 /// Overflow nodes should get combined/lowered to optimal instructions
1317 /// (they should allow eliminating explicit compares by getting flags from
1319 bool shouldFormOverflowOp(unsigned Opcode, EVT VT,
1320 bool MathUsed) const override;
1322 bool storeOfVectorConstantIsCheap(EVT MemVT, unsigned NumElem,
1323 unsigned AddrSpace) const override {
1324 // If we can replace more than 2 scalar stores, there will be a reduction
1325 // in instructions even after we add a vector constant load.
1329 bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT,
1330 const SelectionDAG &DAG,
1331 const MachineMemOperand &MMO) const override;
1333 /// Intel processors have a unified instruction and data cache
1334 const char * getClearCacheBuiltinName() const override {
1335 return nullptr; // nothing to do, move along.
1338 Register getRegisterByName(const char* RegName, LLT VT,
1339 const MachineFunction &MF) const override;
1341 /// If a physical register, this returns the register that receives the
1342 /// exception address on entry to an EH pad.
1344 getExceptionPointerRegister(const Constant *PersonalityFn) const override;
1346 /// If a physical register, this returns the register that receives the
1347 /// exception typeid on entry to a landing pad.
1349 getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
1351 virtual bool needsFixedCatchObjects() const override;
1353 /// This method returns a target specific FastISel object,
1354 /// or null if the target does not support "fast" ISel.
1355 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
1356 const TargetLibraryInfo *libInfo) const override;
1358 /// If the target has a standard location for the stack protector cookie,
1359 /// returns the address of that location. Otherwise, returns nullptr.
1360 Value *getIRStackGuard(IRBuilderBase &IRB) const override;
1362 bool useLoadStackGuardNode() const override;
1363 bool useStackGuardXorFP() const override;
1364 void insertSSPDeclarations(Module &M) const override;
1365 Value *getSDagStackGuard(const Module &M) const override;
1366 Function *getSSPStackGuardCheck(const Module &M) const override;
1367 SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val,
1368 const SDLoc &DL) const override;
1371 /// Return true if the target stores SafeStack pointer at a fixed offset in
1372 /// some non-standard address space, and populates the address space and
1373 /// offset as appropriate.
1374 Value *getSafeStackPointerLocation(IRBuilderBase &IRB) const override;
1376 std::pair<SDValue, SDValue> BuildFILD(EVT DstVT, EVT SrcVT, const SDLoc &DL,
1377 SDValue Chain, SDValue Pointer,
1378 MachinePointerInfo PtrInfo,
1380 SelectionDAG &DAG) const;
1382 /// Customize the preferred legalization strategy for certain types.
1383 LegalizeTypeAction getPreferredVectorAction(MVT VT) const override;
1385 bool softPromoteHalfType() const override { return true; }
1387 MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC,
1388 EVT VT) const override;
1390 unsigned getNumRegistersForCallingConv(LLVMContext &Context,
1392 EVT VT) const override;
1394 unsigned getVectorTypeBreakdownForCallingConv(
1395 LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT,
1396 unsigned &NumIntermediates, MVT &RegisterVT) const override;
1398 bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
1400 bool supportSwiftError() const override;
1402 bool hasStackProbeSymbol(MachineFunction &MF) const override;
1403 bool hasInlineStackProbe(MachineFunction &MF) const override;
1404 StringRef getStackProbeSymbolName(MachineFunction &MF) const override;
1406 unsigned getStackProbeSize(MachineFunction &MF) const;
1408 bool hasVectorBlend() const override { return true; }
1410 unsigned getMaxSupportedInterleaveFactor() const override { return 4; }
1412 /// Lower interleaved load(s) into target specific
1413 /// instructions/intrinsics.
1414 bool lowerInterleavedLoad(LoadInst *LI,
1415 ArrayRef<ShuffleVectorInst *> Shuffles,
1416 ArrayRef<unsigned> Indices,
1417 unsigned Factor) const override;
1419 /// Lower interleaved store(s) into target specific
1420 /// instructions/intrinsics.
1421 bool lowerInterleavedStore(StoreInst *SI, ShuffleVectorInst *SVI,
1422 unsigned Factor) const override;
1424 SDValue expandIndirectJTBranch(const SDLoc& dl, SDValue Value,
1425 SDValue Addr, SelectionDAG &DAG)
1428 Align getPrefLoopAlignment(MachineLoop *ML) const override;
1431 std::pair<const TargetRegisterClass *, uint8_t>
1432 findRepresentativeClass(const TargetRegisterInfo *TRI,
1433 MVT VT) const override;
1436 /// Keep a reference to the X86Subtarget around so that we can
1437 /// make the right decision when generating code for different targets.
1438 const X86Subtarget &Subtarget;
1440 /// Select between SSE or x87 floating point ops.
1441 /// When SSE is available, use it for f32 operations.
1442 /// When SSE2 is available, use it for f64 operations.
1443 bool X86ScalarSSEf32;
1444 bool X86ScalarSSEf64;
1446 /// A list of legal FP immediates.
1447 std::vector<APFloat> LegalFPImmediates;
1449 /// Indicate that this x86 target can instruction
1450 /// select the specified FP immediate natively.
1451 void addLegalFPImmediate(const APFloat& Imm) {
1452 LegalFPImmediates.push_back(Imm);
1455 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
1456 CallingConv::ID CallConv, bool isVarArg,
1457 const SmallVectorImpl<ISD::InputArg> &Ins,
1458 const SDLoc &dl, SelectionDAG &DAG,
1459 SmallVectorImpl<SDValue> &InVals,
1460 uint32_t *RegMask) const;
1461 SDValue LowerMemArgument(SDValue Chain, CallingConv::ID CallConv,
1462 const SmallVectorImpl<ISD::InputArg> &ArgInfo,
1463 const SDLoc &dl, SelectionDAG &DAG,
1464 const CCValAssign &VA, MachineFrameInfo &MFI,
1466 SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg,
1467 const SDLoc &dl, SelectionDAG &DAG,
1468 const CCValAssign &VA,
1469 ISD::ArgFlagsTy Flags, bool isByval) const;
1471 // Call lowering helpers.
1473 /// Check whether the call is eligible for tail call optimization. Targets
1474 /// that want to do tail call optimization should implement this function.
1475 bool IsEligibleForTailCallOptimization(SDValue Callee,
1476 CallingConv::ID CalleeCC,
1478 bool isCalleeStructRet,
1479 bool isCallerStructRet,
1481 const SmallVectorImpl<ISD::OutputArg> &Outs,
1482 const SmallVectorImpl<SDValue> &OutVals,
1483 const SmallVectorImpl<ISD::InputArg> &Ins,
1484 SelectionDAG& DAG) const;
1485 SDValue EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr,
1486 SDValue Chain, bool IsTailCall,
1487 bool Is64Bit, int FPDiff,
1488 const SDLoc &dl) const;
1490 unsigned GetAlignedArgumentStackSize(unsigned StackSize,
1491 SelectionDAG &DAG) const;
1493 unsigned getAddressSpace(void) const;
1495 SDValue FP_TO_INTHelper(SDValue Op, SelectionDAG &DAG, bool IsSigned,
1496 SDValue &Chain) const;
1497 SDValue LRINT_LLRINTHelper(SDNode *N, SelectionDAG &DAG) const;
1499 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
1500 SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const;
1501 SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
1502 SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
1504 unsigned getGlobalWrapperKind(const GlobalValue *GV = nullptr,
1505 const unsigned char OpFlags = 0) const;
1506 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
1507 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
1508 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
1509 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
1510 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
1512 /// Creates target global address or external symbol nodes for calls or
1514 SDValue LowerGlobalOrExternal(SDValue Op, SelectionDAG &DAG,
1515 bool ForCall) const;
1517 SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
1518 SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
1519 SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
1520 SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const;
1521 SDValue LowerFP_TO_INT_SAT(SDValue Op, SelectionDAG &DAG) const;
1522 SDValue LowerLRINT_LLRINT(SDValue Op, SelectionDAG &DAG) const;
1523 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
1524 SDValue LowerSETCCCARRY(SDValue Op, SelectionDAG &DAG) const;
1525 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
1526 SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
1527 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
1528 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
1529 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
1530 SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const;
1531 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
1532 SDValue LowerADDROFRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
1533 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
1534 SDValue LowerFRAME_TO_ARGS_OFFSET(SDValue Op, SelectionDAG &DAG) const;
1535 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
1536 SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
1537 SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
1538 SDValue lowerEH_SJLJ_SETUP_DISPATCH(SDValue Op, SelectionDAG &DAG) const;
1539 SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
1540 SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
1541 SDValue LowerSET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
1542 SDValue LowerWin64_i128OP(SDValue Op, SelectionDAG &DAG) const;
1543 SDValue LowerGC_TRANSITION(SDValue Op, SelectionDAG &DAG) const;
1544 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
1545 SDValue lowerFaddFsub(SDValue Op, SelectionDAG &DAG) const;
1546 SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
1547 SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
1550 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
1551 const SmallVectorImpl<ISD::InputArg> &Ins,
1552 const SDLoc &dl, SelectionDAG &DAG,
1553 SmallVectorImpl<SDValue> &InVals) const override;
1554 SDValue LowerCall(CallLoweringInfo &CLI,
1555 SmallVectorImpl<SDValue> &InVals) const override;
1557 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
1558 const SmallVectorImpl<ISD::OutputArg> &Outs,
1559 const SmallVectorImpl<SDValue> &OutVals,
1560 const SDLoc &dl, SelectionDAG &DAG) const override;
1562 bool supportSplitCSR(MachineFunction *MF) const override {
1563 return MF->getFunction().getCallingConv() == CallingConv::CXX_FAST_TLS &&
1564 MF->getFunction().hasFnAttribute(Attribute::NoUnwind);
1566 void initializeSplitCSR(MachineBasicBlock *Entry) const override;
1567 void insertCopiesSplitCSR(
1568 MachineBasicBlock *Entry,
1569 const SmallVectorImpl<MachineBasicBlock *> &Exits) const override;
1571 bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const override;
1573 bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
1575 EVT getTypeForExtReturn(LLVMContext &Context, EVT VT,
1576 ISD::NodeType ExtendKind) const override;
1578 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
1580 const SmallVectorImpl<ISD::OutputArg> &Outs,
1581 LLVMContext &Context) const override;
1583 const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
1585 TargetLoweringBase::AtomicExpansionKind
1586 shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
1587 bool shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
1588 TargetLoweringBase::AtomicExpansionKind
1589 shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
1592 lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const override;
1594 bool lowerAtomicStoreAsStoreSDNode(const StoreInst &SI) const override;
1595 bool lowerAtomicLoadAsLoadSDNode(const LoadInst &LI) const override;
1597 bool needsCmpXchgNb(Type *MemType) const;
1599 void SetupEntryBlockForSjLj(MachineInstr &MI, MachineBasicBlock *MBB,
1600 MachineBasicBlock *DispatchBB, int FI) const;
1602 // Utility function to emit the low-level va_arg code for X86-64.
1604 EmitVAARGWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const;
1606 /// Utility function to emit the xmm reg save portion of va_start.
1607 MachineBasicBlock *EmitLoweredCascadedSelect(MachineInstr &MI1,
1609 MachineBasicBlock *BB) const;
1611 MachineBasicBlock *EmitLoweredSelect(MachineInstr &I,
1612 MachineBasicBlock *BB) const;
1614 MachineBasicBlock *EmitLoweredCatchRet(MachineInstr &MI,
1615 MachineBasicBlock *BB) const;
1617 MachineBasicBlock *EmitLoweredSegAlloca(MachineInstr &MI,
1618 MachineBasicBlock *BB) const;
1620 MachineBasicBlock *EmitLoweredProbedAlloca(MachineInstr &MI,
1621 MachineBasicBlock *BB) const;
1623 MachineBasicBlock *EmitLoweredTLSAddr(MachineInstr &MI,
1624 MachineBasicBlock *BB) const;
1626 MachineBasicBlock *EmitLoweredTLSCall(MachineInstr &MI,
1627 MachineBasicBlock *BB) const;
1629 MachineBasicBlock *EmitLoweredIndirectThunk(MachineInstr &MI,
1630 MachineBasicBlock *BB) const;
1632 MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr &MI,
1633 MachineBasicBlock *MBB) const;
1635 void emitSetJmpShadowStackFix(MachineInstr &MI,
1636 MachineBasicBlock *MBB) const;
1638 MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr &MI,
1639 MachineBasicBlock *MBB) const;
1641 MachineBasicBlock *emitLongJmpShadowStackFix(MachineInstr &MI,
1642 MachineBasicBlock *MBB) const;
1644 MachineBasicBlock *EmitSjLjDispatchBlock(MachineInstr &MI,
1645 MachineBasicBlock *MBB) const;
1647 /// Emit flags for the given setcc condition and operands. Also returns the
1648 /// corresponding X86 condition code constant in X86CC.
1649 SDValue emitFlagsForSetcc(SDValue Op0, SDValue Op1, ISD::CondCode CC,
1650 const SDLoc &dl, SelectionDAG &DAG,
1651 SDValue &X86CC) const;
1653 /// Check if replacement of SQRT with RSQRT should be disabled.
1654 bool isFsqrtCheap(SDValue Op, SelectionDAG &DAG) const override;
1656 /// Use rsqrt* to speed up sqrt calculations.
1657 SDValue getSqrtEstimate(SDValue Op, SelectionDAG &DAG, int Enabled,
1658 int &RefinementSteps, bool &UseOneConstNR,
1659 bool Reciprocal) const override;
1661 /// Use rcp* to speed up fdiv calculations.
1662 SDValue getRecipEstimate(SDValue Op, SelectionDAG &DAG, int Enabled,
1663 int &RefinementSteps) const override;
1665 /// Reassociate floating point divisions into multiply by reciprocal.
1666 unsigned combineRepeatedFPDivisors() const override;
1668 SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
1669 SmallVectorImpl<SDNode *> &Created) const override;
1673 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
1674 const TargetLibraryInfo *libInfo);
1675 } // end namespace X86
1677 // X86 specific Gather/Scatter nodes.
1678 // The class has the same order of operands as MaskedGatherScatterSDNode for
1680 class X86MaskedGatherScatterSDNode : public MemIntrinsicSDNode {
1682 // This is a intended as a utility and should never be directly created.
1683 X86MaskedGatherScatterSDNode() = delete;
1684 ~X86MaskedGatherScatterSDNode() = delete;
1686 const SDValue &getBasePtr() const { return getOperand(3); }
1687 const SDValue &getIndex() const { return getOperand(4); }
1688 const SDValue &getMask() const { return getOperand(2); }
1689 const SDValue &getScale() const { return getOperand(5); }
1691 static bool classof(const SDNode *N) {
1692 return N->getOpcode() == X86ISD::MGATHER ||
1693 N->getOpcode() == X86ISD::MSCATTER;
1697 class X86MaskedGatherSDNode : public X86MaskedGatherScatterSDNode {
1699 const SDValue &getPassThru() const { return getOperand(1); }
1701 static bool classof(const SDNode *N) {
1702 return N->getOpcode() == X86ISD::MGATHER;
1706 class X86MaskedScatterSDNode : public X86MaskedGatherScatterSDNode {
1708 const SDValue &getValue() const { return getOperand(1); }
1710 static bool classof(const SDNode *N) {
1711 return N->getOpcode() == X86ISD::MSCATTER;
1715 /// Generate unpacklo/unpackhi shuffle mask.
1716 void createUnpackShuffleMask(EVT VT, SmallVectorImpl<int> &Mask, bool Lo,
1719 /// Similar to unpacklo/unpackhi, but without the 128-bit lane limitation
1720 /// imposed by AVX and specific to the unary pattern. Example:
1721 /// v8iX Lo --> <0, 0, 1, 1, 2, 2, 3, 3>
1722 /// v8iX Hi --> <4, 4, 5, 5, 6, 6, 7, 7>
1723 void createSplat2ShuffleMask(MVT VT, SmallVectorImpl<int> &Mask, bool Lo);
1725 } // end namespace llvm
1727 #endif // LLVM_LIB_TARGET_X86_X86ISELLOWERING_H