Skip to content

Commit 5843fba

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 9c031f5 commit 5843fba

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
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
@@ -1606,7 +1606,9 @@ def HexagonSystemLibrary
16061606
(add (sub DefaultLibcallImpls32,
16071607
__adddf3, __divsf3, __udivsi3, __udivdi3,
16081608
__umoddi3, __divdf3, __muldf3, __divsi3, __subdf3, sqrtf,
1609-
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls)>;
1609+
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls,
1610+
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1611+
exp10f, exp10, exp10l_f128)>;
16101612

16111613
//===----------------------------------------------------------------------===//
16121614
// Lanai Runtime Libcalls
@@ -1819,6 +1821,7 @@ defvar MSP430DefaultOptOut = [
18191821
def MSP430SystemLibrary
18201822
: SystemRuntimeLibrary<isMSP430,
18211823
(add (sub DefaultRuntimeLibcallImpls, MSP430DefaultOptOut),
1824+
exp10f, exp10, exp10l_f128,
18221825

18231826
// Floating point conversions - EABI Table 6
18241827
__mspabi_cvtdf,
@@ -2164,8 +2167,12 @@ def __memcpy_4 : RuntimeLibcallImpl<MEMCPY_ALIGN_4>;
21642167

21652168
def isXCore : RuntimeLibcallPredicate<"TT.getArch() == Triple::xcore">;
21662169
def XCoreSystemLibrary
2167-
: SystemRuntimeLibrary<isXCore, (add DefaultRuntimeLibcallImpls,
2168-
__memcpy_4)>;
2170+
: SystemRuntimeLibrary<isXCore,
2171+
(add DefaultRuntimeLibcallImpls,
2172+
exp10f, exp10, exp10l_f128,
2173+
__memcpy_4,
2174+
LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLibcalls), isGNUEnvironment>
2175+
)>;
21692176

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

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)