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 @@ -137,9 +137,6 @@ struct RuntimeLibcallsInfo {
RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const;

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 @@ -197,8 +194,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 @@ -1606,7 +1606,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 @@ -1819,6 +1821,7 @@ defvar MSP430DefaultOptOut = [
def MSP430SystemLibrary
: SystemRuntimeLibrary<isMSP430,
(add (sub DefaultRuntimeLibcallImpls, MSP430DefaultOptOut),
exp10f, exp10, exp10l_f128,

// Floating point conversions - EABI Table 6
__mspabi_cvtdf,
Expand Down Expand Up @@ -2164,8 +2167,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 @@ -2282,3 +2289,26 @@ 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())
}]>;


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 @@ -8,6 +8,9 @@

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

#define DEBUG_TYPE "runtime-libcalls-info"

using namespace llvm;
using namespace RTLIB;
Expand Down Expand Up @@ -62,12 +65,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 @@ -76,10 +73,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 @@ -92,47 +85,18 @@ 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);
setLibcallImpl(RTLIB::STACK_SMASH_HANDLER, RTLIB::__stack_smash_handler);
}

// 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
Loading
Loading