Skip to content
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
15 changes: 5 additions & 10 deletions llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,7 @@ struct RuntimeLibcallsInfo {
const Triple &TT,
ExceptionHandling ExceptionModel = ExceptionHandling::None,
FloatABI::ABIType FloatABI = FloatABI::Default,
EABI EABIVersion = EABI::Default, StringRef ABIName = "") {
// FIXME: The ExceptionModel parameter is to handle the field in
// TargetOptions. This interface fails to distinguish the forced disable
// case for targets which support exceptions by default. This should
// probably be a module flag and removed from TargetOptions.
if (ExceptionModel == ExceptionHandling::None)
ExceptionModel = TT.getDefaultExceptionHandling();

initLibcalls(TT, ExceptionModel, FloatABI, EABIVersion, ABIName);
}
EABI EABIVersion = EABI::Default, StringRef ABIName = "");

explicit RuntimeLibcallsInfo(const Module &M);

Expand Down Expand Up @@ -170,6 +161,10 @@ struct RuntimeLibcallsInfo {
getFunctionTy(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL,
RTLIB::LibcallImpl LibcallImpl) const;

/// Returns true if the function has a vector mask argument, which is assumed
/// to be the last argument.
static bool hasVectorMaskArgument(RTLIB::LibcallImpl Impl);

private:
LLVM_ABI static iota_range<RTLIB::LibcallImpl>
lookupLibcallImplNameImpl(StringRef Name);
Expand Down
26 changes: 26 additions & 0 deletions llvm/include/llvm/IR/RuntimeLibcalls.td
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ foreach FPTy = ["F32", "F64", "F80", "F128", "PPCF128"] in {
def MODF_#FPTy : RuntimeLibcall;
}

foreach VecTy = ["V4F32", "V2F64", "NXV4F32", "NXV2F64"] in {
def SINCOSPI_#VecTy : RuntimeLibcall;
}

def FEGETENV : RuntimeLibcall;
def FESETENV : RuntimeLibcall;

Expand Down Expand Up @@ -1078,6 +1082,28 @@ def __security_check_cookie : RuntimeLibcallImpl<SECURITY_CHECK_COOKIE>;
def __security_check_cookie_arm64ec : RuntimeLibcallImpl<SECURITY_CHECK_COOKIE,
"#__security_check_cookie_arm64ec">;

//===----------------------------------------------------------------------===//
// sleef calls
//===----------------------------------------------------------------------===//

defset list<RuntimeLibcallImpl> SleefLibcalls = {
def _ZGVnN4vl4l4_sincospif : RuntimeLibcallImpl<SINCOSPI_V4F32>;
def _ZGVnN2vl8l8_sincospi : RuntimeLibcallImpl<SINCOSPI_V2F64>;
def _ZGVsNxvl4l4_sincospif : RuntimeLibcallImpl<SINCOSPI_NXV4F32>;
def _ZGVsNxvl8l8_sincospi : RuntimeLibcallImpl<SINCOSPI_NXV2F64>;
}

//===----------------------------------------------------------------------===//
// ARMPL calls
//===----------------------------------------------------------------------===//

defset list<RuntimeLibcallImpl> ARMPLLibcalls = {
def armpl_vsincospiq_f32 : RuntimeLibcallImpl<SINCOSPI_V4F32>;
def armpl_vsincospiq_f64 : RuntimeLibcallImpl<SINCOSPI_V2F64>;
def armpl_svsincospi_f32_x : RuntimeLibcallImpl<SINCOSPI_NXV4F32>;
def armpl_svsincospi_f64_x : RuntimeLibcallImpl<SINCOSPI_NXV2F64>;
}

//===----------------------------------------------------------------------===//
// F128 libm Runtime Libcalls
//===----------------------------------------------------------------------===//
Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,24 @@ RTLIB::Libcall RTLIB::getSINCOS(EVT RetVT) {
}

RTLIB::Libcall RTLIB::getSINCOSPI(EVT RetVT) {
// TODO: Tablegen should generate this function
if (RetVT.isVector()) {
if (!RetVT.isSimple())
return RTLIB::UNKNOWN_LIBCALL;
switch (RetVT.getSimpleVT().SimpleTy) {
case MVT::v4f32:
return RTLIB::SINCOSPI_V4F32;
case MVT::v2f64:
return RTLIB::SINCOSPI_V2F64;
case MVT::nxv4f32:
return RTLIB::SINCOSPI_NXV4F32;
case MVT::nxv2f64:
return RTLIB::SINCOSPI_NXV2F64;
default:
return RTLIB::UNKNOWN_LIBCALL;
}
}

return getFPLibCall(RetVT, SINCOSPI_F32, SINCOSPI_F64, SINCOSPI_F80,
SINCOSPI_F128, SINCOSPI_PPCF128);
}
Expand Down
95 changes: 95 additions & 0 deletions llvm/lib/IR/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "llvm/ADT/FloatingPointMode.h"
#include "llvm/ADT/StringTable.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/SystemLibraries.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/xxhash.h"
#include "llvm/TargetParser/ARMTargetParser.h"
Expand All @@ -25,6 +26,40 @@ using namespace RTLIB;
#define DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
#include "llvm/IR/RuntimeLibcalls.inc"

RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
ExceptionHandling ExceptionModel,
FloatABI::ABIType FloatABI,
EABI EABIVersion, StringRef ABIName) {
// FIXME: The ExceptionModel parameter is to handle the field in
// TargetOptions. This interface fails to distinguish the forced disable
// case for targets which support exceptions by default. This should
// probably be a module flag and removed from TargetOptions.
if (ExceptionModel == ExceptionHandling::None)
ExceptionModel = TT.getDefaultExceptionHandling();

initLibcalls(TT, ExceptionModel, FloatABI, EABIVersion, ABIName);

// TODO: Tablegen should generate these sets
switch (ClVectorLibrary) {
case VectorLibrary::SLEEFGNUABI:
for (RTLIB::LibcallImpl Impl :
{RTLIB::impl__ZGVnN4vl4l4_sincospif, RTLIB::impl__ZGVnN2vl8l8_sincospi,
RTLIB::impl__ZGVsNxvl4l4_sincospif,
RTLIB::impl__ZGVsNxvl8l8_sincospi})
setAvailable(Impl);
break;
case VectorLibrary::ArmPL:
for (RTLIB::LibcallImpl Impl :
{RTLIB::impl_armpl_vsincospiq_f32, RTLIB::impl_armpl_vsincospiq_f64,
RTLIB::impl_armpl_svsincospi_f32_x,
RTLIB::impl_armpl_svsincospi_f64_x})
setAvailable(Impl);
break;
default:
break;
}
}

RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M)
: RuntimeLibcallsInfo(M.getTargetTriple()) {
// TODO: Consider module flags
Expand Down Expand Up @@ -88,6 +123,8 @@ RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT,
static constexpr Attribute::AttrKind CommonFnAttrs[] = {
Attribute::NoCallback, Attribute::NoFree, Attribute::NoSync,
Attribute::NoUnwind, Attribute::WillReturn};
static constexpr Attribute::AttrKind CommonPtrArgAttrs[] = {
Attribute::NoAlias, Attribute::WriteOnly, Attribute::NonNull};

switch (LibcallImpl) {
case RTLIB::impl___sincos_stret:
Expand Down Expand Up @@ -151,9 +188,67 @@ RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT,
fcNegNormal));
return {FuncTy, Attrs};
}
case RTLIB::impl__ZGVnN4vl4l4_sincospif:
case RTLIB::impl__ZGVnN2vl8l8_sincospi:
case RTLIB::impl__ZGVsNxvl4l4_sincospif:
case RTLIB::impl__ZGVsNxvl8l8_sincospi:
case RTLIB::impl_armpl_vsincospiq_f32:
case RTLIB::impl_armpl_vsincospiq_f64:
case RTLIB::impl_armpl_svsincospi_f32_x:
case RTLIB::impl_armpl_svsincospi_f64_x: {
AttrBuilder FuncAttrBuilder(Ctx);

bool IsF32 = LibcallImpl == RTLIB::impl__ZGVnN4vl4l4_sincospif ||
LibcallImpl == RTLIB::impl__ZGVsNxvl4l4_sincospif ||
LibcallImpl == RTLIB::impl_armpl_vsincospiq_f32 ||
LibcallImpl == RTLIB::impl_armpl_svsincospi_f32_x;
Type *ScalarTy = IsF32 ? Type::getFloatTy(Ctx) : Type::getDoubleTy(Ctx);
unsigned EC = IsF32 ? 4 : 2;

bool IsScalable = LibcallImpl == RTLIB::impl__ZGVsNxvl4l4_sincospif ||
LibcallImpl == RTLIB::impl__ZGVsNxvl8l8_sincospi ||
LibcallImpl == RTLIB::impl_armpl_svsincospi_f32_x ||
LibcallImpl == RTLIB::impl_armpl_svsincospi_f64_x;
VectorType *VecTy = VectorType::get(ScalarTy, EC, IsScalable);

for (Attribute::AttrKind Attr : CommonFnAttrs)
FuncAttrBuilder.addAttribute(Attr);
FuncAttrBuilder.addMemoryAttr(MemoryEffects::argMemOnly(ModRefInfo::Mod));

AttributeList Attrs;
Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);

{
AttrBuilder ArgAttrBuilder(Ctx);
for (Attribute::AttrKind AK : CommonPtrArgAttrs)
ArgAttrBuilder.addAttribute(AK);
ArgAttrBuilder.addAlignmentAttr(DL.getABITypeAlign(VecTy));
Attrs = Attrs.addParamAttributes(Ctx, 1, ArgAttrBuilder);
Attrs = Attrs.addParamAttributes(Ctx, 2, ArgAttrBuilder);
}

PointerType *PtrTy = PointerType::get(Ctx, 0);
SmallVector<Type *, 4> ArgTys = {VecTy, PtrTy, PtrTy};
if (hasVectorMaskArgument(LibcallImpl))
ArgTys.push_back(VectorType::get(Type::getInt1Ty(Ctx), EC, IsScalable));

return {FunctionType::get(Type::getVoidTy(Ctx), ArgTys, false), Attrs};
}
default:
return {};
}

return {};
}

bool RuntimeLibcallsInfo::hasVectorMaskArgument(RTLIB::LibcallImpl Impl) {
/// FIXME: This should be generated by tablegen and support the argument at an
/// arbitrary position
Comment on lines +245 to +246
Copy link
Collaborator

Choose a reason for hiding this comment

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

The library functions within TargetLibraryInfo include a VFABI string to provide this information. Perhaps that's not a good fit? not least because in order to decode a full FunctionType requires the scalar function declaration the vector function is a variant of. I just figured it's worth mentioning so that we can share any good bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eventually RuntimeLibcalls needs a way to express the type information in tablegen. I don't want to tie this to the existing macro thing to get there

switch (Impl) {
case RTLIB::impl_armpl_svsincospi_f32_x:
case RTLIB::impl_armpl_svsincospi_f64_x:
return true;
default:
return false;
}
}
12 changes: 12 additions & 0 deletions llvm/test/Transforms/Util/DeclareRuntimeLibcalls/armpl.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; REQUIRES: aarch64-registered-target
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-unknown-linux -mattr=+neon,+sve -vector-library=ArmPL < %s | FileCheck %s

; CHECK: declare void @armpl_svsincospi_f32_x(<vscale x 4 x float>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16, <vscale x 4 x i1>) [[ATTRS:#[0-9]+]]

; CHECK: declare void @armpl_svsincospi_f64_x(<vscale x 2 x double>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16, <vscale x 2 x i1>) [[ATTRS:#[0-9]+]]

; CHECK: declare void @armpl_vsincospiq_f32(<4 x float>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]]

; CHECK: declare void @armpl_vsincospiq_f64(<2 x double>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]]

; CHECK: attributes [[ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
12 changes: 12 additions & 0 deletions llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sleef.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; REQUIRES: aarch64-registered-target
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-unknown-linux -mattr=+neon,+sve -vector-library=sleefgnuabi < %s | FileCheck %s

; CHECK: declare void @_ZGVnN2vl8l8_sincospi(<2 x double>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS:#[0-9]+]]

; CHECK: declare void @_ZGVnN4vl4l4_sincospif(<4 x float>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]]

; CHECK: declare void @_ZGVsNxvl4l4_sincospif(<vscale x 4 x float>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS:#[0-9]+]]

; CHECK: declare void @_ZGVsNxvl8l8_sincospi(<vscale x 2 x double>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS:#[0-9]+]]

; CHECK: attributes [[ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
Loading