1400 Commits

Author SHA1 Message Date
Naveen Seth Hanig
9403c2d64d
Reland [clang][modules-driver] Add scanner to detect C++20 module presence (#153497)
This patch is part of a series to support driver managed module builds
for C++ named modules and Clang modules.
This introduces a scanner that detects C++ named module usage early in
the driver with only negligible overhead.

For now, it is enabled only with the `-fmodules-driver` flag and serves
solely diagnostic purposes. In the future, the scanner will be enabled
for any (modules-driver compatible) compilation with two or more inputs,
and will help the driver determine whether to implicitly enable the
modules driver.

Since the scanner adds very little overhead, we are also exploring
enabling it for compilations with only a single input. This approach
could allow us to detect `import std` usage in a single-file
compilation, which would then activate the modules driver. For
performance measurements on this, see
https://github.com/naveen-seth/llvm-dev-cxx-modules-check-benchmark.

RFC for driver managed module builds:

https://discourse.llvm.org/t/rfc-modules-support-simple-c-20-modules-use-from-the-clang-driver-without-a-build-system

This patch relands the reland (2d31fc8) for commit ded1426. The earlier
reland failed due to a missing link dependency on `clangLex`. This
reland fixes the issue by adding the link dependency after discussing it
in the following RFC:

https://discourse.llvm.org/t/rfc-driver-link-the-driver-against-clangdependencyscanning-clangast-clangfrontend-clangserialization-and-clanglex
2025-08-18 21:21:08 +02:00
Joseph Huber
56ba1181e9
[Clang] Fix warning on synthetic offload arch argument in host only mode (#151969)
Summary:
These arguments are synthetically generated and should always be
considered used. This was emitting a warning on the new driver.
2025-08-06 07:30:07 -05:00
Joseph Huber
4562b557a6
[HIP] Handle -fhip-emit-reloctable in the new driver (#151237)
Summary:
Support for this was missing, here it pretty much overrides the normal
bundling behavior and also requires a few errors to be emitted.
2025-07-30 06:31:59 -05:00
Joseph Huber
2368be38a1
[HIP] Always respect --gpu-bundle-output in the new driver (#150989)
Summary:
This is a bit of an awkward transition point for the new and old
drivers. Previously AMDGPU uses this to generate offloading bundles, but
the new driver much prefers to output the file itself. This patch
changes the behavior to always respect `--gpu-bundle-output` instead of
having it be the default behavior. This means that we effectively get to
override the default new driver behavior with this flag now. This should
hoepfully fix some errors in the downstream comgr tests.
2025-07-28 12:04:49 -05:00
Joseph Huber
4f58c829fd
[Clang] Search for 'offload-arch' only next to the clang driver (#150965)
Summary:
Previously, querying for the offload architecture tool would invoke the
user's PATH, which is bad when potentially using the driver from a
direct path. This patch change this to *only* consider the
`offload-arch` that's supposed to live next to the driver executable.
Now we will no longer pick up a potentially conflicting version of this
tool and it should always be found (Since it's a clang tool that's
installazed alongside the driver)
2025-07-28 11:36:31 -05:00
parabola94
0c4d56a674
[clang][Driver] Add a new member for CLANG_DEFAULT_LINKER to clang::driver::Driver (NFC) (#149784)
The default linker can be changed by a CMake variable
CLANG_DEFAULT_LINKER, but it is shared in all toolchains. This patch
intends to resolve this.
2025-07-24 08:18:27 -06:00
Joseph Huber
6bc54a4874 [Clang] Make SPIR-V handling only for HIPSPRV 2025-07-23 16:04:25 -05:00
Joseph Huber
1206a6165e
[Clang] Fix new driver HIP SPIR-V compilation in device only mode (#150309)
Summary:
This should emit LLVM-IR. Add to the extremely ugly if statement so that
this happens correctly.
2025-07-23 15:41:47 -05:00
Joseph Huber
efa25c4737
[Clang] Fix new driver device only compilation for amdgcnspirv target (#150110)
Summary:
This is broken with the current target because it was not bundling the
output as HIP likes and this would fail if targeting both at the same
time.
2025-07-23 07:55:10 -05:00
Harald van Dijk
d65cc97ab1 [Clang] Fix build on 32-bit platforms after #125556 2025-07-23 12:48:44 +01:00
Joseph Huber
efffa42f59
[Clang] Add generated offloading Xarch args to synthesized args (#150142)
Summary:
The synthesized args contains a list of unique pointers, so this should
clean this generated argument up once created.
2025-07-22 20:20:13 -05:00
Joseph Huber
dc87a14efb [Clang] Fix sanitizer failure on DenseMap sentinel value enum
Summary:
This triggers UBSan because the sentinel value `-1` is outside the range
of accepted enum values. Just replace this with a small set.
2025-07-22 09:12:13 -05:00
Joseph Huber
08ac781596 [Clang][NFC] Fix linting warnings after #125556 2025-07-21 18:57:52 -05:00
Joseph Huber
a7d93653a6
[Clang] Rework creating offloading toolchains (#125556)
Summary:
This patch reworks how we create offloading toolchains. Previously we
would handle this separately for all the different kinds. This patch
instead changes this to use the target triple and the offloading kind to
determine the proper toolchain. In the old case where the user only
passes `--offload-arch` we instead infer the triple from the passed
arguments. This is a pretty major overhaul but currently passes all the
clang tests with only minor changes to error messages.
2025-07-21 18:36:39 -05:00
Naveen Seth Hanig
cb6f132b1c
Revert "Reland [clang][modules-driver] Add scanner to detect C++20 module presence" (#149900)
Reverts llvm/llvm-project#147630.

This causes a linker error caused by linking the driver against the
lexer.
2025-07-21 23:09:49 +02:00
Naveen Seth Hanig
2d31fc85a8
Reland [clang][modules-driver] Add scanner to detect C++20 module presence (#147630)
This patch is part of a series to natively support C++20 module usage
from the Clang driver (without requiring an external build system). This
introduces a new scanner that detects C++20 module usage in source files
without using the preprocessor or lexer.

For now, it is enabled only with the `-fmodules-driver` flag and serves
solely diagnostic purposes. In the future, the scanner will be enabled
for any (modules-driver compatible) compilation with two or more inputs,
and will help the driver determine whether to implicitly enable the
modules driver.

Since the scanner adds very little overhead, we are also exploring
enabling it for compilations with only a single input. This approach
could allow us to detect `import std` usage in a single-file
compilation, which would then activate the modules driver. For
performance measurements on this, see
https://github.com/naveen-seth/llvm-dev-cxx-modules-check-benchmark.

RFC:

https://discourse.llvm.org/t/rfc-modules-support-simple-c-20-modules-use-from-the-clang-driver-without-a-build-system

This patch relands commit ded1426. The CI failure is resolved by
removing the compatibility warning for using the `-fmodules-driver` flag
with pre-C++20 standards, which also better aligns its behavior with
other features/flags supported only in newer standards.
2025-07-21 22:34:14 +02:00
Chuanqi Xu
255a163e51 [C++20] [Modules] Enable reduced BMI by default
As documented in 20.x, we'd like to keep reduced BMI off by default for
1~2 versions. And now we're in 22.x.

I rarely receive bug reports for reduced BMI. I am not sure about the
reason. Maybe not a lot of people are using it. Or it is really stable
enough.

And also, we've been enabling the reduced BMI internally for roughly half a
year.

So I think it's the time to move on. See the document changes for other
information.
2025-07-21 18:57:38 +08:00
Brad Smith
0d2e11f3e8
Remove Native Client support (#133661)
Remove the Native Client support now that it has finally reached end of life.
2025-07-15 13:22:33 -04:00
Corentin Jabot
db389bda9b
Revert "[clang][modules-driver] Add scanner to detect C++20 module presence" (#147286)
Reverts llvm/llvm-project#145220

This breaks CI when building the documentation

```
Included from /home/runner/work/llvm-project/llvm-project/clang/docs/../include/clang/Basic/Diagnostic.td:74:
/home/runner/work/llvm-project/llvm-project/clang/docs/../include/clang/Basic/DiagnosticGroups.td:628:5: error: Diagnostic group contains both remark and non-remark diagnostics
def ModulesDriver : DiagGroup<"modules-driver">;
    ^
```


https://github.com/llvm/llvm-project/actions/runs/16116118496/job/45470268367
2025-07-07 14:22:41 +02:00
Naveen Seth Hanig
ded1426716
[clang][modules-driver] Add scanner to detect C++20 module presence (#145220)
This PR is part of a series to natively support C++20 module usage from
the Clang driver (without requiring an external build system).
This introduces a new scanner that detects C++20 module usage in source
files without using the preprocessor or lexer.

For now, it is enabled only with the `-fmodules-driver` flag and serves
solely diagnostic purposes. In the future, the scanner will be enabled
for any (modules-driver compatible) compilation with two or more inputs,
and will help the driver determine whether to implicitly enable the
modules driver.

Since the scanner adds very little overhead, we are also exploring
enabling it for compilations with only a single input. This approach
could allow us to detect `import std` usage in a single-file
compilation, which would then activate the modules driver.
For performance measurements on this, see
https://github.com/naveen-seth/llvm-dev-cxx-modules-check-benchmark.

RFC:

https://discourse.llvm.org/t/rfc-modules-support-simple-c-20-modules-use-from-the-clang-driver-without-a-build-system
2025-07-07 11:55:34 +02:00
Joseph Huber
6db02dc431
[Clang] Introduce --offload-targets for -fopenmp-targets (#146594)
Summary:
This patch is mostly an NFC that renames the existing `-fopenmp-targets`
into `--offload-targets`. Doing this early to simplify a follow-up patch
that will hopefully allow this syntax to be used more generically over
the existing `--offload` syntax (which I think is mostly unmaintained
now.). Following in the well-trodden path of trying to pull language
specific offload options into generic ones, but right now this is still
just OpenMP specific.
2025-07-04 16:20:53 -05:00
Joseph Huber
d04d255725
[Clang] Properly use CommaJoined for --offload-arch (#146687)
Summary:
This didn't use the built-in 'CommaJoined' feature for arguments and
parsed out the strings manually. This patch simplifies this by just
using the present functionality.
2025-07-02 10:26:32 -05:00
Peter Collingbourne
2a702cdc38
Driver: Avoid llvm::sys::path::append if resource directory absolute.
After #145996 CLANG_RESOURCE_DIR can be an absolute path so we need to
handle it correctly in the driver.

llvm::sys::path::append does not append absolute paths in the way
that I expected (or consistent with other similar APIs such as C++17
std::filesystem::path::append or Python os.path.join); instead, it
effectively discards the leading / and appends the resulting relative path
(e.g. append(P, "/bar") with P = "/foo" sets P to "/foo/bar").

Many tests start failing if I try to align llvm::sys::path::append with
the other APIs because of callers that expect the existing behavior,
so for now let's add a special case here for absolute resource paths,
and document the behavior in Path.h.

Reviewers: MaskRay

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/146449
2025-07-01 20:21:51 -07:00
Garvit Gupta
f8cb7987c6
[RISCV] Integrate RISCV target in baremetal toolchain object and deprecate RISCVToolchain object (#121831)
This patch:
- Adds CXXStdlib, runtimelib defaults for riscv target to
  BareMetal toolchain object.
- Set the unwindlib to None for riscv target to match the
   behavior of RISCVToolChain.
- Removes call to RISCVToolChain object from llvm.

This PR is last patch in the series of patches of merging RISCVToolchain
object into BareMetal toolchain object.

RFC:
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524
2025-06-30 15:18:21 +05:30
Joseph Huber
48e893792a
[Clang] Determine offloading architectures at Toolchain creation (#145799)
Summary:
Previously we had this weird disconnect where we would get some
offloading architectures beforehand and some later. This patch changes
it to where we just generate this information at Toolchain creation.
There's a few edge cases that will need to be cleaned up. Namely, we
don't handle the strange SPIR-V handling that mixes two separate
toolchains and we needed a pre-check to reject errors when inferring the
toolchain from `--offload-arch` in OpenMP.

Possible we could also use this information for some host defines if
needed.
2025-06-26 11:41:42 -05:00
Joseph Huber
029823a84d
[Clang][NFC] Clean up OpenMP offload toolchain generation (#145549)
Summary:
Small cleanup prior to some larger changes in this area. I want to move
the offload arch detection to be done solely here.

This might change the order the targets show up in but shouldn't affect
anything else. Will look into that.
2025-06-25 11:04:06 -05:00
no92
0f302f38b0
[clang] Add managarm support (#144791)
This is a repost of the quickly reverted #139271. The failing buildbot
tests have been fixed and pass on my machine now.
2025-06-20 02:40:20 -04:00
Joseph Huber
4c6f398b86
[Clang] Add standalone AMDGPU SPIR-V toolchain (#144576)
Summary:
The AMDGPU toolchain uses a different set of tools than the standard
SPIR-V toolchain. The linker wrapper prefers to invoke a linker via a
clang toolchain. To make that work we introduce
`--target=spirv64-amd-amdhsa` so that it creates the linking phases that
HIP prefers. Additionally, this can be used to make LLVM-IR / SPIR-V
from C/C++ that can be linked with the HIP output.
2025-06-19 09:23:57 -05:00
Aaron Ballman
3377b56338
Revert "[clang] Add managarm support" (#144514)
Reverts llvm/llvm-project#139271

There are multiple failing build bots:
https://lab.llvm.org/buildbot/#/builders/10/builds/7482
https://lab.llvm.org/buildbot/#/builders/11/builds/17473
2025-06-17 08:39:15 -04:00
Ying Yi
6f29837659
Reland: "[Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (#142409)" (#143614)
Visual Studio has an argument to ignore all PCH related switches.
clang-cl has also support option /Y-. Having the same option in clang
would be helpful. This commit is to add support for ignoring PCH options
(-ignore-pch).

The commit includes:
  1. Implement -ignore-pch as a Driver option.
  2. Add a Driver test and a PCH test.
  3. Add a section of -ignore-pch to user manual.
  4. Add a release note for the new option '-ignore-pch'.

The change since the original landing:
  1. preprocessing-only mode doesn't imply that -include-pch is disabled.

Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
2025-06-17 10:54:22 +01:00
no92
e86740e600
[clang] Add managarm support (#139271)
This PR is part of a series to upstream managarm support, as laid out in
the
[RFC](https://discourse.llvm.org/t/rfc-new-proposed-managarm-support-for-llvm-and-clang-87845/85884/1).
This PR is a follow-up to #87845 and #138854.
2025-06-17 01:51:46 -04:00
Yaxun (Sam) Liu
7232c07eb9 Reland [HIP] use offload wrapper for non-device-only non-rdc (#143964)
Fixed a typo:

-  auto Section = (Prefix + "llvm_offload_entries").str();
+  auto Section = (Prefix + "_offload_entries").str();

which broke buildbot e.g.

https://lab.llvm.org/buildbot/#/builders/208/builds/1948
2025-06-12 21:41:41 -04:00
Yaxun (Sam) Liu
8890706db6 Revert "Reland [HIP] use offload wrapper for non-device-only non-rdc (#132869) (#143964)"
This reverts commit 22f9b4aa1dad597d908be77be1e10ba4c77330ce.
2025-06-12 21:33:05 -04:00
Yaxun (Sam) Liu
22f9b4aa1d
Reland [HIP] use offload wrapper for non-device-only non-rdc (#132869) (#143964)
Fixed two issues:

1. assertion with -flto. the linker wrapper action is missing for
wrapping the device binary. Added it for -flto.

2. when there are two HIP files, the kernels in the second file were not
found. This is because the -r option of linker wrapper assumes offload
entries section of HIP to be hip_offloading_entries but it is actually
llvm_offload_entries, causing the offload entries sections not made
unique for different object files. Fixed and tested working for both
-fgpu-rdc and -fno-gpu-rdc case with and without -r
2025-06-12 20:08:55 -04:00
Steven Perron
b3db0c6a1d
[HLSL][Driver] Make vk1.3 the default. (#143384)
The HLSL driver currently defaults the triple to an unversioned os and
subarch when targeting SPIR-V. This means the SPIR-V backend decides the
default value. That is not a great option because a change the backend
could cause a change in Clang.

Now that we want to choose the default we need to consider the best
option. DXC currently defaults to Vulkan1.0. We are planning on not
supporting Vulkan1.0 in the Clang HLSL compiler because it is newer
versions of Vulkan are commonly supported on nearly all hardware, so
users do not use it.

Since we have to change from DXC anyway, we are using VK1.3. It has been
out long enough to be commonly available, and the initial implementation
of SPIR-V features for HLSL are assuming Vulkan 1.3.

---------

Co-authored-by: Nathan Gauër <github@keenuts.net>
2025-06-11 10:30:38 -04:00
Ying Yi
c926bff560 Revert "[Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (#142409)"
This reverts commit 4fb81f11cea0fce9f1f5409fcd55ae3aba70d368.
2025-06-10 17:19:58 +01:00
MaggieYingYi
4fb81f11ce
[Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (#142409)
Visual Studio has an argument to ignore all PCH related switches. clang-cl has also support option /Y-. Having the same option in clang would be helpful. This commit is to add support for ignoring PCH options (-ignore-pch).

The commit includes:
    1. Implement -ignore-pch as a Driver option.
    2. Add a Driver test and a PCH test.
    3. Add a section of -ignore-pch to user manual.
    4. Add a release note for the new option '-ignore-pch'.

Code reviewed by: Matheus Izvekov <mizvekov@gmail.com>
2025-06-10 12:52:44 +01:00
Joseph Huber
f5e499a338
Revert "[HIP] use offload wrapper for non-device-only non-rdc (#132869)" (#143432)
This breaks a lot of new driver HIP compilation. We should probably
revert this for now until we can make a fixed version.

```c++

static __global__ void print() { printf("%s\n", "foo"); }

void b();

int main() {
  hipLaunchKernelGGL(print, dim3(1), dim3(1), 0, 0);
  auto y = hipDeviceSynchronize();
  b();
}
```
```c++

static __global__ void print() { printf("%s\n", "bar"); }

void b() {
  hipLaunchKernelGGL(print, dim3(1), dim3(1), 0, 0);
  auto y = hipDeviceSynchronize();
}
```
```console
$ clang++ a.hip b.hip --offload-arch=gfx1030 --offload-new-driver
$ ./a.out
foo
foo
```
```console
$ clang++ a.hip b.hip --offload-arch=gfx1030 --offload-new-driver -flto
<crash>
```

This reverts commit d54c28b9c1396fa92d9347ac1135da7907121cb8.
2025-06-09 17:18:49 -05:00
Joseph Huber
dedef408d7
Reapply "[AMDGPU] Use the AMDGPUToolChain when targeting C/C++ directly" (#125744)
Summary:
This reverts commit 740e6aeccdb2f8eeee549ba80b15ff3d5dd3392e.

After discussions it was determined that the behavior for IR inputs
needs to be maintained at least for now. In the future we should put a
deprecation notice on this behavior. This patch keeps the old behavior
for OpenCL and IR inputs, while others will be standalone. This is good
enough for standard compile flows.
2025-06-03 07:54:17 -05:00
Naveen Seth Hanig
8808a543af
[NFC][clang] Move argument handling: Driver::BuildActions -> handleArguments (#142455)
This simply moves code for diagnosing misuse of arguments `/Fo`, `/Fa`,
and `/o` from `Driver::BuildActions` into `Driver::handleArguments`,
following the intention of 740f69b.
This change better aligns with the roles of `BuildActions` and
`handleArguments`.
2025-06-02 23:07:26 -07:00
Abid Qadeer
de38c4eaf5
[flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (#140556)
This PR add functionality to change `flang` command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to what
`CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but I
am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
2025-06-02 11:37:26 +01:00
Matthias Braun
a4b2f4a72a
Check for unsupported target options even with -Qunused-arguments (#141698)
Fix clang accidentally skipping checks for
`err_drv_unsupported_opt_for_target` when `-Qunused-arguments` was
active.
2025-05-28 11:42:47 -07:00
Kazu Hirata
9adcb4fe12
[clang] Use llvm::replace (NFC) (#140264) 2025-05-16 09:06:31 -07:00
Juan Manuel Martinez Caamaño
ca3121b898
[Clang][Driver] Fix condition in combineBackendCompile when using -no-integrated-cpp (#136853)
When using -no-integrated-cpp, before, the driver won't collapse actions
when the input was not llvm-ir
or it would collapse them too aggressively with -save-temps

The original code was checking the action type (which is IR too for
preprocessed->bc actions) instead of the action inputs.
2025-05-12 09:49:59 +02:00
jeremyd2019
52924a2d72
[Clang] [Driver] add a Cygwin ToolChain (#135691)
Add a new Cygwin toolchain that just goes through the motions to
initialize the Generic_GCC base properly. This allows removing some old,
almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp.

MSYS2 (GCC triple (arch)-pc-msys) is a fork of Cygwin (GCC triple
(arch)-pc-cygwin), and this driver can be used for either.

Add a simple test for this driver.
2025-05-09 09:54:02 +03:00
Steven Perron
cc0cf72539
[HLSL] Allow non .hlsl files as source files (#137378)
Changes the driver to assume input file with an unknown extension are
HLSL source files instead of object files.

Fixes https://github.com/llvm/llvm-project/issues/137370
2025-04-29 09:28:29 -04:00
Daniel Chen
5133b432bc
Enable -m32, -maix32 and -maix64 for Flang on AIX. (#136202)
This PR enables `-m32`, -`maix32` and `-maix64` for AIX only. For other
platforms, the driver will issue an error that `-m32` is not supported.
2025-04-21 12:05:48 -04:00
Kazu Hirata
94733492b7
[clang] Use llvm::SmallVector::pop_back_val (NFC) (#136451) 2025-04-19 13:35:18 -07:00
Yaxun (Sam) Liu
d54c28b9c1
[HIP] use offload wrapper for non-device-only non-rdc (#132869)
Currently HIP still uses offload bundler for non-rdc mode for the new
offload driver.

This patch switches to use offload wrapper for non-device-only non-rdc
mode when new offload driver is enabled.

This makes the rdc and non-rdc compilation more consistent and speeds up
compilation since the offload wrapper supports parallel compilation for
different GPU arch's.

It is implemented by adding a linker wrapper action for each assemble
action of input file. Linker wrapper action differentiates this special
type of work vs normal linker wrapper work by the fle type. This type of
work results in object instead of image. The linker wrapper adds "-r"
for it and only includes the object file as input, not the host
libraries.

For device-only non-RDC mode, the new driver keeps the original
behavior.
2025-04-09 09:13:21 -04:00
Alex Voicu
1a7402d3d8
[NFC][Driver][HIP] Fix mixing amdgcnspirv and gfxXXX via --offload-arch (#133024)
Due to `amdgcnspirv` piggybacking on the HIPAMDToolchain, it loses its
immediately apparent SPIR-Vness, which makes the Driver want to go all
the way to Assembly emmission. This was problematic as we were trying to
`llvm-link` SPIR-V, before trying to translate it. This patch ensures
that we do the right thing and stop at bitcode emission if we are mixing
`amdgcnspirv` and concrete targets.
2025-03-26 10:06:21 +00:00