Skip to content

Commit bbcac02

Browse files
authored
ARM: Move more aeabi libcall config into tablegen (#152109)
1 parent 71b066e commit bbcac02

File tree

8 files changed

+142
-205
lines changed

8 files changed

+142
-205
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ struct RuntimeLibcallsInfo {
182182
return true;
183183
}
184184

185+
static bool hasAEABILibcalls(const Triple &TT) {
186+
return TT.isTargetAEABI() || TT.isTargetGNUAEABI() ||
187+
TT.isTargetMuslAEABI() || TT.isAndroid();
188+
}
189+
190+
LLVM_READONLY
191+
static bool isAAPCS_ABI(const Triple &TT, StringRef ABIName);
192+
185193
static bool darwinHasExp10(const Triple &TT);
186194

187195
/// Return true if the target has sincosf/sincos/sincosl functions
@@ -195,8 +203,8 @@ struct RuntimeLibcallsInfo {
195203
}
196204

197205
/// Generated by tablegen.
198-
void setTargetRuntimeLibcallSets(const Triple &TT,
199-
FloatABI::ABIType FloatABI);
206+
void setTargetRuntimeLibcallSets(const Triple &TT, FloatABI::ABIType FloatABI,
207+
EABI ABIType, StringRef ABIName);
200208

201209
/// Set default libcall names. If a target wants to opt-out of a libcall it
202210
/// should be placed here.

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,8 +1498,101 @@ def WindowARMFPIntCasts : LibcallImpls<
14981498
def AEABIDivRemCalls : LibcallImpls<
14991499
(add __aeabi_idivmod, __aeabi_ldivmod,
15001500
__aeabi_uidivmod, __aeabi_uldivmod),
1501-
RuntimeLibcallPredicate<[{TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() ||
1502-
TT.isTargetMuslAEABI()}]>> {
1501+
RuntimeLibcallPredicate<[{hasAEABILibcalls(TT)}]>> {
1502+
let CallingConv = ARM_AAPCS;
1503+
}
1504+
1505+
def AEABICalls : LibcallImpls<
1506+
(add
1507+
// Double-precision floating-point arithmetic helper functions
1508+
// RTABI chapter 4.1.2, Table 2
1509+
__aeabi_dadd,
1510+
__aeabi_ddiv,
1511+
__aeabi_dmul,
1512+
__aeabi_dsub,
1513+
1514+
// Double-precision floating-point comparison helper functions
1515+
// RTABI chapter 4.1.2, Table 3
1516+
__aeabi_dcmpeq__oeq,
1517+
__aeabi_dcmpeq__une,
1518+
__aeabi_dcmplt,
1519+
__aeabi_dcmple,
1520+
__aeabi_dcmpge,
1521+
__aeabi_dcmpgt,
1522+
__aeabi_dcmpun,
1523+
1524+
// Single-precision floating-point arithmetic helper functions
1525+
// RTABI chapter 4.1.2, Table 4
1526+
__aeabi_fadd,
1527+
__aeabi_fdiv,
1528+
__aeabi_fmul,
1529+
__aeabi_fsub,
1530+
1531+
// Single-precision floating-point comparison helper functions
1532+
// RTABI chapter 4.1.2, Table 5
1533+
__aeabi_fcmpeq__oeq,
1534+
__aeabi_fcmpeq__une,
1535+
__aeabi_fcmplt,
1536+
__aeabi_fcmple,
1537+
__aeabi_fcmpge,
1538+
__aeabi_fcmpgt,
1539+
__aeabi_fcmpun,
1540+
1541+
// Floating-point to integer conversions.
1542+
// RTABI chapter 4.1.2, Table 6
1543+
__aeabi_d2iz,
1544+
__aeabi_d2uiz,
1545+
__aeabi_d2lz,
1546+
__aeabi_d2ulz,
1547+
__aeabi_f2iz,
1548+
__aeabi_f2uiz,
1549+
__aeabi_f2lz,
1550+
__aeabi_f2ulz,
1551+
1552+
// Conversions between floating types.
1553+
// RTABI chapter 4.1.2, Table 7
1554+
__aeabi_d2f,
1555+
__aeabi_f2d,
1556+
__aeabi_h2f,
1557+
__aeabi_f2h,
1558+
__aeabi_d2h,
1559+
1560+
// Integer to floating-point conversions.
1561+
// RTABI chapter 4.1.2, Table 8
1562+
__aeabi_i2d,
1563+
__aeabi_ui2d,
1564+
__aeabi_l2d,
1565+
__aeabi_ul2d,
1566+
__aeabi_i2f,
1567+
__aeabi_ui2f,
1568+
__aeabi_l2f,
1569+
__aeabi_ul2f,
1570+
1571+
// Long long helper functions
1572+
// RTABI chapter 4.2, Table 9
1573+
__aeabi_lmul,
1574+
__aeabi_llsl,
1575+
__aeabi_llsr,
1576+
__aeabi_lasr,
1577+
1578+
// Integer division functions
1579+
// RTABI chapter 4.3.1
1580+
__aeabi_idiv,
1581+
__aeabi_uidiv),
1582+
RuntimeLibcallPredicate<[{hasAEABILibcalls(TT) && isAAPCS_ABI(TT, ABIName)}]>> {
1583+
let CallingConv = ARM_AAPCS;
1584+
}
1585+
1586+
// EABI dependent RTLIB, Memory operations
1587+
// RTABI chapter 4.3.4
1588+
def AEABI45MemCalls : LibcallImpls<
1589+
(add __aeabi_memcpy, __aeabi_memcpy4, __aeabi_memcpy8,
1590+
__aeabi_memmove, __aeabi_memmove4, __aeabi_memmove8,
1591+
__aeabi_memset, __aeabi_memset4, __aeabi_memset8,
1592+
__aeabi_memclr, __aeabi_memclr4, __aeabi_memclr8),
1593+
RuntimeLibcallPredicate<[{(EABIVersion == EABI::EABI4 ||
1594+
EABIVersion == EABI::EABI5) &&
1595+
hasAEABILibcalls(TT) && isAAPCS_ABI(TT, ABIName)}]>> {
15031596
let CallingConv = ARM_AAPCS;
15041597
}
15051598

@@ -1519,6 +1612,9 @@ def ARMSystemLibrary
15191612
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
15201613
DefaultLibmExp10,
15211614

1615+
AEABICalls,
1616+
AEABI45MemCalls,
1617+
15221618
// Use divmod compiler-rt calls for iOS 5.0 and later.
15231619
LibcallImpls<(add __divmodsi4, __udivmodsi4),
15241620
RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() &&

llvm/include/llvm/TargetParser/ARMTargetParser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ LLVM_ABI ProfileKind parseArchProfile(StringRef Arch);
270270
LLVM_ABI unsigned parseArchVersion(StringRef Arch);
271271

272272
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
273-
LLVM_ABI StringRef computeDefaultTargetABI(const Triple &TT);
274-
275-
LLVM_ABI ARMABI computeTargetABI(const Triple &TT, StringRef ABIName = "");
273+
LLVM_ABI LLVM_READONLY StringRef computeDefaultTargetABI(const Triple &TT);
274+
LLVM_ABI LLVM_READONLY ARMABI computeTargetABI(const Triple &TT,
275+
StringRef ABIName = "");
276276

277277
/// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
278278
///

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 27 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -22,92 +22,39 @@ using namespace RTLIB;
2222
#undef GET_INIT_RUNTIME_LIBCALL_NAMES
2323
#undef GET_SET_TARGET_RUNTIME_LIBCALL_SETS
2424

25-
static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
26-
FloatABI::ABIType FloatABIType, EABI EABIVersion,
27-
StringRef ABIName) {
28-
// The half <-> float conversion functions are always soft-float on
29-
// non-watchos platforms, but are needed for some targets which use a
30-
// hard-float calling convention by default.
31-
if (!TT.isWatchABI()) {
32-
ARM::ARMABI TargetABI = ARM::computeTargetABI(TT, ABIName);
33-
34-
if (TargetABI == ARM::ARM_ABI_AAPCS || TargetABI == ARM::ARM_ABI_AAPCS16) {
35-
Info.setLibcallImplCallingConv(RTLIB::__truncsfhf2,
36-
CallingConv::ARM_AAPCS);
37-
Info.setLibcallImplCallingConv(RTLIB::__truncdfhf2,
38-
CallingConv::ARM_AAPCS);
39-
Info.setLibcallImplCallingConv(RTLIB::__extendhfsf2,
40-
CallingConv::ARM_AAPCS);
41-
Info.setLibcallImplCallingConv(RTLIB::__gnu_h2f_ieee,
42-
CallingConv::ARM_AAPCS);
43-
Info.setLibcallImplCallingConv(RTLIB::__gnu_f2h_ieee,
44-
CallingConv::ARM_AAPCS);
45-
} else {
46-
Info.setLibcallImplCallingConv(RTLIB::__truncsfhf2,
47-
CallingConv::ARM_APCS);
48-
Info.setLibcallImplCallingConv(RTLIB::__truncdfhf2,
49-
CallingConv::ARM_APCS);
50-
Info.setLibcallImplCallingConv(RTLIB::__extendhfsf2,
51-
CallingConv::ARM_APCS);
52-
Info.setLibcallImplCallingConv(RTLIB::__gnu_h2f_ieee,
53-
CallingConv::ARM_APCS);
54-
Info.setLibcallImplCallingConv(RTLIB::__gnu_f2h_ieee,
55-
CallingConv::ARM_APCS);
56-
}
57-
}
58-
59-
static const RTLIB::LibcallImpl AAPCS_Libcalls[] = {
60-
RTLIB::__aeabi_dadd, RTLIB::__aeabi_ddiv,
61-
RTLIB::__aeabi_dmul, RTLIB::__aeabi_dsub,
62-
RTLIB::__aeabi_dcmpeq__oeq, RTLIB::__aeabi_dcmpeq__une,
63-
RTLIB::__aeabi_dcmplt, RTLIB::__aeabi_dcmple,
64-
RTLIB::__aeabi_dcmpge, RTLIB::__aeabi_dcmpgt,
65-
RTLIB::__aeabi_dcmpun, RTLIB::__aeabi_fadd,
66-
RTLIB::__aeabi_fdiv, RTLIB::__aeabi_fmul,
67-
RTLIB::__aeabi_fsub, RTLIB::__aeabi_fcmpeq__oeq,
68-
RTLIB::__aeabi_fcmpeq__une, RTLIB::__aeabi_fcmplt,
69-
RTLIB::__aeabi_fcmple, RTLIB::__aeabi_fcmpge,
70-
RTLIB::__aeabi_fcmpgt, RTLIB::__aeabi_fcmpun,
71-
RTLIB::__aeabi_d2iz, RTLIB::__aeabi_d2uiz,
72-
RTLIB::__aeabi_d2lz, RTLIB::__aeabi_d2ulz,
73-
RTLIB::__aeabi_f2iz, RTLIB::__aeabi_f2uiz,
74-
RTLIB::__aeabi_f2lz, RTLIB::__aeabi_f2ulz,
75-
RTLIB::__aeabi_d2f, RTLIB::__aeabi_d2h,
76-
RTLIB::__aeabi_f2d, RTLIB::__aeabi_i2d,
77-
RTLIB::__aeabi_ui2d, RTLIB::__aeabi_l2d,
78-
RTLIB::__aeabi_ul2d, RTLIB::__aeabi_i2f,
79-
RTLIB::__aeabi_ui2f, RTLIB::__aeabi_l2f,
80-
RTLIB::__aeabi_ul2f, RTLIB::__aeabi_lmul,
81-
RTLIB::__aeabi_llsl, RTLIB::__aeabi_llsr,
82-
RTLIB::__aeabi_lasr, RTLIB::__aeabi_idiv,
83-
RTLIB::__aeabi_idivmod, RTLIB::__aeabi_uidivmod,
84-
RTLIB::__aeabi_ldivmod, RTLIB::__aeabi_uidiv,
85-
RTLIB::__aeabi_uldivmod, RTLIB::__aeabi_f2h,
86-
RTLIB::__aeabi_d2h, RTLIB::__aeabi_h2f,
87-
RTLIB::__aeabi_memcpy, RTLIB::__aeabi_memmove,
88-
RTLIB::__aeabi_memset, RTLIB::__aeabi_memcpy4,
89-
RTLIB::__aeabi_memcpy8, RTLIB::__aeabi_memmove4,
90-
RTLIB::__aeabi_memmove8, RTLIB::__aeabi_memset4,
91-
RTLIB::__aeabi_memset8, RTLIB::__aeabi_memclr,
92-
RTLIB::__aeabi_memclr4, RTLIB::__aeabi_memclr8};
93-
94-
for (RTLIB::LibcallImpl Impl : AAPCS_Libcalls)
95-
Info.setLibcallImplCallingConv(Impl, CallingConv::ARM_AAPCS);
96-
}
97-
9825
/// Set default libcall names. If a target wants to opt-out of a libcall it
9926
/// should be placed here.
10027
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
10128
ExceptionHandling ExceptionModel,
10229
FloatABI::ABIType FloatABI,
10330
EABI EABIVersion, StringRef ABIName) {
104-
setTargetRuntimeLibcallSets(TT, FloatABI);
31+
setTargetRuntimeLibcallSets(TT, FloatABI, EABIVersion, ABIName);
10532

10633
if (ExceptionModel == ExceptionHandling::SjLj)
10734
setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
10835

10936
if (TT.isARM() || TT.isThumb()) {
110-
setARMLibcallNames(*this, TT, FloatABI, EABIVersion, ABIName);
37+
// The half <-> float conversion functions are always soft-float on
38+
// non-watchos platforms, but are needed for some targets which use a
39+
// hard-float calling convention by default.
40+
if (!TT.isWatchABI()) {
41+
if (isAAPCS_ABI(TT, ABIName)) {
42+
setLibcallImplCallingConv(RTLIB::__truncsfhf2, CallingConv::ARM_AAPCS);
43+
setLibcallImplCallingConv(RTLIB::__truncdfhf2, CallingConv::ARM_AAPCS);
44+
setLibcallImplCallingConv(RTLIB::__extendhfsf2, CallingConv::ARM_AAPCS);
45+
setLibcallImplCallingConv(RTLIB::__gnu_h2f_ieee,
46+
CallingConv::ARM_AAPCS);
47+
setLibcallImplCallingConv(RTLIB::__gnu_f2h_ieee,
48+
CallingConv::ARM_AAPCS);
49+
} else {
50+
setLibcallImplCallingConv(RTLIB::__truncsfhf2, CallingConv::ARM_APCS);
51+
setLibcallImplCallingConv(RTLIB::__truncdfhf2, CallingConv::ARM_APCS);
52+
setLibcallImplCallingConv(RTLIB::__extendhfsf2, CallingConv::ARM_APCS);
53+
setLibcallImplCallingConv(RTLIB::__gnu_h2f_ieee, CallingConv::ARM_APCS);
54+
setLibcallImplCallingConv(RTLIB::__gnu_f2h_ieee, CallingConv::ARM_APCS);
55+
}
56+
}
57+
11158
return;
11259
}
11360

@@ -162,6 +109,11 @@ RuntimeLibcallsInfo::getRecognizedLibcallImpls(StringRef FuncName) {
162109
return make_range(EntriesBegin, EntriesEnd);
163110
}
164111

112+
bool RuntimeLibcallsInfo::isAAPCS_ABI(const Triple &TT, StringRef ABIName) {
113+
const ARM::ARMABI TargetABI = ARM::computeTargetABI(TT, ABIName);
114+
return TargetABI == ARM::ARM_ABI_AAPCS || TargetABI == ARM::ARM_ABI_AAPCS16;
115+
}
116+
165117
bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) {
166118
switch (TT.getOS()) {
167119
case Triple::MacOSX:

0 commit comments

Comments
 (0)