aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2023-01-09 09:45:22 -0800
committerCraig Topper <craig.topper@sifive.com>2023-01-09 09:45:22 -0800
commit1153313c334aa0ebe40b26593bd689a779ecaa23 (patch)
tree9bb4fdd185a54eb5f852ec9833d50cd8afac463c /llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
parentb37758356a39bca8bed3d4e83169254b124ac2df (diff)
downloadllvm-1153313c334aa0ebe40b26593bd689a779ecaa23.zip
llvm-1153313c334aa0ebe40b26593bd689a779ecaa23.tar.gz
llvm-1153313c334aa0ebe40b26593bd689a779ecaa23.tar.bz2
[LocalStackSlotAllocation] Minor simplifications. NFC
Instead of maintaining a separate valid flag for BaseReg, Use BaseReg.isValid(). I think this is left over from an older implementation that maintained a vector of base registers. The other change is not do a speculative assignment to BaseOffset that needs to be reverted. Only commit it after we do the check. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D141153
Diffstat (limited to 'llvm/lib/CodeGen/LocalStackSlotAllocation.cpp')
-rw-r--r--llvm/lib/CodeGen/LocalStackSlotAllocation.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
index 5f54d7c..e491ed1 100644
--- a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
+++ b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
@@ -288,7 +288,6 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
// stack frame. If it wants one, re-use a suitable one we've previously
// allocated, or if there isn't one that fits the bill, allocate a new one
// and ask the target to create a defining instruction for it.
- bool UsedBaseReg = false;
MachineFrameInfo &MFI = Fn.getFrameInfo();
const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
@@ -386,7 +385,7 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
// instruction itself will be taken into account by the target,
// so we don't have to adjust for it here when reusing a base
// register.
- if (UsedBaseReg &&
+ if (BaseReg.isValid() &&
lookupCandidateBaseReg(BaseReg, BaseOffset, FrameSizeAdjust,
LocalOffset, MI, TRI)) {
LLVM_DEBUG(dbgs() << " Reusing base register " << BaseReg << "\n");
@@ -396,8 +395,7 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
// No previously defined register was in range, so create a new one.
int64_t InstrOffset = TRI->getFrameIndexInstrOffset(&MI, idx);
- int64_t PrevBaseOffset = BaseOffset;
- BaseOffset = FrameSizeAdjust + LocalOffset + InstrOffset;
+ int64_t CandBaseOffset = FrameSizeAdjust + LocalOffset + InstrOffset;
// We'd like to avoid creating single-use virtual base registers.
// Because the FrameRefs are in sorted order, and we've already
@@ -406,12 +404,13 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
// then don't bother creating it.
if (ref + 1 >= e ||
!lookupCandidateBaseReg(
- BaseReg, BaseOffset, FrameSizeAdjust,
+ BaseReg, CandBaseOffset, FrameSizeAdjust,
FrameReferenceInsns[ref + 1].getLocalOffset(),
- *FrameReferenceInsns[ref + 1].getMachineInstr(), TRI)) {
- BaseOffset = PrevBaseOffset;
+ *FrameReferenceInsns[ref + 1].getMachineInstr(), TRI))
continue;
- }
+
+ // Save the base offset.
+ BaseOffset = CandBaseOffset;
// Tell the target to insert the instruction to initialize
// the base register.
@@ -428,7 +427,6 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
Offset = -InstrOffset;
++NumBaseRegisters;
- UsedBaseReg = true;
}
assert(BaseReg && "Unable to allocate virtual base register!");
@@ -440,5 +438,5 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
++NumReplacements;
}
- return UsedBaseReg;
+ return BaseReg.isValid();
}