72 Commits

Author SHA1 Message Date
Tom Vijlbrief
ad94f77a6a
[AVR] Add many new AVR MCU model definitions (#144229)
1. Added the missing XMEGA2 definition. The avr64 devices use xmega2 which has SPM(X) defined.

2. The avr16/avr32 devices do have SPM and SPMX features, but the current xmega3 definition has not.
   Xmega3 is also used for modern attiny series which do not have SPM(X), so that is correct.
   Leave the avr16/avr32 devices unchanged (using xmega3 to be in sync with gcc definitions).

Fixes https://github.com/llvm/llvm-project/issues/116116
2025-06-16 09:25:40 +08:00
Kazu Hirata
62d8e001da Revert "[AVR] Add support for many new AVR MCUs (#143914)"
This reverts commit 10bc17fc3676b82c7240046a948d2925dd2045d3.

Multiple buildbot failures have been reported:
https://github.com/llvm/llvm-project/pull/143914
2025-06-14 08:18:50 -07:00
Tom Vijlbrief
10bc17fc36
[AVR] Add support for many new AVR MCUs (#143914)
fixes https://github.com/llvm/llvm-project/issues/116116
2025-06-14 23:10:04 +08:00
Cameron McInally
a42bb8b57a
[Driver] Move CommonArgs to a location visible by the Frontend Drivers (#142800)
This patch moves the CommonArgs utilities into a location visible by the
Frontend Drivers, so that the Frontend Drivers may share option parsing
code with the Compiler Driver. This is useful when the Frontend Drivers
would like to verify that their incoming options are well-formed and
also not reinvent the option parsing wheel.

We already see code in the Clang/Flang Drivers that is parsing and
verifying its incoming options. E.g. OPT_ffp_contract. This option is
parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with
slightly different parsing code. It would be nice if the Frontend
Drivers were not required to duplicate this Compiler Driver code. That
way there is no/low maintenance burden on keeping all these parsing
functions in sync.

Along those lines, the Frontend Drivers will now have a useful mechanism
to verify their incoming options are well-formed. Currently, the
Frontend Drivers trust that the Compiler Driver is not passing back junk
in some cases. The Language Drivers may even accept junk with no error
at all. E.g.:

  `clang -cc1 -mprefer-vector-width=junk test.c'

With this patch, we'll now be able to tighten up incomming options to
the Frontend drivers in a lightweight way.

---------

Co-authored-by: Cameron McInally <cmcinally@nvidia.com>
Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com>
2025-06-06 17:59:24 -04:00
Kazu Hirata
6c37341943
[Driver] Remove unused includes (NFC) (#141448)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-26 09:13:36 -07:00
Brad Smith
dddcbc26d6
[Driver][LTO] Move common code for LTO to addLTOOptions() (#74178) 2025-05-23 23:03:37 -04:00
Daniel Chen
2080334574
[flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX and LoP (#131041)
This PR is to improve the driver code to build `flang-rt` path by
re-using the logic and code of `compiler-rt`.

1. Moved `addFortranRuntimeLibraryPath` and `addFortranRuntimeLibs` to
`ToolChain.h` and made them virtual so that they can be overridden if
customization is needed. The current implementation of those two
procedures is moved to `ToolChain.cpp` as the base implementation to
default to.

2. Both AIX and PPCLinux now override `addFortranRuntimeLibs`. 
The overriding function of `addFortranRuntimeLibs` for both AIX and
PPCLinux calls `getCompilerRTArgString` => `getCompilerRT` =>
`buildCompilerRTBasename` to get the path to `flang-rt`. This code
handles `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR` setting. As shown in
`PPCLinux.cpp`, `FT_static` is the default. If not found, it will search
and build for `FT_shared`. To differentiate `flang-rt` from `clang-rt`,
a boolean flag `IsFortran` is passed to the chain of functions in order
to reach `buildCompilerRTBasename`.
2025-04-03 11:21:19 -04:00
Ben Shi
4bf6e831d5
[clang][Driver][AVR] Reject c/c++ compilation for avr1 devices (#111798)
avr-gcc also rejects since these devices has no SRAM.

Fixes https://github.com/llvm/llvm-project/issues/96881
2024-10-14 19:08:58 +08:00
Kazu Hirata
10886a8f0a [Driver] Use SmallString::operator std::string (NFC) 2024-01-19 22:24:09 -08:00
Brad Smith
1881832994
[Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia (#71359)
Copy 85451f486d8144f8aacd94a47802c77da5a04d27 over to AVR, FreeBSD and
Fuchsia.
2023-11-06 01:56:27 -05:00
Ben Shi
fad99d398a [clang][Driver] Fix a spot in commit 169f60f7c76cb6f7d234ab5dfb2b5e367a35ccbb
My previous commit leads to a failure in 'Builders/ppc64le-lld-multistage-test',
as shown at "https://lab.llvm.org/buildbot/#/builders/36/builds/38790".
2023-10-15 15:29:14 +08:00
Ben Shi
169f60f7c7
[clang][driver] Add avr-libc's default linker script to lld (#68507)
If `-fuse-ld=lld` is specified but no user linker script is offered, we
try to use avr-libc's default one for lld. (not needed for GNU ld)
2023-10-15 13:47:56 +08:00
Ben Shi
1d8d326a86
[clang][driver] Support option '-r' for target AVR (#68484)
If '-r' is specified with target AVR:

1. Do not link to the avr-libc.
2. Do not emit some conflict options.
3. Do not emit any sub-target related address information/warning.
2023-10-11 12:19:33 +08:00
Job Noorman
8de9f2b558 Move SubtargetFeature.h from MC to TargetParser
SubtargetFeature.h is currently part of MC while it doesn't depend on
anything in MC. Since some LLVM components might have the need to work
with target features without necessarily needing MC, it might be
worthwhile to move SubtargetFeature.h to a different location. This will
reduce the dependencies of said components.

Note that I choose TargetParser as the destination because that's where
Triple lives and SubtargetFeatures feels related to that.

This issues came up during a JITLink review (D149522). JITLink would
like to avoid a dependency on MC while still needing to store target
features.

Reviewed By: MaskRay, arsenm

Differential Revision: https://reviews.llvm.org/D150549
2023-06-26 11:20:08 +02:00
Ben Shi
0d37efdbc5 [clang][driver] Enable '-flto' on AVR
Reviewed By: MaskRay

Closes https://github.com/llvm/llvm-project/issues/55940

Differential Revision: https://reviews.llvm.org/D145646
2023-03-22 12:57:58 +08:00
Ben Shi
1c112897b2 [clang][driver] Do not emit default '-Tdata' for AVR devices
Different AVR devices have different data regions. Current clang
driver emits a default '-Tdata' option to the linker. This way
works fine if there is no user specified linker script, but it
will cause conflicts if there is one.

A better solution for setting the default data region to GNU ld
is defining symbol __DATA_REGION_ORIGIN__, which is expected by
GNU ld's default AVR linker script.

Fixes https://github.com/llvm/llvm-project/issues/60362

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D144533
2023-03-01 15:55:30 +08:00
Ben Shi
9161043390 [clang][driver] Handle '-mrelax' and '-mno-relax' for AVR
Reviewed By: MaskRay, aykevl

Fixes https://github.com/llvm/llvm-project/issues/54508

Differential Revision: https://reviews.llvm.org/D144620
2023-02-24 07:16:31 +08:00
Fangrui Song
21c4dc7997 std::optional::value => operator*/operator->
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-17 00:42:05 +00:00
Kazu Hirata
6eb0b0a045 Don't include Optional.h
These files no longer use llvm::Optional.
2022-12-14 21:16:22 -08:00
Fangrui Song
2c5d49cffc [Driver] llvm::Optional => std::optional
and change a few referenced Basic and llvm/lib/WindowsDriver API
2022-12-03 20:17:05 +00:00
Fangrui Song
0c2f6e36f9 [Driver] llvm::None => std::nullopt. NFC 2022-12-03 19:43:25 +00:00
Kazu Hirata
6ba4b62af8 Return None instead of Optional<T>() (NFC)
This patch replaces:

  return Optional<T>();

with:

  return None;

to make the migration from llvm::Optional to std::optional easier.
Specifically, I can deprecate None (in my source tree, that is) to
identify all the instances of None that should be replaced with
std::nullopt.

Note that "return None" far outnumbers "return Optional<T>();".  There
are more than 2000 instances of "return None" in our source tree.

All of the instances in this patch come from functions that return
Optional<T> except Archive::findSym and ASTNodeImporter::import, where
we return Expected<Optional<T>>.  Note that we can construct
Expected<Optional<T>> from any parameter convertible to Optional<T>,
which None certainly is.

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

Differential Revision: https://reviews.llvm.org/D138464
2022-11-21 19:06:42 -08:00
Kazu Hirata
981cbfb592 [clang] Don't include StringSwitch.h (NFC)
These files don't seem to use StringSwitch.
2022-09-18 22:21:32 -07:00
Ben Shi
f45d89d73d [Driver] Support linking to compiler-rt for target AVR
Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D128133
2022-08-16 09:22:50 +08:00
Ben Shi
65c022a75f Revert "[Driver] Support linking to compiler-rt for target AVR"
This reverts commit 44a647d21d946f8cc3eb7c1fea33311cf778f303.
2022-08-16 07:55:41 +08:00
Ben Shi
44a647d21d [Driver] Support linking to compiler-rt for target AVR
Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D128133
2022-08-13 20:40:21 +08:00
Kazu Hirata
cb2c8f694d [clang] Use value instead of getValue (NFC) 2022-07-13 23:39:33 -07:00
KOLANICH
2d01a85720 [Driver] Improve linking options for target AVR
Move user specified inputs to the linking group in case
they and the stardard libraries have mutual reference.

Reviewed By: benshi001

Differential Revision: https://reviews.llvm.org/D127501
2022-07-07 22:45:21 +08:00
Kazu Hirata
97afce08cb [clang] Don't use Optional::hasValue (NFC)
This patch replaces Optional::hasValue with the implicit cast to bool
in conditionals only.
2022-06-25 22:26:24 -07:00
Kazu Hirata
3b7c3a654c Revert "Don't use Optional::hasValue (NFC)"
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25 11:56:50 -07:00
Kazu Hirata
aa8feeefd3 Don't use Optional::hasValue (NFC) 2022-06-25 11:55:57 -07:00
Kazu Hirata
ca4af13e48 [clang] Don't use Optional::getValue (NFC) 2022-06-20 22:59:26 -07:00
Kazu Hirata
452db157c9 [clang] Don't use Optional::hasValue (NFC) 2022-06-20 10:51:34 -07:00
Ben Shi
753b915167 [Driver] Improve linking options for target AVR
1. Support user specified linker (-fuse-ld)
2. Support user specified linker script (-T)

Reviewed By: MaskRay, haowei

Differential Revision: https://reviews.llvm.org/D126192
2022-06-15 02:57:31 +00:00
Haowei Wu
7fae15f925 Revert "[Driver] Improve linking options for target AVR"
This reverts commit 3b6e166999bb83197c8b70468c2d371c58cf0c25 which
causes Clang Driver test failures on Fuchsia builders.
2022-06-14 17:53:46 -07:00
Ben Shi
3b6e166999 [Driver] Improve linking options for target AVR
1. Support user specified linker (-fuse-ld)
2. Support user specified linker script (-T)

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D126192
2022-06-14 01:30:49 +00:00
Ben Shi
520d17bfa0 Revert "[Driver] Improve linking options for target AVR"
This reverts commit d7599be9e84fb205b7f50de406dc87858aebc0f4.
2022-06-14 09:12:21 +08:00
Ben Shi
d7599be9e8 [Driver] Improve linking options for target AVR
1. Support linking with lld
2. Support user specifed linker script

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D126192
2022-06-13 23:38:59 +00:00
Ben Shi
50de68bc2f [Driver][AVR] Emit proper warnings for different options
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D122524
2022-03-29 12:05:21 +08:00
Fangrui Song
52fa1d1a02 [Driver][AVR] Fix warn_drv_avr_stdlib_not_linked condition
Many options (-fsyntax-only, -E, -S, etc) skip the link action phase which the
existing condition does not account for.

Since the code no longer specifies OPT_c, I think a single RUN line about -c
not leading to a warning is sufficient. Adding one for all of -E,
-fsyntax-only, -S would be excessive.

Reviewed By: benshi001

Differential Revision: https://reviews.llvm.org/D122553
2022-03-28 10:27:16 -07:00
Fangrui Song
17ea5bf1d5 Revert "[Driver][AVR] Fix warn_drv_avr_stdlib_not_linked condition"
This reverts commit 16524d2f1bdc2e74ca34425edf43ac8ef5d39531.

The test caused some warnings when avr-gcc was not installed.
2022-03-28 10:11:45 -07:00
Fangrui Song
16524d2f1b [Driver][AVR] Fix warn_drv_avr_stdlib_not_linked condition
Many options (-fsyntax-only, -E, -S, etc) skip the link action phase which the
existing condition does not account for.

Since the code no longer specifies OPT_c, I think a single RUN line about -c
not leading to a warning is sufficient. Adding one for all of -E,
-fsyntax-only, -S would be excessive.

Reviewed By: benshi001

Differential Revision: https://reviews.llvm.org/D122553
2022-03-28 09:43:36 -07:00
Ben Shi
b62ea9b38b [AVR] Add more devices
Synchronize device list with avr-gcc 7.3.0 and avrlibc 2.0.0.

Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D122401
2022-03-25 01:43:41 +00:00
Ben Shi
6edfe45a63 [AVR] Add more devices
Synchronize AVR device lists with gcc-avr-5.4.0 and avr-libc-2.0.0.

Reviewed By: dylanmckay, aykevl

Differential Revision: https://reviews.llvm.org/D121359
2022-03-23 02:00:15 +00:00
Ben Shi
653836251a [clang][AVR] Set '-fno-use-cxa-atexit' to default
AVR is baremetal environment, so the avr-libc does not support
'__cxa_atexit()'.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D118445
2022-01-30 02:26:19 +00:00
Benjamin Kramer
2e20ff8c1a [AVR] Remove a global initializer. NFCI. 2021-11-07 16:30:18 +01:00
Nico Weber
973519826e [clang-cl] Emit nicer warning on unknown /arch: arguments
Now prints the list of known archs. This requires plumbing a Driver
arg through a few functions.

Also add two more convenience insert() overlods to StringMap.

Differential Revision: https://reviews.llvm.org/D109105
2021-09-02 10:37:32 -04:00
Ben Shi
b31199bab4 [AVR][clang] Improve search for avr-libc installation path
Search avr-libc path according to avr-gcc installation at first,
then other possible installed pathes.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D107682
2021-08-17 11:51:35 +08:00
Matt Jacobson
71e71067f3 [AVR][clang] Add '$SYSROOT/avr' to possible avr-libc locations
Reviewed by: benshi001

Differential Revision: https://reviews.llvm.org/D107672
2021-08-07 10:24:14 +08:00
Matt Jacobson
dae7adda94 [AVR][clang] Pass '-fno-use-init-array' to cc1 as default
On AVR, '.ctors' is used, not '.init_array'. Make this the default
unless specifically overridden by driver argument.

This matches gcc, and it matches the behavior in (e.g.) the NetBSD
driver (for certain OS variants).

Reviewed by: MaskRay

Differential Revision: https://reviews.llvm.org/D107610
2021-08-06 10:14:23 +08:00