@@ -526,15 +526,8 @@ struct RISCVOperand final : public MCParsedAsmOperand {
526526 bool isGPRAsFPR32 () const { return isGPRF32 () && Reg.IsGPRAsFPR ; }
527527 bool isGPRPairAsFPR64 () const { return isGPRPair () && Reg.IsGPRAsFPR ; }
528528
529- static bool evaluateConstantImm (const MCExpr *Expr, int64_t &Imm,
530- RISCVMCExpr::Specifier &VK) {
531- if (auto *RE = dyn_cast<RISCVMCExpr>(Expr)) {
532- VK = RE->getSpecifier ();
533- return RE->evaluateAsConstant (Imm);
534- }
535-
529+ static bool evaluateConstantImm (const MCExpr *Expr, int64_t &Imm) {
536530 if (auto CE = dyn_cast<MCConstantExpr>(Expr)) {
537- VK = RISCVMCExpr::VK_None;
538531 Imm = CE->getValue ();
539532 return true ;
540533 }
@@ -549,7 +542,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
549542 RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
550543 if (!isImm ())
551544 return false ;
552- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK );
545+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
553546 bool IsValid;
554547 if (!IsConstantImm)
555548 IsValid = RISCVAsmParser::classifySymbolRef (getImm (), VK);
@@ -564,7 +557,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
564557 int64_t Imm;
565558 RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
566559 // Must be of 'immediate' type but not a constant.
567- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
560+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
568561 return false ;
569562 return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
570563 VK == RISCVMCExpr::VK_None;
@@ -574,7 +567,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
574567 int64_t Imm;
575568 RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
576569 // Must be of 'immediate' type but not a constant.
577- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
570+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
578571 return false ;
579572 return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
580573 (VK == RISCVMCExpr::VK_CALL || VK == RISCVMCExpr::VK_CALL_PLT);
@@ -584,7 +577,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
584577 int64_t Imm;
585578 RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
586579 // Must be of 'immediate' type but not a constant.
587- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
580+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
588581 return false ;
589582 return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
590583 VK == RISCVMCExpr::VK_CALL;
@@ -594,7 +587,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
594587 int64_t Imm;
595588 RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
596589 // Must be of 'immediate' type but not a constant.
597- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
590+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
598591 return false ;
599592 return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
600593 VK == RISCVMCExpr::VK_TPREL_ADD;
@@ -604,7 +597,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
604597 int64_t Imm;
605598 RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
606599 // Must be of 'immediate' type but not a constant.
607- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
600+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
608601 return false ;
609602 return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
610603 VK == RISCVMCExpr::VK_TLSDESC_CALL;
@@ -649,61 +642,48 @@ struct RISCVOperand final : public MCParsedAsmOperand {
649642
650643 bool isImmXLenLI () const {
651644 int64_t Imm;
652- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
653645 if (!isImm ())
654646 return false ;
655- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK);
656- if (VK == RISCVMCExpr::VK_LO || VK == RISCVMCExpr::VK_PCREL_LO ||
657- VK == RISCVMCExpr::VK_TLSDESC_LOAD_LO ||
658- VK == RISCVMCExpr::VK_TLSDESC_ADD_LO)
659- return true ;
660647 // Given only Imm, ensuring that the actually specified constant is either
661648 // a signed or unsigned 64-bit number is unfortunately impossible.
662- if (IsConstantImm) {
663- return VK == RISCVMCExpr::VK_None &&
664- (isRV64Imm () || (isInt<32 >(Imm) || isUInt<32 >(Imm)));
665- }
649+ if (evaluateConstantImm (getImm (), Imm))
650+ return isRV64Imm () || (isInt<32 >(Imm) || isUInt<32 >(Imm));
666651
667652 return RISCVAsmParser::isSymbolDiff (getImm ());
668653 }
669654
670655 bool isImmXLenLI_Restricted () const {
671656 int64_t Imm;
672- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
673657 if (!isImm ())
674658 return false ;
675- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK );
659+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
676660 // 'la imm' supports constant immediates only.
677- return IsConstantImm && (VK == RISCVMCExpr::VK_None) &&
661+ return IsConstantImm &&
678662 (isRV64Imm () || (isInt<32 >(Imm) || isUInt<32 >(Imm)));
679663 }
680664
681665 template <unsigned N> bool isUImm () const {
682666 int64_t Imm;
683- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
684667 if (!isImm ())
685668 return false ;
686- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK );
687- return IsConstantImm && isUInt<N>(Imm) && VK == RISCVMCExpr::VK_None ;
669+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
670+ return IsConstantImm && isUInt<N>(Imm);
688671 }
689672
690673 template <unsigned N, unsigned S> bool isUImmShifted () const {
691674 int64_t Imm;
692- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
693675 if (!isImm ())
694676 return false ;
695- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK);
696- return IsConstantImm && isShiftedUInt<N, S>(Imm) &&
697- VK == RISCVMCExpr::VK_None;
677+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
678+ return IsConstantImm && isShiftedUInt<N, S>(Imm);
698679 }
699680
700681 template <class Pred > bool isUImmPred (Pred p) const {
701682 int64_t Imm;
702- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
703683 if (!isImm ())
704684 return false ;
705- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK );
706- return IsConstantImm && p (Imm) && VK == RISCVMCExpr::VK_None ;
685+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
686+ return IsConstantImm && p (Imm);
707687 }
708688
709689 bool isUImmLog2XLen () const {
@@ -791,22 +771,18 @@ struct RISCVOperand final : public MCParsedAsmOperand {
791771
792772 template <unsigned N> bool isSImm () const {
793773 int64_t Imm;
794- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
795774 if (!isImm ())
796775 return false ;
797- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK);
798- return IsConstantImm && isInt<N>(fixImmediateForRV32 (Imm, isRV64Imm ())) &&
799- VK == RISCVMCExpr::VK_None;
776+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
777+ return IsConstantImm && isInt<N>(fixImmediateForRV32 (Imm, isRV64Imm ()));
800778 }
801779
802780 template <class Pred > bool isSImmPred (Pred p) const {
803781 int64_t Imm;
804- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
805782 if (!isImm ())
806783 return false ;
807- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK);
808- return IsConstantImm && p (fixImmediateForRV32 (Imm, isRV64Imm ())) &&
809- VK == RISCVMCExpr::VK_None;
784+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
785+ return IsConstantImm && p (fixImmediateForRV32 (Imm, isRV64Imm ()));
810786 }
811787
812788 bool isSImm5 () const { return isSImm<5 >(); }
@@ -867,15 +843,14 @@ struct RISCVOperand final : public MCParsedAsmOperand {
867843 bool IsValid;
868844 if (!isImm ())
869845 return false ;
870- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK );
846+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
871847 if (!IsConstantImm)
872848 IsValid = RISCVAsmParser::classifySymbolRef (getImm (), VK);
873849 else
874850 IsValid = isInt<12 >(fixImmediateForRV32 (Imm, isRV64Imm ()));
875851 return IsValid &&
876- ((IsConstantImm && VK == RISCVMCExpr::VK_None) ||
877- VK == RISCVMCExpr::VK_LO || VK == RISCVMCExpr::VK_PCREL_LO ||
878- VK == RISCVMCExpr::VK_TPREL_LO ||
852+ (IsConstantImm || VK == RISCVMCExpr::VK_LO ||
853+ VK == RISCVMCExpr::VK_PCREL_LO || VK == RISCVMCExpr::VK_TPREL_LO ||
879854 VK == RISCVMCExpr::VK_TLSDESC_LOAD_LO ||
880855 VK == RISCVMCExpr::VK_TLSDESC_ADD_LO);
881856 }
@@ -900,40 +875,27 @@ struct RISCVOperand final : public MCParsedAsmOperand {
900875 bool isUImm20LUI () const {
901876 RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
902877 int64_t Imm;
903- bool IsValid;
904878 if (!isImm ())
905879 return false ;
906- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK);
907- if (!IsConstantImm) {
908- IsValid = RISCVAsmParser::classifySymbolRef (getImm (), VK);
909- return IsValid &&
910- (VK == RISCVMCExpr::VK_HI || VK == RISCVMCExpr::VK_TPREL_HI);
911- } else {
912- return isUInt<20 >(Imm) &&
913- (VK == RISCVMCExpr::VK_None || VK == RISCVMCExpr::VK_HI ||
914- VK == RISCVMCExpr::VK_TPREL_HI);
915- }
880+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
881+ if (IsConstantImm)
882+ return isUInt<20 >(Imm);
883+ return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
884+ (VK == RISCVMCExpr::VK_HI || VK == RISCVMCExpr::VK_TPREL_HI);
916885 }
917886
918887 bool isUImm20AUIPC () const {
919888 RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
920889 int64_t Imm;
921- bool IsValid;
922890 if (!isImm ())
923891 return false ;
924- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK);
925- if (!IsConstantImm) {
926- IsValid = RISCVAsmParser::classifySymbolRef (getImm (), VK);
927- return IsValid &&
928- (VK == RISCVMCExpr::VK_PCREL_HI || VK == RISCVMCExpr::VK_GOT_HI ||
929- VK == RISCVMCExpr::VK_TLS_GOT_HI ||
930- VK == RISCVMCExpr::VK_TLS_GD_HI ||
931- VK == RISCVMCExpr::VK_TLSDESC_HI);
932- }
892+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
893+ if (IsConstantImm)
894+ return isUInt<20 >(Imm);
933895
934- return isUInt< 20 >(Imm ) &&
935- (VK == RISCVMCExpr::VK_None || VK == RISCVMCExpr::VK_PCREL_HI ||
936- VK == RISCVMCExpr::VK_GOT_HI || VK == RISCVMCExpr:: VK_TLS_GOT_HI ||
896+ return RISCVAsmParser::classifySymbolRef ( getImm (), VK ) &&
897+ (VK == RISCVMCExpr::VK_PCREL_HI || VK == RISCVMCExpr::VK_GOT_HI ||
898+ VK == RISCVMCExpr::VK_TLS_GOT_HI ||
937899 VK == RISCVMCExpr::VK_TLS_GD_HI ||
938900 VK == RISCVMCExpr::VK_TLSDESC_HI);
939901 }
@@ -1159,8 +1121,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
11591121 static void addExpr (MCInst &Inst, const MCExpr *Expr, bool IsRV64Imm) {
11601122 assert (Expr && " Expr shouldn't be null!" );
11611123 int64_t Imm = 0 ;
1162- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
1163- bool IsConstant = evaluateConstantImm (Expr, Imm, VK);
1124+ bool IsConstant = evaluateConstantImm (Expr, Imm);
11641125
11651126 if (IsConstant)
11661127 Inst.addOperand (
@@ -1209,9 +1170,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
12091170 assert (N == 1 && " Invalid number of operands!" );
12101171 int64_t Imm = 0 ;
12111172 if (Kind == KindTy::Immediate) {
1212- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
1213- [[maybe_unused]] bool IsConstantImm =
1214- evaluateConstantImm (getImm (), Imm, VK);
1173+ [[maybe_unused]] bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
12151174 assert (IsConstantImm && " Invalid VTypeI Operand!" );
12161175 } else {
12171176 Imm = getVType ();
0 commit comments