Skip to content

Commit 468c050

Browse files
committed
RuntimeLibcalls: Add libcall entries for sleef and armpl modf functions
1 parent ea10026 commit 468c050

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ foreach FPTy = ["F32", "F64", "F80", "F128", "PPCF128"] in {
183183
}
184184

185185
foreach VecTy = ["V4F32", "V2F64", "NXV4F32", "NXV2F64"] in {
186+
def MODF_#VecTy : RuntimeLibcall;
186187
def SINCOS_#VecTy : RuntimeLibcall;
187188
def SINCOSPI_#VecTy : RuntimeLibcall;
188189
}
@@ -1093,6 +1094,11 @@ def __security_check_cookie_arm64ec : RuntimeLibcallImpl<SECURITY_CHECK_COOKIE,
10931094
//===----------------------------------------------------------------------===//
10941095

10951096
defset list<RuntimeLibcallImpl> SleefLibcalls = {
1097+
def _ZGVnN2vl8_modf : RuntimeLibcallImpl<MODF_V2F64>;
1098+
def _ZGVnN4vl4_modff : RuntimeLibcallImpl<MODF_V4F32>;
1099+
def _ZGVsNxvl8_modf : RuntimeLibcallImpl<MODF_NXV2F64>;
1100+
def _ZGVsNxvl4_modff : RuntimeLibcallImpl<MODF_NXV4F32>;
1101+
10961102
def _ZGVnN2vl8l8_sincos : RuntimeLibcallImpl<SINCOS_V2F64>;
10971103
def _ZGVnN4vl4l4_sincosf : RuntimeLibcallImpl<SINCOS_V4F32>;
10981104
def _ZGVsNxvl8l8_sincos : RuntimeLibcallImpl<SINCOS_NXV2F64>;
@@ -1109,6 +1115,11 @@ defset list<RuntimeLibcallImpl> SleefLibcalls = {
11091115
//===----------------------------------------------------------------------===//
11101116

11111117
defset list<RuntimeLibcallImpl> ARMPLLibcalls = {
1118+
def armpl_vmodfq_f64 : RuntimeLibcallImpl<MODF_V2F64>; // CallingConv::AArch64_VectorCall
1119+
def armpl_vmodfq_f32 : RuntimeLibcallImpl<MODF_V4F32>; // CallingConv::AArch64_VectorCall
1120+
def armpl_svmodf_f64_x : RuntimeLibcallImpl<MODF_NXV2F64>;
1121+
def armpl_svmodf_f32_x : RuntimeLibcallImpl<MODF_NXV4F32>;
1122+
11121123
def armpl_vsincosq_f64
11131124
: RuntimeLibcallImpl<SINCOS_V2F64>; // CallingConv::AArch64_VectorCall
11141125
def armpl_vsincosq_f32

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
4343
switch (ClVectorLibrary) {
4444
case VectorLibrary::SLEEFGNUABI:
4545
for (RTLIB::LibcallImpl Impl :
46-
{RTLIB::impl__ZGVnN2vl8l8_sincos, RTLIB::impl__ZGVnN4vl4l4_sincosf,
46+
{RTLIB::impl__ZGVnN2vl8_modf, RTLIB::impl__ZGVnN4vl4_modff,
47+
RTLIB::impl__ZGVsNxvl8_modf, RTLIB::impl__ZGVsNxvl4_modff,
48+
RTLIB::impl__ZGVnN2vl8l8_sincos, RTLIB::impl__ZGVnN4vl4l4_sincosf,
4749
RTLIB::impl__ZGVsNxvl8l8_sincos, RTLIB::impl__ZGVsNxvl4l4_sincosf,
4850
RTLIB::impl__ZGVnN4vl4l4_sincospif, RTLIB::impl__ZGVnN2vl8l8_sincospi,
4951
RTLIB::impl__ZGVsNxvl4l4_sincospif,
@@ -52,7 +54,9 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
5254
break;
5355
case VectorLibrary::ArmPL:
5456
for (RTLIB::LibcallImpl Impl :
55-
{RTLIB::impl_armpl_vsincosq_f64, RTLIB::impl_armpl_vsincosq_f32,
57+
{RTLIB::impl_armpl_vmodfq_f64, RTLIB::impl_armpl_vmodfq_f32,
58+
RTLIB::impl_armpl_svmodf_f64_x, RTLIB::impl_armpl_svmodf_f32_x,
59+
RTLIB::impl_armpl_vsincosq_f64, RTLIB::impl_armpl_vsincosq_f32,
5660
RTLIB::impl_armpl_svsincos_f64_x, RTLIB::impl_armpl_svsincos_f32_x,
5761
RTLIB::impl_armpl_vsincospiq_f32, RTLIB::impl_armpl_vsincospiq_f64,
5862
RTLIB::impl_armpl_svsincospi_f32_x,
@@ -197,6 +201,55 @@ RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT,
197201
fcNegNormal));
198202
return {FuncTy, Attrs};
199203
}
204+
case RTLIB::impl__ZGVnN2vl8_modf:
205+
case RTLIB::impl__ZGVnN4vl4_modff:
206+
case RTLIB::impl__ZGVsNxvl8_modf:
207+
case RTLIB::impl__ZGVsNxvl4_modff:
208+
case RTLIB::impl_armpl_vmodfq_f64:
209+
case RTLIB::impl_armpl_vmodfq_f32:
210+
case RTLIB::impl_armpl_svmodf_f64_x:
211+
case RTLIB::impl_armpl_svmodf_f32_x: {
212+
AttrBuilder FuncAttrBuilder(Ctx);
213+
214+
bool IsF32 = LibcallImpl == RTLIB::impl__ZGVnN4vl4_modff ||
215+
LibcallImpl == RTLIB::impl__ZGVsNxvl4_modff ||
216+
LibcallImpl == RTLIB::impl_armpl_vmodfq_f32 ||
217+
LibcallImpl == RTLIB::impl_armpl_svmodf_f32_x;
218+
219+
bool IsScalable = LibcallImpl == RTLIB::impl__ZGVsNxvl8_modf ||
220+
LibcallImpl == RTLIB::impl__ZGVsNxvl4_modff ||
221+
LibcallImpl == RTLIB::impl_armpl_svmodf_f64_x ||
222+
LibcallImpl == RTLIB::impl_armpl_svmodf_f32_x;
223+
224+
Type *ScalarTy = IsF32 ? Type::getFloatTy(Ctx) : Type::getDoubleTy(Ctx);
225+
unsigned EC = IsF32 ? 4 : 2;
226+
227+
Type *VecTy =
228+
IsScalable ? static_cast<Type *>(ScalableVectorType::get(ScalarTy, EC))
229+
: static_cast<Type *>(FixedVectorType::get(ScalarTy, EC));
230+
231+
for (Attribute::AttrKind Attr : CommonFnAttrs)
232+
FuncAttrBuilder.addAttribute(Attr);
233+
FuncAttrBuilder.addMemoryAttr(MemoryEffects::argMemOnly(ModRefInfo::Mod));
234+
235+
AttributeList Attrs;
236+
Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
237+
238+
{
239+
AttrBuilder ArgAttrBuilder(Ctx);
240+
for (Attribute::AttrKind AK : CommonPtrArgAttrs)
241+
ArgAttrBuilder.addAttribute(AK);
242+
ArgAttrBuilder.addAlignmentAttr(DL.getABITypeAlign(VecTy));
243+
Attrs = Attrs.addParamAttributes(Ctx, 1, ArgAttrBuilder);
244+
}
245+
246+
PointerType *PtrTy = PointerType::get(Ctx, 0);
247+
SmallVector<Type *, 4> ArgTys = {VecTy, PtrTy};
248+
if (IsScalable && hasVectorMaskArgument(LibcallImpl))
249+
ArgTys.push_back(ScalableVectorType::get(Type::getInt1Ty(Ctx), EC));
250+
251+
return {FunctionType::get(VecTy, ArgTys, false), Attrs};
252+
}
200253
case RTLIB::impl__ZGVnN2vl8l8_sincos:
201254
case RTLIB::impl__ZGVnN4vl4l4_sincosf:
202255
case RTLIB::impl__ZGVsNxvl8l8_sincos:
@@ -271,6 +324,8 @@ bool RuntimeLibcallsInfo::hasVectorMaskArgument(RTLIB::LibcallImpl Impl) {
271324
/// FIXME: This should be generated by tablegen and support the argument at an
272325
/// arbitrary position
273326
switch (Impl) {
327+
case RTLIB::impl_armpl_svmodf_f64_x:
328+
case RTLIB::impl_armpl_svmodf_f32_x:
274329
case RTLIB::impl_armpl_svsincos_f32_x:
275330
case RTLIB::impl_armpl_svsincos_f64_x:
276331
case RTLIB::impl_armpl_svsincospi_f32_x:

llvm/test/Transforms/Util/DeclareRuntimeLibcalls/armpl.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
; REQUIRES: aarch64-registered-target
22
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-unknown-linux -mattr=+neon,+sve -vector-library=ArmPL < %s | FileCheck %s
33

4+
; CHECK: declare <vscale x 4 x float> @armpl_svmodf_f32_x(<vscale x 4 x float>, ptr noalias nonnull writeonly align 16, <vscale x 4 x i1>) [[ATTRS:#[0-9]+]]
5+
6+
; CHECK: declare <vscale x 2 x double> @armpl_svmodf_f64_x(<vscale x 2 x double>, ptr noalias nonnull writeonly align 16, <vscale x 2 x i1>) [[ATTRS]]
7+
48
; CHECK: declare void @armpl_svsincos_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]+]]
59

610
; CHECK: declare void @armpl_svsincos_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]]
@@ -9,6 +13,10 @@
913

1014
; 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]]
1115

16+
; CHECK: declare <4 x float> @armpl_vmodfq_f32(<4 x float>, ptr noalias nonnull writeonly align 16) [[ATTRS]]
17+
18+
; CHECK: declare <2 x double> @armpl_vmodfq_f64(<2 x double>, ptr noalias nonnull writeonly align 16) [[ATTRS]]
19+
1220
; CHECK: declare void @armpl_vsincospiq_f32(<4 x float>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]]
1321

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

llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sleef.ll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
; REQUIRES: aarch64-registered-target
22
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-unknown-linux -mattr=+neon,+sve -vector-library=sleefgnuabi < %s | FileCheck %s
33

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

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

10+
; CHECK: declare <4 x float> @_ZGVnN4vl4_modff(<4 x float>, ptr noalias nonnull writeonly align 16) [[ATTRS]]
11+
812
; CHECK: declare void @_ZGVnN4vl4l4_sincosf(<4 x float>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]]
913

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

16+
; CHECK: declare <vscale x 4 x float> @_ZGVsNxvl4_modff(<vscale x 4 x float>, ptr noalias nonnull writeonly align 16) [[ATTRS]]
17+
1218
; CHECK: declare void @_ZGVsNxvl4l4_sincosf(<vscale x 4 x float>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]]
1319

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

22+
; CHECK: declare <vscale x 2 x double> @_ZGVsNxvl8_modf(<vscale x 2 x double>, ptr noalias nonnull writeonly align 16) [[ATTRS]]
23+
1624
; CHECK: declare void @_ZGVsNxvl8l8_sincos(<vscale x 2 x double>, ptr noalias nonnull writeonly align 16, ptr noalias nonnull writeonly align 16) [[ATTRS]]
1725

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

0 commit comments

Comments
 (0)