-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Allow Specifying SGMasks for Inline Asm #155491
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-backend-amdgpu Author: Patrick Simmons (linuxrocks123) ChangesAddresses SWDEV-549227 Full diff: https://github.com/llvm/llvm-project/pull/155491.diff 1 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
index dbe74b1b08f8c..8c514714bd7dd 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
@@ -2391,6 +2391,16 @@ bool SchedGroup::canAddMI(const MachineInstr &MI) const {
if (MI.isMetaInstruction())
Result = false;
+ else if (MI.isInlineAsm()) {
+ std::string Text = MI.getOperand(0).getSymbolName();
+ if (Text.find("SGMASK:") != std::string::npos) {
+ Text = Text.substr(Text.find("SGMASK:") + strlen("SGMASK:"));
+ Text = Text.substr(0, Text.find_first_of(" \t\r\n"));
+ unsigned long InlineAsmMask = std::stoul(Text, nullptr, 0);
+ Result = ((unsigned long)SGMask & InlineAsmMask) != 0;
+ }
+ }
+
else if (((SGMask & SchedGroupMask::ALU) != SchedGroupMask::NONE) &&
(TII->isVALU(MI) || TII->isMFMAorWMMA(MI) || TII->isSALU(MI) ||
TII->isTRANS(MI)))
|
This PR allows the user to specify sched group barrier information for inline asm instructions. The mechanism for doing so is adding a comment with the text "SGMASK:" inside the inline asm string. The contents of "" should be the schedule barrier groups you want to group the inline asm with. So, for example, if your inline asm is a VALU instruction, you would have an inline asm statement that looks like this:
Because of the "SGMASK:0x2", sched group barrier instructions will now be able to recognize that the inline asm instruction is a VALU instruction and schedule it accordingly. |
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.
Needs tests. Also don't use c string functions, StringRef has everything on it directly.
I also don't love the idea of parsing something special out of inline assembly. The general way to handle inline asm is answer yes for every question, so just if (isInlineAsm()) return true
. If you want to try to be more refined than that, you can try to guess at the contents by the register constraints before dropping to scraping the asm contents
@arsenm Thanks, I switched to using Regarding the parsing of the inline assembly, the goal of this PR is to allow the user to optionally specify the schedule group mask for a specific inline assembly instruction to allow schedule group barriers to work correctly with that instruction. Parsing a special token out of the inline assembly is the only reasonable mechanism I currently see for accomplishing that, but I am open to suggestions. |
3286912
to
f0d70b2
Compare
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.
Same question for the other attributes and metadata.
@llvm.compiler.used = appending addrspace(1) global [1 x ptr] [ptr addrspacecast (ptr addrspace(1) @__hip_cuid_bffb86447932ec40 to ptr)], section "llvm.metadata" | ||
@__hip_cuid_bffb86447932ec40 = addrspace(1) global i8 0 |
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.
Is this needed for the test to work?
I am going to outright reject the concept of trying to parse the content of inline assembly. I am firmly in the camp of wont fixing any performance issue involving inline assembly |
#157080 also proposes codifying not doing things like this |
Addresses SWDEV-549227