[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Jun 8 19:35:56 PDT 2025


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143082

>From 9a03bb12f3caaba0833bd9f194b1951eb2c5aa0a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 6 Jun 2025 14:50:57 +0900
Subject: [PATCH] RuntimeLibcalls: Use array initializers for default values

---
 llvm/include/llvm/IR/RuntimeLibcalls.h |  7 +++++--
 llvm/lib/IR/RuntimeLibcalls.cpp        | 10 ----------
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index d8f467e30fa6a..3e1531ebfd9d6 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -103,10 +103,13 @@ struct RuntimeLibcallsInfo {
 
 private:
   /// Stores the name each libcall.
-  const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
+  const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr};
+
+  static_assert(static_cast<int>(CallingConv::C) == 0,
+                "default calling conv should be encoded as 0");
 
   /// Stores the CallingConv that should be used for each libcall.
-  CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
+  CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = {};
 
   /// The condition type that should be used to test the result of each of the
   /// soft floating-point comparison libcall against integer zero.
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 515bc8c050f7b..ed870ba8c1bd9 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -32,9 +32,6 @@ static void setAArch64LibcallNames(RuntimeLibcallsInfo &Info,
 }
 
 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;
@@ -68,19 +65,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");



More information about the llvm-branch-commits mailing list