aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Driver.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-09-06[clang] Implement setting crash_diagnostics_dir through env variableMatheus Izvekov1-8/+11
This implements setting the equivalent of `-fcrash-diagnostics-dir` through the environment variable `CLANG_CRASH_DIAGNOSTICS_DIR`. If present, the flag still takes precedence. This helps integration with test frameworks and pipelines. With this feature, we change the libcxx bootstrapping build pipeline to produce clang crash reproducers as artifacts. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D133082
2022-09-03[clang] Qualify auto in range-based for loops (NFC)Kazu Hirata1-1/+1
2022-09-03Revert "[Clang] change default storing path of `-ftime-trace`"Junduo Dong1-99/+0
This reverts commit 38941da066a7b785ba4771710189172e94e37824.
2022-09-02[Clang] change default storing path of `-ftime-trace`Junduo Dong1-0/+99
1. This implementation change the default storing behavior of -ftime-trace only. That is, if the compiling job contains the linking action, the executable file' s directory may be seem as the main work directory. Thus the time trace files would be stored in the same directory of linking result. By this approach, the user can easily get the time-trace files in the main work directory. The improved demo results: ``` $ clang++ -ftime-trace -o main.out /demo/main.cpp $ ls . main.out main-[random-string].json ``` 2. In addition, the main codes of time-trace files' path inference have been refactored. * The <path> of -ftime-trace=<path> is infered in clang driver * After that, -ftime-trace=<path> can be added into clang's options By this approach, the dirty work of path processing and judging can be implemented in driver layer, so that the clang may focus on its main work. # $ clang -ftime-trace -o xxx.out xxx.cpp Differential Revision: https://reviews.llvm.org/D131469
2022-09-02[Driver] Unsupport --print-multiarchFangrui Song1-6/+0
* If GCC is configured with `--disable-multi-arch`, `--print-multiarch` output is an empty line. * If GCC is configured with `--enable-multi-arch`, `--print-multiarch` output may be a normalized triple or (on Debian, 'vendor' is omitted) `x86_64-linux-gnu`. The Clang support D101400 just prints the Debian multiarch style triple unconditionally, but the string is not really expected for non-Debian systems. AIUI many Linux distributions and non-Linux OSes don't configure GCC with `--enable-multi-arch`. Instead of getting us in the trouble of supporting all kinds of variants, drop the support as before D101400. Close https://github.com/llvm/llvm-project/issues/51469 Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D133170
2022-09-01[CUDA] Allow using -o with -fsyntax-onlyArtem Belevich1-2/+4
-fsyntax-only breaks down CUDA compilation pipeline and make it look like multiple independent subcompilations and that trips the multiple arguments check when -o is specified. We do want to allow -fsyntax-only to be used with otherwise unmodified clang options as it's commonly used by various tooling. Differential Revision: https://reviews.llvm.org/D133133
2022-08-31[Driver] Remove Joined -Z and err_drv_use_of_Z_optionFangrui Song1-5/+0
This takes a detour to report an error, but we can just remove Joined -Z which is rejected by GCC.
2022-08-27Use llvm::all_equal (NFC)Kazu Hirata1-3/+1
2022-08-26[CUDA] Fix arguments after removing unused private variableJoseph Huber1-2/+2
Summary: A previous patch removed the use of the `OK` private variable in CUDA which resulted in usused variable warnings. this was fixed in f886f7e8ef7aa4f54298db792a656373af90440c but did not change the constructor to accurately represent its removal. This patch removes it from the interface entirely.
2022-08-26[OpenMP] Deprecate the old driver for OpenMP offloadingJoseph Huber1-183/+0
Recently OpenMP has transitioned to using the "new" driver which primarily merges the device and host linking phases into a single wrapper that handles both at the same time. This replaced a few tools that were only used for OpenMP offloading, such as the `clang-offload-wrapper` and `clang-nvlink-wrapper`. The new driver carries some marked benefits compared to the old driver that is now being deprecated. Things like device-side LTO, static library support, and more compatible tooling. As such, we should be able to completely deprecate the old driver, at least for OpenMP. The old driver support will still exist for CUDA and HIP, although both of these can currently be compiled on Linux with `--offload-new-driver` to use the new method. Note that this does not deprecate the `clang-offload-bundler`, although it is unused by OpenMP now, it is still used by the HIP toolchain both as their device binary format and object format. When I proposed deprecating this code I heard some vendors voice concernes about needing to update their code in their fork. They should be able to just revert this commit if it lands. Reviewed By: jdoerfert, MaskRay, ye-luo Differential Revision: https://reviews.llvm.org/D130020
2022-08-24[CUDA][OpenMP] Fix the new driver crashing on multiple device-only outputsJoseph Huber1-8/+16
The new driver supports device-only compilation for the offloading device. The way this is handlded is a little different from the old offloading driver. The old driver would put all the outputs in the final action list akin to a linker job. The new driver however generated these in the middle of the host's job so we instead put them all in a single offloading action. However, we only handled these kinds of offloading actions correctly when there was only a single input. When we had multiple inputs we would instead attempt to get the host job, which didn't exist, and crash. This patch simply adds some extra logic to generate the jobs for all dependencies if there is not host action. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D132248
2022-08-20[clang][lldb][cmake] Use new `*_INSTALL_LIBDIR_BASENAME` CPP macroJohn Ericson1-1/+1
Use this instead of `*_LIBDIR_SUFFIX`, from which it is computed. This gets us ready for D130586, in which `*_LIBDIR_SUFFIX` is deprecated. Differential Revision: https://reviews.llvm.org/D132300
2022-08-18Revert "[cmake] Use `CMAKE_INSTALL_LIBDIR` too"John Ericson1-1/+1
This reverts commit f7a33090a91015836497c75f173775392ab0304d. Unfortunately this causes a number of failures that didn't show up in my local build.
2022-08-18[clang][Driver] Pass correct reproduce flag to lld-linkAlex Brachet1-1/+5
Additionally, the explicit linux target has been removed from the test. Differential Revision: https://reviews.llvm.org/D131214
2022-08-18[cmake] Use `CMAKE_INSTALL_LIBDIR` tooJohn Ericson1-1/+1
We held off on this before as `LLVM_LIBDIR_SUFFIX` conflicted with it. Now we return this. `LLVM_LIBDIR_SUFFIX` is kept as a deprecated way to set `CMAKE_INSTALL_LIBDIR`. The other `*_LIBDIR_SUFFIX` are just removed entirely. I imagine this is too potentially-breaking to make LLVM 15. That's fine. I have a more minimal version of this in the disto (NixOS) patches for LLVM 15 (like previous versions). This more expansive version I will test harder after the release is cut. Reviewed By: sebastian-ne, ldionne, #libc, #libc_abi Differential Revision: https://reviews.llvm.org/D130586
2022-08-17[Driver] Override default location of config filesSerge Pavlov1-12/+8
If directory for config files was specified in project configuration using parameters CLANG_CONFIG_FILE_SYSTEM_DIR or CLANG_CONFIG_FILE_USER_DIR, it was not overriden by command-line option `--config-system-dir=` or `--config-user-dir=` that specified empty path. This change corrects the behavior. It fixes the issue https://github.com/llvm/llvm-project/issues/56836 ([clang] [test] test/Driver/config-file-errs.c fails if CLANG_CONFIG_FILE_SYSTEM_DIR is specified).
2022-08-05[HLSL] emit-obj when set output.Xiang Li1-0/+3
When not set output, set default output to stdout. When set output with -Fo and no -fcgl, set -emit-obj to generate dx container. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D130858
2022-08-01[Driver] Re-run lld with --reproduce when it crashesAlex Brachet1-27/+73
This was discussed on https://discourse.llvm.org/t/rfc-generating-lld-reproducers-on-crashes/58071/12 When lld crashes, or errors when -gen-reproducer=error and -fcrash-diagnostics=all clang will re-run lld with --reproduce=$temp_file for easily reproducing the crash/error. Differential Revision: https://reviews.llvm.org/D120175
2022-07-20[HIP] Allow the new driver to compile HIP in non-RDC modeJoseph Huber1-2/+21
The new driver primarily allows us to support RDC-mode compilations with proper linking. This is not needed for non-RDC mode compilation, but we still would like the new driver to be able to handle this mode so we can transition away from the old driver in the future. This patch adds the necessary code to support creating a fatbinary for HIP code generation. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D129784
2022-07-20[HLSL] add -I option for dxc mode.Xiang Li1-0/+5
A new option -I is added for dxc mode. It is just alias of existing cc1 -I option. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D128462
2022-07-15[CUDA] Make the new driver properly ignore non-CUDA inputsJoseph Huber1-0/+8
The new driver generated offloadinga actions for each active toolchain. However, for CUDA and HIP it is possible for the toolchain to be active but one of the files is not a valid input. This can occur if the user compiles both a CUDA and C source file in the same compiler invocation. This patch adds some simple logic to quit if the input is not valid as well. Reviewed By: tra, MaskRay Differential Revision: https://reviews.llvm.org/D129885
2022-07-13[clang] Use value instead of getValue (NFC)Kazu Hirata1-1/+1
2022-07-13[CUDA] Allow the new driver to compile CUDA in non-RDC modeJoseph Huber1-5/+17
The new driver primarily allows us to support RDC-mode compilations with proper linking. This is not needed for non-RDC mode compilation, but we still would like the new driver to be able to handle this mode so we can transition away from the old driver in the future. This patch adds the necessary code to support creating a fatbinary for CUDA code generation as well as removing old assumptions and errors about RDC-mode with the new driver. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D129655
2022-07-11[Clang] Parse toolchain-specific offloading arguments directlyJoseph Huber1-3/+12
OpenMP supports multiple offloading toolchains and architectures. In order to support this we originally used `getArgsForToolchain` to get the arguments only intended for each toolchain. This allowed users to manually specify if an `--offload-arch=` argument was intended for which toolchain using `-Xopenmp-target=` or other methods. For example, ``` clang input.c -fopenmp -fopenmp-targets=nvptx64,amdgcn -Xopenmp-target=nvptx64 --offload-arch=sm_70 -Xopenmp-target=amdgcn --offload-arch=gfx908 ``` However, this was causing problems with the AMDGPU toolchain. This is because the AMDGPU toolchain for OpenMP uses an `amdgpu` arch to determine the architecture. If this tool is not availible the compiler will exit with an error even when manually specifying the architecture. This patch pulls out the logic in `getArgsForToolchain` and specializes it for extracting `--offload-arch` arguments to avoid this. Reviewed By: JonChesterfield, yaxunl Differential Revision: https://reviews.llvm.org/D129435
2022-06-28[clang-cl] Add -emit-ast to clang-cl driverTobias Hieta1-0/+8
Also make the output of -emit-ast end up where /o points. The same with .plist files from the static analyzer. These are changes needed to make it possible to do CTU static analysing work with clang-cl. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D128409
2022-06-26[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
This patch replaces x.hasValue() with x where x is contextually convertible to bool.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata1-2/+2
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
2022-06-23[CUDA] Do not embed a fatbinary when using the new driverJoseph Huber1-11/+0
Previously, when using the new driver we created a fatbinary with the PTX and Cubin output. This was mainly done in an attempt to create some backwards compatibility with the existing CUDA support that embeds the fatbinary in each TU. This will most likely be more work than necessary to actually implement. The linker wrapper cannot do anything with these embedded PTX files because we do not know how to link them, and if we did want to include multiple files it should go through the `clang-offload-packager` instead. Also this didn't repsect the setting that disables embedding PTX (although it wasn't used anyway). Reviewed By: tra Differential Revision: https://reviews.llvm.org/D128441
2022-06-22[Clang] Allow multiple comma separated arguments to `--offload-arch=`Joseph Huber1-22/+24
This patch updates the `--[no-]offload-arch` command line arguments to allow the user to pass in many architectures in a single argument rather than specifying it multiple times. This means that the following command line, ``` clang foo.cu --offload-arch=sm_70 --offload-arch=sm_80 ``` can become: ``` clang foo.cu --offload-arch=sm_70,sm_80 ``` Reviewed By: ye-luo Differential Revision: https://reviews.llvm.org/D128206
2022-06-20[clang] Don't use Optional::getValue (NFC)Kazu Hirata1-8/+5
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata1-4/+2
2022-06-18[clang][driver] Ensure we don't accumulate entries in -MJ filesJan Svoboda1-0/+4
Previously, each job would overwrite the -MJ file. This didn't quite work for Clang invocations with multiple architectures, which got fixed in D121997 by always appending to the -MJ file. That's not correct either, since the file would grow indefinitely on subsequent Clang invocations. This patch ensures the driver always removes the file before jobs fill it in by appending. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D128098
2022-06-14[OpenMP] Fix offload packager not writing to temps correctlyJoseph Huber1-4/+6
The offloading packager doesn't have a normal offloading kind. This would result in its output being sent to the executable name when in save-temps mode. This would then get overwritten by the actual output. This patch adds specific checks to make sure that it gets the correct name. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D127673
2022-06-13[Clang] Change host/device only compilation to a driver modeJoseph Huber1-31/+23
We use the flags `--offload-host-only` and `--offload-device-only` to change the driver's code generation for offloading programs. These are currently parsed out independently in many places. This patch simply refactors this to work as a mode for the Driver. This stopped us from emitting warnings if unused because it's always used now, but I don't think this is a great loss. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D127515
2022-06-13[clang][driver] Introduce new -fdriver-only flagJan Svoboda1-0/+15
This patch introduces the new -fdriver-only flag which instructs Clang to only execute the driver logic without running individual jobs. In a way, this is very similar to -###, with the following differences: * it doesn't automatically print all jobs, * it doesn't avoid side effects (e.g. it will generate compilation database when -MJ is specified). This flag will be useful in testing D121997. Reviewed By: dexonsmith, egorzhdan Differential Revision: https://reviews.llvm.org/D127408
2022-06-08[clang][driver] adds `-print-diagnostics`Christopher Di Bella1-0/+7
Prints a list of all the warnings that Clang offers. Differential Revision: https://reviews.llvm.org/D126796
2022-06-04Use static_cast from SmallString to std::string (NFC)Kazu Hirata1-2/+2
2022-05-31[HLSL][clang][Driver] Parse target profile early to update Driver::TargetTriple.Xiang Li1-5/+13
This is to avoid err_target_unknown_abi which is caused by use default TargetTriple instead of shader model target triple. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D125585
2022-05-31[Clang] Extend -gen-reproducer flagAlex Brachet1-5/+1
`-gen-reproducer` causes crash reproduction to be emitted even when clang didn't crash, and now can optionally take an argument of never, on-crash (default), on-error and always. Differential revision: https://reviews.llvm.org/D120201
2022-05-27Revert "[Clang] Extend -gen-reproducer flag"Alex Brachet1-1/+5
This reverts commit 684c080108766b4f112f172fed4a49059484614d.
2022-05-27[Clang] Extend -gen-reproducer flagAlex Brachet1-5/+1
-gen-reproducer causes crash reproduction to be emitted even when clang didn't crash, and now can optionally take an argument of never, on-crash (default), on-error and always. Differential revision: https://reviews.llvm.org/D120201
2022-05-25[Clang] Introduce `--offload-link` option to perform offload device linkingJoseph Huber1-1/+2
The new driver uses an augmented linker wrapper to perform the device linking phase, but to the user looks like a regular linker invocation. Contrary to the old driver, the new driver contains all the information necessary to produce a linked device image in the host object itself. Currently, we infer the usage of the device linker by the user specifying an offloading toolchain, e.g. (--offload-arch=...) or (-fopenmp-targets=...), but this shouldn't be strictly necessary. This patch introduces a new option `--offload-link` to tell the driver to use the offloading linker instead. So a compilation flow can now look like this, ``` clang foo.cu --offload-new-driver -fgpu-rdc --offload-arch=sm_70 -c clang foo.o --offload-link -lcudart ``` I was considering if this could be merged into the `-fuse-ld` option, but because the device linker wraps over the users linker it would conflict with that. In the future it's possible to merge this into `lld` completely or `gold` via a plugin and we would use this option to enable the device linking feature. Let me know what you think for this. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D126398
2022-05-16[OpenMP] Don't build the offloading driver without a source inputJoseph Huber1-3/+5
The Clang driver additional stages to build a complete offloading program for applications using CUDA or OpenMP offloading. This normally requires either a source file input or a valid object file to be handled. This would cause problems when trying to compile an assembly or LLVM IR file through clang with flags that would enable offloading. This patch simply adds a check to prevent the offloading toolchain from being used if we don't have a valid source file. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D125705
2022-05-13[Clang] Add DriverKit supportEgor Zhdan1-0/+1
This is the second patch that upstreams the support for Apple's DriverKit. The first patch: https://reviews.llvm.org/D118046. Differential Revision: https://reviews.llvm.org/D121911
2022-05-11[Clang] Introduce clang-offload-packager tool to bundle device filesJoseph Huber1-2/+12
In order to do offloading compilation we need to embed files into the host and create fatbainaries. Clang uses a special binary format to bundle several files along with their metadata into a single binary image. This is currently performed using the `-fembed-offload-binary` option. However this is not very extensibile since it requires changing the command flag every time we want to add something and makes optional arguments difficult. This patch introduces a new tool called `clang-offload-packager` that behaves similarly to CUDA's `fatbinary`. This tool takes several input files with metadata and embeds it into a single image that can then be embedded in the host. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D125165
2022-05-06[OpenMP] Try to Infer target triples using the offloading architectureJoseph Huber1-92/+145
Currently we require the `-fopenmp-targets=` option to specify the triple to use for the offloading toolchains, and the `-Xopenmp-target=` option to specify architectures to a specific toolchain. The changes made in D124721 allowed us to use `--offload-arch=` to specify multiple target architectures. However, this can become combersome with many different architectures. This patch introduces functinality that attempts to deduce the target triple and architectures from the offloading action. Currently we will deduce known GPU architectures when only `-fopenmp` is specified. This required a bit of a hack to cache the deduced architectures, without this we would've just thrown an error when we tried to look up the architecture again when generating the job. Normally we require the user to manually specify the toolchain arguments, but here they would confict unless we overrode them. Depends on: D124721 Reviewed By: saiislam Differential Revision: https://reviews.llvm.org/D125050
2022-05-06[OpenMP] Allow compiling multiple target architectures with OpenMPJoseph Huber1-16/+22
This patch adds support for OpenMP to use the `--offload-arch` and `--no-offload-arch` options. Traditionally, OpenMP has only supported compiling for a single architecture via the `-Xopenmp-target` option. Now we can pass in a bound architecture and use that if given, otherwise we default to the value of the `-march` option as before. Note that this only applies the basic support, the OpenMP target runtime does not yet know how to choose between multiple architectures. Additionally other parts of the offloading toolchain (e.g. LTO) require the `-march` option, these should be worked out later. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D124721
2022-05-05[flang][driver] Add support for consuming LLVM IR/BC filesAndrzej Warzynski1-2/+3
This change makes sure that Flang's driver recognises LLVM IR and BC as supported file formats. To this end, `isFortran` is extended and renamed as `isSupportedByFlang` (the latter better reflects the new functionality). New tests are added to verify that the target triple is correctly overridden by the frontend driver's default value or the value specified with `-triple`. Strictly speaking, this is not a functionality that's new in this patch (it was added in D124664). This patch simply enables us to write such tests and hence I'm including them here. Differential Revision: https://reviews.llvm.org/D124667
2022-05-05[Driver] Make "upgrade" of -include to include-pch optional; disable in clangdSam McCall1-1/+2
If clang is passed "-include foo.h", it will rewrite to "-include-pch foo.h.pch" before passing it to cc1, if foo.h.pch exists. Existence is checked, but validity is not. This is probably a reasonable assumption for the compiler itself, but not for clang-based tools where the actual compiler may be a different version of clang, or even GCC. In the end, we lose our -include, we gain a -include-pch that can't be used, and the file often fails to parse. I would like to turn this off for all non-clang invocations (i.e. createInvocationFromCommandLine), but we have explicit tests of this behavior for libclang and I can't work out the implications of changing it. Instead this patch: - makes it optional in the driver, default on (no change) - makes it optional in createInvocationFromCommandLine, default on (no change) - changes driver to do IO through the VFS so it can be tested - tests the option - turns the option off in clangd where the problem was reported Subsequent patches should make libclang opt in explicitly and flip the default for all other tools. It's probably also time to extract an options struct for createInvocationFromCommandLine. Fixes https://github.com/clangd/clangd/issues/856 Fixes https://github.com/clangd/vscode-clangd/issues/324 Differential Revision: https://reviews.llvm.org/D124970