[llvm] [MISched] Extend overridePostRASchedPolicy to support per-function scheduling direction (PR #149297)
Harrison Hao via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 18 00:18:24 PDT 2025
harrisonGPU wrote:
@wangpc-pp @mshockwave @jroelofs Thanks a lot for the guidance!
I've now updated both `overridePostRASchedPolicy` and `overrideSchedPolicy`. In the new version, I'm passing `MachineBasicBlock` instead of `MachineFunction`.
For graphics shader compilers, we have different shader stages (e.g., vertex shader, fragment shader), which means each stage corresponds to a separate function within the same pipeline. We want to control the post-RA scheduling direction per function using function attributes. Although a function may have multiple scheduling regions, we believe the post-RA scheduling direction should remain consistent across all regions within the same function.
In a previous patch, I implemented this using a target feature, but we think a function attribute makes more sense for finer-grained control. So, I propose to extend the `overridePostRASchedPolicy` interface by adding `MachineBasicBlock` as an argument:
https://github.com/llvm/llvm-project/pull/147708
With this change, the backend can access the function attribute and select the post-RA scheduling direction accordingly. Here's the updated hook:
```cpp
void GCNSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
const MachineBasicBlock &MBB,
unsigned NumRegionInstr) const {
const Function &F = MBB.getParent()->getFunction();
Attribute PostRADirectionAttr = F.getFnAttribute("amdgpu-post-ra-direction");
if (!PostRADirectionAttr.isValid())
return;
StringRef PostRADirectionStr = PostRADirectionAttr.getValueAsString();
if (PostRADirectionStr == "topdown") {
Policy.OnlyTopDown = true;
Policy.OnlyBottomUp = false;
} else if (PostRADirectionStr == "bottomup") {
Policy.OnlyTopDown = false;
Policy.OnlyBottomUp = true;
} else if (PostRADirectionStr == "bidirectional") {
Policy.OnlyTopDown = false;
Policy.OnlyBottomUp = false;
} else {
DiagnosticInfoOptimizationFailure Diag(
F, F.getSubprogram(),
Twine("invalid value for post-ra direction attribute: '") +
PostRADirectionStr + "'");
F.getContext().diagnose(Diag);
}
}
```
https://github.com/llvm/llvm-project/pull/149297
More information about the llvm-commits
mailing list