Skip to content

Commit a082f66

Browse files
authored
ARM: Start moving runtime libcall configuration out of TargetLowering (#142617)
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 23fd60d commit a082f66

File tree

4 files changed

+86
-71
lines changed

4 files changed

+86
-71
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,56 @@ static void setAArch64LibcallNames(RuntimeLibcallsInfo &Info,
3131
}
3232
}
3333

34+
static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT) {
35+
// Register based DivRem for AEABI (RTABI 4.2)
36+
if (TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() ||
37+
TT.isTargetMuslAEABI() || TT.isOSWindows()) {
38+
if (TT.isOSWindows()) {
39+
const struct {
40+
const RTLIB::Libcall Op;
41+
const char *const Name;
42+
const CallingConv::ID CC;
43+
} LibraryCalls[] = {
44+
{RTLIB::SDIVREM_I8, "__rt_sdiv", CallingConv::ARM_AAPCS},
45+
{RTLIB::SDIVREM_I16, "__rt_sdiv", CallingConv::ARM_AAPCS},
46+
{RTLIB::SDIVREM_I32, "__rt_sdiv", CallingConv::ARM_AAPCS},
47+
{RTLIB::SDIVREM_I64, "__rt_sdiv64", CallingConv::ARM_AAPCS},
48+
49+
{RTLIB::UDIVREM_I8, "__rt_udiv", CallingConv::ARM_AAPCS},
50+
{RTLIB::UDIVREM_I16, "__rt_udiv", CallingConv::ARM_AAPCS},
51+
{RTLIB::UDIVREM_I32, "__rt_udiv", CallingConv::ARM_AAPCS},
52+
{RTLIB::UDIVREM_I64, "__rt_udiv64", CallingConv::ARM_AAPCS},
53+
};
54+
55+
for (const auto &LC : LibraryCalls) {
56+
Info.setLibcallName(LC.Op, LC.Name);
57+
Info.setLibcallCallingConv(LC.Op, LC.CC);
58+
}
59+
} else {
60+
const struct {
61+
const RTLIB::Libcall Op;
62+
const char *const Name;
63+
const CallingConv::ID CC;
64+
} LibraryCalls[] = {
65+
{RTLIB::SDIVREM_I8, "__aeabi_idivmod", CallingConv::ARM_AAPCS},
66+
{RTLIB::SDIVREM_I16, "__aeabi_idivmod", CallingConv::ARM_AAPCS},
67+
{RTLIB::SDIVREM_I32, "__aeabi_idivmod", CallingConv::ARM_AAPCS},
68+
{RTLIB::SDIVREM_I64, "__aeabi_ldivmod", CallingConv::ARM_AAPCS},
69+
70+
{RTLIB::UDIVREM_I8, "__aeabi_uidivmod", CallingConv::ARM_AAPCS},
71+
{RTLIB::UDIVREM_I16, "__aeabi_uidivmod", CallingConv::ARM_AAPCS},
72+
{RTLIB::UDIVREM_I32, "__aeabi_uidivmod", CallingConv::ARM_AAPCS},
73+
{RTLIB::UDIVREM_I64, "__aeabi_uldivmod", CallingConv::ARM_AAPCS},
74+
};
75+
76+
for (const auto &LC : LibraryCalls) {
77+
Info.setLibcallName(LC.Op, LC.Name);
78+
Info.setLibcallCallingConv(LC.Op, LC.CC);
79+
}
80+
}
81+
}
82+
}
83+
3484
/// Set default libcall names. If a target wants to opt-out of a libcall it
3585
/// should be placed here.
3686
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
@@ -298,8 +348,9 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
298348

299349
if (TT.getArch() == Triple::ArchType::aarch64)
300350
setAArch64LibcallNames(*this, TT);
301-
302-
if (TT.getArch() == Triple::ArchType::avr) {
351+
else if (TT.isARM() || TT.isThumb())
352+
setARMLibcallNames(*this, TT);
353+
else if (TT.getArch() == Triple::ArchType::avr) {
303354
// Division rtlib functions (not supported), use divmod functions instead
304355
setLibcallName(RTLIB::SDIV_I8, nullptr);
305356
setLibcallName(RTLIB::SDIV_I16, nullptr);

llvm/lib/Target/ARM/ARMISelLowering.cpp

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

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