This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Add include guards to LLVMOption TableGen
ClosedPublic

Authored by modocache on Jun 27 2023, 1:39 PM.

Details

Summary

Add include guards that allow multiple includes of OptParser.td. This
is helpful when defining multiple sets of options in multiple files.
For example, a user could define a HelpOptions.td file that defines
only -h and --help:

// HelpOptions.td
include "llvm/Option/OptParser.td"

def HelpOptionGroup : OptionGroup<"Help Options">;
def help : Flag<["--", "-"], "help">, Group<HelpOptionGroup>,
           Flags<[]>;
def : Flag<["-"], "h">, Group<HelpOptionGroup>, Flags<[]>, Alias<help>;

This file could then be included into any TableGen file that wishes to
define these options:

// MyOptions.td
include "llvm/Option/OptParser.td"

def MyOptionGroup : OptionGroup<"My Options">;
// ...define my options.

// And also define `-h` and `--help`:
include "HelpOptions.td"

This currently isn't possible, because this would result in
OptParser.td being included twice. Alternatively, the include of
OptParser.td in the HelpOptions.td example above could be removed,
but then llvm-tblgen --gen-opt-parser-defs HelpOptions.td would fail
(because the OptionGroup and Option records are defined in
OptParser.td).

Diff Detail

Event Timeline

modocache created this revision.Jun 27 2023, 1:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2023, 1:39 PM
modocache requested review of this revision.Jun 27 2023, 1:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2023, 1:39 PM
rriddle accepted this revision.Jun 27 2023, 1:45 PM

Seems like an objective improvement for enabling self-contained tablegen files, and shouldn't negatively impact any existing flow AFAICT.

This revision is now accepted and ready to land.Jun 27 2023, 1:45 PM
This revision was landed with ongoing or failed builds.Jun 27 2023, 5:21 PM
This revision was automatically updated to reflect the committed changes.