@@ -573,17 +573,18 @@ static void printPredicates(ArrayRef<const Record *> Predicates, StringRef Name,
573
573
raw_ostream &OS) {
574
574
for (unsigned I = 0 ; I < Predicates.size (); ++I) {
575
575
StringRef Pred = Predicates[I]->getValueAsString (Name);
576
- OS << " case " << I + 1 << " : {\n "
577
- << " // " << Predicates[I]->getName () << " \n "
578
- << " " << Pred << " \n "
579
- << " }\n " ;
576
+ Pred = Pred.trim ();
577
+ OS.indent (2 ) << " case " << I + 1 << " : {\n " ;
578
+ OS.indent (4 ) << " // " << Predicates[I]->getName () << " \n " ;
579
+ OS.indent (4 ) << Pred << " \n " ;
580
+ OS.indent (2 ) << " }\n " ;
580
581
}
581
582
}
582
583
583
584
static void mergeCondAndCode (raw_ostream &CombinedStream, StringRef CondStr,
584
585
StringRef CodeStr) {
585
586
// Remove first indentation and last '&&'.
586
- CondStr = CondStr.drop_front (6 ).drop_back (4 );
587
+ CondStr = CondStr.drop_front (8 ).drop_back (4 );
587
588
CombinedStream.indent (4 ) << " if (" << CondStr << " ) {\n " ;
588
589
CombinedStream << CodeStr;
589
590
CombinedStream.indent (4 ) << " return true;\n " ;
@@ -721,14 +722,14 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
721
722
// Emit checks for all required features.
722
723
for (auto &Op : FeaturesSet) {
723
724
StringRef Not = Op.first ? " !" : " " ;
724
- CondStream.indent (6 ) << Not << " STI.getFeatureBits()[" << TargetName
725
+ CondStream.indent (8 ) << Not << " STI.getFeatureBits()[" << TargetName
725
726
<< " ::" << Op.second << " ]"
726
727
<< " &&\n " ;
727
728
}
728
729
729
730
// Emit checks for all required feature groups.
730
731
for (auto &Set : AnyOfFeatureSets) {
731
- CondStream.indent (6 ) << " (" ;
732
+ CondStream.indent (8 ) << " (" ;
732
733
for (auto &Op : Set) {
733
734
bool IsLast = &Op == &*Set.rbegin ();
734
735
StringRef Not = Op.first ? " !" : " " ;
@@ -745,10 +746,10 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
745
746
for (const auto &SourceOperand : Source.Operands ) {
746
747
if (SourceOperandMap[OpNo].TiedOpIdx != -1 ) {
747
748
if (Source.Operands [OpNo].Rec ->isSubClassOf (" RegisterClass" ))
748
- CondStream.indent (6 )
749
+ CondStream.indent (8 )
749
750
<< " (MI.getOperand(" << OpNo << " ).isReg()) && (MI.getOperand("
750
751
<< SourceOperandMap[OpNo].TiedOpIdx << " ).isReg()) &&\n "
751
- << " (MI.getOperand(" << OpNo
752
+ << indent ( 8 ) << " (MI.getOperand(" << OpNo
752
753
<< " ).getReg() == MI.getOperand("
753
754
<< SourceOperandMap[OpNo].TiedOpIdx << " ).getReg()) &&\n " ;
754
755
else
@@ -761,16 +762,16 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
761
762
// We don't need to do anything for source instruction operand checks.
762
763
break ;
763
764
case OpData::Imm:
764
- CondStream.indent (6 )
765
+ CondStream.indent (8 )
765
766
<< " (MI.getOperand(" << OpNo << " ).isImm()) &&\n "
766
767
<< " (MI.getOperand(" << OpNo
767
768
<< " ).getImm() == " << SourceOperandMap[OpNo].Data .Imm
768
769
<< " ) &&\n " ;
769
770
break ;
770
771
case OpData::Reg: {
771
772
const Record *Reg = SourceOperandMap[OpNo].Data .Reg ;
772
- CondStream.indent (6 ) << " (MI.getOperand(" << OpNo << " ).isReg()) &&\n "
773
- << " (MI.getOperand(" << OpNo
773
+ CondStream.indent (8 ) << " (MI.getOperand(" << OpNo << " ).isReg()) &&\n "
774
+ << indent ( 8 ) << " (MI.getOperand(" << OpNo
774
775
<< " ).getReg() == " << TargetName
775
776
<< " ::" << Reg->getName () << " ) &&\n " ;
776
777
break ;
@@ -808,12 +809,12 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
808
809
// Don't check register class if this is a tied operand, it was done
809
810
// for the operand its tied to.
810
811
if (DestOperand.getTiedRegister () == -1 ) {
811
- CondStream.indent (6 ) << " MI.getOperand(" << OpIdx << " ).isReg()" ;
812
+ CondStream.indent (8 ) << " MI.getOperand(" << OpIdx << " ).isReg()" ;
812
813
if (EType == EmitterType::CheckCompress)
813
814
CondStream << " && MI.getOperand(" << OpIdx
814
815
<< " ).getReg().isPhysical()" ;
815
816
CondStream << " &&\n "
816
- << indent (6 ) << TargetName << " MCRegisterClasses["
817
+ << indent (8 ) << TargetName << " MCRegisterClasses["
817
818
<< TargetName << " ::" << ClassRec->getName ()
818
819
<< " RegClassID].contains(MI.getOperand(" << OpIdx
819
820
<< " ).getReg()) &&\n " ;
@@ -827,16 +828,16 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
827
828
if (CompressOrUncompress) {
828
829
unsigned Entry = getPredicates (MCOpPredicateMap, MCOpPredicates,
829
830
DestRec, " MCOperandPredicate" );
830
- CondStream.indent (6 ) << ValidatorName << " ("
831
+ CondStream.indent (8 ) << ValidatorName << " ("
831
832
<< " MI.getOperand(" << OpIdx << " ), STI, "
832
833
<< Entry << " ) &&\n " ;
833
834
} else {
834
835
unsigned Entry =
835
836
getPredicates (ImmLeafPredicateMap, ImmLeafPredicates, DestRec,
836
837
" ImmediateCode" );
837
- CondStream.indent (6 )
838
+ CondStream.indent (8 )
838
839
<< " MI.getOperand(" << OpIdx << " ).isImm() &&\n " ;
839
- CondStream.indent (6 ) << TargetName << " ValidateMachineOperand("
840
+ CondStream.indent (8 ) << TargetName << " ValidateMachineOperand("
840
841
<< " MI.getOperand(" << OpIdx << " ), &STI, "
841
842
<< Entry << " ) &&\n " ;
842
843
}
@@ -850,15 +851,15 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
850
851
if (CompressOrUncompress) {
851
852
unsigned Entry = getPredicates (MCOpPredicateMap, MCOpPredicates,
852
853
DestRec, " MCOperandPredicate" );
853
- CondStream.indent (6 )
854
+ CondStream.indent (8 )
854
855
<< ValidatorName << " ("
855
856
<< " MCOperand::createImm(" << DestOperandMap[OpNo].Data .Imm
856
857
<< " ), STI, " << Entry << " ) &&\n " ;
857
858
} else {
858
859
unsigned Entry =
859
860
getPredicates (ImmLeafPredicateMap, ImmLeafPredicates, DestRec,
860
861
" ImmediateCode" );
861
- CondStream.indent (6 )
862
+ CondStream.indent (8 )
862
863
<< TargetName
863
864
<< " ValidateMachineOperand(MachineOperand::CreateImm("
864
865
<< DestOperandMap[OpNo].Data .Imm << " ), &STI, " << Entry
@@ -893,10 +894,11 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
893
894
Func.indent (2 ) << " return false;\n }\n " ;
894
895
895
896
if (!MCOpPredicates.empty ()) {
896
- OS << " static bool " << ValidatorName << " (const MCOperand &MCOp,\n "
897
- << " const MCSubtargetInfo &STI,\n "
898
- << " unsigned PredicateIndex) {\n "
899
- << " switch (PredicateIndex) {\n "
897
+ auto IndentLength = ValidatorName.size () + 13 ;
898
+ OS << " static bool " << ValidatorName << " (const MCOperand &MCOp,\n " ;
899
+ OS.indent (IndentLength) << " const MCSubtargetInfo &STI,\n " ;
900
+ OS.indent (IndentLength) << " unsigned PredicateIndex) {\n " ;
901
+ OS << " switch (PredicateIndex) {\n "
900
902
<< " default:\n "
901
903
<< " llvm_unreachable(\" Unknown MCOperandPredicate kind\" );\n "
902
904
<< " break;\n " ;
@@ -908,15 +910,18 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
908
910
}
909
911
910
912
if (!ImmLeafPredicates.empty ()) {
913
+ auto IndentLength = TargetName.size () + 35 ;
911
914
OS << " static bool " << TargetName
912
- << " ValidateMachineOperand(const MachineOperand &MO,\n "
913
- << " const " << TargetName << " Subtarget *Subtarget,\n "
914
- << " unsigned PredicateIndex) {\n "
915
- << " int64_t Imm = MO.getImm();\n "
916
- << " switch (PredicateIndex) {\n "
917
- << " default:\n "
918
- << " llvm_unreachable(\" Unknown ImmLeaf Predicate kind\" );\n "
919
- << " break;\n " ;
915
+ << " ValidateMachineOperand(const MachineOperand &MO,\n " ;
916
+ OS.indent (IndentLength)
917
+ << " const " << TargetName << " Subtarget *Subtarget,\n " ;
918
+ OS.indent (IndentLength)
919
+ << " unsigned PredicateIndex) {\n "
920
+ << " int64_t Imm = MO.getImm();\n "
921
+ << " switch (PredicateIndex) {\n "
922
+ << " default:\n "
923
+ << " llvm_unreachable(\" Unknown ImmLeaf Predicate kind\" );\n "
924
+ << " break;\n " ;
920
925
921
926
printPredicates (ImmLeafPredicates, " ImmediateCode" , OS);
922
927
0 commit comments