LLVM 22.0.0git
RuntimeLibcalls.cpp
Go to the documentation of this file.
1//===- RuntimeLibcalls.cpp - Interface for runtime libcalls -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "llvm/Support/Debug.h"
12#include "llvm/Support/xxhash.h"
14
15#define DEBUG_TYPE "runtime-libcalls-info"
16
17using namespace llvm;
18using namespace RTLIB;
19
20#define GET_INIT_RUNTIME_LIBCALL_NAMES
21#define GET_SET_TARGET_RUNTIME_LIBCALL_SETS
22#define DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
23#include "llvm/IR/RuntimeLibcalls.inc"
24#undef GET_INIT_RUNTIME_LIBCALL_NAMES
25#undef GET_SET_TARGET_RUNTIME_LIBCALL_SETS
26#undef DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
27
28/// Set default libcall names. If a target wants to opt-out of a libcall it
29/// should be placed here.
30void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
31 ExceptionHandling ExceptionModel,
32 FloatABI::ABIType FloatABI,
33 EABI EABIVersion, StringRef ABIName) {
34 setTargetRuntimeLibcallSets(TT, ExceptionModel, FloatABI, EABIVersion,
35 ABIName);
36
37 if (TT.isARM() || TT.isThumb()) {
38 // The half <-> float conversion functions are always soft-float on
39 // non-watchos platforms, but are needed for some targets which use a
40 // hard-float calling convention by default.
41 if (!TT.isWatchABI()) {
42 if (isAAPCS_ABI(TT, ABIName)) {
43 setLibcallImplCallingConv(RTLIB::impl___truncsfhf2,
45 setLibcallImplCallingConv(RTLIB::impl___truncdfhf2,
47 setLibcallImplCallingConv(RTLIB::impl___extendhfsf2,
49 } else {
50 setLibcallImplCallingConv(RTLIB::impl___truncsfhf2,
52 setLibcallImplCallingConv(RTLIB::impl___truncdfhf2,
54 setLibcallImplCallingConv(RTLIB::impl___extendhfsf2,
56 }
57 }
58
59 return;
60 }
61}
62
65RuntimeLibcallsInfo::libcallImplNameHit(uint16_t NameOffsetEntry,
66 uint16_t StrOffset) {
67 int NumAliases = 1;
68 for (uint16_t Entry : ArrayRef(RuntimeLibcallNameOffsetTable)
69 .drop_front(NameOffsetEntry + 1)) {
70 if (Entry != StrOffset)
71 break;
72 ++NumAliases;
73 }
74
75 RTLIB::LibcallImpl ImplStart = static_cast<RTLIB::LibcallImpl>(
76 &RuntimeLibcallNameOffsetTable[NameOffsetEntry] -
77 &RuntimeLibcallNameOffsetTable[0]);
78 return enum_seq(ImplStart,
79 static_cast<RTLIB::LibcallImpl>(ImplStart + NumAliases));
80}
81
82bool RuntimeLibcallsInfo::isAAPCS_ABI(const Triple &TT, StringRef ABIName) {
83 const ARM::ARMABI TargetABI = ARM::computeTargetABI(TT, ABIName);
84 return TargetABI == ARM::ARM_ABI_AAPCS || TargetABI == ARM::ARM_ABI_AAPCS16;
85}
86
87bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) {
88 switch (TT.getOS()) {
89 case Triple::MacOSX:
90 return !TT.isMacOSXVersionLT(10, 9);
91 case Triple::IOS:
92 return !TT.isOSVersionLT(7, 0);
94 case Triple::TvOS:
95 case Triple::WatchOS:
96 case Triple::XROS:
98 return true;
99 default:
100 return false;
101 }
102}
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
Definition: Compiler.h:356
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
LLVM_ABI LLVM_READONLY ARMABI computeTargetABI(const Triple &TT, StringRef ABIName="")
@ ARM_APCS
ARM Procedure Calling Standard (obsolete, but still used on some targets).
Definition: CallingConv.h:107
@ ARM_AAPCS
ARM Architecture Procedure Calling Standard calling convention (aka EABI).
Definition: CallingConv.h:111
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto enum_seq(EnumT Begin, EnumT End)
Iterate over an enum type from Begin up to - but not including - End.
Definition: Sequence.h:337
ExceptionHandling
Definition: CodeGen.h:53
EABI
Definition: CodeGen.h:73
void setLibcallImplCallingConv(RTLIB::LibcallImpl Call, CallingConv::ID CC)
Set the CallingConv that should be used for the specified libcall implementation.