[llvm] [Analysis] Add DebugInfoCache analysis (PR #118629)
Artem Pianykh via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 13:57:29 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();
----------------
artempyanykh wrote:
Great question! I could use help/guidance here, @felipepiovezan. IIUC passes that _may formally_ change the module won't necessarily invalidate the analysis:
* changing globals, enum types, imported entities in a CU [would invalidate it](https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/DebugInfo.cpp#L226-L254)
* adding/removing CUs would too.
However, I'm not sure what's the proper way to express this here.
https://github.com/llvm/llvm-project/pull/118629
More information about the llvm-commits
mailing list