Skip to content

Commit 2732860

Browse files
committed
[RISCV][InsertVSETVLI] Add Subtarget variable to class [nfc]
A bit debateable since we could extract it from the MachineFunction (and thus the MachineInstr), but we have the same pattern for MachineFunction associated structure already for TII and MRI.
1 parent 717946f commit 2732860

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,12 @@ static bool areCompatibleVTYPEs(uint64_t CurVType, uint64_t NewVType,
338338

339339
/// Return the fields and properties demanded by the provided instruction.
340340
DemandedFields getDemanded(const MachineInstr &MI,
341-
const MachineRegisterInfo *MRI) {
341+
const MachineRegisterInfo *MRI,
342+
const RISCVSubtarget *ST) {
342343
// Warning: This function has to work on both the lowered (i.e. post
343344
// emitVSETVLIs) and pre-lowering forms. The main implication of this is
344345
// that it can't use the value of a SEW, VL, or Policy operand as they might
345346
// be stale after lowering.
346-
bool HasVInstructionsF64 =
347-
MI.getMF()->getSubtarget<RISCVSubtarget>().hasVInstructionsF64();
348347

349348
// Most instructions don't use any of these subfeilds.
350349
DemandedFields Res;
@@ -403,7 +402,7 @@ DemandedFields getDemanded(const MachineInstr &MI,
403402
// tail lanes to either be the original value or -1. We are writing
404403
// unknown bits to the lanes here.
405404
if (hasUndefinedMergeOp(MI, *MRI)) {
406-
if (isFloatScalarMoveOrScalarSplatInstr(MI) && !HasVInstructionsF64)
405+
if (isFloatScalarMoveOrScalarSplatInstr(MI) && !ST->hasVInstructionsF64())
407406
Res.SEW = DemandedFields::SEWGreaterThanOrEqualAndLessThan64;
408407
else
409408
Res.SEW = DemandedFields::SEWGreaterThanOrEqual;
@@ -720,6 +719,7 @@ struct BlockData {
720719
};
721720

722721
class RISCVInsertVSETVLI : public MachineFunctionPass {
722+
const RISCVSubtarget *ST;
723723
const TargetInstrInfo *TII;
724724
MachineRegisterInfo *MRI;
725725

@@ -958,9 +958,7 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
958958
if (!CurInfo.isValid() || CurInfo.isUnknown() || CurInfo.hasSEWLMULRatioOnly())
959959
return true;
960960

961-
DemandedFields Used = getDemanded(MI, MRI);
962-
bool HasVInstructionsF64 =
963-
MI.getMF()->getSubtarget<RISCVSubtarget>().hasVInstructionsF64();
961+
DemandedFields Used = getDemanded(MI, MRI, ST);
964962

965963
// A slidedown/slideup with an *undefined* merge op can freely clobber
966964
// elements not copied from the source vector (e.g. masked off, tail, or
@@ -988,7 +986,7 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
988986
Used.LMUL = false;
989987
Used.SEWLMULRatio = false;
990988
Used.VLAny = false;
991-
if (isFloatScalarMoveOrScalarSplatInstr(MI) && !HasVInstructionsF64)
989+
if (isFloatScalarMoveOrScalarSplatInstr(MI) && !ST->hasVInstructionsF64())
992990
Used.SEW = DemandedFields::SEWGreaterThanOrEqualAndLessThan64;
993991
else
994992
Used.SEW = DemandedFields::SEWGreaterThanOrEqual;
@@ -1329,9 +1327,6 @@ static bool willVLBeAVL(const VSETVLIInfo &Info, const RISCVSubtarget &ST) {
13291327
/// this is geared to catch the common case of a fixed length vsetvl in a single
13301328
/// block loop when it could execute once in the preheader instead.
13311329
void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
1332-
const MachineFunction &MF = *MBB.getParent();
1333-
const RISCVSubtarget &ST = MF.getSubtarget<RISCVSubtarget>();
1334-
13351330
if (!BlockInfo[MBB.getNumber()].Pred.isUnknown())
13361331
return;
13371332

@@ -1360,7 +1355,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
13601355
return;
13611356

13621357
// If VL can be less than AVL, then we can't reduce the frequency of exec.
1363-
if (!willVLBeAVL(AvailableInfo, ST))
1358+
if (!willVLBeAVL(AvailableInfo, *ST))
13641359
return;
13651360

13661361
// Model the effect of changing the input state of the block MBB to
@@ -1476,7 +1471,7 @@ void RISCVInsertVSETVLI::doLocalPostpass(MachineBasicBlock &MBB) {
14761471
for (MachineInstr &MI : make_range(MBB.rbegin(), MBB.rend())) {
14771472

14781473
if (!isVectorConfigInstr(MI)) {
1479-
doUnion(Used, getDemanded(MI, MRI));
1474+
doUnion(Used, getDemanded(MI, MRI, ST));
14801475
continue;
14811476
}
14821477

@@ -1506,7 +1501,7 @@ void RISCVInsertVSETVLI::doLocalPostpass(MachineBasicBlock &MBB) {
15061501
}
15071502
}
15081503
NextMI = &MI;
1509-
Used = getDemanded(MI, MRI);
1504+
Used = getDemanded(MI, MRI, ST);
15101505
}
15111506

15121507
for (auto *MI : ToDelete)
@@ -1529,13 +1524,13 @@ void RISCVInsertVSETVLI::insertReadVL(MachineBasicBlock &MBB) {
15291524

15301525
bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
15311526
// Skip if the vector extension is not enabled.
1532-
const RISCVSubtarget &ST = MF.getSubtarget<RISCVSubtarget>();
1533-
if (!ST.hasVInstructions())
1527+
ST = &MF.getSubtarget<RISCVSubtarget>();
1528+
if (!ST->hasVInstructions())
15341529
return false;
15351530

15361531
LLVM_DEBUG(dbgs() << "Entering InsertVSETVLI for " << MF.getName() << "\n");
15371532

1538-
TII = ST.getInstrInfo();
1533+
TII = ST->getInstrInfo();
15391534
MRI = &MF.getRegInfo();
15401535

15411536
assert(BlockInfo.empty() && "Expect empty block infos");

0 commit comments

Comments
 (0)