This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] CheckSchedClassTables - check for unnecessary scheduler overrides
Needs ReviewPublic

Authored by RKSimon on Nov 19 2022, 9:42 AM.

Details

Summary

Pulled out of D47637, which was based off some internal work I did years ago but got lost in the upstreaming process.

This patch adds a SubtargetEmitter::CheckSchedClassTables method to verify the state of the scheduler classes. A command line switch "-check-sched-class-table" is added, which is enabled by default for EXPENSIVE_CHECKS builds.

So far this just adds checks for unnecessary overrides of base classes (which typically end up causing bloat in the generated tables), but future patches will add additional checks similar to earlier versions of D47637 and D48222.

The number of unnecessary overrides that are listed are quite extensive (warnings are currently found in the AMDGPU, ARM, AArch64, PowerPC and X86 targets), I'm not convinced they need to be addressed before this patch is committed, although the spam in EXPENSIVE_CHECKS builds is pretty large, but I'm happy to help create bugs/patches to fix them first if reviewers would prefer it.

Diff Detail

Event Timeline

RKSimon created this revision.Nov 19 2022, 9:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2022, 9:42 AM
RKSimon requested review of this revision.Nov 19 2022, 9:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2022, 9:42 AM

Just how more extra noisy does it become?

RKSimon added inline comments.Nov 19 2022, 11:21 AM
llvm/include/llvm/MC/MCSchedule.h
158

Sorry - I should have removed the "NumReadAdvanceEntries == 0" entry, it was just an experiment

RKSimon edited the summary of this revision. (Show Details)Nov 19 2022, 11:22 AM
RKSimon removed a reviewer: sdardis.

Just how more extra noisy does it become?

Current warnings:
AMDGPU - 1
AArch64 - 3049
ARM - 992
PowerPC - 244
X86 - 227

Actually its worse than I thought so almost definitely needs addressing before this can land :)

Just how more extra noisy does it become?

Current warnings:
AMDGPU - 1
AArch64 - 3049
ARM - 992
PowerPC - 244
X86 - 227

Actually its worse than I thought so almost definitely needs addressing before this can land :)

We can only find one overridden pair each time, right?

llvm/include/llvm/MC/MCSchedule.h
158

But the comment mentioned it too?

llvm/utils/TableGen/CodeGenSchedule.cpp
972

Not familiar with it, does the old function returns 0 too when fail to loopup?

llvm/utils/TableGen/SubtargetEmitter.cpp
1378

Do we need to break the loop?

We can only find one overridden pair each time, right?

Yes each warning is per instruction + per model - e.,g. there are usually 2 warnings for the znver1/2 overrides as they are basically copies of each other.

The x86 cases I'm slowly working through as I'm confident about what is going on - but for other targets my concern is that they've ended up with at least some overrides just so each model has the same entries, even though some are redundant.

RKSimon updated this revision to Diff 476735.Nov 20 2022, 2:56 AM

Remove "NumReadAdvanceEntries == 0" test code

RKSimon updated this revision to Diff 476737.Nov 20 2022, 2:57 AM

cleanup comment

RKSimon added inline comments.Nov 20 2022, 6:08 AM
llvm/utils/TableGen/CodeGenSchedule.cpp
1149

Something we could consider is checking here if the base and override classes COMPLETELY match and just don't bother using the override class? We should probably still warn though.

HaohaiWen added inline comments.Nov 23 2022, 1:12 AM
llvm/utils/TableGen/CodeGenSchedule.cpp
972

DenseMap returns new constructed value if not existed. In this case, it should be uninitialized unsigned.
Looks like return 0 is better.

SchedClasses.emplace_back(0, "NoInstrModel",
                          Records.getDef("NoItinerary"));
HaohaiWen added inline comments.Nov 23 2022, 1:38 AM
llvm/utils/TableGen/SubtargetEmitter.cpp
1378

Can we use InstRW to overwrite same instruction on same schedule model twice?
I tried and trigged assertion in CodeGenSchedule.cpp:1088.

RKSimon planned changes to this revision.Nov 23 2022, 2:15 AM

About to go on PTO - I will try to get these changes applied soon.

Matt added a subscriber: Matt.Feb 1 2023, 8:31 PM

I'm intending to resurrect this patch soon - most of the X86 warnings have been addressed but there are still a lot of ARM/AArch64/Power warnings that need cleaning up