aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Driver.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-01-11[OpenMP] Adjust phases for AMDGPU offloading for OpenMP in save-temps modeJoseph Huber1-30/+21
Currently, the behaviour of `-save-temps` changes the generated output when offloading to AMDGPU. This is because we only have a single phase and it contains the `-disable-llvm-passes` flags which results in unoptimized bitcode. We need to make sure we generate another phase that produces both the optimized and unoptimized bitcode. There used to be a check that turned these phases into a no-op. But I believe it is more correct to not generate them this way in the first place. Doing this requires a bit of a hack, replacing an already generated phase action, but it should be fine. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D141440
2023-01-11[OpenMP] Add support for '--offload-arch=native' to OpenMP offloadingJoseph Huber1-17/+56
This patch adds support for '--offload-arch=native' to OpenMP offloading. This will automatically generate the toolchains required to fulfil whatever GPUs the user has installed. Getting this to work requires a bit of a hack. The problem is that we need the ToolChain to launch its searching program. But we do not yet have that ToolChain built. I had to temporarily make the ToolChain and also add some logic to ignore regular warnings & errors. Depends on D141078 Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D141105
2023-01-11[CUDA][HIP] Support '--offload-arch=native' for the new driverJoseph Huber1-5/+19
This patch applies the same handling for the `--offload-arch=native' string to the new driver. The support for OpenMP will require some extra logic to infer the triples from the derived architecture strings. Depends on D141051 Reviewed By: tra Differential Revision: https://reviews.llvm.org/D141078
2023-01-11[CUDA][HIP] Add support for `--offload-arch=native` to CUDA and refactorJoseph Huber1-11/+13
This patch adds basic support for `--offload-arch=native` to CUDA. This is done using the `nvptx-arch` tool that was introduced previously. Some of the logic for handling executing these tools was factored into a common helper as well. This patch does not add support for OpenMP or the "new" driver. That will be done later. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D141051
2023-01-06[OpenMP] Introduce '-f[no-]openmp-target-jit' flag to control JIT for offloadingJoseph Huber1-0/+11
JIT support for OpenMP offloading was introduced in D139287. This patch adds a simple flag that enables this mode. It simply requires enabling `-foffload-lto` mode and `--embed-bitcode` in the linker wrapper. This option implies LTO if it is not enabled. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D141158
2022-12-17std::optional::value => operator*/operator->Fangrui Song1-1/+1
value() has undesired exception checking semantics and calls __throw_bad_optional_access in libc++. Moreover, the API is unavailable without _LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). This fixes clang.
2022-12-13[HIP] support --offload-arch=nativeYaxun (Sam) Liu1-0/+11
This patch detects system GPU and use them in --offload-arch if 'native' is specified. If system GPU cannot be detected clang will fall back to the default GPU arch. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D139045
2022-12-07Add support for a backdoor driver option that enables emitting headerAkira Hatanaka1-1/+1
usage information in JSON to a file Each line in the file is a JSON object that has the name of the main source file followed by the list of system header files included directly or indirectly from that file. For example: {"source":"/tmp/foo.c", "includes":["/usr/include/stdio.h", "/usr/include/stdlib.h"]} To reduce the amount of data written to the file, only the system headers that are directly included from a non-system header file are recorded. In order to emit the header information in JSON, it is necessary to set the following environment variables: CC_PRINT_HEADERS_FORMAT=json CC_PRINT_HEADERS_FILTERING=only-direct-system The following combination is equivalent to setting CC_PRINT_HEADERS=1: CC_PRINT_HEADERS_FORMAT=textual CC_PRINT_HEADERS_FILTERING=none Differential Revision: https://reviews.llvm.org/D137996
2022-12-06Process: convert Optional to std::optionalKrzysztof Parzyszek1-3/+4
This applies to GetEnv and FindInEnvPath.
2022-12-03[Driver] llvm::Optional => std::optionalFangrui Song1-11/+11
and change a few referenced Basic and llvm/lib/WindowsDriver API
2022-12-03[clang] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[Driver] llvm::None => std::nullopt. NFCFangrui Song1-10/+10
2022-12-02[clang][Driver] Don't overwrite `DiagnosticsEngine::IgnoreAllWarnings`, rely ↵Volodymyr Sapsai1-3/+0
on `DiagnosticOptions::IgnoreWarnings` value. Driver overwrites `DiagnosticsEngine::IgnoreAllWarnings` based on `-w` flag without taking into account `DiagnosticOptions::IgnoreWarnings` that is propagated to `DiagnosticsEngine` in `ProcessWarningOptions` (called from `CompilerInstance::createDiagnostics`). It makes it hard to manipulate `DiagnosticOptions` directly and pushes towards string-based API. Most of in-tree tools use `DiagnosticOptions` already, so migrate `clang_parseTranslationUnit_Impl` to use it too. Don't parse `-w` directly but rely on ``` def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">, Flags<[CC1Option]>, MarshallingInfoFlag<DiagnosticOpts<"IgnoreWarnings">>; ``` Allows to reland D138252. Differential Revision: https://reviews.llvm.org/D138970
2022-12-01Support: Convert Program APIs to std::optionalMatt Arsenault1-1/+1
2022-11-18[C++20] [Modules] Remove unmaintained Header ModuleChuanqi Xu1-21/+1
Currently there is a -emit-header-module mode, which can combine several headers together as a module interface. However, this breaks our assumption (for standard c++ modules) about module interface. The module interface should come from a module interface unit. And if it is a header, it should be a header unit. And currently we have no ideas to combine several headers together. So I think this mode is an experimental one and it is not maintained and it is not used. So it will be better to remove them. Reviewed By: Bigcheese, dblaikie, bruno Differential Revision: https://reviews.llvm.org/D137609
2022-11-16[clang][Driver] allow tilde in user config dirMichał Górny1-3/+7
This patch allows users to configure clang with option e.g. `-DCLANG_CONFIG_FILE_USER_DIR=~/.config/clang` or invoke clang with `--config-user-dir=~/.config/clang`. Patch merged on behalf of @paperchalice (LJC) Differential Revision: https://reviews.llvm.org/D136940
2022-11-16[Driver] Enable nested configuration filesSerge Pavlov1-5/+0
Users may partition parameters specified by configuration file and put different groups into separate files. These files are inserted into the main file using constructs `@file`. Relative file names in it are resolved relative to the including configuration file and this is not convenient in some cases. A configuration file, which resides in system directory, may need to include a file with user-defined parameters and still provide default definitions if such file is absent. To solve such problems, the option `--config=` is allowed inside configuration files. Like `@file` it results in insertion of command-line arguments but the algorithm of file search is different and allows overriding system definitions with user ones. Differential Revision: https://reviews.llvm.org/D136354
2022-11-10[clang] Only use major version in resource dirTimm Bäder1-1/+1
This causes unnecessary churn for downstreams. For the full discussion, see https://discourse.llvm.org/t/should-we-continue-embed-the-full-llvm-version-in-lib-clang/62094 Differential Revision: https://reviews.llvm.org/D125860
2022-11-08[Driver] Refactor err_drv_unsupported_option_argument call sites to use ↵Fangrui Song1-2/+2
llvm::opt::Arg::getSpelling For `-foo=bar`, getSpelling return `-foo=` which is exactly what we need from the diagnostic. Drop `-` from the err_drv_unsupported_option_argument template. This change makes `--` long option diagnostics more convenient. Reviewed By: lenary Differential Revision: https://reviews.llvm.org/D137659
2022-11-08Fix duplicate word typos; NFCRageking81-1/+1
This revision fixes typos where there are 2 consecutive words which are duplicated. There should be no code changes in this revision (only changes to comments and docs). Do let me know if there are any undesirable changes in this revision. Thanks.
2022-11-03[Driver] Don't preprocess source files when reproducing linker crashesAlex Brachet1-20/+29
It's not necessary to redo the source file preprocessing for reproducing linker crashes because we must have successfully created the object file by this point. Skip this step, and also don't report the preprocessed source file or create the clang invocation shell script. The latter is no longer sensible without the preprocessed source, or helpful given the linker reproducer will have it's own shell script. Differential Revision: https://reviews.llvm.org/D137289
2022-10-31Handle errors in expansion of response filesSerge Pavlov1-8/+19
Previously an error raised during an expansion of response files (including configuration files) was ignored and only the fact of its presence was reported to the user with generic error messages. This made it difficult to analyze problems. For example, if a configuration file tried to read an inexistent file, the error message said that 'configuration file cannot be found', which is wrong and misleading. This change enhances handling errors in the expansion so that users could get more informative error messages. Differential Revision: https://reviews.llvm.org/D136090
2022-10-30Revert "Handle errors in expansion of response files"Serge Pavlov1-19/+8
This reverts commit 17eb198de934eced784e16ec15e020a574ba07e1. Reverted for investigation, because ClangDriverTests failed on some builders.
2022-10-29Handle errors in expansion of response filesSerge Pavlov1-8/+19
Previously an error raised during an expansion of response files (including configuration files) was ignored and only the fact of its presence was reported to the user with generic error messages. This made it difficult to analyze problems. For example, if a configuration file tried to read an inexistent file, the error message said that 'configuration file cannot be found', which is wrong and misleading. This change enhances handling errors in the expansion so that users could get more informative error messages. Differential Revision: https://reviews.llvm.org/D136090
2022-10-19Keep configuration file search directories in ExpansionContext. NFCSerge Pavlov1-50/+24
Class ExpansionContext encapsulates options for search and expansion of response files, including configuration files. With this change the directories which are searched for configuration files are also stored in ExpansionContext. Differential Revision: https://reviews.llvm.org/D135439
2022-10-12[Clang] Do not crash when an invalid offload architecture is setJoseph Huber1-5/+17
If an invalid architecture is set we currently return an empty string. This will cause the offloading toolchain to continue to be built and hit an assertion elsewhere due to the invalid architecture. This patch fixes that so we now correctly exit. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D135791
2022-10-11[Clang] Do not build the OffloadActionBuilder when using the new driverJoseph Huber1-10/+13
The Offloading toolchain currently has two methods for construction the requires actions. The "new" driver and the old `OffloadActionBuilder`. Using either one is mutually exclusive, so we should not initialize this when using the new driver. This was causing some error messages to be printed multiple times because we were checking them in both the old and the new driver. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D135715
2022-10-06[Clang] Emit a warning for ambiguous joined '-o' argumentsJoseph Huber1-0/+13
The offloading toolchain makes heavy use of options beginning with `--o`. This is problematic when combined with the joined `-o` flag. In the following situation, the user will not get the expected output and will not notice as the expected output will still be written. ``` clang++ -x cuda foo.cu -offload-arch=sm_80 -o foo ``` This patch introduces a warning that checks for joined `-o` arguments that would also be a valid driver argument if an additional `-` were added. I believe this situation is uncommon enough to warrant a warning, and can be trivially fixed by the end user by using the more common separate form instead. Reviewed By: tra, MaskRay Differential Revision: https://reviews.llvm.org/D135389
2022-10-06[Clang] Fix using LTO with the new driver in RDC-modeJoseph Huber1-1/+3
The new driver supports LTO for RDC-mode compilations. However, this was not correctly handled for non-LTO compilations. HIP can handle this as it is fed to `lld` which will perform the LTO itself. CUDA however would require every work which is wholly useless in non-RDC mode so it should report an error. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D135305
2022-10-03[ARM64EC][clang-cl] Add /arm64EC flagchenglin.bi1-0/+10
Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D134788
2022-09-30[clang] [Driver] Disable default configs via envvar during testingMichał Górny1-0/+7
Add support for a CLANG_NO_DEFAULT_CONFIG envvar that works like the --no-default-config option when set to a non-empty value. Use it to disable loading system configuration files during the test suite runs. Configuration files can change the driver behavior in extensive ways, and it is neither really possible nor feasible to account for or undo the effects of even the most common configuration uses. Therefore, the most reasonable option seems to be to ignore configuration files while running the majority of tests (with the notable exception of tests for configuration file support). Due to the diversity of ways that %clang is used in the test suite, including using it to copy or symlink the clang executable, as well to call -cc1 and -cc1as modes, it is not feasible to pass the explicit options to disable config loading either. Using an environment variable has the advantage of being easily applied across the test suite and easily unset for default configuration file loading tests. Differential Revision: https://reviews.llvm.org/D134905
2022-09-29[clang] [Driver] More flexible rules for loading default configsMichał Górny1-63/+77
Change the default config file loading logic to be more flexible and more readable at the same time. The new algorithm focuses on four locations, in order: 1. <triple>-<mode>.cfg using real driver mode 2. <triple>-<mode>.cfg using executable suffix 3. <triple>.cfg + <mode>.cfg using real driver mode 4. <triple>.cfg + <mode>.cfg using executable suffix This is meant to preserve reasonable level of compatibility with the existing use, while introducing more flexibility and making the code simpler. Notably: 1. In this layout, the actual target triple is normally respected, and e.g. in `-m32` build the `x86_64-*` configs will never be used. 2. Both real driver mode (preferable) and executable suffix are supported. This permits correctly handling calls with explicit `--driver-mode=` while at the same time preserving compatibility with the existing code. 3. The first two locations provide users with the ability to override configuration per specific target+mode combinaton, while the next two make it possible to independently specify per-target and per-mode configuration. 4. All config file locations are applicable independently of whether clang is started via a prefixed executable, or bare `clang`. 5. If the target is not explicitly specified and the executable prefix does not name a valid triple, it is used instead of the actual target triple for backwards compatibility. This is particularly meant to address Gentoo's use case for configuration files: to configure the default runtimes (i.e. `-rtlib=`, `-stdlib=`) and `--gcc-install-dir=` for all the relevant drivers, as well as to make it more convenient for users to override `-W` flags to test compatibility with future versions of Clang easier. Differential Revision: https://reviews.llvm.org/D134337
2022-09-29[Support] Class for response file expansion (NFC)Serge Pavlov1-1/+3
Functions that implement expansion of response and config files depend on many options, which are passes as arguments. Extending the expansion requires new options, it in turn causes changing calls in various places making them even more bulky. This change introduces a class ExpansionContext, which represents set of options that control the expansion. Its methods implements expansion of responce files including config files. It makes extending the expansion easier. No functional changes. Differential Revision: https://reviews.llvm.org/D132379
2022-09-28Revert "[Support] Class for response file expansion (NFC)"Serge Pavlov1-3/+1
This reverts commit 6e491c48d6b9cadcc5b77f730dd83a1448197329. There are missed changes in flang.
2022-09-28[Support] Class for response file expansion (NFC)Serge Pavlov1-1/+3
Functions that implement expansion of response and config files depend on many options, which are passes as arguments. Extending the expansion requires new options, it in turn causes changing calls in various places making them even more bulky. This change introduces a class ExpansionContext, which represents set of options that control the expansion. Its methods implements expansion of responce files including config files. It makes extending the expansion easier. No functional changes. Differential Revision: https://reviews.llvm.org/D132379
2022-09-27[Driver] Silence a -Wparentheses error. NFCCraig Topper1-2/+2
2022-09-27[Driver] Prevent Mips specific code from claiming -mabi argument on other ↵Craig Topper1-25/+27
targets. Fixes PR57976. Reviewed By: erichkeane, arichardson, MaskRay Differential Revision: https://reviews.llvm.org/D134671
2022-09-26[HIP] Fix unbundling archiveYaxun (Sam) Liu1-2/+6
HIP is able to unbundle archive of bundled bitcode. However currently there are two bugs: 1. archives passed by -l: are not unbundled. 2. archives passed as input files are not unbundled The actual file name of an archive passed by -l: should not be prefixed with lib and appended with '.a', but the file path is prefixed with paths in '-L' options. The actual file name of an archive passed as an input file stays the same, not affected by the '-L' options.
2022-09-24[Clang] Make Clang driver suggest '-Xclang' for CC1 options passed to the driverJoseph Huber1-5/+11
This patch adds an additional check for if an options passed to the Clang driver could've been intended for the clang compiler. This is primarily done for the times when a user attempts to pass an option like `-ast-dump` to the driver instead. Reviewed By: MaskRay, aaron.ballman Differential Revision: https://reviews.llvm.org/D134550
2022-09-21[clang] [Driver] Support multiple configuration filesMichał Górny1-68/+71
Support specifying multiple configuration files via multiple `--config` options. When multiple files are specified, the options from subsequent files are appended to the options from the initial file. While at it, remove the incorrect assertion about CfgFileName being non-empty. It can be empty if `--config ""` is passed, and it makes sense to report it as non-existing file rather than crash. Differential Revision: https://reviews.llvm.org/D134270
2022-09-20[clang] [Driver] Do not transform explicit --config filenameMichał Górny1-18/+20
Disable transformations (e.g. attempting to replace target architecture) in the config filename that is passed explicitly via `--config`. This behavior is surprising and confusing -- if user passes an explicit config filename, Clang should use it as is. The transformations are still applied when the name is deduced from filename. Update the tests accordingly. This primarily ensures that full filename with .cfg suffix is passed to --config (appending `.cfg` implicitly is not documented, and would collide with use of filenames with other suffixes). The config-file2.c suite is removed entirely as it tested the transformations on the argument to --config. However, the aspects of that that were not tested as part of config-file3.c are now added there (based on config filename deduced from executable). This change streamlines the code in Driver::loadConfigFile(), opening the possibility of further changes, including support for handling multiple --config options and refactoring of filename deduction. Differential Revision: https://reviews.llvm.org/D134208
2022-09-19[CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-modeJoseph Huber1-1/+1
Previously when using the `clang-offload-packager` we did not pass the active offloading kinds. Then in Clang when we attempted to detect when there was host-offloading action that needed to be embedded in the host we did not find it. This patch adds the active offloading kinds so we know when there is input to be embedded. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D134189
2022-09-19[CUDA][NFC] Rename 'addDeviceDepences' to 'addDeviceDependences' in ↵wanglian1-3/+3
DeviceActionBuilder. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D134007
2022-09-16[clang] [Driver] Add an option to disable default config filenamesMichał Górny1-5/+8
Add a `--no-default-config` option that disables the search for default set of config filenames (based on the compiler executable name). Suggested in https://discourse.llvm.org/t/rfc-adding-a-default-file-location-to-config-file-support/63606. Differential Revision: https://reviews.llvm.org/D134018
2022-09-09[Clang] Use virtual FS in processing config filesSerge Pavlov1-16/+23
Clang has support of virtual file system for the purpose of testing, but treatment of config files did not use it. This change enables VFS in it as well. Differential Revision: https://reviews.llvm.org/D132867
2022-09-09Revert "[Clang] Use virtual FS in processing config files"Serge Pavlov1-23/+16
This reverts commit 9424497e43aff088e014d65fd952ec557e28e6cf. Some buildbots failed, reverted for investigation.
2022-09-09[Clang] Use virtual FS in processing config filesSerge Pavlov1-16/+23
Clang has support of virtual file system for the purpose of testing, but treatment of config files did not use it. This change enables VFS in it as well. Differential Revision: https://reviews.llvm.org/D132867
2022-09-06[CUDA] Fix test failing when using the new driverJoseph Huber1-1/+1
Summary: Previously the new driver crashed when using `-fsyntax-only` which required a work-around in one of the test files. This was not properly updated when it was fixed for the new driver. This patch fixes the test and also adjusts a missing boolean check.
2022-09-06[Clang] Fix the new driver crashing when using '-fsyntax-only'Joseph Huber1-3/+11
The new driver currently crashses when attempting to use the '-fsyntax-only' option. This is because the option causes all output to be given the `TY_Nothing' type which should signal the end of the pipeline. The new driver was not treating this correctly and attempting to use empty input. This patch fixes the handling so we do not attempt to continue when the input is nothing. One concession is that we must now check when generating the arguments for Clang if the input is of 'TY_Nothing'. This is because the new driver will only create code if the device code is a dependency on the host, creating the output without the dependency would require a complete rewrite of the logic as we do not maintain any state between calls to 'BuildOffloadingActions' so I believe this is the most straightforward method. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D133161
2022-09-06[OpenMP] Remove use of removed '-f[no-]openmp-new-driver' flagJoseph Huber1-3/+1
The changes in D130020 removed all support for the old method of compiling OpenMP offloading programs. This means that `-fopenmp-new-driver` has no effect and `-fno-openmp-new-driver` does not work. This patch removes the use and documentation of this flag. Note that the `--offload-new-driver` flag still exists for using the new driver optionally with CUDA and HIP. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D133367