Lines Matching refs:OS

1980                  raw_ostream &OS) {  in emitConvertFuncs()  argument
2301 OS << "enum {\n"; in emitConvertFuncs()
2303 OS << " " << KV.second << ",\n"; in emitConvertFuncs()
2305 OS << "};\n\n"; in emitConvertFuncs()
2307 OS << "static const uint8_t TiedAsmOperandTable[][3] = {\n"; in emitConvertFuncs()
2309 OS << " /* " << KV.second << " */ { " << utostr(std::get<0>(KV.first)) in emitConvertFuncs()
2313 OS << "};\n\n"; in emitConvertFuncs()
2315 OS << "static const uint8_t TiedAsmOperandTable[][3] = " in emitConvertFuncs()
2318 OS << "namespace {\n"; in emitConvertFuncs()
2321 OS << "enum OperatorConversionKind {\n"; in emitConvertFuncs()
2323 OS << " " << Converter << ",\n"; in emitConvertFuncs()
2324 OS << " CVT_NUM_CONVERTERS\n"; in emitConvertFuncs()
2325 OS << "};\n\n"; in emitConvertFuncs()
2328 OS << "enum InstructionConversionKind {\n"; in emitConvertFuncs()
2330 OS << " " << Signature << ",\n"; in emitConvertFuncs()
2331 OS << " CVT_NUM_SIGNATURES\n"; in emitConvertFuncs()
2332 OS << "};\n\n"; in emitConvertFuncs()
2334 OS << "} // end anonymous namespace\n\n"; in emitConvertFuncs()
2337 OS << "static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][" in emitConvertFuncs()
2342 OS << " // " << InstructionConversionKinds[Row] << "\n"; in emitConvertFuncs()
2343 OS << " { "; in emitConvertFuncs()
2345 OS << OperandConversionKinds[ConversionTable[Row][i]] << ", "; in emitConvertFuncs()
2348 OS << (unsigned)(ConversionTable[Row][i + 1]) << ", "; in emitConvertFuncs()
2361 OS << TiedOpndEnum->second << ", "; in emitConvertFuncs()
2364 OS << "CVT_Done },\n"; in emitConvertFuncs()
2367 OS << "};\n\n"; in emitConvertFuncs()
2370 OS << ConvertFnBody; in emitConvertFuncs()
2373 OS << OperandFnBody; in emitConvertFuncs()
2381 raw_ostream &OS) { in emitMatchClassEnumeration() argument
2382 OS << "namespace {\n\n"; in emitMatchClassEnumeration()
2384 OS << "/// MatchClassKind - The kinds of classes which participate in\n" in emitMatchClassEnumeration()
2386 OS << "enum MatchClassKind {\n"; in emitMatchClassEnumeration()
2387 OS << " InvalidMatchClass = 0,\n"; in emitMatchClassEnumeration()
2388 OS << " OptionalMatchClass = 1,\n"; in emitMatchClassEnumeration()
2393 OS << " MCK_LAST_TOKEN = " << LastName << ",\n"; in emitMatchClassEnumeration()
2396 OS << " MCK_LAST_REGISTER = " << LastName << ",\n"; in emitMatchClassEnumeration()
2401 OS << " " << CI.Name << ", // "; in emitMatchClassEnumeration()
2403 OS << "'" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2406 OS << "register class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2408 OS << "derived register class\n"; in emitMatchClassEnumeration()
2410 OS << "user defined class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2413 OS << " NumMatchClassKinds\n"; in emitMatchClassEnumeration()
2414 OS << "};\n\n"; in emitMatchClassEnumeration()
2416 OS << "} // end anonymous namespace\n\n"; in emitMatchClassEnumeration()
2422 raw_ostream &OS) { in emitOperandMatchErrorDiagStrings() argument
2430 OS << "static const char *getMatchKindDiag(" << Info.Target.getName() in emitOperandMatchErrorDiagStrings()
2433 OS << " switch (MatchResult) {\n"; in emitOperandMatchErrorDiagStrings()
2439 OS << " case " << Info.Target.getName() << "AsmParser::Match_" in emitOperandMatchErrorDiagStrings()
2441 OS << " return \"" << CI.DiagnosticString << "\";\n"; in emitOperandMatchErrorDiagStrings()
2445 OS << " default:\n"; in emitOperandMatchErrorDiagStrings()
2446 OS << " return nullptr;\n"; in emitOperandMatchErrorDiagStrings()
2448 OS << " }\n"; in emitOperandMatchErrorDiagStrings()
2449 OS << "}\n\n"; in emitOperandMatchErrorDiagStrings()
2452 static void emitRegisterMatchErrorFunc(AsmMatcherInfo &Info, raw_ostream &OS) { in emitRegisterMatchErrorFunc() argument
2453 OS << "static unsigned getDiagKindFromRegisterClass(MatchClassKind " in emitRegisterMatchErrorFunc()
2458 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitRegisterMatchErrorFunc()
2460 OS << " switch (RegisterClass) {\n"; in emitRegisterMatchErrorFunc()
2463 OS << " case " << CI.Name << ":\n"; in emitRegisterMatchErrorFunc()
2464 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitRegisterMatchErrorFunc()
2469 OS << " default:\n"; in emitRegisterMatchErrorFunc()
2470 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitRegisterMatchErrorFunc()
2472 OS << " }\n"; in emitRegisterMatchErrorFunc()
2474 OS << "}\n\n"; in emitRegisterMatchErrorFunc()
2478 static void emitValidateOperandClass(AsmMatcherInfo &Info, raw_ostream &OS) { in emitValidateOperandClass() argument
2479 OS << "static unsigned validateOperandClass(MCParsedAsmOperand &GOp, " in emitValidateOperandClass()
2481 OS << " " << Info.Target.getName() << "Operand &Operand = (" in emitValidateOperandClass()
2485 OS << " if (Kind == InvalidMatchClass)\n"; in emitValidateOperandClass()
2486 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n\n"; in emitValidateOperandClass()
2490 OS << " if (Operand.isToken() && Kind <= MCK_LAST_TOKEN)\n"; in emitValidateOperandClass()
2491 OS << " return isSubclass(matchTokenString(Operand.getToken()), Kind) ?\n" in emitValidateOperandClass()
2497 OS << " switch (Kind) {\n" in emitValidateOperandClass()
2503 OS << " // '" << CI.ClassName << "' class\n"; in emitValidateOperandClass()
2504 OS << " case " << CI.Name << ": {\n"; in emitValidateOperandClass()
2505 OS << " DiagnosticPredicate DP(Operand." << CI.PredicateMethod in emitValidateOperandClass()
2507 OS << " if (DP.isMatch())\n"; in emitValidateOperandClass()
2508 OS << " return MCTargetAsmParser::Match_Success;\n"; in emitValidateOperandClass()
2510 OS << " if (DP.isNearMatch())\n"; in emitValidateOperandClass()
2511 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitValidateOperandClass()
2513 OS << " break;\n"; in emitValidateOperandClass()
2515 OS << " break;\n"; in emitValidateOperandClass()
2516 OS << " }\n"; in emitValidateOperandClass()
2518 OS << " } // end switch (Kind)\n\n"; in emitValidateOperandClass()
2521 OS << " if (Operand.isReg()) {\n"; in emitValidateOperandClass()
2522 OS << " MatchClassKind OpKind;\n"; in emitValidateOperandClass()
2523 OS << " switch (Operand.getReg().id()) {\n"; in emitValidateOperandClass()
2524 OS << " default: OpKind = InvalidMatchClass; break;\n"; in emitValidateOperandClass()
2526 OS << " case " << RC.first->getValueAsString("Namespace") in emitValidateOperandClass()
2529 OS << " }\n"; in emitValidateOperandClass()
2530 OS << " return isSubclass(OpKind, Kind) ? " in emitValidateOperandClass()
2535 OS << " if (Kind > MCK_LAST_TOKEN && Kind <= MCK_LAST_REGISTER)\n"; in emitValidateOperandClass()
2536 OS << " return getDiagKindFromRegisterClass(Kind);\n\n"; in emitValidateOperandClass()
2540 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitValidateOperandClass()
2541 OS << "}\n\n"; in emitValidateOperandClass()
2547 raw_ostream &OS) { in emitIsSubclass() argument
2548 OS << "/// isSubclass - Compute whether \\p A is a subclass of \\p B.\n"; in emitIsSubclass()
2549 OS << "static bool isSubclass(MatchClassKind A, MatchClassKind B) {\n"; in emitIsSubclass()
2550 OS << " if (A == B)\n"; in emitIsSubclass()
2551 OS << " return true;\n\n"; in emitIsSubclass()
2568 OS << " switch (A) {\n"; in emitIsSubclass()
2569 OS << " default:\n"; in emitIsSubclass()
2570 OS << " return false;\n"; in emitIsSubclass()
2574 OS << "\n case " << A.Name << ":\n"; in emitIsSubclass()
2577 OS << " return B == " << SuperClasses.back() << ";\n"; in emitIsSubclass()
2582 OS << " switch (B) {\n"; in emitIsSubclass()
2583 OS << " default: return false;\n"; in emitIsSubclass()
2585 OS << " case " << SC << ": return true;\n"; in emitIsSubclass()
2586 OS << " }\n"; in emitIsSubclass()
2589 OS << " return false;\n"; in emitIsSubclass()
2596 OS << " }\n"; in emitIsSubclass()
2598 OS << " return false;\n"; in emitIsSubclass()
2600 OS << "}\n\n"; in emitIsSubclass()
2607 raw_ostream &OS) { in emitMatchTokenString() argument
2615 OS << "static MatchClassKind matchTokenString(StringRef Name) {\n"; in emitMatchTokenString()
2617 StringMatcher("Name", Matches, OS).Emit(); in emitMatchTokenString()
2619 OS << " return InvalidMatchClass;\n"; in emitMatchTokenString()
2620 OS << "}\n\n"; in emitMatchTokenString()
2626 raw_ostream &OS) { in emitMatchRegisterName() argument
2641 OS << "static MCRegister MatchRegisterName(StringRef Name) {\n"; in emitMatchRegisterName()
2645 StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates); in emitMatchRegisterName()
2647 OS << " return " << Namespace << "::NoRegister;\n"; in emitMatchRegisterName()
2648 OS << "}\n\n"; in emitMatchRegisterName()
2654 raw_ostream &OS) { in emitMatchRegisterAltName() argument
2676 OS << "static MCRegister MatchRegisterAltName(StringRef Name) {\n"; in emitMatchRegisterAltName()
2680 StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates); in emitMatchRegisterAltName()
2682 OS << " return " << Namespace << "::NoRegister;\n"; in emitMatchRegisterAltName()
2683 OS << "}\n\n"; in emitMatchRegisterAltName()
2687 static void emitOperandDiagnosticTypes(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandDiagnosticTypes() argument
2704 OS << " Match_" << Type << ",\n"; in emitOperandDiagnosticTypes()
2705 OS << " END_OPERAND_DIAGNOSTIC_TYPES\n"; in emitOperandDiagnosticTypes()
2710 static void emitGetSubtargetFeatureName(AsmMatcherInfo &Info, raw_ostream &OS) { in emitGetSubtargetFeatureName() argument
2711 OS << "// User-level names for subtarget features that participate in\n" in emitGetSubtargetFeatureName()
2715 OS << " switch(Val) {\n"; in emitGetSubtargetFeatureName()
2719 OS << " case " << SFI.getEnumBitName() << ": return \"" in emitGetSubtargetFeatureName()
2722 OS << " default: return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2723 OS << " }\n"; in emitGetSubtargetFeatureName()
2726 OS << " return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2728 OS << "}\n\n"; in emitGetSubtargetFeatureName()
2757 emitMnemonicAliasVariant(raw_ostream &OS, const AsmMatcherInfo &Info, in emitMnemonicAliasVariant() argument
2832 StringMatcher("Mnemonic", Cases, OS).Emit(Indent); in emitMnemonicAliasVariant()
2837 static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info, in emitMnemonicAliases() argument
2848 OS << "static void applyMnemonicAliases(StringRef &Mnemonic, " in emitMnemonicAliases()
2850 OS << " switch (VariantID) {\n"; in emitMnemonicAliases()
2856 OS << " case " << AsmParserVariantNo << ":\n"; in emitMnemonicAliases()
2857 emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2, in emitMnemonicAliases()
2859 OS << " break;\n"; in emitMnemonicAliases()
2861 OS << " }\n"; in emitMnemonicAliases()
2864 emitMnemonicAliasVariant(OS, Info, Aliases); in emitMnemonicAliases()
2866 OS << "}\n\n"; in emitMnemonicAliases()
2872 emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, in emitCustomOperandParsing() argument
2883 OS << "namespace {\n"; in emitCustomOperandParsing()
2884 OS << " struct OperandMatchEntry {\n"; in emitCustomOperandParsing()
2885 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) << " Mnemonic;\n"; in emitCustomOperandParsing()
2886 OS << " " << getMinimalTypeForRange(MaxMask) << " OperandMask;\n"; in emitCustomOperandParsing()
2887 OS << " " in emitCustomOperandParsing()
2892 OS << " " << getMinimalTypeForRange(MaxFeaturesIndex) in emitCustomOperandParsing()
2894 OS << " StringRef getMnemonic() const {\n"; in emitCustomOperandParsing()
2895 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in emitCustomOperandParsing()
2896 OS << " MnemonicTable[Mnemonic]);\n"; in emitCustomOperandParsing()
2897 OS << " }\n"; in emitCustomOperandParsing()
2898 OS << " };\n\n"; in emitCustomOperandParsing()
2900 OS << " // Predicate for searching for an opcode.\n"; in emitCustomOperandParsing()
2901 OS << " struct LessOpcodeOperand {\n"; in emitCustomOperandParsing()
2902 OS << " bool operator()(const OperandMatchEntry &LHS, StringRef RHS) {\n"; in emitCustomOperandParsing()
2903 OS << " return LHS.getMnemonic() < RHS;\n"; in emitCustomOperandParsing()
2904 OS << " }\n"; in emitCustomOperandParsing()
2905 OS << " bool operator()(StringRef LHS, const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2906 OS << " return LHS < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2907 OS << " }\n"; in emitCustomOperandParsing()
2908 OS << " bool operator()(const OperandMatchEntry &LHS,"; in emitCustomOperandParsing()
2909 OS << " const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2910 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2911 OS << " }\n"; in emitCustomOperandParsing()
2912 OS << " };\n"; in emitCustomOperandParsing()
2914 OS << "} // end anonymous namespace\n\n"; in emitCustomOperandParsing()
2916 OS << "static const OperandMatchEntry OperandMatchTable[" in emitCustomOperandParsing()
2919 OS << " /* Operand List Mnemonic, Mask, Operand Class, Features */\n"; in emitCustomOperandParsing()
2923 OS << " { "; in emitCustomOperandParsing()
2927 OS << StringTable.GetOrAddStringOffset(LenMnemonic, false) << " /* " in emitCustomOperandParsing()
2930 OS << OMI.OperandMask; in emitCustomOperandParsing()
2931 OS << " /* "; in emitCustomOperandParsing()
2935 OS << LS << i; in emitCustomOperandParsing()
2936 OS << " */, "; in emitCustomOperandParsing()
2938 OS << OMI.CI->Name; in emitCustomOperandParsing()
2941 OS << ", AMFBS"; in emitCustomOperandParsing()
2943 OS << "_None"; in emitCustomOperandParsing()
2946 OS << '_' << II.RequiredFeatures[i]->TheDef->getName(); in emitCustomOperandParsing()
2948 OS << " },\n"; in emitCustomOperandParsing()
2950 OS << "};\n\n"; in emitCustomOperandParsing()
2954 OS << "ParseStatus " << Target.getName() << ClassName << "::\n" in emitCustomOperandParsing()
2962 OS << " case " << CI.Name << ":\n" in emitCustomOperandParsing()
2966 OS << " default:\n"; in emitCustomOperandParsing()
2967 OS << " return ParseStatus::NoMatch;\n"; in emitCustomOperandParsing()
2968 OS << " }\n"; in emitCustomOperandParsing()
2969 OS << " return ParseStatus::NoMatch;\n"; in emitCustomOperandParsing()
2970 OS << "}\n\n"; in emitCustomOperandParsing()
2975 OS << "ParseStatus " << Target.getName() << ClassName << "::\n" in emitCustomOperandParsing()
2981 OS << " // Get the current feature set.\n"; in emitCustomOperandParsing()
2982 OS << " const FeatureBitset &AvailableFeatures = " in emitCustomOperandParsing()
2985 OS << " // Get the next operand index.\n"; in emitCustomOperandParsing()
2986 OS << " unsigned NextOpNum = Operands.size()" in emitCustomOperandParsing()
2990 OS << " // Search the table.\n"; in emitCustomOperandParsing()
2992 OS << " auto MnemonicRange =\n"; in emitCustomOperandParsing()
2993 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2995 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2997 OS << " auto MnemonicRange = std::pair(std::begin(OperandMatchTable)," in emitCustomOperandParsing()
2999 OS << " if (!Mnemonic.empty())\n"; in emitCustomOperandParsing()
3000 OS << " MnemonicRange =\n"; in emitCustomOperandParsing()
3001 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
3003 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
3006 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitCustomOperandParsing()
3007 OS << " return ParseStatus::NoMatch;\n\n"; in emitCustomOperandParsing()
3009 OS << " for (const OperandMatchEntry *it = MnemonicRange.first,\n" in emitCustomOperandParsing()
3012 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in emitCustomOperandParsing()
3013 OS << " assert(Mnemonic == it->getMnemonic());\n\n"; in emitCustomOperandParsing()
3016 OS << " // check if the available features match\n"; in emitCustomOperandParsing()
3017 OS << " const FeatureBitset &RequiredFeatures = " in emitCustomOperandParsing()
3019 OS << " if (!ParseForAllFeatures && (AvailableFeatures & " in emitCustomOperandParsing()
3021 OS << " continue;\n\n"; in emitCustomOperandParsing()
3024 OS << " // check if the operand in question has a custom parser.\n"; in emitCustomOperandParsing()
3025 OS << " if (!(it->OperandMask & (1 << NextOpNum)))\n"; in emitCustomOperandParsing()
3026 OS << " continue;\n\n"; in emitCustomOperandParsing()
3032 OS << " // call custom parse method to handle the operand\n"; in emitCustomOperandParsing()
3033 OS << " ParseStatus Result = " << ParserName << "(Operands, it->Class);\n"; in emitCustomOperandParsing()
3034 OS << " if (!Result.isNoMatch())\n"; in emitCustomOperandParsing()
3035 OS << " return Result;\n"; in emitCustomOperandParsing()
3036 OS << " }\n\n"; in emitCustomOperandParsing()
3038 OS << " // Okay, we had no match.\n"; in emitCustomOperandParsing()
3039 OS << " return ParseStatus::NoMatch;\n"; in emitCustomOperandParsing()
3040 OS << "}\n\n"; in emitCustomOperandParsing()
3044 AsmMatcherInfo &Info, raw_ostream &OS, in emitAsmTiedOperandConstraints() argument
3048 OS << "static bool "; in emitAsmTiedOperandConstraints()
3049 OS << "checkAsmTiedOperandConstraints(const " << Target.getName() in emitAsmTiedOperandConstraints()
3051 OS << " unsigned Kind, const OperandVector " in emitAsmTiedOperandConstraints()
3054 OS << " ArrayRef<unsigned> DefaultsOffset,\n"; in emitAsmTiedOperandConstraints()
3055 OS << " uint64_t &ErrorInfo) {\n"; in emitAsmTiedOperandConstraints()
3056 OS << " assert(Kind < CVT_NUM_SIGNATURES && \"Invalid signature!\");\n"; in emitAsmTiedOperandConstraints()
3057 OS << " const uint8_t *Converter = ConversionTable[Kind];\n"; in emitAsmTiedOperandConstraints()
3058 OS << " for (const uint8_t *p = Converter; *p; p += 2) {\n"; in emitAsmTiedOperandConstraints()
3059 OS << " switch (*p) {\n"; in emitAsmTiedOperandConstraints()
3060 OS << " case CVT_Tied: {\n"; in emitAsmTiedOperandConstraints()
3061 OS << " unsigned OpIdx = *(p + 1);\n"; in emitAsmTiedOperandConstraints()
3062 OS << " assert(OpIdx < (size_t)(std::end(TiedAsmOperandTable) -\n"; in emitAsmTiedOperandConstraints()
3063 OS << " std::begin(TiedAsmOperandTable)) &&\n"; in emitAsmTiedOperandConstraints()
3064 OS << " \"Tied operand not found\");\n"; in emitAsmTiedOperandConstraints()
3065 OS << " unsigned OpndNum1 = TiedAsmOperandTable[OpIdx][1];\n"; in emitAsmTiedOperandConstraints()
3066 OS << " unsigned OpndNum2 = TiedAsmOperandTable[OpIdx][2];\n"; in emitAsmTiedOperandConstraints()
3071 OS << " OpndNum1 = OpndNum1 - DefaultsOffset[OpndNum1];\n"; in emitAsmTiedOperandConstraints()
3072 OS << " OpndNum2 = OpndNum2 - DefaultsOffset[OpndNum2];\n"; in emitAsmTiedOperandConstraints()
3074 OS << " if (OpndNum1 != OpndNum2) {\n"; in emitAsmTiedOperandConstraints()
3075 OS << " auto &SrcOp1 = Operands[OpndNum1];\n"; in emitAsmTiedOperandConstraints()
3076 OS << " auto &SrcOp2 = Operands[OpndNum2];\n"; in emitAsmTiedOperandConstraints()
3077 OS << " if (!AsmParser.areEqualRegs(*SrcOp1, *SrcOp2)) {\n"; in emitAsmTiedOperandConstraints()
3078 OS << " ErrorInfo = OpndNum2;\n"; in emitAsmTiedOperandConstraints()
3079 OS << " return false;\n"; in emitAsmTiedOperandConstraints()
3080 OS << " }\n"; in emitAsmTiedOperandConstraints()
3081 OS << " }\n"; in emitAsmTiedOperandConstraints()
3082 OS << " break;\n"; in emitAsmTiedOperandConstraints()
3083 OS << " }\n"; in emitAsmTiedOperandConstraints()
3084 OS << " default:\n"; in emitAsmTiedOperandConstraints()
3085 OS << " break;\n"; in emitAsmTiedOperandConstraints()
3086 OS << " }\n"; in emitAsmTiedOperandConstraints()
3087 OS << " }\n"; in emitAsmTiedOperandConstraints()
3088 OS << " return true;\n"; in emitAsmTiedOperandConstraints()
3089 OS << "}\n\n"; in emitAsmTiedOperandConstraints()
3092 static void emitMnemonicSpellChecker(raw_ostream &OS, CodeGenTarget &Target, in emitMnemonicSpellChecker() argument
3094 OS << "static std::string " << Target.getName() in emitMnemonicSpellChecker()
3098 OS << " return \"\";"; in emitMnemonicSpellChecker()
3100 OS << " const unsigned MaxEditDist = 2;\n"; in emitMnemonicSpellChecker()
3101 OS << " std::vector<StringRef> Candidates;\n"; in emitMnemonicSpellChecker()
3102 OS << " StringRef Prev = \"\";\n\n"; in emitMnemonicSpellChecker()
3104 OS << " // Find the appropriate table for this asm variant.\n"; in emitMnemonicSpellChecker()
3105 OS << " const MatchEntry *Start, *End;\n"; in emitMnemonicSpellChecker()
3106 OS << " switch (VariantID) {\n"; in emitMnemonicSpellChecker()
3107 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in emitMnemonicSpellChecker()
3111 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in emitMnemonicSpellChecker()
3114 OS << " }\n\n"; in emitMnemonicSpellChecker()
3115 OS << " for (auto I = Start; I < End; I++) {\n"; in emitMnemonicSpellChecker()
3116 OS << " // Ignore unsupported instructions.\n"; in emitMnemonicSpellChecker()
3117 OS << " const FeatureBitset &RequiredFeatures = " in emitMnemonicSpellChecker()
3119 OS << " if ((FBS & RequiredFeatures) != RequiredFeatures)\n"; in emitMnemonicSpellChecker()
3120 OS << " continue;\n"; in emitMnemonicSpellChecker()
3121 OS << "\n"; in emitMnemonicSpellChecker()
3122 OS << " StringRef T = I->getMnemonic();\n"; in emitMnemonicSpellChecker()
3123 OS << " // Avoid recomputing the edit distance for the same string.\n"; in emitMnemonicSpellChecker()
3124 OS << " if (T == Prev)\n"; in emitMnemonicSpellChecker()
3125 OS << " continue;\n"; in emitMnemonicSpellChecker()
3126 OS << "\n"; in emitMnemonicSpellChecker()
3127 OS << " Prev = T;\n"; in emitMnemonicSpellChecker()
3128 OS << " unsigned Dist = S.edit_distance(T, false, MaxEditDist);\n"; in emitMnemonicSpellChecker()
3129 OS << " if (Dist <= MaxEditDist)\n"; in emitMnemonicSpellChecker()
3130 OS << " Candidates.push_back(T);\n"; in emitMnemonicSpellChecker()
3131 OS << " }\n"; in emitMnemonicSpellChecker()
3132 OS << "\n"; in emitMnemonicSpellChecker()
3133 OS << " if (Candidates.empty())\n"; in emitMnemonicSpellChecker()
3134 OS << " return \"\";\n"; in emitMnemonicSpellChecker()
3135 OS << "\n"; in emitMnemonicSpellChecker()
3136 OS << " std::string Res = \", did you mean: \";\n"; in emitMnemonicSpellChecker()
3137 OS << " unsigned i = 0;\n"; in emitMnemonicSpellChecker()
3138 OS << " for (; i < Candidates.size() - 1; i++)\n"; in emitMnemonicSpellChecker()
3139 OS << " Res += Candidates[i].str() + \", \";\n"; in emitMnemonicSpellChecker()
3140 OS << " return Res + Candidates[i].str() + \"?\";\n"; in emitMnemonicSpellChecker()
3142 OS << "}\n"; in emitMnemonicSpellChecker()
3143 OS << "\n"; in emitMnemonicSpellChecker()
3146 static void emitMnemonicChecker(raw_ostream &OS, CodeGenTarget &Target, in emitMnemonicChecker() argument
3149 OS << "static bool " << Target.getName() in emitMnemonicChecker()
3151 OS << " " in emitMnemonicChecker()
3153 OS << " " in emitMnemonicChecker()
3157 OS << " return false;\n"; in emitMnemonicChecker()
3160 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in emitMnemonicChecker()
3161 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);"; in emitMnemonicChecker()
3162 OS << "\n\n"; in emitMnemonicChecker()
3164 OS << " // Find the appropriate table for this asm variant.\n"; in emitMnemonicChecker()
3165 OS << " const MatchEntry *Start, *End;\n"; in emitMnemonicChecker()
3166 OS << " switch (VariantID) {\n"; in emitMnemonicChecker()
3167 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in emitMnemonicChecker()
3171 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in emitMnemonicChecker()
3174 OS << " }\n\n"; in emitMnemonicChecker()
3176 OS << " // Search the table.\n"; in emitMnemonicChecker()
3178 OS << " auto MnemonicRange = " in emitMnemonicChecker()
3181 OS << " auto MnemonicRange = std::pair(Start, End);\n"; in emitMnemonicChecker()
3182 OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n"; in emitMnemonicChecker()
3183 OS << " if (!Mnemonic.empty())\n"; in emitMnemonicChecker()
3184 OS << " MnemonicRange = " in emitMnemonicChecker()
3188 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitMnemonicChecker()
3189 OS << " return false;\n\n"; in emitMnemonicChecker()
3191 OS << " for (const MatchEntry *it = MnemonicRange.first, " in emitMnemonicChecker()
3193 OS << " it != ie; ++it) {\n"; in emitMnemonicChecker()
3194 OS << " const FeatureBitset &RequiredFeatures =\n"; in emitMnemonicChecker()
3195 OS << " FeatureBitsets[it->RequiredFeaturesIdx];\n"; in emitMnemonicChecker()
3196 OS << " if ((AvailableFeatures & RequiredFeatures) == "; in emitMnemonicChecker()
3197 OS << "RequiredFeatures)\n"; in emitMnemonicChecker()
3198 OS << " return true;\n"; in emitMnemonicChecker()
3199 OS << " }\n"; in emitMnemonicChecker()
3200 OS << " return false;\n"; in emitMnemonicChecker()
3202 OS << "}\n"; in emitMnemonicChecker()
3203 OS << "\n"; in emitMnemonicChecker()
3208 raw_ostream &OS) { in emitMatchClassKindNames() argument
3209 OS << "#ifndef NDEBUG\n"; in emitMatchClassKindNames()
3210 OS << "const char *getMatchClassName(MatchClassKind Kind) {\n"; in emitMatchClassKindNames()
3211 OS << " switch (Kind) {\n"; in emitMatchClassKindNames()
3213 OS << " case InvalidMatchClass: return \"InvalidMatchClass\";\n"; in emitMatchClassKindNames()
3214 OS << " case OptionalMatchClass: return \"OptionalMatchClass\";\n"; in emitMatchClassKindNames()
3216 OS << " case " << CI.Name << ": return \"" << CI.Name << "\";\n"; in emitMatchClassKindNames()
3218 OS << " case NumMatchClassKinds: return \"NumMatchClassKinds\";\n"; in emitMatchClassKindNames()
3220 OS << " }\n"; in emitMatchClassKindNames()
3221 OS << " llvm_unreachable(\"unhandled MatchClassKind!\");\n"; in emitMatchClassKindNames()
3222 OS << "}\n\n"; in emitMatchClassKindNames()
3223 OS << "#endif // NDEBUG\n"; in emitMatchClassKindNames()
3234 void AsmMatcherEmitter::run(raw_ostream &OS) { in run() argument
3239 emitSourceFileHeader("Assembly Matcher Source Fragment", OS, Records); in run()
3305 OS << "\n#ifdef GET_ASSEMBLER_HEADER\n"; in run()
3306 OS << "#undef GET_ASSEMBLER_HEADER\n"; in run()
3307 OS << " // This should be included into the middle of the declaration of\n"; in run()
3308 OS << " // your subclasses implementation of MCTargetAsmParser.\n"; in run()
3309 OS << " FeatureBitset ComputeAvailableFeatures(const FeatureBitset &FB) " in run()
3312 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
3319 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
3323 OS << " void convertToMapAndConstraints(unsigned Kind,\n "; in run()
3324 OS << " const OperandVector &Operands) override;\n"; in run()
3325 OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n" in run()
3328 OS << " SmallVectorImpl<NearMissInfo> " in run()
3331 OS << " uint64_t &ErrorInfo,\n" in run()
3333 OS << " bool matchingInlineAsm,\n" in run()
3336 OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n" in run()
3348 OS << " ParseStatus MatchOperandParserImpl(\n"; in run()
3349 OS << " OperandVector &Operands,\n"; in run()
3350 OS << " StringRef Mnemonic,\n"; in run()
3351 OS << " bool ParseForAllFeatures = false);\n"; in run()
3353 OS << " ParseStatus tryCustomParseOperand(\n"; in run()
3354 OS << " OperandVector &Operands,\n"; in run()
3355 OS << " unsigned MCK);\n\n"; in run()
3358 OS << "#endif // GET_ASSEMBLER_HEADER\n\n"; in run()
3361 OS << "\n#ifdef GET_OPERAND_DIAGNOSTIC_TYPES\n"; in run()
3362 OS << "#undef GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
3363 emitOperandDiagnosticTypes(Info, OS); in run()
3364 OS << "#endif // GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
3366 OS << "\n#ifdef GET_REGISTER_MATCHER\n"; in run()
3367 OS << "#undef GET_REGISTER_MATCHER\n\n"; in run()
3371 Info.SubtargetFeatures, OS); in run()
3376 emitMatchRegisterName(Target, AsmParser, OS); in run()
3379 emitMatchRegisterAltName(Target, AsmParser, OS); in run()
3381 OS << "#endif // GET_REGISTER_MATCHER\n\n"; in run()
3383 OS << "\n#ifdef GET_SUBTARGET_FEATURE_NAME\n"; in run()
3384 OS << "#undef GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
3387 emitGetSubtargetFeatureName(Info, OS); in run()
3389 OS << "#endif // GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
3391 OS << "\n#ifdef GET_MATCHER_IMPLEMENTATION\n"; in run()
3392 OS << "#undef GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3395 bool HasMnemonicAliases = emitMnemonicAliases(OS, Info, Target); in run()
3402 HasOptionalOperands, OS); in run()
3405 emitMatchClassEnumeration(Target, Info.Classes, OS); in run()
3409 emitOperandMatchErrorDiagStrings(Info, OS); in run()
3412 emitRegisterMatchErrorFunc(Info, OS); in run()
3415 emitMatchTokenString(Target, Info.Classes, OS); in run()
3418 emitIsSubclass(Target, Info.Classes, OS); in run()
3421 emitValidateOperandClass(Info, OS); in run()
3423 emitMatchClassKindNames(Info.Classes, OS); in run()
3428 Info.SubtargetFeatures, OS); in run()
3431 emitAsmTiedOperandConstraints(Target, Info, OS, HasOptionalOperands); in run()
3448 OS << "static const char MnemonicTable[] =\n"; in run()
3449 StringTable.EmitString(OS); in run()
3450 OS << ";\n\n"; in run()
3476 OS << "// Feature bitsets.\n" in run()
3482 OS << " " << getNameForFeatureBitset(FeatureBitset) << ",\n"; in run()
3484 OS << "};\n\n" in run()
3490 OS << " {"; in run()
3494 OS << I->second.getEnumBitName() << ", "; in run()
3496 OS << "},\n"; in run()
3498 OS << "};\n\n"; in run()
3510 OS << "namespace {\n"; in run()
3511 OS << " struct MatchEntry {\n"; in run()
3512 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) << " Mnemonic;\n"; in run()
3513 OS << " uint16_t Opcode;\n"; in run()
3514 OS << " " << getMinimalTypeForRange(NumConverters) << " ConvertFn;\n"; in run()
3515 OS << " " << getMinimalTypeForRange(FeatureBitsets.size()) in run()
3517 OS << " " in run()
3522 OS << " StringRef getMnemonic() const {\n"; in run()
3523 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in run()
3524 OS << " MnemonicTable[Mnemonic]);\n"; in run()
3525 OS << " }\n"; in run()
3526 OS << " };\n\n"; in run()
3528 OS << " // Predicate for searching for an opcode.\n"; in run()
3529 OS << " struct LessOpcode {\n"; in run()
3530 OS << " bool operator()(const MatchEntry &LHS, StringRef RHS) {\n"; in run()
3531 OS << " return LHS.getMnemonic() < RHS;\n"; in run()
3532 OS << " }\n"; in run()
3533 OS << " bool operator()(StringRef LHS, const MatchEntry &RHS) {\n"; in run()
3534 OS << " return LHS < RHS.getMnemonic();\n"; in run()
3535 OS << " }\n"; in run()
3536 OS << " bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {\n"; in run()
3537 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in run()
3538 OS << " }\n"; in run()
3539 OS << " };\n"; in run()
3541 OS << "} // end anonymous namespace\n\n"; in run()
3548 OS << "static const MatchEntry MatchTable" << VC << "[] = {\n"; in run()
3557 OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in run()
3563 OS << "AMFBS"; in run()
3565 OS << "_None"; in run()
3568 OS << '_' << MI->RequiredFeatures[i]->TheDef->getName(); in run()
3570 OS << ", { "; in run()
3573 OS << LS << Op.Class->Name; in run()
3574 OS << " }, },\n"; in run()
3577 OS << "};\n\n"; in run()
3580 OS << "#include \"llvm/Support/Debug.h\"\n"; in run()
3581 OS << "#include \"llvm/Support/Format.h\"\n\n"; in run()
3584 OS << "unsigned " << Target.getName() << ClassName << "::\n" in run()
3586 OS << " MCInst &Inst,\n"; in run()
3588 OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n"; in run()
3590 OS << " uint64_t &ErrorInfo,\n" in run()
3592 OS << " bool matchingInlineAsm, unsigned VariantID) {\n"; in run()
3595 OS << " // Eliminate obvious mismatches.\n"; in run()
3596 OS << " if (Operands.size() > " << (MaxNumOperands + HasMnemonicFirst) in run()
3598 OS << " ErrorInfo = " << (MaxNumOperands + HasMnemonicFirst) << ";\n"; in run()
3599 OS << " return Match_InvalidOperand;\n"; in run()
3600 OS << " }\n\n"; in run()
3604 OS << " // Get the current feature set.\n"; in run()
3605 OS << " const FeatureBitset &AvailableFeatures = " in run()
3608 OS << " // Get the instruction mnemonic, which is the first token.\n"; in run()
3610 OS << " StringRef Mnemonic = ((" << Target.getName() in run()
3613 OS << " StringRef Mnemonic;\n"; in run()
3614 OS << " if (Operands[0]->isToken())\n"; in run()
3615 OS << " Mnemonic = ((" << Target.getName() in run()
3620 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in run()
3621 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);\n\n"; in run()
3626 OS << " // Some state to try to produce better error messages.\n"; in run()
3627 OS << " bool HadMatchOtherThanFeatures = false;\n"; in run()
3628 OS << " bool HadMatchOtherThanPredicate = false;\n"; in run()
3629 OS << " unsigned RetCode = Match_InvalidOperand;\n"; in run()
3630 OS << " MissingFeatures.set();\n"; in run()
3631 OS << " // Set ErrorInfo to the operand that mismatches if it is\n"; in run()
3632 OS << " // wrong for all instances of the instruction.\n"; in run()
3633 OS << " ErrorInfo = ~0ULL;\n"; in run()
3637 OS << " SmallBitVector OptionalOperandsMask(" << MaxNumOperands << ");\n"; in run()
3641 OS << " // Find the appropriate table for this asm variant.\n"; in run()
3642 OS << " const MatchEntry *Start, *End;\n"; in run()
3643 OS << " switch (VariantID) {\n"; in run()
3644 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in run()
3648 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in run()
3651 OS << " }\n"; in run()
3653 OS << " // Search the table.\n"; in run()
3655 OS << " auto MnemonicRange = " in run()
3658 OS << " auto MnemonicRange = std::pair(Start, End);\n"; in run()
3659 OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n"; in run()
3660 OS << " if (!Mnemonic.empty())\n"; in run()
3661 OS << " MnemonicRange = " in run()
3665 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"AsmMatcher: found \" " in run()
3670 OS << " // Return a more specific error code if no mnemonics match.\n"; in run()
3671 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in run()
3672 OS << " return Match_MnemonicFail;\n\n"; in run()
3674 OS << " for (const MatchEntry *it = MnemonicRange.first, " in run()
3676 OS << " it != ie; ++it) {\n"; in run()
3677 OS << " const FeatureBitset &RequiredFeatures = " in run()
3679 OS << " bool HasRequiredFeatures =\n"; in run()
3680 OS << " (AvailableFeatures & RequiredFeatures) == RequiredFeatures;\n"; in run()
3681 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Trying to match " in run()
3683 OS << " << MII.getName(it->Opcode) " in run()
3687 OS << " // Some state to record ways in which this instruction did not " in run()
3689 OS << " NearMissInfo OperandNearMiss = NearMissInfo::getSuccess();\n"; in run()
3690 OS << " NearMissInfo FeaturesNearMiss = NearMissInfo::getSuccess();\n"; in run()
3691 OS << " NearMissInfo EarlyPredicateNearMiss = " in run()
3693 OS << " NearMissInfo LatePredicateNearMiss = " in run()
3695 OS << " bool MultipleInvalidOperands = false;\n"; in run()
3699 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in run()
3700 OS << " assert(Mnemonic == it->getMnemonic());\n"; in run()
3705 OS << " bool OperandsValid = true;\n"; in run()
3707 OS << " OptionalOperandsMask.reset(0, " << MaxNumOperands << ");\n"; in run()
3709 OS << " for (unsigned FormalIdx = " << (HasMnemonicFirst ? "0" : "SIndex") in run()
3712 OS << " auto Formal = " in run()
3714 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3715 OS << " dbgs() << \" Matching formal operand class \" " in run()
3717 OS << " << \" against actual operand at index \" " in run()
3719 OS << " if (ActualIdx < Operands.size())\n"; in run()
3720 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \" (\";\n"; in run()
3721 OS << " Operands[ActualIdx]->print(dbgs()); dbgs() << " in run()
3723 OS << " else\n"; in run()
3724 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \": \");\n"; in run()
3725 OS << " if (ActualIdx >= Operands.size()) {\n"; in run()
3726 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"actual operand " in run()
3729 OS << " bool ThisOperandValid = (Formal == " in run()
3732 OS << " if (!ThisOperandValid) {\n"; in run()
3733 OS << " if (!OperandNearMiss) {\n"; in run()
3734 OS << " // Record info about match failure for later use.\n"; in run()
3735 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"recording " in run()
3737 OS << " OperandNearMiss =\n"; in run()
3738 OS << " NearMissInfo::getTooFewOperands(Formal, " in run()
3740 OS << " } else if (OperandNearMiss.getKind() != " in run()
3742 OS << " // If more than one operand is invalid, give up on this " in run()
3744 OS << " DEBUG_WITH_TYPE(\n"; in run()
3745 OS << " \"asm-matcher\",\n"; in run()
3746 OS << " dbgs() << \"second invalid operand, giving up on " in run()
3748 OS << " MultipleInvalidOperands = true;\n"; in run()
3749 OS << " break;\n"; in run()
3750 OS << " }\n"; in run()
3751 OS << " } else {\n"; in run()
3752 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"but formal " in run()
3754 OS << " if (isSubclass(Formal, OptionalMatchClass)) {\n"; in run()
3755 OS << " OptionalOperandsMask.set(FormalIdx);\n"; in run()
3756 OS << " }\n"; in run()
3757 OS << " }\n"; in run()
3758 OS << " continue;\n"; in run()
3760 OS << " if (Formal == InvalidMatchClass) {\n"; in run()
3762 OS << " OptionalOperandsMask.set(FormalIdx, " << MaxNumOperands in run()
3765 OS << " break;\n"; in run()
3766 OS << " }\n"; in run()
3767 OS << " if (isSubclass(Formal, OptionalMatchClass)) {\n"; in run()
3769 OS << " OptionalOperandsMask.set(FormalIdx);\n"; in run()
3771 OS << " continue;\n"; in run()
3772 OS << " }\n"; in run()
3773 OS << " OperandsValid = false;\n"; in run()
3774 OS << " ErrorInfo = ActualIdx;\n"; in run()
3775 OS << " break;\n"; in run()
3777 OS << " }\n"; in run()
3778 OS << " MCParsedAsmOperand &Actual = *Operands[ActualIdx];\n"; in run()
3779 OS << " unsigned Diag = validateOperandClass(Actual, Formal);\n"; in run()
3780 OS << " if (Diag == Match_Success) {\n"; in run()
3781 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3782 OS << " dbgs() << \"match success using generic " in run()
3784 OS << " ++ActualIdx;\n"; in run()
3785 OS << " continue;\n"; in run()
3786 OS << " }\n"; in run()
3787 OS << " // If the generic handler indicates an invalid operand\n"; in run()
3788 OS << " // failure, check for a special case.\n"; in run()
3789 OS << " if (Diag != Match_Success) {\n"; in run()
3790 OS << " unsigned TargetDiag = validateTargetOperandClass(Actual, " in run()
3792 OS << " if (TargetDiag == Match_Success) {\n"; in run()
3793 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3794 OS << " dbgs() << \"match success using target " in run()
3796 OS << " ++ActualIdx;\n"; in run()
3797 OS << " continue;\n"; in run()
3798 OS << " }\n"; in run()
3799 OS << " // If the target matcher returned a specific error code use\n"; in run()
3800 OS << " // that, else use the one from the generic matcher.\n"; in run()
3801 OS << " if (TargetDiag != Match_InvalidOperand && " in run()
3803 OS << " Diag = TargetDiag;\n"; in run()
3804 OS << " }\n"; in run()
3805 OS << " // If current formal operand wasn't matched and it is optional\n" in run()
3807 OS << " if (Diag == Match_InvalidOperand " in run()
3810 OS << " OptionalOperandsMask.set(FormalIdx);\n"; in run()
3812 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"ignoring " in run()
3814 OS << " continue;\n"; in run()
3815 OS << " }\n"; in run()
3818 OS << " if (!OperandNearMiss) {\n"; in run()
3819 OS << " // If this is the first invalid operand we have seen, " in run()
3821 OS << " // information about it.\n"; in run()
3822 OS << " DEBUG_WITH_TYPE(\n"; in run()
3823 OS << " \"asm-matcher\",\n"; in run()
3824 OS << " dbgs()\n"; in run()
3825 OS << " << \"operand match failed, recording near-miss with " in run()
3827 OS << " << Diag << \"\\n\");\n"; in run()
3828 OS << " OperandNearMiss =\n"; in run()
3829 OS << " NearMissInfo::getMissedOperand(Diag, Formal, " in run()
3831 OS << " ++ActualIdx;\n"; in run()
3832 OS << " } else {\n"; in run()
3833 OS << " // If more than one operand is invalid, give up on this " in run()
3835 OS << " DEBUG_WITH_TYPE(\n"; in run()
3836 OS << " \"asm-matcher\",\n"; in run()
3837 OS << " dbgs() << \"second operand mismatch, skipping this " in run()
3839 OS << " MultipleInvalidOperands = true;\n"; in run()
3840 OS << " break;\n"; in run()
3841 OS << " }\n"; in run()
3842 OS << " }\n\n"; in run()
3844 OS << " // If this operand is broken for all of the instances of " in run()
3846 OS << " // mnemonic, keep track of it so we can report loc info.\n"; in run()
3847 OS << " // If we already had a match that only failed due to a\n"; in run()
3848 OS << " // target predicate, that diagnostic is preferred.\n"; in run()
3849 OS << " if (!HadMatchOtherThanPredicate &&\n"; in run()
3850 OS << " (it == MnemonicRange.first || ErrorInfo <= ActualIdx)) " in run()
3852 OS << " if (HasRequiredFeatures && (ErrorInfo != ActualIdx || Diag " in run()
3854 OS << " RetCode = Diag;\n"; in run()
3855 OS << " ErrorInfo = ActualIdx;\n"; in run()
3856 OS << " }\n"; in run()
3857 OS << " // Otherwise, just reject this instance of the mnemonic.\n"; in run()
3858 OS << " OperandsValid = false;\n"; in run()
3859 OS << " break;\n"; in run()
3860 OS << " }\n\n"; in run()
3864 OS << " if (MultipleInvalidOperands) {\n"; in run()
3866 OS << " if (!OperandsValid) {\n"; in run()
3867 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: " in run()
3869 OS << " \"operand mismatches, " in run()
3871 OS << " \"this opcode\\n\");\n"; in run()
3872 OS << " continue;\n"; in run()
3873 OS << " }\n"; in run()
3876 OS << " if (!HasRequiredFeatures) {\n"; in run()
3878 OS << " HadMatchOtherThanFeatures = true;\n"; in run()
3879 OS << " FeatureBitset NewMissingFeatures = RequiredFeatures & " in run()
3881 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Missing target " in run()
3883 OS << " for (unsigned I = 0, E = " in run()
3885 OS << " if (NewMissingFeatures[I])\n"; in run()
3886 OS << " dbgs() << ' ' << I;\n"; in run()
3887 OS << " dbgs() << \"\\n\");\n"; in run()
3889 OS << " FeaturesNearMiss = " in run()
3892 OS << " if (NewMissingFeatures.count() <=\n" in run()
3894 OS << " MissingFeatures = NewMissingFeatures;\n"; in run()
3895 OS << " continue;\n"; in run()
3897 OS << " }\n"; in run()
3898 OS << "\n"; in run()
3899 OS << " Inst.clear();\n\n"; in run()
3900 OS << " Inst.setOpcode(it->Opcode);\n"; in run()
3902 OS << " // We have a potential match but have not rendered the operands.\n" in run()
3913 OS << " DEBUG_WITH_TYPE(\n"; in run()
3914 OS << " \"asm-matcher\",\n"; in run()
3915 OS << " dbgs() << \"Early target match predicate failed with diag " in run()
3917 OS << " << MatchResult << \"\\n\");\n"; in run()
3919 OS << " EarlyPredicateNearMiss = " in run()
3922 OS << " RetCode = MatchResult;\n" in run()
3926 OS << " }\n\n"; in run()
3929 OS << " // If we did not successfully match the operands, then we can't " in run()
3931 OS << " // an MCInst, so bail out on this instruction variant now.\n"; in run()
3932 OS << " if (OperandNearMiss) {\n"; in run()
3933 OS << " // If the operand mismatch was the only problem, reprrt it as " in run()
3935 OS << " if (NearMisses && !FeaturesNearMiss && " in run()
3937 OS << " DEBUG_WITH_TYPE(\n"; in run()
3938 OS << " \"asm-matcher\",\n"; in run()
3939 OS << " dbgs()\n"; in run()
3940 OS << " << \"Opcode result: one mismatched operand, adding " in run()
3942 OS << " NearMisses->push_back(OperandNearMiss);\n"; in run()
3943 OS << " } else {\n"; in run()
3944 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: " in run()
3946 OS << " \"types of " in run()
3948 OS << " \"reporting " in run()
3950 OS << " }\n"; in run()
3951 OS << " continue;\n"; in run()
3952 OS << " }\n\n"; in run()
3964 OS << " unsigned DefaultsOffset[" << (MaxNumOperands + 1) in run()
3966 OS << " assert(OptionalOperandsMask.size() == " << (MaxNumOperands) in run()
3968 OS << " for (unsigned i = 0, NumDefaults = 0; i < " << (MaxNumOperands) in run()
3970 OS << " DefaultsOffset[i + 1] = NumDefaults;\n"; in run()
3971 OS << " NumDefaults += (OptionalOperandsMask[i] ? 1 : 0);\n"; in run()
3972 OS << " }\n\n"; in run()
3975 OS << " if (matchingInlineAsm) {\n"; in run()
3976 OS << " convertToMapAndConstraints(it->ConvertFn, Operands);\n"; in run()
3979 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
3981 OS << " DefaultsOffset, " in run()
3984 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
3986 OS << " ErrorInfo))\n"; in run()
3988 OS << " return Match_InvalidTiedOperand;\n"; in run()
3989 OS << "\n"; in run()
3991 OS << " return Match_Success;\n"; in run()
3992 OS << " }\n\n"; in run()
3993 OS << " // We have selected a definite instruction, convert the parsed\n" in run()
3996 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands,\n" in run()
3999 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n"; in run()
4001 OS << "\n"; in run()
4004 OS << " // We have a potential match. Check the target predicate to\n" in run()
4014 OS << " LatePredicateNearMiss = " in run()
4017 OS << " RetCode = MatchResult;\n" in run()
4021 OS << " }\n\n"; in run()
4024 OS << " int NumNearMisses = ((int)(bool)OperandNearMiss +\n"; in run()
4025 OS << " (int)(bool)FeaturesNearMiss +\n"; in run()
4026 OS << " (int)(bool)EarlyPredicateNearMiss +\n"; in run()
4027 OS << " (int)(bool)LatePredicateNearMiss);\n"; in run()
4028 OS << " if (NumNearMisses == 1) {\n"; in run()
4029 OS << " // We had exactly one type of near-miss, so add that to the " in run()
4031 OS << " assert(!OperandNearMiss && \"OperandNearMiss was handled " in run()
4033 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: " in run()
4035 OS << " \"mismatch, so " in run()
4037 OS << " \"near-miss\\n\");\n"; in run()
4038 OS << " if (NearMisses && FeaturesNearMiss)\n"; in run()
4039 OS << " NearMisses->push_back(FeaturesNearMiss);\n"; in run()
4040 OS << " else if (NearMisses && EarlyPredicateNearMiss)\n"; in run()
4041 OS << " NearMisses->push_back(EarlyPredicateNearMiss);\n"; in run()
4042 OS << " else if (NearMisses && LatePredicateNearMiss)\n"; in run()
4043 OS << " NearMisses->push_back(LatePredicateNearMiss);\n"; in run()
4044 OS << "\n"; in run()
4045 OS << " continue;\n"; in run()
4046 OS << " } else if (NumNearMisses > 1) {\n"; in run()
4047 OS << " // This instruction missed in more than one way, so ignore " in run()
4049 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: " in run()
4051 OS << " \"types of mismatch, " in run()
4053 OS << " \"reporting " in run()
4055 OS << " continue;\n"; in run()
4056 OS << " }\n"; in run()
4062 OS << " " << InsnCleanupFn << "(Inst);\n"; in run()
4065 OS << " std::string Info;\n"; in run()
4066 OS << " if " in run()
4069 OS << " MII.getDeprecatedInfo(Inst, getSTI(), Info)) {\n"; in run()
4070 OS << " SMLoc Loc = ((" << Target.getName() in run()
4072 OS << " getParser().Warning(Loc, Info, std::nullopt);\n"; in run()
4073 OS << " }\n"; in run()
4078 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
4080 OS << " DefaultsOffset, " in run()
4083 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
4085 OS << " ErrorInfo))\n"; in run()
4087 OS << " return Match_InvalidTiedOperand;\n"; in run()
4088 OS << "\n"; in run()
4091 OS << " DEBUG_WITH_TYPE(\n"; in run()
4092 OS << " \"asm-matcher\",\n"; in run()
4093 OS << " dbgs() << \"Opcode result: complete match, selecting this " in run()
4095 OS << " return Match_Success;\n"; in run()
4096 OS << " }\n\n"; in run()
4099 OS << " // No instruction variants matched exactly.\n"; in run()
4100 OS << " return Match_NearMisses;\n"; in run()
4102 OS << " // Okay, we had no match. Try to return a useful error code.\n"; in run()
4103 OS << " if (HadMatchOtherThanPredicate || !HadMatchOtherThanFeatures)\n"; in run()
4104 OS << " return RetCode;\n\n"; in run()
4105 OS << " ErrorInfo = 0;\n"; in run()
4106 OS << " return Match_MissingFeature;\n"; in run()
4108 OS << "}\n\n"; in run()
4111 emitCustomOperandParsing(OS, Target, Info, ClassName, StringTable, in run()
4115 OS << "#endif // GET_MATCHER_IMPLEMENTATION\n\n"; in run()
4117 OS << "\n#ifdef GET_MNEMONIC_SPELL_CHECKER\n"; in run()
4118 OS << "#undef GET_MNEMONIC_SPELL_CHECKER\n\n"; in run()
4120 emitMnemonicSpellChecker(OS, Target, VariantCount); in run()
4122 OS << "#endif // GET_MNEMONIC_SPELL_CHECKER\n\n"; in run()
4124 OS << "\n#ifdef GET_MNEMONIC_CHECKER\n"; in run()
4125 OS << "#undef GET_MNEMONIC_CHECKER\n\n"; in run()
4127 emitMnemonicChecker(OS, Target, VariantCount, HasMnemonicFirst, in run()
4130 OS << "#endif // GET_MNEMONIC_CHECKER\n\n"; in run()