diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td index 23242ad84b0c4..d2d09a0b1fc54 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td @@ -165,6 +165,20 @@ class ImmOperand; def u16imm : ImmOperand; +class ValuePredicatedOperand + : CustomOperand { + let ImmTy = op.ImmTy; + defvar OpPredicate = op.ParserMatchClass.PredicateMethod; + let PredicateMethod = + "getPredicate([](const AMDGPUOperand &Op) -> bool { "# + "return Op."#OpPredicate#"() && "#valuePredicate#"; })"; + let ParserMethod = op.ParserMatchClass.ParserMethod; + let DefaultValue = op.DefaultValue; + let DefaultMethod = op.DefaultMethod; + let PrintMethod = op.PrintMethod; +} + //===--------------------------------------------------------------------===// // Custom Operands //===--------------------------------------------------------------------===// diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp index fe2729f9790aa..be74c627d2137 100644 --- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp +++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp @@ -909,6 +909,10 @@ class AMDGPUOperand : public MCParsedAsmOperand { bool isWaitVDST() const; bool isWaitEXP() const; + auto getPredicate(std::function P) const { + return std::bind(P, *this); + } + StringRef getToken() const { assert(isToken()); return StringRef(Tok.Data, Tok.Length); @@ -1773,7 +1777,6 @@ class AMDGPUAsmParser : public MCTargetAsmParser { void cvtVOP3Interp(MCInst &Inst, const OperandVector &Operands); void cvtVINTERP(MCInst &Inst, const OperandVector &Operands); - void cvtSMEMAtomic(MCInst &Inst, const OperandVector &Operands); bool parseDimId(unsigned &Encoding); ParseStatus parseDim(OperandVector &Operands); @@ -7722,66 +7725,6 @@ void AMDGPUAsmParser::cvtMubufImpl(MCInst &Inst, addOptionalImmOperand(Inst, Operands, OptionalIdx, AMDGPUOperand::ImmTyCPol, 0); } -//===----------------------------------------------------------------------===// -// SMEM -//===----------------------------------------------------------------------===// - -void AMDGPUAsmParser::cvtSMEMAtomic(MCInst &Inst, const OperandVector &Operands) { - OptionalImmIndexMap OptionalIdx; - bool IsAtomicReturn = false; - - for (unsigned i = 1, e = Operands.size(); i != e; ++i) { - AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]); - if (!Op.isCPol()) - continue; - IsAtomicReturn = Op.getImm() & AMDGPU::CPol::GLC; - break; - } - - if (!IsAtomicReturn) { - int NewOpc = AMDGPU::getAtomicNoRetOp(Inst.getOpcode()); - if (NewOpc != -1) - Inst.setOpcode(NewOpc); - } - - IsAtomicReturn = MII.get(Inst.getOpcode()).TSFlags & - SIInstrFlags::IsAtomicRet; - - for (unsigned i = 1, e = Operands.size(); i != e; ++i) { - AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]); - - // Add the register arguments - if (Op.isReg()) { - Op.addRegOperands(Inst, 1); - if (IsAtomicReturn && i == 1) - Op.addRegOperands(Inst, 1); - continue; - } - - // Handle the case where soffset is an immediate - if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyNone) { - Op.addImmOperands(Inst, 1); - continue; - } - - // Handle tokens like 'offen' which are sometimes hard-coded into the - // asm string. There are no MCInst operands for these. - if (Op.isToken()) { - continue; - } - assert(Op.isImm()); - - // Handle optional arguments - OptionalIdx[Op.getImmTy()] = i; - } - - if ((int)Inst.getNumOperands() <= - AMDGPU::getNamedOperandIdx(Inst.getOpcode(), AMDGPU::OpName::offset)) - addOptionalImmOperand(Inst, Operands, OptionalIdx, - AMDGPUOperand::ImmTySMEMOffsetMod); - addOptionalImmOperand(Inst, Operands, OptionalIdx, AMDGPUOperand::ImmTyCPol, 0); -} - //===----------------------------------------------------------------------===// // smrd //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.td b/llvm/lib/Target/AMDGPU/SIInstrInfo.td index b0493edfa335a..02c769bf21ac3 100644 --- a/llvm/lib/Target/AMDGPU/SIInstrInfo.td +++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.td @@ -1078,6 +1078,8 @@ def highmod : NamedBitOperand<"high", "High">; def CPol : CustomOperand; def CPol_0 : DefaultOperand; def CPol_GLC1 : DefaultOperand; +def CPol_GLC : ValuePredicatedOperand; +def CPol_NonGLC : ValuePredicatedOperand; def TFE : NamedBitOperand<"tfe">; def UNorm : NamedBitOperand<"unorm">; diff --git a/llvm/lib/Target/AMDGPU/SMInstructions.td b/llvm/lib/Target/AMDGPU/SMInstructions.td index 7ca685a0cc5d5..6235965b6e165 100644 --- a/llvm/lib/Target/AMDGPU/SMInstructions.td +++ b/llvm/lib/Target/AMDGPU/SMInstructions.td @@ -234,8 +234,6 @@ class SM_Atomic_Pseudo : + Operand CPolTy = !if(isRet, CPol_GLC, CPol_NonGLC)> : SM_Atomic_Pseudo