@@ -545,8 +545,10 @@ bool SemaRISCV::CheckLMUL(CallExpr *TheCall, unsigned ArgNum) {
545545 << Arg->getSourceRange ();
546546}
547547
548- static bool CheckInvalidVLENandLMUL (const TargetInfo &TI, CallExpr *TheCall,
549- Sema &S, QualType Type, int EGW) {
548+ static bool CheckInvalidVLENandLMUL (const TargetInfo &TI,
549+ llvm::StringMap<bool > &FunctionFeatureMap,
550+ CallExpr *TheCall, Sema &S, QualType Type,
551+ int EGW) {
550552 assert ((EGW == 128 || EGW == 256 ) && " EGW can only be 128 or 256 bits" );
551553
552554 // LMUL * VLEN >= EGW
@@ -567,7 +569,7 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, CallExpr *TheCall,
567569 // Vscale is VLEN/RVVBitsPerBlock.
568570 unsigned MinRequiredVLEN = VScaleFactor * llvm::RISCV::RVVBitsPerBlock;
569571 std::string RequiredExt = " zvl" + std::to_string (MinRequiredVLEN) + " b" ;
570- if (!TI.hasFeature (RequiredExt))
572+ if (!TI.hasFeature (RequiredExt) && !FunctionFeatureMap. lookup (RequiredExt) )
571573 return S.Diag (TheCall->getBeginLoc (),
572574 diag::err_riscv_type_requires_extension)
573575 << Type << RequiredExt;
@@ -579,6 +581,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo &TI,
579581 unsigned BuiltinID,
580582 CallExpr *TheCall) {
581583 ASTContext &Context = getASTContext ();
584+ const FunctionDecl *FD = SemaRef.getCurFunctionDecl ();
585+ llvm::StringMap<bool > FunctionFeatureMap;
586+ Context.getFunctionFeatureMap (FunctionFeatureMap, FD);
587+
582588 // vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx,
583589 // vsmul.vv, vsmul.vx are not included for EEW=64 in Zve64*.
584590 switch (BuiltinID) {
@@ -635,10 +641,6 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo &TI,
635641 ASTContext::BuiltinVectorTypeInfo Info = Context.getBuiltinVectorTypeInfo (
636642 TheCall->getType ()->castAs <BuiltinType>());
637643
638- const FunctionDecl *FD = SemaRef.getCurFunctionDecl ();
639- llvm::StringMap<bool > FunctionFeatureMap;
640- Context.getFunctionFeatureMap (FunctionFeatureMap, FD);
641-
642644 if (Context.getTypeSize (Info.ElementType ) == 64 && !TI.hasFeature (" v" ) &&
643645 !FunctionFeatureMap.lookup (" v" ))
644646 return Diag (TheCall->getBeginLoc (),
@@ -714,20 +716,24 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo &TI,
714716 case RISCVVector::BI__builtin_rvv_vsm4k_vi_tu: {
715717 QualType Arg0Type = TheCall->getArg (0 )->getType ();
716718 QualType Arg1Type = TheCall->getArg (1 )->getType ();
717- return CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg0Type, 128 ) ||
718- CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg1Type, 128 ) ||
719+ return CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef,
720+ Arg0Type, 128 ) ||
721+ CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef,
722+ Arg1Type, 128 ) ||
719723 SemaRef.BuiltinConstantArgRange (TheCall, 2 , 0 , 31 );
720724 }
721725 case RISCVVector::BI__builtin_rvv_vsm3c_vi_tu:
722726 case RISCVVector::BI__builtin_rvv_vsm3c_vi: {
723727 QualType Arg0Type = TheCall->getArg (0 )->getType ();
724- return CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg0Type, 256 ) ||
728+ return CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef,
729+ Arg0Type, 256 ) ||
725730 SemaRef.BuiltinConstantArgRange (TheCall, 2 , 0 , 31 );
726731 }
727732 case RISCVVector::BI__builtin_rvv_vaeskf1_vi:
728733 case RISCVVector::BI__builtin_rvv_vsm4k_vi: {
729734 QualType Arg0Type = TheCall->getArg (0 )->getType ();
730- return CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg0Type, 128 ) ||
735+ return CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef,
736+ Arg0Type, 128 ) ||
731737 SemaRef.BuiltinConstantArgRange (TheCall, 1 , 0 , 31 );
732738 }
733739 case RISCVVector::BI__builtin_rvv_vaesdf_vv:
@@ -754,8 +760,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo &TI,
754760 case RISCVVector::BI__builtin_rvv_vsm4r_vs_tu: {
755761 QualType Arg0Type = TheCall->getArg (0 )->getType ();
756762 QualType Arg1Type = TheCall->getArg (1 )->getType ();
757- return CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg0Type, 128 ) ||
758- CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg1Type, 128 );
763+ return CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef,
764+ Arg0Type, 128 ) ||
765+ CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef,
766+ Arg1Type, 128 );
759767 }
760768 case RISCVVector::BI__builtin_rvv_vsha2ch_vv:
761769 case RISCVVector::BI__builtin_rvv_vsha2cl_vv:
@@ -769,17 +777,18 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo &TI,
769777 ASTContext::BuiltinVectorTypeInfo Info =
770778 Context.getBuiltinVectorTypeInfo (Arg0Type->castAs <BuiltinType>());
771779 uint64_t ElemSize = Context.getTypeSize (Info.ElementType );
772- if (ElemSize == 64 && !TI.hasFeature (" zvknhb" ))
780+ if (ElemSize == 64 && !TI.hasFeature (" zvknhb" ) &&
781+ !FunctionFeatureMap.lookup (" zvknhb" ))
773782 return Diag (TheCall->getBeginLoc (),
774783 diag::err_riscv_builtin_requires_extension)
775784 << /* IsExtension */ true << TheCall->getSourceRange () << " zvknhb" ;
776785
777- return CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg0Type ,
778- ElemSize * 4 ) ||
779- CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg1Type ,
780- ElemSize * 4 ) ||
781- CheckInvalidVLENandLMUL (TI, TheCall, SemaRef, Arg2Type ,
782- ElemSize * 4 );
786+ return CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef ,
787+ Arg0Type, ElemSize * 4 ) ||
788+ CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef ,
789+ Arg1Type, ElemSize * 4 ) ||
790+ CheckInvalidVLENandLMUL (TI, FunctionFeatureMap, TheCall, SemaRef ,
791+ Arg2Type, ElemSize * 4 );
783792 }
784793
785794 case RISCVVector::BI__builtin_rvv_sf_vc_i_se:
0 commit comments