summaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/TargetLibraryInfo.cpp
AgeCommit message (Collapse)Author
2024-03-27[NFC][TLI] Move VecFuncs to statics to reduce stack usage (#86829)Alex MacLean
`TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib` has a lot of data in local stack arrays, which MSVC keeps on the stack even in release builds. To reduce stack usage, the data arrays (which are const), are moved outside the function as statics. This drops the method stack usage to be negligible.
2024-03-20Revert "Enable exp10 libcall on linux (#68736)"Nikita Popov
This reverts commit 9848fa4aa2a83b0fc3a93e5f905ef09c8dd85226. Causes buildbot failures.
2024-03-20Enable exp10 libcall on linux (#68736)Krishna Narayanan
2024-03-12[Analysis] Treat ldexpf() as missing on MinGW (#84748)Martin Storsjö
The function does exist, but it is a plain wrapper over regular ldexp(), so there's no benefit in calling it over regular ldexp(). Therefore, treat it as missing. This fixes builds of Wine for aarch64 with Clang in mingw mode, which regressed recently in 8d976c7f20fe8d92fe6f54af411594e15fac25ae. That commit unlocked transforming calls to ldexp into ldexpf, for some codepaths within Wine. Wine can use compilers in mingw mode without the regular mingw runtime libraries, which caused this to fail. (However, if the transformation to use ldexpf() would have made sense, the right fix would have been for Wine to provide a similar ldexpf->ldexp wrapper just like mingw does.)
2024-02-24[InstCombine] Handle more even/odd math functions (#81324)Artem Tyurin
At the moment this PR adds support only for `erf` function. Fixes #77220.
2024-02-15Adding support of AMDLIBM vector library (#78560)Rohit Aggarwal
Hi, AMD has it's own implementation of vector calls. This patch include the changes to enable the use of AMD's math library using -fveclib=AMDLIBM. Please refer https://github.com/amd/aocl-libm-ose --------- Co-authored-by: Rohit Aggarwal <Rohit.Aggarwal@amd.com>
2024-01-23[TLI] Remove leftover assert in TargetLibraryInfoImpl initialize (#79056)tltao
Remove unnecessary assert for a sorted StandardNames after implementation of getLibFunc is changed from binary search to a DenseMap Lookup in commit 7d950f040e3da66ec83f91b58d8c2220483d6335. The original getLibFunc binary search implementation is in commit c740e3f0d1ca9690100160ed2708d97d3c6562f0. Co-authored-by: Tony Tao <tonytao@ca.ibm.com>
2024-01-17 [llvm] Teach MachO about XROS (#78373)Cyndy Ishida
Add support for XROS to encode in Mach-O file formats.
2023-12-21[TLI] Add getLibFunc that accepts an Opcode and scalar Type. (#75919)Paschalis Mpeis
It sets a LibFunc similarly with the other two getLibFunc methods. Currently, it supports only the FRem Instruction. Add tests for FRem.
2023-11-22[IR][TLI] Cache getLibFunc() result on Function (NFC) (#72867)Nikita Popov
Cache the result of the TLI libfunc lookup in the Function object. This only caches the actual lookup of the LibFunc in the TLI map, but not the prototype validation, as that might differ between different TLI instances. This uses the existing mechanism for invalidating the intrinsic ID when the function name changes. The libfunc will be invalidated in that case as well. I don't believe this increases the size of Function on 64bit (which currently has a trailing `bool` member), and I don't think we would particularly care if it did, as Functions are uncommon as Values go.
2023-10-03[TLI] Added a guard for empty vector function name. (#68100)JolantaJensen
A guard for empty vector function name was removed in #66656. This patch adds the guard back.
2023-10-02Fix mechanism propagating mangled names for TLI function mappings (#66656)JolantaJensen
Currently the mappings from TLI are used to generate the list of available "scalar to vector" mappings attached to scalar calls as "vector-function-abi-variant" LLVM IR attribute. Function names from TLI are wrapped in mangled name following the pattern: _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)] The problem is the mangled name uses _LLVM_ as the ISA name which prevents the compiler to compute vectorization factor for scalable vectors as it cannot make any decision based on the _LLVM_ ISA. If we use "s" as the ISA name, the compiler can make decisions based on VFABI specification where SVE spacific rules are described. This patch is only a refactoring stage where there is no change to the compiler's behaviour.
2023-08-15[NFC][TLI] Replace std::lower_bound call in getLibFunc with DenseMap lookupDhruv Chawla
While std::lower_bound takes logarithmic time (relative to the length of the array) to execute, DenseMap gives better performance characteristics as it traverses few (if any) elements when collisions do occur, especially when the number of elements are known in advance. This gives a speedup of 0.24%: https://llvm-compile-time-tracker.com/compare.php?from=ac00cca3d9c6c3e9118ebbe47aa5b3ba1ee7404f&to=7f3d4c8ce8cee3a236a2328e46b2a8374672b46e&stat=instructions:u Differential Revision: https://reviews.llvm.org/D157951
2023-08-14[OSX][TargetLibraryInfo] Mark memrchr as unavailable on OSXPavel Kosov
On Mac OSX (tested version macOS 12.4, sdk 12.1) llvm can replace call to `strrchr()` with call to `memrchr()` when string length is known at compile time. This results in link error, because `memrchr` is not present in `libSystem`. It is needed to disable this optimization in `TargetLibraryInfo` for affected OSX versions. This non-standard function (`memrchr`) is not present on (at least) several versions of MacOS https://www.gnu.org/software/gnulib/manual/html_node/memrchr.html , so, in this patch `memrchr` is marked as unavailable for all versions. If someone knows versions where it should be available - please let me know. Github issue: https://github.com/llvm/llvm-project/issues/62254 Tests for this feature also cannot be easily added: https://reviews.llvm.org/D134134#3801747 ~~~ Huawei RRI, OS Lab Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D155168
2023-07-12[TLI][AArch64] Add mappings to vectorized functions from ArmPLMaciej Gabka
Arm Performance Libraries contain math library which provides vectorized versions of common math functions. This patch allows to use it with clang and llvm via -fveclib=ArmPL or -vector-library=ArmPL, so loops with such calls can be vectorized. The executable needs to be linked with the amath library. Arm Performance Libraries are available at: https://developer.arm.com/Tools%20and%20Software/Arm%20Performance%20Libraries Reviewed by: paulwalker-arm Differential Revision: https://reviews.llvm.org/D154508
2023-04-28[MemProf] Use updated version of hot/cold operator newTeresa Johnson
Switch to the just updated versions of the API in tcmalloc that change the name of the hot cold paramter to a reserved identifier __hot_cold_t. This was based on feedback from Richard Smith, as I also need to add some follow-on handling to clang so they are annotated properly. Differential Revision: https://reviews.llvm.org/D149475
2023-04-19[MemProf] Optionally pass hot/cold hints to operator newTeresa Johnson
Optionally (off by default) replace operator new() calls marked with a hot or cold memprof attribute with an operator new() call that takes a hot_cold_t parameter. Currently this is supported by the open source version of tcmalloc, see: https://github.com/google/tcmalloc/blob/master/tcmalloc/new_extension.h Differential Revision: https://reviews.llvm.org/D148718
2023-03-29[TLI][AArch64] Extend SLEEF vectorized functions mapping with VLA functionsPaul Osmialowski
This commit extends D134719 "[AArch64] Enable libm vectorized functions via SLEEF" with the mappings for the scalable functions. It also introduces all the necessary changes needed to support masked interfaces. Reviewed By: danielkiss, sdesmalen Differential Revision: https://reviews.llvm.org/D146839
2023-03-29Revert "[TLI][AArch64] Extend SLEEF vectorized functions mapping with VLA ↵Paul Osmialowski
functions" Reverting it so I could land it with Arcanist. This reverts commit 59dcf927ee43e995374907b6846b657f68d7ea49.
2023-03-29[TLI][AArch64] Extend SLEEF vectorized functions mapping with VLA functionsPaul Osmialowski
This commit extends D134719 "[AArch64] Enable libm vectorized functions via SLEEF" with the mappings for the scalable functions. It also introduces all the necessary changes needed to support masked interfaces. Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-20[AArch64] Enable libm vectorized functions via SLEEFDaniel Kiss
It enables trigonometry functions vectorization via SLEEF: http://sleef.org/. - A new vectorization library enum is added to TargetLibraryInfo.h: SLEEF. - A new option is added to TargetLibraryInfoImpl - ClVectorLibrary: SLEEF. - A comprehensive test case is included in this changeset. - A new vectorization library argument is added to -fveclib: -fveclib=SLEEF. Trigonometry functions that are vectorized by sleef: acos asin atan atanh cos cosh exp exp2 exp10 lgamma log10 log2 log sin sinh sqrt tan tanh tgamma Co-authored-by: Stefan Teleman Reviewed By: paulwalker-arm Differential Revision: https://reviews.llvm.org/D134719
2023-01-18Add parameter extension attributes in various instrumentation passes.Jonas Paulsson
For the targets that have in their ABI the requirement that arguments and return values are extended to the full register bitwidth, it is important that calls when built also take care of this detail. The OMPIRBuilder, AddressSanitizer, GCOVProfiling, MemorySanitizer and ThreadSanitizer passes are with this patch hopefully now doing this properly. Reviewed By: Eli Friedman, Ulrich Weigand, Johannes Doerfert Differential Revision: https://reviews.llvm.org/D133949
2022-12-20[BuildLibCalls][RISCV] Sign extend return value of bcmp on riscv64.Craig Topper
riscv64 wants callees to sign extend signed and unsigned int returns. The caller can use this to avoid a sign extend if the result is used by a comparison since riscv64 only has 64-bit compares. InstCombine/SimplifyLibCalls aggressively turn memcmps that are only used by an icmp eq 0 into bcmp, but we lose the signext attribute that would have been present on the memcmp. This causes an unneeded sext.w in the generated assembly. This looks even sillier if bcmp is implemented alias to memcmp. In that case, not only did we not get any savings by using bcmp, we added an instruction. This probably applies to other functions, this just happens to be the one I noticed so far. See also the discussion here https://discourse.llvm.org/t/can-we-preserve-signext-return-attribute-when-converting-memcmp-to-bcmp/67126 Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D139901
2022-12-12[RISCV] Set ShouldSignExtI32Param in TargetLibraryInfo for riscv64.Craig Topper
riscv64 sign extends signed and unsigned i32 arguments like Mips. Based on discussion here https://discourse.llvm.org/t/can-we-preserve-signext-return-attribute-when-converting-memcmp-to-bcmp/67126 I'll work on returns next. Differential Revision: https://reviews.llvm.org/D139893
2022-10-03[Analysis][SimplifyLibCalls] Refactor code related to size_t in lib func ↵Bjorn Pettersson
signatures. NFC Added a helper in TargetLibraryInfo to get size of "size_t" in bits, given a Module reference. The new getSizeTSize helper is using the same strategy as for example isValidProtoForLibFunc has been using in the past, assuming that the size can be derived by asking DataLayout about the size/type of a pointer to int. FortifiedLibCallSimplifier::optimizeStrpCpyChk was changed to use the new getSizeTSize helper instead of assuming that sizeof(size_t) is equal to sizeof(int*) by itself (that is the assumption used in TargetLibraryInfoImpl::getSizeTSize so the result will be the same). Having a common helper for this ensure that we use the same strategy when deriving the size of "size_t" in different parts of the code. One bonus with this refactoring (basing it on Module instead of just DataLayout) is that it makes it easier to override this for a specific target triple, in case the assumption of using getPointerSizeInBits wouldn't hold. Differential Revision: https://reviews.llvm.org/D110585
2022-09-20[TargetLibraryInfo] Mark memrchr as unavailable on WindowsMateusz Mikuła
Otherwise LLVM will optimise strrchr into memrchr on Windows resulting in linker error: ``` $ cat memrchr_test.c int main(int argc, char **argv) { return (long)strrchr("KkMm", argv[argc-1][0]); } $ clang memrchr_test.c -O memrchr_test.c:3:12: warning: cast to smaller integer type 'long' from 'char *' [-Wpointer-to-int-cast] return (long)strrchr("KkMm", argv[argc-1][0]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ld.lld: error: undefined symbol: memrchr >>> referenced by D:/msys64/tmp/memrchr_test-e7aabd.o:(main) clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` Example taken from MSYS2 Discord and tested with windows-gnu target. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D134134
2022-08-10[InstCombine] Tighten up known library function signature tests (PR #56463)Martin Sebor
Replace a switch statement used to validate arguments to known library functions with a more consistent table-driven approach and tighten it up.
2022-08-08[llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
With C++17 there is no Clang pedantic warning or MSVC C5051.
2022-06-14[PS5] Make library function availability match PS4Paul Robinson
2022-03-14[TLI] Check that malloc argument has type size_tNikita Popov
DSE assumes that this is the case when forming a calloc from a malloc + memset pair. For tests, either update the malloc signature or change the data layout.
2021-12-07Revert "Revert "Use VersionTuple for parsing versions in Triple, fixing ↵James Farrell
issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible."" This reverts commit 63a6348cad6caccf285c1661bc60d8ba5a40c972. Differential Revision: https://reviews.llvm.org/D115254
2021-12-06Revert "Use VersionTuple for parsing versions in Triple, fixing issues that ↵James Farrell
caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible." This reverts commit 50324670342d9391f62671685f4d6b4880a4ea9a.
2021-12-06Use VersionTuple for parsing versions in Triple, fixing issues that caused ↵James Farrell
the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible. This reverts commit 40d5eeac6cd89a2360c3ba997cbaa816abca828c. Differential Revision: https://reviews.llvm.org/D114885
2021-12-01[TLI] Add memset_pattern4, memset_pattern8 lib functions.Florian Hahn
Similar to memset_pattern16, memset_pattern4, memset_pattern8 are available on Darwin platforms. https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/memset_pattern4.3.html Reviewed By: ab Differential Revision: https://reviews.llvm.org/D114881
2021-11-30Revert "Use VersionTuple for parsing versions in Triple. This makes it ↵Nikita Popov
possible to distinguish between "16" and "16.0" after parsing, which previously was not possible." This reverts commit 1e8286467036d8ef1a972de723f805a4981b2692. llvm/test/Transforms/LoopStrengthReduce/X86/2009-11-10-LSRCrash.ll fails with assertion failure: llc: /home/nikic/llvm-project/llvm/include/llvm/ADT/Optional.h:196: T& llvm::optional_detail::OptionalStorage<T, true>::getValue() & [with T = unsigned int]: Assertion `hasVal' failed. ... #8 0x00005633843af5cb llvm::MCStreamer::emitVersionForTarget(llvm::Triple const&, llvm::VersionTuple const&) #9 0x0000563383b47f14 llvm::AsmPrinter::doInitialization(llvm::Module&)
2021-11-30Use VersionTuple for parsing versions in Triple. This makes it possible to ↵James Farrell
distinguish between "16" and "16.0" after parsing, which previously was not possible. See also https://github.com/android/ndk/issues/1455. Differential Revision: https://reviews.llvm.org/D114163
2021-11-23[PS4][TLI] Remove redundant linePaul Robinson
2021-10-23[llvm] Use StringRef::contains (NFC)Kazu Hirata
2021-10-07[PS4][TargetLibraryInfo] Set TLI info correctly for PS4Paul Robinson
2021-10-04[TargetLibraryInfo] Refactor size_t checks in isValidProtoForLibFunc. NFCBjorn Pettersson
In TargetLibraryInfoImpl::isValidProtoForLibFunc we no longer need the IsSizeTTy lambda function and the SizeTTy object. Instead we just follow the regular structure of checking for integer types given an exepected number of bits.
2021-09-28[TargetLibraryInfo] Pick new/delete calls by targetPaul Robinson
There are two sets of new/delete functions, one with Windows/MSVC mangling and one with Itanium mangling. Mark one set or the other as unavailable depending on the target. Split the test malloc-free-delete.ll into three parts: malloc-free.dll for the C API tests, new-delete-itanium.ll and new-delete-msvc.ll for the target-specific new/delete tests. Differential Revision: https://reviews.llvm.org/D110419
2021-09-28[Analysis] Be defensive when matching size_t in lib call signaturesBjorn Pettersson
When TargetLibraryInfoImpl::isValidProtoForLibFunc is checking function signatures to detect lib calls it may check that a parameter or return value matches with the "size_t" type. For this to work it has to derive the IR type matching with "size_t". Depending on if a DataLayout is provided or not, this has been done in two different way. Either a more strict check being based on IntPtrType (which is given by the DataLayout) or a more relaxed check assuming that any integer type matches with "size_t". Given that the stricter approach exist it seems like we do not want to trigger rewrites etc if we aren't sure that a function calls actually match with the library function. Therefore it was questioned why we actually have the more relaxed approach when not being able to derive an IR type for "size_t". This patch will take a more defensive approach, requiring that a DataLayout is passed to isValidProtoForLibFunc. Differential Revision: https://reviews.llvm.org/D110584
2021-09-28[Analysis] Add FIXME:s related to size_t type checksBjorn Pettersson
Differential Revision: https://reviews.llvm.org/D110583
2021-09-24[TargetLibraryInfo] Correctly handle sqrt*_finitePaul Robinson
Other <math>_finite calls are marked as unavailable except on GNU/Linux; it looks like the sqrt set was just overlooked. Differential Revision: https://reviews.llvm.org/D110418
2021-09-24[TargetLibraryInfo][AMDGPU] Minor cleanup, NFCPaul Robinson
2021-09-22[Analysis] improve function matching for strlen libcallSanjay Patel
The return type of strlen is size_t, not just any integer. This is a partial fix for an example based on: https://llvm.org/PR50836 There's another bug here because we can still crash processing a real strlen or something that looks like it.
2021-08-16[PS4] stp[n]cpy not available on PS4Paul Robinson
2021-08-15[Analysis][SimplifyLibCalls] improve function signature check for memcmpSanjay Patel
This would assert/crash as shown in: https://llvm.org/PR50850 The matching for bcmp/bcopy should probably also be updated, but that's another patch.
2021-08-05Mark getc_unlocked as unavailable by defaultRyan Prichard
Before D45736, getc_unlocked was available by default, but turned off for non-Cygwin/non-MinGW Windows. D45736 then added 9 more unlocked functions, which were unavailable by default, but it also: * left getc_unlocked enabled by default, * removed the disabling line for Windows, and * added code to enable getc_unlocked for GNU, Android, and OSX. For consistency, make getc_unlocked unavailable by default. Maybe this was the intent of D45736 anyway. Reviewed By: MaskRay, efriedma Differential Revision: https://reviews.llvm.org/D107527