Skip to content

Commit a8d3505

Browse files
committed
RuntimeLibcalls: Really move default libcall handling to tablegen
Hack in the default setting so it's consistently generated like the other cases. Maintain a list of targets where this applies. The alternative would require new infrastructure to sort the system library initialization in some way. I wanted the unhandled target case to be treated as a fatal error, but it turns out there's a hack in IRSymtab using RuntimeLibcalls, which will fail out in many tests that do not have a triple set. Many of the failures are simply running llvm-as with no triple, which probably should not depend on knowing an accurate set of calls.
1 parent b1c46d2 commit a8d3505

File tree

6 files changed

+398
-917
lines changed

6 files changed

+398
-917
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ struct RuntimeLibcallsInfo {
137137
LLVM_ABI RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const;
138138

139139
private:
140-
static const RTLIB::LibcallImpl
141-
DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1];
142-
143140
/// Stores the implementation choice for each each libcall.
144141
RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
145142
RTLIB::Unsupported};
@@ -197,8 +194,6 @@ struct RuntimeLibcallsInfo {
197194
return hasSinCos(TT) || TT.isPS();
198195
}
199196

200-
LLVM_ABI void initDefaultLibCallImpls();
201-
202197
/// Generated by tablegen.
203198
void setTargetRuntimeLibcallSets(const Triple &TT,
204199
FloatABI::ABIType FloatABI);

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,9 @@ def HexagonSystemLibrary
16101610
(add (sub DefaultLibcallImpls32,
16111611
__adddf3, __divsf3, __udivsi3, __udivdi3,
16121612
__umoddi3, __divdf3, __muldf3, __divsi3, __subdf3, sqrtf,
1613-
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls)>;
1613+
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls,
1614+
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1615+
exp10f, exp10, exp10l_f128)>;
16141616

16151617
//===----------------------------------------------------------------------===//
16161618
// Lanai Runtime Libcalls
@@ -1823,6 +1825,7 @@ defvar MSP430DefaultOptOut = [
18231825
def MSP430SystemLibrary
18241826
: SystemRuntimeLibrary<isMSP430,
18251827
(add (sub DefaultRuntimeLibcallImpls, MSP430DefaultOptOut),
1828+
exp10f, exp10, exp10l_f128,
18261829

18271830
// Floating point conversions - EABI Table 6
18281831
__mspabi_cvtdf,
@@ -2168,8 +2171,12 @@ def __memcpy_4 : RuntimeLibcallImpl<MEMCPY_ALIGN_4>;
21682171

21692172
def isXCore : RuntimeLibcallPredicate<"TT.getArch() == Triple::xcore">;
21702173
def XCoreSystemLibrary
2171-
: SystemRuntimeLibrary<isXCore, (add DefaultRuntimeLibcallImpls,
2172-
__memcpy_4)>;
2174+
: SystemRuntimeLibrary<isXCore,
2175+
(add DefaultRuntimeLibcallImpls,
2176+
exp10f, exp10, exp10l_f128,
2177+
__memcpy_4,
2178+
LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLibcalls), isGNUEnvironment>
2179+
)>;
21732180

21742181
//===----------------------------------------------------------------------===//
21752182
// ZOS Runtime Libcalls
@@ -2286,3 +2293,26 @@ def WasmSystemLibrary
22862293
CompilerRTOnlyInt64Libcalls, CompilerRTOnlyInt128Libcalls,
22872294
exp10f, exp10,
22882295
emscripten_return_address)>;
2296+
2297+
//===----------------------------------------------------------------------===//
2298+
// Legacy Default Runtime Libcalls
2299+
//===----------------------------------------------------------------------===//
2300+
2301+
// TODO: Should make every target explicit.
2302+
def isDefaultLibcallArch : RuntimeLibcallPredicate<[{
2303+
TT.isMIPS() || TT.isLoongArch() || TT.isVE() || TT.isBPF() ||
2304+
TT.getArch() == Triple::csky || TT.getArch() == Triple::arc ||
2305+
TT.getArch() == Triple::m68k || TT.getArch() == Triple::xtensa ||
2306+
(TT.isSystemZ() && !TT.isOSzOS())
2307+
}]>;
2308+
2309+
2310+
def isArch64Bit : RuntimeLibcallPredicate<[{TT.isArch64Bit()}]>;
2311+
def LegacyDefaultSystemLibrary
2312+
: SystemRuntimeLibrary<isDefaultLibcallArch,
2313+
(add DefaultRuntimeLibcallImpls,
2314+
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
2315+
exp10f, exp10, exp10l_f128,
2316+
__powisf2, __powidf2, __powitf2_f128,
2317+
LibcallImpls<(add Int128RTLibcalls), isArch64Bit>
2318+
)>;

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
#include "llvm/IR/RuntimeLibcalls.h"
1010
#include "llvm/ADT/StringTable.h"
11+
#include "llvm/Support/Debug.h"
12+
13+
#define DEBUG_TYPE "runtime-libcalls-info"
1114

1215
using namespace llvm;
1316
using namespace RTLIB;
@@ -62,12 +65,6 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
6265
Info.setLibcallImplCallingConv(Impl, CallingConv::ARM_AAPCS);
6366
}
6467

65-
void RTLIB::RuntimeLibcallsInfo::initDefaultLibCallImpls() {
66-
std::memcpy(LibcallImpls, DefaultLibcallImpls, sizeof(LibcallImpls));
67-
static_assert(sizeof(LibcallImpls) == sizeof(DefaultLibcallImpls),
68-
"libcall array size should match");
69-
}
70-
7168
/// Set default libcall names. If a target wants to opt-out of a libcall it
7269
/// should be placed here.
7370
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
@@ -76,10 +73,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
7673
EABI EABIVersion, StringRef ABIName) {
7774
setTargetRuntimeLibcallSets(TT, FloatABI);
7875

79-
// Early exit for targets that have fully ported to tablegen.
80-
if (TT.isAMDGPU() || TT.isNVPTX() || TT.isWasm())
81-
return;
82-
8376
if (TT.isX86() || TT.isVE() || TT.isARM() || TT.isThumb()) {
8477
if (ExceptionModel == ExceptionHandling::SjLj)
8578
setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
@@ -92,47 +85,18 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
9285
// FIXME: What about other targets?
9386
setLibcallImpl(RTLIB::FPEXT_F16_F32, RTLIB::__extendhfsf2);
9487
setLibcallImpl(RTLIB::FPROUND_F32_F16, RTLIB::__truncsfhf2);
95-
96-
if (!darwinHasExp10(TT)) {
97-
setLibcallImpl(RTLIB::EXP10_F32, RTLIB::Unsupported);
98-
setLibcallImpl(RTLIB::EXP10_F64, RTLIB::Unsupported);
99-
}
10088
}
10189

10290
if (TT.isOSOpenBSD()) {
10391
setLibcallImpl(RTLIB::STACKPROTECTOR_CHECK_FAIL, RTLIB::Unsupported);
10492
setLibcallImpl(RTLIB::STACK_SMASH_HANDLER, RTLIB::__stack_smash_handler);
10593
}
10694

107-
// Skip default manual processing for targets that have been mostly ported to
108-
// tablegen for now. Eventually the rest of this should be deleted.
109-
if (TT.isX86() || TT.isAArch64() || TT.isWasm() || TT.isPPC())
110-
return;
111-
11295
if (TT.isARM() || TT.isThumb()) {
11396
setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
11497
return;
11598
}
11699

117-
if (hasSinCos(TT)) {
118-
setLibcallImpl(RTLIB::SINCOS_F32, RTLIB::sincosf);
119-
setLibcallImpl(RTLIB::SINCOS_F64, RTLIB::sincos);
120-
setLibcallImpl(RTLIB::SINCOS_F128, RTLIB::sincos_f128);
121-
}
122-
123-
setLibcallImpl(RTLIB::EXP10_F32, RTLIB::exp10f);
124-
setLibcallImpl(RTLIB::EXP10_F64, RTLIB::exp10);
125-
setLibcallImpl(RTLIB::EXP10_F128, RTLIB::exp10l_f128);
126-
127-
// These libcalls are only available in compiler-rt, not libgcc.
128-
if (TT.isArch64Bit()) {
129-
setLibcallImpl(RTLIB::SHL_I128, RTLIB::__ashlti3);
130-
setLibcallImpl(RTLIB::SRL_I128, RTLIB::__lshrti3);
131-
setLibcallImpl(RTLIB::SRA_I128, RTLIB::__ashrti3);
132-
setLibcallImpl(RTLIB::MUL_I128, RTLIB::__multi3);
133-
setLibcallImpl(RTLIB::MULO_I64, RTLIB::__mulodi4);
134-
}
135-
136100
if (TT.getArch() == Triple::ArchType::msp430) {
137101
setLibcallImplCallingConv(RTLIB::__mspabi_mpyll,
138102
CallingConv::MSP430_BUILTIN);

0 commit comments

Comments
 (0)