Skip to content

[RISCV] Add XSfmm pseudo instruction and vset* insertion support #143068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,10 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
"operand must be a valid system register "
"name or an integer in the range");
}
case Match_InvalidXSfmmVType: {
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
return generateXSfmmVTypeError(ErrorLoc);
}
case Match_InvalidVTypeI: {
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
return generateVTypeError(ErrorLoc);
Expand Down
66 changes: 64 additions & 2 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ enum {
// 3 -> SEW * 4
DestEEWShift = ElementsDependOnMaskShift + 1,
DestEEWMask = 3ULL << DestEEWShift,

// 0 -> Don't care about altfmt bit in VTYPE.
// 1 -> Is not altfmt.
// 2 -> Is altfmt(BF16).
AltFmtTypeShift = DestEEWShift + 2,
AltFmtTypeMask = 3ULL << AltFmtTypeShift,

// XSfmmbase
HasTWidenOpShift = AltFmtTypeShift + 2,
HasTWidenOpMask = 1ULL << HasTWidenOpShift,

HasTMOpShift = HasTWidenOpShift + 1,
HasTMOpMask = 1ULL << HasTMOpShift,

HasTKOpShift = HasTMOpShift + 1,
HasTKOpMask = 1ULL << HasTKOpShift,
};

// Helper functions to read TSFlags.
Expand Down Expand Up @@ -179,6 +195,11 @@ static inline bool hasRoundModeOp(uint64_t TSFlags) {
return TSFlags & HasRoundModeOpMask;
}

enum class AltFmtType { DontCare, NotAltFmt, AltFmt };
static inline AltFmtType getAltFmtType(uint64_t TSFlags) {
return static_cast<AltFmtType>((TSFlags & AltFmtTypeMask) >> AltFmtTypeShift);
}

/// \returns true if this instruction uses vxrm
static inline bool usesVXRM(uint64_t TSFlags) { return TSFlags & UsesVXRMMask; }

Expand All @@ -194,11 +215,47 @@ static inline bool elementsDependOnMask(uint64_t TSFlags) {
return TSFlags & ElementsDependOnMaskMask;
}

// XSfmmbase
static inline bool hasTWidenOp(uint64_t TSFlags) {
return TSFlags & HasTWidenOpMask;
}

static inline bool hasTMOp(uint64_t TSFlags) { return TSFlags & HasTMOpMask; }

static inline bool hasTKOp(uint64_t TSFlags) { return TSFlags & HasTKOpMask; }

static inline unsigned getTNOpNum(const MCInstrDesc &Desc) {
const uint64_t TSFlags = Desc.TSFlags;
assert(hasTWidenOp(TSFlags) && hasVLOp(TSFlags));
unsigned Offset = 3;
if (hasTKOp(TSFlags))
Offset = 4;
return Desc.getNumOperands() - Offset;
}

static inline unsigned getTMOpNum(const MCInstrDesc &Desc) {
const uint64_t TSFlags = Desc.TSFlags;
assert(hasTWidenOp(TSFlags) && hasTMOp(TSFlags));
if (hasTKOp(TSFlags))
return Desc.getNumOperands() - 5;
// vtzero.t
return Desc.getNumOperands() - 4;
}

static inline unsigned getTKOpNum(const MCInstrDesc &Desc) {
const uint64_t TSFlags = Desc.TSFlags;
assert(hasTWidenOp(TSFlags) && hasTKOp(TSFlags));
return Desc.getNumOperands() - 3;
}

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));
// In Xsfmmbase, TN is an alias for VL, so here we use the same TSFlags bit.
if (hasTWidenOp(TSFlags))
return getTNOpNum(Desc);
unsigned Offset = 2;
if (hasVecPolicyOp(TSFlags))
Offset = 3;
Expand All @@ -216,7 +273,7 @@ static inline unsigned getSEWOpNum(const MCInstrDesc &Desc) {
const uint64_t TSFlags = Desc.TSFlags;
assert(hasSEWOp(TSFlags));
unsigned Offset = 1;
if (hasVecPolicyOp(TSFlags))
if (hasVecPolicyOp(TSFlags) || hasTWidenOp(TSFlags))
Offset = 2;
return Desc.getNumOperands() - Offset;
}
Expand All @@ -233,6 +290,9 @@ static inline int getFRMOpNum(const MCInstrDesc &Desc) {
if (!hasRoundModeOp(TSFlags) || usesVXRM(TSFlags))
return -1;

if (hasTWidenOp(TSFlags) && hasTMOp(TSFlags))
return getTMOpNum(Desc) - 1;

// The operand order
// --------------------------------------
// | n-1 (if any) | n-2 | n-3 | n-4 |
Expand Down Expand Up @@ -370,7 +430,9 @@ enum OperandType : unsigned {
OPERAND_SEW_MASK,
// Vector rounding mode for VXRM or FRM.
OPERAND_VEC_RM,
OPERAND_LAST_RISCV_IMM = OPERAND_VEC_RM,
// Vtype operand for XSfmm extension.
OPERAND_XSFMM_VTYPE,
OPERAND_LAST_RISCV_IMM = OPERAND_XSFMM_VTYPE,
// Operand is either a register or uimm5, this is used by V extension pseudo
// instructions to represent a value that be passed as AVL to either vsetvli
// or vsetivli.
Expand Down
Loading