Skip to content

Commit 4af2e36

Browse files
authored
[CodeGen][NVPTX] Add a TRI function get the Dwarf register number for a virtual register. (#129017)
NVPTX needs to be able to get the Dwarf register number for a virtual register. The interface we have for this today is on MCRegisterInfo and take a MCRegister argument. It shouldn't be legal to convert a Register containing a virtual register to an MCRegister. This patch adds a getDwarfRegNumForVirtReg function that takes a Register to TRI and splits the NVPTX override of getDwarfRegNum.
1 parent 79a28aa commit 4af2e36

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,10 @@ class TargetRegisterInfo : public MCRegisterInfo {
11111111
prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags,
11121112
const StackOffset &Offset) const;
11131113

1114+
virtual int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const {
1115+
llvm_unreachable("getDwarfRegNumForVirtReg does not exist on this target");
1116+
}
1117+
11141118
/// Spill the register so it can be used by the register scavenger.
11151119
/// Return true if the register was spilled, false otherwise.
11161120
/// If this function does not spill the register, the scavenger

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,
106106
return true;
107107
}
108108
// Try getting dwarf register for virtual register anyway, eg. for NVPTX.
109-
int64_t Reg = TRI.getDwarfRegNum(MachineReg, false);
109+
int64_t Reg = TRI.getDwarfRegNumForVirtReg(MachineReg, false);
110110
if (Reg > 0) {
111111
DwarfRegs.push_back(Register::createRegister(Reg, nullptr));
112112
return true;

llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,18 @@ void NVPTXRegisterInfo::addToDebugRegisterMap(
170170
}
171171

172172
int64_t NVPTXRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const {
173-
if (RegNum.isPhysical()) {
174-
StringRef Name = NVPTXInstPrinter::getRegisterName(RegNum.id());
175-
// In NVPTXFrameLowering.cpp, we do arrange for %Depot to be accessible from
176-
// %SP. Using the %Depot register doesn't provide any debug info in
177-
// cuda-gdb, but switching it to %SP does.
178-
if (RegNum.id() == NVPTX::VRDepot)
179-
Name = "%SP";
180-
return encodeRegisterForDwarf(Name);
181-
}
173+
StringRef Name = NVPTXInstPrinter::getRegisterName(RegNum.id());
174+
// In NVPTXFrameLowering.cpp, we do arrange for %Depot to be accessible from
175+
// %SP. Using the %Depot register doesn't provide any debug info in
176+
// cuda-gdb, but switching it to %SP does.
177+
if (RegNum.id() == NVPTX::VRDepot)
178+
Name = "%SP";
179+
return encodeRegisterForDwarf(Name);
180+
}
181+
182+
int64_t NVPTXRegisterInfo::getDwarfRegNumForVirtReg(Register RegNum,
183+
bool isEH) const {
184+
assert(RegNum.isVirtual());
182185
uint64_t lookup = debugRegisterMap.lookup(RegNum.id());
183186
if (lookup)
184187
return lookup;

llvm/lib/Target/NVPTX/NVPTXRegisterInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class NVPTXRegisterInfo : public NVPTXGenRegisterInfo {
7272
StringRef RegisterName) const;
7373
void clearDebugRegisterMap() const;
7474
int64_t getDwarfRegNum(MCRegister RegNum, bool isEH) const override;
75+
int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const override;
7576
};
7677

7778
StringRef getNVPTXRegClassName(const TargetRegisterClass *RC);

0 commit comments

Comments
 (0)