|
| 1 | +//===- LibcallLoweringInfo.h ---------------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "llvm/IR/RuntimeLibcalls.h" |
| 10 | + |
| 11 | +namespace llvm { |
| 12 | + |
| 13 | +class LibcallLoweringInfo { |
| 14 | +private: |
| 15 | + LLVM_ABI const RTLIB::RuntimeLibcallsInfo &RTLCI; |
| 16 | + /// Stores the implementation choice for each each libcall. |
| 17 | + LLVM_ABI RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = { |
| 18 | + RTLIB::Unsupported}; |
| 19 | + |
| 20 | +public: |
| 21 | + LLVM_ABI LibcallLoweringInfo(const RTLIB::RuntimeLibcallsInfo &RTLCI); |
| 22 | + |
| 23 | + /// Get the libcall routine name for the specified libcall. |
| 24 | + // FIXME: This should be removed. Only LibcallImpl should have a name. |
| 25 | + LLVM_ABI const char *getLibcallName(RTLIB::Libcall Call) const { |
| 26 | + // FIXME: Return StringRef |
| 27 | + return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LibcallImpls[Call]) |
| 28 | + .data(); |
| 29 | + } |
| 30 | + |
| 31 | + /// Return the lowering's selection of implementation call for \p Call |
| 32 | + LLVM_ABI RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const { |
| 33 | + return LibcallImpls[Call]; |
| 34 | + } |
| 35 | + |
| 36 | + /// Rename the default libcall routine name for the specified libcall. |
| 37 | + LLVM_ABI void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) { |
| 38 | + LibcallImpls[Call] = Impl; |
| 39 | + } |
| 40 | + |
| 41 | + // FIXME: Remove this wrapper in favor of directly using |
| 42 | + // getLibcallImplCallingConv |
| 43 | + LLVM_ABI CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const { |
| 44 | + return RTLCI.LibcallImplCallingConvs[LibcallImpls[Call]]; |
| 45 | + } |
| 46 | + |
| 47 | + /// Get the CallingConv that should be used for the specified libcall. |
| 48 | + LLVM_ABI CallingConv::ID |
| 49 | + getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const { |
| 50 | + return RTLCI.LibcallImplCallingConvs[Call]; |
| 51 | + } |
| 52 | + |
| 53 | + /// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully |
| 54 | + /// unsupported. |
| 55 | + LLVM_ABI StringRef getMemcpyName() const { |
| 56 | + RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY); |
| 57 | + if (Memcpy != RTLIB::Unsupported) |
| 58 | + return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Memcpy); |
| 59 | + |
| 60 | + // Fallback to memmove if memcpy isn't available. |
| 61 | + return getLibcallName(RTLIB::MEMMOVE); |
| 62 | + } |
| 63 | +}; |
| 64 | + |
| 65 | +} // end namespace llvm |
0 commit comments