Skip to content

Commit 58bb2d1

Browse files
authored
[X86][MC] Support encoding of EGPR for APX (#71909)
#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
1 parent f86770a commit 58bb2d1

File tree

9 files changed

+1493
-74
lines changed

9 files changed

+1493
-74
lines changed

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class X86AsmParser : public MCTargetAsmParser {
106106

107107
DispEncoding ForcedDispEncoding = DispEncoding_Default;
108108

109+
// Does this instruction use apx extended register?
110+
bool UseApxExtendedReg = false;
111+
109112
private:
110113
SMLoc consumeToken() {
111114
MCAsmParser &Parser = getParser();
@@ -1410,6 +1413,9 @@ bool X86AsmParser::MatchRegisterByName(MCRegister &RegNo, StringRef RegName,
14101413
}
14111414
}
14121415

1416+
if (X86II::isApxExtendedReg(RegNo))
1417+
UseApxExtendedReg = true;
1418+
14131419
// If this is "db[0-15]", match it as an alias
14141420
// for dr[0-15].
14151421
if (RegNo == 0 && RegName.startswith("db")) {
@@ -3084,6 +3090,7 @@ bool X86AsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
30843090
// Reset the forced VEX encoding.
30853091
ForcedVEXEncoding = VEXEncoding_Default;
30863092
ForcedDispEncoding = DispEncoding_Default;
3093+
UseApxExtendedReg = false;
30873094

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

3964+
if (UseApxExtendedReg && !X86II::canUseApxExtendedReg(MCID))
3965+
return Match_Unsupported;
3966+
39573967
if (ForcedVEXEncoding == VEXEncoding_EVEX &&
39583968
(MCID.TSFlags & X86II::EncodingMask) != X86II::EVEX)
39593969
return Match_Unsupported;

llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h

+9
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,12 @@ namespace X86II {
12081208
return RegNo >= X86::ZMM0 && RegNo <= X86::ZMM31;
12091209
}
12101210

1211+
/// \returns true if \p RegNo is an apx extended register.
1212+
inline bool isApxExtendedReg(unsigned RegNo) {
1213+
assert(X86::R31WH - X86::R16 == 95 && "EGPRs are not continuous");
1214+
return RegNo >= X86::R16 && RegNo <= X86::R31WH;
1215+
}
1216+
12111217
/// \returns true if the MachineOperand is a x86-64 extended (r8 or
12121218
/// higher) register, e.g. r8, xmm8, xmm13, etc.
12131219
inline bool isX86_64ExtendedReg(unsigned RegNo) {
@@ -1218,6 +1224,9 @@ namespace X86II {
12181224
(RegNo >= X86::ZMM8 && RegNo <= X86::ZMM31))
12191225
return true;
12201226

1227+
if (isApxExtendedReg(RegNo))
1228+
return true;
1229+
12211230
switch (RegNo) {
12221231
default: break;
12231232
case X86::R8: case X86::R9: case X86::R10: case X86::R11:

0 commit comments

Comments
 (0)