Skip to content

Commit 14d4d03

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 b2fc78b commit 14d4d03

File tree

5 files changed

+42
-90
lines changed

5 files changed

+42
-90
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ struct RuntimeLibcallsInfo {
128128
}
129129

130130
private:
131-
static const RTLIB::LibcallImpl
132-
DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1];
133-
134131
/// Stores the implementation choice for each each libcall.
135132
RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
136133
RTLIB::Unsupported};
@@ -178,8 +175,6 @@ struct RuntimeLibcallsInfo {
178175
return hasSinCos(TT) || TT.isPS();
179176
}
180177

181-
LLVM_ABI void initDefaultLibCallImpls();
182-
183178
/// Generated by tablegen.
184179
void setTargetRuntimeLibcallSets(const Triple &TT,
185180
FloatABI::ABIType FloatABI);

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,9 @@ def HexagonSystemLibrary
15811581
(add (sub DefaultLibcallImpls32,
15821582
__adddf3, __divsf3, __udivsi3, __udivdi3,
15831583
__umoddi3, __divdf3, __muldf3, __divsi3, __subdf3, sqrtf,
1584-
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls)>;
1584+
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls,
1585+
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1586+
exp10f, exp10, exp10l_f128)>;
15851587

15861588
//===----------------------------------------------------------------------===//
15871589
// Lanai Runtime Libcalls
@@ -2128,8 +2130,12 @@ def __memcpy_4 : RuntimeLibcallImpl<MEMCPY_ALIGN_4>;
21282130

21292131
def isXCore : RuntimeLibcallPredicate<"TT.getArch() == Triple::xcore">;
21302132
def XCoreSystemLibrary
2131-
: SystemRuntimeLibrary<isXCore, (add DefaultRuntimeLibcallImpls,
2132-
__memcpy_4)>;
2133+
: SystemRuntimeLibrary<isXCore,
2134+
(add DefaultRuntimeLibcallImpls,
2135+
exp10f, exp10, exp10l_f128,
2136+
__memcpy_4,
2137+
LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLibcalls), isGNUEnvironment>
2138+
)>;
21332139

21342140
//===----------------------------------------------------------------------===//
21352141
// ZOS Runtime Libcalls
@@ -2246,3 +2252,27 @@ def WasmSystemLibrary
22462252
CompilerRTOnlyInt64Libcalls, CompilerRTOnlyInt128Libcalls,
22472253
exp10f, exp10,
22482254
emscripten_return_address)>;
2255+
2256+
//===----------------------------------------------------------------------===//
2257+
// Legacy Default Runtime Libcalls
2258+
//===----------------------------------------------------------------------===//
2259+
2260+
// TODO: Should make every target explicit.
2261+
def isDefaultLibcallArch : RuntimeLibcallPredicate<[{
2262+
TT.isMIPS() || TT.isLoongArch() || TT.isVE() || TT.isBPF() ||
2263+
TT.getArch() == Triple::csky || TT.getArch() == Triple::arc ||
2264+
TT.getArch() == Triple::m68k || TT.getArch() == Triple::xtensa ||
2265+
(TT.isSystemZ() && !TT.isOSzOS()) ||
2266+
TT.isSPIRV() || TT.isDXIL()
2267+
}]>;
2268+
2269+
2270+
def isArch64Bit : RuntimeLibcallPredicate<[{TT.isArch64Bit()}]>;
2271+
def LegacyDefaultSystemLibrary
2272+
: SystemRuntimeLibrary<isDefaultLibcallArch,
2273+
(add DefaultRuntimeLibcallImpls,
2274+
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
2275+
exp10f, exp10, exp10l_f128,
2276+
__powisf2, __powidf2, __powitf2_f128,
2277+
LibcallImpls<(add Int128RTLibcalls), isArch64Bit>
2278+
)>;

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/Support/CommandLine.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,46 +85,17 @@ 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
}
10593

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

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

llvm/test/TableGen/RuntimeLibcallEmitter.td

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,6 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
104104
// CHECK-NEXT: #endif
105105

106106
// CHECK: #ifdef GET_INIT_RUNTIME_LIBCALL_NAMES
107-
// CHECK-NEXT: const RTLIB::LibcallImpl llvm::RTLIB::RuntimeLibcallsInfo::DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
108-
// CHECK-NEXT: RTLIB::Unsupported, // RTLIB::BZERO
109-
// CHECK-NEXT: RTLIB::Unsupported, // RTLIB::CALLOC
110-
// CHECK-NEXT: RTLIB::Unsupported, // RTLIB::MEMCPY
111-
// CHECK-NEXT: RTLIB::Unsupported, // RTLIB::MEMSET
112-
// CHECK-NEXT: RTLIB::__ashlsi3, // RTLIB::SHL_I32
113-
// CHECK-NEXT: RTLIB::sqrtl_f80, // RTLIB::SQRT_F80
114-
// CHECK-NEXT: RTLIB::sqrtl_f128, // RTLIB::SQRT_F128
115-
// CHECK-NEXT: RTLIB::__lshrdi3, // RTLIB::SRL_I64
116-
// CHECK-NEXT: RTLIB::Unsupported
117-
// CHECK-NEXT: };
118-
// CHECK-EMPTY:
119107
// CHECK-NEXT: const char *const llvm::RTLIB::RuntimeLibcallsInfo::LibCallImplNames[RTLIB::NumLibcallImpls] = {
120108
// CHECK-NEXT: nullptr, // RTLIB::Unsupported
121109
// CHECK-NEXT: "___memcpy", // RTLIB::___memcpy
@@ -236,7 +224,7 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
236224
// CHECK-EMPTY:
237225
// CHECK-NEXT: return;
238226
// CHECK-NEXT: }
239-
// CHECK-NEXT: initDefaultLibCallImpls();
227+
// CHECK-NEXT: LLVM_DEBUG(dbgs() << "no system runtime library applied to target \'" << TT.str() << "\'\n");
240228
// CHECK-NEXT: }
241229
// CHECK-EMPTY:
242230
// CHECK: #endif

llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -307,29 +307,6 @@ void RuntimeLibcallEmitter::emitGetInitRuntimeLibcallNames(
307307
raw_ostream &OS) const {
308308
// TODO: Emit libcall names as string offset table.
309309

310-
OS << "const RTLIB::LibcallImpl "
311-
"llvm::RTLIB::RuntimeLibcallsInfo::"
312-
"DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {\n";
313-
314-
for (const RuntimeLibcall &LibCall : RuntimeLibcallDefList) {
315-
auto I = LibCallToDefaultImpl.find(&LibCall);
316-
if (I == LibCallToDefaultImpl.end()) {
317-
OS << " RTLIB::Unsupported,";
318-
} else {
319-
const RuntimeLibcallImpl *LibCallImpl = I->second;
320-
OS << " ";
321-
LibCallImpl->emitEnumEntry(OS);
322-
OS << ',';
323-
}
324-
325-
OS << " // ";
326-
LibCall.emitEnumEntry(OS);
327-
OS << '\n';
328-
}
329-
330-
OS << " RTLIB::Unsupported\n"
331-
"};\n\n";
332-
333310
// Emit the implementation names
334311
OS << "const char *const llvm::RTLIB::RuntimeLibcallsInfo::"
335312
"LibCallImplNames[RTLIB::NumLibcallImpls] = {\n"
@@ -528,13 +505,11 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
528505
TopLevelPredicate.emitEndIf(OS);
529506
}
530507

531-
// Fallback to the old default set for manual table entries.
532-
//
533-
// TODO: Remove this when targets have switched to using generated tables by
534-
// default.
535-
OS << " initDefaultLibCallImpls();\n";
536-
537-
OS << "}\n\n";
508+
// FIXME: This should be a fatal error. A few contexts are improperly relying
509+
// on RuntimeLibcalls constructed with fully unknown triples.
510+
OS << " LLVM_DEBUG(dbgs() << \"no system runtime library applied to target "
511+
"\\'\" << TT.str() << \"\\'\\n\");\n"
512+
"}\n\n";
538513
}
539514

540515
void RuntimeLibcallEmitter::run(raw_ostream &OS) {

0 commit comments

Comments
 (0)