Skip to content

RuntimeLibcalls: Invert handling of 64-bit only libcalls #148571

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

Merged
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
52 changes: 24 additions & 28 deletions llvm/include/llvm/IR/RuntimeLibcalls.td
Original file line number Diff line number Diff line change
Expand Up @@ -439,26 +439,21 @@ let IsDefault = true in {
def __ashlhi3 : RuntimeLibcallImpl<SHL_I16>;
def __ashlsi3 : RuntimeLibcallImpl<SHL_I32>;
def __ashldi3 : RuntimeLibcallImpl<SHL_I64>;
def __ashlti3 : RuntimeLibcallImpl<SHL_I128>;

def __lshrhi3 : RuntimeLibcallImpl<SRL_I16>;
def __lshrsi3 : RuntimeLibcallImpl<SRL_I32>;
def __lshrdi3 : RuntimeLibcallImpl<SRL_I64>;
def __lshrti3 : RuntimeLibcallImpl<SRL_I128>;

def __ashrhi3 : RuntimeLibcallImpl<SRA_I16>;
def __ashrsi3 : RuntimeLibcallImpl<SRA_I32>;
def __ashrdi3 : RuntimeLibcallImpl<SRA_I64>;
def __ashrti3 : RuntimeLibcallImpl<SRA_I128>;

def __mulqi3 : RuntimeLibcallImpl<MUL_I8>;
def __mulhi3 : RuntimeLibcallImpl<MUL_I16>;
def __mulsi3 : RuntimeLibcallImpl<MUL_I32>;
def __muldi3 : RuntimeLibcallImpl<MUL_I64>;
def __multi3 : RuntimeLibcallImpl<MUL_I128>;

def __mulosi4 : RuntimeLibcallImpl<MULO_I32>;
def __mulodi4 : RuntimeLibcallImpl<MULO_I64>;

def __divqi3 : RuntimeLibcallImpl<SDIV_I8>;
def __divhi3 : RuntimeLibcallImpl<SDIV_I16>;
Expand Down Expand Up @@ -935,10 +930,29 @@ def calloc : RuntimeLibcallImpl<CALLOC>;
} // End let IsDefault = true

//--------------------------------------------------------------------
// compiler-rt, not available for most architectures
// compiler-rt/libgcc but 64-bit only, not available by default
//--------------------------------------------------------------------

def __muloti4 : RuntimeLibcallImpl<MULO_I128>;
// Exist in libgcc and compiler-rt for 64-bit targets, or if
// COMPILER_RT_ENABLE_SOFTWARE_INT128.
defset list<RuntimeLibcallImpl> Int128RTLibcalls = {
def __ashlti3 : RuntimeLibcallImpl<SHL_I128>;
def __lshrti3 : RuntimeLibcallImpl<SRL_I128>;
def __ashrti3 : RuntimeLibcallImpl<SRA_I128>;
def __multi3 : RuntimeLibcallImpl<MUL_I128>;
}

//--------------------------------------------------------------------
// compiler-rt only, not available by default
//--------------------------------------------------------------------

defset list<RuntimeLibcallImpl> CompilerRTOnlyInt64Libcalls = {
def __mulodi4 : RuntimeLibcallImpl<MULO_I64>;
}

defset list<RuntimeLibcallImpl> CompilerRTOnlyInt128Libcalls = {
def __muloti4 : RuntimeLibcallImpl<MULO_I128>;
}

//--------------------------------------------------------------------
// Define implementation other libcalls
Expand Down Expand Up @@ -1034,21 +1048,6 @@ defset list<RuntimeLibcallImpl> LibmF128FiniteLibcalls = {
defvar AllDefaultRuntimeLibcallImpls
= !filter(entry, !instances<RuntimeLibcallImpl>(), entry.IsDefault);

// Exist in libgcc and compiler-rt for 64-bit targets, or if
// COMPILER_RT_ENABLE_SOFTWARE_INT128.
defvar Int128RTLibcalls = [
__ashlti3, __lshrti3, __ashrti3, __multi3
];

// Only available in compiler-rt
defvar CompilerRTOnlyInt64Libcalls = [
__mulodi4
];

defvar CompilerRTOnlyInt128Libcalls = [
__muloti4
];

defvar DefaultRuntimeLibcallImpls_f80 =
!filter(entry, AllDefaultRuntimeLibcallImpls,
!match(!cast<string>(entry.Provides), "F80"));
Expand All @@ -1064,12 +1063,9 @@ defvar DefaultRuntimeLibcallImpls_f128 =
defvar DefaultRuntimeLibcallImpls =
!listremove(
!listremove(
!listremove(
!listremove(AllDefaultRuntimeLibcallImpls, Int128RTLibcalls),
!listconcat(CompilerRTOnlyInt64Libcalls,
CompilerRTOnlyInt128Libcalls)),
DefaultRuntimeLibcallImpls_f80),
DefaultRuntimeLibcallImpls_ppcf128);
!listremove(AllDefaultRuntimeLibcallImpls, Int128RTLibcalls),
DefaultRuntimeLibcallImpls_f80),
DefaultRuntimeLibcallImpls_ppcf128);

/// Default set of libcall impls for 32-bit architectures.
defvar DefaultLibcallImpls32 = DefaultRuntimeLibcallImpls;
Expand Down
20 changes: 11 additions & 9 deletions llvm/lib/IR/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ 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;

// Use the f128 variants of math functions on x86
if (TT.isX86() && TT.isGNUEnvironment())
setLongDoubleIsF128Libm(*this, /*FiniteOnlyFuncs=*/true);
Expand Down Expand Up @@ -241,15 +245,13 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
if (TT.isARM() || TT.isThumb())
setARMLibcallNames(*this, TT, FloatABI, EABIVersion);

if (!TT.isWasm()) {
// These libcalls are only available in compiler-rt, not libgcc.
if (TT.isArch32Bit()) {
setLibcallImpl(RTLIB::SHL_I128, RTLIB::Unsupported);
setLibcallImpl(RTLIB::SRL_I128, RTLIB::Unsupported);
setLibcallImpl(RTLIB::SRA_I128, RTLIB::Unsupported);
setLibcallImpl(RTLIB::MUL_I128, RTLIB::Unsupported);
setLibcallImpl(RTLIB::MULO_I64, RTLIB::Unsupported);
}
// 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) {
Expand Down
Loading