diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h @@ -164,10 +164,30 @@ return TSFlags & IsRVVWideningReductionMask; } /// \returns true if mask policy is valid for the instruction. -static inline bool UsesMaskPolicy(uint64_t TSFlags) { +static inline bool usesMaskPolicy(uint64_t TSFlags) { return TSFlags & UsesMaskPolicyMask; } +static inline unsigned getVLOpNum(const MCInstrDesc &Desc) { + const uint64_t TSFlags = Desc.TSFlags; + // This method is only called if we expect to have a VL operand, and all + // instructions with VL also have SEW. + assert(hasSEWOp(TSFlags) && hasVLOp(TSFlags)); + unsigned Offset = 2; + if (hasVecPolicyOp(TSFlags)) + Offset = 3; + return Desc.getNumOperands() - Offset; +} + +static inline unsigned getSEWOpNum(const MCInstrDesc &Desc) { + const uint64_t TSFlags = Desc.TSFlags; + assert(hasSEWOp(TSFlags)); + unsigned Offset = 1; + if (hasVecPolicyOp(TSFlags)) + Offset = 2; + return Desc.getNumOperands() - Offset; +} + // RISC-V Specific Machine Operand Flags enum { MO_None = 0, diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp --- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp +++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp @@ -544,23 +544,11 @@ } static unsigned getVLOpNum(const MachineInstr &MI) { - const uint64_t TSFlags = MI.getDesc().TSFlags; - // This method is only called if we expect to have a VL operand, and all - // instructions with VL also have SEW. - assert(RISCVII::hasSEWOp(TSFlags) && RISCVII::hasVLOp(TSFlags)); - unsigned Offset = 2; - if (RISCVII::hasVecPolicyOp(TSFlags)) - Offset = 3; - return MI.getNumExplicitOperands() - Offset; + return RISCVII::getVLOpNum(MI.getDesc()); } static unsigned getSEWOpNum(const MachineInstr &MI) { - const uint64_t TSFlags = MI.getDesc().TSFlags; - assert(RISCVII::hasSEWOp(TSFlags)); - unsigned Offset = 1; - if (RISCVII::hasVecPolicyOp(TSFlags)) - Offset = 2; - return MI.getNumExplicitOperands() - Offset; + return RISCVII::getSEWOpNum(MI.getDesc()); } static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags, @@ -572,7 +560,7 @@ // destination is tied to a source. Unless the source is undef. In that case // the user would have some control over the policy values. bool TailAgnostic = true; - bool UsesMaskPolicy = RISCVII::UsesMaskPolicy(TSFlags); + bool UsesMaskPolicy = RISCVII::usesMaskPolicy(TSFlags); // FIXME: Could we look at the above or below instructions to choose the // matched mask policy to reduce vsetvli instructions? Default mask policy is // agnostic if instructions use mask policy, otherwise is undisturbed. Because