The PTX assembler doesn't like dots in symbol names. We have a pass that
fixes this (NVPTXAssignValidGlobalNames - since 264cd4672d), but there's
a pernicious bug in the way debug info is emitted that means this pass
alone won't work properly if it's ever run as part of the codegen
pipeline involving debug info emission.
AsmPrinter::doInitialization collects all metadata and initializes all
the DWARF DIEs that are later emitted after the main module has been
printed. Naturally, doInitialization is executed *before* any of the
other passes contained in the same PassManager execute their
runOnModule functions that may arbitrarily modify the module.
If any of those functions try and modify the module in such a way that
the debuginfo goes out of date, then the debuginfo *will* be out of date
once the AsmPrinter actually gets to finalize printing the debug info.
As far as I can tell: any code that runs in the same PassManager as the
AsmPrinter could result in bad debug info.
I don't see a simple way around this, unless DWARF debug info is
collected and printed a different way - probably during the
runOnModule method. That will be much more disruptive change, so for
now the small (!) hack introduced here sanitizes the symbol names
referred to by the MCSymbolRefExpr that is earlier constructed by the
AsmPrinter's DWARF handler.
N.B. There's the slight possibility that this also introduces a new bug
- sanitized symbol names referred to by the MCExprs may not be of
private linkage, and so may not actually exist. Given that symbols with
dots in them are are already illegal according to ptxas, I don't think
this is a practical issue to worry about.
Since the NVPTXUtilities are now used by the MC layer, I've hoisted them
into their own Utils lib as per ARM and AMDGPU.