Skip to content

[CodeGen][NVPTX] Add a TRI function get the Dwarf register number for a virtual register. #129017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,10 @@ class TargetRegisterInfo : public MCRegisterInfo {
prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags,
const StackOffset &Offset) const;

virtual int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const {
llvm_unreachable("getDwarfRegNumForVirtReg does not exist on this target");
}

/// Spill the register so it can be used by the register scavenger.
/// Return true if the register was spilled, false otherwise.
/// If this function does not spill the register, the scavenger
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,
return true;
}
// Try getting dwarf register for virtual register anyway, eg. for NVPTX.
int64_t Reg = TRI.getDwarfRegNum(MachineReg, false);
int64_t Reg = TRI.getDwarfRegNumForVirtReg(MachineReg, false);
if (Reg > 0) {
DwarfRegs.push_back(Register::createRegister(Reg, nullptr));
return true;
Expand Down
21 changes: 12 additions & 9 deletions llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,18 @@ void NVPTXRegisterInfo::addToDebugRegisterMap(
}

int64_t NVPTXRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const {
if (RegNum.isPhysical()) {
StringRef Name = NVPTXInstPrinter::getRegisterName(RegNum.id());
// In NVPTXFrameLowering.cpp, we do arrange for %Depot to be accessible from
// %SP. Using the %Depot register doesn't provide any debug info in
// cuda-gdb, but switching it to %SP does.
if (RegNum.id() == NVPTX::VRDepot)
Name = "%SP";
return encodeRegisterForDwarf(Name);
}
StringRef Name = NVPTXInstPrinter::getRegisterName(RegNum.id());
// In NVPTXFrameLowering.cpp, we do arrange for %Depot to be accessible from
// %SP. Using the %Depot register doesn't provide any debug info in
// cuda-gdb, but switching it to %SP does.
if (RegNum.id() == NVPTX::VRDepot)
Name = "%SP";
return encodeRegisterForDwarf(Name);
}

int64_t NVPTXRegisterInfo::getDwarfRegNumForVirtReg(Register RegNum,
bool isEH) const {
assert(RegNum.isVirtual());
uint64_t lookup = debugRegisterMap.lookup(RegNum.id());
if (lookup)
return lookup;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/NVPTX/NVPTXRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class NVPTXRegisterInfo : public NVPTXGenRegisterInfo {
StringRef RegisterName) const;
void clearDebugRegisterMap() const;
int64_t getDwarfRegNum(MCRegister RegNum, bool isEH) const override;
int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const override;
};

StringRef getNVPTXRegClassName(const TargetRegisterClass *RC);
Expand Down