This is an archive of the discontinued LLVM Phabricator instance.

Lazyly initialize uncommon toolchain detector
ClosedPublic

Authored by serge-sans-paille on Jan 26 2023, 12:48 AM.

Details

Summary

Cuda and rocm toolchain detectors are currently run unconditionally, while their result may not be used at all. Make their initialization lazy so that the discovery code is not run in common cases.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 12:48 AM
serge-sans-paille requested review of this revision.Jan 26 2023, 12:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 12:48 AM

Does this mean that clang will no longer search for the ROCM and CUDA library paths for every C compile?

Does this mean that clang will no longer search for the ROCM and CUDA library paths for every C compile?

That's the goal, yes.

Does this mean that clang will no longer search for the ROCM and CUDA library paths for every C compile?

That's the goal, yes.

That's great! Thanks for working on this. I think this looks OK, but someone with more C++ knowledge than me should probably look over the LazyDetector class implementation.

zero9178 added inline comments.
clang/lib/Driver/ToolChains/LazyDetector.h
26

Any reason this is mutable? I don't see it being used a non-const way in a const method

clang/lib/Driver/ToolChains/LazyDetector.h
26

yeah, T const *operator->() const updates the optional by actually creating the value. (std::optional::empalce is not const)

zero9178 added inline comments.Feb 2 2023, 4:31 AM
clang/lib/Driver/ToolChains/LazyDetector.h
26

Your T const *operator->() const method does not do so, T *operator->() does, which is non-const and hence can call emplace without issues.
So as far as C++ goes it is not required.

remove mutable qualifier

clang/lib/Driver/ToolChains/LazyDetector.h
26

gotcha :-)

tbaeder added a subscriber: tbaeder.Feb 5 2023, 2:09 AM
tbaeder added inline comments.
clang/lib/Driver/ToolChains/LazyDetector.h
37

Is the .value() here permitted? AFAIK the convention is to always use operator*.

And I think @aaron.ballman would tell you to drop the {} around that single-statement if :)

Address @tbader's comment

LGTM

clang/lib/Driver/ToolChains/LazyDetector.h
37

llvm style prefers const T to T const

This revision was not accepted when it landed; it landed in state Needs Review.Feb 6 2023, 3:05 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
TWeaver added a subscriber: TWeaver.Feb 6 2023, 6:42 AM

Hello all,

sorry to be a bother, but I believe this patch has caused a failure in this buildbot (and potentially others).

https://lab.llvm.org/buildbot/#/builders/109/builds/57277

Hahnfeld reopened this revision.Feb 6 2023, 6:42 AM
Hahnfeld added a subscriber: Hahnfeld.

This broke clang/test/Driver/rocm-detect.hip on a number of platforms (including the pre-merge checks on this PR), I've reverted for now in b5ee4f755fcff56243f6ff0cea9e7a722259304a.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 6 2023, 7:44 AM
This revision was automatically updated to reflect the committed changes.

(The first line of 0ffaffcaac97de31e1b0e7e80c4f7cab724eda20 should have mentioned Lazyly initialize uncommon toolchain detector. You can add Reland prefix or add the message in the body of the commit message.)
I fixed a -fsanitize-address-stack-use-after-scope issue in 6ab9f1e59371fe96ca3fda1a26a28ae0b7caf637