[clang] [llvm] [ThinLTO] Support dead RTTI data elimination under -fno-split-lto-unit (PR #126336)

Teresa Johnson via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 11:01:51 PST 2025


================
@@ -0,0 +1,49 @@
+#include "llvm/Transforms/IPO/DeadRTTIElimination.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/IR/ModuleSummaryIndex.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/LibCXXABI.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "dre"
+
+STATISTIC(NumDeadTypeInfo, "Number of dead type info global variable");
+
+void DeadRTTIElimIndex::run() {
+  if (!ABI)
+    return;
+
+  if (ExportSummary.typeIdCompatibleVtableMap().empty())
+    return;
+
+  DenseSet<StringRef> TypeIdSlotMayLiveVTables;
+
+  const auto &UsedTypeIds = ExportSummary.getTypeIdAccessed();
+  for (StringRef TypeId : UsedTypeIds) {
+    auto Info = ExportSummary.getTypeIdCompatibleVtableSummary(TypeId);
+
+    if (!Info.has_value())
+      continue;
+
+    for (auto CompatibleVTable : *Info)
+      TypeIdSlotMayLiveVTables.insert(CompatibleVTable.VTableVI.name());
+  }
+
+  for (auto &VI : ExportSummary) {
+    StringRef GVSName = VI.second.U.Name;
+    if (!ABI->isVTable(GVSName) ||
+        TypeIdSlotMayLiveVTables.contains(GVSName) ||
+        VI.second.SummaryList.empty())
+      continue;
+
+    auto *GVS = dyn_cast<GlobalVarSummary>(VI.second.SummaryList[0].get());
+    if (GVS &&
+        GVS->getVCallVisibility() == llvm::GlobalObject::VCallVisibilityPublic)
+      continue;
+
+    ++NumDeadTypeInfo;
+    for (auto &SL : VI.second.SummaryList)
+      SL->eraseRef(ABI->getTypeInfoFromVTable(GVSName));
----------------
teresajohnson wrote:

I don't love removing references from the Index. Can this handling just be incorporated into computeDeadSymbolsWithConstProp?

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


More information about the cfe-commits mailing list