-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[AMDGPU] wip: MIR pretty printing for S_WAITCNT_FENCE_soft #150391
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
Closed
ssahasra
wants to merge
1
commit into
users/ssahasra/waitcnt-fence-soft
from
users/ssahasra/waitcnt-pretty-print
Closed
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 |
---|---|---|
|
@@ -12,10 +12,135 @@ | |
//===----------------------------------------------------------------------===// | ||
|
||
#include "AMDGPUMIRFormatter.h" | ||
#include "SIDefines.h" | ||
#include "SIMachineFunctionInfo.h" | ||
|
||
using namespace llvm; | ||
|
||
bool parseAtomicOrdering(StringRef Src, unsigned &Order) { | ||
Src.consume_front("."); | ||
for (unsigned I = 0; I <= (unsigned)AtomicOrdering::LAST; ++I) { | ||
if (Src == toIRString((AtomicOrdering)I)) { | ||
Order = I; | ||
return true; | ||
} | ||
} | ||
Order = ~0u; | ||
return false; | ||
} | ||
|
||
static const char *fmtScope(unsigned Scope) { | ||
static const char *Names[] = {"none", "singlethread", "wavefront", | ||
"workgroup", "agent", "system"}; | ||
return Names[Scope]; | ||
} | ||
|
||
bool parseAtomicScope(StringRef Src, unsigned &Scope) { | ||
Src.consume_front("."); | ||
for (unsigned I = 0; | ||
I != (unsigned)AMDGPU::SIAtomicScope::NUM_SI_ATOMIC_SCOPES; ++I) { | ||
if (Src == fmtScope(I)) { | ||
Scope = I; | ||
return true; | ||
} | ||
} | ||
Scope = ~0u; | ||
return false; | ||
} | ||
|
||
static const char *fmtAddrSpace(unsigned Space) { | ||
static const char *Names[] = {"none", "global", "lds", | ||
"scratch", "gds", "other"}; | ||
return Names[Space]; | ||
} | ||
|
||
bool parseOneAddrSpace(StringRef Src, unsigned &AddrSpace) { | ||
if (Src == "none") { | ||
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. StringSwitch? |
||
AddrSpace = (unsigned)AMDGPU::SIAtomicAddrSpace::NONE; | ||
return true; | ||
} | ||
if (Src == "flat") { | ||
AddrSpace = (unsigned)AMDGPU::SIAtomicAddrSpace::FLAT; | ||
return true; | ||
} | ||
if (Src == "atomic") { | ||
AddrSpace = (unsigned)AMDGPU::SIAtomicAddrSpace::ATOMIC; | ||
return true; | ||
} | ||
if (Src == "all") { | ||
AddrSpace = (unsigned)AMDGPU::SIAtomicAddrSpace::ALL; | ||
return true; | ||
} | ||
for (unsigned I = 1, A = 1; A <= (unsigned)AMDGPU::SIAtomicAddrSpace::LAST; | ||
A <<= 1, ++I) { | ||
if (Src == fmtAddrSpace(I)) { | ||
AddrSpace = A; | ||
return true; | ||
} | ||
} | ||
AddrSpace = ~0u; | ||
return false; | ||
} | ||
|
||
bool parseAddrSpace(StringRef Src, unsigned &AddrSpace) { | ||
Src = Src.trim(); | ||
Src.consume_front("."); | ||
while (!Src.empty()) { | ||
auto [First, Rest] = Src.split('.'); | ||
unsigned OneSpace; | ||
if (!parseOneAddrSpace(First, OneSpace)) | ||
return false; | ||
AddrSpace |= OneSpace; | ||
Src = Rest; | ||
} | ||
return true; | ||
} | ||
|
||
static void fmtAddrSpace(raw_ostream &OS, int64_t Imm) { | ||
OS << '.'; | ||
if (Imm == (unsigned)AMDGPU::SIAtomicAddrSpace::NONE) { | ||
OS << "none"; | ||
return; | ||
} | ||
if (Imm == (unsigned)AMDGPU::SIAtomicAddrSpace::FLAT) { | ||
OS << "flat"; | ||
return; | ||
} | ||
if (Imm == (unsigned)AMDGPU::SIAtomicAddrSpace::ATOMIC) { | ||
OS << "atomic"; | ||
return; | ||
} | ||
if (Imm == (unsigned)AMDGPU::SIAtomicAddrSpace::ALL) { | ||
OS << "all"; | ||
return; | ||
} | ||
|
||
ListSeparator LS{"."}; | ||
auto AddrSpace = (AMDGPU::SIAtomicAddrSpace)Imm; | ||
const auto LAST = (unsigned)AMDGPU::SIAtomicAddrSpace::LAST; | ||
|
||
for (unsigned A = 1, I = 1; A <= LAST; A <<= 1, ++I) { | ||
if (any(AddrSpace & (AMDGPU::SIAtomicAddrSpace)A)) | ||
OS << LS << StringRef(fmtAddrSpace(I)); | ||
} | ||
} | ||
|
||
static void printFenceOperand(raw_ostream &OS, const MachineInstr &MI, | ||
std::optional<unsigned int> OpIdx, int64_t Imm) { | ||
#define GET_IDX(Name) \ | ||
AMDGPU::getNamedOperandIdx(AMDGPU::S_WAITCNT_FENCE_soft, AMDGPU::OpName::Name) | ||
if (OpIdx == GET_IDX(Ordering)) { | ||
assert(Imm <= (unsigned)AtomicOrdering::LAST); | ||
OS << '.' << StringRef(toIRString((AtomicOrdering)Imm)); | ||
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. This should return StringRef in the first place? |
||
} else if (OpIdx == GET_IDX(Scope)) { | ||
assert(Imm < (unsigned)AMDGPU::SIAtomicScope::NUM_SI_ATOMIC_SCOPES); | ||
OS << '.' << StringRef(fmtScope(Imm)); | ||
} else if (OpIdx == GET_IDX(AddrSpace)) { | ||
fmtAddrSpace(OS, Imm); | ||
} | ||
#undef GET_IDX | ||
} | ||
|
||
void AMDGPUMIRFormatter::printImm(raw_ostream &OS, const MachineInstr &MI, | ||
std::optional<unsigned int> OpIdx, int64_t Imm) const { | ||
|
||
|
@@ -24,12 +149,46 @@ void AMDGPUMIRFormatter::printImm(raw_ostream &OS, const MachineInstr &MI, | |
assert(OpIdx == 0); | ||
printSDelayAluImm(Imm, OS); | ||
break; | ||
case AMDGPU::S_WAITCNT_FENCE_soft: | ||
printFenceOperand(OS, MI, OpIdx, Imm); | ||
break; | ||
default: | ||
MIRFormatter::printImm(OS, MI, OpIdx, Imm); | ||
break; | ||
} | ||
} | ||
|
||
static bool | ||
parseFenceParameter(const unsigned int OpIdx, int64_t &Imm, | ||
llvm::StringRef &Src, | ||
llvm::MIRFormatter::ErrorCallbackType &ErrorCallback) { | ||
#define GET_IDX(Name) \ | ||
AMDGPU::getNamedOperandIdx(AMDGPU::S_WAITCNT_FENCE_soft, AMDGPU::OpName::Name) | ||
if (OpIdx == (unsigned)GET_IDX(Ordering)) { | ||
unsigned Order = 0; | ||
if (!parseAtomicOrdering(Src, Order)) | ||
return ErrorCallback(Src.begin(), "Expected atomic ordering"); | ||
Imm = Order; | ||
return false; | ||
} | ||
if (OpIdx == (unsigned)GET_IDX(Scope)) { | ||
unsigned Scope = 0; | ||
if (!parseAtomicScope(Src, Scope)) | ||
return ErrorCallback(Src.begin(), "Expected atomic scope"); | ||
Imm = Scope; | ||
return false; | ||
} | ||
if (OpIdx == (unsigned)GET_IDX(AddrSpace)) { | ||
unsigned AddrSpace = 0; | ||
if (!parseAddrSpace(Src, AddrSpace)) | ||
return ErrorCallback(Src.begin(), "Expected address space"); | ||
Imm = AddrSpace; | ||
return false; | ||
} | ||
return true; | ||
#undef GET_IDX | ||
} | ||
|
||
/// Implement target specific parsing of immediate mnemonics. The mnemonic is | ||
/// a string with a leading dot. | ||
bool AMDGPUMIRFormatter::parseImmMnemonic(const unsigned OpCode, | ||
|
@@ -41,6 +200,8 @@ bool AMDGPUMIRFormatter::parseImmMnemonic(const unsigned OpCode, | |
switch (OpCode) { | ||
case AMDGPU::S_DELAY_ALU: | ||
return parseSDelayAluImmMnemonic(OpIdx, Imm, Src, ErrorCallback); | ||
case AMDGPU::S_WAITCNT_FENCE_soft: | ||
return parseFenceParameter(OpIdx, Imm, Src, ErrorCallback); | ||
default: | ||
break; | ||
} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
Can we make AtomicOrdering work with enum_seq?