Skip to content

Commit 674cda5

Browse files
committed
[Codegen] Make Width in getMemOperandsWithOffsetWidth a LocationSize.
This is another part of #70452 which makes getMemOperandsWithOffsetWidth use a LocationSize for Width, as opposed to the unsigned it currently uses. The advantages on it's own are not super high if getMemOperandsWithOffsetWidth usually uses known sizes, but if the values can come from an MMO it can help be more accurate in case they are Unknown (and in the future, scalable).
1 parent e6dff54 commit 674cda5

21 files changed

+70
-70
lines changed

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ class TargetInstrInfo : public MCInstrInfo {
14461446
/// abstraction that supports negative offsets.
14471447
virtual bool getMemOperandsWithOffsetWidth(
14481448
const MachineInstr &MI, SmallVectorImpl<const MachineOperand *> &BaseOps,
1449-
int64_t &Offset, bool &OffsetIsScalable, unsigned &Width,
1449+
int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width,
14501450
const TargetRegisterInfo *TRI) const {
14511451
return false;
14521452
}

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,11 +1729,11 @@ class BaseMemOpClusterMutation : public ScheduleDAGMutation {
17291729
SUnit *SU;
17301730
SmallVector<const MachineOperand *, 4> BaseOps;
17311731
int64_t Offset;
1732-
unsigned Width;
1732+
LocationSize Width;
17331733
bool OffsetIsScalable;
17341734

17351735
MemOpInfo(SUnit *SU, ArrayRef<const MachineOperand *> BaseOps,
1736-
int64_t Offset, bool OffsetIsScalable, unsigned Width)
1736+
int64_t Offset, bool OffsetIsScalable, LocationSize Width)
17371737
: SU(SU), BaseOps(BaseOps.begin(), BaseOps.end()), Offset(Offset),
17381738
Width(Width), OffsetIsScalable(OffsetIsScalable) {}
17391739

@@ -1866,11 +1866,12 @@ void BaseMemOpClusterMutation::clusterNeighboringMemOps(
18661866

18671867
auto MemOpb = MemOpRecords[NextIdx];
18681868
unsigned ClusterLength = 2;
1869-
unsigned CurrentClusterBytes = MemOpa.Width + MemOpb.Width;
1869+
unsigned CurrentClusterBytes = MemOpa.Width.getValue().getKnownMinValue() +
1870+
MemOpb.Width.getValue().getKnownMinValue();
18701871
if (SUnit2ClusterInfo.count(MemOpa.SU->NodeNum)) {
18711872
ClusterLength = SUnit2ClusterInfo[MemOpa.SU->NodeNum].first + 1;
1872-
CurrentClusterBytes =
1873-
SUnit2ClusterInfo[MemOpa.SU->NodeNum].second + MemOpb.Width;
1873+
CurrentClusterBytes = SUnit2ClusterInfo[MemOpa.SU->NodeNum].second +
1874+
MemOpb.Width.getValue().getKnownMinValue();
18741875
}
18751876

18761877
if (!TII->shouldClusterMemOps(MemOpa.BaseOps, MemOpa.Offset,
@@ -1940,7 +1941,7 @@ void BaseMemOpClusterMutation::collectMemOpRecords(
19401941
SmallVector<const MachineOperand *, 4> BaseOps;
19411942
int64_t Offset;
19421943
bool OffsetIsScalable;
1943-
unsigned Width;
1944+
LocationSize Width = 0;
19441945
if (TII->getMemOperandsWithOffsetWidth(MI, BaseOps, Offset,
19451946
OffsetIsScalable, Width, TRI)) {
19461947
MemOpRecords.push_back(

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ bool TargetInstrInfo::getMemOperandWithOffset(
13651365
const MachineInstr &MI, const MachineOperand *&BaseOp, int64_t &Offset,
13661366
bool &OffsetIsScalable, const TargetRegisterInfo *TRI) const {
13671367
SmallVector<const MachineOperand *, 4> BaseOps;
1368-
unsigned Width;
1368+
LocationSize Width = 0;
13691369
if (!getMemOperandsWithOffsetWidth(MI, BaseOps, Offset, OffsetIsScalable,
13701370
Width, TRI) ||
13711371
BaseOps.size() != 1)

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,7 @@ bool AArch64InstrInfo::isCandidateToMergeOrPair(const MachineInstr &MI) const {
26752675

26762676
bool AArch64InstrInfo::getMemOperandsWithOffsetWidth(
26772677
const MachineInstr &LdSt, SmallVectorImpl<const MachineOperand *> &BaseOps,
2678-
int64_t &Offset, bool &OffsetIsScalable, unsigned &Width,
2678+
int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width,
26792679
const TargetRegisterInfo *TRI) const {
26802680
if (!LdSt.mayLoadOrStore())
26812681
return false;

llvm/lib/Target/AArch64/AArch64InstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class AArch64InstrInfo final : public AArch64GenInstrInfo {
155155

156156
bool getMemOperandsWithOffsetWidth(
157157
const MachineInstr &MI, SmallVectorImpl<const MachineOperand *> &BaseOps,
158-
int64_t &Offset, bool &OffsetIsScalable, unsigned &Width,
158+
int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width,
159159
const TargetRegisterInfo *TRI) const override;
160160

161161
/// If \p OffsetIsScalable is set to 'true', the offset is scaled by `vscale`.

llvm/lib/Target/AMDGPU/SIInsertHardClauses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class SIInsertHardClauses : public MachineFunctionPass {
208208

209209
int64_t Dummy1;
210210
bool Dummy2;
211-
unsigned Dummy3;
211+
LocationSize Dummy3 = 0;
212212
SmallVector<const MachineOperand *, 4> BaseOps;
213213
if (Type <= LAST_REAL_HARDCLAUSE_TYPE) {
214214
if (!SII->getMemOperandsWithOffsetWidth(MI, BaseOps, Dummy1, Dummy2,

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static bool isStride64(unsigned Opc) {
360360

361361
bool SIInstrInfo::getMemOperandsWithOffsetWidth(
362362
const MachineInstr &LdSt, SmallVectorImpl<const MachineOperand *> &BaseOps,
363-
int64_t &Offset, bool &OffsetIsScalable, unsigned &Width,
363+
int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width,
364364
const TargetRegisterInfo *TRI) const {
365365
if (!LdSt.mayLoadOrStore())
366366
return false;
@@ -424,7 +424,7 @@ bool SIInstrInfo::getMemOperandsWithOffsetWidth(
424424
DataOpIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::data0);
425425
Width = getOpSize(LdSt, DataOpIdx);
426426
DataOpIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::data1);
427-
Width += getOpSize(LdSt, DataOpIdx);
427+
Width = Width.getValue() + getOpSize(LdSt, DataOpIdx);
428428
} else {
429429
Width = getOpSize(LdSt, DataOpIdx);
430430
}
@@ -3647,12 +3647,10 @@ bool SIInstrInfo::checkInstOffsetsDoNotOverlap(const MachineInstr &MIa,
36473647
const MachineInstr &MIb) const {
36483648
SmallVector<const MachineOperand *, 4> BaseOps0, BaseOps1;
36493649
int64_t Offset0, Offset1;
3650-
unsigned Dummy0, Dummy1;
3650+
LocationSize Dummy0 = 0, Dummy1 = 0;
36513651
bool Offset0IsScalable, Offset1IsScalable;
3652-
if (!getMemOperandsWithOffsetWidth(MIa, BaseOps0, Offset0, Offset0IsScalable,
3653-
Dummy0, &RI) ||
3654-
!getMemOperandsWithOffsetWidth(MIb, BaseOps1, Offset1, Offset1IsScalable,
3655-
Dummy1, &RI))
3652+
if (!getMemOperandsWithOffsetWidth(MIa, BaseOps0, Offset0, Offset0IsScalable, Dummy0, &RI) ||
3653+
!getMemOperandsWithOffsetWidth(MIb, BaseOps1, Offset1, Offset1IsScalable, Dummy1, &RI))
36563654
return false;
36573655

36583656
if (!memOpsHaveSameBaseOperands(BaseOps0, BaseOps1))

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
240240
bool getMemOperandsWithOffsetWidth(
241241
const MachineInstr &LdSt,
242242
SmallVectorImpl<const MachineOperand *> &BaseOps, int64_t &Offset,
243-
bool &OffsetIsScalable, unsigned &Width,
243+
bool &OffsetIsScalable, LocationSize &Width,
244244
const TargetRegisterInfo *TRI) const final;
245245

246246
bool shouldClusterMemOps(ArrayRef<const MachineOperand *> BaseOps1,

llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,7 @@ bool HexagonInstrInfo::addLatencyToSchedule(const MachineInstr &MI1,
30703070
/// Get the base register and byte offset of a load/store instr.
30713071
bool HexagonInstrInfo::getMemOperandsWithOffsetWidth(
30723072
const MachineInstr &LdSt, SmallVectorImpl<const MachineOperand *> &BaseOps,
3073-
int64_t &Offset, bool &OffsetIsScalable, unsigned &Width,
3073+
int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width,
30743074
const TargetRegisterInfo *TRI) const {
30753075
OffsetIsScalable = false;
30763076
const MachineOperand *BaseOp = getBaseAndOffset(LdSt, Offset, Width);
@@ -3288,7 +3288,7 @@ unsigned HexagonInstrInfo::getAddrMode(const MachineInstr &MI) const {
32883288
// an immediate value, return nullptr.
32893289
MachineOperand *HexagonInstrInfo::getBaseAndOffset(const MachineInstr &MI,
32903290
int64_t &Offset,
3291-
unsigned &AccessSize) const {
3291+
LocationSize &AccessSize) const {
32923292
// Return if it is not a base+offset type instruction or a MemOp.
32933293
if (getAddrMode(MI) != HexagonII::BaseImmOffset &&
32943294
getAddrMode(MI) != HexagonII::BaseLongOffset &&

llvm/lib/Target/Hexagon/HexagonInstrInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class HexagonInstrInfo : public HexagonGenInstrInfo {
208208
bool getMemOperandsWithOffsetWidth(
209209
const MachineInstr &LdSt,
210210
SmallVectorImpl<const MachineOperand *> &BaseOps, int64_t &Offset,
211-
bool &OffsetIsScalable, unsigned &Width,
211+
bool &OffsetIsScalable, LocationSize &Width,
212212
const TargetRegisterInfo *TRI) const override;
213213

214214
/// Reverses the branch condition of the specified condition list,
@@ -437,7 +437,7 @@ class HexagonInstrInfo : public HexagonGenInstrInfo {
437437

438438
unsigned getAddrMode(const MachineInstr &MI) const;
439439
MachineOperand *getBaseAndOffset(const MachineInstr &MI, int64_t &Offset,
440-
unsigned &AccessSize) const;
440+
LocationSize &AccessSize) const;
441441
SmallVector<MachineInstr*,2> getBranchingInstrs(MachineBasicBlock& MBB) const;
442442
unsigned getCExtOpNum(const MachineInstr &MI) const;
443443
HexagonII::CompoundGroup

0 commit comments

Comments
 (0)