Skip to content

Commit fb4074a

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 18a2de6 commit fb4074a

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
}
@@ -353,10 +367,10 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
353367
setLibcallImpl(RTLIB::SINCOS_STRET_F32, RTLIB::__sincosf_stret);
354368
setLibcallImpl(RTLIB::SINCOS_STRET_F64, RTLIB::__sincos_stret);
355369
if (TT.isWatchABI()) {
356-
setLibcallCallingConv(RTLIB::SINCOS_STRET_F32,
357-
CallingConv::ARM_AAPCS_VFP);
358-
setLibcallCallingConv(RTLIB::SINCOS_STRET_F64,
359-
CallingConv::ARM_AAPCS_VFP);
370+
setLibcallImplCallingConv(RTLIB::__sincosf_stret,
371+
CallingConv::ARM_AAPCS_VFP);
372+
setLibcallImplCallingConv(RTLIB::__sincos_stret,
373+
CallingConv::ARM_AAPCS_VFP);
360374
}
361375
}
362376

@@ -421,18 +435,18 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
421435

422436
for (const auto &LC : LibraryCalls) {
423437
setLibcallImpl(LC.Op, LC.Impl);
424-
setLibcallCallingConv(LC.Op, LC.CC);
438+
setLibcallImplCallingConv(LC.Impl, LC.CC);
425439
}
426440
}
427441

428442
if (TT.isARM() || TT.isThumb())
429443
setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
430444
else if (TT.getArch() == Triple::ArchType::avr) {
431445
// Several of the runtime library functions use a special calling conv
432-
setLibcallCallingConv(RTLIB::SDIVREM_I8, CallingConv::AVR_BUILTIN);
433-
setLibcallCallingConv(RTLIB::SDIVREM_I16, CallingConv::AVR_BUILTIN);
434-
setLibcallCallingConv(RTLIB::UDIVREM_I8, CallingConv::AVR_BUILTIN);
435-
setLibcallCallingConv(RTLIB::UDIVREM_I16, CallingConv::AVR_BUILTIN);
446+
setLibcallImplCallingConv(RTLIB::__divmodqi4, CallingConv::AVR_BUILTIN);
447+
setLibcallImplCallingConv(RTLIB::__divmodhi4, CallingConv::AVR_BUILTIN);
448+
setLibcallImplCallingConv(RTLIB::__udivmodqi4, CallingConv::AVR_BUILTIN);
449+
setLibcallImplCallingConv(RTLIB::__udivmodhi4, CallingConv::AVR_BUILTIN);
436450
}
437451

438452
if (!TT.isWasm()) {

llvm/lib/Target/ARM/ARMISelLowering.cpp

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

685685
for (const auto &LC : LibraryCalls) {
686686
setLibcallImpl(LC.Op, LC.Impl);
687-
setLibcallCallingConv(LC.Op, LC.CC);
687+
setLibcallImplCallingConv(LC.Impl, LC.CC);
688688
if (LC.Cond != CmpInst::BAD_ICMP_PREDICATE)
689689
setCmpLibcallCC(LC.Op, LC.Cond);
690690
}
@@ -723,7 +723,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
723723

724724
for (const auto &LC : MemOpsLibraryCalls) {
725725
setLibcallImpl(LC.Op, LC.Impl);
726-
setLibcallCallingConv(LC.Op, LC.CC);
726+
setLibcallImplCallingConv(LC.Impl, LC.CC);
727727
}
728728
}
729729
}
@@ -733,13 +733,13 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
733733
// hard-float calling convention by default.
734734
if (!TT.isWatchABI()) {
735735
if (TM.isAAPCS_ABI()) {
736-
setLibcallCallingConv(RTLIB::FPROUND_F32_F16, CallingConv::ARM_AAPCS);
737-
setLibcallCallingConv(RTLIB::FPROUND_F64_F16, CallingConv::ARM_AAPCS);
738-
setLibcallCallingConv(RTLIB::FPEXT_F16_F32, CallingConv::ARM_AAPCS);
736+
setLibcallImplCallingConv(RTLIB::__truncsfhf2, CallingConv::ARM_AAPCS);
737+
setLibcallImplCallingConv(RTLIB::__truncdfhf2, CallingConv::ARM_AAPCS);
738+
setLibcallImplCallingConv(RTLIB::__extendhfsf2, CallingConv::ARM_AAPCS);
739739
} else {
740-
setLibcallCallingConv(RTLIB::FPROUND_F32_F16, CallingConv::ARM_APCS);
741-
setLibcallCallingConv(RTLIB::FPROUND_F64_F16, CallingConv::ARM_APCS);
742-
setLibcallCallingConv(RTLIB::FPEXT_F16_F32, CallingConv::ARM_APCS);
740+
setLibcallImplCallingConv(RTLIB::__truncsfhf2, CallingConv::ARM_APCS);
741+
setLibcallImplCallingConv(RTLIB::__truncdfhf2, CallingConv::ARM_APCS);
742+
setLibcallImplCallingConv(RTLIB::__extendhfsf2, CallingConv::ARM_APCS);
743743
}
744744
}
745745

@@ -761,7 +761,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
761761

762762
for (const auto &LC : LibraryCalls) {
763763
setLibcallImpl(LC.Op, LC.Impl);
764-
setLibcallCallingConv(LC.Op, LC.CC);
764+
setLibcallImplCallingConv(LC.Impl, LC.CC);
765765
}
766766
} else if (!TT.isOSBinFormatMachO()) {
767767
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)