Skip to content

Commit 73b6cb6

Browse files
committed
[NFCI] Replace AArch64StackOffset by StackOffset.
This patch replaces the AArch64StackOffset class by the generic one defined in TypeSize.h. Reviewed By: david-arm Differential Revision: https://reviews.llvm.org/D88983
1 parent 8383fdd commit 73b6cb6

File tree

10 files changed

+184
-373
lines changed

10 files changed

+184
-373
lines changed

llvm/include/llvm/Support/TypeSize.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,12 @@ class LinearPolyBase {
117117
// StackOffset - Represent an offset with named fixed and scalable components.
118118
//===----------------------------------------------------------------------===//
119119

120-
namespace NewStackOffset {
121120
class StackOffset;
122-
} // end namespace NewStackOffset
123-
124-
template <> struct LinearPolyBaseTypeTraits<NewStackOffset::StackOffset> {
121+
template <> struct LinearPolyBaseTypeTraits<StackOffset> {
125122
using ScalarTy = int64_t;
126123
static constexpr unsigned Dimensions = 2;
127124
};
128125

129-
namespace NewStackOffset {
130-
131126
/// StackOffset is a class to represent an offset with 2 dimensions,
132127
/// named fixed and scalable, respectively. This class allows a value for both
133128
/// dimensions to depict e.g. "8 bytes and 16 scalable bytes", which is needed
@@ -151,9 +146,6 @@ class StackOffset : public LinearPolyBase<StackOffset> {
151146
ScalarTy getScalable() const { return this->getValue(1); }
152147
};
153148

154-
} // end namespace NewStackOffset
155-
156-
157149
//===----------------------------------------------------------------------===//
158150
// UnivariateLinearPolyBase - a base class for linear polynomials with multiple
159151
// dimensions, but where only one dimension can be set at any time.

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 64 additions & 60 deletions
Large diffs are not rendered by default.

llvm/lib/Target/AArch64/AArch64FrameLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
1414
#define LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
1515

16-
#include "AArch64StackOffset.h"
16+
#include "llvm/Support/TypeSize.h"
1717
#include "llvm/CodeGen/TargetFrameLowering.h"
1818

1919
namespace llvm {

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,47 @@ bool llvm::isNZCVTouchedInInstructionRange(const MachineInstr &DefMI,
34293429
});
34303430
}
34313431

3432+
void AArch64InstrInfo::decomposeStackOffsetForDwarfOffsets(
3433+
const StackOffset &Offset, int64_t &ByteSized, int64_t &VGSized) {
3434+
// The smallest scalable element supported by scaled SVE addressing
3435+
// modes are predicates, which are 2 scalable bytes in size. So the scalable
3436+
// byte offset must always be a multiple of 2.
3437+
assert(Offset.getScalable() % 2 == 0 && "Invalid frame offset");
3438+
3439+
// VGSized offsets are divided by '2', because the VG register is the
3440+
// the number of 64bit granules as opposed to 128bit vector chunks,
3441+
// which is how the 'n' in e.g. MVT::nxv1i8 is modelled.
3442+
// So, for a stack offset of 16 MVT::nxv1i8's, the size is n x 16 bytes.
3443+
// VG = n * 2 and the dwarf offset must be VG * 8 bytes.
3444+
ByteSized = Offset.getFixed();
3445+
VGSized = Offset.getScalable() / 2;
3446+
}
3447+
3448+
/// Returns the offset in parts to which this frame offset can be
3449+
/// decomposed for the purpose of describing a frame offset.
3450+
/// For non-scalable offsets this is simply its byte size.
3451+
void AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(
3452+
const StackOffset &Offset, int64_t &NumBytes, int64_t &NumPredicateVectors,
3453+
int64_t &NumDataVectors) {
3454+
// The smallest scalable element supported by scaled SVE addressing
3455+
// modes are predicates, which are 2 scalable bytes in size. So the scalable
3456+
// byte offset must always be a multiple of 2.
3457+
assert(Offset.getScalable() % 2 == 0 && "Invalid frame offset");
3458+
3459+
NumBytes = Offset.getFixed();
3460+
NumDataVectors = 0;
3461+
NumPredicateVectors = Offset.getScalable() / 2;
3462+
// This method is used to get the offsets to adjust the frame offset.
3463+
// If the function requires ADDPL to be used and needs more than two ADDPL
3464+
// instructions, part of the offset is folded into NumDataVectors so that it
3465+
// uses ADDVL for part of it, reducing the number of ADDPL instructions.
3466+
if (NumPredicateVectors % 8 == 0 || NumPredicateVectors < -64 ||
3467+
NumPredicateVectors > 62) {
3468+
NumDataVectors = NumPredicateVectors / 8;
3469+
NumPredicateVectors -= NumDataVectors * 8;
3470+
}
3471+
}
3472+
34323473
// Helper function to emit a frame offset adjustment from a given
34333474
// pointer (SrcReg), stored into DestReg. This function is explicit
34343475
// in that it requires the opcode.
@@ -3538,7 +3579,8 @@ void llvm::emitFrameOffset(MachineBasicBlock &MBB,
35383579
MachineInstr::MIFlag Flag, bool SetNZCV,
35393580
bool NeedsWinCFI, bool *HasWinCFI) {
35403581
int64_t Bytes, NumPredicateVectors, NumDataVectors;
3541-
Offset.getForFrameOffset(Bytes, NumPredicateVectors, NumDataVectors);
3582+
AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(
3583+
Offset, Bytes, NumPredicateVectors, NumDataVectors);
35423584

35433585
// First emit non-scalable frame offsets, or a simple 'mov'.
35443586
if (Bytes || (!Offset && SrcReg != DestReg)) {
@@ -3798,7 +3840,7 @@ int llvm::isAArch64FrameOffsetLegal(const MachineInstr &MI,
37983840
// Construct the complete offset.
37993841
bool IsMulVL = ScaleValue.isScalable();
38003842
unsigned Scale = ScaleValue.getKnownMinSize();
3801-
int64_t Offset = IsMulVL ? SOffset.getScalableBytes() : SOffset.getBytes();
3843+
int64_t Offset = IsMulVL ? SOffset.getScalable() : SOffset.getFixed();
38023844

38033845
const MachineOperand &ImmOpnd =
38043846
MI.getOperand(AArch64InstrInfo::getLoadStoreImmIdx(MI.getOpcode()));
@@ -3840,11 +3882,9 @@ int llvm::isAArch64FrameOffsetLegal(const MachineInstr &MI,
38403882
*OutUnscaledOp = *UnscaledOp;
38413883

38423884
if (IsMulVL)
3843-
SOffset = StackOffset(Offset, MVT::nxv1i8) +
3844-
StackOffset(SOffset.getBytes(), MVT::i8);
3885+
SOffset = StackOffset::get(SOffset.getFixed(), Offset);
38453886
else
3846-
SOffset = StackOffset(Offset, MVT::i8) +
3847-
StackOffset(SOffset.getScalableBytes(), MVT::nxv1i8);
3887+
SOffset = StackOffset::get(Offset, SOffset.getScalable());
38483888
return AArch64FrameOffsetCanUpdate |
38493889
(SOffset ? 0 : AArch64FrameOffsetIsLegal);
38503890
}
@@ -3856,7 +3896,7 @@ bool llvm::rewriteAArch64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
38563896
unsigned ImmIdx = FrameRegIdx + 1;
38573897

38583898
if (Opcode == AArch64::ADDSXri || Opcode == AArch64::ADDXri) {
3859-
Offset += StackOffset(MI.getOperand(ImmIdx).getImm(), MVT::i8);
3899+
Offset += StackOffset::getFixed(MI.getOperand(ImmIdx).getImm());
38603900
emitFrameOffset(*MI.getParent(), MI, MI.getDebugLoc(),
38613901
MI.getOperand(0).getReg(), FrameReg, Offset, TII,
38623902
MachineInstr::NoFlags, (Opcode == AArch64::ADDSXri));

llvm/lib/Target/AArch64/AArch64InstrInfo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "AArch64.h"
1717
#include "AArch64RegisterInfo.h"
18-
#include "AArch64StackOffset.h"
1918
#include "llvm/ADT/Optional.h"
2019
#include "llvm/CodeGen/MachineCombinerPattern.h"
2120
#include "llvm/CodeGen/TargetInstrInfo.h"
@@ -293,6 +292,13 @@ class AArch64InstrInfo final : public AArch64GenInstrInfo {
293292
Optional<ParamLoadedValue> describeLoadedValue(const MachineInstr &MI,
294293
Register Reg) const override;
295294

295+
static void decomposeStackOffsetForFrameOffsets(const StackOffset &Offset,
296+
int64_t &NumBytes,
297+
int64_t &NumPredicateVectors,
298+
int64_t &NumDataVectors);
299+
static void decomposeStackOffsetForDwarfOffsets(const StackOffset &Offset,
300+
int64_t &ByteSized,
301+
int64_t &VGSized);
296302
#define GET_INSTRINFO_HELPER_DECLS
297303
#include "AArch64GenInstrInfo.inc"
298304

llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "AArch64FrameLowering.h"
1616
#include "AArch64InstrInfo.h"
1717
#include "AArch64MachineFunctionInfo.h"
18-
#include "AArch64StackOffset.h"
1918
#include "AArch64Subtarget.h"
2019
#include "MCTargetDesc/AArch64AddressingModes.h"
2120
#include "llvm/ADT/BitVector.h"
@@ -525,7 +524,7 @@ bool AArch64RegisterInfo::isFrameOffsetLegal(const MachineInstr *MI,
525524
Register BaseReg,
526525
int64_t Offset) const {
527526
assert(MI && "Unable to get the legal offset for nil instruction.");
528-
StackOffset SaveOffset(Offset, MVT::i8);
527+
StackOffset SaveOffset = StackOffset::getFixed(Offset);
529528
return isAArch64FrameOffsetLegal(*MI, SaveOffset) & AArch64FrameOffsetIsLegal;
530529
}
531530

@@ -556,7 +555,7 @@ void AArch64RegisterInfo::materializeFrameBaseRegister(MachineBasicBlock *MBB,
556555
void AArch64RegisterInfo::resolveFrameIndex(MachineInstr &MI, Register BaseReg,
557556
int64_t Offset) const {
558557
// ARM doesn't need the general 64-bit offsets
559-
StackOffset Off(Offset, MVT::i8);
558+
StackOffset Off = StackOffset::getFixed(Offset);
560559

561560
unsigned i = 0;
562561

@@ -619,9 +618,9 @@ void AArch64RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
619618
TFI->resolveFrameIndexReference(MF, FrameIndex, FrameReg,
620619
/*PreferFP=*/true,
621620
/*ForSimm=*/false);
622-
Offset += StackOffset(MI.getOperand(FIOperandNum + 1).getImm(), MVT::i8);
621+
Offset += StackOffset::getFixed(MI.getOperand(FIOperandNum + 1).getImm());
623622
MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg, false /*isDef*/);
624-
MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset.getBytes());
623+
MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset.getFixed());
625624
return;
626625
}
627626

@@ -637,12 +636,11 @@ void AArch64RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
637636
// TAGPstack must use the virtual frame register in its 3rd operand.
638637
const AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
639638
FrameReg = MI.getOperand(3).getReg();
640-
Offset = {MFI.getObjectOffset(FrameIndex) +
641-
AFI->getTaggedBasePointerOffset(),
642-
MVT::i8};
639+
Offset = StackOffset::getFixed(MFI.getObjectOffset(FrameIndex) +
640+
AFI->getTaggedBasePointerOffset());
643641
} else if (Tagged) {
644-
StackOffset SPOffset = {
645-
MFI.getObjectOffset(FrameIndex) + (int64_t)MFI.getStackSize(), MVT::i8};
642+
StackOffset SPOffset = StackOffset::getFixed(
643+
MFI.getObjectOffset(FrameIndex) + (int64_t)MFI.getStackSize());
646644
if (MFI.hasVarSizedObjects() ||
647645
isAArch64FrameOffsetLegal(MI, SPOffset, nullptr, nullptr, nullptr) !=
648646
(AArch64FrameOffsetCanUpdate | AArch64FrameOffsetIsLegal)) {
@@ -663,8 +661,8 @@ void AArch64RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
663661
return;
664662
}
665663
FrameReg = AArch64::SP;
666-
Offset = {MFI.getObjectOffset(FrameIndex) + (int64_t)MFI.getStackSize(),
667-
MVT::i8};
664+
Offset = StackOffset::getFixed(MFI.getObjectOffset(FrameIndex) +
665+
(int64_t)MFI.getStackSize());
668666
} else {
669667
Offset = TFI->resolveFrameIndexReference(
670668
MF, FrameIndex, FrameReg, /*PreferFP=*/false, /*ForSimm=*/true);

llvm/lib/Target/AArch64/AArch64StackOffset.h

Lines changed: 0 additions & 151 deletions
This file was deleted.

llvm/unittests/Target/AArch64/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ set(LLVM_LINK_COMPONENTS
1919

2020
add_llvm_target_unittest(AArch64Tests
2121
InstSizes.cpp
22-
TestStackOffset.cpp
22+
DecomposeStackOffsetTest.cpp
2323
)

0 commit comments

Comments
 (0)