-
Notifications
You must be signed in to change notification settings - Fork 14.3k
ARM: Start moving runtime libcalls into tablegen #146084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arsenm
wants to merge
1
commit into
users/arsenm/arm/set-eabi-libcall-calling-convs-in-runtime-libcalls
Choose a base branch
from
users/arsenm/arm/start-moving-runtime-libcalls-into-tablegen
base: users/arsenm/arm/set-eabi-libcall-calling-convs-in-runtime-libcalls
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+51
−77
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jun 27, 2025
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- llvm/include/llvm/IR/RuntimeLibcalls.h llvm/lib/IR/RuntimeLibcalls.cpp llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp View the diff from clang-format here.diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 7fb6b503d..562203509 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -168,7 +168,8 @@ private:
void initDefaultLibCallImpls();
/// Generated by tablegen.
- void setTargetRuntimeLibcallSets(const Triple &TT, FloatABI::ABIType FloatABI);
+ void setTargetRuntimeLibcallSets(const Triple &TT,
+ FloatABI::ABIType FloatABI);
/// Set default libcall names. If a target wants to opt-out of a libcall it
/// should be placed here.
|
@llvm/pr-subscribers-tablegen @llvm/pr-subscribers-llvm-ir Author: Matt Arsenault (arsenm) ChangesWe still need to manually set the calling conventions of Full diff: https://github.com/llvm/llvm-project/pull/146084.diff 4 Files Affected:
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index ecf20cbfd09f2..7fb6b503daa22 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -168,7 +168,7 @@ struct RuntimeLibcallsInfo {
void initDefaultLibCallImpls();
/// Generated by tablegen.
- void setTargetRuntimeLibcallSets(const Triple &TT);
+ void setTargetRuntimeLibcallSets(const Triple &TT, FloatABI::ABIType FloatABI);
/// Set default libcall names. If a target wants to opt-out of a libcall it
/// should be placed here.
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 396dc45240412..ac9f258e39ad2 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -15,6 +15,9 @@ include "llvm/IR/RuntimeLibcallsImpl.td"
class DuplicateLibcallImplWithPrefix<RuntimeLibcallImpl Impl, string prefix>
: RuntimeLibcallImpl<Impl.Provides, prefix#Impl.LibCallFuncName>;
+/// Libcall Predicates
+def isOSWindows : RuntimeLibcallPredicate<"TT.isOSWindows()">;
+
//--------------------------------------------------------------------
// Declare all kinds of used libcalls
//--------------------------------------------------------------------
@@ -1243,6 +1246,7 @@ def __aeabi_memclr4 : RuntimeLibcallImpl<AEABI_MEMCLR4>;
def __aeabi_memclr8 : RuntimeLibcallImpl<AEABI_MEMCLR8>;
// isTargetWindows()
+defset list<RuntimeLibcallImpl> WindowsFPIntCastLibcalls = {
def __stoi64 : RuntimeLibcallImpl<FPTOSINT_F32_I64>; // CallingConv::ARM_AAPCS_VFP
def __dtoi64 : RuntimeLibcallImpl<FPTOSINT_F64_I64>; // CallingConv::ARM_AAPCS_VFP
def __stou64 : RuntimeLibcallImpl<FPTOUINT_F32_I64>; // CallingConv::ARM_AAPCS_VFP
@@ -1251,6 +1255,7 @@ def __i64tos : RuntimeLibcallImpl<SINTTOFP_I64_F32>; // CallingConv::ARM_AAPCS_V
def __i64tod : RuntimeLibcallImpl<SINTTOFP_I64_F64>; // CallingConv::ARM_AAPCS_VFP
def __u64tos : RuntimeLibcallImpl<UINTTOFP_I64_F32>; // CallingConv::ARM_AAPCS_VFP
def __u64tod : RuntimeLibcallImpl<UINTTOFP_I64_F64>; // CallingConv::ARM_AAPCS_VFP
+}
def __rt_sdiv : RuntimeLibcallImpl<SDIVREM_I32>; // CallingConv::ARM_AAPCS
def __rt_sdiv64 : RuntimeLibcallImpl<SDIVREM_I64>; // CallingConv::ARM_AAPCS
@@ -1277,6 +1282,49 @@ def __aeabi_h2f : RuntimeLibcallImpl<FPEXT_F16_F32>; // CallingConv::ARM_AAPCS
def __gnu_f2h_ieee : RuntimeLibcallImpl<FPROUND_F32_F16>;
def __gnu_h2f_ieee : RuntimeLibcallImpl<FPEXT_F16_F32>;
+
+def WindowARMDivRemCalls : LibcallImpls<
+ (add __rt_sdiv, __rt_sdiv64, __rt_udiv, __rt_udiv64),
+ isOSWindows> {
+ let CallingConv = ARM_AAPCS;
+}
+
+def WindowARMFPIntCasts : LibcallImpls<
+ (add WindowsFPIntCastLibcalls),
+ isOSWindows> {
+ let CallingConv = ARM_AAPCS_VFP;
+}
+
+
+// Register based DivRem for AEABI (RTABI 4.2)
+def AEABIDivRemCalls : LibcallImpls<
+ (add __aeabi_idivmod, __aeabi_ldivmod,
+ __aeabi_uidivmod, __aeabi_uldivmod),
+ RuntimeLibcallPredicate<[{TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() ||
+ TT.isTargetMuslAEABI()}]>> {
+ let CallingConv = ARM_AAPCS;
+}
+
+def isARMOrThumb : RuntimeLibcallPredicate<"TT.isARM() || TT.isThumb()">;
+
+def ARMSystemLibrary
+ : SystemRuntimeLibrary<isARMOrThumb,
+ (add DefaultLibcallImpls32,
+ WindowARMDivRemCalls,
+ WindowARMFPIntCasts,
+ AEABIDivRemCalls,
+ // Use divmod compiler-rt calls for iOS 5.0 and later.
+ LibcallImpls<(add __divmodsi4, __udivmodsi4),
+ RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() &&
+ (!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>)> {
+ let DefaultLibcallCallingConv = LibcallCallingConv<[{
+ (!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) ?
+ (FloatABI == FloatABI::Hard ? CallingConv::ARM_AAPCS_VFP
+ : CallingConv::ARM_AAPCS) :
+ CallingConv::C
+ }]>;
+}
+
//===----------------------------------------------------------------------===//
// AVR Runtime Libcalls
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 9f24e9d1fc4b1..46b4acde922e2 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -25,80 +25,6 @@ static cl::opt<bool>
static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
FloatABI::ABIType FloatABIType,
EABI EABIVersion) {
- if (!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) {
- CallingConv::ID DefaultCC = FloatABIType == FloatABI::Hard
- ? CallingConv::ARM_AAPCS_VFP
- : CallingConv::ARM_AAPCS;
- for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls())
- Info.setLibcallImplCallingConv(LC, DefaultCC);
- }
-
- // Register based DivRem for AEABI (RTABI 4.2)
- if (TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() ||
- TT.isTargetMuslAEABI() || TT.isOSWindows()) {
- if (TT.isOSWindows()) {
- const struct {
- const RTLIB::Libcall Op;
- const RTLIB::LibcallImpl Impl;
- const CallingConv::ID CC;
- } LibraryCalls[] = {
- {RTLIB::SDIVREM_I32, RTLIB::__rt_sdiv, CallingConv::ARM_AAPCS},
- {RTLIB::SDIVREM_I64, RTLIB::__rt_sdiv64, CallingConv::ARM_AAPCS},
- {RTLIB::UDIVREM_I32, RTLIB::__rt_udiv, CallingConv::ARM_AAPCS},
- {RTLIB::UDIVREM_I64, RTLIB::__rt_udiv64, CallingConv::ARM_AAPCS},
- };
-
- for (const auto &LC : LibraryCalls) {
- Info.setLibcallImpl(LC.Op, LC.Impl);
- Info.setLibcallImplCallingConv(LC.Impl, LC.CC);
- }
- } else {
- const struct {
- const RTLIB::Libcall Op;
- const RTLIB::LibcallImpl Impl;
- const CallingConv::ID CC;
- } LibraryCalls[] = {
- {RTLIB::SDIVREM_I32, RTLIB::__aeabi_idivmod, CallingConv::ARM_AAPCS},
- {RTLIB::SDIVREM_I64, RTLIB::__aeabi_ldivmod, CallingConv::ARM_AAPCS},
- {RTLIB::UDIVREM_I32, RTLIB::__aeabi_uidivmod, CallingConv::ARM_AAPCS},
- {RTLIB::UDIVREM_I64, RTLIB::__aeabi_uldivmod, CallingConv::ARM_AAPCS},
- };
-
- for (const auto &LC : LibraryCalls) {
- Info.setLibcallImpl(LC.Op, LC.Impl);
- Info.setLibcallImplCallingConv(LC.Impl, LC.CC);
- }
- }
- }
-
- if (TT.isOSWindows()) {
- static const struct {
- const RTLIB::Libcall Op;
- const RTLIB::LibcallImpl Impl;
- const CallingConv::ID CC;
- } LibraryCalls[] = {
- {RTLIB::FPTOSINT_F32_I64, RTLIB::__stoi64, CallingConv::ARM_AAPCS_VFP},
- {RTLIB::FPTOSINT_F64_I64, RTLIB::__dtoi64, CallingConv::ARM_AAPCS_VFP},
- {RTLIB::FPTOUINT_F32_I64, RTLIB::__stou64, CallingConv::ARM_AAPCS_VFP},
- {RTLIB::FPTOUINT_F64_I64, RTLIB::__dtou64, CallingConv::ARM_AAPCS_VFP},
- {RTLIB::SINTTOFP_I64_F32, RTLIB::__i64tos, CallingConv::ARM_AAPCS_VFP},
- {RTLIB::SINTTOFP_I64_F64, RTLIB::__i64tod, CallingConv::ARM_AAPCS_VFP},
- {RTLIB::UINTTOFP_I64_F32, RTLIB::__u64tos, CallingConv::ARM_AAPCS_VFP},
- {RTLIB::UINTTOFP_I64_F64, RTLIB::__u64tod, CallingConv::ARM_AAPCS_VFP},
- };
-
- for (const auto &LC : LibraryCalls) {
- Info.setLibcallImpl(LC.Op, LC.Impl);
- Info.setLibcallImplCallingConv(LC.Impl, LC.CC);
- }
- }
-
- // Use divmod compiler-rt calls for iOS 5.0 and later.
- if (TT.isOSBinFormatMachO() && (!TT.isiOS() || !TT.isOSVersionLT(5, 0))) {
- Info.setLibcallImpl(RTLIB::SDIVREM_I32, RTLIB::__divmodsi4);
- Info.setLibcallImpl(RTLIB::UDIVREM_I32, RTLIB::__udivmodsi4);
- }
-
static const RTLIB::LibcallImpl AAPCS_Libcalls[] = {
RTLIB::__aeabi_dadd, RTLIB::__aeabi_ddiv,
RTLIB::__aeabi_dmul, RTLIB::__aeabi_dsub,
@@ -214,7 +140,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
ExceptionHandling ExceptionModel,
FloatABI::ABIType FloatABI,
EABI EABIVersion, StringRef ABIName) {
- setTargetRuntimeLibcallSets(TT);
+ setTargetRuntimeLibcallSets(TT, FloatABI);
// Use the f128 variants of math functions on x86
if (TT.isX86() && TT.isGNUEnvironment())
diff --git a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
index 041c404dde9b3..81494f80fb5c9 100644
--- a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
@@ -362,7 +362,7 @@ void RuntimeLibcallEmitter::emitGetInitRuntimeLibcallNames(
void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
raw_ostream &OS) const {
OS << "void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets("
- "const llvm::Triple &TT) {\n"
+ "const llvm::Triple &TT, FloatABI::ABIType FloatABI) {\n"
" struct LibcallImplPair {\n"
" RTLIB::Libcall Func;\n"
" RTLIB::LibcallImpl Impl;\n"
|
We still need to manually set the calling conventions of some libcalls until the lowering is separated out.
77239be
to
91dd754
Compare
6e10221
to
4e563f6
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We still need to manually set the calling conventions of
some libcalls until the lowering is separated out.