@@ -842,43 +842,35 @@ LLVM_DUMP_METHOD void MatchableInfo::dump() const {
842
842
843
843
static std::pair<StringRef, StringRef>
844
844
parseTwoOperandConstraint (StringRef S, ArrayRef<SMLoc> Loc) {
845
+ // Trim whitespace and the leading '$' on the operand names.
846
+ auto TrimWSDollar = [Loc](StringRef OpName) {
847
+ OpName = OpName.trim (" \t " );
848
+ if (!OpName.consume_front (" $" ))
849
+ PrintFatalError (Loc, " expected '$' prefix on asm operand name" );
850
+ return OpName;
851
+ };
852
+
845
853
// Split via the '='.
846
- std::pair<StringRef, StringRef> Ops = S.split (' =' );
847
- if (Ops. second == " " )
854
+ auto [Src, Dst] = S.split (' =' );
855
+ if (Dst == " " )
848
856
PrintFatalError (Loc, " missing '=' in two-operand alias constraint" );
849
- // Trim whitespace and the leading '$' on the operand names.
850
- size_t start = Ops.first .find_first_of (' $' );
851
- if (start == std::string::npos)
852
- PrintFatalError (Loc, " expected '$' prefix on asm operand name" );
853
- Ops.first = Ops.first .substr (start + 1 );
854
- size_t end = Ops.first .find_last_of (" \t " );
855
- Ops.first = Ops.first .slice (0 , end);
856
- // Now the second operand.
857
- start = Ops.second .find_first_of (' $' );
858
- if (start == std::string::npos)
859
- PrintFatalError (Loc, " expected '$' prefix on asm operand name" );
860
- Ops.second = Ops.second .substr (start + 1 );
861
- end = Ops.second .find_last_of (" \t " );
862
- Ops.first = Ops.first .slice (0 , end);
863
- return Ops;
857
+ return {TrimWSDollar (Src), TrimWSDollar (Dst)};
864
858
}
865
859
866
860
void MatchableInfo::formTwoOperandAlias (StringRef Constraint) {
867
861
// Figure out which operands are aliased and mark them as tied.
868
- std::pair<StringRef, StringRef> Ops =
869
- parseTwoOperandConstraint (Constraint, TheDef->getLoc ());
862
+ auto [Src, Dst] = parseTwoOperandConstraint (Constraint, TheDef->getLoc ());
870
863
871
864
// Find the AsmOperands that refer to the operands we're aliasing.
872
- int SrcAsmOperand = findAsmOperandNamed (Ops. first );
873
- int DstAsmOperand = findAsmOperandNamed (Ops. second );
865
+ int SrcAsmOperand = findAsmOperandNamed (Src );
866
+ int DstAsmOperand = findAsmOperandNamed (Dst );
874
867
if (SrcAsmOperand == -1 )
875
868
PrintFatalError (TheDef->getLoc (),
876
- " unknown source two-operand alias operand '" + Ops.first +
877
- " '." );
869
+ " unknown source two-operand alias operand '" + Src + " '." );
878
870
if (DstAsmOperand == -1 )
879
871
PrintFatalError (TheDef->getLoc (),
880
- " unknown destination two-operand alias operand '" +
881
- Ops. second + " '." );
872
+ " unknown destination two-operand alias operand '" + Dst +
873
+ " '." );
882
874
883
875
// Find the ResOperand that refers to the operand we're aliasing away
884
876
// and update it to refer to the combined operand instead.
@@ -894,15 +886,9 @@ void MatchableInfo::formTwoOperandAlias(StringRef Constraint) {
894
886
// Adjust the ResOperand references to any AsmOperands that followed
895
887
// the one we just deleted.
896
888
for (ResOperand &Op : ResOperands) {
897
- switch (Op.Kind ) {
898
- default :
899
- // Nothing to do for operands that don't reference AsmOperands.
900
- break ;
901
- case ResOperand::RenderAsmOperand:
902
- if (Op.AsmOperandNum > (unsigned )SrcAsmOperand)
903
- --Op.AsmOperandNum ;
904
- break ;
905
- }
889
+ if (Op.Kind == ResOperand::RenderAsmOperand &&
890
+ Op.AsmOperandNum > (unsigned )SrcAsmOperand)
891
+ --Op.AsmOperandNum ;
906
892
}
907
893
}
908
894
@@ -925,11 +911,10 @@ static void extractSingletonRegisterForAsmOperand(MatchableInfo::AsmOperand &Op,
925
911
return ;
926
912
}
927
913
928
- if (!Tok.starts_with (RegisterPrefix))
914
+ if (!Tok.consume_front (RegisterPrefix))
929
915
return ;
930
916
931
- StringRef RegName = Tok.substr (RegisterPrefix.size ());
932
- if (const CodeGenRegister *Reg = Info.Target .getRegisterByName (RegName))
917
+ if (const CodeGenRegister *Reg = Info.Target .getRegisterByName (Tok))
933
918
Op.SingletonReg = Reg->TheDef ;
934
919
935
920
// If there is no register prefix (i.e. "%" in "%eax"), then this may
@@ -1542,10 +1527,9 @@ void AsmMatcherInfo::buildInfo() {
1542
1527
Variant.AsmVariantNo = AsmVariant->getValueAsInt (" Variant" );
1543
1528
1544
1529
for (const CodeGenInstruction *CGI : Target.getInstructions ()) {
1545
-
1546
1530
// If the tblgen -match-prefix option is specified (for tblgen hackers),
1547
1531
// filter the set of instructions we consider.
1548
- if (!StringRef ( CGI->getName () ).starts_with (MatchPrefix))
1532
+ if (!CGI->getName ().starts_with (MatchPrefix))
1549
1533
continue ;
1550
1534
1551
1535
// Ignore "codegen only" instructions.
@@ -1578,7 +1562,7 @@ void AsmMatcherInfo::buildInfo() {
1578
1562
// If the tblgen -match-prefix option is specified (for tblgen hackers),
1579
1563
// filter the set of instruction aliases we consider, based on the target
1580
1564
// instruction.
1581
- if (!StringRef ( Alias->ResultInst ->getName () ).starts_with (MatchPrefix))
1565
+ if (!Alias->ResultInst ->getName ().starts_with (MatchPrefix))
1582
1566
continue ;
1583
1567
1584
1568
StringRef V = Alias->TheDef ->getValueAsString (" AsmVariantName" );
@@ -2663,11 +2647,8 @@ static void emitMatchRegisterAltName(const CodeGenTarget &Target,
2663
2647
std::string Namespace =
2664
2648
Regs.front ().TheDef ->getValueAsString (" Namespace" ).str ();
2665
2649
for (const CodeGenRegister &Reg : Regs) {
2666
-
2667
- auto AltNames = Reg.TheDef ->getValueAsListOfStrings (" AltNames" );
2668
-
2669
- for (auto AltName : AltNames) {
2670
- AltName = StringRef (AltName).trim ();
2650
+ for (StringRef AltName : Reg.TheDef ->getValueAsListOfStrings (" AltNames" )) {
2651
+ AltName = AltName.trim ();
2671
2652
2672
2653
// don't handle empty alternative names
2673
2654
if (AltName.empty ())
@@ -2718,8 +2699,8 @@ static void emitGetSubtargetFeatureName(AsmMatcherInfo &Info, raw_ostream &OS) {
2718
2699
<< " static const char *getSubtargetFeatureName(uint64_t Val) {\n " ;
2719
2700
if (!Info.SubtargetFeatures .empty ()) {
2720
2701
OS << " switch(Val) {\n " ;
2721
- for (const auto &SF : Info. SubtargetFeatures ) {
2722
- const SubtargetFeatureInfo &SFI = SF. second ;
2702
+ for (const SubtargetFeatureInfo &SFI :
2703
+ make_second_range (Info. SubtargetFeatures )) {
2723
2704
// FIXME: Totally just a placeholder name to get the algorithm working.
2724
2705
OS << " case " << SFI.getEnumBitName () << " : return \" "
2725
2706
<< SFI.TheDef ->getValueAsString (" PredicateName" ) << " \" ;\n " ;
@@ -2737,17 +2718,15 @@ static std::string GetAliasRequiredFeatures(const Record *R,
2737
2718
const AsmMatcherInfo &Info) {
2738
2719
std::string Result;
2739
2720
2740
- bool First = true ;
2721
+ ListSeparator LS ( " && " ) ;
2741
2722
for (const Record *RF : R->getValueAsListOfDefs (" Predicates" )) {
2742
2723
const SubtargetFeatureInfo *F = Info.getSubtargetFeature (RF);
2743
2724
if (!F)
2744
2725
PrintFatalError (R->getLoc (),
2745
2726
" Predicate '" + RF->getName () +
2746
2727
" ' is not marked as an AssemblerPredicate!" );
2747
- if (!First)
2748
- Result += " && " ;
2728
+ Result += LS;
2749
2729
Result += " Features.test(" + F->getEnumBitName () + ' )' ;
2750
- First = false ;
2751
2730
}
2752
2731
2753
2732
return Result;
@@ -3638,9 +3617,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
3638
3617
OS << " ErrorInfo = ~0ULL;\n " ;
3639
3618
}
3640
3619
3641
- if (HasOptionalOperands) {
3620
+ if (HasOptionalOperands)
3642
3621
OS << " SmallBitVector OptionalOperandsMask(" << MaxNumOperands << " );\n " ;
3643
- }
3644
3622
3645
3623
// Emit code to search the table.
3646
3624
OS << " // Find the appropriate table for this asm variant.\n " ;
@@ -3708,9 +3686,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
3708
3686
// Emit check that the subclasses match.
3709
3687
if (!ReportMultipleNearMisses)
3710
3688
OS << " bool OperandsValid = true;\n " ;
3711
- if (HasOptionalOperands) {
3689
+ if (HasOptionalOperands)
3712
3690
OS << " OptionalOperandsMask.reset(0, " << MaxNumOperands << " );\n " ;
3713
- }
3714
3691
OS << " for (unsigned FormalIdx = " << (HasMnemonicFirst ? " 0" : " SIndex" )
3715
3692
<< " , ActualIdx = " << (HasMnemonicFirst ? " 1" : " SIndex" )
3716
3693
<< " ; FormalIdx != " << MaxNumOperands << " ; ++FormalIdx) {\n " ;
@@ -3771,9 +3748,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
3771
3748
OS << " break;\n " ;
3772
3749
OS << " }\n " ;
3773
3750
OS << " if (isSubclass(Formal, OptionalMatchClass)) {\n " ;
3774
- if (HasOptionalOperands) {
3751
+ if (HasOptionalOperands)
3775
3752
OS << " OptionalOperandsMask.set(FormalIdx);\n " ;
3776
- }
3777
3753
OS << " continue;\n " ;
3778
3754
OS << " }\n " ;
3779
3755
OS << " OperandsValid = false;\n " ;
@@ -3812,9 +3788,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
3812
3788
<< " // then try to match next formal operand\n " ;
3813
3789
OS << " if (Diag == Match_InvalidOperand "
3814
3790
<< " && isSubclass(Formal, OptionalMatchClass)) {\n " ;
3815
- if (HasOptionalOperands) {
3791
+ if (HasOptionalOperands)
3816
3792
OS << " OptionalOperandsMask.set(FormalIdx);\n " ;
3817
- }
3818
3793
OS << " DEBUG_WITH_TYPE(\" asm-matcher\" , dbgs() << \" ignoring "
3819
3794
" optional operand\\ n\" );\n " ;
3820
3795
OS << " continue;\n " ;
0 commit comments