2450 Commits

Author SHA1 Message Date
Nikita Popov
406d9b1dd6
[CodeGen] Move IsFixed into ArgFlags (NFCI) (#152319)
The information whether a specific argument is vararg or fixed is
currently stored separately from all the other argument information in
ArgFlags. This means that it is not accessible from CCAssign, and
backends have developed all kinds of workarounds for how they can access
it after all.

Move this information to ArgFlags to make it directly available in all
relevant places.

I've opted to invert this and store it as IsVarArg, as I think that both
makes the meaning more obvious and provides for a better default (which
is IsVarArg=false).
2025-08-07 09:12:40 +02:00
Fangrui Song
5570ce5cef MCSymbolELF: Migrate away from classof
The object file format specific derived classes are used in context
where the type is statically known. We don't use isa/dyn_cast and we
want to eliminate MCSymbol::Kind in the base class.
2025-08-03 15:17:13 -07: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
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
Jessica Clarke
4b99eb2eb4
[Sparc] Remove bogus stack adjustment for LD/GD TLS (#149890)
This argument is the number of bytes to adjust the stack by for the
duration of the call. In most cases, PEI is able to eliminate the
corresponding call frame pseudos, folding them into the initial stack
frame allocation (rounded up to stack alignment), where it just ends up
allocating more space than needed. However, in the rare case where this
cannot be done, e.g. due to the use of a dynamic alloca, the 1 byte
stack adjustment persists and results in a misaligned stack for the
duration of the call. This has been the case ever since TLS support was
added in cb1dca602c43 ("[Sparc] Add support for TLS in sparc."), and I
can only assume that 1 was used erroneously thinking that it is the
number of arguments (as there is 1 register argument for the call), not
the number of bytes for on-stack arguments.

Fixes: https://github.com/llvm/llvm-project/issues/149808
2025-07-22 16:44:18 +01:00
Fangrui Song
5ba458c559 MCFixup: Replace getTargetKind with getKind 2025-07-15 00:21:07 -07:00
Fangrui Song
0b674f4c52 MCFixup: Replace getTargetKind with getKind
MCFixupKind is now a type alias (fixup kinds are inherently
target-specific). getTargetKind is no longer necessary.
2025-07-15 00:08:45 -07:00
Kazu Hirata
7c83d66719
[llvm] Remove unused includes (NFC) (#148768)
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-14 22:19:14 -07:00
Matt Arsenault
51c89f3854
SPARC: Start moving runtime libcall config to tablegen (#147672) 2025-07-14 18:17:59 +09:00
Matt Arsenault
df54961d16
SPARC: Remove subtarget checks on setLibcallImpl (#147667)
Remove the subtarget dependent useSoftMulDiv check on the mul/div
libcall configuration. The libcall still needs to exist with the
given ABI for the module regardless of the subtarget dependent
lowering decision which is separately controlled.

Also the f128<->i64 conversion calls were set twice, so eliminate
the redundant setting and always do it for sparc32.
2025-07-14 18:11:54 +09:00
Koakuma
d86c63d8e3
[SPARC][IAS] Add definitions for cryptographic instructions
Reviewers: brad0, rorth, s-barannikov

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/139451
2025-07-13 15:14:51 +07:00
Matt Arsenault
d8ef156379
DAG: Remove verifyReturnAddressArgumentIsConstant (#147240)
The intrinsic argument is already marked with immarg so non-constant
values are rejected by the IR verifier.
2025-07-07 16:28:47 +09: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
7d500b115d SPARC: Remove unneeded MCFixupKindInfo::FKF_IsPCRel
SPARC now sets PCRel at fixup creation and no longer needs to the
MCAssembler::evaluateFixup workaround that checks
MCFixupKindInfo::FKF_IsPCRel.
2025-07-04 15:45:14 -07:00
Fangrui Song
83fbd86909 SPARCMCCodeEmitter: Set PCRel at fixup creation 2025-07-04 15:37:24 -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
Jie Fu
842f4f711d [Target] Prevent copying in loop variables (NFC)
/data/llvm-project/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp:2390:19: error: loop variable '[Reg, N]' creates a copy from type 'std::pair<unsigned int, llvm::SDValue> const' [-Werror,-Wrange-loop-construct]
  for (const auto [Reg, N] : RegsToPass) {
                  ^
/data/llvm-project/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp:2390:8: note: use reference type 'std::pair<unsigned int, llvm::SDValue> const &' to prevent copying
  for (const auto [Reg, N] : RegsToPass) {
       ^~~~~~~~~~~~~~~~~~~~~
                  &
/data/llvm-project/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp:2402:19: error: loop variable '[Reg, N]' creates a copy from type 'std::pair<unsigned int, llvm::SDValue> const' [-Werror,-Wrange-loop-construct]
  for (const auto [Reg, N] : RegsToPass)
                  ^
/data/llvm-project/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp:2402:8: note: use reference type 'std::pair<unsigned int, llvm::SDValue> const &' to prevent copying
  for (const auto [Reg, N] : RegsToPass)
       ^~~~~~~~~~~~~~~~~~~~~
                  &
2 errors generated.
2025-06-29 14:24:41 +08:00
Kazu Hirata
9cf251d9d8
[Target] Use range-based for loops (NFC) (#146253) 2025-06-28 20:41:39 -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
Kazu Hirata
1a94bcf90f
[llvm] Remove unused includes (NFC) (#146199)
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-06-27 22:08:06 -07:00
Matt Arsenault
b88e1f6a79
TableGen: Generate enum for runtime libcall implementations (#144973)
Work towards separating the ABI existence of libcalls vs. the
lowering selection. Set libcall selection through enums, rather
than through raw string names.
2025-06-27 17:40:43 +09:00
Matt Arsenault
48155f93dd
CodeGen: Emit error if getRegisterByName fails (#145194)
This avoids using report_fatal_error and standardizes the error
message in a subset of the error conditions.
2025-06-23 16:33:35 +09:00
Koakuma
dfb5cadf5e
[SPARC][IAS] Properly set implied feature sets for ISA levels/extensions (#143232)
Some SPARC ISA levels and/or extensions are defined in a way such that
the availability of it implies the availability of other, more fundamental
ISA features (for example, targeting 64-bit environment implies that
V9 instructions are available).
Properly set those in the TableGen definitions.

Fixes https://github.com/llvm/llvm-project/issues/142388.
2025-06-20 05:12:51 +07: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
4e884dd993 SPARC: Remove SparcMCExpr.h 2025-06-17 09:42:54 -07:00
Fangrui Song
7c22612b29 SPARC: Remove dead specifier code from asm operand printer
We don't currently print %specifier( ) for asm operands.
The old code was also incorrect - as it did not print "(".
2025-06-15 12:43:37 -07:00
Fangrui Song
254a92d49a MC: Add MCSpecifierExpr::create
as a target-agnostic implementation to replace target-specific
XXXMCExpr::create.
2025-06-15 11:41:33 -07:00
Fangrui Song
3b09a3d5ae MC,SPARC: Replace SparcMCExpr with MCSpecifierExpr
Add a hook printSpecifierExpr so that targets can implement
relocation specifier printing without inheriting from MCSpecifierExpr.
2025-06-13 09:36:38 -07:00
Fangrui Song
43be31e35a SPARC: Simplify SparcMCExpr
Reduce direct uses of SparcMCExpr, facilitating transition to
MCSpecifierExpr in the future.
2025-06-13 00:12:08 -07:00
Fangrui Song
97a32f2ad9 MC: Add MCSpecifierExpr to unify target MCExprs
Many targets define MCTargetExpr subclasses just to encode an expression
with a relocation specifier. Create a generic MCSpecifierExpr to be
inherited instead. Migrate M68k and SPARC as examples.
2025-06-07 11:33:40 -07:00
Fangrui Song
b4382a2c46 SPARC: Modernize AsmBackend
* Move implementations out-of-line to align with other backends.
* clang-format the class.
2025-06-07 09:35:19 -07:00
Koakuma
4c88873be8
[SPARC][IAS] Add definitions for OSA 2011 instructions
Reviewers: rorth, brad0, s-barannikov

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/138403
2025-05-29 22:16:58 +07: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
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
e3e949cf5b MCELFObjectTargetWriter::needsRelocateWithSymbol: Remove MCSymbol argument
Replace MCSymbol argument with MCValue::AddSym. The minor difference in
.weakref handling is negligible, as our implementation may not fully
align with GAS, and .weakref is not used in practice.
2025-05-24 23:55:26 -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
e9339481e5 ARM,Sparc: Avoid using the MCContext & argument
Prepare for removing MCContext from getRelocType functions.
2025-05-24 21:25:19 -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
Koakuma
3f15b66dec
[SPARC] Use op-then-halve instructions when we have VIS3
Reviewers: brad0, s-barannikov, arsenm, rorth

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/135718
2025-05-23 22:44:05 +07:00
Rahul Joshi
52c2e45c11
[NFC][CodeGen] Adopt MachineFunctionProperties convenience accessors (#141101) 2025-05-23 08:30:29 -07:00
Fangrui Song
68472a39a0 [MC] Restore MCAsmBackend::shouldForceRelocation to false
For IsPCRel fixups, we had the `A->getKind() != MCSymbolRefExpr::VK_None`
condition to force relocations. The condition has then been changed to
`Target.getSpecifier()` (086af836889436baffc71c743c7c8259bad8ed60).

38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc updated
shouldForceRelocation to test `Target.getSpecifier`.
It is not a good fit as many targets with %lo/%hi style specifiers
(SPARC, MIPS, PowerPC, RISC-V) do not force relocations for these
specifiers.

Revert the Target.getSpecifier implementation
(38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc) and update
targets that need it (SystemZAsmBackend/X86AsmBackend) instead.
Targets need customization might define addReloc instead.

Note: The X86AsmBackend implementation is too conservative.
GNU Assembler doesn't emit a relocation for `call local@plt; local`
a3d39316764726ed9fd939550c7781199b1eb77e added missing coverage
for GOT/PLT related relocations.
2025-05-22 09:49:27 -07:00
JP Lehr
84841e2ffe Revert "[MC] Restore MCAsmBackend::shouldForceRelocation to false"
This reverts commit 6f6dc1f239433393c0b09430193beb85d03464c8.

Resulted in several bot failures.
2025-05-22 04:15:08 -05:00
Fangrui Song
6f6dc1f239 [MC] Restore MCAsmBackend::shouldForceRelocation to false
Revert the Target.getSpecifier implementation
(38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc) and update SystemZAsmBackend
instead.

Many targets with %lo/%hi style specifiers (SPARC, MIPS, PowerPC,
RISC-V) do not force relocations for these specifiers.

Additionally, with the introduction of the addReloc hook,
shouldForceRelocation is not that necessary and should probably be
phased out.
2025-05-21 22:51:51 -07:00
Koakuma
21b4059b3c
[SPARC] Print target address when disassembling branches and calls (#140340)
Similar to https://reviews.llvm.org/D93241, print target addresses
instead of raw offset values when disassembling branches and calls.

Should fix https://github.com/llvm/llvm-project/issues/122196 and
https://github.com/llvm/llvm-project/issues/139284.
2025-05-19 22:59:59 +07:00
Craig Topper
dcd62f3674
[SelectionDAG] Rename MemSDNode::getOriginalAlign to getBaseAlign. NFC (#139930)
This matches the underlying function in MachineMemOperand and how it is
printed when BaseAlign differs from Align.
2025-05-16 09:37:02 -07:00
Koakuma
87b4cacf2d
[SPARC][IAS][NFC] Rename CBCOND -> CPBCOND
This is in prep for OSA2011 instruction definitions, which has a CBCond
instruction family.

Reviewers: rorth, s-barannikov, brad0

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/138402
2025-05-12 13:28:15 +07:00
Koakuma
cf19c6b5e2
[SPARC][IAS] Add definitions for UA 2007 instructions
Reviewers: rorth, s-barannikov, brad0

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/138401
2025-05-12 13:26:56 +07:00
Koakuma
2e1809f94a
[SPARC][IAS] Add definitions for UA 2005 instructions
Reviewers: rorth, s-barannikov, brad0

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/138400
2025-05-12 07:45:49 +07:00
Matthias Braun
675cb70641
Register assembly printer passes (#138348)
Register assembly printer passes in the pass registry.

This makes it possible to use `llc -start-before=<target>-asm-printer ...` in tests.

Adds a `char &ID` parameter to the AssemblyPrinter constructor to allow
targets to use the `INITIALIZE_PASS` macros and register the pass in the
pass registry. This currently has a default parameter so it won't break
any targets that have not been updated.
2025-05-06 18:01:17 -07:00