Skip to content

Commit 2087b4d

Browse files
committed
ARM: Start moving runtime libcall configuration out of TargetLowering
These Module level triple checks implemented in the Subtarget are kind of a pain and we should probably get rid of all of them in across all targets, and stick to a consistent set of names.
1 parent 18e9455 commit 2087b4d

File tree

4 files changed

+86
-69
lines changed

4 files changed

+86
-69
lines changed

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,34 @@ class Triple {
917917
isOSBinFormatELF();
918918
}
919919

920+
// ARM EABI is the bare-metal EABI described in ARM ABI documents and
921+
// can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
922+
// FIXME: Add a flag for bare-metal for that target and set Triple::EABI
923+
// even for GNUEABI, so we can make a distinction here and still conform to
924+
// the EABI on GNU (and Android) mode. This requires change in Clang, too.
925+
// FIXME: The Darwin exception is temporary, while we move users to
926+
// "*-*-*-macho" triples as quickly as possible.
927+
bool isTargetAEABI() const {
928+
return (getEnvironment() == Triple::EABI ||
929+
getEnvironment() == Triple::EABIHF) &&
930+
!isOSDarwin() && !isOSWindows();
931+
}
932+
933+
bool isTargetGNUAEABI() const {
934+
return (getEnvironment() == Triple::GNUEABI ||
935+
getEnvironment() == Triple::GNUEABIT64 ||
936+
getEnvironment() == Triple::GNUEABIHF ||
937+
getEnvironment() == Triple::GNUEABIHFT64) &&
938+
!isOSDarwin() && !isOSWindows();
939+
}
940+
941+
bool isTargetMuslAEABI() const {
942+
return (getEnvironment() == Triple::MuslEABI ||
943+
getEnvironment() == Triple::MuslEABIHF ||
944+
getEnvironment() == Triple::OpenHOS) &&
945+
!isOSDarwin() && !isOSWindows();
946+
}
947+
920948
/// Tests whether the target is T32.
921949
bool isArmT32() const {
922950
switch (getSubArch()) {

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,56 @@
1111
using namespace llvm;
1212
using namespace RTLIB;
1313

14+
static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT) {
15+
// Register based DivRem for AEABI (RTABI 4.2)
16+
if (TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() ||
17+
TT.isTargetMuslAEABI() || TT.isOSWindows()) {
18+
if (TT.isOSWindows()) {
19+
const struct {
20+
const RTLIB::Libcall Op;
21+
const char *const Name;
22+
const CallingConv::ID CC;
23+
} LibraryCalls[] = {
24+
{RTLIB::SDIVREM_I8, "__rt_sdiv", CallingConv::ARM_AAPCS},
25+
{RTLIB::SDIVREM_I16, "__rt_sdiv", CallingConv::ARM_AAPCS},
26+
{RTLIB::SDIVREM_I32, "__rt_sdiv", CallingConv::ARM_AAPCS},
27+
{RTLIB::SDIVREM_I64, "__rt_sdiv64", CallingConv::ARM_AAPCS},
28+
29+
{RTLIB::UDIVREM_I8, "__rt_udiv", CallingConv::ARM_AAPCS},
30+
{RTLIB::UDIVREM_I16, "__rt_udiv", CallingConv::ARM_AAPCS},
31+
{RTLIB::UDIVREM_I32, "__rt_udiv", CallingConv::ARM_AAPCS},
32+
{RTLIB::UDIVREM_I64, "__rt_udiv64", CallingConv::ARM_AAPCS},
33+
};
34+
35+
for (const auto &LC : LibraryCalls) {
36+
Info.setLibcallName(LC.Op, LC.Name);
37+
Info.setLibcallCallingConv(LC.Op, LC.CC);
38+
}
39+
} else {
40+
const struct {
41+
const RTLIB::Libcall Op;
42+
const char *const Name;
43+
const CallingConv::ID CC;
44+
} LibraryCalls[] = {
45+
{RTLIB::SDIVREM_I8, "__aeabi_idivmod", CallingConv::ARM_AAPCS},
46+
{RTLIB::SDIVREM_I16, "__aeabi_idivmod", CallingConv::ARM_AAPCS},
47+
{RTLIB::SDIVREM_I32, "__aeabi_idivmod", CallingConv::ARM_AAPCS},
48+
{RTLIB::SDIVREM_I64, "__aeabi_ldivmod", CallingConv::ARM_AAPCS},
49+
50+
{RTLIB::UDIVREM_I8, "__aeabi_uidivmod", CallingConv::ARM_AAPCS},
51+
{RTLIB::UDIVREM_I16, "__aeabi_uidivmod", CallingConv::ARM_AAPCS},
52+
{RTLIB::UDIVREM_I32, "__aeabi_uidivmod", CallingConv::ARM_AAPCS},
53+
{RTLIB::UDIVREM_I64, "__aeabi_uldivmod", CallingConv::ARM_AAPCS},
54+
};
55+
56+
for (const auto &LC : LibraryCalls) {
57+
Info.setLibcallName(LC.Op, LC.Name);
58+
Info.setLibcallCallingConv(LC.Op, LC.CC);
59+
}
60+
}
61+
}
62+
}
63+
1464
/// Set default libcall names. If a target wants to opt-out of a libcall it
1565
/// should be placed here.
1666
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
@@ -249,6 +299,9 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
249299
}
250300
}
251301

302+
if (TT.getArch() == Triple::ArchType::arm)
303+
setARMLibcallNames(*this, TT);
304+
252305
if (TT.getArch() == Triple::ArchType::avr) {
253306
// Division rtlib functions (not supported), use divmod functions instead
254307
setLibcallName(RTLIB::SDIV_I8, nullptr);

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,50 +1274,6 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
12741274
setOperationAction(ISD::UREM, MVT::i64, Custom);
12751275
HasStandaloneRem = false;
12761276

1277-
if (Subtarget->isTargetWindows()) {
1278-
const struct {
1279-
const RTLIB::Libcall Op;
1280-
const char * const Name;
1281-
const CallingConv::ID CC;
1282-
} LibraryCalls[] = {
1283-
{ RTLIB::SDIVREM_I8, "__rt_sdiv", CallingConv::ARM_AAPCS },
1284-
{ RTLIB::SDIVREM_I16, "__rt_sdiv", CallingConv::ARM_AAPCS },
1285-
{ RTLIB::SDIVREM_I32, "__rt_sdiv", CallingConv::ARM_AAPCS },
1286-
{ RTLIB::SDIVREM_I64, "__rt_sdiv64", CallingConv::ARM_AAPCS },
1287-
1288-
{ RTLIB::UDIVREM_I8, "__rt_udiv", CallingConv::ARM_AAPCS },
1289-
{ RTLIB::UDIVREM_I16, "__rt_udiv", CallingConv::ARM_AAPCS },
1290-
{ RTLIB::UDIVREM_I32, "__rt_udiv", CallingConv::ARM_AAPCS },
1291-
{ RTLIB::UDIVREM_I64, "__rt_udiv64", CallingConv::ARM_AAPCS },
1292-
};
1293-
1294-
for (const auto &LC : LibraryCalls) {
1295-
setLibcallName(LC.Op, LC.Name);
1296-
setLibcallCallingConv(LC.Op, LC.CC);
1297-
}
1298-
} else {
1299-
const struct {
1300-
const RTLIB::Libcall Op;
1301-
const char * const Name;
1302-
const CallingConv::ID CC;
1303-
} LibraryCalls[] = {
1304-
{ RTLIB::SDIVREM_I8, "__aeabi_idivmod", CallingConv::ARM_AAPCS },
1305-
{ RTLIB::SDIVREM_I16, "__aeabi_idivmod", CallingConv::ARM_AAPCS },
1306-
{ RTLIB::SDIVREM_I32, "__aeabi_idivmod", CallingConv::ARM_AAPCS },
1307-
{ RTLIB::SDIVREM_I64, "__aeabi_ldivmod", CallingConv::ARM_AAPCS },
1308-
1309-
{ RTLIB::UDIVREM_I8, "__aeabi_uidivmod", CallingConv::ARM_AAPCS },
1310-
{ RTLIB::UDIVREM_I16, "__aeabi_uidivmod", CallingConv::ARM_AAPCS },
1311-
{ RTLIB::UDIVREM_I32, "__aeabi_uidivmod", CallingConv::ARM_AAPCS },
1312-
{ RTLIB::UDIVREM_I64, "__aeabi_uldivmod", CallingConv::ARM_AAPCS },
1313-
};
1314-
1315-
for (const auto &LC : LibraryCalls) {
1316-
setLibcallName(LC.Op, LC.Name);
1317-
setLibcallCallingConv(LC.Op, LC.CC);
1318-
}
1319-
}
1320-
13211277
setOperationAction(ISD::SDIVREM, MVT::i32, Custom);
13221278
setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
13231279
setOperationAction(ISD::SDIVREM, MVT::i64, Custom);

llvm/lib/Target/ARM/ARMSubtarget.h

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -348,31 +348,11 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
348348
bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
349349
bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
350350

351-
// ARM EABI is the bare-metal EABI described in ARM ABI documents and
352-
// can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
353-
// FIXME: Add a flag for bare-metal for that target and set Triple::EABI
354-
// even for GNUEABI, so we can make a distinction here and still conform to
355-
// the EABI on GNU (and Android) mode. This requires change in Clang, too.
356-
// FIXME: The Darwin exception is temporary, while we move users to
357-
// "*-*-*-macho" triples as quickly as possible.
358-
bool isTargetAEABI() const {
359-
return (TargetTriple.getEnvironment() == Triple::EABI ||
360-
TargetTriple.getEnvironment() == Triple::EABIHF) &&
361-
!isTargetDarwin() && !isTargetWindows();
362-
}
363-
bool isTargetGNUAEABI() const {
364-
return (TargetTriple.getEnvironment() == Triple::GNUEABI ||
365-
TargetTriple.getEnvironment() == Triple::GNUEABIT64 ||
366-
TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
367-
TargetTriple.getEnvironment() == Triple::GNUEABIHFT64) &&
368-
!isTargetDarwin() && !isTargetWindows();
369-
}
370-
bool isTargetMuslAEABI() const {
371-
return (TargetTriple.getEnvironment() == Triple::MuslEABI ||
372-
TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
373-
TargetTriple.getEnvironment() == Triple::OpenHOS) &&
374-
!isTargetDarwin() && !isTargetWindows();
375-
}
351+
bool isTargetAEABI() const { return TargetTriple.isTargetAEABI(); }
352+
353+
bool isTargetGNUAEABI() const { return TargetTriple.isTargetGNUAEABI(); }
354+
355+
bool isTargetMuslAEABI() const { return TargetTriple.isTargetMuslAEABI(); }
376356

377357
// ARM Targets that support EHABI exception handling standard
378358
// Darwin uses SjLj. Other targets might need more checks.

0 commit comments

Comments
 (0)