Skip to content

[Codegen] Change getSpillSize/getReloadSize to LocationSize. NFC #82636

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 25, 2024
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
10 changes: 6 additions & 4 deletions llvm/include/llvm/CodeGen/MachineInstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/TargetOpcodes.h"
Expand Down Expand Up @@ -1744,16 +1745,17 @@ class MachineInstr
bool allImplicitDefsAreDead() const;

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

/// Return a valid size if the instruction is a folded spill instruction.
std::optional<unsigned> getFoldedSpillSize(const TargetInstrInfo *TII) const;
std::optional<LocationSize>
getFoldedSpillSize(const TargetInstrInfo *TII) const;

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

/// Return a valid size if the instruction is a folded restore instruction.
std::optional<unsigned>
std::optional<LocationSize>
getFoldedRestoreSize(const TargetInstrInfo *TII) const;

/// Copy implicit register operands from specified
Expand Down
26 changes: 11 additions & 15 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,25 +1106,21 @@ static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS) {

// We assume a single instruction only has a spill or reload, not
// both.
std::optional<unsigned> Size;
std::optional<LocationSize> Size;
if ((Size = MI.getRestoreSize(TII))) {
CommentOS << *Size << "-byte Reload\n";
CommentOS << Size->getValue() << "-byte Reload\n";
} else if ((Size = MI.getFoldedRestoreSize(TII))) {
if (*Size) {
if (*Size == unsigned(MemoryLocation::UnknownSize))
CommentOS << "Unknown-size Folded Reload\n";
else
CommentOS << *Size << "-byte Folded Reload\n";
}
if (!Size->hasValue())
CommentOS << "Unknown-size Folded Reload\n";
else if (Size->getValue())
CommentOS << Size->getValue() << "-byte Folded Reload\n";
} else if ((Size = MI.getSpillSize(TII))) {
CommentOS << *Size << "-byte Spill\n";
CommentOS << Size->getValue() << "-byte Spill\n";
} else if ((Size = MI.getFoldedSpillSize(TII))) {
if (*Size) {
if (*Size == unsigned(MemoryLocation::UnknownSize))
CommentOS << "Unknown-size Folded Spill\n";
else
CommentOS << *Size << "-byte Folded Spill\n";
}
if (!Size->hasValue())
CommentOS << "Unknown-size Folded Spill\n";
else if (Size->getValue())
CommentOS << Size->getValue() << "-byte Folded Spill\n";
}

// Check for spill-induced copies
Expand Down
34 changes: 21 additions & 13 deletions llvm/lib/CodeGen/MachineInstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2354,48 +2354,56 @@ void MachineInstr::changeDebugValuesDefReg(Register Reg) {

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

static unsigned getSpillSlotSize(const MMOList &Accesses,
const MachineFrameInfo &MFI) {
unsigned Size = 0;
static LocationSize getSpillSlotSize(const MMOList &Accesses,
const MachineFrameInfo &MFI) {
uint64_t Size = 0;
for (const auto *A : Accesses)
if (MFI.isSpillSlotObjectIndex(
cast<FixedStackPseudoSourceValue>(A->getPseudoValue())
->getFrameIndex()))
Size += A->getSize();
->getFrameIndex())) {
uint64_t S = A->getSize();
if (S == ~UINT64_C(0))
return LocationSize::beforeOrAfterPointer();
Size += S;
}
return Size;
}

std::optional<unsigned>
std::optional<LocationSize>
MachineInstr::getSpillSize(const TargetInstrInfo *TII) const {
int FI;
if (TII->isStoreToStackSlotPostFE(*this, FI)) {
const MachineFrameInfo &MFI = getMF()->getFrameInfo();
if (MFI.isSpillSlotObjectIndex(FI))
return (*memoperands_begin())->getSize();
if (MFI.isSpillSlotObjectIndex(FI)) {
uint64_t Size = (*memoperands_begin())->getSize();
return Size == ~UINT64_C(0) ? LocationSize::beforeOrAfterPointer() : Size;
}
}
return std::nullopt;
}

std::optional<unsigned>
std::optional<LocationSize>
MachineInstr::getFoldedSpillSize(const TargetInstrInfo *TII) const {
MMOList Accesses;
if (TII->hasStoreToStackSlot(*this, Accesses))
return getSpillSlotSize(Accesses, getMF()->getFrameInfo());
return std::nullopt;
}

std::optional<unsigned>
std::optional<LocationSize>
MachineInstr::getRestoreSize(const TargetInstrInfo *TII) const {
int FI;
if (TII->isLoadFromStackSlotPostFE(*this, FI)) {
const MachineFrameInfo &MFI = getMF()->getFrameInfo();
if (MFI.isSpillSlotObjectIndex(FI))
return (*memoperands_begin())->getSize();
if (MFI.isSpillSlotObjectIndex(FI)) {
uint64_t Size = (*memoperands_begin())->getSize();
return Size == ~UINT64_C(0) ? LocationSize::beforeOrAfterPointer() : Size;
}
}
return std::nullopt;
}

std::optional<unsigned>
std::optional<LocationSize>
MachineInstr::getFoldedRestoreSize(const TargetInstrInfo *TII) const {
MMOList Accesses;
if (TII->hasLoadFromStackSlot(*this, Accesses))
Expand Down