[RISCV] Use TypeSize instead of uint64_t in getMachineMemOperand interface (#133274)

The primary reason is that if you pass a TypeSize without explicitly
converting to LocationSize, you otherwise implicit convert to uint64_t
to call the respective LocationSize constructor. This means that any
scalable value becomes a runtime assertion failure.

By replacing uint64_t with TypeSize in this API, we avoid the implicit
conversion for TypeSize. uint64_t callers implicit convert to
LocationSize (via the raw constructor) which should have unchanged
behavior.
This commit is contained in:
Philip Reames
2025-03-27 11:04:00 -07:00
committed by GitHub
parent aa207c3f05
commit d584cea064
2 changed files with 5 additions and 9 deletions

View File

@@ -1073,7 +1073,7 @@ public:
AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic);
MachineMemOperand *getMachineMemOperand(
MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, uint64_t Size,
MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, TypeSize Size,
Align BaseAlignment, const AAMDNodes &AAInfo = AAMDNodes(),
const MDNode *Ranges = nullptr, SyncScope::ID SSID = SyncScope::System,
AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
@@ -1099,7 +1099,7 @@ public:
: LLT::scalar(8 * Size.getValue().getKnownMinValue()));
}
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
int64_t Offset, uint64_t Size) {
int64_t Offset, TypeSize Size) {
return getMachineMemOperand(MMO, Offset, LocationSize::precise(Size));
}
@@ -1115,7 +1115,7 @@ public:
LLT Ty);
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
const MachinePointerInfo &PtrInfo,
uint64_t Size) {
TypeSize Size) {
return getMachineMemOperand(MMO, PtrInfo, LocationSize::precise(Size));
}

View File

@@ -705,11 +705,9 @@ void RISCVInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
llvm_unreachable("Can't store this register to stack slot");
if (IsScalableVector) {
LocationSize LocSize =
LocationSize::precise(TypeSize::getScalable(MFI.getObjectSize(FI)));
MachineMemOperand *MMO = MF->getMachineMemOperand(
MachinePointerInfo::getFixedStack(*MF, FI), MachineMemOperand::MOStore,
LocSize, MFI.getObjectAlign(FI));
TypeSize::getScalable(MFI.getObjectSize(FI)), MFI.getObjectAlign(FI));
MFI.setStackID(FI, TargetStackID::ScalableVector);
BuildMI(MBB, I, DebugLoc(), get(Opcode))
@@ -799,11 +797,9 @@ void RISCVInstrInfo::loadRegFromStackSlot(
llvm_unreachable("Can't load this register from stack slot");
if (IsScalableVector) {
LocationSize LocSize =
LocationSize::precise(TypeSize::getScalable(MFI.getObjectSize(FI)));
MachineMemOperand *MMO = MF->getMachineMemOperand(
MachinePointerInfo::getFixedStack(*MF, FI), MachineMemOperand::MOLoad,
LocSize, MFI.getObjectAlign(FI));
TypeSize::getScalable(MFI.getObjectSize(FI)), MFI.getObjectAlign(FI));
MFI.setStackID(FI, TargetStackID::ScalableVector);
BuildMI(MBB, I, DL, get(Opcode), DstReg)