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,67 @@ 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+ VectorType *VecTy = VectorType::get (ScalarTy, EC, IsScalable);
213+
214+ for (Attribute::AttrKind Attr : CommonFnAttrs)
215+ FuncAttrBuilder.addAttribute (Attr);
216+ FuncAttrBuilder.addMemoryAttr (MemoryEffects::argMemOnly (ModRefInfo::Mod));
217+
218+ AttributeList Attrs;
219+ Attrs = Attrs.addFnAttributes (Ctx, FuncAttrBuilder);
220+
221+ {
222+ AttrBuilder ArgAttrBuilder (Ctx);
223+ for (Attribute::AttrKind AK : CommonPtrArgAttrs)
224+ ArgAttrBuilder.addAttribute (AK);
225+ ArgAttrBuilder.addAlignmentAttr (DL.getABITypeAlign (VecTy));
226+ Attrs = Attrs.addParamAttributes (Ctx, 1 , ArgAttrBuilder);
227+ Attrs = Attrs.addParamAttributes (Ctx, 2 , ArgAttrBuilder);
228+ }
229+
230+ PointerType *PtrTy = PointerType::get (Ctx, 0 );
231+ SmallVector<Type *, 4 > ArgTys = {VecTy, PtrTy, PtrTy};
232+ if (hasVectorMaskArgument (LibcallImpl))
233+ ArgTys.push_back (VectorType::get (Type::getInt1Ty (Ctx), EC, IsScalable));
234+
235+ return {FunctionType::get (Type::getVoidTy (Ctx), ArgTys, false ), Attrs};
236+ }
154237 default :
155238 return {};
156239 }
157240
158241 return {};
159242}
243+
244+ bool RuntimeLibcallsInfo::hasVectorMaskArgument (RTLIB::LibcallImpl Impl) {
245+ // / FIXME: This should be generated by tablegen and support the argument at an
246+ // / arbitrary position
247+ switch (Impl) {
248+ case RTLIB::impl_armpl_svsincospi_f32_x:
249+ case RTLIB::impl_armpl_svsincospi_f64_x:
250+ return true ;
251+ default :
252+ return false ;
253+ }
254+ }
0 commit comments