Skip to content

[AMDGPU][AsmParser] Eliminate custom predicates for named-bit operands. #69243

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

Merged
merged 1 commit into from
Oct 17, 2023
Merged
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
10 changes: 6 additions & 4 deletions llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;

def i1imm_0 : OperandWithDefaultOps<i1, (ops (i1 0))>;

class CustomOperandClass<string name, bit optional, string parserMethod,
string defaultMethod>
class CustomOperandClass<string name, bit optional, string predicateMethod,
string parserMethod, string defaultMethod>
: AsmOperandClass {
let Name = name;
let PredicateMethod = "is"#name;
let PredicateMethod = predicateMethod;
let ParserMethod = parserMethod;
let RenderMethod = "addImmOperands";
let IsOptional = optional;
Expand All @@ -138,14 +138,16 @@ class CustomOperandClass<string name, bit optional, string parserMethod,

class CustomOperandProps<bit optional = 0, string name = NAME> {
string ImmTy = "ImmTy"#name;
string PredicateMethod = "is"#name;
string ParserMethod = "parse"#name;
string DefaultValue = "0";
string DefaultMethod = "[this]() { return "#
"AMDGPUOperand::CreateImm(this, "#DefaultValue#", SMLoc(), "#
"AMDGPUOperand::"#ImmTy#"); }";
string PrintMethod = "print"#name;
AsmOperandClass ParserMatchClass =
CustomOperandClass<name, optional, ParserMethod, DefaultMethod>;
CustomOperandClass<name, optional, PredicateMethod, ParserMethod,
DefaultMethod>;
string OperandType = "OPERAND_IMMEDIATE";
}

Expand Down
11 changes: 2 additions & 9 deletions llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,25 +356,20 @@ class AMDGPUOperand : public MCParsedAsmOperand {
return isImm() && Imm.Type == ImmT;
}

template <ImmTy Ty> bool isImmTy() const { return isImmTy(Ty); }

bool isImmLiteral() const { return isImmTy(ImmTyNone); }

bool isImmModifier() const {
return isImm() && Imm.Type != ImmTyNone;
}

bool isClampSI() const { return isImmTy(ImmTyClampSI); }
bool isOModSI() const { return isImmTy(ImmTyOModSI); }
bool isDMask() const { return isImmTy(ImmTyDMask); }
bool isDim() const { return isImmTy(ImmTyDim); }
bool isUNorm() const { return isImmTy(ImmTyUNorm); }
bool isDA() const { return isImmTy(ImmTyDA); }
bool isR128A16() const { return isImmTy(ImmTyR128A16); }
bool isA16() const { return isImmTy(ImmTyA16); }
bool isLWE() const { return isImmTy(ImmTyLWE); }
bool isOff() const { return isImmTy(ImmTyOff); }
bool isExpTgt() const { return isImmTy(ImmTyExpTgt); }
bool isExpVM() const { return isImmTy(ImmTyExpVM); }
bool isExpCompr() const { return isImmTy(ImmTyExpCompr); }
bool isOffen() const { return isImmTy(ImmTyOffen); }
bool isIdxen() const { return isImmTy(ImmTyIdxen); }
bool isAddr64() const { return isImmTy(ImmTyAddr64); }
Expand All @@ -387,7 +382,6 @@ class AMDGPUOperand : public MCParsedAsmOperand {
bool isLDS() const { return isImmTy(ImmTyLDS); }
bool isCPol() const { return isImmTy(ImmTyCPol); }
bool isTFE() const { return isImmTy(ImmTyTFE); }
bool isD16() const { return isImmTy(ImmTyD16); }
bool isFORMAT() const { return isImmTy(ImmTyFORMAT) && isUInt<7>(getImm()); }
bool isDppBankMask() const { return isImmTy(ImmTyDppBankMask); }
bool isDppRowMask() const { return isImmTy(ImmTyDppRowMask); }
Expand All @@ -404,7 +398,6 @@ class AMDGPUOperand : public MCParsedAsmOperand {
bool isOpSelHi() const { return isImmTy(ImmTyOpSelHi); }
bool isNegLo() const { return isImmTy(ImmTyNegLo); }
bool isNegHi() const { return isImmTy(ImmTyNegHi); }
bool isHigh() const { return isImmTy(ImmTyHigh); }

bool isRegOrImm() const {
return isReg() || isImm();
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ class NamedIntOperand<ValueType Type, string Prefix, string Name = NAME,

class NamedBitOperand<string Id, string Name = NAME>
: CustomOperand<i1, 1, Name> {
let PredicateMethod = "isImmTy<AMDGPUOperand::"#ImmTy#">";
let ParserMethod =
"[this](OperandVector &Operands) -> ParseStatus { "#
"return parseNamedBit(\""#Id#"\", Operands, AMDGPUOperand::"#ImmTy#"); }";
Expand All @@ -1056,6 +1057,7 @@ class NamedBitOperand<string Id, string Name = NAME>
class DefaultOperand<CustomOperand Op, int Value>
: OperandWithDefaultOps<Op.Type, (ops (Op.Type Value))>,
CustomOperandProps<1, Op.ParserMatchClass.Name> {
let PredicateMethod = Op.ParserMatchClass.PredicateMethod;
let ParserMethod = Op.ParserMatchClass.ParserMethod;
let PrintMethod = Op.PrintMethod;
}
Expand Down