Question about setting the dialect in AsmPrinterInlineAsm.cpp

Hi All,

While processing an inline asm block, within AsmPrinterInlineAsm.cpp, the inline asm dialect is forcibly set by the AsmParser instance (within the emitInlineAsm function)

void AsmPrinter::emitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
                               const MCTargetOptions &MCOptions,
                               const MDNode *LocMDNode,
                               InlineAsm::AsmDialect Dialect) const {
  Parser->setAssemblerDialect(Dialect); // —> SETTING DIALECT HERE

Because of setting the inline asm dialect in AsmPrinterInlineAsm.cpp, any queries to the overridden getAssemblerDialect method elsewhere, will return the set dialect, and not the assembler dialect in the MachineAsmInfo.

My question is, is this strictly necessary? EmitGCCInlineAsmStr and EmitMSInlineAsmStr is already set up to deal with gnu and intel inline asm flavours. Within the EmitMSInlineAsmStr, the .intel_syntax directive is also explicitly emitted. Couldn't we do away with setting the inline asm dialect in AsmPrinterInlineAsm.cpp (and subsequently change the overridden getAssemblerDialect method to just return the MCAsmInfo's version of the assembler dialect?) Are there any other use case(s) as to why it is being set?

Because otherwise, if we introduce another assembler dialect/variant, within the Target's respective MCAsmInfo instance (a variant which might be based off the standard two inline asm dialects), and we want to make use of it in the (Target)AsmParser, we would have to explicitly query the MCAsmInfo to get its version of the assembler dialect field (for any reasons we might need it). I'm not too "sure" if this is the correct way to go about it.


Best Regards,
Anirudh Prasad