@@ -2821,6 +2821,43 @@ std::string getArchSupplInfoLoongArch(StringRef const &TargetName,
28212821 return " { .loongarch = { 0, " + MemoryAccess + " }}" ;
28222822}
28232823
2824+ std::string getArchSupplInfoXtensa (StringRef const &TargetName,
2825+ CodeGenInstruction const *CGI,
2826+ raw_string_ostream &OS) {
2827+ static std::set<std::string> Formats;
2828+ // Get instruction format
2829+ ArrayRef<std::pair<Record *, SMRange>> SCs = CGI->TheDef ->getSuperClasses ();
2830+ if (SCs.empty ()) {
2831+ llvm_unreachable (" A CGI without superclass should not exist." );
2832+ }
2833+
2834+ const Record *PrevSC = nullptr ;
2835+ for (int I = SCs.size () - 1 ; I >= 0 ; --I) {
2836+ const Record *SC = SCs[I].first ;
2837+ if (Regex (" XtensaInst[0-9]+" ).match (SC->getName ())) {
2838+ if (!PrevSC)
2839+ llvm_unreachable (" I class has no predecessor." );
2840+ if (PrevSC->getName () == " Requires" ) {
2841+ break ;
2842+ }
2843+
2844+ StringRef form = PrevSC->getName ();
2845+ form.consume_front (" Xtensa" );
2846+ form.consume_back (" _Inst" );
2847+ std::string Format = " XTENSA_INSN_FORM_" + form.upper ();
2848+ if (Formats.find (Format) == Formats.end ()) {
2849+ OS << Format + " ,\n " ;
2850+ }
2851+ Formats.emplace (Format);
2852+ return " { .xtensa = { " + Format + " }}" ;
2853+ }
2854+ PrevSC = SC;
2855+ }
2856+
2857+ // Pseudo instructions
2858+ return " {{ 0 }}" ;
2859+ }
2860+
28242861std::string getArchSupplInfo (StringRef const &TargetName,
28252862 CodeGenInstruction const *CGI,
28262863 raw_string_ostream &FormatEnum) {
@@ -2832,6 +2869,8 @@ std::string getArchSupplInfo(StringRef const &TargetName,
28322869 return getArchSupplInfoLoongArch (TargetName, CGI, FormatEnum);
28332870 } else if (StringRef (TargetName).upper () == " SYSTEMZ" ) {
28342871 return getArchSupplInfoSystemZ (TargetName, CGI, FormatEnum);
2872+ } else if (StringRef (TargetName).upper () == " XTENSA" ) {
2873+ return getArchSupplInfoXtensa (TargetName, CGI, FormatEnum);
28352874 }
28362875 return " {{ 0 }}" ;
28372876}
0 commit comments