Skip to content

Commit 31892e8

Browse files
committed
RuntimeLibcalls: Associate calling convention with libcall impls
Instead of associating the libcall with the RTLIB::Libcall, put it into a table indexed by the RTLIB::LibcallImpl. The LibcallImpls should contain all ABI details for a particular implementation, not the abstract Libcall. In the future the wrappers in terms of the RTLIB::Libcall should be removed.
1 parent 3325765 commit 31892e8

File tree

6 files changed

+92
-51
lines changed

6 files changed

+92
-51
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,6 +3562,11 @@ class LLVM_ABI TargetLoweringBase {
35623562
Libcalls.setLibcallImpl(Call, Impl);
35633563
}
35643564

3565+
/// Get the libcall impl routine name for the specified libcall.
3566+
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
3567+
return Libcalls.getLibcallImpl(Call);
3568+
}
3569+
35653570
/// Get the libcall routine name for the specified libcall.
35663571
const char *getLibcallName(RTLIB::Libcall Call) const {
35673572
return Libcalls.getLibcallName(Call);
@@ -3584,11 +3589,18 @@ class LLVM_ABI TargetLoweringBase {
35843589
}
35853590

35863591
/// Set the CallingConv that should be used for the specified libcall.
3587-
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
3588-
Libcalls.setLibcallCallingConv(Call, CC);
3592+
void setLibcallImplCallingConv(RTLIB::LibcallImpl Call, CallingConv::ID CC) {
3593+
Libcalls.setLibcallImplCallingConv(Call, CC);
3594+
}
3595+
3596+
/// Get the CallingConv that should be used for the specified libcall
3597+
/// implementation.
3598+
CallingConv::ID getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const {
3599+
return Libcalls.getLibcallImplCallingConv(Call);
35893600
}
35903601

35913602
/// Get the CallingConv that should be used for the specified libcall.
3603+
// FIXME: Remove this wrapper and directly use the used LibcallImpl
35923604
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
35933605
return Libcalls.getLibcallCallingConv(Call);
35943606
}

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,21 @@ template <> struct enum_iteration_traits<RTLIB::Libcall> {
3737
static constexpr bool is_iterable = true;
3838
};
3939

40+
template <> struct enum_iteration_traits<RTLIB::LibcallImpl> {
41+
static constexpr bool is_iterable = true;
42+
};
43+
4044
namespace RTLIB {
4145

4246
// Return an iterator over all Libcall values.
4347
static inline auto libcalls() {
4448
return enum_seq(static_cast<RTLIB::Libcall>(0), RTLIB::UNKNOWN_LIBCALL);
4549
}
4650

51+
static inline auto libcall_impls() {
52+
return enum_seq(static_cast<RTLIB::LibcallImpl>(1), RTLIB::NumLibcallImpls);
53+
}
54+
4755
/// A simple container for information about the supported runtime calls.
4856
struct RuntimeLibcallsInfo {
4957
explicit RuntimeLibcallsInfo(
@@ -76,16 +84,21 @@ struct RuntimeLibcallsInfo {
7684
return LibcallImpls[Call];
7785
}
7886

79-
/// Set the CallingConv that should be used for the specified libcall.
80-
// FIXME: This should be a function of RTLIB::LibcallImpl
81-
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
82-
LibcallCallingConvs[Call] = CC;
87+
/// Set the CallingConv that should be used for the specified libcall
88+
/// implementation
89+
void setLibcallImplCallingConv(RTLIB::LibcallImpl Call, CallingConv::ID CC) {
90+
LibcallImplCallingConvs[Call] = CC;
8391
}
8492

85-
/// Get the CallingConv that should be used for the specified libcall.
86-
// FIXME: This should be a function of RTLIB::LibcallImpl
93+
// FIXME: Remove this wrapper in favor of directly using
94+
// getLibcallImplCallingConv
8795
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
88-
return LibcallCallingConvs[Call];
96+
return LibcallImplCallingConvs[LibcallImpls[Call]];
97+
}
98+
99+
/// Get the CallingConv that should be used for the specified libcall.
100+
CallingConv::ID getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const {
101+
return LibcallImplCallingConvs[Call];
89102
}
90103

91104
ArrayRef<RTLIB::LibcallImpl> getLibcallImpls() const {
@@ -130,8 +143,9 @@ struct RuntimeLibcallsInfo {
130143
static_assert(static_cast<int>(CallingConv::C) == 0,
131144
"default calling conv should be encoded as 0");
132145

133-
/// Stores the CallingConv that should be used for each libcall.
134-
CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = {};
146+
/// Stores the CallingConv that should be used for each libcall
147+
/// implementation.;
148+
CallingConv::ID LibcallImplCallingConvs[RTLIB::NumLibcallImpls] = {};
135149

136150
/// The condition type that should be used to test the result of each of the
137151
/// soft floating-point comparison libcall against integer zero.

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
2929
CallingConv::ID DefaultCC = FloatABIType == FloatABI::Hard
3030
? CallingConv::ARM_AAPCS_VFP
3131
: CallingConv::ARM_AAPCS;
32-
for (RTLIB::Libcall LC : RTLIB::libcalls())
33-
Info.setLibcallCallingConv(LC, DefaultCC);
32+
for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls())
33+
Info.setLibcallImplCallingConv(LC, DefaultCC);
3434
}
3535

3636
// Register based DivRem for AEABI (RTABI 4.2)
@@ -50,7 +50,7 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
5050

5151
for (const auto &LC : LibraryCalls) {
5252
Info.setLibcallImpl(LC.Op, LC.Impl);
53-
Info.setLibcallCallingConv(LC.Op, LC.CC);
53+
Info.setLibcallImplCallingConv(LC.Impl, LC.CC);
5454
}
5555
} else {
5656
const struct {
@@ -66,7 +66,7 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
6666

6767
for (const auto &LC : LibraryCalls) {
6868
Info.setLibcallImpl(LC.Op, LC.Impl);
69-
Info.setLibcallCallingConv(LC.Op, LC.CC);
69+
Info.setLibcallImplCallingConv(LC.Impl, LC.CC);
7070
}
7171
}
7272
}
@@ -89,7 +89,7 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
8989

9090
for (const auto &LC : LibraryCalls) {
9191
Info.setLibcallImpl(LC.Op, LC.Impl);
92-
Info.setLibcallCallingConv(LC.Op, LC.CC);
92+
Info.setLibcallImplCallingConv(LC.Impl, LC.CC);
9393
}
9494
}
9595

@@ -199,20 +199,34 @@ static void setMSP430Libcalls(RuntimeLibcallsInfo &Info, const Triple &TT) {
199199
Info.setLibcallImpl(LC.Op, LC.Impl);
200200

201201
// Several of the runtime library functions use a special calling conv
202-
Info.setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::MSP430_BUILTIN);
203-
Info.setLibcallCallingConv(RTLIB::UREM_I64, CallingConv::MSP430_BUILTIN);
204-
Info.setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::MSP430_BUILTIN);
205-
Info.setLibcallCallingConv(RTLIB::SREM_I64, CallingConv::MSP430_BUILTIN);
206-
Info.setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::MSP430_BUILTIN);
207-
Info.setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::MSP430_BUILTIN);
208-
Info.setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::MSP430_BUILTIN);
209-
Info.setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::MSP430_BUILTIN);
210-
Info.setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::MSP430_BUILTIN);
211-
Info.setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::MSP430_BUILTIN);
212-
Info.setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::MSP430_BUILTIN);
213-
Info.setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::MSP430_BUILTIN);
214-
Info.setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::MSP430_BUILTIN);
215-
Info.setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::MSP430_BUILTIN);
202+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_divull,
203+
CallingConv::MSP430_BUILTIN);
204+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_remull,
205+
CallingConv::MSP430_BUILTIN);
206+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_divlli,
207+
CallingConv::MSP430_BUILTIN);
208+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_remlli,
209+
CallingConv::MSP430_BUILTIN);
210+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_addd,
211+
CallingConv::MSP430_BUILTIN);
212+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_subd,
213+
CallingConv::MSP430_BUILTIN);
214+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_mpyd,
215+
CallingConv::MSP430_BUILTIN);
216+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_divd,
217+
CallingConv::MSP430_BUILTIN);
218+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_cmpd__oeq,
219+
CallingConv::MSP430_BUILTIN);
220+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_cmpd__une,
221+
CallingConv::MSP430_BUILTIN);
222+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_cmpd__oge,
223+
CallingConv::MSP430_BUILTIN);
224+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_cmpd__olt,
225+
CallingConv::MSP430_BUILTIN);
226+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_cmpd__ole,
227+
CallingConv::MSP430_BUILTIN);
228+
Info.setLibcallImplCallingConv(RTLIB::__mspabi_cmpd__ogt,
229+
CallingConv::MSP430_BUILTIN);
216230

217231
// TODO: __mspabi_srall, __mspabi_srlll, __mspabi_sllll
218232
}
@@ -361,10 +375,10 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
361375
setLibcallImpl(RTLIB::SINCOS_STRET_F32, RTLIB::__sincosf_stret);
362376
setLibcallImpl(RTLIB::SINCOS_STRET_F64, RTLIB::__sincos_stret);
363377
if (TT.isWatchABI()) {
364-
setLibcallCallingConv(RTLIB::SINCOS_STRET_F32,
365-
CallingConv::ARM_AAPCS_VFP);
366-
setLibcallCallingConv(RTLIB::SINCOS_STRET_F64,
367-
CallingConv::ARM_AAPCS_VFP);
378+
setLibcallImplCallingConv(RTLIB::__sincosf_stret,
379+
CallingConv::ARM_AAPCS_VFP);
380+
setLibcallImplCallingConv(RTLIB::__sincos_stret,
381+
CallingConv::ARM_AAPCS_VFP);
368382
}
369383
}
370384

@@ -453,18 +467,18 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
453467

454468
for (const auto &LC : LibraryCalls) {
455469
setLibcallImpl(LC.Op, LC.Impl);
456-
setLibcallCallingConv(LC.Op, LC.CC);
470+
setLibcallImplCallingConv(LC.Impl, LC.CC);
457471
}
458472
}
459473

460474
if (TT.isARM() || TT.isThumb())
461475
setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
462476
else if (TT.getArch() == Triple::ArchType::avr) {
463477
// Several of the runtime library functions use a special calling conv
464-
setLibcallCallingConv(RTLIB::SDIVREM_I8, CallingConv::AVR_BUILTIN);
465-
setLibcallCallingConv(RTLIB::SDIVREM_I16, CallingConv::AVR_BUILTIN);
466-
setLibcallCallingConv(RTLIB::UDIVREM_I8, CallingConv::AVR_BUILTIN);
467-
setLibcallCallingConv(RTLIB::UDIVREM_I16, CallingConv::AVR_BUILTIN);
478+
setLibcallImplCallingConv(RTLIB::__divmodqi4, CallingConv::AVR_BUILTIN);
479+
setLibcallImplCallingConv(RTLIB::__divmodhi4, CallingConv::AVR_BUILTIN);
480+
setLibcallImplCallingConv(RTLIB::__udivmodqi4, CallingConv::AVR_BUILTIN);
481+
setLibcallImplCallingConv(RTLIB::__udivmodhi4, CallingConv::AVR_BUILTIN);
468482
}
469483

470484
if (!TT.isWasm()) {

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
686686

687687
for (const auto &LC : LibraryCalls) {
688688
setLibcallImpl(LC.Op, LC.Impl);
689-
setLibcallCallingConv(LC.Op, LC.CC);
689+
setLibcallImplCallingConv(LC.Impl, LC.CC);
690690
if (LC.Cond != CmpInst::BAD_ICMP_PREDICATE)
691691
setCmpLibcallCC(LC.Op, LC.Cond);
692692
}
@@ -725,7 +725,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
725725

726726
for (const auto &LC : MemOpsLibraryCalls) {
727727
setLibcallImpl(LC.Op, LC.Impl);
728-
setLibcallCallingConv(LC.Op, LC.CC);
728+
setLibcallImplCallingConv(LC.Impl, LC.CC);
729729
}
730730
}
731731
}
@@ -735,13 +735,13 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
735735
// hard-float calling convention by default.
736736
if (!TT.isWatchABI()) {
737737
if (TM.isAAPCS_ABI()) {
738-
setLibcallCallingConv(RTLIB::FPROUND_F32_F16, CallingConv::ARM_AAPCS);
739-
setLibcallCallingConv(RTLIB::FPROUND_F64_F16, CallingConv::ARM_AAPCS);
740-
setLibcallCallingConv(RTLIB::FPEXT_F16_F32, CallingConv::ARM_AAPCS);
738+
setLibcallImplCallingConv(RTLIB::__truncsfhf2, CallingConv::ARM_AAPCS);
739+
setLibcallImplCallingConv(RTLIB::__truncdfhf2, CallingConv::ARM_AAPCS);
740+
setLibcallImplCallingConv(RTLIB::__extendhfsf2, CallingConv::ARM_AAPCS);
741741
} else {
742-
setLibcallCallingConv(RTLIB::FPROUND_F32_F16, CallingConv::ARM_APCS);
743-
setLibcallCallingConv(RTLIB::FPROUND_F64_F16, CallingConv::ARM_APCS);
744-
setLibcallCallingConv(RTLIB::FPEXT_F16_F32, CallingConv::ARM_APCS);
742+
setLibcallImplCallingConv(RTLIB::__truncsfhf2, CallingConv::ARM_APCS);
743+
setLibcallImplCallingConv(RTLIB::__truncdfhf2, CallingConv::ARM_APCS);
744+
setLibcallImplCallingConv(RTLIB::__extendhfsf2, CallingConv::ARM_APCS);
745745
}
746746
}
747747

@@ -763,7 +763,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
763763

764764
for (const auto &LC : LibraryCalls) {
765765
setLibcallImpl(LC.Op, LC.Impl);
766-
setLibcallCallingConv(LC.Op, LC.CC);
766+
setLibcallImplCallingConv(LC.Impl, LC.CC);
767767
}
768768
} else if (!TT.isOSBinFormatMachO()) {
769769
setLibcallImpl(RTLIB::FPROUND_F32_F16, RTLIB::__gnu_f2h_ieee);

llvm/lib/Target/Lanai/LanaiISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ LanaiTargetLowering::LanaiTargetLowering(const TargetMachine &TM,
151151
setMinimumJumpTableEntries(100);
152152

153153
// Use fast calling convention for library functions.
154-
for (RTLIB::Libcall LC : RTLIB::libcalls())
155-
setLibcallCallingConv(LC, CallingConv::Fast);
154+
for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls())
155+
setLibcallImplCallingConv(LC, CallingConv::Fast);
156156

157157
MaxStoresPerMemset = 16; // For @llvm.memset -> sequence of stores
158158
MaxStoresPerMemsetOptSize = 8;

llvm/lib/Target/MSP430/MSP430ISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ MSP430TargetLowering::MSP430TargetLowering(const TargetMachine &TM,
208208
for (const auto &LC : LibraryCalls) {
209209
setLibcallImpl(LC.Op, LC.Impl);
210210
}
211-
setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::MSP430_BUILTIN);
211+
setLibcallImplCallingConv(RTLIB::__mspabi_mpyll,
212+
CallingConv::MSP430_BUILTIN);
212213
}
213214

214215
setMinFunctionAlignment(Align(2));

0 commit comments

Comments
 (0)