Skip to content

[llvm][clang] Cherry-pick performance improvements to command line generation #7233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jansvoboda11
Copy link

No description provided.

@jansvoboda11 jansvoboda11 requested a review from artemcm August 15, 2023 20:25
@jansvoboda11
Copy link
Author

Locally, these tests fail for check-llvm and check-clang before and after this PR:

Failed Tests (7):
  LLVM :: CodeGen/AArch64/neon-dotreduce.ll
  LLVM :: DebugInfo/X86/debug-info-default-template-parameter.ll
  LLVM :: DebugInfo/X86/swift-async-entryvalues2.ll
  LLVM :: Instrumentation/AddressSanitizer/do-not-instrument-ptrauth-globals.ll
  LLVM :: ObjectYAML/Offload/binary.yaml
  LLVM :: ObjectYAML/Offload/multiple_members.yaml
  LLVM :: tools/yaml2obj/COFF/xrelocs.yaml
Failed Tests (3):
  Clang :: APINotes/objcxx-swift-name.m
  Clang :: SemaCXX/ptrauth-qualifier.cpp
  Clang-Unit :: Tooling/./ToolingTests/JSONCompilationDatabase/GetAllFiles

@artemcm
Copy link

artemcm commented Aug 15, 2023

Coooooool.

@jansvoboda11
Copy link
Author

@swift-ci please test

Since we now only support Visual Studio 2019 16.7 and newer, we're able to use the /Zc:preprocessor flag that turns on the standards-conforming preprocessor. Among other things, it correctly expands __VA_ARGS__. This enables removal of some boilerplate in D135128.

Reviewed By: Bigcheese, thieta

Differential Revision: https://reviews.llvm.org/D135128
Since we now only support Visual Studio 2019 16.7 and newer, we're able to use the `/Zc:preprocessor` flag that turns on the standards-conforming preprocessor. It (among other things) correctly expands `__VA_ARGS__` (see https://learn.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview?view=msvc-170#macro-arguments-are-unpacked). This enables us to get rid of some repetitive boilerplate in Clang's command-line parser/generator.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D135128
The `const char *` storage backing StringLiteral has static lifetime. Making `Twine` aware of that allows us to avoid allocating heap memory in some contexts (e.g. avoid passing it to `StringSaver::save()` in a follow-up Clang patch).

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D157010
The `Twine::str()` function currently always allocates heap memory via `std::string`. However, some instances of `Twine` don't need an intermediate buffer at all, and the rest can attempt to print into a stack buffer first.

This is intentionally not making use of `Twine::isSingleStringLiteral()` from D157010 to skip saving the string in the bump-pointer allocator, since the `StringSaver` documentation suggests that MUST happen for every given string.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D157015
This will make it possible to accept the spelling as `StringLiteral` in D157029 and avoid some unnecessary allocations in a later patch.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D157035
This patch abstracts away the string allocation and vector push-back from command line generation. Instead, **all** generated arguments are passed into `ArgumentConsumer`, which may choose to do the string allocation and vector push-back, or something else entirely.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D157046
This patch makes use of the infrastructure established in D157046 to avoid needless allocations via `StringSaver`.

Depends on D157046.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D157048
This patch makes use of the infrastructure established in D157046 to speed up computation of the canonical context hash in the dependency scanner. This is somewhat hot code, since it's ran for all modules in the dependency graph of every TU.

I also tried an alternative approach that tried to avoid allocations as much as possible (essentially doing `HashBuilder.add(Arg.toStringRef(ArgVec))`), but that turned out to be slower than approach in this patch.

Note that this is not problematic in the same way command-line hashing used to be prior D143027. The lambda is now being called even for constant strings.

Depends on D157046.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D157052
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.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D157028
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
… line

When generating command lines, use the option spelling generated by TableGen (`StringLiteral`) instead of constructing it at runtime. This saves some needless allocations.

Depends on D157029.

Reviewed By: benlangmuir, MaskRay

Differential Revision: https://reviews.llvm.org/D157054
@jansvoboda11
Copy link
Author

swiftlang/swift#67950
@swift-ci please test

1 similar comment
@jansvoboda11
Copy link
Author

swiftlang/swift#67950
@swift-ci please test

@jansvoboda11 jansvoboda11 force-pushed the jan_svoboda/stable-20221013-cmdline-cherry-pick branch from f0c5816 to 72de458 Compare August 17, 2023 15:32
@jansvoboda11
Copy link
Author

swiftlang/swift#67950
@swift-ci please test

@jansvoboda11 jansvoboda11 merged commit 5e6d56a into stable/20221013 Aug 17, 2023
@jansvoboda11 jansvoboda11 deleted the jan_svoboda/stable-20221013-cmdline-cherry-pick branch August 17, 2023 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants