This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] [ISel Matcher Emitter] Rework with two passes: one to size, one to emit
ClosedPublic

Authored by Paul-C-Anagnostopoulos on Nov 17 2020, 7:32 AM.

Details

Summary

This patch reworks DAGISelMatcherEmitter.cpp in order to speed it up. It now makes two passes over the matcher tree: one to size the matchers and one to emit them. This eliminates the relaxation method that was used to size the matchers previously. The emitter produces exactly the same output as before.

For the AMDGPU target, the emitting phase took 88.5% of the TableGen run; now it takes 3.5% of the time. On my machine the run went from 751 seconds to 89 seconds.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2020, 7:32 AM
Paul-C-Anagnostopoulos requested review of this revision.Nov 17 2020, 7:32 AM
foad added a subscriber: foad.Nov 17 2020, 8:49 AM

Looks good to me. I'm looking forward to the improved build times.

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
51

Did you mean to include this in this patch? It seems unrelated.

978

Seems unrelated?

arsenm added inline comments.Nov 17 2020, 9:08 AM
llvm/utils/TableGen/DAGISelMatcher.h
44

Probably should be size_t

I'll get this in as soon as there is some more review *and* I manage to reinstate my building ability. I just updated Visual Studio and can't build anything. Sigh.

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
51

This part of the update eliminates the extra pass over the matcher tree just to count the matcher kinds for the histogram. The counting was merged into the new first pass for sizing.

978

This part of the update eliminates the extra pass over the matcher tree just to count the matcher kinds for the histogram. The counting was merged into the new first pass for sizing.

llvm/utils/TableGen/DAGISelMatcher.h
44

Yes, I will fix this.

foad added inline comments.Nov 17 2020, 9:18 AM
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
51

Fair enough, sounds good!

Changed the child size to a size_t. And changed the VBR size to match.

I will auto-LGTM this revision on Friday.

RKSimon added inline comments.Nov 19 2020, 1:59 AM
llvm/utils/TableGen/DAGISelMatcher.h
92

We seem to mainly use this as "HighestKind + 1" - wouldn't a NumOfKinds / KindCount value be better (and wouldn't need the assignment to the previous enum value).

MorphNodeTo, // Build a node, finish a match and update results.
KindCount        // Total number of kind types.
llvm/utils/TableGen/DAGISelMatcher.h
92

I had that originally but changed my mind. Why? . . . Ah, because then the compiler complains when it isn't included in a switch on the kind. Is there a trick I don't know? Using default: just seems confusing.

RKSimon added inline comments.Nov 20 2020, 3:25 AM
llvm/utils/TableGen/DAGISelMatcher.h
92

OK - no worries for now then

RKSimon accepted this revision.Nov 20 2020, 10:11 AM

LGTM - thank you for working on this!

This revision is now accepted and ready to land.Nov 20 2020, 10:11 AM
RKSimon added inline comments.Oct 14 2021, 5:44 AM
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
1124

@Paul-C-Anagnostopoulos scan-build is warning that TotalSize is initialized but never read - is there anything useful we can do with TotalSize here?

https://llvm.org/reports/scan-build/report-DAGISelMatcherEmitter.cpp-EmitMatcherTable-39-50bd0b.html#EndPath

foad added inline comments.Oct 14 2021, 5:48 AM
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
1124

In a debug build I think it would make sense to assert that it matches the size calculated on line 1134.