Skip to content

Commit 027cfc3

Browse files
committed
ARM: Move more aeabi libcall config into tablegen
1 parent 2af18c4 commit 027cfc3

File tree

8 files changed

+119
-169
lines changed

8 files changed

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

@@ -1505,6 +1596,9 @@ def ARMSystemLibrary
15051596
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
15061597
DefaultLibmExp10,
15071598

1599+
AEABICalls,
1600+
AEABI45MemCalls,
1601+
15081602
// Use divmod compiler-rt calls for iOS 5.0 and later.
15091603
LibcallImpls<(add __divmodsi4, __udivmodsi4),
15101604
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: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,44 +55,6 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
5555
CallingConv::ARM_APCS);
5656
}
5757
}
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);
9658
}
9759

9860
/// Set default libcall names. If a target wants to opt-out of a libcall it
@@ -101,7 +63,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
10163
ExceptionHandling ExceptionModel,
10264
FloatABI::ABIType FloatABI,
10365
EABI EABIVersion, StringRef ABIName) {
104-
setTargetRuntimeLibcallSets(TT, FloatABI);
66+
setTargetRuntimeLibcallSets(TT, FloatABI, EABIVersion, ABIName);
10567

10668
if (ExceptionModel == ExceptionHandling::SjLj)
10769
setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
@@ -162,6 +124,11 @@ RuntimeLibcallsInfo::getRecognizedLibcallImpls(StringRef FuncName) {
162124
return make_range(EntriesBegin, EntriesEnd);
163125
}
164126

127+
bool RuntimeLibcallsInfo::isAAPCS_ABI(const Triple &TT, StringRef ABIName) {
128+
const ARM::ARMABI TargetABI = ARM::computeTargetABI(TT, ABIName);
129+
return TargetABI == ARM::ARM_ABI_AAPCS || TargetABI == ARM::ARM_ABI_AAPCS16;
130+
}
131+
165132
bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) {
166133
switch (TT.getOS()) {
167134
case Triple::MacOSX:

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -587,126 +587,6 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
587587
}
588588
}
589589

590-
// RTLIB
591-
if (TM.isAAPCS_ABI() && (TT.isTargetAEABI() || TT.isTargetGNUAEABI() ||
592-
TT.isTargetMuslAEABI() || TT.isAndroid())) {
593-
// FIXME: This does not depend on the subtarget and should go directly into
594-
// RuntimeLibcalls. This is only here because of missing support for setting
595-
// the calling convention of an implementation.
596-
// clang-format off
597-
static const struct {
598-
const RTLIB::Libcall Op;
599-
const RTLIB::LibcallImpl Impl;
600-
} LibraryCalls[] = {
601-
// Double-precision floating-point arithmetic helper functions
602-
// RTABI chapter 4.1.2, Table 2
603-
{ RTLIB::ADD_F64, RTLIB::__aeabi_dadd },
604-
{ RTLIB::DIV_F64, RTLIB::__aeabi_ddiv },
605-
{ RTLIB::MUL_F64, RTLIB::__aeabi_dmul },
606-
{ RTLIB::SUB_F64, RTLIB::__aeabi_dsub },
607-
608-
// Double-precision floating-point comparison helper functions
609-
// RTABI chapter 4.1.2, Table 3
610-
{ RTLIB::OEQ_F64, RTLIB::__aeabi_dcmpeq__oeq },
611-
{ RTLIB::UNE_F64, RTLIB::__aeabi_dcmpeq__une },
612-
{ RTLIB::OLT_F64, RTLIB::__aeabi_dcmplt },
613-
{ RTLIB::OLE_F64, RTLIB::__aeabi_dcmple },
614-
{ RTLIB::OGE_F64, RTLIB::__aeabi_dcmpge },
615-
{ RTLIB::OGT_F64, RTLIB::__aeabi_dcmpgt },
616-
{ RTLIB::UO_F64, RTLIB::__aeabi_dcmpun },
617-
618-
// Single-precision floating-point arithmetic helper functions
619-
// RTABI chapter 4.1.2, Table 4
620-
{ RTLIB::ADD_F32, RTLIB::__aeabi_fadd },
621-
{ RTLIB::DIV_F32, RTLIB::__aeabi_fdiv },
622-
{ RTLIB::MUL_F32, RTLIB::__aeabi_fmul },
623-
{ RTLIB::SUB_F32, RTLIB::__aeabi_fsub },
624-
625-
// Single-precision floating-point comparison helper functions
626-
// RTABI chapter 4.1.2, Table 5
627-
{ RTLIB::OEQ_F32, RTLIB::__aeabi_fcmpeq__oeq },
628-
{ RTLIB::UNE_F32, RTLIB::__aeabi_fcmpeq__une },
629-
{ RTLIB::OLT_F32, RTLIB::__aeabi_fcmplt},
630-
{ RTLIB::OLE_F32, RTLIB::__aeabi_fcmple },
631-
{ RTLIB::OGE_F32, RTLIB::__aeabi_fcmpge },
632-
{ RTLIB::OGT_F32, RTLIB::__aeabi_fcmpgt },
633-
{ RTLIB::UO_F32, RTLIB::__aeabi_fcmpun },
634-
635-
// Floating-point to integer conversions.
636-
// RTABI chapter 4.1.2, Table 6
637-
{ RTLIB::FPTOSINT_F64_I32, RTLIB::__aeabi_d2iz },
638-
{ RTLIB::FPTOUINT_F64_I32, RTLIB::__aeabi_d2uiz },
639-
{ RTLIB::FPTOSINT_F64_I64, RTLIB::__aeabi_d2lz },
640-
{ RTLIB::FPTOUINT_F64_I64, RTLIB::__aeabi_d2ulz },
641-
{ RTLIB::FPTOSINT_F32_I32, RTLIB::__aeabi_f2iz },
642-
{ RTLIB::FPTOUINT_F32_I32, RTLIB::__aeabi_f2uiz },
643-
{ RTLIB::FPTOSINT_F32_I64, RTLIB::__aeabi_f2lz },
644-
{ RTLIB::FPTOUINT_F32_I64, RTLIB::__aeabi_f2ulz },
645-
646-
// Conversions between floating types.
647-
// RTABI chapter 4.1.2, Table 7
648-
{ RTLIB::FPROUND_F64_F32, RTLIB::__aeabi_d2f },
649-
{ RTLIB::FPROUND_F64_F16, RTLIB::__aeabi_d2h },
650-
{ RTLIB::FPEXT_F32_F64, RTLIB::__aeabi_f2d },
651-
652-
// Integer to floating-point conversions.
653-
// RTABI chapter 4.1.2, Table 8
654-
{ RTLIB::SINTTOFP_I32_F64, RTLIB::__aeabi_i2d },
655-
{ RTLIB::UINTTOFP_I32_F64, RTLIB::__aeabi_ui2d },
656-
{ RTLIB::SINTTOFP_I64_F64, RTLIB::__aeabi_l2d },
657-
{ RTLIB::UINTTOFP_I64_F64, RTLIB::__aeabi_ul2d },
658-
{ RTLIB::SINTTOFP_I32_F32, RTLIB::__aeabi_i2f },
659-
{ RTLIB::UINTTOFP_I32_F32, RTLIB::__aeabi_ui2f },
660-
{ RTLIB::SINTTOFP_I64_F32, RTLIB::__aeabi_l2f },
661-
{ RTLIB::UINTTOFP_I64_F32, RTLIB::__aeabi_ul2f },
662-
663-
// Long long helper functions
664-
// RTABI chapter 4.2, Table 9
665-
{ RTLIB::MUL_I64, RTLIB::__aeabi_lmul },
666-
{ RTLIB::SHL_I64, RTLIB::__aeabi_llsl },
667-
{ RTLIB::SRL_I64, RTLIB::__aeabi_llsr },
668-
{ RTLIB::SRA_I64, RTLIB::__aeabi_lasr },
669-
670-
// Integer division functions
671-
// RTABI chapter 4.3.1
672-
{ RTLIB::SDIV_I32, RTLIB::__aeabi_idiv },
673-
{ RTLIB::SDIV_I64, RTLIB::__aeabi_ldivmod },
674-
{ RTLIB::UDIV_I32, RTLIB::__aeabi_uidiv },
675-
{ RTLIB::UDIV_I64, RTLIB::__aeabi_uldivmod },
676-
};
677-
// clang-format on
678-
679-
for (const auto &LC : LibraryCalls)
680-
setLibcallImpl(LC.Op, LC.Impl);
681-
682-
// EABI dependent RTLIB
683-
if (TM.Options.EABIVersion == EABI::EABI4 ||
684-
TM.Options.EABIVersion == EABI::EABI5) {
685-
static const struct {
686-
const RTLIB::Libcall Op;
687-
const RTLIB::LibcallImpl Impl;
688-
} MemOpsLibraryCalls[] = {
689-
// Memory operations
690-
// RTABI chapter 4.3.4
691-
{RTLIB::MEMCPY, RTLIB::__aeabi_memcpy},
692-
{RTLIB::MEMMOVE, RTLIB::__aeabi_memmove},
693-
{RTLIB::MEMSET, RTLIB::__aeabi_memset},
694-
{RTLIB::AEABI_MEMCPY4, RTLIB::__aeabi_memcpy4},
695-
{RTLIB::AEABI_MEMCPY8, RTLIB::__aeabi_memcpy8},
696-
{RTLIB::AEABI_MEMMOVE4, RTLIB::__aeabi_memmove4},
697-
{RTLIB::AEABI_MEMMOVE8, RTLIB::__aeabi_memmove8},
698-
{RTLIB::AEABI_MEMSET4, RTLIB::__aeabi_memset4},
699-
{RTLIB::AEABI_MEMSET8, RTLIB::__aeabi_memset8},
700-
{RTLIB::AEABI_MEMCLR, RTLIB::__aeabi_memclr},
701-
{RTLIB::AEABI_MEMCLR4, RTLIB::__aeabi_memclr4},
702-
{RTLIB::AEABI_MEMCLR8, RTLIB::__aeabi_memclr8},
703-
};
704-
705-
for (const auto &LC : MemOpsLibraryCalls)
706-
setLibcallImpl(LC.Op, LC.Impl);
707-
}
708-
}
709-
710590
// In EABI, these functions have an __aeabi_ prefix, but in GNUEABI they have
711591
// a __gnu_ prefix (which is the default).
712592
if (TT.isTargetAEABI()) {

llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def MSP430LibraryWithCondCC : SystemRuntimeLibrary<isMSP430,
4141
>;
4242

4343

44-
// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, FloatABI::ABIType FloatABI) {
44+
// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName) {
4545
// CHECK: if (TT.getArch() == Triple::avr && TT.isOSHurd()) {
4646
// CHECK-NEXT: const CallingConv::ID DefaultCC = isFoo() ? CallingConv::Fast : CallingConv::GHC;
4747
// CHECK-NEXT: for (CallingConv::ID &Entry : LibcallImplCallingConvs) {

llvm/test/TableGen/RuntimeLibcallEmitter.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
150150
// CHECK-NEXT: };
151151

152152

153-
// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, FloatABI::ABIType FloatABI) {
153+
// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName) {
154154
// CHECK-NEXT: struct LibcallImplPair {
155155
// CHECK-NEXT: RTLIB::Libcall Func;
156156
// CHECK-NEXT: RTLIB::LibcallImpl Impl;

llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ const uint16_t RTLIB::RuntimeLibcallsInfo::RuntimeLibcallNameOffsetTable[] = {
356356
void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
357357
raw_ostream &OS) const {
358358
OS << "void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets("
359-
"const llvm::Triple &TT, FloatABI::ABIType FloatABI) {\n"
359+
"const llvm::Triple &TT, FloatABI::ABIType FloatABI, EABI EABIVersion, "
360+
"StringRef ABIName) {\n"
360361
" struct LibcallImplPair {\n"
361362
" RTLIB::Libcall Func;\n"
362363
" RTLIB::LibcallImpl Impl;\n"

0 commit comments

Comments
 (0)