1010#include " llvm/ADT/FloatingPointMode.h"
1111#include " llvm/ADT/StringTable.h"
1212#include " llvm/IR/Module.h"
13+ #include " llvm/IR/SystemLibraries.h"
1314#include " llvm/Support/Debug.h"
1415#include " llvm/Support/xxhash.h"
1516#include " llvm/TargetParser/ARMTargetParser.h"
@@ -25,6 +26,40 @@ using namespace RTLIB;
2526#define DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
2627#include " llvm/IR/RuntimeLibcalls.inc"
2728
29+ RuntimeLibcallsInfo::RuntimeLibcallsInfo (const Triple &TT,
30+ ExceptionHandling ExceptionModel,
31+ FloatABI::ABIType FloatABI,
32+ EABI EABIVersion, StringRef ABIName) {
33+ // FIXME: The ExceptionModel parameter is to handle the field in
34+ // TargetOptions. This interface fails to distinguish the forced disable
35+ // case for targets which support exceptions by default. This should
36+ // probably be a module flag and removed from TargetOptions.
37+ if (ExceptionModel == ExceptionHandling::None)
38+ ExceptionModel = TT.getDefaultExceptionHandling ();
39+
40+ initLibcalls (TT, ExceptionModel, FloatABI, EABIVersion, ABIName);
41+
42+ // TODO: Tablegen should generate these sets
43+ switch (ClVectorLibrary) {
44+ case VectorLibrary::SLEEFGNUABI:
45+ for (RTLIB::LibcallImpl Impl :
46+ {RTLIB::impl__ZGVnN4vl4l4_sincospif, RTLIB::impl__ZGVnN2vl8l8_sincospi,
47+ RTLIB::impl__ZGVsNxvl4l4_sincospif,
48+ RTLIB::impl__ZGVsNxvl8l8_sincospi})
49+ setAvailable (Impl);
50+ break ;
51+ case VectorLibrary::ArmPL:
52+ for (RTLIB::LibcallImpl Impl :
53+ {RTLIB::impl_armpl_vsincospiq_f32, RTLIB::impl_armpl_vsincospiq_f64,
54+ RTLIB::impl_armpl_svsincospi_f32_x,
55+ RTLIB::impl_armpl_svsincospi_f64_x})
56+ setAvailable (Impl);
57+ break ;
58+ default :
59+ break ;
60+ }
61+ }
62+
2863RuntimeLibcallsInfo::RuntimeLibcallsInfo (const Module &M)
2964 : RuntimeLibcallsInfo(M.getTargetTriple()) {
3065 // TODO: Consider module flags
@@ -88,6 +123,8 @@ RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT,
88123 static constexpr Attribute::AttrKind CommonFnAttrs[] = {
89124 Attribute::NoCallback, Attribute::NoFree, Attribute::NoSync,
90125 Attribute::NoUnwind, Attribute::WillReturn};
126+ static constexpr Attribute::AttrKind CommonPtrArgAttrs[] = {
127+ Attribute::NoAlias, Attribute::WriteOnly, Attribute::NonNull};
91128
92129 switch (LibcallImpl) {
93130 case RTLIB::impl___sincos_stret:
@@ -151,9 +188,69 @@ RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT,
151188 fcNegNormal));
152189 return {FuncTy, Attrs};
153190 }
191+ case RTLIB::impl__ZGVnN4vl4l4_sincospif:
192+ case RTLIB::impl__ZGVnN2vl8l8_sincospi:
193+ case RTLIB::impl__ZGVsNxvl4l4_sincospif:
194+ case RTLIB::impl__ZGVsNxvl8l8_sincospi:
195+ case RTLIB::impl_armpl_vsincospiq_f32:
196+ case RTLIB::impl_armpl_vsincospiq_f64:
197+ case RTLIB::impl_armpl_svsincospi_f32_x:
198+ case RTLIB::impl_armpl_svsincospi_f64_x: {
199+ AttrBuilder FuncAttrBuilder (Ctx);
200+
201+ bool IsF32 = LibcallImpl == RTLIB::impl__ZGVnN4vl4l4_sincospif ||
202+ LibcallImpl == RTLIB::impl__ZGVsNxvl4l4_sincospif ||
203+ LibcallImpl == RTLIB::impl_armpl_vsincospiq_f32 ||
204+ LibcallImpl == RTLIB::impl_armpl_svsincospi_f32_x;
205+ Type *ScalarTy = IsF32 ? Type::getFloatTy (Ctx) : Type::getDoubleTy (Ctx);
206+ unsigned EC = IsF32 ? 4 : 2 ;
207+
208+ bool IsScalable = LibcallImpl == RTLIB::impl__ZGVsNxvl4l4_sincospif ||
209+ LibcallImpl == RTLIB::impl__ZGVsNxvl8l8_sincospi ||
210+ LibcallImpl == RTLIB::impl_armpl_svsincospi_f32_x ||
211+ LibcallImpl == RTLIB::impl_armpl_svsincospi_f64_x;
212+ Type *VecTy =
213+ IsScalable ? static_cast <Type *>(ScalableVectorType::get (ScalarTy, EC))
214+ : static_cast <Type *>(FixedVectorType::get (ScalarTy, EC));
215+
216+ for (Attribute::AttrKind Attr : CommonFnAttrs)
217+ FuncAttrBuilder.addAttribute (Attr);
218+ FuncAttrBuilder.addMemoryAttr (MemoryEffects::argMemOnly (ModRefInfo::Mod));
219+
220+ AttributeList Attrs;
221+ Attrs = Attrs.addFnAttributes (Ctx, FuncAttrBuilder);
222+
223+ {
224+ AttrBuilder ArgAttrBuilder (Ctx);
225+ for (Attribute::AttrKind AK : CommonPtrArgAttrs)
226+ ArgAttrBuilder.addAttribute (AK);
227+ ArgAttrBuilder.addAlignmentAttr (DL.getABITypeAlign (VecTy));
228+ Attrs = Attrs.addParamAttributes (Ctx, 1 , ArgAttrBuilder);
229+ Attrs = Attrs.addParamAttributes (Ctx, 2 , ArgAttrBuilder);
230+ }
231+
232+ PointerType *PtrTy = PointerType::get (Ctx, 0 );
233+ SmallVector<Type *, 4 > ArgTys = {VecTy, PtrTy, PtrTy};
234+ if (IsScalable && hasVectorMaskArgument (LibcallImpl))
235+ ArgTys.push_back (ScalableVectorType::get (Type::getInt1Ty (Ctx), EC));
236+
237+ return {FunctionType::get (Type::getVoidTy (Ctx), ArgTys, false ), Attrs};
238+ }
154239 default :
155240 return {};
156241 }
157242
158243 return {};
159244}
245+
246+ bool RuntimeLibcallsInfo::hasVectorMaskArgument (RTLIB::LibcallImpl Impl) {
247+ // / FIXME: This should be generated by tablegen and support the argument at an
248+ // / arbitrary position
249+ switch (Impl) {
250+ case RTLIB::impl_armpl_svsincospi_f32_x:
251+ case RTLIB::impl_armpl_svsincospi_f64_x:
252+ return true ;
253+ default :
254+ return false ;
255+ }
256+ }
0 commit comments