Skip to content

Commit dd3edc8

Browse files
authored
[CodeGen] Add Register::stackSlotIndex(). Replace uses of Register::stackSlot2Index. NFC (#125028)
1 parent 7fd8426 commit dd3edc8

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

llvm/include/llvm/CodeGen/Register.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ class Register {
9898
/// register in a function will get the index 0.
9999
unsigned virtRegIndex() const { return virtReg2Index(Reg); }
100100

101+
/// Compute the frame index from a register value representing a stack slot.
102+
int stackSlotIndex() const {
103+
assert(isStack() && "Not a stack slot");
104+
return static_cast<int>(Reg - MCRegister::FirstStackSlot);
105+
}
106+
101107
constexpr operator unsigned() const { return Reg; }
102108

103109
constexpr unsigned id() const { return Reg; }

llvm/lib/CodeGen/ReachingDefAnalysis.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, Register Reg) const {
346346
"Unexpected basic block number.");
347347
int LatestDef = ReachingDefDefaultVal;
348348

349-
if (Register::isStackSlot(Reg)) {
350-
int FrameIndex = Register::stackSlot2Index(Reg);
349+
if (Reg.isStack()) {
350+
int FrameIndex = Reg.stackSlotIndex();
351351
for (int Def : MBBFrameObjsReachingDefs.lookup(MBBNumber).lookup(
352352
FrameIndex - ObjectIndexBegin)) {
353353
if (Def >= InstId)
@@ -617,8 +617,8 @@ MachineInstr *ReachingDefAnalysis::getLocalLiveOutMIDef(MachineBasicBlock *MBB,
617617
if (Last == MBB->end())
618618
return nullptr;
619619

620-
if (Register::isStackSlot(Reg)) {
621-
int FrameIndex = Register::stackSlot2Index(Reg);
620+
if (Reg.isStack()) {
621+
int FrameIndex = Reg.stackSlotIndex();
622622
if (isFIDef(*Last, FrameIndex, TII))
623623
return &*Last;
624624
}

llvm/lib/CodeGen/StackSlotColoring.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void StackSlotColoring::InitializeSlots() {
266266
for (auto *I : Intervals) {
267267
LiveInterval &li = I->second;
268268
LLVM_DEBUG(li.dump());
269-
int FI = Register::stackSlot2Index(li.reg());
269+
int FI = li.reg().stackSlotIndex();
270270
if (MFI->isDeadObjectIndex(FI))
271271
continue;
272272

@@ -300,7 +300,7 @@ void StackSlotColoring::InitializeSlots() {
300300
int StackSlotColoring::ColorSlot(LiveInterval *li) {
301301
int Color = -1;
302302
bool Share = false;
303-
int FI = Register::stackSlot2Index(li->reg());
303+
int FI = li->reg().stackSlotIndex();
304304
uint8_t StackID = MFI->getStackID(FI);
305305

306306
if (!DisableSharing) {
@@ -361,7 +361,7 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
361361
LLVM_DEBUG(dbgs() << "Color spill slot intervals:\n");
362362
bool Changed = false;
363363
for (LiveInterval *li : SSIntervals) {
364-
int SS = Register::stackSlot2Index(li->reg());
364+
int SS = li->reg().stackSlotIndex();
365365
int NewSS = ColorSlot(li);
366366
assert(NewSS >= 0 && "Stack coloring failed?");
367367
SlotMapping[SS] = NewSS;
@@ -373,7 +373,7 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
373373

374374
LLVM_DEBUG(dbgs() << "\nSpill slots after coloring:\n");
375375
for (LiveInterval *li : SSIntervals) {
376-
int SS = Register::stackSlot2Index(li->reg());
376+
int SS = li->reg().stackSlotIndex();
377377
li->setWeight(SlotWeights[SS]);
378378
}
379379
// Sort them by new weight.

llvm/lib/CodeGen/TargetRegisterInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ Printable printReg(Register Reg, const TargetRegisterInfo *TRI,
109109
return Printable([Reg, TRI, SubIdx, MRI](raw_ostream &OS) {
110110
if (!Reg)
111111
OS << "$noreg";
112-
else if (Register::isStackSlot(Reg))
113-
OS << "SS#" << Register::stackSlot2Index(Reg);
112+
else if (Reg.isStack())
113+
OS << "SS#" << Reg.stackSlotIndex();
114114
else if (Reg.isVirtual()) {
115115
StringRef Name = MRI ? MRI->getVRegName(Reg) : "";
116116
if (Name != "") {
117117
OS << '%' << Name;
118118
} else {
119-
OS << '%' << Register::virtReg2Index(Reg);
119+
OS << '%' << Reg.virtRegIndex();
120120
}
121121
} else if (!TRI)
122122
OS << '$' << "physreg" << Reg.id();

llvm/lib/Target/AMDGPU/AMDGPUMarkLastScratchLoad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool AMDGPUMarkLastScratchLoad::runOnMachineFunction(MachineFunction &MF) {
8888
if (Segment.end.isBlock())
8989
continue;
9090

91-
const int FrameIndex = Register::stackSlot2Index(LI.reg());
91+
const int FrameIndex = LI.reg().stackSlotIndex();
9292
MachineInstr *LastLoad = nullptr;
9393

9494
MachineInstr *MISegmentEnd = SI->getInstructionFromIndex(Segment.end);

llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ namespace {
253253
/*Kill*/false, /*Dead*/false, /*Undef*/false,
254254
/*EarlyClobber*/false, Sub);
255255
if (Reg.isStack()) {
256-
int FI = llvm::Register::stackSlot2Index(Reg);
256+
int FI = Reg.stackSlotIndex();
257257
return MachineOperand::CreateFI(FI);
258258
}
259259
llvm_unreachable("Cannot create MachineOperand");
@@ -1148,8 +1148,8 @@ void HCE::recordExtender(MachineInstr &MI, unsigned OpNum) {
11481148
bool IsStore = MI.mayStore();
11491149

11501150
// Fixed stack slots have negative indexes, and they cannot be used
1151-
// with TRI::stackSlot2Index and TRI::index2StackSlot. This is somewhat
1152-
// unfortunate, but should not be a frequent thing.
1151+
// with Register::stackSlotIndex and Register::index2StackSlot. This is
1152+
// somewhat unfortunate, but should not be a frequent thing.
11531153
for (MachineOperand &Op : MI.operands())
11541154
if (Op.isFI() && Op.getIndex() < 0)
11551155
return;

0 commit comments

Comments
 (0)