[llvm] [llvm-dwarfdump] Decode the virtual register names from the dwarf register numbers (PR #192353)
Scott Linder via llvm-commits
llvm-commits at lists.llvm.org
Mon May 4 13:49:32 PDT 2026
================
@@ -23,6 +24,57 @@ namespace llvm {
typedef DWARFExpression::Operation Op;
typedef Op::Description Desc;
+/// Some backends (e.g. NVPTX) encode virtual register names as the DWARF
+/// register number: the ASCII bytes of the name are concatenated into a
+/// uint64_t (see NVPTXRegisterInfo::encodeRegisterForDwarf). When the object
+/// file is not the target backend, MCRegisterInfo cannot map these numbers, so
+/// recover the string for dumping.
+static bool decodeVirtualRegisterName(uint64_t DwarfRegNum,
+ SmallString<32> &Out) {
+ if (DwarfRegNum == 0)
+ return false;
+
+ SmallString<32> Tmp;
+ for (uint64_t V = DwarfRegNum; V; V >>= 8)
+ Tmp.push_back(static_cast<char>(V & 0xFF));
+
+ // Encoding builds the uint64_t as (result << 8) | byte per character (MSB of
+ // the value is the first character). Unpacking with >>= 8 yields bytes LSB
+ // first, so reverse to restore the original register name (e.g. %rd2).
+ std::reverse(Tmp.begin(), Tmp.end());
+
+ if (Tmp.empty() || Tmp.size() < 2)
+ return false;
----------------
slinder1 wrote:
```suggestion
if (Tmp.size() < 2)
return false;
```
https://github.com/llvm/llvm-project/pull/192353
More information about the llvm-commits
mailing list