Skip to content

TableGen: Generate enum for runtime libcall implementations #144973

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/tablegen/add-runtime-libcall-backend
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
9 changes: 2 additions & 7 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -3558,13 +3558,8 @@ class LLVM_ABI TargetLoweringBase {
return nullptr;
}

/// Rename the default libcall routine name for the specified libcall.
void setLibcallName(RTLIB::Libcall Call, const char *Name) {
Libcalls.setLibcallName(Call, Name);
}

void setLibcallName(ArrayRef<RTLIB::Libcall> Calls, const char *Name) {
Libcalls.setLibcallName(Calls, Name);
void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
Libcalls.setLibcallImpl(Call, Impl);
}

/// Get the libcall routine name for the specified libcall.
Expand Down
55 changes: 38 additions & 17 deletions llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "llvm/Support/Compiler.h"
#include "llvm/TargetParser/Triple.h"

/// TableGen will produce 2 enums, RTLIB::Libcall and
/// RTLIB::LibcallImpl. RTLIB::Libcall describes abstract functionality the
/// compiler may choose to access, RTLIB::LibcallImpl describes a particular ABI
/// implementation, which includes a name and type signature.
#define GET_RUNTIME_LIBCALL_ENUM
#include "llvm/IR/RuntimeLibcalls.inc"
#undef GET_RUNTIME_LIBCALL_ENUM
Expand All @@ -48,38 +52,46 @@ struct RuntimeLibcallsInfo {
FloatABI::ABIType FloatABI = FloatABI::Default,
EABI EABIVersion = EABI::Default) {
initSoftFloatCmpLibcallPredicates();
initDefaultLibCallNames();
initDefaultLibCallImpls();
initLibcalls(TT, ExceptionModel, FloatABI, EABIVersion);
}

/// Rename the default libcall routine name for the specified libcall.
void setLibcallName(RTLIB::Libcall Call, const char *Name) {
LibcallRoutineNames[Call] = Name;
}

void setLibcallName(ArrayRef<RTLIB::Libcall> Calls, const char *Name) {
for (auto Call : Calls)
setLibcallName(Call, Name);
void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
LibcallImpls[Call] = Impl;
}

/// Get the libcall routine name for the specified libcall.
// FIXME: This should be removed. Only LibcallImpl should have a name.
const char *getLibcallName(RTLIB::Libcall Call) const {
return LibcallRoutineNames[Call];
return LibCallImplNames[LibcallImpls[Call]];
}

/// Get the libcall routine name for the specified libcall implementation.
const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) const {
return LibCallImplNames[CallImpl];
}

/// Return the lowering's selection of implementation call for \p Call
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
return LibcallImpls[Call];
}

/// Set the CallingConv that should be used for the specified libcall.
// FIXME: This should be a function of RTLIB::LibcallImpl
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
LibcallCallingConvs[Call] = CC;
}

/// Get the CallingConv that should be used for the specified libcall.
// FIXME: This should be a function of RTLIB::LibcallImpl
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
return LibcallCallingConvs[Call];
}

ArrayRef<const char *> getLibcallNames() const {
// Trim UNKNOWN_LIBCALL from the end
return ArrayRef(LibcallRoutineNames).drop_back();
ArrayRef<RTLIB::LibcallImpl> getLibcallImpls() const {
// Trim Unsupported from the start
return ArrayRef(LibcallImpls).drop_front();
}

/// Get the comparison predicate that's to be used to test the result of the
Expand All @@ -91,6 +103,7 @@ struct RuntimeLibcallsInfo {
}

// FIXME: This should be removed. This should be private constant.
// FIXME: This should be a function of RTLIB::LibcallImpl
void setSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call,
CmpInst::Predicate Pred) {
SoftFloatCompareLibcallPredicates[Call] = Pred;
Expand All @@ -107,11 +120,12 @@ struct RuntimeLibcallsInfo {
}

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

/// Stores the name each libcall.
const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr};
/// Stores the implementation choice for each each libcall.
RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
RTLIB::Unsupported};

static_assert(static_cast<int>(CallingConv::C) == 0,
"default calling conv should be encoded as 0");
Expand All @@ -127,6 +141,13 @@ struct RuntimeLibcallsInfo {
// opcode.
CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL];

/// Names of concrete implementations of runtime calls. e.g. __ashlsi3 for
/// SHL_I32
static const char *const LibCallImplNames[RTLIB::NumLibcallImpls];

/// Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind.
static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls];

static bool darwinHasSinCosStret(const Triple &TT) {
assert(TT.isOSDarwin() && "should be called with darwin triple");
// Don't bother with 32 bit x86.
Expand All @@ -148,7 +169,7 @@ struct RuntimeLibcallsInfo {
(TT.isAndroid() && !TT.isAndroidVersionLT(9));
}

void initDefaultLibCallNames();
void initDefaultLibCallImpls();

/// Generated by tablegen.
void setPPCLibCallNameOverrides();
Expand Down
Loading
Loading