-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm] use 64-bit types for result of getDwarfRegNum (NFC) #109494
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ unsigned MCRegisterInfo::getSubRegIndex(MCRegister Reg, | |
return 0; | ||
} | ||
|
||
int MCRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const { | ||
int64_t MCRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const { | ||
const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs; | ||
unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize; | ||
|
||
|
@@ -151,24 +151,28 @@ int MCRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const { | |
const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key); | ||
if (I == M+Size || I->FromReg != RegNum) | ||
return -1; | ||
return I->ToReg; | ||
// Consumers need to be able to detect -1 and -2, but at various points | ||
// the numbers move between unsigned and signed representations, as well as | ||
// between 32- and 64-bit representations. We need to convert first to int | ||
// before int64_t for proper sign handling. | ||
return int64_t(int(I->ToReg)); | ||
} | ||
|
||
std::optional<MCRegister> MCRegisterInfo::getLLVMRegNum(unsigned RegNum, | ||
std::optional<MCRegister> MCRegisterInfo::getLLVMRegNum(uint64_t RegNum, | ||
bool isEH) const { | ||
const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs; | ||
unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize; | ||
|
||
if (!M) | ||
return std::nullopt; | ||
DwarfLLVMRegPair Key = { RegNum, 0 }; | ||
DwarfLLVMRegPair Key = {unsigned(RegNum), 0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't it be better to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I originally tried to do a broader switch to 64-bit types for registers, but it caused many problems. There are various places in code generation where registers are not just treated as 32-bit numbers, but also treat certain bit offsets as flags. So I limited the change as much as possible to just the output of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oof. Got it. Please mention this in the commit description for posterity. |
||
const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key); | ||
if (I != M + Size && I->FromReg == RegNum) | ||
return MCRegister::from(I->ToReg); | ||
return std::nullopt; | ||
} | ||
|
||
int MCRegisterInfo::getDwarfRegNumFromDwarfEHRegNum(unsigned RegNum) const { | ||
int64_t MCRegisterInfo::getDwarfRegNumFromDwarfEHRegNum(uint64_t RegNum) const { | ||
// On ELF platforms, DWARF EH register numbers are the same as DWARF | ||
// other register numbers. On Darwin x86, they differ and so need to be | ||
// mapped. The .cfi_* directives accept integer literals as well as | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,6 @@ struct LanaiRegisterInfo : public LanaiGenRegisterInfo { | |
Register getFrameRegister(const MachineFunction &MF) const override; | ||
Register getBaseRegister() const; | ||
bool hasBasePointer(const MachineFunction &MF) const; | ||
|
||
int getDwarfRegNum(unsigned RegNum, bool IsEH) const; | ||
Comment on lines
-46
to
-47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It caused errors when I switched There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries. What you say makes sense. |
||
}; | ||
|
||
} // end namespace llvm | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about doing the following:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be good. I'm not certain there are not other negative values currently being used as signal values, but if that switch passes the tests then it's probably fine. I'm not certain that's necessarily better, though. But I'm fine with either implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, what about
int64_t(int32_t(I->ToReg))
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the existing code dealing with these register numbers uses the types
int
andunsigned
. Theint64_t(int(I->ToReg))
conversion seems more consistent with other usage thanint64_t(int32_t(I->ToReg))
.