Skip to content

Commit 1ef3055

Browse files
committed
ARM: Start moving runtime libcalls into tablegen
We still need to manually set the calling conventions of some libcalls until the lowering is separated out.
1 parent 833137e commit 1ef3055

File tree

4 files changed

+51
-74
lines changed

4 files changed

+51
-74
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct RuntimeLibcallsInfo {
168168
void initDefaultLibCallImpls();
169169

170170
/// Generated by tablegen.
171-
void setTargetRuntimeLibcallSets(const Triple &TT);
171+
void setTargetRuntimeLibcallSets(const Triple &TT, FloatABI::ABIType FloatABI);
172172

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

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ include "llvm/IR/RuntimeLibcallsImpl.td"
1515
class DuplicateLibcallImplWithPrefix<RuntimeLibcallImpl Impl, string prefix>
1616
: RuntimeLibcallImpl<Impl.Provides, prefix#Impl.LibCallFuncName>;
1717

18+
/// Libcall Predicates
19+
def isOSWindows : RuntimeLibcallPredicate<"TT.isOSWindows()">;
20+
1821
//--------------------------------------------------------------------
1922
// Declare all kinds of used libcalls
2023
//--------------------------------------------------------------------
@@ -1243,6 +1246,7 @@ def __aeabi_memclr4 : RuntimeLibcallImpl<AEABI_MEMCLR4>;
12431246
def __aeabi_memclr8 : RuntimeLibcallImpl<AEABI_MEMCLR8>;
12441247

12451248
// isTargetWindows()
1249+
defset list<RuntimeLibcallImpl> WindowsFPIntCastLibcalls = {
12461250
def __stoi64 : RuntimeLibcallImpl<FPTOSINT_F32_I64>; // CallingConv::ARM_AAPCS_VFP
12471251
def __dtoi64 : RuntimeLibcallImpl<FPTOSINT_F64_I64>; // CallingConv::ARM_AAPCS_VFP
12481252
def __stou64 : RuntimeLibcallImpl<FPTOUINT_F32_I64>; // CallingConv::ARM_AAPCS_VFP
@@ -1251,6 +1255,7 @@ def __i64tos : RuntimeLibcallImpl<SINTTOFP_I64_F32>; // CallingConv::ARM_AAPCS_V
12511255
def __i64tod : RuntimeLibcallImpl<SINTTOFP_I64_F64>; // CallingConv::ARM_AAPCS_VFP
12521256
def __u64tos : RuntimeLibcallImpl<UINTTOFP_I64_F32>; // CallingConv::ARM_AAPCS_VFP
12531257
def __u64tod : RuntimeLibcallImpl<UINTTOFP_I64_F64>; // CallingConv::ARM_AAPCS_VFP
1258+
}
12541259

12551260
def __rt_sdiv : RuntimeLibcallImpl<SDIVREM_I32>; // CallingConv::ARM_AAPCS
12561261
def __rt_sdiv64 : RuntimeLibcallImpl<SDIVREM_I64>; // CallingConv::ARM_AAPCS
@@ -1277,6 +1282,49 @@ def __aeabi_h2f : RuntimeLibcallImpl<FPEXT_F16_F32>; // CallingConv::ARM_AAPCS
12771282
def __gnu_f2h_ieee : RuntimeLibcallImpl<FPROUND_F32_F16>;
12781283
def __gnu_h2f_ieee : RuntimeLibcallImpl<FPEXT_F16_F32>;
12791284

1285+
1286+
def WindowARMDivRemCalls : LibcallImpls<
1287+
(add __rt_sdiv, __rt_sdiv64, __rt_udiv, __rt_udiv64),
1288+
isOSWindows> {
1289+
let CallingConv = ARM_AAPCS;
1290+
}
1291+
1292+
def WindowARMFPIntCasts : LibcallImpls<
1293+
(add WindowsFPIntCastLibcalls),
1294+
isOSWindows> {
1295+
let CallingConv = ARM_AAPCS_VFP;
1296+
}
1297+
1298+
1299+
// Register based DivRem for AEABI (RTABI 4.2)
1300+
def AEABIDivRemCalls : LibcallImpls<
1301+
(add __aeabi_idivmod, __aeabi_ldivmod,
1302+
__aeabi_uidivmod, __aeabi_uldivmod),
1303+
RuntimeLibcallPredicate<[{TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() ||
1304+
TT.isTargetMuslAEABI()}]>> {
1305+
let CallingConv = ARM_AAPCS;
1306+
}
1307+
1308+
def isARMOrThumb : RuntimeLibcallPredicate<"TT.isARM() || TT.isThumb()">;
1309+
1310+
def ARMSystemLibrary
1311+
: SystemRuntimeLibrary<isARMOrThumb,
1312+
(add DefaultLibcallImpls32,
1313+
WindowARMDivRemCalls,
1314+
WindowARMFPIntCasts,
1315+
AEABIDivRemCalls,
1316+
// Use divmod compiler-rt calls for iOS 5.0 and later.
1317+
LibcallImpls<(add __divmodsi4, __udivmodsi4),
1318+
RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() &&
1319+
(!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>)> {
1320+
let DefaultLibcallCallingConv = LibcallCallingConv<[{
1321+
(!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) ?
1322+
(FloatABI == FloatABI::Hard ? CallingConv::ARM_AAPCS_VFP
1323+
: CallingConv::ARM_AAPCS) :
1324+
CallingConv::C
1325+
}]>;
1326+
}
1327+
12801328
//===----------------------------------------------------------------------===//
12811329
// AVR Runtime Libcalls
12821330
//===----------------------------------------------------------------------===//

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -25,77 +25,6 @@ static cl::opt<bool>
2525
static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
2626
FloatABI::ABIType FloatABIType,
2727
EABI EABIVersion) {
28-
if (!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) {
29-
CallingConv::ID DefaultCC = FloatABIType == FloatABI::Hard
30-
? CallingConv::ARM_AAPCS_VFP
31-
: CallingConv::ARM_AAPCS;
32-
for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls())
33-
Info.setLibcallImplCallingConv(LC, DefaultCC);
34-
}
35-
36-
// Register based DivRem for AEABI (RTABI 4.2)
37-
if (TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() ||
38-
TT.isTargetMuslAEABI() || TT.isOSWindows()) {
39-
if (TT.isOSWindows()) {
40-
const struct {
41-
const RTLIB::Libcall Op;
42-
const RTLIB::LibcallImpl Impl;
43-
const CallingConv::ID CC;
44-
} LibraryCalls[] = {
45-
{RTLIB::SDIVREM_I32, RTLIB::__rt_sdiv, CallingConv::ARM_AAPCS},
46-
{RTLIB::SDIVREM_I64, RTLIB::__rt_sdiv64, CallingConv::ARM_AAPCS},
47-
{RTLIB::UDIVREM_I32, RTLIB::__rt_udiv, CallingConv::ARM_AAPCS},
48-
{RTLIB::UDIVREM_I64, RTLIB::__rt_udiv64, CallingConv::ARM_AAPCS},
49-
};
50-
51-
for (const auto &LC : LibraryCalls) {
52-
Info.setLibcallImpl(LC.Op, LC.Impl);
53-
Info.setLibcallImplCallingConv(LC.Impl, LC.CC);
54-
}
55-
} else {
56-
const struct {
57-
const RTLIB::Libcall Op;
58-
const RTLIB::LibcallImpl Impl;
59-
} LibraryCalls[] = {
60-
{RTLIB::SDIVREM_I32, RTLIB::__aeabi_idivmod},
61-
{RTLIB::SDIVREM_I64, RTLIB::__aeabi_ldivmod},
62-
{RTLIB::UDIVREM_I32, RTLIB::__aeabi_uidivmod},
63-
{RTLIB::UDIVREM_I64, RTLIB::__aeabi_uldivmod},
64-
};
65-
66-
for (const auto &LC : LibraryCalls)
67-
Info.setLibcallImpl(LC.Op, LC.Impl);
68-
}
69-
}
70-
71-
if (TT.isOSWindows()) {
72-
static const struct {
73-
const RTLIB::Libcall Op;
74-
const RTLIB::LibcallImpl Impl;
75-
const CallingConv::ID CC;
76-
} LibraryCalls[] = {
77-
{RTLIB::FPTOSINT_F32_I64, RTLIB::__stoi64, CallingConv::ARM_AAPCS_VFP},
78-
{RTLIB::FPTOSINT_F64_I64, RTLIB::__dtoi64, CallingConv::ARM_AAPCS_VFP},
79-
{RTLIB::FPTOUINT_F32_I64, RTLIB::__stou64, CallingConv::ARM_AAPCS_VFP},
80-
{RTLIB::FPTOUINT_F64_I64, RTLIB::__dtou64, CallingConv::ARM_AAPCS_VFP},
81-
{RTLIB::SINTTOFP_I64_F32, RTLIB::__i64tos, CallingConv::ARM_AAPCS_VFP},
82-
{RTLIB::SINTTOFP_I64_F64, RTLIB::__i64tod, CallingConv::ARM_AAPCS_VFP},
83-
{RTLIB::UINTTOFP_I64_F32, RTLIB::__u64tos, CallingConv::ARM_AAPCS_VFP},
84-
{RTLIB::UINTTOFP_I64_F64, RTLIB::__u64tod, CallingConv::ARM_AAPCS_VFP},
85-
};
86-
87-
for (const auto &LC : LibraryCalls) {
88-
Info.setLibcallImpl(LC.Op, LC.Impl);
89-
Info.setLibcallImplCallingConv(LC.Impl, LC.CC);
90-
}
91-
}
92-
93-
// Use divmod compiler-rt calls for iOS 5.0 and later.
94-
if (TT.isOSBinFormatMachO() && (!TT.isiOS() || !TT.isOSVersionLT(5, 0))) {
95-
Info.setLibcallImpl(RTLIB::SDIVREM_I32, RTLIB::__divmodsi4);
96-
Info.setLibcallImpl(RTLIB::UDIVREM_I32, RTLIB::__udivmodsi4);
97-
}
98-
9928
static const RTLIB::LibcallImpl AAPCS_Libcalls[] = {
10029
RTLIB::__aeabi_dadd, RTLIB::__aeabi_ddiv,
10130
RTLIB::__aeabi_dmul, RTLIB::__aeabi_dsub,
@@ -212,7 +141,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
212141
ExceptionHandling ExceptionModel,
213142
FloatABI::ABIType FloatABI,
214143
EABI EABIVersion, StringRef ABIName) {
215-
setTargetRuntimeLibcallSets(TT);
144+
setTargetRuntimeLibcallSets(TT, FloatABI);
216145

217146
// Use the f128 variants of math functions on x86
218147
if (TT.isX86() && TT.isGNUEnvironment())

llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void RuntimeLibcallEmitter::emitGetInitRuntimeLibcallNames(
362362
void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
363363
raw_ostream &OS) const {
364364
OS << "void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets("
365-
"const llvm::Triple &TT) {\n"
365+
"const llvm::Triple &TT, FloatABI::ABIType FloatABI) {\n"
366366
" struct LibcallImplPair {\n"
367367
" RTLIB::Libcall Func;\n"
368368
" RTLIB::LibcallImpl Impl;\n"

0 commit comments

Comments
 (0)