[llvm] llvm-tli-checker: Remove TLINameList helper struct (PR #142535)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 22:58:25 PDT 2025


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/142535

This avoids subclassing std::vector and a static constructor.
This started as a refactor to make TargetLibraryInfo available during
printing so a custom name could be reported. It turns out this struct
wasn't doing anything, other than providing a hacky way of printing the
standard name instead of the target's custom name. Just remove this and
stop hacking on the TargetLibraryInfo to falsely report the function
is available later.

>From 11a4fad71296ed88da8c5339c0b5bd9feee9b01a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 2 Jun 2025 14:37:58 +0200
Subject: [PATCH] llvm-tli-checker: Remove TLINameList helper struct

This avoids subclassing std::vector and a static constructor.
This started as a refactor to make TargetLibraryInfo available during
printing so a custom name could be reported. It turns out this struct
wasn't doing anything, other than providing a hacky way of printing the
standard name instead of the target's custom name. Just remove this and
stop hacking on the TargetLibraryInfo to falsely report the function
is available later.
---
 .../include/llvm/Analysis/TargetLibraryInfo.h |  6 ++
 .../llvm-tli-checker/llvm-tli-checker.cpp     | 64 +++++++++----------
 2 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
index 0596ff86b473e..e900d2d4fd80d 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -452,6 +452,12 @@ class TargetLibraryInfo {
     return false;
   }
 
+  /// Return the canonical name for a LibFunc. This should not be used for
+  /// semantic purposes, use getName instead.
+  static StringRef getStandardName(LibFunc F) {
+    return TargetLibraryInfoImpl::StandardNames[F];
+  }
+
   StringRef getName(LibFunc F) const {
     auto State = getState(F);
     if (State == TargetLibraryInfoImpl::Unavailable)
diff --git a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
index ca0b424722196..bc20386987cae 100644
--- a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -110,43 +110,31 @@ static std::string getPrintableName(StringRef Name) {
   return OutputName;
 }
 
-// Store all the names that TargetLibraryInfo knows about; the bool indicates
-// whether TLI has it marked as "available" for the target of interest.
-// This is a vector to preserve the sorted order for better reporting.
-struct TLINameList : std::vector<std::pair<StringRef, bool>> {
-  // Record all the TLI info in the vector.
-  void initialize(StringRef TargetTriple);
-  // Print out what we found.
-  void dump();
-};
-static TLINameList TLINames;
-
-void TLINameList::initialize(StringRef TargetTriple) {
-  Triple T(TargetTriple);
-  TargetLibraryInfoImpl TLII(T);
-  TargetLibraryInfo TLI(TLII);
+static void reportNumberOfEntries(const TargetLibraryInfo &TLI,
+                                  StringRef TargetTriple) {
+  unsigned NumAvailable = 0;
 
-  reserve(LibFunc::NumLibFuncs);
-  size_t NumAvailable = 0;
+  // Assume this gets called after initialize(), so we have the above line of
+  // output as a header.  So, for example, no need to repeat the triple.
   for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {
-    LibFunc LF = (LibFunc)FI;
-    bool Available = TLI.has(LF);
-    // getName returns names only for available funcs.
-    TLII.setAvailable(LF);
-    emplace_back(TLI.getName(LF), Available);
-    if (Available)
+    if (TLI.has(static_cast<LibFunc>(FI)))
       ++NumAvailable;
   }
+
   outs() << "TLI knows " << LibFunc::NumLibFuncs << " symbols, " << NumAvailable
          << " available for '" << TargetTriple << "'\n";
 }
 
-void TLINameList::dump() {
+static void dumpTLIEntries(const TargetLibraryInfo &TLI) {
   // Assume this gets called after initialize(), so we have the above line of
   // output as a header.  So, for example, no need to repeat the triple.
-  for (auto &TLIName : TLINames) {
-    outs() << (TLIName.second ? "    " : "not ")
-           << "available: " << getPrintableName(TLIName.first) << '\n';
+  for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {
+    LibFunc LF = static_cast<LibFunc>(FI);
+    bool IsAvailable = TLI.has(LF);
+    StringRef FuncName = TargetLibraryInfo::getStandardName(LF);
+
+    outs() << (IsAvailable ? "    " : "not ")
+           << "available: " << getPrintableName(FuncName) << '\n';
   }
 }
 
@@ -271,11 +259,16 @@ int main(int argc, char *argv[]) {
     return 0;
   }
 
-  TLINames.initialize(Args.getLastArgValue(OPT_triple_EQ));
+  StringRef TripleStr = Args.getLastArgValue(OPT_triple_EQ);
+  Triple TargetTriple(TripleStr);
+  TargetLibraryInfoImpl TLII(TargetTriple);
+  TargetLibraryInfo TLI(TLII);
+
+  reportNumberOfEntries(TLI, TripleStr);
 
   // --dump-tli doesn't require any input files.
   if (Args.hasArg(OPT_dump_tli)) {
-    TLINames.dump();
+    dumpTLIEntries(TLI);
     return 0;
   }
 
@@ -321,9 +314,13 @@ int main(int argc, char *argv[]) {
     unsigned TLIdoesntSDKdoes = 0;
     unsigned TLIandSDKboth = 0;
     unsigned TLIandSDKneither = 0;
-    for (auto &TLIName : TLINames) {
-      bool TLIHas = TLIName.second;
-      bool SDKHas = SDKNames.count(TLIName.first) == 1;
+
+    for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {
+      LibFunc LF = static_cast<LibFunc>(FI);
+
+      StringRef TLIName = TLI.getStandardName(LF);
+      bool TLIHas = TLI.has(LF);
+      bool SDKHas = SDKNames.count(TLIName) == 1;
       int Which = int(TLIHas) * 2 + int(SDKHas);
       switch (Which) {
       case 0: ++TLIandSDKneither; break;
@@ -338,8 +335,7 @@ int main(int argc, char *argv[]) {
         constexpr char YesNo[2][4] = {"no ", "yes"};
         constexpr char Indicator[4][3] = {"!!", ">>", "<<", "=="};
         outs() << Indicator[Which] << " TLI " << YesNo[TLIHas] << " SDK "
-               << YesNo[SDKHas] << ": " << getPrintableName(TLIName.first)
-               << '\n';
+               << YesNo[SDKHas] << ": " << getPrintableName(TLIName) << '\n';
       }
     }
 



More information about the llvm-commits mailing list