1 //===-- RISCVISelLowering.h - RISCV DAG Lowering Interface ------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interfaces that RISCV uses to lower LLVM code into a
10 // selection DAG.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_RISCV_RISCVISELLOWERING_H
15 #define LLVM_LIB_TARGET_RISCV_RISCVISELLOWERING_H
16 
17 #include "RISCV.h"
18 #include "llvm/CodeGen/CallingConvLower.h"
19 #include "llvm/CodeGen/SelectionDAG.h"
20 #include "llvm/CodeGen/TargetLowering.h"
21 
22 namespace llvm {
23 class RISCVSubtarget;
24 struct RISCVRegisterInfo;
25 namespace RISCVISD {
26 enum NodeType : unsigned {
27   FIRST_NUMBER = ISD::BUILTIN_OP_END,
28   RET_FLAG,
29   URET_FLAG,
30   SRET_FLAG,
31   MRET_FLAG,
32   CALL,
33   /// Select with condition operator - This selects between a true value and
34   /// a false value (ops #3 and #4) based on the boolean result of comparing
35   /// the lhs and rhs (ops #0 and #1) of a conditional expression with the
36   /// condition code in op #2, a XLenVT constant from the ISD::CondCode enum.
37   /// The lhs and rhs are XLenVT integers. The true and false values can be
38   /// integer or floating point.
39   SELECT_CC,
40   BR_CC,
41   BuildPairF64,
42   SplitF64,
43   TAIL,
44   // Multiply high for signedxunsigned.
45   MULHSU,
46   // RV64I shifts, directly matching the semantics of the named RISC-V
47   // instructions.
48   SLLW,
49   SRAW,
50   SRLW,
51   // 32-bit operations from RV64M that can't be simply matched with a pattern
52   // at instruction selection time. These have undefined behavior for division
53   // by 0 or overflow (divw) like their target independent counterparts.
54   DIVW,
55   DIVUW,
56   REMUW,
57   // RV64IB rotates, directly matching the semantics of the named RISC-V
58   // instructions.
59   ROLW,
60   RORW,
61   // RV64IZbb bit counting instructions directly matching the semantics of the
62   // named RISC-V instructions.
63   CLZW,
64   CTZW,
65   // RV64IB/RV32IB funnel shifts, with the semantics of the named RISC-V
66   // instructions, but the same operand order as fshl/fshr intrinsics.
67   FSR,
68   FSL,
69   // RV64IB funnel shifts, with the semantics of the named RISC-V instructions,
70   // but the same operand order as fshl/fshr intrinsics.
71   FSRW,
72   FSLW,
73   // FPR<->GPR transfer operations when the FPR is smaller than XLEN, needed as
74   // XLEN is the only legal integer width.
75   //
76   // FMV_H_X matches the semantics of the FMV.H.X.
77   // FMV_X_ANYEXTH is similar to FMV.X.H but has an any-extended result.
78   // FMV_W_X_RV64 matches the semantics of the FMV.W.X.
79   // FMV_X_ANYEXTW_RV64 is similar to FMV.X.W but has an any-extended result.
80   //
81   // This is a more convenient semantic for producing dagcombines that remove
82   // unnecessary GPR->FPR->GPR moves.
83   FMV_H_X,
84   FMV_X_ANYEXTH,
85   FMV_W_X_RV64,
86   FMV_X_ANYEXTW_RV64,
87   // FP to XLen int conversions. Corresponds to fcvt.l(u).s/d/h on RV64 and
88   // fcvt.w(u).s/d/h on RV32. Unlike FP_TO_S/UINT these saturate out of
89   // range inputs. These are used for FP_TO_S/UINT_SAT lowering.
90   FCVT_X_RTZ,
91   FCVT_XU_RTZ,
92   // FP to 32 bit int conversions for RV64. These are used to keep track of the
93   // result being sign extended to 64 bit. These saturate out of range inputs.
94   // Used for FP_TO_S/UINT and FP_TO_S/UINT_SAT lowering.
95   FCVT_W_RTZ_RV64,
96   FCVT_WU_RTZ_RV64,
97   // READ_CYCLE_WIDE - A read of the 64-bit cycle CSR on a 32-bit target
98   // (returns (Lo, Hi)). It takes a chain operand.
99   READ_CYCLE_WIDE,
100   // Generalized Reverse and Generalized Or-Combine - directly matching the
101   // semantics of the named RISC-V instructions. Lowered as custom nodes as
102   // TableGen chokes when faced with commutative permutations in deeply-nested
103   // DAGs. Each node takes an input operand and a control operand and outputs a
104   // bit-manipulated version of input. All operands are i32 or XLenVT.
105   GREV,
106   GREVW,
107   GORC,
108   GORCW,
109   SHFL,
110   SHFLW,
111   UNSHFL,
112   UNSHFLW,
113   // Bit Compress/Decompress implement the generic bit extract and bit deposit
114   // functions. This operation is also referred to as bit gather/scatter, bit
115   // pack/unpack, parallel extract/deposit, compress/expand, or right
116   // compress/right expand.
117   BCOMPRESS,
118   BCOMPRESSW,
119   BDECOMPRESS,
120   BDECOMPRESSW,
121   // Vector Extension
122   // VMV_V_X_VL matches the semantics of vmv.v.x but includes an extra operand
123   // for the VL value to be used for the operation.
124   VMV_V_X_VL,
125   // VFMV_V_F_VL matches the semantics of vfmv.v.f but includes an extra operand
126   // for the VL value to be used for the operation.
127   VFMV_V_F_VL,
128   // VMV_X_S matches the semantics of vmv.x.s. The result is always XLenVT sign
129   // extended from the vector element size.
130   VMV_X_S,
131   // VMV_S_X_VL matches the semantics of vmv.s.x. It carries a VL operand.
132   VMV_S_X_VL,
133   // VFMV_S_F_VL matches the semantics of vfmv.s.f. It carries a VL operand.
134   VFMV_S_F_VL,
135   // Splats an i64 scalar to a vector type (with element type i64) where the
136   // scalar is a sign-extended i32.
137   SPLAT_VECTOR_I64,
138   // Splats an 64-bit value that has been split into two i32 parts. This is
139   // expanded late to two scalar stores and a stride 0 vector load.
140   SPLAT_VECTOR_SPLIT_I64_VL,
141   // Read VLENB CSR
142   READ_VLENB,
143   // Truncates a RVV integer vector by one power-of-two. Carries both an extra
144   // mask and VL operand.
145   TRUNCATE_VECTOR_VL,
146   // Matches the semantics of vslideup/vslidedown. The first operand is the
147   // pass-thru operand, the second is the source vector, the third is the
148   // XLenVT index (either constant or non-constant), the fourth is the mask
149   // and the fifth the VL.
150   VSLIDEUP_VL,
151   VSLIDEDOWN_VL,
152   // Matches the semantics of vslide1up/slide1down. The first operand is the
153   // source vector, the second is the XLenVT scalar value. The third and fourth
154   // operands are the mask and VL operands.
155   VSLIDE1UP_VL,
156   VSLIDE1DOWN_VL,
157   // Matches the semantics of the vid.v instruction, with a mask and VL
158   // operand.
159   VID_VL,
160   // Matches the semantics of the vfcnvt.rod function (Convert double-width
161   // float to single-width float, rounding towards odd). Takes a double-width
162   // float vector and produces a single-width float vector. Also has a mask and
163   // VL operand.
164   VFNCVT_ROD_VL,
165   // These nodes match the semantics of the corresponding RVV vector reduction
166   // instructions. They produce a vector result which is the reduction
167   // performed over the first vector operand plus the first element of the
168   // second vector operand. The first operand is an unconstrained vector type,
169   // and the result and second operand's types are expected to be the
170   // corresponding full-width LMUL=1 type for the first operand:
171   //   nxv8i8 = vecreduce_add nxv32i8, nxv8i8
172   //   nxv2i32 = vecreduce_add nxv8i32, nxv2i32
173   // The different in types does introduce extra vsetvli instructions but
174   // similarly it reduces the number of registers consumed per reduction.
175   // Also has a mask and VL operand.
176   VECREDUCE_ADD_VL,
177   VECREDUCE_UMAX_VL,
178   VECREDUCE_SMAX_VL,
179   VECREDUCE_UMIN_VL,
180   VECREDUCE_SMIN_VL,
181   VECREDUCE_AND_VL,
182   VECREDUCE_OR_VL,
183   VECREDUCE_XOR_VL,
184   VECREDUCE_FADD_VL,
185   VECREDUCE_SEQ_FADD_VL,
186   VECREDUCE_FMIN_VL,
187   VECREDUCE_FMAX_VL,
188 
189   // Vector binary and unary ops with a mask as a third operand, and VL as a
190   // fourth operand.
191   // FIXME: Can we replace these with ISD::VP_*?
192   ADD_VL,
193   AND_VL,
194   MUL_VL,
195   OR_VL,
196   SDIV_VL,
197   SHL_VL,
198   SREM_VL,
199   SRA_VL,
200   SRL_VL,
201   SUB_VL,
202   UDIV_VL,
203   UREM_VL,
204   XOR_VL,
205 
206   SADDSAT_VL,
207   UADDSAT_VL,
208   SSUBSAT_VL,
209   USUBSAT_VL,
210 
211   FADD_VL,
212   FSUB_VL,
213   FMUL_VL,
214   FDIV_VL,
215   FNEG_VL,
216   FABS_VL,
217   FSQRT_VL,
218   FMA_VL,
219   FCOPYSIGN_VL,
220   SMIN_VL,
221   SMAX_VL,
222   UMIN_VL,
223   UMAX_VL,
224   FMINNUM_VL,
225   FMAXNUM_VL,
226   MULHS_VL,
227   MULHU_VL,
228   FP_TO_SINT_VL,
229   FP_TO_UINT_VL,
230   SINT_TO_FP_VL,
231   UINT_TO_FP_VL,
232   FP_ROUND_VL,
233   FP_EXTEND_VL,
234 
235   // Widening instructions
236   VWMUL_VL,
237   VWMULU_VL,
238 
239   // Vector compare producing a mask. Fourth operand is input mask. Fifth
240   // operand is VL.
241   SETCC_VL,
242 
243   // Vector select with an additional VL operand. This operation is unmasked.
244   VSELECT_VL,
245 
246   // Mask binary operators.
247   VMAND_VL,
248   VMOR_VL,
249   VMXOR_VL,
250 
251   // Set mask vector to all zeros or ones.
252   VMCLR_VL,
253   VMSET_VL,
254 
255   // Matches the semantics of vrgather.vx and vrgather.vv with an extra operand
256   // for VL.
257   VRGATHER_VX_VL,
258   VRGATHER_VV_VL,
259   VRGATHEREI16_VV_VL,
260 
261   // Vector sign/zero extend with additional mask & VL operands.
262   VSEXT_VL,
263   VZEXT_VL,
264 
265   //  vpopc.m with additional mask and VL operands.
266   VPOPC_VL,
267 
268   // Reads value of CSR.
269   // The first operand is a chain pointer. The second specifies address of the
270   // required CSR. Two results are produced, the read value and the new chain
271   // pointer.
272   READ_CSR,
273   // Write value to CSR.
274   // The first operand is a chain pointer, the second specifies address of the
275   // required CSR and the third is the value to write. The result is the new
276   // chain pointer.
277   WRITE_CSR,
278   // Read and write value of CSR.
279   // The first operand is a chain pointer, the second specifies address of the
280   // required CSR and the third is the value to write. Two results are produced,
281   // the value read before the modification and the new chain pointer.
282   SWAP_CSR,
283 
284   // Memory opcodes start here.
285   VLE_VL = ISD::FIRST_TARGET_MEMORY_OPCODE,
286   VSE_VL,
287 
288   // WARNING: Do not add anything in the end unless you want the node to
289   // have memop! In fact, starting from FIRST_TARGET_MEMORY_OPCODE all
290   // opcodes will be thought as target memory ops!
291 };
292 } // namespace RISCVISD
293 
294 class RISCVTargetLowering : public TargetLowering {
295   const RISCVSubtarget &Subtarget;
296 
297 public:
298   explicit RISCVTargetLowering(const TargetMachine &TM,
299                                const RISCVSubtarget &STI);
300 
301   const RISCVSubtarget &getSubtarget() const { return Subtarget; }
302 
303   bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
304                           MachineFunction &MF,
305                           unsigned Intrinsic) const override;
306   bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
307                              unsigned AS,
308                              Instruction *I = nullptr) const override;
309   bool isLegalICmpImmediate(int64_t Imm) const override;
310   bool isLegalAddImmediate(int64_t Imm) const override;
311   bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;
312   bool isTruncateFree(EVT SrcVT, EVT DstVT) const override;
313   bool isZExtFree(SDValue Val, EVT VT2) const override;
314   bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const override;
315   bool isCheapToSpeculateCttz() const override;
316   bool isCheapToSpeculateCtlz() const override;
317   bool isFPImmLegal(const APFloat &Imm, EVT VT,
318                     bool ForCodeSize) const override;
319 
320   bool softPromoteHalfType() const override { return true; }
321 
322   /// Return the register type for a given MVT, ensuring vectors are treated
323   /// as a series of gpr sized integers.
324   MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC,
325                                     EVT VT) const override;
326 
327   /// Return the number of registers for a given MVT, ensuring vectors are
328   /// treated as a series of gpr sized integers.
329   unsigned getNumRegistersForCallingConv(LLVMContext &Context,
330                                          CallingConv::ID CC,
331                                          EVT VT) const override;
332 
333   /// Return true if the given shuffle mask can be codegen'd directly, or if it
334   /// should be stack expanded.
335   bool isShuffleMaskLegal(ArrayRef<int> M, EVT VT) const override;
336 
337   bool hasBitPreservingFPLogic(EVT VT) const override;
338   bool
339   shouldExpandBuildVectorWithShuffles(EVT VT,
340                                       unsigned DefinedValues) const override;
341 
342   // Provide custom lowering hooks for some operations.
343   SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
344   void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
345                           SelectionDAG &DAG) const override;
346 
347   SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
348 
349   bool targetShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits,
350                                     const APInt &DemandedElts,
351                                     TargetLoweringOpt &TLO) const override;
352 
353   void computeKnownBitsForTargetNode(const SDValue Op,
354                                      KnownBits &Known,
355                                      const APInt &DemandedElts,
356                                      const SelectionDAG &DAG,
357                                      unsigned Depth) const override;
358   unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
359                                            const APInt &DemandedElts,
360                                            const SelectionDAG &DAG,
361                                            unsigned Depth) const override;
362 
363   // This method returns the name of a target specific DAG node.
364   const char *getTargetNodeName(unsigned Opcode) const override;
365 
366   ConstraintType getConstraintType(StringRef Constraint) const override;
367 
368   unsigned getInlineAsmMemConstraint(StringRef ConstraintCode) const override;
369 
370   std::pair<unsigned, const TargetRegisterClass *>
371   getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
372                                StringRef Constraint, MVT VT) const override;
373 
374   void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
375                                     std::vector<SDValue> &Ops,
376                                     SelectionDAG &DAG) const override;
377 
378   MachineBasicBlock *
379   EmitInstrWithCustomInserter(MachineInstr &MI,
380                               MachineBasicBlock *BB) const override;
381 
382   EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
383                          EVT VT) const override;
384 
385   bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
386     return VT.isScalarInteger();
387   }
388   bool convertSelectOfConstantsToMath(EVT VT) const override { return true; }
389 
390   bool shouldInsertFencesForAtomic(const Instruction *I) const override {
391     return isa<LoadInst>(I) || isa<StoreInst>(I);
392   }
393   Instruction *emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst,
394                                 AtomicOrdering Ord) const override;
395   Instruction *emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst,
396                                  AtomicOrdering Ord) const override;
397 
398   bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
399                                   EVT VT) const override;
400 
401   ISD::NodeType getExtendForAtomicOps() const override {
402     return ISD::SIGN_EXTEND;
403   }
404 
405   ISD::NodeType getExtendForAtomicCmpSwapArg() const override {
406     return ISD::SIGN_EXTEND;
407   }
408 
409   bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const override {
410     if (DAG.getMachineFunction().getFunction().hasMinSize())
411       return false;
412     return true;
413   }
414   bool isDesirableToCommuteWithShift(const SDNode *N,
415                                      CombineLevel Level) const override;
416 
417   /// If a physical register, this returns the register that receives the
418   /// exception address on entry to an EH pad.
419   Register
420   getExceptionPointerRegister(const Constant *PersonalityFn) const override;
421 
422   /// If a physical register, this returns the register that receives the
423   /// exception typeid on entry to a landing pad.
424   Register
425   getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
426 
427   bool shouldExtendTypeInLibCall(EVT Type) const override;
428   bool shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned) const override;
429 
430   /// Returns the register with the specified architectural or ABI name. This
431   /// method is necessary to lower the llvm.read_register.* and
432   /// llvm.write_register.* intrinsics. Allocatable registers must be reserved
433   /// with the clang -ffixed-xX flag for access to be allowed.
434   Register getRegisterByName(const char *RegName, LLT VT,
435                              const MachineFunction &MF) const override;
436 
437   // Lower incoming arguments, copy physregs into vregs
438   SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
439                                bool IsVarArg,
440                                const SmallVectorImpl<ISD::InputArg> &Ins,
441                                const SDLoc &DL, SelectionDAG &DAG,
442                                SmallVectorImpl<SDValue> &InVals) const override;
443   bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
444                       bool IsVarArg,
445                       const SmallVectorImpl<ISD::OutputArg> &Outs,
446                       LLVMContext &Context) const override;
447   SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
448                       const SmallVectorImpl<ISD::OutputArg> &Outs,
449                       const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
450                       SelectionDAG &DAG) const override;
451   SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
452                     SmallVectorImpl<SDValue> &InVals) const override;
453 
454   bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
455                                          Type *Ty) const override {
456     return true;
457   }
458   bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
459   bool shouldConsiderGEPOffsetSplit() const override { return true; }
460 
461   bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
462                               SDValue C) const override;
463 
464   TargetLowering::AtomicExpansionKind
465   shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
466   Value *emitMaskedAtomicRMWIntrinsic(IRBuilderBase &Builder, AtomicRMWInst *AI,
467                                       Value *AlignedAddr, Value *Incr,
468                                       Value *Mask, Value *ShiftAmt,
469                                       AtomicOrdering Ord) const override;
470   TargetLowering::AtomicExpansionKind
471   shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *CI) const override;
472   Value *emitMaskedAtomicCmpXchgIntrinsic(IRBuilderBase &Builder,
473                                           AtomicCmpXchgInst *CI,
474                                           Value *AlignedAddr, Value *CmpVal,
475                                           Value *NewVal, Value *Mask,
476                                           AtomicOrdering Ord) const override;
477 
478   /// Returns true if the target allows unaligned memory accesses of the
479   /// specified type.
480   bool allowsMisalignedMemoryAccesses(
481       EVT VT, unsigned AddrSpace = 0, Align Alignment = Align(1),
482       MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
483       bool *Fast = nullptr) const override;
484 
485   bool splitValueIntoRegisterParts(SelectionDAG &DAG, const SDLoc &DL,
486                                    SDValue Val, SDValue *Parts,
487                                    unsigned NumParts, MVT PartVT,
488                                    Optional<CallingConv::ID> CC) const override;
489 
490   SDValue
491   joinRegisterPartsIntoValue(SelectionDAG &DAG, const SDLoc &DL,
492                              const SDValue *Parts, unsigned NumParts,
493                              MVT PartVT, EVT ValueVT,
494                              Optional<CallingConv::ID> CC) const override;
495 
496   static RISCVII::VLMUL getLMUL(MVT VT);
497   static unsigned getRegClassIDForLMUL(RISCVII::VLMUL LMul);
498   static unsigned getSubregIndexByMVT(MVT VT, unsigned Index);
499   static unsigned getRegClassIDForVecVT(MVT VT);
500   static std::pair<unsigned, unsigned>
501   decomposeSubvectorInsertExtractToSubRegs(MVT VecVT, MVT SubVecVT,
502                                            unsigned InsertExtractIdx,
503                                            const RISCVRegisterInfo *TRI);
504   MVT getContainerForFixedLengthVector(MVT VT) const;
505 
506   bool shouldRemoveExtendFromGSIndex(EVT VT) const override;
507 
508 private:
509   /// RISCVCCAssignFn - This target-specific function extends the default
510   /// CCValAssign with additional information used to lower RISC-V calling
511   /// conventions.
512   typedef bool RISCVCCAssignFn(const DataLayout &DL, RISCVABI::ABI,
513                                unsigned ValNo, MVT ValVT, MVT LocVT,
514                                CCValAssign::LocInfo LocInfo,
515                                ISD::ArgFlagsTy ArgFlags, CCState &State,
516                                bool IsFixed, bool IsRet, Type *OrigTy,
517                                const RISCVTargetLowering &TLI,
518                                Optional<unsigned> FirstMaskArgument);
519 
520   void analyzeInputArgs(MachineFunction &MF, CCState &CCInfo,
521                         const SmallVectorImpl<ISD::InputArg> &Ins, bool IsRet,
522                         RISCVCCAssignFn Fn) const;
523   void analyzeOutputArgs(MachineFunction &MF, CCState &CCInfo,
524                          const SmallVectorImpl<ISD::OutputArg> &Outs,
525                          bool IsRet, CallLoweringInfo *CLI,
526                          RISCVCCAssignFn Fn) const;
527 
528   template <class NodeTy>
529   SDValue getAddr(NodeTy *N, SelectionDAG &DAG, bool IsLocal = true) const;
530 
531   SDValue getStaticTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG,
532                            bool UseGOT) const;
533   SDValue getDynamicTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG) const;
534 
535   SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
536   SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
537   SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
538   SDValue lowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
539   SDValue lowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
540   SDValue lowerSELECT(SDValue Op, SelectionDAG &DAG) const;
541   SDValue lowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
542   SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
543   SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
544   SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
545   SDValue lowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
546   SDValue lowerShiftRightParts(SDValue Op, SelectionDAG &DAG, bool IsSRA) const;
547   SDValue lowerSPLAT_VECTOR_PARTS(SDValue Op, SelectionDAG &DAG) const;
548   SDValue lowerVectorMaskSplat(SDValue Op, SelectionDAG &DAG) const;
549   SDValue lowerVectorMaskExt(SDValue Op, SelectionDAG &DAG,
550                              int64_t ExtTrueVal) const;
551   SDValue lowerVectorMaskTrunc(SDValue Op, SelectionDAG &DAG) const;
552   SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
553   SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
554   SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
555   SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
556   SDValue lowerVECREDUCE(SDValue Op, SelectionDAG &DAG) const;
557   SDValue lowerVectorMaskVECREDUCE(SDValue Op, SelectionDAG &DAG) const;
558   SDValue lowerFPVECREDUCE(SDValue Op, SelectionDAG &DAG) const;
559   SDValue lowerINSERT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
560   SDValue lowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
561   SDValue lowerSTEP_VECTOR(SDValue Op, SelectionDAG &DAG) const;
562   SDValue lowerVECTOR_REVERSE(SDValue Op, SelectionDAG &DAG) const;
563   SDValue lowerABS(SDValue Op, SelectionDAG &DAG) const;
564   SDValue lowerMLOAD(SDValue Op, SelectionDAG &DAG) const;
565   SDValue lowerMSTORE(SDValue Op, SelectionDAG &DAG) const;
566   SDValue lowerFixedLengthVectorFCOPYSIGNToRVV(SDValue Op,
567                                                SelectionDAG &DAG) const;
568   SDValue lowerMGATHER(SDValue Op, SelectionDAG &DAG) const;
569   SDValue lowerMSCATTER(SDValue Op, SelectionDAG &DAG) const;
570   SDValue lowerFixedLengthVectorLoadToRVV(SDValue Op, SelectionDAG &DAG) const;
571   SDValue lowerFixedLengthVectorStoreToRVV(SDValue Op, SelectionDAG &DAG) const;
572   SDValue lowerFixedLengthVectorSetccToRVV(SDValue Op, SelectionDAG &DAG) const;
573   SDValue lowerFixedLengthVectorLogicOpToRVV(SDValue Op, SelectionDAG &DAG,
574                                              unsigned MaskOpc,
575                                              unsigned VecOpc) const;
576   SDValue lowerFixedLengthVectorShiftToRVV(SDValue Op, SelectionDAG &DAG) const;
577   SDValue lowerFixedLengthVectorSelectToRVV(SDValue Op,
578                                             SelectionDAG &DAG) const;
579   SDValue lowerToScalableOp(SDValue Op, SelectionDAG &DAG, unsigned NewOpc,
580                             bool HasMask = true) const;
581   SDValue lowerVPOp(SDValue Op, SelectionDAG &DAG, unsigned RISCVISDOpc) const;
582   SDValue lowerFixedLengthVectorExtendToRVV(SDValue Op, SelectionDAG &DAG,
583                                             unsigned ExtendOpc) const;
584   SDValue lowerGET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
585   SDValue lowerSET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
586 
587   SDValue expandUnalignedRVVLoad(SDValue Op, SelectionDAG &DAG) const;
588   SDValue expandUnalignedRVVStore(SDValue Op, SelectionDAG &DAG) const;
589 
590   bool isEligibleForTailCallOptimization(
591       CCState &CCInfo, CallLoweringInfo &CLI, MachineFunction &MF,
592       const SmallVector<CCValAssign, 16> &ArgLocs) const;
593 
594   /// Generate error diagnostics if any register used by CC has been marked
595   /// reserved.
596   void validateCCReservedRegs(
597       const SmallVectorImpl<std::pair<llvm::Register, llvm::SDValue>> &Regs,
598       MachineFunction &MF) const;
599 
600   bool useRVVForFixedLengthVectorVT(MVT VT) const;
601 
602   MVT getVPExplicitVectorLengthTy() const override;
603 
604   /// RVV code generation for fixed length vectors does not lower all
605   /// BUILD_VECTORs. This makes BUILD_VECTOR legalisation a source of stores to
606   /// merge. However, merging them creates a BUILD_VECTOR that is just as
607   /// illegal as the original, thus leading to an infinite legalisation loop.
608   /// NOTE: Once BUILD_VECTOR can be custom lowered for all legal vector types,
609   /// this override can be removed.
610   bool mergeStoresAfterLegalization(EVT VT) const override;
611 };
612 
613 namespace RISCV {
614 // We use 64 bits as the known part in the scalable vector types.
615 static constexpr unsigned RVVBitsPerBlock = 64;
616 } // namespace RISCV
617 
618 namespace RISCVVIntrinsicsTable {
619 
620 struct RISCVVIntrinsicInfo {
621   unsigned IntrinsicID;
622   uint8_t SplatOperand;
623 };
624 
625 using namespace RISCV;
626 
627 #define GET_RISCVVIntrinsicsTable_DECL
628 #include "RISCVGenSearchableTables.inc"
629 
630 } // end namespace RISCVVIntrinsicsTable
631 
632 } // end namespace llvm
633 
634 #endif
635