671 Commits

Author SHA1 Message Date
Sergei Barannikov
d6679d5a5f
[Target] Remove SoftFail field on targets that don't use it (NFC) (#154659)
That is, on all targets except ARM and AArch64.
This field used to be required due to a bug, it was fixed long ago
by 23423c0ea8d414e56081cb6a13bd8b2cc91513a9.
2025-08-21 05:21:42 +03:00
Kazu Hirata
cbf5af9668
[llvm] Remove unused includes (NFC) (#154051)
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-08-17 23:46:35 -07:00
Nikita Popov
01bc742185
[CodeGen] Give ArgListEntry a proper constructor (NFC) (#153817)
This ensures that the required fields are set, and also makes the
construction more convenient.
2025-08-15 18:06:07 +02:00
Nikita Popov
2bf2b6b24d
[AVR] Only specify one legal int string in data layout (#153010)
There should not be both `n8` and `n16:8`. This is a single list of
legal integers. Additionally, this should use the standard order in
increasing size `n8:16`.
2025-08-11 20:42:28 +02:00
Trevor Gross
733fddb6f4
[AVR] Change half to use softPromoteHalfType (#152783)
The default `half` legalization has some issues with quieting NaNs and
carrying excess precision. As has been done for various other targets,
update AVR to use `softPromoteHalfType` which avoids these issues.

The most obvious corrected test below is `test_load_store`, which no
longer contains calls to extend and trunc (this passing through libcalls
means that `f16` does not round trip).

Fixes the AVR part of https://github.com/llvm/llvm-project/issues/97975
Fixes the AVR part of https://github.com/llvm/llvm-project/issues/97981
2025-08-10 11:39:27 +08:00
Krzysztof Parzyszek
f89306fe74 [AVR] Fix build break with shared libraries
For example:

/usr/bin/ld: lib/Target/AVR/CMakeFiles/LLVMAVRCodeGen.dir/AVRTargetMachi
ne.cpp.o: in function `llvm::TargetTransformInfoImplCRTPBase<llvm::AVRTT
IImpl>::~TargetTransformInfoImplCRTPBase()':
AVRTargetMachine.cpp:(.text._ZN4llvm31TargetTransformInfoImplCRTPBaseINS
_10AVRTTIImplEED2Ev[_ZN4llvm31TargetTransformInfoImplCRTPBaseINS_10AVRTT
IImplEED5Ev]+0x13): undefined reference to `llvm::TargetTransformInfoImp
lBase::~TargetTransformInfoImplBase()'

Add missing dependencies to CMakeLists.txt.
2025-08-09 08:36:59 -05:00
Tom Vijlbrief
160f5ca0f5
[AVR][NFC] Split AVRTargetTransformInfo.h to AVRTargetTransformInfo.cpp (#152841) 2025-08-09 16:09:45 +08:00
Tom Vijlbrief
97f0ff0c80
[AVR] Fix Avr indvar detection and strength reduction (missed optimization) (#152028)
Fix https://github.com/llvm/llvm-project/issues/151080
2025-08-09 12:46:32 +08:00
Ayke
aeeb9b5077
[AVR] Fix codegen after getConstant assertions got enabled (#152269)
This fixes https://github.com/llvm/llvm-project/issues/152097

This commit fixes two instances of a (somewhat) recently enabled
assertion. One with a test, the other I can't reproduce (might be dead
code) but certainly looks like an instance of the same problem.

The PR that introduced the regression:
https://github.com/llvm/llvm-project/pull/117558

With this patch, the AVR backend is usable again for TinyGo.
2025-08-07 11:40:33 +02:00
Fangrui Song
d3589edafc MCAsmBackend::applyFixup: Change Data to indicate the relocated location
`Data` now references the first byte of the fixup offset within the current fragment.

MCAssembler::layout asserts that the fixup offset is within either the
fixed-size content or the optional variable-size tail, as this is the
most the generic code can validate without knowing the target-specific
fixup size.

Many backends applyFixup assert
```
assert(Offset + Size <= F.getSize() && "Invalid fixup offset!");
```

This refactoring allows a subsequent change to move the fixed-size
content outside of MCSection::ContentStorage, fixing the
-fsanitize=pointer-overflow issue of #150846

Pull Request: https://github.com/llvm/llvm-project/pull/151724
2025-08-02 09:27:06 -07:00
Fangrui Song
491c7bdd58 MCAsmBackend::applyFixup: Replace Data.getSize() with F.getSize()
to facilitate replacing `MutableArrayRef<char> Data` (fragment content)
with the relocated location. This is necessary to fix the
pointer-overflow sanitizer issue and reland #150846
2025-08-01 00:31:51 -07:00
Fangrui Song
d9489fd073 AVR,BPF: Derive from MCAsmInfoELF
instead of MCAsmInfo. MCAsmInfo is derived by object file format
MCAsmInfo.
2025-07-26 14:42:08 -07:00
Fangrui Song
2571924ad6 MCSectionELF: Remove classof
The object file format specific derived classes are used in context like
MCStreamer and MCObjectTargetWriter where the type is statically known.
We don't use isa/dyn_cast and we want to eliminate
MCSection::SectionVariant in the base class.
2025-07-25 09:50:19 -07:00
Kazu Hirata
3e53d4d386
[llvm] Remove unused includes (NFC) (#150265)
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-07-23 15:18:46 -07:00
Tom Vijlbrief
9f29007999
[AVR] Force to emit relocation slots for relative branch instructions (#145291)
fixes https://github.com/llvm/llvm-project/issues/133579
2025-07-20 22:10:31 +08:00
Tom Vijlbrief
60b168c146
[AVR] Simplify SPWRITE on XMEGA (#147210)
It is unnecessary to disable/restore interrupt when writing to the SPH/SPL
pair on XMEGA devices, as the manual indicates:

```
To prevent corruption when updating the stack pointer from software,
a write to SPL will automatically disable interrupts for up to four instructions
or until the next I/O memory write.
```
2025-07-14 09:40:37 +08:00
Tom Vijlbrief
6d98f67f31
[AVR] Fix broken link in README.md (#146821)
Fix broken link
2025-07-12 19:51:03 +02:00
Fangrui Song
0b49f2f485 MCSpecifierExpr: Use SubclassData to encode the relocation specifier 2025-07-08 23:39:05 -07:00
Fangrui Song
aec88832df MC: Remove unneeded MCFixupKind casts 2025-07-05 14:43:34 -07:00
Fangrui Song
5a40023497 MCAsmBackend: Reduce FK_NONE uses 2025-07-05 13:22:07 -07:00
Fangrui Song
244e053b6c MC: Remove llvm/MC/MCFixupKindInfo.h
The file used to define `MCFixupKindInfo`, a simple structure,
which is now in MCAsmBackend.h.
2025-07-05 11:24:11 -07:00
Fangrui Song
7b7dc151a7 AVRMCCodeEmitter: Set PCRel at fixup creation
Avoid reliance on the MCAssembler::evaluateFixup workaround that checks
MCFixupKindInfo::FKF_IsPCRel. Additionally, standardize how fixups are
appended. This helper will facilitate future fixup data structure
optimizations.
2025-07-04 18:08:46 -07:00
Fangrui Song
20b3ab5683 MCFixup: Remove unused Loc argument
MCFixup::Loc has been removed in favor of MCExpr::Loc through
`const MCExpr *Value` (commit 777391a2164b89d2030ca013562151ca3c3676d1).
2025-07-04 12:23:04 -07:00
Fangrui Song
dd2891535d
MCAsmBackend: Merge addReloc into applyFixup (#146820)
Follow-up to #141333. Relocation generation called both addReloc and
applyFixup, with the default addReloc invoking shouldForceRelocation,
resulting in three virtual calls. This approach was also inflexible, as
targets needing additional data required extending
`shouldForceRelocation` (see #73721, resolved by #141311).

This change integrates relocation handling into applyFixup, eliminating
two virtual calls. The prior default addReloc is renamed to
maybeAddReloc. Targets overriding addReloc now call their customized
addReloc implementation.
2025-07-02 23:14:11 -07:00
Fangrui Song
e878b7e349 MCParsedAsmOperand::print: Add MCAsmInfo parameter
so that subclasses can provide the appropriate MCAsmInfo to print
MCExpr objects.

At present, llvm/utils/TableGen/AsmMatcherEmitter.cpp constucts a
generic MCAsmInfo.
2025-06-28 12:05:33 -07:00
Fangrui Song
d93aff42c2 MC: Migrate away from operator<< MCExpr
MCExpr::print has an optional MCAsmInfo argument, which is error-prone
when omitted. MCExpr::print and the convenience helper operator<< are
discouraged to use. Switch to MCAsmInfo::printExpr instead. Use the
target-specific MCAsmInfo if available.
2025-06-28 10:58:09 -07:00
Fangrui Song
5aa3e6baa0 MC: Reduce MCSymbolRefExpr::VK_None uses 2025-06-27 21:46:36 -07:00
Fangrui Song
af2bf2e544 MC: Remove unneeded MCSymbolRefExpr::VariantKind calls 2025-06-27 09:47:53 -07:00
Patryk Wychowaniec
c7d9eabf4a
[AVR] Don't apply post-indexing on mismatched pointers (#145224)
fixes https://github.com/llvm/llvm-project/issues/143247
2025-06-22 18:18:00 +08:00
Andrew Rogers
19658d1474
[llvm] annotate interfaces in llvm/Target for DLL export (#143615)
## Purpose

This patch is one in a series of code-mods that annotate LLVM’s public
interface for export. This patch annotates the `llvm/Target` library.
These annotations currently have no meaningful impact on the LLVM build;
however, they are a prerequisite to support an LLVM Windows DLL (shared
library) build.

## Background

This effort is tracked in #109483. Additional context is provided in
[this
discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307),
and documentation for `LLVM_ABI` and related annotations is found in the
LLVM repo
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst).

A sub-set of these changes were generated automatically using the
[Interface Definition Scanner (IDS)](https://github.com/compnerd/ids)
tool, followed formatting with `git clang-format`.

The bulk of this change is manual additions of `LLVM_ABI` to
`LLVMInitializeX` functions defined in .cpp files under llvm/lib/Target.
Adding `LLVM_ABI` to the function implementation is required here
because they do not `#include "llvm/Support/TargetSelect.h"`, which
contains the declarations for this functions and was already updated
with `LLVM_ABI` in a previous patch. I considered patching these files
with `#include "llvm/Support/TargetSelect.h"` instead, but since
TargetSelect.h is a large file with a bunch of preprocessor x-macro
stuff in it I was concerned it would unnecessarily impact compile times.

In addition, a number of unit tests under llvm/unittests/Target required
additional dependencies to make them build correctly against the LLVM
DLL on Windows using MSVC.

## Validation

Local builds and tests to validate cross-platform compatibility. This
included llvm, clang, and lldb on the following configurations:

- Windows with MSVC
- Windows with Clang
- Linux with GCC
- Linux with Clang
- Darwin with Clang
2025-06-17 13:28:45 -07:00
Fangrui Song
a02afb0def AVR: Migrate to the new relocation specifier representation
Define printImpl and evaluateAsRelocationImpl within AVRMCAsmInfo.
2025-06-16 20:40:17 -07:00
Fangrui Song
5acdd8d0cf AVR: Rename AVRMCExpr::VK_ to AVR::S_
Prepare for removing AVRMCExpr. Adopt the new naming convention (S_
instead of VK_; the relocation specifier was previously named
`VariantKind`)) used by most other targets.

Make AVRMCAsmInfo.h include AVRMCExpr.h and change .cpp files to include
AVRMCAsmInfo.h. We will eventually remove AVRMCExpr.h.
2025-06-16 09:15:59 -07:00
Fangrui Song
29fcad000c AVR: Replace deprecated MCExpr::print with MCAsmInfo::printExpr 2025-06-15 21:27:12 -07:00
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
Fangrui Song
dcb8cd8ecd ARM: Replace deprecated MCExpr::print with MCAsmInfo::printExpr 2025-06-15 17:19:14 -07: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
Fangrui Song
39064519cb AVRMCExpr: Migrate to MCSpecifierExpr 2025-06-08 00:15:32 -07:00
Matt Arsenault
437b16085c
AVR: Move runtime libcall name setting out of TargetLowering (#142545)
RuntimeLibcallInfo needs to be accurate outside of codegen
contexts.
2025-06-04 10:52:25 +09:00
Kazu Hirata
86eb419ba1
[llvm] Remove unused includes (NFC) (#141526)
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 14:57:16 -07:00
Fangrui Song
cb7d68a77b MCParser: Replace deprecated alias MCAsmLexer with AsmLexer 2025-05-25 12:08:40 -07:00
Fangrui Song
a0901a2f87 Replace #include MCAsmLexer.h with AsmLexer.h
MCAsmLexer.h has been made a forwarder header since #134207
2025-05-25 11:57:29 -07:00
Fangrui Song
fe32806d67 ELFObjectWriter: Remove the MCContext argument from getRelocType
Additionally, swap MCFixup/MCValue order to match addReloc/recordRelocation.
2025-05-24 21:48:11 -07:00
Fangrui Song
e373f7a452 MC: Simplify recordRelocation
* Remove the MCAssembler * argument. Change subclasses to use MCAssembler *MCObjectWriter::Asm.
* Remove pure specifier and add an empty implementation
* Change MCFragment * to MCFragment &
2025-05-24 09:54:03 -07:00
Fangrui Song
75dbda4601 MCAsmBackend: Remove the MCAssembler argument from addReloc 2025-05-23 23:33:55 -07:00
Fangrui Song
871b0a3221
MCAsmBackend: Simplify applyFixup (#141333)
Remove the MCSubtargetInfo argument from applyFixup, introduced in
https://reviews.llvm.org/D45962 , as it's only required by ARM. Instead,
add const MCFragment & so that ARMAsmBackend can retrieve
MCSubtargetInfo via a static member function.

Additionally, remove the MCAssembler argument, which is also only
required by ARM.

Additionally, make applyReloc non-const. Its arguments now fully cover
addReloc's functionality.
2025-05-23 23:09:56 -07:00
Fangrui Song
84f06b88b6 MCAsmBackend: Add member variable MCAssembler * and define getContext
A lot of member functions have the MCAssembler * argument just to call
getContext. Let's cache the MCAssembler pointer.
2025-05-23 23:01:30 -07:00
Fangrui Song
f0ff2bea75 MCAsmBackend: Remove MCSubtargetInfo argument
After #141311 removed the MCSubtargetInfo argument from
shouldForceRelocation, addReloc does not need this argument, either.

In a rare scenario that the information is needed, the target should
check the MCFragment subclass and get it from
MCDataFragment/MCRelaxableFragment.
2025-05-23 20:55:42 -07:00
Fangrui Song
89909d826a AVRAsmBackend: Don't use the MCSubtargetInfo argument
The argument will be removed from `addReloc`.
Use MCContext::getSubtargetInfo instead, to be consistent with other
adjustRelativeBranch calls.
2025-05-23 20:41:44 -07:00
Fangrui Song
ccffa1d3fe
[MC] Don't pass MCSubtargetInfo down to shouldForceRelocation and evaluateTargetFixup (#141311)
This reverts the code change in commit
e87f33d9ce785668223c3bcc4e06956985cccda1 (#73721) but keeps its test.
There have been many changes to lib/MC and AsmBackend.cpp files, so this
is not a pure revert.

#73721, a workaround to generate necessary relocations in mixed
non-relax/relax code,
is no longer necessary after #140692 fixed the root issue (whether two
locations are separated by a fragment with indeterminate size due to
linker relaxation).
2025-05-23 20:21:15 -07:00