This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Extract common `OptTable` bits into macros
ClosedPublic

Authored by jansvoboda11 on Aug 3 2023, 1:20 PM.

Details

Summary

All command-line tools using llvm::opt create an enum of option IDs and a table of OptTable::Info object. Most of the tools use the same ID (OPT_##ID), kind (Option::KIND##Class), group ID (OPT_##GROUP) and alias ID (OPT_##ALIAS). This patch extracts that common code into canonical macros. This results in fewer changes when tweaking the OPTION macros emitted by the TableGen backend.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Aug 3 2023, 1:20 PM
jansvoboda11 requested review of this revision.Aug 3 2023, 1:20 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptAug 3 2023, 1:20 PM

I'll be away for a few days but I took a quick glance. This change looks reasonable. Thanks!

Here's an example of a patch that changes the OPTION macro: D157029. I wonder if we could have counterparts to LLVM_MAKE_OPT_ID and LLVM_CONSTRUCT_OPT_INFO that allow overriding the default OPT_ prefix. That would make D157029 even smaller. WDYT @MaskRay?

Consolidate all usages by extra _WITH_ID_PREFIX macros

MaskRay accepted this revision.Aug 3 2023, 7:22 PM

Here's an example of a patch that changes the OPTION macro: D157029. I wonder if we could have counterparts to LLVM_MAKE_OPT_ID and LLVM_CONSTRUCT_OPT_INFO that allow overriding the default OPT_ prefix. That would make D157029 even smaller. WDYT @MaskRay?

The #define OPTION(...) LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(COFF_OPT_, __VA_ARGS__), use case looks good:)

This revision is now accepted and ready to land.Aug 3 2023, 7:22 PM
MaskRay added inline comments.Aug 3 2023, 7:36 PM
lld/ELF/Driver.h
28

lld/wasm lld/COFF lld/MachO are not updated?

Convert missed LLD parts.

Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 8:32 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
jansvoboda11 added inline comments.Aug 3 2023, 8:33 PM
lld/ELF/Driver.h
28

You're right, I accidentally missed some LLD parts. Updated.

This revision was automatically updated to reflect the committed changes.