[llvm] [ARM][TableGen][MC] Change the ARM mnemonic operands to be optional for ASM parsing (PR #83436)

Alfie Richards via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 06:19:39 PST 2024


================
@@ -1474,7 +1513,7 @@ void AsmMatcherInfo::buildOperandMatchInfo() {
         OperandMask |= maskTrailingOnes<unsigned>(NumOptionalOps + 1)
                        << (i - NumOptionalOps);
       }
-      if (Op.Class->IsOptional)
+      if (Op.Class->IsOptional && Op.Class->OptionalShouldOffsetCustomParsers)
----------------
AlfieRichardsArm wrote:

Yes I'll take a  shot at explaining.

This is addressing the `ParserMethod` functionality for operands, (eg. FPImmOperand was the one causing me issues)
The way this is done is at operand parsing time (`ARMAsmParser::parseOperand` in this case), `MatchOperandParserImpl` uses the Mnemonic and the number of operands in the OperandVector at that point to check if the operand at that index has a custom ParserMethod.

This causes issues when an operand with a custom ParserMethod comes after an optional operand as the index can change and the optional operand resolution isn't done until match time (after this point). This flag is here to say these optional operands will _always_ be populated populate at parse time so that the indexes of the operands with custom parsers can be known. (See ARMAsmParser.cpp:7062 for where we add the optional operands even if not present in tokens and ARMAsmParser.cpp:7158 after parsing where it is optionally removed).

This is a pretty poor solution getting around the fundamental problem that if we want to have operand classes with custom parsers, where the class information is tied to the instruction definition, then parsing needs to be done at match time where the operand tokens and classes are matched up. But this would require a much deeper change to the parsing and matching machinery. 

https://github.com/llvm/llvm-project/pull/83436


More information about the llvm-commits mailing list