Skip to content

Commit efc895c

Browse files
committed
Replace the setAVLReg and AVLIsReg with DefMI
1 parent 2dc09aa commit efc895c

File tree

1 file changed

+30
-40
lines changed

1 file changed

+30
-40
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,10 @@ DemandedFields getDemanded(const MachineInstr &MI,
444444
/// values of the VL and VTYPE registers after insertion.
445445
class VSETVLIInfo {
446446
union {
447-
Register AVLReg;
447+
const MachineInstr *AVLDefMI;
448448
unsigned AVLImm;
449449
};
450450

451-
const MachineInstr *AVLDefMI;
452-
453451
enum : uint8_t {
454452
Uninitialized,
455453
AVLIsDefMI,
@@ -468,7 +466,7 @@ class VSETVLIInfo {
468466

469467
public:
470468
VSETVLIInfo()
471-
: AVLImm(0), AVLDefMI(nullptr), TailAgnostic(false), MaskAgnostic(false),
469+
: AVLImm(0), TailAgnostic(false), MaskAgnostic(false),
472470
SEWLMULRatioOnly(false) {}
473471

474472
static VSETVLIInfo getUnknown() {
@@ -481,9 +479,8 @@ class VSETVLIInfo {
481479
void setUnknown() { State = Unknown; }
482480
bool isUnknown() const { return State == Unknown; }
483481

484-
void setAVLReg(Register Reg, const MachineInstr *DefMI) {
485-
assert(Reg.isVirtual());
486-
AVLReg = Reg;
482+
void setAVLDefMI(const MachineInstr *DefMI) {
483+
assert(DefMI);
487484
AVLDefMI = DefMI;
488485
State = AVLIsDefMI;
489486
}
@@ -496,29 +493,31 @@ class VSETVLIInfo {
496493
void setAVLVLMAX() { State = AVLIsVLMAX; }
497494

498495
void setAVLIgnored() { State = AVLIsIgnored; }
499-
void setAVLDefMI(const MachineInstr *DefMI) { AVLDefMI = DefMI; }
500496

501497
bool hasAVLImm() const { return State == AVLIsImm; }
502-
bool hasAVLReg() const { return State == AVLIsDefMI; }
498+
bool hasAVLDefMI() const { return State == AVLIsDefMI; }
503499
bool hasAVLVLMAX() const { return State == AVLIsVLMAX; }
504500
bool hasAVLIgnored() const { return State == AVLIsIgnored; }
505501
Register getAVLReg() const {
506-
assert(hasAVLReg());
507-
return AVLReg;
502+
assert(hasAVLDefMI());
503+
return AVLDefMI->getOperand(0).getReg();
508504
}
509505
unsigned getAVLImm() const {
510506
assert(hasAVLImm());
511507
return AVLImm;
512508
}
513509

514-
const MachineInstr *getAVLDefMI() const { return AVLDefMI; }
510+
const MachineInstr *getAVLDefMI() const {
511+
assert(AVLDefMI);
512+
return AVLDefMI;
513+
}
515514

516515
void setAVL(VSETVLIInfo Info) {
517516
assert(Info.isValid());
518517
if (Info.isUnknown())
519518
setUnknown();
520-
else if (Info.hasAVLReg())
521-
setAVLReg(Info.getAVLReg(), Info.getAVLDefMI());
519+
else if (Info.hasAVLDefMI())
520+
setAVLDefMI(Info.getAVLDefMI());
522521
else if (Info.hasAVLVLMAX())
523522
setAVLVLMAX();
524523
else if (Info.hasAVLIgnored())
@@ -537,7 +536,7 @@ class VSETVLIInfo {
537536
bool hasNonZeroAVL() const {
538537
if (hasAVLImm())
539538
return getAVLImm() > 0;
540-
if (hasAVLReg()) {
539+
if (hasAVLDefMI()) {
541540
const MachineInstr *MI = getAVLDefMI();
542541
assert(MI);
543542
return isNonZeroLoadImmediate(*MI);
@@ -556,8 +555,8 @@ class VSETVLIInfo {
556555
}
557556

558557
bool hasSameAVL(const VSETVLIInfo &Other) const {
559-
if (hasAVLReg() && Other.hasAVLReg())
560-
return getAVLReg() == Other.getAVLReg();
558+
if (hasAVLDefMI() && Other.hasAVLDefMI())
559+
return getAVLDefMI()->isIdenticalTo(*Other.getAVLDefMI());
561560

562561
if (hasAVLImm() && Other.hasAVLImm())
563562
return getAVLImm() == Other.getAVLImm();
@@ -737,8 +736,8 @@ class VSETVLIInfo {
737736
OS << "Uninitialized";
738737
if (isUnknown())
739738
OS << "unknown";
740-
if (hasAVLReg())
741-
OS << "AVLReg=" << (unsigned)AVLReg;
739+
if (hasAVLDefMI())
740+
OS << "AVLReg=" << (unsigned)getAVLReg();
742741
if (hasAVLImm())
743742
OS << "AVLImm=" << (unsigned)AVLImm;
744743
if (hasAVLVLMAX())
@@ -878,7 +877,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
878877
if (AVLReg == RISCV::X0)
879878
NewInfo.setAVLVLMAX();
880879
else
881-
NewInfo.setAVLReg(AVLReg, MRI.getVRegDef(AVLReg));
880+
NewInfo.setAVLDefMI(MRI.getVRegDef(AVLReg));
882881
}
883882
NewInfo.setVTYPE(MI.getOperand(2).getImm());
884883

@@ -950,9 +949,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
950949
else
951950
InstrInfo.setAVLImm(Imm);
952951
} else {
953-
InstrInfo.setAVLReg(VLOp.getReg(), VLOp.getReg().isVirtual()
954-
? MRI->getVRegDef(VLOp.getReg())
955-
: nullptr);
952+
InstrInfo.setAVLDefMI(MRI->getVRegDef(VLOp.getReg()));
956953
}
957954
} else {
958955
assert(isScalarExtractInstr(MI));
@@ -972,7 +969,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
972969
// AVL operand with the AVL of the defining vsetvli. We avoid general
973970
// register AVLs to avoid extending live ranges without being sure we can
974971
// kill the original source reg entirely.
975-
if (InstrInfo.hasAVLReg()) {
972+
if (InstrInfo.hasAVLDefMI()) {
976973
const MachineInstr *DefMI = InstrInfo.getAVLDefMI();
977974
if (DefMI && isVectorConfigInstr(*DefMI)) {
978975
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI, *MRI);
@@ -1012,7 +1009,7 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
10121009
// If our AVL is a virtual register, it might be defined by a VSET(I)VLI. If
10131010
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
10141011
// same, we can use the X0, X0 form.
1015-
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLReg()) {
1012+
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLDefMI()) {
10161013
const MachineInstr *DefMI = Info.getAVLDefMI();
10171014
assert(DefMI);
10181015
if (isVectorConfigInstr(*DefMI)) {
@@ -1131,11 +1128,11 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
11311128
// it might be defined by a VSET(I)VLI. If it has the same VLMAX we need
11321129
// and the last VL/VTYPE we observed is the same, we don't need a
11331130
// VSETVLI here.
1134-
if (Require.hasAVLReg() && CurInfo.hasCompatibleVTYPE(Used, Require)) {
1135-
MachineInstr *DefMI = MRI->getUniqueVRegDef(Require.getAVLReg());
1131+
if (Require.hasAVLDefMI() && CurInfo.hasCompatibleVTYPE(Used, Require)) {
1132+
const MachineInstr *DefMI = Require.getAVLDefMI();
11361133
assert(DefMI);
1137-
if (Require.getAVLDefMI() && isVectorConfigInstr(*Require.getAVLDefMI())) {
1138-
VSETVLIInfo DefInfo = getInfoForVSETVLI(*Require.getAVLDefMI(), *MRI);
1134+
if (DefMI && isVectorConfigInstr(*DefMI)) {
1135+
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI, *MRI);
11391136
if (DefInfo.hasSameAVL(CurInfo) && DefInfo.hasSameVLMAX(CurInfo))
11401137
return false;
11411138
}
@@ -1227,10 +1224,7 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info,
12271224

12281225
if (RISCV::isFaultFirstLoad(MI)) {
12291226
// Update AVL to vl-output of the fault first load.
1230-
Info.setAVLReg(MI.getOperand(1).getReg(),
1231-
MI.getOperand(1).getReg().isVirtual()
1232-
? MRI->getVRegDef(MI.getOperand(1).getReg())
1233-
: nullptr);
1227+
Info.setAVLDefMI(MRI->getVRegDef(MI.getOperand(1).getReg()));
12341228
return;
12351229
}
12361230

@@ -1321,15 +1315,11 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
13211315
if (DisableInsertVSETVLPHIOpt)
13221316
return true;
13231317

1324-
if (!Require.hasAVLReg())
1325-
return true;
1326-
1327-
Register AVLReg = Require.getAVLReg();
1328-
if (!AVLReg.isVirtual())
1318+
if (!Require.hasAVLDefMI())
13291319
return true;
13301320

13311321
// We need the AVL to be produce by a PHI node in this basic block.
1332-
MachineInstr *PHI = MRI->getVRegDef(AVLReg);
1322+
const MachineInstr *PHI = Require.getAVLDefMI();
13331323
if (!PHI || PHI->getOpcode() != RISCV::PHI || PHI->getParent() != &MBB)
13341324
return true;
13351325

@@ -1498,7 +1488,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
14981488
// If the AVL value is a register (other than our VLMAX sentinel),
14991489
// we need to prove the value is available at the point we're going
15001490
// to insert the vsetvli at.
1501-
if (AvailableInfo.hasAVLReg()) {
1491+
if (AvailableInfo.hasAVLDefMI()) {
15021492
const MachineInstr *AVLDefMI = AvailableInfo.getAVLDefMI();
15031493
assert(AVLDefMI);
15041494
// This is an inline dominance check which covers the case of

0 commit comments

Comments
 (0)