@@ -120,42 +120,23 @@ void RISCVABIInfo::computeInfo(CGFunctionInfo &FI) const {
120120 default :
121121 ABIVLen = 0 ;
122122 break ;
123- case CallingConv::CC_RISCVVLSCall_32:
124- ABIVLen = 32 ;
125- break ;
126- case CallingConv::CC_RISCVVLSCall_64:
127- ABIVLen = 64 ;
128- break ;
129- case CallingConv::CC_RISCVVLSCall_128:
130- ABIVLen = 128 ;
131- break ;
132- case CallingConv::CC_RISCVVLSCall_256:
133- ABIVLen = 256 ;
134- break ;
135- case CallingConv::CC_RISCVVLSCall_512:
136- ABIVLen = 512 ;
137- break ;
138- case CallingConv::CC_RISCVVLSCall_1024:
139- ABIVLen = 1024 ;
140- break ;
141- case CallingConv::CC_RISCVVLSCall_2048:
142- ABIVLen = 2048 ;
143- break ;
144- case CallingConv::CC_RISCVVLSCall_4096:
145- ABIVLen = 4096 ;
146- break ;
147- case CallingConv::CC_RISCVVLSCall_8192:
148- ABIVLen = 8192 ;
149- break ;
150- case CallingConv::CC_RISCVVLSCall_16384:
151- ABIVLen = 16384 ;
152- break ;
153- case CallingConv::CC_RISCVVLSCall_32768:
154- ABIVLen = 32768 ;
155- break ;
156- case CallingConv::CC_RISCVVLSCall_65536:
157- ABIVLen = 65536 ;
123+ #define CC_VLS_CASE (ABI_VLEN ) \
124+ case CallingConv::CC_RISCVVLSCall_##ABI_VLEN: \
125+ ABIVLen = ABI_VLEN; \
158126 break ;
127+ CC_VLS_CASE (32 )
128+ CC_VLS_CASE (64 )
129+ CC_VLS_CASE (128 )
130+ CC_VLS_CASE (256 )
131+ CC_VLS_CASE (512 )
132+ CC_VLS_CASE (1024 )
133+ CC_VLS_CASE (2048 )
134+ CC_VLS_CASE (4096 )
135+ CC_VLS_CASE (8192 )
136+ CC_VLS_CASE (16384 )
137+ CC_VLS_CASE (32768 )
138+ CC_VLS_CASE (65536 )
139+ #undef CC_VLS_CASE
159140 }
160141 QualType RetTy = FI.getReturnType ();
161142 if (!getCXXABI ().classifyReturnType (FI))
@@ -466,7 +447,7 @@ bool RISCVABIInfo::detectVLSCCEligibleStruct(QualType Ty, unsigned ABIVLen,
466447 // Otherwise, pass the struct indirectly.
467448
468449 if (llvm::StructType *STy = dyn_cast<llvm::StructType>(CGT.ConvertType (Ty))) {
469- int NumElts = STy->getStructNumElements ();
450+ unsigned NumElts = STy->getStructNumElements ();
470451 if (NumElts > 8 )
471452 return false ;
472453
@@ -522,7 +503,7 @@ bool RISCVABIInfo::detectVLSCCEligibleStruct(QualType Ty, unsigned ABIVLen,
522503 // Check array of fixed-length vector and turn it into scalable vector type
523504 // if legal.
524505 if (auto *ArrTy = dyn_cast<llvm::ArrayType>(FirstEltTy)) {
525- int NumArrElt = ArrTy->getNumElements ();
506+ unsigned NumArrElt = ArrTy->getNumElements ();
526507 if (NumArrElt > 8 )
527508 return false ;
528509
@@ -595,17 +576,6 @@ ABIArgInfo RISCVABIInfo::coerceVLSVector(QualType Ty, unsigned ABIVLen) const {
595576 // * (RVVBitsPerBlock / EltSize)
596577 ResType = llvm::ScalableVectorType::get (EltType, NumElts / VScale->first );
597578 } else {
598- // If the corresponding extension is not supported, just make it an i32
599- // vector.
600- const TargetInfo &TI = getContext ().getTargetInfo ();
601- if ((EltType->isHalfTy () && !TI.hasFeature (" zvfhmin" )) ||
602- (EltType->isBFloatTy () && !TI.hasFeature (" zvfbfmin" )) ||
603- (EltType->isFloatTy () && !TI.hasFeature (" zve32f" )) ||
604- (EltType->isDoubleTy () && !TI.hasFeature (" zve64d" )) ||
605- EltType->isIntegerTy (128 ))
606- EltType =
607- llvm::Type::getIntNTy (getVMContext (), EltType->getScalarSizeInBits ());
608-
609579 // Check registers needed <= 8.
610580 if ((EltType->getScalarSizeInBits () * NumElts / ABIVLen) > 8 )
611581 return getNaturalAlignIndirect (Ty, /* ByVal=*/ false );
@@ -615,6 +585,23 @@ ABIArgInfo RISCVABIInfo::coerceVLSVector(QualType Ty, unsigned ABIVLen) const {
615585 ResType = llvm::ScalableVectorType::get (
616586 EltType,
617587 llvm::divideCeil (NumElts * llvm::RISCV::RVVBitsPerBlock, ABIVLen));
588+
589+ // If the corresponding extension is not supported, just make it an i8
590+ // vector with same LMUL.
591+ const TargetInfo &TI = getContext ().getTargetInfo ();
592+ if ((EltType->isHalfTy () && !TI.hasFeature (" zvfhmin" )) ||
593+ (EltType->isBFloatTy () && !TI.hasFeature (" zvfbfmin" )) ||
594+ (EltType->isFloatTy () && !TI.hasFeature (" zve32f" )) ||
595+ (EltType->isDoubleTy () && !TI.hasFeature (" zve64d" )) ||
596+ (EltType->isIntegerTy (64 ) && !TI.hasFeature (" zve64x" )) ||
597+ EltType->isIntegerTy (128 )) {
598+ // The number of elements needs to be at least 1.
599+ ResType = llvm::ScalableVectorType::get (
600+ llvm::Type::getInt8Ty (getVMContext ()),
601+ llvm::divideCeil (EltType->getScalarSizeInBits () * NumElts *
602+ llvm::RISCV::RVVBitsPerBlock,
603+ 8 * ABIVLen));
604+ }
618605 }
619606
620607 return ABIArgInfo::getDirect (ResType);
@@ -726,7 +713,11 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed,
726713 return ABIArgInfo::getDirect ();
727714 }
728715
729- if (const VectorType *VT = Ty->getAs <VectorType>()) {
716+ // TODO: _BitInt is not handled yet in VLS calling convention since _BitInt
717+ // ABI is also not merged yet in RISCV:
718+ // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/419
719+ if (const VectorType *VT = Ty->getAs <VectorType>();
720+ VT && !VT->getElementType ()->isBitIntType ()) {
730721 if (VT->getVectorKind () == VectorKind::RVVFixedLengthData ||
731722 VT->getVectorKind () == VectorKind::RVVFixedLengthMask ||
732723 VT->getVectorKind () == VectorKind::RVVFixedLengthMask_1 ||
0 commit comments