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

Mingming Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 13 18:11:27 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());
+  }
----------------
mingmingl-llvm wrote:

As I understand it, a vtable's (call it `_ZTV3foo`) RTTI is preserved if any class that appears higher up in the inheritance tree relative to `_ZTV3foo` has its RTTI used by non vtables (e.g., captured by dynamic_cast https://gcc.godbolt.org/z/nq4dT385j).

Would you mind adding some comments here for this case and also a regression test?

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


More information about the cfe-commits mailing list