Skip to content
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

[TableGen][SubtargetEmitter] Refactor hasReadOfWrite to CodeGenProcModel #92032

Merged

Conversation

michaelmaitland
Copy link
Contributor

@michaelmaitland michaelmaitland commented May 13, 2024

SubtargetEmitter::GenSchedClassTables takes a CodeGenProcModel, but calls hasReadOfWrite which loops over all ProcModels. We move hasReadOfWrite to CodeGenProcModel and remove the loop over all ProcModels. This leads to a 144% speedup on the RISC-V backend of our downstream.

…l argument

SubtargetEmitter::GenSchedClassTables takes a CodeGenProcModel, but
calls hasReadOfWrite which loops over all ProcModels. We overload hasReadOfWrite
to have a version that return true if the given write record is referenced by a
ReadAdvance for the specified ProcModel. This leads to a 144% speedup on
the RISC-V backend of our downstream.

This patch is purley performance related has no impact on the final generated
code.
@michaelmaitland michaelmaitland changed the title [TableGen][SubtargetEmitter] Refactor hasReadOfWrite to take ProcMode… [TableGen][SubtargetEmitter] Refactor hasReadOfWrite to take ProcModel argument May 13, 2024
Copy link
Contributor

@tmatheson-arm tmatheson-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if (!SchedModels.hasReadOfWrite(
SchedModels.getSchedWrite(WriteID).TheDef)) {
if (!SchedModels.hasReadOfWrite(SchedModels.getSchedWrite(WriteID).TheDef,
ProcModel)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code here checked all ProcModels not just this ProcModel. I'm surprised that this doesn't change the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to remove my statement that it does not change the output. It may change the output on some targets.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing the code, I think if it did change the output everything would still work. For each Write for each ProcModel we are creating a vector of MCWriteLatencyEntry objects. Then we search a large vector to if that sequence of MCWriteLatencyEntry already exists in somewhere in SchedTables.WriteLatencies. If we find the sequence we save its index. If we don't find it, we append the vector we have to the end of SchedTables.WriteLatencies and save the index where it was appended. The index is used to find the sequence later at runtime.

In the usual case we probably find the sequence once we've created it for the first ProcModel. I think at worst, this patch would make us not find it for some ProcModel and cause it to be added at the end. I don't think would be a functional issue. It would just make SchedTables.WriteLatencies larger.

llvm/utils/TableGen/Common/CodeGenSchedule.cpp Outdated Show resolved Hide resolved
llvm/utils/TableGen/Common/CodeGenSchedule.cpp Outdated Show resolved Hide resolved
@michaelmaitland michaelmaitland changed the title [TableGen][SubtargetEmitter] Refactor hasReadOfWrite to take ProcModel argument [TableGen][SubtargetEmitter] Refactor hasReadOfWrite to CodeGenProcModel May 14, 2024
Copy link

github-actions bot commented May 14, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@michaelmaitland michaelmaitland force-pushed the subtarget-emitter-hasreadofwrite branch from a183d4e to a71f334 Compare May 14, 2024 13:37
Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@michaelmaitland michaelmaitland merged commit 67beebf into llvm:main May 14, 2024
3 of 4 checks passed
mub-at-arm pushed a commit to mub-at-arm/llvm-project that referenced this pull request May 16, 2024
…del (llvm#92032)

SubtargetEmitter::GenSchedClassTables takes a CodeGenProcModel, but
calls hasReadOfWrite which loops over all ProcModels. We move
hasReadOfWrite to CodeGenProcModel and remove the loop over all
ProcModels. This leads to a 144% speedup on the RISC-V backend of our
downstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants