-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU] Fix operand definitions for atomic scalar memory instructions. #71799
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -909,6 +909,10 @@ class AMDGPUOperand : public MCParsedAsmOperand { | |
bool isWaitVDST() const; | ||
bool isWaitEXP() const; | ||
|
||
auto getPredicate(std::function<bool(const AMDGPUOperand &Op)> 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); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
// 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 | ||
//===----------------------------------------------------------------------===// | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be simpler to implement a couple more named predicate methods in
AMDGPUOperand
, e.g.:Anyway I don't object if you want to do it this way, but it took me a while to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer to have a single generic helper and use that to avoid scattering details of operand definitions over multiple places. Ultimately, the idea is to have an interface to AsmParser that would allow implementing a new kind of operands with a couple lines in a single place in an intuitive manner and not being wrong thinking it does the expected thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. In the long term do you think we should aim for a deisgn where all operand predicate strings in .td files are expressions involving
Op
(likeOp.isCPol()
) instead of just names of predicate methods (likeisCPol
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I see it more an implementation detail and would just do what seems most natural given the current state of things. My immediate impression is that
getPredicate()
basically works around AsmMatcherEmitter expecting the predicate be an operand method, which doesn't seem to work well for non-trivial cases.Speaking more generally, I would try to design it in such a way that wouldn't require specifying any predicate names explicitly at all, whether it's with or without the object expression.