Skip to content

Commit

Permalink
[X86][MC] Support encoding of EGPR for APX (#71909)
Browse files Browse the repository at this point in the history
#70958 adds registers R16-R31 (EGPR), this patch
1. Introduces a new instruction prefix REX2
2. Supports encoding of EGPR with REX2 for legacy instructions in MAP
0/1
3. Supports encoding of EGPR with EVEX for the existing instructions in
EVEX space

RFC:

https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
  • Loading branch information
KanRobert authored Nov 13, 2023
1 parent f86770a commit 58bb2d1
Show file tree
Hide file tree
Showing 9 changed files with 1,493 additions and 74 deletions.
10 changes: 10 additions & 0 deletions llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class X86AsmParser : public MCTargetAsmParser {

DispEncoding ForcedDispEncoding = DispEncoding_Default;

// Does this instruction use apx extended register?
bool UseApxExtendedReg = false;

private:
SMLoc consumeToken() {
MCAsmParser &Parser = getParser();
Expand Down Expand Up @@ -1410,6 +1413,9 @@ bool X86AsmParser::MatchRegisterByName(MCRegister &RegNo, StringRef RegName,
}
}

if (X86II::isApxExtendedReg(RegNo))
UseApxExtendedReg = true;

// If this is "db[0-15]", match it as an alias
// for dr[0-15].
if (RegNo == 0 && RegName.startswith("db")) {
Expand Down Expand Up @@ -3084,6 +3090,7 @@ bool X86AsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
// Reset the forced VEX encoding.
ForcedVEXEncoding = VEXEncoding_Default;
ForcedDispEncoding = DispEncoding_Default;
UseApxExtendedReg = false;

// Parse pseudo prefixes.
while (true) {
Expand Down Expand Up @@ -3954,6 +3961,9 @@ unsigned X86AsmParser::checkTargetMatchPredicate(MCInst &Inst) {
unsigned Opc = Inst.getOpcode();
const MCInstrDesc &MCID = MII.get(Opc);

if (UseApxExtendedReg && !X86II::canUseApxExtendedReg(MCID))
return Match_Unsupported;

if (ForcedVEXEncoding == VEXEncoding_EVEX &&
(MCID.TSFlags & X86II::EncodingMask) != X86II::EVEX)
return Match_Unsupported;
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,12 @@ namespace X86II {
return RegNo >= X86::ZMM0 && RegNo <= X86::ZMM31;
}

/// \returns true if \p RegNo is an apx extended register.
inline bool isApxExtendedReg(unsigned RegNo) {
assert(X86::R31WH - X86::R16 == 95 && "EGPRs are not continuous");
return RegNo >= X86::R16 && RegNo <= X86::R31WH;
}

/// \returns true if the MachineOperand is a x86-64 extended (r8 or
/// higher) register, e.g. r8, xmm8, xmm13, etc.
inline bool isX86_64ExtendedReg(unsigned RegNo) {
Expand All @@ -1218,6 +1224,9 @@ namespace X86II {
(RegNo >= X86::ZMM8 && RegNo <= X86::ZMM31))
return true;

if (isApxExtendedReg(RegNo))
return true;

switch (RegNo) {
default: break;
case X86::R8: case X86::R9: case X86::R10: case X86::R11:
Expand Down
Loading

0 comments on commit 58bb2d1

Please sign in to comment.