Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:10

0001 //===- RuntimeLibcalls.h - Interface for runtime libcalls -------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file implements a common interface to work with library calls into a
0010 // runtime that may be emitted by a given backend.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_IR_RUNTIME_LIBCALLS_H
0015 #define LLVM_IR_RUNTIME_LIBCALLS_H
0016 
0017 #include "llvm/ADT/ArrayRef.h"
0018 #include "llvm/IR/CallingConv.h"
0019 #include "llvm/Support/AtomicOrdering.h"
0020 #include "llvm/TargetParser/Triple.h"
0021 
0022 namespace llvm {
0023 namespace RTLIB {
0024 
0025 /// RTLIB::Libcall enum - This enum defines all of the runtime library calls
0026 /// the backend can emit.  The various long double types cannot be merged,
0027 /// because 80-bit library functions use "xf" and 128-bit use "tf".
0028 ///
0029 /// When adding PPCF128 functions here, note that their names generally need
0030 /// to be overridden for Darwin with the xxx$LDBL128 form.  See
0031 /// PPCISelLowering.cpp.
0032 ///
0033 enum Libcall {
0034 #define HANDLE_LIBCALL(code, name) code,
0035 #include "llvm/IR/RuntimeLibcalls.def"
0036 #undef HANDLE_LIBCALL
0037 };
0038 
0039 /// A simple container for information about the supported runtime calls.
0040 struct RuntimeLibcallsInfo {
0041   explicit RuntimeLibcallsInfo(const Triple &TT) {
0042     initLibcalls(TT);
0043   }
0044 
0045   /// Rename the default libcall routine name for the specified libcall.
0046   void setLibcallName(RTLIB::Libcall Call, const char *Name) {
0047     LibcallRoutineNames[Call] = Name;
0048   }
0049 
0050   void setLibcallName(ArrayRef<RTLIB::Libcall> Calls, const char *Name) {
0051     for (auto Call : Calls)
0052       setLibcallName(Call, Name);
0053   }
0054 
0055   /// Get the libcall routine name for the specified libcall.
0056   const char *getLibcallName(RTLIB::Libcall Call) const {
0057     return LibcallRoutineNames[Call];
0058   }
0059 
0060   /// Set the CallingConv that should be used for the specified libcall.
0061   void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
0062     LibcallCallingConvs[Call] = CC;
0063   }
0064 
0065   /// Get the CallingConv that should be used for the specified libcall.
0066   CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
0067     return LibcallCallingConvs[Call];
0068   }
0069 
0070   iterator_range<const char **> getLibcallNames() {
0071     return llvm::make_range(LibcallRoutineNames,
0072                             LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL);
0073   }
0074 
0075 private:
0076   /// Stores the name each libcall.
0077   const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
0078 
0079   /// Stores the CallingConv that should be used for each libcall.
0080   CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
0081 
0082   static bool darwinHasSinCos(const Triple &TT) {
0083     assert(TT.isOSDarwin() && "should be called with darwin triple");
0084     // Don't bother with 32 bit x86.
0085     if (TT.getArch() == Triple::x86)
0086       return false;
0087     // Macos < 10.9 has no sincos_stret.
0088     if (TT.isMacOSX())
0089       return !TT.isMacOSXVersionLT(10, 9) && TT.isArch64Bit();
0090     // iOS < 7.0 has no sincos_stret.
0091     if (TT.isiOS())
0092       return !TT.isOSVersionLT(7, 0);
0093     // Any other darwin such as WatchOS/TvOS is new enough.
0094     return true;
0095   }
0096 
0097   /// Set default libcall names. If a target wants to opt-out of a libcall it
0098   /// should be placed here.
0099   void initLibcalls(const Triple &TT);
0100 };
0101 
0102 } // namespace RTLIB
0103 } // namespace llvm
0104 
0105 #endif // LLVM_IR_RUNTIME_LIBCALLS_H