[llvm] [Analysis] Add DebugInfoCache analysis (PR #118629)

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 30 10:22:17 PST 2025


================
@@ -0,0 +1,47 @@
+//===- llvm/Analysis/DebugInfoCache.cpp - debug info cache ----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains an analysis that builds a cache of debug info for each
+// DICompileUnit in a module.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/DebugInfoCache.h"
+#include "llvm/IR/Module.h"
+
+using namespace llvm;
+
+namespace {
+DebugInfoFinder processCompileUnit(DICompileUnit *CU) {
+  DebugInfoFinder DIFinder;
+  DIFinder.processCompileUnit(CU);
+
+  return DIFinder;
+}
+} // namespace
+
+DebugInfoCache::DebugInfoCache(const Module &M) {
+  for (const auto CU : M.debug_compile_units()) {
+    auto DIFinder = processCompileUnit(CU);
+    Result[CU] = std::move(DIFinder);
+  }
+}
+
+bool DebugInfoCache::invalidate(Module &M, const PreservedAnalyses &PA,
+                                ModuleAnalysisManager::Invalidator &) {
+  // Check whether the analysis has been explicitly invalidated. Otherwise, it's
+  // stateless and remains preserved.
+  auto PAC = PA.getChecker<DebugInfoCacheAnalysis>();
+  return !PAC.preservedWhenStateless();
----------------
felipepiovezan wrote:

Reading the docs in https://llvm.org/docs/NewPassManager.html#implementing-analysis-invalidation

What you wrote seems to say that your analysis is only invalidated when explicitly invalidated, which is certainly not true (see "If an analysis is stateless and generally shouldn’t be invalidated, use the following:"). Your analysis is invalidated whenever debug metadata is changed/added/removed.

I think we should simply not implement this method, which implies the analysis is invalidated whenever the module changes.

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


More information about the llvm-commits mailing list