Skip to content

RuntimeLibcalls: Really move default libcall handling to tablegen #148780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: users/arsenm/runtime-libcalls/stop-opt-out-exp10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ struct RuntimeLibcallsInfo {
}

private:
static const RTLIB::LibcallImpl
DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1];

/// Stores the implementation choice for each each libcall.
RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
RTLIB::Unsupported};
Expand Down Expand Up @@ -178,8 +175,6 @@ struct RuntimeLibcallsInfo {
return hasSinCos(TT) || TT.isPS();
}

LLVM_ABI void initDefaultLibCallImpls();

/// Generated by tablegen.
void setTargetRuntimeLibcallSets(const Triple &TT,
FloatABI::ABIType FloatABI);
Expand Down
36 changes: 33 additions & 3 deletions llvm/include/llvm/IR/RuntimeLibcalls.td
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,9 @@ def HexagonSystemLibrary
(add (sub DefaultLibcallImpls32,
__adddf3, __divsf3, __udivsi3, __udivdi3,
__umoddi3, __divdf3, __muldf3, __divsi3, __subdf3, sqrtf,
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls)>;
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls,
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
exp10f, exp10, exp10l_f128)>;

//===----------------------------------------------------------------------===//
// Lanai Runtime Libcalls
Expand Down Expand Up @@ -2128,8 +2130,12 @@ def __memcpy_4 : RuntimeLibcallImpl<MEMCPY_ALIGN_4>;

def isXCore : RuntimeLibcallPredicate<"TT.getArch() == Triple::xcore">;
def XCoreSystemLibrary
: SystemRuntimeLibrary<isXCore, (add DefaultRuntimeLibcallImpls,
__memcpy_4)>;
: SystemRuntimeLibrary<isXCore,
(add DefaultRuntimeLibcallImpls,
exp10f, exp10, exp10l_f128,
__memcpy_4,
LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLibcalls), isGNUEnvironment>
)>;

//===----------------------------------------------------------------------===//
// ZOS Runtime Libcalls
Expand Down Expand Up @@ -2246,3 +2252,27 @@ def WasmSystemLibrary
CompilerRTOnlyInt64Libcalls, CompilerRTOnlyInt128Libcalls,
exp10f, exp10,
emscripten_return_address)>;

//===----------------------------------------------------------------------===//
// Legacy Default Runtime Libcalls
//===----------------------------------------------------------------------===//

// TODO: Should make every target explicit.
def isDefaultLibcallArch : RuntimeLibcallPredicate<[{
TT.isMIPS() || TT.isLoongArch() || TT.isVE() || TT.isBPF() ||
TT.getArch() == Triple::csky || TT.getArch() == Triple::arc ||
TT.getArch() == Triple::m68k || TT.getArch() == Triple::xtensa ||
(TT.isSystemZ() && !TT.isOSzOS()) ||
TT.isSPIRV() || TT.isDXIL()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes away when #148628 and #148631 land

}]>;


def isArch64Bit : RuntimeLibcallPredicate<[{TT.isArch64Bit()}]>;
def LegacyDefaultSystemLibrary
: SystemRuntimeLibrary<isDefaultLibcallArch,
(add DefaultRuntimeLibcallImpls,
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
exp10f, exp10, exp10l_f128,
__powisf2, __powidf2, __powitf2_f128,
LibcallImpls<(add Int128RTLibcalls), isArch64Bit>
)>;
42 changes: 3 additions & 39 deletions llvm/lib/IR/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//===----------------------------------------------------------------------===//

#include "llvm/IR/RuntimeLibcalls.h"
#include "llvm/Support/Debug.h"

#define DEBUG_TYPE "runtime-libcalls-info"

using namespace llvm;
using namespace RTLIB;
Expand Down Expand Up @@ -61,12 +64,6 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
Info.setLibcallImplCallingConv(Impl, CallingConv::ARM_AAPCS);
}

void RTLIB::RuntimeLibcallsInfo::initDefaultLibCallImpls() {
std::memcpy(LibcallImpls, DefaultLibcallImpls, sizeof(LibcallImpls));
static_assert(sizeof(LibcallImpls) == sizeof(DefaultLibcallImpls),
"libcall array size should match");
}

/// Set default libcall names. If a target wants to opt-out of a libcall it
/// should be placed here.
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
Expand All @@ -75,10 +72,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
EABI EABIVersion, StringRef ABIName) {
setTargetRuntimeLibcallSets(TT, FloatABI);

// Early exit for targets that have fully ported to tablegen.
if (TT.isAMDGPU() || TT.isNVPTX() || TT.isWasm())
return;

if (TT.isX86() || TT.isVE() || TT.isARM() || TT.isThumb()) {
if (ExceptionModel == ExceptionHandling::SjLj)
setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
Expand All @@ -91,46 +84,17 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
// FIXME: What about other targets?
setLibcallImpl(RTLIB::FPEXT_F16_F32, RTLIB::__extendhfsf2);
setLibcallImpl(RTLIB::FPROUND_F32_F16, RTLIB::__truncsfhf2);

if (!darwinHasExp10(TT)) {
setLibcallImpl(RTLIB::EXP10_F32, RTLIB::Unsupported);
setLibcallImpl(RTLIB::EXP10_F64, RTLIB::Unsupported);
}
}

if (TT.isOSOpenBSD()) {
setLibcallImpl(RTLIB::STACKPROTECTOR_CHECK_FAIL, RTLIB::Unsupported);
}

// Skip default manual processing for targets that have been mostly ported to
// tablegen for now. Eventually the rest of this should be deleted.
if (TT.isX86() || TT.isAArch64() || TT.isWasm() || TT.isPPC())
return;

if (TT.isARM() || TT.isThumb()) {
setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
return;
}

if (hasSinCos(TT)) {
setLibcallImpl(RTLIB::SINCOS_F32, RTLIB::sincosf);
setLibcallImpl(RTLIB::SINCOS_F64, RTLIB::sincos);
setLibcallImpl(RTLIB::SINCOS_F128, RTLIB::sincos_f128);
}

setLibcallImpl(RTLIB::EXP10_F32, RTLIB::exp10f);
setLibcallImpl(RTLIB::EXP10_F64, RTLIB::exp10);
setLibcallImpl(RTLIB::EXP10_F128, RTLIB::exp10l_f128);

// These libcalls are only available in compiler-rt, not libgcc.
if (TT.isArch64Bit()) {
setLibcallImpl(RTLIB::SHL_I128, RTLIB::__ashlti3);
setLibcallImpl(RTLIB::SRL_I128, RTLIB::__lshrti3);
setLibcallImpl(RTLIB::SRA_I128, RTLIB::__ashrti3);
setLibcallImpl(RTLIB::MUL_I128, RTLIB::__multi3);
setLibcallImpl(RTLIB::MULO_I64, RTLIB::__mulodi4);
}

if (TT.getArch() == Triple::ArchType::msp430) {
setLibcallImplCallingConv(RTLIB::__mspabi_mpyll,
CallingConv::MSP430_BUILTIN);
Expand Down
14 changes: 1 addition & 13 deletions llvm/test/TableGen/RuntimeLibcallEmitter.td
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,6 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
// CHECK-NEXT: #endif

// CHECK: #ifdef GET_INIT_RUNTIME_LIBCALL_NAMES
// CHECK-NEXT: const RTLIB::LibcallImpl llvm::RTLIB::RuntimeLibcallsInfo::DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
// CHECK-NEXT: RTLIB::Unsupported, // RTLIB::BZERO
// CHECK-NEXT: RTLIB::Unsupported, // RTLIB::CALLOC
// CHECK-NEXT: RTLIB::Unsupported, // RTLIB::MEMCPY
// CHECK-NEXT: RTLIB::Unsupported, // RTLIB::MEMSET
// CHECK-NEXT: RTLIB::__ashlsi3, // RTLIB::SHL_I32
// CHECK-NEXT: RTLIB::sqrtl_f80, // RTLIB::SQRT_F80
// CHECK-NEXT: RTLIB::sqrtl_f128, // RTLIB::SQRT_F128
// CHECK-NEXT: RTLIB::__lshrdi3, // RTLIB::SRL_I64
// CHECK-NEXT: RTLIB::Unsupported
// CHECK-NEXT: };
// CHECK-EMPTY:
// CHECK-NEXT: const char *const llvm::RTLIB::RuntimeLibcallsInfo::LibCallImplNames[RTLIB::NumLibcallImpls] = {
// CHECK-NEXT: nullptr, // RTLIB::Unsupported
// CHECK-NEXT: "___memcpy", // RTLIB::___memcpy
Expand Down Expand Up @@ -236,7 +224,7 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
// CHECK-EMPTY:
// CHECK-NEXT: return;
// CHECK-NEXT: }
// CHECK-NEXT: initDefaultLibCallImpls();
// CHECK-NEXT: LLVM_DEBUG(dbgs() << "no system runtime library applied to target \'" << TT.str() << "\'\n");
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK: #endif
35 changes: 5 additions & 30 deletions llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,29 +307,6 @@ void RuntimeLibcallEmitter::emitGetInitRuntimeLibcallNames(
raw_ostream &OS) const {
// TODO: Emit libcall names as string offset table.

OS << "const RTLIB::LibcallImpl "
"llvm::RTLIB::RuntimeLibcallsInfo::"
"DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {\n";

for (const RuntimeLibcall &LibCall : RuntimeLibcallDefList) {
auto I = LibCallToDefaultImpl.find(&LibCall);
if (I == LibCallToDefaultImpl.end()) {
OS << " RTLIB::Unsupported,";
} else {
const RuntimeLibcallImpl *LibCallImpl = I->second;
OS << " ";
LibCallImpl->emitEnumEntry(OS);
OS << ',';
}

OS << " // ";
LibCall.emitEnumEntry(OS);
OS << '\n';
}

OS << " RTLIB::Unsupported\n"
"};\n\n";

// Emit the implementation names
OS << "const char *const llvm::RTLIB::RuntimeLibcallsInfo::"
"LibCallImplNames[RTLIB::NumLibcallImpls] = {\n"
Expand Down Expand Up @@ -528,13 +505,11 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
TopLevelPredicate.emitEndIf(OS);
}

// Fallback to the old default set for manual table entries.
//
// TODO: Remove this when targets have switched to using generated tables by
// default.
OS << " initDefaultLibCallImpls();\n";

OS << "}\n\n";
// FIXME: This should be a fatal error. A few contexts are improperly relying
// on RuntimeLibcalls constructed with fully unknown triples.
OS << " LLVM_DEBUG(dbgs() << \"no system runtime library applied to target "
"\\'\" << TT.str() << \"\\'\\n\");\n"
"}\n\n";
}

void RuntimeLibcallEmitter::run(raw_ostream &OS) {
Expand Down