89 Commits

Author SHA1 Message Date
Matt Arsenault
a3aaa1a391
DAG: Use RuntimeLibcalls to legalize vector frem calls (#170719)
This continues the replacement of TargetLibraryInfo uses in codegen
with RuntimeLibcallsInfo started in
821d2825a4f782da3da3c03b8a002802bff4b95c.
The series there handled all of the multiple result calls. This
extends for the other handled case, which happened to be frem.

For some reason the Libcall for these are prefixed with "REM_", for
the instruction "frem", which maps to the libcall "fmod".
2025-12-11 13:33:27 +00:00
Matt Arsenault
43e69b1892
RuntimeLibcalls: Add malloc and free entries (#167081)
Calloc was already here, but not the others. Also add
manual type information.
2025-11-26 10:19:00 -05:00
Matt Arsenault
eb5297e0ad
RuntimeLibcalls: Add mustprogress to common function attributes (#167080) 2025-11-25 09:48:36 -05:00
Matt Arsenault
590ab43e8a
RuntimeLibcalls: Move VectorLibrary handling into TargetOptions (#167996)
This fixes the -fveclib flag getting lost on its way to the backend.

Previously this was its own cl::opt with a random boolean. Move the
flag handling into CommandFlags with other backend ABI-ish options,
and have clang directly set it, rather than forcing it to go through
command line parsing.

Prior to de68181d7f, codegen used TargetLibraryInfo to find the vector
function. Clang has special handling for TargetLibraryInfo, where it
would
directly construct one with the vector library in the pass pipeline.
RuntimeLibcallsInfo currently is not used as an analysis in codegen, and
needs to know the vector library when constructed.

RuntimeLibraryAnalysis could follow the same trick that
TargetLibraryInfo is using in the future, but a lot more boilerplate changes 
are needed to thread that analysis through codegen. Ideally this would come 
from an IR module flag, and nothing would be in TargetOptions. For now, it's 
better for all of these sorts of controls to be consistent.
2025-11-14 11:19:21 -08:00
Matt Arsenault
75e38aa649
RuntimeLibcalls: Add libcall entries for sleef and armpl modf functions (#166985) 2025-11-12 02:01:15 +00:00
Matt Arsenault
f2f04c363c
RuntimeLibcalls: Add call entries for sincos sleef and armpl libcalls (#166983)
These are the tested set of libcalls used for codegen of llvm.sincos
and are needed to get the legalization to follow standard procedure.
2025-11-10 12:00:02 -08:00
Matt Arsenault
b7423af8da
RuntimeLibcalls: Add entries for vector sincospi functions (#166981)
Add libcall entries for sleef and armpl sincospi implementations.
This is the start of adding the vector library functions; eventually
they should all be tracked here.

I'm starting with this case because this is a prerequisite to fix
reporting sincospi calls which do not exist on any common targets
without
regressing vector codegen when these libraries are available.
2025-11-10 10:56:33 -08:00
Matt Arsenault
ac547a532a
Analysis: Add RuntimeLibcall analysis pass (#165196)
Currently RuntimeLibcallsInfo is a hardcoded list based on the triple.
In the future the available libcall set should be dynamically modifiable
with module flags.

Note this isn't really used yet. TargetLowering is still constructing
its own copy, and untangling that to use this requires several more
steps.
2025-11-05 14:48:50 -08:00
Matt Arsenault
056d2c12f7
RuntimeLibcalls: Split lowering decisions into LibcallLoweringInfo (#164987)
Introduce a new class for the TargetLowering usage. This tracks the
subtarget specific lowering decisions for which libcall to use.
RuntimeLibcallsInfo is a module level property, which may have multiple
implementations of a particular libcall available. This attempts to be
a minimum boilerplate patch to introduce the new concept.

In the future we should have a tablegen way of selecting which
implementations should be used for a subtarget. Currently we
do have some conflicting implementations added, it just happens
to work out that the default cases to prefer is alphabetically
first (plus some of these still are using manual overrides
in TargetLowering constructors).
2025-11-05 17:10:36 +00:00
Matt Arsenault
fb21f16fe6
RuntimeLibcalls: Add stub API for getting function signatures (#166290)
Eventually this should be generated by tablegen for all functions.
For now add a manually implementation for sincos_stret, which I
have an immediate use for. This will allow pulling repeated code
across targets into shared call sequence code.

Also add sqrt just to make sure we can handle adding return attributes
on the declaration.
2025-11-04 10:06:29 -08:00
Matt Arsenault
b74801ad87
TableGen: Use IfDefEmitter (#164209) 2025-10-21 10:09:05 +09:00
Matt Arsenault
fc0f1fc695
ARM: Move remaining half convert libcall config into tablegen (#153408)
The __truncdfhf2 handling is kind of convoluted, but reproduces
the existing, likely wrong, handling.
2025-09-11 12:11:46 +09:00
Daniel Paoliello
f99b0f3de4
[NFC] RuntimeLibcalls: Prefix the impls with 'Impl_' (#153850)
As noted in #153256, TableGen is generating reserved names for
RuntimeLibcalls, which resulted in a build failure for Arm64EC since
`vcruntime.h` defines `__security_check_cookie` as a macro.

To avoid using reserved names, all impl names will now be prefixed with
`Impl_`.

`NumLibcallImpls` was lifted out as a `constexpr size_t` instead of
being an enum field.

While I was churning the dependent code, I also removed the TODO to move
the impl enum into its own namespace and use an `enum class`: I
experimented with using an `enum class` and adding a namespace, but we
decided it was too verbose so it was dropped.
2025-09-02 09:57:33 -07:00
Matt Arsenault
19ebfa6d0b
RuntimeLibcalls: Move exception call config to tablegen (#151948)
Also starts pruning out these calls if the exception model is
forced to none.

I worked backwards from the logic in addPassesToHandleExceptions
and the pass content. There appears to be some tolerance
for mixing and matching exception modes inside of a single module.
As far as I can tell _Unwind_CallPersonality is only relevant for
wasm, so just add it there.

As usual, the arm64ec case makes things difficult and is
missing test coverage. The set of calls in list form is necessary
to use foreach for the duplication, but in every other context a
dag is more convenient. You cannot use foreach over a dag, and I
haven't found a way to flatten a dag into a list.

This removes the last manual setLibcallImpl call in generic code.
2025-08-19 10:35:59 +09:00
Matt Arsenault
fe67267d19
MSP430: Move __mspabi_mpyll calling conv config to tablegen (#153988)
There are several libcall choices for MUL_I64 which depend on the
subtarget, but this is the base case. The manual custom ISelLowering
is still overriding the decision until we have a way to control
lowering choices, but we can still get the calling convention
set for now.
2025-08-19 10:25:10 +09:00
Matt Arsenault
3e5d8a1439 Reapply "RuntimeLibcalls: Generate table of libcall name lengths (#153… (#153864)
This reverts commit 334e9bf2dd01fbbfe785624c0de477b725cde6f2.

Check if llvm-nm exists before building the benchmark.
2025-08-16 09:53:50 +09:00
gulfemsavrun
334e9bf2dd
Revert "RuntimeLibcalls: Generate table of libcall name lengths (#153… (#153864)
…210)"

This reverts commit 9a14b1d254a43dc0d4445c3ffa3d393bca007ba3.

Revert "RuntimeLibcalls: Return StringRef for libcall names (#153209)"

This reverts commit cb1228fbd535b8f9fe78505a15292b0ba23b17de.

Revert "TableGen: Emit statically generated hash table for runtime
libcalls (#150192)"

This reverts commit 769a9058c8d04fc920994f6a5bbb03c8a4fbcd05.

Reverted three changes because of a CMake error while building llvm-nm
as reported in the following PR:
https://github.com/llvm/llvm-project/pull/150192#issuecomment-3192223073
2025-08-15 13:32:27 -07:00
Matt Arsenault
769a9058c8
TableGen: Emit statically generated hash table for runtime libcalls (#150192)
a96121089b9c94e08c6632f91f2dffc73c0ffa28 reverted a change
to use a binary search on the string name table because it
was too slow. This replaces it with a static string hash
table based on the known set of libcall names. Microbenchmarking
shows this is similarly fast to using DenseMap. It's possibly
slightly slower than using StringSet, though these aren't an
exact comparison. This also saves on the one time use construction
of the map, so it could be better in practice.

This search isn't simple set check, since it does find the
range of possible matches with the same name. There's also
an additional check for whether the current target supports
the name. The runtime constructed set doesn't require this,
since it only adds the symbols live for the target.

Followed algorithm from this post
http://0x80.pl/notesen/2023-04-30-lookup-in-strings.html

I'm also thinking the 2 special case global symbols should
just be added to RuntimeLibcalls. There are also other global
references emitted in the backend that aren't tracked; we probably
should just use this as a centralized database for all compiler
selected symbols.
2025-08-15 09:02:56 +09:00
Matt Arsenault
ddb2dc50af
ARM: Move gnu half convert calling conv config into tablegen (#153394) 2025-08-14 17:36:29 +09:00
Matt Arsenault
bbcac029db
ARM: Move more aeabi libcall config into tablegen (#152109) 2025-08-14 15:43:15 +09:00
Matt Arsenault
32f1fe3770
ARM: Move calling conv config to RuntimeLibcalls (#152065)
Consolidate module level ABI into RuntimeLibcalls
2025-08-14 08:36:03 +09:00
Matt Arsenault
1392edcc07
ARM: Remove idiv runtime call aliases (#152098)
Really only the i32 variants exist. We don't need synthetic
aliases for illegal types which will be promoted.
2025-08-05 17:49:22 +09:00
Matt Arsenault
1862e3c56c
RuntimeLibcalls: Move __stack_smash_handler config to tablegen (#150870) 2025-08-04 17:27:44 +09:00
Matt Arsenault
144cd87088
RuntimeLibcalls: Remove target check for sjlj config (#148792)
I'm assuming this was the set of targets that were relevant
for sjlj handling. Just take the raw exception setting instead,
and assume it makes sense for the target.
2025-08-04 14:15:53 +09:00
Matt Arsenault
5478da99a1
RuntimeLibcalls: Move __stack_chk_fail config to tablegen (#148789) 2025-08-04 13:02:57 +09:00
Matt Arsenault
5b528a1041
RuntimeLibcalls: Remove darwin override of half convert libcalls (#148782)
These are already the default calls set for these conversions, so
they should not require explicit setting. The non-default cases are
currently overridden in ARMISelLowering. Just delete this until
the list of calls and lowering decisions are separated.

This was added back in 6402ad27c01c9503a12d41d7e40646cf0d1f919f. It
appears to not be relevant for AArch64, where calls appear to never
be used for these. It also appears to not be relevant for x86, where
the default calls seem to always end up used anyway.
2025-08-04 11:06:03 +09:00
Matt Arsenault
b2f0ffd659
RuntimeLibcalls: Really move default libcall handling to tablegen (#148780)
Hack in the default setting so it's consistently generated like
the other cases. Maintain a list of targets where this applies.
The alternative would require new infrastructure to sort the system
library initialization in some way.

I wanted the unhandled target case to be treated as a fatal
error, but it turns out there's a hack in IRSymtab using
RuntimeLibcalls, which will fail out in many tests that
do not have a triple set. Many of the failures are simply
running llvm-as with no triple, which probably should not
depend on knowing an accurate set of calls.
2025-08-04 08:32:00 +09:00
Matt Arsenault
d0d3f15c38
RuntimeLibcalls: Stop opting out of exp10 (#148604) 2025-08-04 00:08:46 +09:00
Matt Arsenault
0b7a95a6fd Partially Reapply "RuntimeLibcalls: Add methods to recognize libcall names (#149001)"
This partially reverts commit a96121089b9c94e08c6632f91f2dffc73c0ffa28.

Drop the IRSymtab changes for now
2025-07-18 18:06:26 +09:00
Nikita Popov
a96121089b Revert "RuntimeLibcalls: Add methods to recognize libcall names (#149001)"
This reverts commit 45477add8dfe9851605697bd908b49f0ec244625.

This causes a significant LTO compile-time regression.
2025-07-18 10:15:19 +02:00
Matt Arsenault
45477add8d
RuntimeLibcalls: Add methods to recognize libcall names (#149001)
Also replace the current static DenseMap of preserved symbol
names in the Symtab hack with this. That was broken statefulness
across compiles, so this at least fixes that. However this is
still broken, llvm-as shouldn't really depend on the triple.
2025-07-18 08:53:32 +09:00
Matt Arsenault
af56fd0c1a
TableGen: Use StringOffsetTable for RuntimeLibcall names (#148839) 2025-07-15 23:24:46 +09:00
Matt Arsenault
259a11db5e
StackProtector: Use RuntimeLibcalls to query libcall names (#147913)
The compiler should not introduce calls to arbitrary strings
that aren't defined in RuntimeLibcalls. Previously OpenBSD was
disabling the default __stack_chk_fail, but there was no record
of the alternative __stack_smash_handler function it emits instead.

This also avoids a random triple check in the pass.
2025-07-15 18:37:59 +09:00
Matt Arsenault
0991435fc3
RuntimeLibcalls: Mostly move x86 configuration into tablegen (#148575)
This is getting pretty ugly, but seems to be the worst of the
cases. Opting out of the base set of calls for the various windows
cases is really ugly. We need to apply that to the arm cases as well.

It also may make sense to go back to transposing the architecture
and operating system (i.e. make isOSWindows the SystemLibrary
and then modify based on architecture).
2025-07-15 16:18:34 +09: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
d1db176e82
ARM: Stop setting sincos_stret calling convention (#147457)
This was going out of its way to explicitly mark these as
ARM_AAPCS_VFP. This has been explicitly set since 8b40366b54bd4,
where the commit message states that "sincos" (not sincos_stret)
has a special calling convention. However, that commit also sets
the calling convention for all libcalls to ARM_AAPCS_VFP, and
getEffectiveCallingConv returns the same for CCC anyway in tests
using isWatchABI triples.

The net result of this appears to be a change in behavior when
using -float-abi=soft with isWatchABI, which have no tests so
I assume this is a theoretical combination.

If I assert
```
  if (getTargetMachine().getTargetTriple().isWatchABI()) {
    assert(!useSoftFloat());
    assert(getEffectiveCallingConv(CallingConv::C, false) == CallingConv::ARM_AAPCS_VFP);
  }
```
Only 2 tests fail the second condition, which look like copy paste
accidents
using v7k triples with linux and only needed a filler triple. This is a
consequence
of strangely using the target architecture in place of the OS ABI check,
as was done in 042a6c1fe19caf48af7e287dc8f6fd5fec158093
2025-07-15 08:30:49 +09:00
Matt Arsenault
301a1d565f
RuntimeLibcalls: Invert handling of 64-bit only libcalls (#148571)
Switch the default set to exclude these conditionally available
calls, so they are opt-in instead of opt-out.
2025-07-15 00:59:54 +09:00
Matt Arsenault
91d017a7c0
RuntimeLibcalls: Remove __muloti4 from default libcall set (#148562)
The current logic says it's only available on wasm, so only
explicitly add it there. Also fix a misnomer in the compiler-rt
call list.
2025-07-15 00:56:01 +09:00
Matt Arsenault
83632788c9
Hexagon: Move runtime libcall configuration to tablegen (#147482) 2025-07-13 10:44:49 +09:00
Matt Arsenault
7299250c03
DAG: Use fast variants of fast math libcalls (#147481)
Hexagon currently has an untested global flag to control fast
math variants of libcalls. Add fast variants as explicit libcall
options so this can be a flag based lowering decision, and implement
it. I have no idea what fast math flags the hexagon case requires,
so I picked the maximally potentially relevant set of flags although
this probably is refinable per call. Looking in compiler-rt, I'm not
sure if the fast variants are anything more than aliases.
2025-07-13 10:41:45 +09:00
Matt Arsenault
953416ae40
ARM: Start moving runtime libcalls into tablegen (#146084)
We still need to manually set the calling conventions of
some libcalls until the lowering is separated out.
2025-07-10 19:38:31 +09:00
Matt Arsenault
deade03910
ARM: Unconditionally set eabi libcall calling convs in RuntimeLibcalls (#146083)
This fully consolidates all the calling convention configuration into
RuntimeLibcallInfo. I'm assuming that __aeabi functions have a universal
calling convention, and on other ABIs just don't use them. This will
enable splitting of RuntimeLibcallInfo into the ABI and lowering component.
2025-07-09 17:16:48 +09:00
Matt Arsenault
dc69b00b0a
RuntimeLibcalls: Remove table of soft float compare cond codes (#146082)
Previously we had a table of entries for every Libcall for
the comparison to use against an integer 0 if it was a soft
float compare function. This was only relevant to a handful of
opcodes, so it was wasteful. Now that we can distinguish the
abstract libcall for the compare with the concrete implementation,
we can just directly hardcode the comparison against the libcall
impl without this configuration system.
2025-07-09 17:13:58 +09:00
Matt Arsenault
ae496bfac0
MSP430: Move libcall CC setting to RuntimeLibcallsInfo (#146081)
As a temporary step configure the calling convention here. This
can't be moved into tablegen until RuntimeLibcallsInfo is split
into a separate lowering component.
2025-07-08 17:18:48 +09:00
Matt Arsenault
58ad99606b
TableGen: Handle setting runtime libcall calling conventions (#144980)
Allow associating a non-default CallingConv with a set of library
functions, and applying a default for a SystemLibrary.

I also wanted to be able to apply a default calling conv
to a RuntimeLibcallImpl, but that turned out to be annoying
so leave it for later.
2025-07-08 17:12:48 +09:00
Matt Arsenault
dd9646565e ARM: Move sjlj libcall configuration to RuntimeLibcalls
Manually submitting, closes #147227
2025-07-08 13:52:32 +09:00
Matt Arsenault
591b0d0fdf
RuntimeLibcalls: Associate calling convention with libcall impls (#144979)
Instead of associating the libcall with the RTLIB::Libcall, put it
into a table indexed by the RTLIB::LibcallImpl. The LibcallImpls
should contain all ABI details for a particular implementation, not
the abstract Libcall. In the future the wrappers in terms of the
RTLIB::Libcall should be removed.
2025-07-08 10:20:52 +09:00
Matt Arsenault
5088231e52
TableGen: Allow defining sets of runtime libraries (#144978)
Add a way to define a SystemLibrary for a complete set of
libcalls, subdivided by a predicate based on the triple.
Libraries can be defined using dag set operations, and the
prior default set can be subtracted from and added to (though
I think eventually all targets should move to explicit opt-ins.
We're still doing things like reporting ppcf128 libcalls as
available dy default on all targets).

Start migrating some of the easier targets to only use the new
system. Targets that don't define a SystemLibrary are still
manually mutating a table set to the old defaults.
2025-07-08 10:17:45 +09:00
Matt Arsenault
b4d3283ab7
AArch64: Add libcall impl declarations for __arm_sc* memory functions (#144977)
These were bypassing the ordinary libcall emission mechanism. Make sure
we have entries in RuntimeLibcalls, which should include all possible
calls the compiler could emit.

Fixes not emitting the # prefix in the arm64ec case.
2025-06-27 17:53:03 +09:00
Matt Arsenault
779f7243c8
XCore: Declare libcalls used for align 4 memcpy (#144976)
This usage was hidden in XCoreSelectionDAGInfo and bypassed
the usual libcall system, so define these for later use.
2025-06-27 17:50:01 +09:00