This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Support warnings on unused classes and multiclasses.
Needs ReviewPublic

Authored by kosarev on Jun 7 2023, 7:32 AM.

Diff Detail

Event Timeline

kosarev created this revision.Jun 7 2023, 7:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 7:32 AM
kosarev requested review of this revision.Jun 7 2023, 7:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 7:32 AM

This still needs some polishing, proper tests and documentation and then maybe separating the AMDGPU changes, but some early feedback might be a help.

foad added a comment.Jun 7 2023, 7:36 AM

Nice! This looks very useful as a diagnostic tool. I'm not sure I'd ever want to have it enabled by default.

Yeah, I'd prefer the checks disabled by default in TableGen, but hope they can always be enabled for AMDGPU so we can catch unused bits as they appear rather than treat them later on occasional checks.

kosarev updated this revision to Diff 531344.Jun 14 2023, 8:15 AM

Separated AMDGPU changes, added tests and documentation.

kosarev retitled this revision from [AMDGPU][TableGen][WIP] Warn on unused classes and multiclasses. to [TableGen] Support warnings on unused classes and multiclasses..Jun 14 2023, 8:16 AM
kosarev edited the summary of this revision. (Show Details)
foad added a comment.Jun 15 2023, 1:55 AM

The implementation looks good to me, except perhaps for isInCommonTableGenHeader. It seems like you're inventing a new concept of C-like "system headers", which TableGen did not previously have.

The implementation looks good to me, except perhaps for isInCommonTableGenHeader. It seems like you're inventing a new concept of C-like "system headers", which TableGen did not previously have.

That was the intention, yes. I think conceptually the common .td files are part of the TableGen backends as much as system headers are part of a C implementation.

However, I guess the purity of the core TableGen code might still be of concern with the isInCommonTableGenHeader() hardcoding the paths, in which case something more explicit would probably work better, like instantiating a special class in such headers maybe?

// In include/llvm/CodeGen/ValueTypes.td.
// The file path in the source position of the definition should now
// be considered a path of a common TableGen header.
def : CommonTableGenHeader<"ValueTypes">;

As shown by the many related revisions, this is clearly a good idea.

I'm wracking my brain as for how the "common" TableGen files can be identified in a cleaner way. I don't like the def way, but something like a pragma common_header perhaps?

foad added a comment.Jun 29 2023, 2:00 AM

I'm wracking my brain as for how the "common" TableGen files can be identified in a cleaner way. I don't like the def way, but something like a pragma common_header perhaps?

Maybe you could specify on the command line which files you do want to see warnings in?
llvm-tblgen -warn-in=lib/Target/AMDGPU/ ...

Maybe you could specify on the command line which files you do want to see warnings in?
llvm-tblgen -warn-in=lib/Target/AMDGPU/ ...

Would be easy to implement, but feels a bit like we ask the user to provide information that should already be known to the system. To be compared with something like gcc --warn-in=foo.c foo.c.

I'm wracking my brain as for how the "common" TableGen files can be identified in a cleaner way. I don't like the def way, but something like a pragma common_header perhaps?

Yeah, a pragma was my first thought as well, so probably should be most natural and expected, though it's yet another concept to be added. Will try that.

The implementation looks good to me, except perhaps for isInCommonTableGenHeader. It seems like you're inventing a new concept of C-like "system headers", which TableGen did not previously have.

I like it, but maybe instead add the equivalent option (-isystem) and pass it from CMake? Paths may change, and there are also at least clang and mlir that might want to enable this warning.

As shown by the many related revisions, this is clearly a good idea.

I'm wracking my brain as for how the "common" TableGen files can be identified in a cleaner way. I don't like the def way, but something like a pragma common_header perhaps?

"common header" sounds rather vague. Maybe add a way to disable/enable specific warning?