Skip to content

Commit a316f14

Browse files
authored
[RISCV][NFC] Move getRVVMCOpcode to RISCVInstrInfo (#70637)
To simplify more code.
1 parent 6d30bc0 commit a316f14

File tree

5 files changed

+25
-34
lines changed

5 files changed

+25
-34
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,10 +2841,9 @@ bool RISCVDAGToDAGISel::selectSHXADD_UWOp(SDValue N, unsigned ShAmt,
28412841
static bool vectorPseudoHasAllNBitUsers(SDNode *User, unsigned UserOpNo,
28422842
unsigned Bits,
28432843
const TargetInstrInfo *TII) {
2844-
const RISCVVPseudosTable::PseudoInfo *PseudoInfo =
2845-
RISCVVPseudosTable::getPseudoInfo(User->getMachineOpcode());
2844+
unsigned MCOpcode = RISCV::getRVVMCOpcode(User->getMachineOpcode());
28462845

2847-
if (!PseudoInfo)
2846+
if (!MCOpcode)
28482847
return false;
28492848

28502849
const MCInstrDesc &MCID = TII->get(User->getMachineOpcode());
@@ -2865,7 +2864,7 @@ static bool vectorPseudoHasAllNBitUsers(SDNode *User, unsigned UserOpNo,
28652864
return false;
28662865

28672866
auto NumDemandedBits =
2868-
RISCV::getVectorLowDemandedScalarBits(PseudoInfo->BaseInstr, Log2SEW);
2867+
RISCV::getVectorLowDemandedScalarBits(MCOpcode, Log2SEW);
28692868
return NumDemandedBits && Bits >= *NumDemandedBits;
28702869
}
28712870

@@ -3404,21 +3403,11 @@ bool RISCVDAGToDAGISel::doPeepholeMaskedRVV(MachineSDNode *N) {
34043403
}
34053404

34063405
static bool IsVMerge(SDNode *N) {
3407-
unsigned Opc = N->getMachineOpcode();
3408-
return Opc == RISCV::PseudoVMERGE_VVM_MF8 ||
3409-
Opc == RISCV::PseudoVMERGE_VVM_MF4 ||
3410-
Opc == RISCV::PseudoVMERGE_VVM_MF2 ||
3411-
Opc == RISCV::PseudoVMERGE_VVM_M1 ||
3412-
Opc == RISCV::PseudoVMERGE_VVM_M2 ||
3413-
Opc == RISCV::PseudoVMERGE_VVM_M4 || Opc == RISCV::PseudoVMERGE_VVM_M8;
3406+
return RISCV::getRVVMCOpcode(N->getMachineOpcode()) == RISCV::VMERGE_VVM;
34143407
}
34153408

34163409
static bool IsVMv(SDNode *N) {
3417-
unsigned Opc = N->getMachineOpcode();
3418-
return Opc == RISCV::PseudoVMV_V_V_MF8 || Opc == RISCV::PseudoVMV_V_V_MF4 ||
3419-
Opc == RISCV::PseudoVMV_V_V_MF2 || Opc == RISCV::PseudoVMV_V_V_M1 ||
3420-
Opc == RISCV::PseudoVMV_V_V_M2 || Opc == RISCV::PseudoVMV_V_V_M4 ||
3421-
Opc == RISCV::PseudoVMV_V_V_M8;
3410+
return RISCV::getRVVMCOpcode(N->getMachineOpcode()) == RISCV::VMV_V_V;
34223411
}
34233412

34243413
static unsigned GetVMSetForLMul(RISCVII::VLMUL LMUL) {

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,8 @@ static bool isVLPreservingConfig(const MachineInstr &MI) {
6767
return RISCV::X0 == MI.getOperand(0).getReg();
6868
}
6969

70-
static uint16_t getRVVMCOpcode(uint16_t RVVPseudoOpcode) {
71-
const RISCVVPseudosTable::PseudoInfo *RVV =
72-
RISCVVPseudosTable::getPseudoInfo(RVVPseudoOpcode);
73-
if (!RVV)
74-
return 0;
75-
return RVV->BaseInstr;
76-
}
77-
7870
static bool isFloatScalarMoveOrScalarSplatInstr(const MachineInstr &MI) {
79-
switch (getRVVMCOpcode(MI.getOpcode())) {
71+
switch (RISCV::getRVVMCOpcode(MI.getOpcode())) {
8072
default:
8173
return false;
8274
case RISCV::VFMV_S_F:
@@ -86,7 +78,7 @@ static bool isFloatScalarMoveOrScalarSplatInstr(const MachineInstr &MI) {
8678
}
8779

8880
static bool isScalarExtractInstr(const MachineInstr &MI) {
89-
switch (getRVVMCOpcode(MI.getOpcode())) {
81+
switch (RISCV::getRVVMCOpcode(MI.getOpcode())) {
9082
default:
9183
return false;
9284
case RISCV::VMV_X_S:
@@ -96,7 +88,7 @@ static bool isScalarExtractInstr(const MachineInstr &MI) {
9688
}
9789

9890
static bool isScalarInsertInstr(const MachineInstr &MI) {
99-
switch (getRVVMCOpcode(MI.getOpcode())) {
91+
switch (RISCV::getRVVMCOpcode(MI.getOpcode())) {
10092
default:
10193
return false;
10294
case RISCV::VMV_S_X:
@@ -106,7 +98,7 @@ static bool isScalarInsertInstr(const MachineInstr &MI) {
10698
}
10799

108100
static bool isScalarSplatInstr(const MachineInstr &MI) {
109-
switch (getRVVMCOpcode(MI.getOpcode())) {
101+
switch (RISCV::getRVVMCOpcode(MI.getOpcode())) {
110102
default:
111103
return false;
112104
case RISCV::VMV_V_I:
@@ -117,7 +109,7 @@ static bool isScalarSplatInstr(const MachineInstr &MI) {
117109
}
118110

119111
static bool isVSlideInstr(const MachineInstr &MI) {
120-
switch (getRVVMCOpcode(MI.getOpcode())) {
112+
switch (RISCV::getRVVMCOpcode(MI.getOpcode())) {
121113
default:
122114
return false;
123115
case RISCV::VSLIDEDOWN_VX:
@@ -131,7 +123,7 @@ static bool isVSlideInstr(const MachineInstr &MI) {
131123
/// Get the EEW for a load or store instruction. Return std::nullopt if MI is
132124
/// not a load or store which ignores SEW.
133125
static std::optional<unsigned> getEEWForLoadStore(const MachineInstr &MI) {
134-
switch (getRVVMCOpcode(MI.getOpcode())) {
126+
switch (RISCV::getRVVMCOpcode(MI.getOpcode())) {
135127
default:
136128
return std::nullopt;
137129
case RISCV::VLE8_V:

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,3 +3103,11 @@ RISCV::getVectorLowDemandedScalarBits(uint16_t Opcode, unsigned Log2SEW) {
31033103
return 1U << Log2SEW;
31043104
}
31053105
}
3106+
3107+
unsigned RISCV::getRVVMCOpcode(unsigned RVVPseudoOpcode) {
3108+
const RISCVVPseudosTable::PseudoInfo *RVV =
3109+
RISCVVPseudosTable::getPseudoInfo(RVVPseudoOpcode);
3110+
if (!RVV)
3111+
return 0;
3112+
return RVV->BaseInstr;
3113+
}

llvm/lib/Target/RISCV/RISCVInstrInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ bool hasEqualFRM(const MachineInstr &MI1, const MachineInstr &MI2);
283283
std::optional<unsigned> getVectorLowDemandedScalarBits(uint16_t Opcode,
284284
unsigned Log2SEW);
285285

286+
// Returns the MC opcode of RVV pseudo instruction.
287+
unsigned getRVVMCOpcode(unsigned RVVPseudoOpcode);
288+
286289
// Special immediate for AVL operand of V pseudo instructions to indicate VLMax.
287290
static constexpr int64_t VLMaxSentinel = -1LL;
288291

llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ FunctionPass *llvm::createRISCVOptWInstrsPass() {
8484
static bool vectorPseudoHasAllNBitUsers(const MachineOperand &UserOp,
8585
unsigned Bits) {
8686
const MachineInstr &MI = *UserOp.getParent();
87-
const RISCVVPseudosTable::PseudoInfo *PseudoInfo =
88-
RISCVVPseudosTable::getPseudoInfo(MI.getOpcode());
87+
unsigned MCOpcode = RISCV::getRVVMCOpcode(MI.getOpcode());
8988

90-
if (!PseudoInfo)
89+
if (!MCOpcode)
9190
return false;
9291

9392
const MCInstrDesc &MCID = MI.getDesc();
@@ -101,7 +100,7 @@ static bool vectorPseudoHasAllNBitUsers(const MachineOperand &UserOp,
101100
return false;
102101

103102
auto NumDemandedBits =
104-
RISCV::getVectorLowDemandedScalarBits(PseudoInfo->BaseInstr, Log2SEW);
103+
RISCV::getVectorLowDemandedScalarBits(MCOpcode, Log2SEW);
105104
return NumDemandedBits && Bits >= *NumDemandedBits;
106105
}
107106

0 commit comments

Comments
 (0)