[llvm-branch-commits] [llvm] TableGen: Generate enum for runtime libcall implementations (PR #144973)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jun 27 00:27:04 PDT 2025


================
@@ -235,29 +247,57 @@ void RuntimeLibcallEmitter::emitGetInitRuntimeLibcallNames(
   // TODO: Emit libcall names as string offset table.
 
   OS << "#ifdef GET_INIT_RUNTIME_LIBCALL_NAMES\n"
-        "const char *const "
+        "const RTLIB::LibcallImpl "
         "llvm::RTLIB::RuntimeLibcallsInfo::"
-        "DefaultLibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {\n";
+        "DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {\n";
 
   for (const RuntimeLibcall &LibCall : RuntimeLibcallDefList) {
     auto I = LibCallToDefaultImpl.find(&LibCall);
-    if (I == LibCallToDefaultImpl.end())
-      OS << "  nullptr,";
-    else {
+    if (I == LibCallToDefaultImpl.end()) {
+      OS << "  RTLIB::Unsupported,";
+    } else {
       const RuntimeLibcallImpl *LibCallImpl = I->second;
       OS << "  ";
-      LibCallImpl->emitQuotedLibcallFuncName(OS);
-      OS << ',';
+      LibCallImpl->emitEnumEntry(OS);
+      OS << ",";
     }
 
     OS << " // ";
     LibCall.emitEnumEntry(OS);
     OS << '\n';
   }
 
-  OS << "  nullptr // RTLIB::UNKNOWN_LIBCALL\n"
+  OS << "  RTLIB::Unsupported\n"
         "};\n\n";
 
+  // Emit the implementation names
+  OS << "const char *const llvm::RTLIB::RuntimeLibcallsInfo::"
+        "LibCallImplNames[RTLIB::NumLibcallImpls] = {\n"
+        "  nullptr, // RTLIB::Unsupported\n";
+
+  for (const RuntimeLibcallImpl &LibCallImpl : RuntimeLibcallImplDefList) {
+    OS << "  \"" << LibCallImpl.getLibcallFuncName() << "\", // ";
+    LibCallImpl.emitEnumEntry(OS);
+    OS << '\n';
+  }
+
+  OS << "};\n\n";
+
+  // Emit the reverse mapping from implementation libraries to RTLIB::Libcall
+  OS << "const RTLIB::Libcall llvm::RTLIB::RuntimeLibcallsInfo::"
+        "ImplToLibcall[RTLIB::NumLibcallImpls] = {\n"
+        "  RTLIB::UNKNOWN_LIBCALL, // RTLIB::Unsupported\n";
+
+  for (const RuntimeLibcallImpl &LibCallImpl : RuntimeLibcallImplDefList) {
+    const RuntimeLibcall *Provides = LibCallImpl.getProvides();
+    OS << "  ";
+    Provides->emitEnumEntry(OS);
+    OS << ", // ";
+    LibCallImpl.emitEnumEntry(OS);
+    OS << '\n';
+  }
+  OS << "};\n\n";
----------------
arsenm wrote:

I have some later patches that use it, but I'm not sure they are posted yet. Right now it's used for avoiding the soft float compare type special case table, but eventually it will also be useful for libcall recognize 

https://github.com/llvm/llvm-project/pull/144973


More information about the llvm-branch-commits mailing list