Skip to content

Commit

Permalink
[Xe] Canonicalize XeSymbolOperand in TableGen
Browse files Browse the repository at this point in the history
Continue refactoring from intel#1140, intel#1143, intel#1166
  • Loading branch information
houjenko committed May 14, 2024
1 parent be00b2a commit 77cf8f3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
23 changes: 14 additions & 9 deletions llvm/lib/Target/Xe/AsmParser/XeAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class XeOperand : public MCParsedAsmOperand {
k_Immf64Opnd,
k_LoadFields,
k_StoreFields,
k_UIPOpnd,
k_JIPOpnd,
k_UIPOtherOpnd,
k_JIPOtherOpnd,
k_SAAddrOpnd, // addr with $indaddr, $addr and $ldstoff operands
k_SNAddrOpnd, // addr with $indaddr and $ldstoff operands
k_NAAddrOpnd, // addr with $addr and $ldstoff operands
Expand Down Expand Up @@ -244,10 +244,12 @@ class XeOperand : public MCParsedAsmOperand {
bool isNNAddrOpnd() const { return Kind == k_NNAddrOpnd; }
bool isMem() const override { return false; }

bool isSymbolRef() const { return Kind == k_UIPOpnd || Kind == k_JIPOpnd; }
bool isSymbolRef() const {
return Kind == k_UIPOtherOpnd || Kind == k_JIPOtherOpnd;
}

bool isUIPOpnd() const { return Kind == k_UIPOpnd; }
bool isJIPOpnd() const { return Kind == k_JIPOpnd; }
bool isUIPOtherOpnd() const { return Kind == k_UIPOtherOpnd; }
bool isJIPOtherOpnd() const { return Kind == k_JIPOtherOpnd; }
bool isGlobalVarOrImm64Opnd() const { return Kind == k_GlobalVarOrImm64Opnd; }
bool isBfnSubOpcode() const { return Kind == k_BfnSubOpcode; }

Expand Down Expand Up @@ -567,11 +569,11 @@ class XeOperand : public MCParsedAsmOperand {
MCI.addOperand(MCOperand::createDFPImm(getImmf64Opnd()));
}

void addUIPOpndOperands(MCInst &MCI, unsigned N) const {
void addUIPOtherOpndOperands(MCInst &MCI, unsigned N) const {
assert(N == 1 && "Invalid number of operands!");
MCI.addOperand(MCOperand::createExpr(getSymbolRef()));
}
void addJIPOpndOperands(MCInst &MCI, unsigned N) const {
void addJIPOtherOpndOperands(MCInst &MCI, unsigned N) const {
assert(N == 1 && "Invalid number of operands!");
MCI.addOperand(MCOperand::createExpr(getSymbolRef()));
}
Expand Down Expand Up @@ -833,11 +835,14 @@ class XeAsmParser : public MCTargetAsmParser {

ParseStatus parseSymbolRef(XeOperand::KindTy K, OperandVector &Operands);

template <MVT::SimpleValueType T>
ParseStatus parseUIPOpnd(OperandVector &Operands) {
return parseSymbolRef(XeOperand::k_UIPOpnd, Operands);
return parseSymbolRef(XeOperand::k_UIPOtherOpnd, Operands);
}

template <MVT::SimpleValueType T>
ParseStatus parseJIPOpnd(OperandVector &Operands) {
return parseSymbolRef(XeOperand::k_JIPOpnd, Operands);
return parseSymbolRef(XeOperand::k_JIPOtherOpnd, Operands);
}
ParseStatus parseGlobalVarOrImm64Opnd(OperandVector &Operands) {
// A symbol reference starts with "@", otherwise it is an imm64 operand
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Xe/Disassembler/XeDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ static DecodeStatus decodeNoMaskOpnd(MCInst &MCI, uint64_t Bits,
return MCDisassembler::Success;
}

template <MVT::SimpleValueType T>
static DecodeStatus decodeJIPOpnd(MCInst &MCI, uint64_t Bits, uint64_t Address,
const MCDisassembler *Decoder) {
LLVM_DEBUG(dumpDecodeInfo(__FUNCTION__, MCI, Decoder));
Expand All @@ -423,6 +424,7 @@ static DecodeStatus decodeJIPOpnd(MCInst &MCI, uint64_t Bits, uint64_t Address,
return MCDisassembler::Success;
}

template <MVT::SimpleValueType T>
static DecodeStatus decodeUIPOpnd(MCInst &MCI, uint64_t Bits, uint64_t Address,
const MCDisassembler *Decoder) {
LLVM_DEBUG(dumpDecodeInfo(__FUNCTION__, MCI, Decoder));
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Xe/MCTargetDesc/XeInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,14 @@ void XeInstPrinter::printImmOpnd(const MCInst *MCI, unsigned OpNo,
}
}

template <MVT::SimpleValueType T>
void XeInstPrinter::printUIPOpnd(const MCInst *MCI, uint64_t Address,
unsigned OpNo, raw_ostream &OS) {
const MCOperand &MCOp = MCI->getOperand(OpNo);
MCOp.getExpr()->print(OS, &MAI);
}

template <MVT::SimpleValueType T>
void XeInstPrinter::printJIPOpnd(const MCInst *MCI, uint64_t Address,
unsigned OpNo, raw_ostream &OS) {
const MCOperand &MCOp = MCI->getOperand(OpNo);
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/Xe/MCTargetDesc/XeInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ class XeInstPrinter : public MCInstPrinter {
template <MVT::SimpleValueType T>
void printImmOpnd(const MCInst *MCI, unsigned OpNo, raw_ostream &OS);

template <MVT::SimpleValueType T>
void printUIPOpnd(const MCInst *MCI, uint64_t Address, unsigned OpNo,
raw_ostream &OS);

template <MVT::SimpleValueType T>
void printJIPOpnd(const MCInst *MCI, uint64_t Address, unsigned OpNo,
raw_ostream &OS);
void printGlobalVarOrImm64Opnd(const MCInst *MCI, unsigned OpNo,
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/Xe/MCTargetDesc/XeMCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ class XeMCCodeEmitter : public MCCodeEmitter {
void encodeSBIDOpnd(const MCInst &MI, unsigned OpNo, APInt &Op,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const;
template <MVT::SimpleValueType T>
void encodeUIPOpnd(const MCInst &MI, unsigned OpNo, APInt &Op,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const;
template <MVT::SimpleValueType T>
void encodeJIPOpnd(const MCInst &MI, unsigned OpNo, APInt &Op,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const;
Expand Down Expand Up @@ -281,6 +283,7 @@ void XeMCCodeEmitter::encodeSBIDOpnd(const MCInst &MI, unsigned OpNo, APInt &Op,
Op = MI.getOperand(OpNo).getImm();
}

template <MVT::SimpleValueType T>
void XeMCCodeEmitter::encodeUIPOpnd(const MCInst &MCI, unsigned OpNo, APInt &Op,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
Expand All @@ -290,6 +293,7 @@ void XeMCCodeEmitter::encodeUIPOpnd(const MCInst &MCI, unsigned OpNo, APInt &Op,
encodePCRel32ImmOpnd(MCI, MCOp.getExpr(), /*Offset=*/5, Op, Fixups, STI);
}

template <MVT::SimpleValueType T>
void XeMCCodeEmitter::encodeJIPOpnd(const MCInst &MCI, unsigned OpNo, APInt &Op,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
Expand Down
11 changes: 6 additions & 5 deletions llvm/lib/Target/Xe/XeInstrFormats.td
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ class XeOperandNameWithRC<string BaseName, RegisterClass rc> {
string dm = "decode" # Name;
}

class XeAsmOperandWithTY<string BaseName, ValueType ty, string NameWithTY>
class XeAsmOperandWithTY<string BaseName, string TyName, string NameWithTY>
: AsmOperandClass {
let Name = BaseName # ty # "Opnd";
let Name = BaseName # TyName # "Opnd";
let ParserMethod = "parse" # NameWithTY;
}

class XeOperandNameWithTY<string BaseName, ValueType ty> {
string Name = BaseName # "Opnd" # "<MVT::" # ty # ">";
string TyName = !if ( !eq(ty, OtherVT), "Other", !cast<string>(ty) );
string Name = BaseName # "Opnd" # "<MVT::" # TyName # ">";
string pm = "print" # Name;
AsmOperandClass pmc = XeAsmOperandWithTY<BaseName, ty, Name>;
AsmOperandClass pmc = XeAsmOperandWithTY<BaseName, TyName, Name>;
string em = "encode" # Name;
string sm = "select" # Name;
string dm = "decode" # Name;
Expand All @@ -84,7 +85,7 @@ class XeSymbolOrImmOperand<ValueType ty, string name>
: XeOperandOld<ty, name>;

class XeSymbolOperand<ValueType ty, string name>
: XeOperandOld<ty, name> {
: XeOperand<ty, name> {
let OperandType = "OPERAND_PCREL";
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/Xe/XeInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,8 @@ let isReturn = 1, isBarrier = 1, isTerminator = 1, isNotDuplicable = 1,
}
}

def UIPOpnd : XeSymbolOperand<OtherVT, "UIPOpnd">;
def JIPOpnd : XeSymbolOperand<OtherVT, "JIPOpnd">;
def UIPOpnd : XeSymbolOperand<OtherVT, "UIP">;
def JIPOpnd : XeSymbolOperand<OtherVT, "JIP">;

let swsb = 0, src0 = 0 in {
let fields = 0, uip = 0 in {
Expand Down

0 comments on commit 77cf8f3

Please sign in to comment.