Skip to content

Commit d6ded91

Browse files
authored
[Codegen] Change getSpillSize/getReloadSize to LocationSize. NFC (#82636)
This is a small part of #70452, attempting to take a small simpler part of it in isolation to simplify what remains. It changes the getSpillSize, getFoldedSpillSize, getRestoreSize and getFoldedRestoreSize methods to return optional<LocationSize> instead of unsigned. The code is intended to be the same, keeping the optional<> to specify when there was no size found, with some minor adjustments to make sure that unknown (~UINT64_C(0)) sizes are handled sensibly. Hopefully as more unsigned's are converted to LocationSize's the use of ~UINT64_C(0) can be cleaned up too.
1 parent 2c5a688 commit d6ded91

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/ilist.h"
2121
#include "llvm/ADT/ilist_node.h"
2222
#include "llvm/ADT/iterator_range.h"
23+
#include "llvm/Analysis/MemoryLocation.h"
2324
#include "llvm/CodeGen/MachineMemOperand.h"
2425
#include "llvm/CodeGen/MachineOperand.h"
2526
#include "llvm/CodeGen/TargetOpcodes.h"
@@ -1744,16 +1745,17 @@ class MachineInstr
17441745
bool allImplicitDefsAreDead() const;
17451746

17461747
/// Return a valid size if the instruction is a spill instruction.
1747-
std::optional<unsigned> getSpillSize(const TargetInstrInfo *TII) const;
1748+
std::optional<LocationSize> getSpillSize(const TargetInstrInfo *TII) const;
17481749

17491750
/// Return a valid size if the instruction is a folded spill instruction.
1750-
std::optional<unsigned> getFoldedSpillSize(const TargetInstrInfo *TII) const;
1751+
std::optional<LocationSize>
1752+
getFoldedSpillSize(const TargetInstrInfo *TII) const;
17511753

17521754
/// Return a valid size if the instruction is a restore instruction.
1753-
std::optional<unsigned> getRestoreSize(const TargetInstrInfo *TII) const;
1755+
std::optional<LocationSize> getRestoreSize(const TargetInstrInfo *TII) const;
17541756

17551757
/// Return a valid size if the instruction is a folded restore instruction.
1756-
std::optional<unsigned>
1758+
std::optional<LocationSize>
17571759
getFoldedRestoreSize(const TargetInstrInfo *TII) const;
17581760

17591761
/// Copy implicit register operands from specified

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,25 +1106,21 @@ static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS) {
11061106

11071107
// We assume a single instruction only has a spill or reload, not
11081108
// both.
1109-
std::optional<unsigned> Size;
1109+
std::optional<LocationSize> Size;
11101110
if ((Size = MI.getRestoreSize(TII))) {
1111-
CommentOS << *Size << "-byte Reload\n";
1111+
CommentOS << Size->getValue() << "-byte Reload\n";
11121112
} else if ((Size = MI.getFoldedRestoreSize(TII))) {
1113-
if (*Size) {
1114-
if (*Size == unsigned(MemoryLocation::UnknownSize))
1115-
CommentOS << "Unknown-size Folded Reload\n";
1116-
else
1117-
CommentOS << *Size << "-byte Folded Reload\n";
1118-
}
1113+
if (!Size->hasValue())
1114+
CommentOS << "Unknown-size Folded Reload\n";
1115+
else if (Size->getValue())
1116+
CommentOS << Size->getValue() << "-byte Folded Reload\n";
11191117
} else if ((Size = MI.getSpillSize(TII))) {
1120-
CommentOS << *Size << "-byte Spill\n";
1118+
CommentOS << Size->getValue() << "-byte Spill\n";
11211119
} else if ((Size = MI.getFoldedSpillSize(TII))) {
1122-
if (*Size) {
1123-
if (*Size == unsigned(MemoryLocation::UnknownSize))
1124-
CommentOS << "Unknown-size Folded Spill\n";
1125-
else
1126-
CommentOS << *Size << "-byte Folded Spill\n";
1127-
}
1120+
if (!Size->hasValue())
1121+
CommentOS << "Unknown-size Folded Spill\n";
1122+
else if (Size->getValue())
1123+
CommentOS << Size->getValue() << "-byte Folded Spill\n";
11281124
}
11291125

11301126
// Check for spill-induced copies

llvm/lib/CodeGen/MachineInstr.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,48 +2354,56 @@ void MachineInstr::changeDebugValuesDefReg(Register Reg) {
23542354

23552355
using MMOList = SmallVector<const MachineMemOperand *, 2>;
23562356

2357-
static unsigned getSpillSlotSize(const MMOList &Accesses,
2358-
const MachineFrameInfo &MFI) {
2359-
unsigned Size = 0;
2357+
static LocationSize getSpillSlotSize(const MMOList &Accesses,
2358+
const MachineFrameInfo &MFI) {
2359+
uint64_t Size = 0;
23602360
for (const auto *A : Accesses)
23612361
if (MFI.isSpillSlotObjectIndex(
23622362
cast<FixedStackPseudoSourceValue>(A->getPseudoValue())
2363-
->getFrameIndex()))
2364-
Size += A->getSize();
2363+
->getFrameIndex())) {
2364+
uint64_t S = A->getSize();
2365+
if (S == ~UINT64_C(0))
2366+
return LocationSize::beforeOrAfterPointer();
2367+
Size += S;
2368+
}
23652369
return Size;
23662370
}
23672371

2368-
std::optional<unsigned>
2372+
std::optional<LocationSize>
23692373
MachineInstr::getSpillSize(const TargetInstrInfo *TII) const {
23702374
int FI;
23712375
if (TII->isStoreToStackSlotPostFE(*this, FI)) {
23722376
const MachineFrameInfo &MFI = getMF()->getFrameInfo();
2373-
if (MFI.isSpillSlotObjectIndex(FI))
2374-
return (*memoperands_begin())->getSize();
2377+
if (MFI.isSpillSlotObjectIndex(FI)) {
2378+
uint64_t Size = (*memoperands_begin())->getSize();
2379+
return Size == ~UINT64_C(0) ? LocationSize::beforeOrAfterPointer() : Size;
2380+
}
23752381
}
23762382
return std::nullopt;
23772383
}
23782384

2379-
std::optional<unsigned>
2385+
std::optional<LocationSize>
23802386
MachineInstr::getFoldedSpillSize(const TargetInstrInfo *TII) const {
23812387
MMOList Accesses;
23822388
if (TII->hasStoreToStackSlot(*this, Accesses))
23832389
return getSpillSlotSize(Accesses, getMF()->getFrameInfo());
23842390
return std::nullopt;
23852391
}
23862392

2387-
std::optional<unsigned>
2393+
std::optional<LocationSize>
23882394
MachineInstr::getRestoreSize(const TargetInstrInfo *TII) const {
23892395
int FI;
23902396
if (TII->isLoadFromStackSlotPostFE(*this, FI)) {
23912397
const MachineFrameInfo &MFI = getMF()->getFrameInfo();
2392-
if (MFI.isSpillSlotObjectIndex(FI))
2393-
return (*memoperands_begin())->getSize();
2398+
if (MFI.isSpillSlotObjectIndex(FI)) {
2399+
uint64_t Size = (*memoperands_begin())->getSize();
2400+
return Size == ~UINT64_C(0) ? LocationSize::beforeOrAfterPointer() : Size;
2401+
}
23942402
}
23952403
return std::nullopt;
23962404
}
23972405

2398-
std::optional<unsigned>
2406+
std::optional<LocationSize>
23992407
MachineInstr::getFoldedRestoreSize(const TargetInstrInfo *TII) const {
24002408
MMOList Accesses;
24012409
if (TII->hasLoadFromStackSlot(*this, Accesses))

0 commit comments

Comments
 (0)