aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Option/OptTable.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-01-22[StrTable] Switch the option parser to `llvm::StringTable` (#123308)Chandler Carruth1-34/+36
Now that we have a dedicated abstraction for string tables, switch the option parser library's string table over to it rather than using a raw `const char*`. Also try to use the `StringTable::Offset` type rather than a raw `unsigned` where we can to avoid accidental increments or other issues. This is based on review feedback for the initial switch of options to a string table. Happy to tweak or adjust if desired here.
2024-12-11Rework the `Option` library to reduce dynamic relocations (#119198)Chandler Carruth1-64/+91
Apologies for the large change, I looked for ways to break this up and all of the ones I saw added real complexity. This change focuses on the option's prefixed names and the array of prefixes. These are present in every option and the dominant source of dynamic relocations for PIE or PIC users of LLVM and Clang tooling. In some cases, 100s or 1000s of them for the Clang driver which has a huge number of options. This PR addresses this by building a string table and a prefixes table that can be referenced with indices rather than pointers that require dynamic relocations. This removes almost 7k dynmaic relocations from the `clang` binary, roughly 8% of the remaining dynmaic relocations outside of vtables. For busy-boxing use cases where many different option tables are linked into the same binary, the savings add up a bit more. The string table is a straightforward mechanism, but the prefixes required some subtlety. They are encoded in a Pascal-string fashion with a size followed by a sequence of offsets. This works relatively well for the small realistic prefixes arrays in use. Lots of code has to change in order to land this though: both all the option library code has to be updated to use the string table and prefixes table, and all the users of the options library have to be updated to correctly instantiate the objects. Some follow-up patches in the works to provide an abstraction for this style of code, and to start using the same technique for some of the other strings here now that the infrastructure is in place.
2024-09-13[LLVM][Option] Refactor option name comparison (#108219)Rahul Joshi1-34/+18
Move common functions shared by TableGen Option Emitter and Options library to Support: - Move `StrCmpOptionName` and base it on the existing version in OptTable.cpp, with an additional mode to control fall back to case insensitive comparison. - Add `StrCmpOptionPrefixes` to compare prefixes and use zip() to iterate through lists of prefixes. - Rename `CompareOptionRecords` to less ambiguous name `IsOptionRecordLess`. - Merge 2 back-to-back ifs with same condition in `IsOptionRecordLess`. Fixes https://github.com/llvm/llvm-project/issues/107723
2024-05-19[llvm] Use operator==(StringRef, StringRef) (NFC) (#92705)Kazu Hirata1-1/+1
2024-04-05Reland "[flang][clang] Add Visibility specific help text for options (#81869)"David Spickett1-6/+8
This reverts commit 67d20412b448533c77f54ac7a1e5d0775d273729. This includes fixes for clanginstallapi.
2024-04-05Revert "[flang][clang] Add Visibility specific help text for options (#81869)"David Spickett1-8/+6
This reverts commit 7e958f64efea6cb824e96ace51e021afbc150922. Failing on multiple bots.
2024-04-05[flang][clang] Add Visibility specific help text for options (#81869)David Spickett1-6/+8
And use it to print the correct default OpenMP version for flang and flang -fc1. This change adds an optional `HelpTextsForVariants` to options. This allows you to change the help text that gets shown in documentation and `--help` based on the program its being generated for. As `OptTable` needs to be constexpr compatible, I have used a std::array of help text variants. Each entry is: (list of visibilities) - > help text string So for the OpenMP version we have (flang, fc1) -> "OpenMP version for flang is...". So you can have multiple visibilities use the same string. The number of entries is currently set to 1, and the number of visibilities per entry is 2, because that's the maximum we need for now. The code is written so we can increase these numbers later, and the unused elements will be initialised. I have not applied this to group descriptions just because I don't know of one that needs changing. It could easily be enabled for those too if needed. There are minor changes to them just to get it all to compile. This approach of storing many help strings per option in the 1 driver library seemed preferable to making a whole new library for Flang (even if that would mostly be including stuff from Clang).
2023-12-14[OptTable] Make new lines in help text respect indentation (#75366)Andres Villegas1-4/+13
With this changes, new lines in the HelpText defined in OptTable have the same indentation as the first line. Before, the help output will look something like: ``` --color=<value> Whether to use color when symbolizing log markup: always, auto, never ``` With this change: ``` --color=<value> Whether to use color when symbolizing log markup: always, auto, never ```
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-6/+6
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-08-15[Driver] Refactor to use llvm Option's new Visibility flagsJustin Bogner1-1/+4
This is a big refactor of the clang driver's option handling to use the Visibility flags introduced in https://reviews.llvm.org/D157149. There are a few distinct parts, but they can't really be split into separate commits and still be made to compile. 1. We split out some of the flags in ClangFlags to ClangVisibility. Note that this does not include any subtractive flags. 2. We update the Flag definitions and OptIn/OptOut constructs in Options.td by hand. 3. We introduce and use a script, update_options_td_flags, to ease migration of flag definitions in Options.td, and we run that on Options.td. I intend to remove this later, but I'm committing it so that downstream forks can use the script to simplify merging. 4. We update calls to OptTable in the clang driver, cc1as, flang, and clangd to use the visibility APIs instead of Include/Exclude flags. 5. We deprecate the Include/Exclude APIs and add a release note. *if you are running into conflicts with this change:* Note that https://reviews.llvm.org/D157150 may also be the culprit and if so it should be handled first. The script in `clang/utils/update_options_td_flags.py` can help. Take the downstream side of all conflicts and then run the following: ``` % cd clang/include/clang/Driver % ../../../utils/update_options_td_flags.py Options.td > Options.td.new % mv Options.td.new Options.td ``` This will hopefully be sufficient, please take a look at the diff. Differential Revision: https://reviews.llvm.org/D157151
2023-08-15Reapply "[Option] Add "Visibility" field and clone the OptTable APIs to use it"Justin Bogner1-20/+108
This reverts commit 4e3b89483a6922d3f48670bb1c50a37f342918c6, with fixes for places I'd missed updating in lld and lldb. I've also renamed OptionVisibility::Default to "DefaultVis" to avoid ambiguity since the undecorated name has to be available anywhere Options.inc is included. Original message follows: This splits OptTable's "Flags" field into "Flags" and "Visibility", updates the places where we instantiate Option tables, and adds variants of the OptTable APIs that use Visibility mask instead of Include/Exclude flags. We need to do this to clean up a bunch of complexity in the clang driver's option handling - there's a whole slew of flags like CoreOption, NoDriverOption, and FlangOnlyOption there today to try to handle all of the permutations of flags that the various drivers need, but it really doesn't scale well, as can be seen by things like the somewhat recently introduced CLDXCOption. Instead, we'll provide an additive model for visibility that's separate from the other flags. For things like "HelpHidden", which is used as a "subtractive" modifier for option visibility, we leave that in "Flags" and handle it as a special case. Note that we don't actually update the users of the Include/Exclude APIs here or change the flags that exist in clang at all - that will come in a follow up that refactors clang's Options.td to use the increased flexibility this change allows. Differential Revision: https://reviews.llvm.org/D157149
2023-08-14Revert "[Option] Add "Visibility" field and clone the OptTable APIs to use it"Justin Bogner1-108/+20
this is failing on bots, reverting to investigate. This reverts commit a16104e6da6f36f3d72dbf53d10ba56495a0d65a.
2023-08-14[Option] Add "Visibility" field and clone the OptTable APIs to use itJustin Bogner1-20/+108
This splits OptTable's "Flags" field into "Flags" and "Visibility", updates the places where we instantiate Option tables, and adds variants of the OptTable APIs that use Visibility mask instead of Include/Exclude flags. We need to do this to clean up a bunch of complexity in the clang driver's option handling - there's a whole slew of flags like CoreOption, NoDriverOption, and FlangOnlyOption there today to try to handle all of the permutations of flags that the various drivers need, but it really doesn't scale well, as can be seen by things like the somewhat recently introduced CLDXCOption. Instead, we'll provide an additive model for visibility that's separate from the other flags. For things like "HelpHidden", which is used as a "subtractive" modifier for option visibility, we leave that in "Flags" and handle it as a special case. Note that we don't actually update the users of the Include/Exclude APIs here or change the flags that exist in clang at all - that will come in a follow up that refactors clang's Options.td to use the increased flexibility this change allows. Differential Revision: https://reviews.llvm.org/D157149
2023-08-09[llvm] Construct option's prefixed name at compile-timeJan Svoboda1-10/+10
Some Clang command-line handling code could benefit from the option's prefixed name being a `StringLiteral`. This patch changes the `llvm::opt` TableGen backend to generate and emit that into the .inc file. Depends on D157028. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D157029
2023-07-19Revert "[OptTable] Make explicitly included options override excluded ones"Justin Bogner1-4/+2
Looks like a couple of flang bots are broken by this change. Reverting to investigate. This reverts commit b2eda85f047f27788ccd7b9af9bd59c5d44b2051.
2023-07-19[OptTable] Make explicitly included options override excluded onesJustin Bogner1-2/+4
When we have both explicitly included and excluded option sets, we were excluding anything from the latter set regardless of what was in the former. This doesn't compose well and led to an overly complicated design around DXC options where a third flag was introduced to handle options that overlapped between DXC and CL. With this change we check the included options before excluding anything from the exclude list, which allows for options that are in multiple categories to be handled in a sensible way. This allows us to remove CLDXCOption but should otherwise be NFC. Differential Revision: https://reviews.llvm.org/D155729
2023-06-07[Option] Support special argument "--"Fangrui Song1-0/+10
Many command line option implementations, including getopt_long and our Support/CommandLine.cpp, support `--` as an end-of-option indicator. All the subsequent arguments are then treated as positional arguments. D1387 added KIND_REMAINING_ARGS and 76ff1d915c9c42823a3f2b08ff936cf7a48933c5 dropped special handling of `--`. Users need to add `def DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>;` and append `OPT_DASH_DASH` to the `OPT_INPUT` list., which is not ergonomic. Restore this feature under an option and modify llvm-strings to utilize the feature as an example. In the future, we probably should enable this feature by default and exclude some tools that handle `DASH_DASH` differently (clang, clang-scan-deps, etc. I suspect that many are workarounds for LLVMOption not supporting `--` as a built-in feature). Reviewed By: serge-sans-paille Differential Revision: https://reviews.llvm.org/D152286
2023-05-12[llvm] Migrate {starts,ends}with_insensitive to ↵Kazu Hirata1-1/+1
{starts,ends}_with_insensitive (NFC) This patch migrates uses of StringRef::{starts,ends}with_insensitive to StringRef::{starts,ends}_with_insensitive so that we can use names similar to those used in std::string_view. I'm planning to deprecate StringRef::{starts,ends}with_insensitive once the migration is complete across the code base. Differential Revision: https://reviews.llvm.org/D150426
2023-01-19[llvm] Cleanup edit_distance short circuitingserge-sans-paille1-3/+8
Also prevent integer overflow if MaximumDistance == UINT_MAX. This is a follow-up to 6ad1b4095172373590134afff19a7fbad9d7889d
2023-01-19Optimize OptTable::findNearest implementation and usageserge-sans-paille1-2/+11
When used to find an exact match, some extra context can be used to totally cut some computations. This saves 1% of the instruction count when pre processing sqlite3.c through valgrind --tool=callgrind ./bin/clang -E sqlite3.c -o/dev/null Differential Revision: https://reviews.llvm.org/D142026
2023-01-12[OptTable] Precompute OptTable prefixes union table through tablegenserge-sans-paille1-24/+33
This avoid rediscovering this table when reading each options, providing a sensible 2% speedup when processing and empty file, and a measurable speedup on typical workloads, see: This is optional, the legacy, on-the-fly, approach can still be used through the GenericOptTable class, while the new one is used through PrecomputedOptTable. https://llvm-compile-time-tracker.com/compare.php?from=4da6cb3202817ee2897d6b690e4af950459caea4&to=19a492b704e8f5c1dea120b9c0d3859bd78796be&stat=instructions:u Differential Revision: https://reviews.llvm.org/D140800
2023-01-12[OptTable] Make ValuesCode initialisation of Options constexprserge-sans-paille1-11/+0
Current implementation requires a copy of the initialization array to a vector to be able to modify their Values field. This is inefficient: it requires a large copy to update a value, while TableGen has all information to avoid this overwrite. Modify TableGen to emit the Values code and use it to perform the initialisation. The impact on performance is not amazing compared to the actual compilation, but still noticeable: https://llvm-compile-time-tracker.com/compare.php?from=d9ab3e82f30d646deff054230b0c742704a1cf26&to=f2b37fb65d5149f70b43d1801beb5239285a2a20&stat=instructions:u Differential Revision: https://reviews.llvm.org/D140699
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-1/+1
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-12-27[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-25/+15
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This a recommit of e953ae5bbc313fd0cc980ce021d487e5b5199ea4 and the subsequent fixes caa713559bd38f337d7d35de35686775e8fb5175 and 06b90e2e9c991e211fecc97948e533320a825470. The above patchset caused some version of GCC to take eons to compile clang/lib/Basic/Targets/AArch64.cpp, as spotted in aa171833ab0017d9732e82b8682c9848ab25ff9e. The fix is to make BuiltinInfo tables a compilation unit static variable, instead of a private static variable. Differential Revision: https://reviews.llvm.org/D139881
2022-12-25Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵Vitaly Buka1-15/+25
builtin and call information" Revert "Fix lldb option handling since e953ae5bbc313fd0cc980ce021d487e5b5199ea4 (part 2)" Revert "Fix lldb option handling since e953ae5bbc313fd0cc980ce021d487e5b5199ea4" GCC build hangs on this bot https://lab.llvm.org/buildbot/#/builders/37/builds/19104 compiling CMakeFiles/obj.clangBasic.dir/Targets/AArch64.cpp.d The bot uses GNU 11.3.0, but I can reproduce locally with gcc (Debian 12.2.0-3) 12.2.0. This reverts commit caa713559bd38f337d7d35de35686775e8fb5175. This reverts commit 06b90e2e9c991e211fecc97948e533320a825470. This reverts commit e953ae5bbc313fd0cc980ce021d487e5b5199ea4.
2022-12-24[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-25/+15
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This is a recommit of 719d98dfa841c522d8d452f0685e503538415a53 that into account a GGC issue (probably https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92181) when dealing with intiailizer_list and constant expressions. Workaround this by avoiding initializer list, at the expense of a temporary plain old array. Differential Revision: https://reviews.llvm.org/D139881
2022-12-23Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵serge-sans-paille1-15/+25
builtin and call information" There are still remaining issues with GCC 12, see for instance https://lab.llvm.org/buildbot/#/builders/93/builds/12669 This reverts commit 5ce4e92264102de21760c94db9166afe8f71fcf6.
2022-12-23[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-25/+15
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This is a recommit of 719d98dfa841c522d8d452f0685e503538415a53 with a change to llvm/utils/TableGen/OptParserEmitter.cpp to cope with GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 Differential Revision: https://reviews.llvm.org/D139881
2022-12-23Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵serge-sans-paille1-15/+25
builtin and call information" Failing builds: https://lab.llvm.org/buildbot#builders/9/builds/19030 This is GCC specific and has been reported upstream: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 This reverts commit 719d98dfa841c522d8d452f0685e503538415a53.
2022-12-23[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-25/+15
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139881
2022-12-16Use range based loop to iterate over OptTable::PrefixesUnionserge-sans-paille1-6/+3
And sneak in a small storage optimization of OptTable::PrefixChars
2022-12-09[NFC] Finish cleaning up StringRef usage in OptTable::ParseOneArgserge-sans-paille1-8/+11
This is a followup to https://reviews.llvm.org/D139274
2022-12-09Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2serge-sans-paille1-23/+15
Differential Revision: https://reviews.llvm.org/D139274
2022-12-09Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"serge-sans-paille1-16/+19
This reverts commit 4faf00006cf989f3ae212912994022c0486a2dc4.
2022-12-09Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2serge-sans-paille1-19/+16
Differential Revision: https://reviews.llvm.org/D139274
2022-12-07Revert "Store OptTable::Info::Name as a StringRef"serge-sans-paille1-21/+29
Another revert, for another set of issues I don't reproduce locally... see https://lab.llvm.org/buildbot/#/builders/139/builds/32327 This reverts commit bdfa3100dc3ea9e9ce4d3d4100ea6bb4c3fa2b81.
2022-12-07Store OptTable::Info::Name as a StringRefserge-sans-paille1-29/+21
This is a recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e, with a few cleanups. This avoids implicit conversion to StringRef at several points, which in turns avoid redundant calls to strlen. As a side effect, this greatly simplifies the implementation of StrCmpOptionNameIgnoreCase. It also eventually gives a consistent, humble speedup in compilation time (timing updated since original commit). https://llvm-compile-time-tracker.com/compare.php?from=76fcfea283472a80356d87c89270b0e2d106b54c&to=b70eb1f347f22fe4d2977360c4ed701eabc43994&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139274
2022-12-06Revert "Store OptTable::Info::Name as a StringRef"Douglas Yung1-15/+23
This reverts commit 5951b0bb23f3265bea16f28c2af9d278b9d829c6. This is causing 24 test failures on the PS4 linux bot: https://lab.llvm.org/buildbot/#/builders/139/builds/32263
2022-12-06Store OptTable::Info::Name as a StringRefserge-sans-paille1-23/+15
This is a recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e, with a few cleanups. This avoids implicit conversion to StringRef at several points, which in turns avoid redundant calls to strlen. As a side effect, this greatly simplifies the implementation of StrCmpOptionNameIgnoreCase. It also eventually gives a consistent, humble speedup in compilation time (timing updated since original commit). https://llvm-compile-time-tracker.com/compare.php?from=de4b6a1bc64db33643f001ad45fae7b92b4a4688&to=c23a93d1292052b4be2fbe8c586fa31143d0c7ed&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139274
2022-12-06Revert "Store OptTable::Info::Name as a StringRef"Nico Weber1-15/+23
This reverts commit 8ae18303f97d5dcfaecc90b4d87effb2011ed82e. Breaks buildling lldb, see https://reviews.llvm.org/D139274#3974171
2022-12-06Store OptTable::Info::Name as a StringRefserge-sans-paille1-23/+15
This avoids implicit conversion to StringRef at several points, which in turns avoid redundant calls to strlen. As a side effect, this greatly simplifies the implementation of StrCmpOptionNameIgnoreCase. It also eventually gives a consistent, humble speedup in compilation time. https://llvm-compile-time-tracker.com/compare.php?from=5f5b942823474e98e43a27d515a87ce140396c53&to=60e13b778119fc32d50dc38ff1a564a87146e9c6&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139274
2022-08-08[llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-1/+1
With C++17 there is no Clang pedantic warning or MSVC C5051.
2021-12-09[llvm] Use range-based for loops (NFC)Kazu Hirata1-5/+5
2021-12-02[llvm] Use range-based for loops (NFC)Kazu Hirata1-4/+3
2021-09-27[llvm/OptTable] Add named param comment for GroupedShortOptionNico Weber1-6/+8
2021-09-27[llvm/OptTable] Drop "The" prefix on fieldsNico Weber1-17/+11
2021-09-27[llvm] Convert OptTable::ParseOneArg() to std::unique_ptr<>Nico Weber1-10/+13
2021-09-27[llvm] Convert OptTable::parseOneArgGrouped() to std::unique_ptr<>Nico Weber1-8/+13
2021-09-27[llvm] ConvertOption::accept(), acceptInternal() to std::unique_ptr<>Nico Weber1-8/+9
These functions transfer ownership to the caller. Make this clear in the type system. No behavior change.
2021-09-03[OptTable] Reapply Improve error message output for grouped short optionsgbreynoo1-4/+13
This reapplies 71d7fed3bc2ad6c22729d446526a59fcfd99bd03 which was reverted by 3e2bd82f02c6cbbfb0544897c7645867f04b3a7e. This change includes the fix for breaking the sanitizer bots. As seen in https://bugs.llvm.org/show_bug.cgi?id=48880 the current implementation for parsing grouped short options can return unclear error messages. This change fixes the example given in the ticket in which a flag is incorrectly given an argument. Also when parsing a group we now keep reading past the first incorrect option and output errors for all incorrect options in the group. Differential Revision: https://reviews.llvm.org/D108770