Skip to content

Commit 894d047

Browse files
committed
[RISCV] Remove RISCVII::hasMergeOp. NFC
We can mostly get this from the operand info in MCInstrDesc. The exception is the _TIED pseudos so I've added a new flag for those. Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D152313
1 parent 616d30c commit 894d047

File tree

5 files changed

+28
-68
lines changed

5 files changed

+28
-68
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ enum {
5858
ConstraintShift = InstFormatShift + 5,
5959
VS2Constraint = 0b001 << ConstraintShift,
6060
VS1Constraint = 0b010 << ConstraintShift,
61-
VMConstraint = 0b100 << ConstraintShift,
61+
VMConstraint = 0b100 << ConstraintShift,
6262
ConstraintMask = 0b111 << ConstraintShift,
6363

6464
VLMulShift = ConstraintShift + 3,
@@ -68,15 +68,14 @@ enum {
6868
ForceTailAgnosticShift = VLMulShift + 3,
6969
ForceTailAgnosticMask = 1 << ForceTailAgnosticShift,
7070

71-
// Does this instruction have a merge operand that must be removed when
72-
// converting to MCInst. It will be the first explicit use operand. Used by
73-
// RVV Pseudos.
74-
HasMergeOpShift = ForceTailAgnosticShift + 1,
75-
HasMergeOpMask = 1 << HasMergeOpShift,
71+
// Is this a _TIED vector pseudo instruction. For these instructions we
72+
// shouldn't skip the tied operand when converting to MC instructions.
73+
IsTiedPseudoShift = ForceTailAgnosticShift + 1,
74+
IsTiedPseudoMask = 1 << IsTiedPseudoShift,
7675

7776
// Does this instruction have a SEW operand. It will be the last explicit
7877
// operand unless there is a vector policy operand. Used by RVV Pseudos.
79-
HasSEWOpShift = HasMergeOpShift + 1,
78+
HasSEWOpShift = IsTiedPseudoShift + 1,
8079
HasSEWOpMask = 1 << HasSEWOpShift,
8180

8281
// Does this instruction have a VL operand. It will be the second to last
@@ -140,9 +139,9 @@ static inline VLMUL getLMul(uint64_t TSFlags) {
140139
static inline bool doesForceTailAgnostic(uint64_t TSFlags) {
141140
return TSFlags & ForceTailAgnosticMask;
142141
}
143-
/// \returns true if there is a merge operand for the instruction.
144-
static inline bool hasMergeOp(uint64_t TSFlags) {
145-
return TSFlags & HasMergeOpMask;
142+
/// \returns true if this a _TIED pseudo.
143+
static inline bool isTiedPseudo(uint64_t TSFlags) {
144+
return TSFlags & IsTiedPseudoMask;
146145
}
147146
/// \returns true if there is a SEW operand for the instruction.
148147
static inline bool hasSEWOp(uint64_t TSFlags) {
@@ -165,12 +164,6 @@ static inline bool usesMaskPolicy(uint64_t TSFlags) {
165164
return TSFlags & UsesMaskPolicyMask;
166165
}
167166

168-
static inline unsigned getMergeOpNum(const MCInstrDesc &Desc) {
169-
assert(hasMergeOp(Desc.TSFlags));
170-
assert(!Desc.isVariadic());
171-
return Desc.getNumDefs();
172-
}
173-
174167
static inline unsigned getVLOpNum(const MCInstrDesc &Desc) {
175168
const uint64_t TSFlags = Desc.TSFlags;
176169
// This method is only called if we expect to have a VL operand, and all
@@ -199,9 +192,7 @@ static inline unsigned getVecPolicyOpNum(const MCInstrDesc &Desc) {
199192
// Is the first def operand tied to the first use operand. This is true for
200193
// vector pseudo instructions that have a merge operand for tail/mask
201194
// undisturbed. It's also true for vector FMA instructions where one of the
202-
// operands is also the destination register. This is different than
203-
// RISCVII::hasMergeOp which only indicates whether the tied operand from the
204-
// pseudoinstruction also exists on the MC layer instruction.
195+
// operands is also the destination register.
205196
static inline bool isFirstDefTiedToFirstUse(const MCInstrDesc &Desc) {
206197
return Desc.getNumDefs() < Desc.getNumOperands() &&
207198
Desc.getOperandConstraint(Desc.getNumDefs(), MCOI::TIED_TO) == 0;

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,12 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
631631
assert(MF && "MBB expected to be in a machine function");
632632

633633
const RISCVSubtarget &Subtarget = MF->getSubtarget<RISCVSubtarget>();
634+
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
634635
const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
635636
assert(TRI && "TargetRegisterInfo expected");
636637

637-
uint64_t TSFlags = MI->getDesc().TSFlags;
638+
const MCInstrDesc &MCID = MI->getDesc();
639+
uint64_t TSFlags = MCID.TSFlags;
638640
unsigned NumOps = MI->getNumExplicitOperands();
639641

640642
// Skip policy, VL and SEW operands which are the last operands if present.
@@ -652,10 +654,17 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
652654
if (hasVLOutput && OpNo == 1)
653655
continue;
654656

655-
// Skip merge op. It should be the first operand after the result.
656-
if (RISCVII::hasMergeOp(TSFlags) && OpNo == 1U + hasVLOutput) {
657-
assert(MI->getNumExplicitDefs() == 1U + hasVLOutput);
658-
continue;
657+
// Skip merge op. It should be the first operand after the defs.
658+
if (OpNo == MI->getNumExplicitDefs() && MO.isReg() && MO.isTied()) {
659+
assert(MCID.getOperandConstraint(OpNo, MCOI::TIED_TO) == 0 &&
660+
"Expected tied to first def.");
661+
const MCInstrDesc &OutMCID = TII->get(OutMI.getOpcode());
662+
// Skip if the next operand in OutMI is not supposed to be tied. Unless it
663+
// is a _TIED instruction.
664+
if (OutMCID.getOperandConstraint(OutMI.getNumOperands(), MCOI::TIED_TO) <
665+
0 &&
666+
!RISCVII::isTiedPseudo(TSFlags))
667+
continue;
659668
}
660669

661670
MCOperand MCOp;
@@ -704,7 +713,6 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
704713

705714
// Unmasked pseudo instructions need to append dummy mask operand to
706715
// V instructions. All V instructions are modeled as the masked version.
707-
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
708716
const MCInstrDesc &OutMCID = TII->get(OutMI.getOpcode());
709717
if (OutMI.getNumOperands() < OutMCID.getNumOperands()) {
710718
assert(OutMCID.operands()[OutMI.getNumOperands()].RegClass ==

llvm/lib/Target/RISCV/RISCVInstrFormats.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ class RVInst<dag outs, dag ins, string opcodestr, string argstr,
190190
bit ForceTailAgnostic = false;
191191
let TSFlags{11} = ForceTailAgnostic;
192192

193-
bit HasMergeOp = 0;
194-
let TSFlags{12} = HasMergeOp;
193+
bit IsTiedPseudo = 0;
194+
let TSFlags{12} = IsTiedPseudo;
195195

196196
bit HasSEWOp = 0;
197197
let TSFlags{13} = HasSEWOp;

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,13 +1793,6 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
17931793
}
17941794

17951795
const uint64_t TSFlags = Desc.TSFlags;
1796-
if (RISCVII::hasMergeOp(TSFlags)) {
1797-
unsigned OpIdx = RISCVII::getMergeOpNum(Desc);
1798-
if (MI.findTiedOperandIdx(0) != OpIdx) {
1799-
ErrInfo = "Merge op improperly tied";
1800-
return false;
1801-
}
1802-
}
18031796
if (RISCVII::hasVLOp(TSFlags)) {
18041797
const MachineOperand &Op = MI.getOperand(RISCVII::getVLOpNum(Desc));
18051798
if (!Op.isImm() && !Op.isReg()) {

0 commit comments

Comments
 (0)