Skip to content

RuntimeLibcalls: Use array initializers for default values #143082

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

Merged
merged 3 commits into from
Jun 17, 2025

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jun 6, 2025

No description provided.

Copy link
Contributor Author

arsenm commented Jun 6, 2025

@arsenm arsenm marked this pull request as ready for review June 6, 2025 06:48
@llvmbot llvmbot added the llvm:ir label Jun 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2025

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/143082.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.h (+5-3)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (-10)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index d2704d5aa2616..d67430968edf1 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -90,10 +90,11 @@ struct RuntimeLibcallsInfo {
 
 private:
   /// Stores the name each libcall.
-  const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
+  const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr};
 
   /// Stores the CallingConv that should be used for each libcall.
-  CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
+  CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = {
+      CallingConv::C};
 
   /// The condition type that should be used to test the result of each of the
   /// soft floating-point comparison libcall against integer zero.
@@ -101,7 +102,8 @@ struct RuntimeLibcallsInfo {
   // FIXME: This is only relevant for the handful of floating-point comparison
   // runtime calls; it's excessive to have a table entry for every single
   // opcode.
-  CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL];
+  CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] =
+      {CmpInst::BAD_ICMP_PREDICATE};
 
   static bool darwinHasSinCosStret(const Triple &TT) {
     assert(TT.isOSDarwin() && "should be called with darwin triple");
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index a6fda0cfeadd2..01978b7ae39e3 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -12,9 +12,6 @@ using namespace llvm;
 using namespace RTLIB;
 
 void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() {
-  std::fill(SoftFloatCompareLibcallPredicates,
-            SoftFloatCompareLibcallPredicates + RTLIB::UNKNOWN_LIBCALL,
-            CmpInst::BAD_ICMP_PREDICATE);
   SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F32] = CmpInst::ICMP_EQ;
   SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F64] = CmpInst::ICMP_EQ;
   SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F128] = CmpInst::ICMP_EQ;
@@ -48,19 +45,12 @@ void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() {
 /// Set default libcall names. If a target wants to opt-out of a libcall it
 /// should be placed here.
 void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
-  std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames),
-            nullptr);
-
   initSoftFloatCmpLibcallPredicates();
 
 #define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name);
 #include "llvm/IR/RuntimeLibcalls.def"
 #undef HANDLE_LIBCALL
 
-  // Initialize calling conventions to their default.
-  for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC)
-    setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C);
-
   // Use the f128 variants of math functions on x86
   if (TT.isX86() && TT.isGNUEnvironment()) {
     setLibcallName(RTLIB::REM_F128, "fmodf128");

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/cleanup-has-sincos-predicates branch from ee79ca1 to 65cb831 Compare June 6, 2025 07:18
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/use-initializer-lists branch from 8aa7850 to 0e8bba5 Compare June 6, 2025 07:18

/// The condition type that should be used to test the result of each of the
/// soft floating-point comparison libcall against integer zero.
///
// FIXME: This is only relevant for the handful of floating-point comparison
// runtime calls; it's excessive to have a table entry for every single
// opcode.
CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL];
CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] =
{CmpInst::BAD_ICMP_PREDICATE};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CmpInst::BAD_ICMP_PREDICATE is not zero (42) so only the first element of the array will be initialized to CmpInst::BAD_ICMP_PREDICATE rest will be zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no actual reason to initialize this, the only fields that are used are explicitly initialized separately. We should shrink the array as the FIXME says

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/use-initializer-lists branch from 0e8bba5 to f991879 Compare June 6, 2025 14:09
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/cleanup-has-sincos-predicates branch from 65cb831 to 6e17ae5 Compare June 6, 2025 14:09

/// Stores the CallingConv that should be used for each libcall.
CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = {
CallingConv::C};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly writing "CallingConv::C" here is confusing; either just use {}, or use something like SmallVector that actually has a constructor which fills an arbitrary value.

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/cleanup-has-sincos-predicates branch from 6e17ae5 to 30983d1 Compare June 9, 2025 02:35
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/use-initializer-lists branch from 540bdad to 9a03bb1 Compare June 9, 2025 02:35
Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/cleanup-has-sincos-predicates branch from 30983d1 to fbfc09b Compare June 11, 2025 00:33
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/use-initializer-lists branch from 9a03bb1 to 4cf8c0f Compare June 11, 2025 00:33
arsenm added 3 commits June 12, 2025 11:50
Work towards making RuntimeLibcalls the centralized location for
all libcall information. This requires changing the encoding from
tracking the ISD::CondCode to using CmpInst::Predicate.
The darwinHasSinCos wasn't actually used for sincos, only the stret
variant. Rename this to reflect that, and introduce a new one for
enabling sincos.
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/cleanup-has-sincos-predicates branch from fbfc09b to fc327d3 Compare June 12, 2025 03:11
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/use-initializer-lists branch from 4cf8c0f to 3a86744 Compare June 12, 2025 03:11
Copy link
Contributor Author

arsenm commented Jun 17, 2025

Merge activity

  • Jun 17, 12:37 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 17, 12:46 AM UTC: Graphite couldn't merge this PR because it had conflicts with the trunk branch.
  • Jun 17, 12:58 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 17, 1:00 AM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/cleanup-has-sincos-predicates branch from fc327d3 to c85d667 Compare June 17, 2025 00:43
Base automatically changed from users/arsenm/runtime-libcalls/cleanup-has-sincos-predicates to main June 17, 2025 00:46
@arsenm arsenm merged commit 8b1528f into main Jun 17, 2025
10 of 13 checks passed
@arsenm arsenm deleted the users/arsenm/runtime-libcalls/use-initializer-lists branch June 17, 2025 01:00
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants