@@ -2466,7 +2466,8 @@ static void emitRegisterMatchErrorFunc(AsmMatcherInfo &Info, raw_ostream &OS) {
2466
2466
}
2467
2467
2468
2468
// / emitValidateOperandClass - Emit the function to validate an operand class.
2469
- static void emitValidateOperandClass (AsmMatcherInfo &Info, raw_ostream &OS) {
2469
+ static void emitValidateOperandClass (const CodeGenTarget &Target,
2470
+ AsmMatcherInfo &Info, raw_ostream &OS) {
2470
2471
OS << " static unsigned validateOperandClass(MCParsedAsmOperand &GOp, "
2471
2472
<< " MatchClassKind Kind) {\n " ;
2472
2473
OS << " " << Info.Target .getName () << " Operand &Operand = ("
@@ -2508,15 +2509,21 @@ static void emitValidateOperandClass(AsmMatcherInfo &Info, raw_ostream &OS) {
2508
2509
OS << " } // end switch (Kind)\n\n " ;
2509
2510
2510
2511
// Check for register operands, including sub-classes.
2512
+ const auto &Regs = Target.getRegBank ().getRegisters ();
2513
+ StringRef Namespace = Regs.front ().TheDef ->getValueAsString (" Namespace" );
2514
+ SmallVector<StringRef> Table (1 + Regs.size (), " InvalidMatchClass" );
2515
+ for (const auto &RC : Info.RegisterClasses ) {
2516
+ const auto &Reg = Target.getRegBank ().getReg (RC.first );
2517
+ Table[Reg->EnumValue ] = RC.second ->Name ;
2518
+ }
2511
2519
OS << " if (Operand.isReg()) {\n " ;
2512
- OS << " MatchClassKind OpKind;\n " ;
2513
- OS << " switch (Operand.getReg().id()) {\n " ;
2514
- OS << " default: OpKind = InvalidMatchClass; break;\n " ;
2515
- for (const auto &RC : Info.RegisterClasses )
2516
- OS << " case " << RC.first ->getValueAsString (" Namespace" )
2517
- << " ::" << RC.first ->getName () << " : OpKind = " << RC.second ->Name
2518
- << " ; break;\n " ;
2519
- OS << " }\n " ;
2520
+ OS << " static constexpr uint16_t Table[" << Namespace
2521
+ << " ::NUM_TARGET_REGS] = {\n " ;
2522
+ for (auto &MatchClassName : Table)
2523
+ OS << " " << MatchClassName << " ,\n " ;
2524
+ OS << " };\n\n " ;
2525
+ OS << " MatchClassKind OpKind = "
2526
+ " (MatchClassKind)Table[Operand.getReg().id()];\n " ;
2520
2527
OS << " return isSubclass(OpKind, Kind) ? "
2521
2528
<< " (unsigned)MCTargetAsmParser::Match_Success :\n "
2522
2529
<< " getDiagKindFromRegisterClass(Kind);\n }\n\n " ;
@@ -3412,7 +3419,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
3412
3419
emitIsSubclass (Target, Info.Classes , OS);
3413
3420
3414
3421
// Emit the routine to validate an operand against a match class.
3415
- emitValidateOperandClass (Info, OS);
3422
+ emitValidateOperandClass (Target, Info, OS);
3416
3423
3417
3424
emitMatchClassKindNames (Info.Classes , OS);
3418
3425
0 commit comments