Where is `AsmVerbose` or `IsVerboseAsm` set?

I am learning LLVM backend. I would like to enable IsVerboseAsm for AsmPrinter on my new target machine so that I can print comments.

I tried to do this by referring to Target/X86. Because I noticed that on my target machine, IsVerboseAsm is always false, while for X86 it is always true.

However, I could not find any code to configure IsVerboseAsm. I traced it with gdb and found that the source of this data came from a macro under include/clang/Driver/Options.inc generated when LLVM compiled:

CODEGEN_OPTION_WITH_MARSHALLING(prefix_1, &"-fno-verbose-asm"[1], fno_verbose_asm, Flag, f_Group, INVALID, nullptr, CC1Option, 0, nullptr. nullptr, nullptr, "-fno-verbose-asm", true, 0, CodeGenOpts.AsmVerbose, true, false, true, normalizeSimpleNegativeFlag, denormalizeSimpleFlag , mergeForwardValue, extractForwardValue, -1)

Further tracing is unnecessarily complicated for me. On the other hand, I also wonder why it would appear in such a place if this is target-independent code.

So, what keywords should I be looking at so I can know how to enable IsVerboseAsm for the AsmPrinter of the target machine I’m adding? I know I can always write some code to directly set the options in TargetOptions to true, but I’d like to know how other backends do it.

The handling is automatically set for CodeGenOpts under clang/include/llvm/MC/TargetRegistry.h via marshalling callbacks used by llvm::opt::PrecomputedOptTable. The key information is here in clang/lib/Driver/Toolchains/Clang.cpp:

  // Decide whether to use verbose asm. Verbose assembly is the default on
  // toolchains which have the integrated assembler on by default.
  bool IsIntegratedAssemblerDefault = TC.IsIntegratedAssemblerDefault();
  if (!Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
                    IsIntegratedAssemblerDefault))
    CmdArgs.push_back("-fno-verbose-asm");

Under clang -cc1, CodeGenOpts::AsmVerbose is set based on these arguments. That information is then passed MC options in BackendUtil.cpp:

Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;

And finally, it’s used as the IsVerboseAsm argument to createAsmStreamer in llvm/lib/CodeGen/LLVMTargetMachine.cpp:

    MCStreamer *S = getTarget().createAsmStreamer(
        Context, std::move(FOut), Options.MCOptions.AsmVerbose,
        UseDwarfDirectory, InstPrinter, std::move(MCE), std::move(MAB),
        Options.MCOptions.ShowMCInst);

So the backends don’t actually handle it themselves: if a target machine is known to have an integrated assembler in Clang, the default is to have verbose ASM enabled by default.

1 Like