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

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 23:59:14 PDT 2025


Author: Matt Arsenault
Date: 2025-09-03T15:59:10+09:00
New Revision: 655cdf2e45a108177f013a59f108d17a8a267783

URL: https://github.com/llvm/llvm-project/commit/655cdf2e45a108177f013a59f108d17a8a267783
DIFF: https://github.com/llvm/llvm-project/commit/655cdf2e45a108177f013a59f108d17a8a267783.diff

LOG: llvm-tli-checker: Remove TLINameList helper struct (#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.

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/TargetLibraryInfo.h
    llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
index c7bd1618e2f9b..26963ed73512a 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -454,6 +454,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