76 Commits

Author SHA1 Message Date
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
Matt Arsenault
f38773e980
Hexagon: Add libcall declarations for special memcpy (#144975)
HexagonSelectionDAGInfo was bypassing the ordinary RuntimeLibcallInfo
handling for this case, so define a libcall for it and use it.
2025-06-27 17:46:42 +09: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
3fdf46ad60
TableGen: Add runtime libcall backend (#144972)
Replace RuntimeLibcalls.def with a tablegenerated version. This
is in preparation for splitting RuntimeLibcalls into two components.
For now match the existing functionality.
2025-06-27 17:37:03 +09:00
Matt Arsenault
62d36857b5
RuntimeLibcalls: Cleanup darwin bzero configuration (#145639)
Write this in a more predicate-apply style instead of the
switch.
2025-06-25 20:13:07 +09:00
Matt Arsenault
9e8152b514
RuntimeLibcalls: Cleanup darwin exp10 case (#145638)
Add a predicate function following the example of __sincos_stret
2025-06-25 20:09:45 +09:00
Matt Arsenault
b991b21874
Triple: Add BridgeOS to isOSDarwin (#145636)
This fixes a TODO and avoids a special case. Also required
hacking up a few cases to avoid asserting in codegen; it's not
confidence inspiring that there is only one codegen test using
a bridgeos triple and its specifically for the exp10 libcall
names.

This also changes the behavior, losing an extra leading _ in the
emitted name matching the other apple outputs. I have no idea if
this is right or not. IMO it's someone from apple's problem to fix
it and add appropriate test coverage, or we can rip all references
to BridgeOS out from upstream.
2025-06-25 20:06:51 +09:00
Matt Arsenault
a65e0edd6a
PowerPC: Stop reporting memcpy as an alias of memmove on AIX (#143836)
Instead of reporting ___memmove as an implementation of memcpy,
make it unavailable and let the lowering logic consider memmove as
a fallback path.

This avoids a special case 1:N mapping for libcall implementations.
2025-06-23 22:15:37 +09:00
Matt Arsenault
58987d2e34
RuntimeLibcalls: Pass in ABI name from MCOptions (#144894)
ARM needs this to compute the available libcalls.
2025-06-23 22:14:44 +09:00
Matt Arsenault
1c35fe4e6b
RuntimeLibcalls: Pass in exception handling type (#144696)
All of the ABI options that influence libcall decisions need
to be passed in.
2025-06-19 19:08:52 +09:00
Matt Arsenault
5bee2c34bd
RuntimeLibcalls: Pass in FloatABI and EABI type (#144691)
We need the full set of ABI options to accurately compute
the full set of libcalls. This partially resolves missing
information required to compute the set of ARM calls.
2025-06-19 19:02:42 +09:00
Matt Arsenault
7b9d10d2e6
PowerPC: Fix using long double libm functions for f128 intrinsics (#144382)
This wasn't setting the correct libcall names, which default to the
l suffixed libm names.
2025-06-18 13:26:15 +09:00
Matt Arsenault
8b1528fad9
RuntimeLibcalls: Use array initializers for default values (#143082) 2025-06-17 10:00:41 +09:00
Matt Arsenault
24631e5440
AArch64: Fix outline atomic libcall names for arm64ec (#144378)
Add a missing # prefix to each libcall name
2025-06-17 09:52:50 +09:00