Skip to content

Commit 4b4d366

Browse files
committed
[RISCV] Store only VNInfo val no in VSETVLIInfo. NFC
The VNInfo id (called val no elsewhere it seems) and register is enough to uniquely identify AVL values, so try to store as little state as possible. This may also allow us to use dummy val nos in an upcoming patch when we don't have LiveIntervals.
1 parent 428b9be commit 4b4d366

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ DemandedFields getDemanded(const MachineInstr &MI, const RISCVSubtarget *ST) {
504504
class VSETVLIInfo {
505505
struct AVLDef {
506506
// Every AVLDef should have a VNInfo.
507-
const VNInfo *ValNo;
507+
unsigned ValNo;
508508
Register DefReg;
509509
};
510510
union {
@@ -543,9 +543,9 @@ class VSETVLIInfo {
543543
void setUnknown() { State = Unknown; }
544544
bool isUnknown() const { return State == Unknown; }
545545

546-
void setAVLRegDef(const VNInfo *VNInfo, Register AVLReg) {
547-
assert(VNInfo && AVLReg.isVirtual());
548-
AVLRegDef.ValNo = VNInfo;
546+
void setAVLRegDef(unsigned ValNo, Register AVLReg) {
547+
assert(AVLReg.isVirtual());
548+
AVLRegDef.ValNo = ValNo;
549549
AVLRegDef.DefReg = AVLReg;
550550
State = AVLIsReg;
551551
}
@@ -571,7 +571,7 @@ class VSETVLIInfo {
571571
assert(hasAVLImm());
572572
return AVLImm;
573573
}
574-
const VNInfo *getAVLVNInfo() const {
574+
unsigned getAVLValNo() const {
575575
assert(hasAVLReg());
576576
return AVLRegDef.ValNo;
577577
}
@@ -580,8 +580,10 @@ class VSETVLIInfo {
580580
// boundary slot.
581581
const MachineInstr *getAVLDefMI(const LiveIntervals *LIS) const {
582582
assert(hasAVLReg());
583-
auto *MI = LIS->getInstructionFromIndex(getAVLVNInfo()->def);
584-
assert(!(getAVLVNInfo()->isPHIDef() && MI));
583+
const VNInfo *VNI =
584+
LIS->getInterval(getAVLReg()).getValNumInfo(getAVLValNo());
585+
auto *MI = LIS->getInstructionFromIndex(VNI->def);
586+
assert(!(VNI->isPHIDef() && MI));
585587
return MI;
586588
}
587589

@@ -590,7 +592,7 @@ class VSETVLIInfo {
590592
if (Info.isUnknown())
591593
setUnknown();
592594
else if (Info.hasAVLReg())
593-
setAVLRegDef(Info.getAVLVNInfo(), Info.getAVLReg());
595+
setAVLRegDef(Info.getAVLValNo(), Info.getAVLReg());
594596
else if (Info.hasAVLVLMAX())
595597
setAVLVLMAX();
596598
else if (Info.hasAVLIgnored())
@@ -629,7 +631,7 @@ class VSETVLIInfo {
629631

630632
bool hasSameAVL(const VSETVLIInfo &Other) const {
631633
if (hasAVLReg() && Other.hasAVLReg())
632-
return getAVLVNInfo()->id == Other.getAVLVNInfo()->id &&
634+
return getAVLValNo() == Other.getAVLValNo() &&
633635
getAVLReg() == Other.getAVLReg();
634636

635637
if (hasAVLImm() && Other.hasAVLImm())
@@ -927,7 +929,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
927929
if (AVLReg == RISCV::X0)
928930
NewInfo.setAVLVLMAX();
929931
else if (VNInfo *VNI = getVNInfoFromReg(AVLReg, MI, LIS))
930-
NewInfo.setAVLRegDef(VNI, AVLReg);
932+
NewInfo.setAVLRegDef(VNI->id, AVLReg);
931933
else {
932934
assert(MI.getOperand(1).isUndef());
933935
NewInfo.setAVLIgnored();
@@ -1003,7 +1005,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
10031005
else
10041006
InstrInfo.setAVLImm(Imm);
10051007
} else if (VNInfo *VNI = getVNInfoFromReg(VLOp.getReg(), MI, LIS)) {
1006-
InstrInfo.setAVLRegDef(VNI, VLOp.getReg());
1008+
InstrInfo.setAVLRegDef(VNI->id, VLOp.getReg());
10071009
} else {
10081010
assert(VLOp.isUndef());
10091011
InstrInfo.setAVLIgnored();
@@ -1255,7 +1257,7 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info,
12551257
auto &LI = LIS->getInterval(MI.getOperand(1).getReg());
12561258
SlotIndex SI = LIS->getSlotIndexes()->getInstructionIndex(MI).getRegSlot();
12571259
VNInfo *VNI = LI.getVNInfoAt(SI);
1258-
Info.setAVLRegDef(VNI, MI.getOperand(1).getReg());
1260+
Info.setAVLRegDef(VNI->id, MI.getOperand(1).getReg());
12591261
return;
12601262
}
12611263

@@ -1350,7 +1352,8 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
13501352
return true;
13511353

13521354
// We need the AVL to have been produced by a PHI node in this basic block.
1353-
const VNInfo *Valno = Require.getAVLVNInfo();
1355+
const VNInfo *Valno = LIS->getInterval(Require.getAVLReg())
1356+
.getValNumInfo(Require.getAVLValNo());
13541357
if (!Valno->isPHIDef() || LIS->getMBBFromIndex(Valno->def) != &MBB)
13551358
return true;
13561359

@@ -1514,7 +1517,8 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
15141517
// we need to prove the value is available at the point we're going
15151518
// to insert the vsetvli at.
15161519
if (AvailableInfo.hasAVLReg()) {
1517-
SlotIndex SI = AvailableInfo.getAVLVNInfo()->def;
1520+
const LiveInterval &LI = LIS->getInterval(AvailableInfo.getAVLReg());
1521+
SlotIndex SI = LI.getValNumInfo(AvailableInfo.getAVLValNo())->def;
15181522
// This is an inline dominance check which covers the case of
15191523
// UnavailablePred being the preheader of a loop.
15201524
if (LIS->getMBBFromIndex(SI) != UnavailablePred)

0 commit comments

Comments
 (0)