@@ -526,15 +526,8 @@ struct RISCVOperand final : public MCParsedAsmOperand {
526
526
bool isGPRAsFPR32 () const { return isGPRF32 () && Reg.IsGPRAsFPR ; }
527
527
bool isGPRPairAsFPR64 () const { return isGPRPair () && Reg.IsGPRAsFPR ; }
528
528
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) {
536
530
if (auto CE = dyn_cast<MCConstantExpr>(Expr)) {
537
- VK = RISCVMCExpr::VK_None;
538
531
Imm = CE->getValue ();
539
532
return true ;
540
533
}
@@ -549,7 +542,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
549
542
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
550
543
if (!isImm ())
551
544
return false ;
552
- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK );
545
+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
553
546
bool IsValid;
554
547
if (!IsConstantImm)
555
548
IsValid = RISCVAsmParser::classifySymbolRef (getImm (), VK);
@@ -564,7 +557,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
564
557
int64_t Imm;
565
558
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
566
559
// Must be of 'immediate' type but not a constant.
567
- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
560
+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
568
561
return false ;
569
562
return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
570
563
VK == RISCVMCExpr::VK_None;
@@ -574,7 +567,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
574
567
int64_t Imm;
575
568
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
576
569
// Must be of 'immediate' type but not a constant.
577
- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
570
+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
578
571
return false ;
579
572
return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
580
573
(VK == RISCVMCExpr::VK_CALL || VK == RISCVMCExpr::VK_CALL_PLT);
@@ -584,7 +577,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
584
577
int64_t Imm;
585
578
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
586
579
// Must be of 'immediate' type but not a constant.
587
- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
580
+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
588
581
return false ;
589
582
return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
590
583
VK == RISCVMCExpr::VK_CALL;
@@ -594,7 +587,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
594
587
int64_t Imm;
595
588
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
596
589
// Must be of 'immediate' type but not a constant.
597
- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
590
+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
598
591
return false ;
599
592
return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
600
593
VK == RISCVMCExpr::VK_TPREL_ADD;
@@ -604,7 +597,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
604
597
int64_t Imm;
605
598
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
606
599
// Must be of 'immediate' type but not a constant.
607
- if (!isImm () || evaluateConstantImm (getImm (), Imm, VK ))
600
+ if (!isImm () || evaluateConstantImm (getImm (), Imm))
608
601
return false ;
609
602
return RISCVAsmParser::classifySymbolRef (getImm (), VK) &&
610
603
VK == RISCVMCExpr::VK_TLSDESC_CALL;
@@ -649,61 +642,48 @@ struct RISCVOperand final : public MCParsedAsmOperand {
649
642
650
643
bool isImmXLenLI () const {
651
644
int64_t Imm;
652
- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
653
645
if (!isImm ())
654
646
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 ;
660
647
// Given only Imm, ensuring that the actually specified constant is either
661
648
// 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));
666
651
667
652
return RISCVAsmParser::isSymbolDiff (getImm ());
668
653
}
669
654
670
655
bool isImmXLenLI_Restricted () const {
671
656
int64_t Imm;
672
- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
673
657
if (!isImm ())
674
658
return false ;
675
- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK );
659
+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
676
660
// 'la imm' supports constant immediates only.
677
- return IsConstantImm && (VK == RISCVMCExpr::VK_None) &&
661
+ return IsConstantImm &&
678
662
(isRV64Imm () || (isInt<32 >(Imm) || isUInt<32 >(Imm)));
679
663
}
680
664
681
665
template <unsigned N> bool isUImm () const {
682
666
int64_t Imm;
683
- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
684
667
if (!isImm ())
685
668
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);
688
671
}
689
672
690
673
template <unsigned N, unsigned S> bool isUImmShifted () const {
691
674
int64_t Imm;
692
- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
693
675
if (!isImm ())
694
676
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);
698
679
}
699
680
700
681
template <class Pred > bool isUImmPred (Pred p) const {
701
682
int64_t Imm;
702
- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
703
683
if (!isImm ())
704
684
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);
707
687
}
708
688
709
689
bool isUImmLog2XLen () const {
@@ -791,22 +771,18 @@ struct RISCVOperand final : public MCParsedAsmOperand {
791
771
792
772
template <unsigned N> bool isSImm () const {
793
773
int64_t Imm;
794
- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
795
774
if (!isImm ())
796
775
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 ()));
800
778
}
801
779
802
780
template <class Pred > bool isSImmPred (Pred p) const {
803
781
int64_t Imm;
804
- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
805
782
if (!isImm ())
806
783
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 ()));
810
786
}
811
787
812
788
bool isSImm5 () const { return isSImm<5 >(); }
@@ -867,15 +843,14 @@ struct RISCVOperand final : public MCParsedAsmOperand {
867
843
bool IsValid;
868
844
if (!isImm ())
869
845
return false ;
870
- bool IsConstantImm = evaluateConstantImm (getImm (), Imm, VK );
846
+ bool IsConstantImm = evaluateConstantImm (getImm (), Imm);
871
847
if (!IsConstantImm)
872
848
IsValid = RISCVAsmParser::classifySymbolRef (getImm (), VK);
873
849
else
874
850
IsValid = isInt<12 >(fixImmediateForRV32 (Imm, isRV64Imm ()));
875
851
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 ||
879
854
VK == RISCVMCExpr::VK_TLSDESC_LOAD_LO ||
880
855
VK == RISCVMCExpr::VK_TLSDESC_ADD_LO);
881
856
}
@@ -900,40 +875,27 @@ struct RISCVOperand final : public MCParsedAsmOperand {
900
875
bool isUImm20LUI () const {
901
876
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
902
877
int64_t Imm;
903
- bool IsValid;
904
878
if (!isImm ())
905
879
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);
916
885
}
917
886
918
887
bool isUImm20AUIPC () const {
919
888
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
920
889
int64_t Imm;
921
- bool IsValid;
922
890
if (!isImm ())
923
891
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);
933
895
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 ||
937
899
VK == RISCVMCExpr::VK_TLS_GD_HI ||
938
900
VK == RISCVMCExpr::VK_TLSDESC_HI);
939
901
}
@@ -1159,8 +1121,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
1159
1121
static void addExpr (MCInst &Inst, const MCExpr *Expr, bool IsRV64Imm) {
1160
1122
assert (Expr && " Expr shouldn't be null!" );
1161
1123
int64_t Imm = 0 ;
1162
- RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
1163
- bool IsConstant = evaluateConstantImm (Expr, Imm, VK);
1124
+ bool IsConstant = evaluateConstantImm (Expr, Imm);
1164
1125
1165
1126
if (IsConstant)
1166
1127
Inst.addOperand (
@@ -1209,9 +1170,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
1209
1170
assert (N == 1 && " Invalid number of operands!" );
1210
1171
int64_t Imm = 0 ;
1211
1172
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);
1215
1174
assert (IsConstantImm && " Invalid VTypeI Operand!" );
1216
1175
} else {
1217
1176
Imm = getVType ();
0 commit comments