Skip to content

Commit 7b8942f

Browse files
committed
Replace the setAVLReg and AVLIsReg with DefMI
1 parent 16fb15c commit 7b8942f

File tree

1 file changed

+30
-39
lines changed

1 file changed

+30
-39
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,10 @@ DemandedFields getDemanded(const MachineInstr &MI,
455455
/// values of the VL and VTYPE registers after insertion.
456456
class VSETVLIInfo {
457457
union {
458-
Register AVLReg;
458+
const MachineInstr *AVLDefMI;
459459
unsigned AVLImm;
460460
};
461461

462-
const MachineInstr *AVLDefMI;
463-
464462
enum : uint8_t {
465463
Uninitialized,
466464
AVLIsDefMI,
@@ -479,7 +477,7 @@ class VSETVLIInfo {
479477

480478
public:
481479
VSETVLIInfo()
482-
: AVLImm(0), AVLDefMI(nullptr), TailAgnostic(false), MaskAgnostic(false),
480+
: AVLImm(0), TailAgnostic(false), MaskAgnostic(false),
483481
SEWLMULRatioOnly(false) {}
484482

485483
static VSETVLIInfo getUnknown() {
@@ -492,9 +490,8 @@ class VSETVLIInfo {
492490
void setUnknown() { State = Unknown; }
493491
bool isUnknown() const { return State == Unknown; }
494492

495-
void setAVLReg(Register Reg, const MachineInstr *DefMI) {
496-
assert(Reg.isVirtual());
497-
AVLReg = Reg;
493+
void setAVLDefMI(const MachineInstr *DefMI) {
494+
assert(DefMI);
498495
AVLDefMI = DefMI;
499496
State = AVLIsDefMI;
500497
}
@@ -507,29 +504,31 @@ class VSETVLIInfo {
507504
void setAVLVLMAX() { State = AVLIsVLMAX; }
508505

509506
void setAVLIgnored() { State = AVLIsIgnored; }
510-
void setAVLDefMI(const MachineInstr *DefMI) { AVLDefMI = DefMI; }
511507

512508
bool hasAVLImm() const { return State == AVLIsImm; }
513-
bool hasAVLReg() const { return State == AVLIsDefMI; }
509+
bool hasAVLDefMI() const { return State == AVLIsDefMI; }
514510
bool hasAVLVLMAX() const { return State == AVLIsVLMAX; }
515511
bool hasAVLIgnored() const { return State == AVLIsIgnored; }
516512
Register getAVLReg() const {
517-
assert(hasAVLReg());
518-
return AVLReg;
513+
assert(hasAVLDefMI());
514+
return AVLDefMI->getOperand(0).getReg();
519515
}
520516
unsigned getAVLImm() const {
521517
assert(hasAVLImm());
522518
return AVLImm;
523519
}
524520

525-
const MachineInstr *getAVLDefMI() const { return AVLDefMI; }
521+
const MachineInstr *getAVLDefMI() const {
522+
assert(AVLDefMI);
523+
return AVLDefMI;
524+
}
526525

527526
void setAVL(VSETVLIInfo Info) {
528527
assert(Info.isValid());
529528
if (Info.isUnknown())
530529
setUnknown();
531-
else if (Info.hasAVLReg())
532-
setAVLReg(Info.getAVLReg(), Info.getAVLDefMI());
530+
else if (Info.hasAVLDefMI())
531+
setAVLDefMI(Info.getAVLDefMI());
533532
else if (Info.hasAVLVLMAX())
534533
setAVLVLMAX();
535534
else if (Info.hasAVLIgnored())
@@ -548,7 +547,7 @@ class VSETVLIInfo {
548547
bool hasNonZeroAVL() const {
549548
if (hasAVLImm())
550549
return getAVLImm() > 0;
551-
if (hasAVLReg()) {
550+
if (hasAVLDefMI()) {
552551
const MachineInstr *MI = getAVLDefMI();
553552
assert(MI);
554553
return isNonZeroLoadImmediate(*MI);
@@ -567,8 +566,8 @@ class VSETVLIInfo {
567566
}
568567

569568
bool hasSameAVL(const VSETVLIInfo &Other) const {
570-
if (hasAVLReg() && Other.hasAVLReg())
571-
return getAVLReg() == Other.getAVLReg();
569+
if (hasAVLDefMI() && Other.hasAVLDefMI())
570+
return getAVLDefMI()->isIdenticalTo(*Other.getAVLDefMI());
572571

573572
if (hasAVLImm() && Other.hasAVLImm())
574573
return getAVLImm() == Other.getAVLImm();
@@ -748,8 +747,8 @@ class VSETVLIInfo {
748747
OS << "Uninitialized";
749748
if (isUnknown())
750749
OS << "unknown";
751-
if (hasAVLReg())
752-
OS << "AVLReg=" << (unsigned)AVLReg;
750+
if (hasAVLDefMI())
751+
OS << "AVLReg=" << (unsigned)getAVLReg();
753752
if (hasAVLImm())
754753
OS << "AVLImm=" << (unsigned)AVLImm;
755754
if (hasAVLVLMAX())
@@ -889,7 +888,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
889888
if (AVLReg == RISCV::X0)
890889
NewInfo.setAVLVLMAX();
891890
else
892-
NewInfo.setAVLReg(AVLReg, MRI.getVRegDef(AVLReg));
891+
NewInfo.setAVLDefMI(MRI.getVRegDef(AVLReg));
893892
}
894893
NewInfo.setVTYPE(MI.getOperand(2).getImm());
895894

@@ -961,9 +960,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
961960
else
962961
InstrInfo.setAVLImm(Imm);
963962
} else {
964-
InstrInfo.setAVLReg(VLOp.getReg(), VLOp.getReg().isVirtual()
965-
? MRI->getVRegDef(VLOp.getReg())
966-
: nullptr);
963+
InstrInfo.setAVLDefMI(MRI->getVRegDef(VLOp.getReg()));
967964
}
968965
} else {
969966
assert(isScalarExtractInstr(MI));
@@ -983,7 +980,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
983980
// AVL operand with the AVL of the defining vsetvli. We avoid general
984981
// register AVLs to avoid extending live ranges without being sure we can
985982
// kill the original source reg entirely.
986-
if (InstrInfo.hasAVLReg()) {
983+
if (InstrInfo.hasAVLDefMI()) {
987984
const MachineInstr *DefMI = InstrInfo.getAVLDefMI();
988985
if (isVectorConfigInstr(*DefMI)) {
989986
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI, *MRI);
@@ -1023,7 +1020,7 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
10231020
// If our AVL is a virtual register, it might be defined by a VSET(I)VLI. If
10241021
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
10251022
// same, we can use the X0, X0 form.
1026-
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLReg()) {
1023+
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLDefMI()) {
10271024
const MachineInstr *DefMI = Info.getAVLDefMI();
10281025
assert(DefMI);
10291026
if (isVectorConfigInstr(*DefMI)) {
@@ -1142,11 +1139,11 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
11421139
// it might be defined by a VSET(I)VLI. If it has the same VLMAX we need
11431140
// and the last VL/VTYPE we observed is the same, we don't need a
11441141
// VSETVLI here.
1145-
if (Require.hasAVLReg() && CurInfo.hasCompatibleVTYPE(Used, Require)) {
1146-
MachineInstr *DefMI = MRI->getUniqueVRegDef(Require.getAVLReg());
1142+
if (Require.hasAVLDefMI() && CurInfo.hasCompatibleVTYPE(Used, Require)) {
1143+
const MachineInstr *DefMI = Require.getAVLDefMI();
11471144
assert(DefMI);
1148-
if (Require.getAVLDefMI() && isVectorConfigInstr(*Require.getAVLDefMI())) {
1149-
VSETVLIInfo DefInfo = getInfoForVSETVLI(*Require.getAVLDefMI(), *MRI);
1145+
if (DefMI && isVectorConfigInstr(*DefMI)) {
1146+
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI, *MRI);
11501147
if (DefInfo.hasSameAVL(CurInfo) && DefInfo.hasSameVLMAX(CurInfo))
11511148
return false;
11521149
}
@@ -1238,10 +1235,7 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info,
12381235

12391236
if (RISCV::isFaultFirstLoad(MI)) {
12401237
// Update AVL to vl-output of the fault first load.
1241-
Info.setAVLReg(MI.getOperand(1).getReg(),
1242-
MI.getOperand(1).getReg().isVirtual()
1243-
? MRI->getVRegDef(MI.getOperand(1).getReg())
1244-
: nullptr);
1238+
Info.setAVLDefMI(MRI->getVRegDef(MI.getOperand(1).getReg()));
12451239
return;
12461240
}
12471241

@@ -1332,14 +1326,11 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
13321326
if (DisableInsertVSETVLPHIOpt)
13331327
return true;
13341328

1335-
if (!Require.hasAVLReg())
1329+
if (!Require.hasAVLDefMI())
13361330
return true;
13371331

1338-
Register AVLReg = Require.getAVLReg();
1339-
13401332
// We need the AVL to be produce by a PHI node in this basic block.
1341-
MachineInstr *PHI = MRI->getUniqueVRegDef(AVLReg);
1342-
assert(PHI);
1333+
const MachineInstr *PHI = Require.getAVLDefMI();
13431334
if (PHI->getOpcode() != RISCV::PHI || PHI->getParent() != &MBB)
13441335
return true;
13451336

@@ -1509,7 +1500,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
15091500
// If the AVL value is a register (other than our VLMAX sentinel),
15101501
// we need to prove the value is available at the point we're going
15111502
// to insert the vsetvli at.
1512-
if (AvailableInfo.hasAVLReg()) {
1503+
if (AvailableInfo.hasAVLDefMI()) {
15131504
const MachineInstr *AVLDefMI = AvailableInfo.getAVLDefMI();
15141505
assert(AVLDefMI);
15151506
// This is an inline dominance check which covers the case of

0 commit comments

Comments
 (0)