LLVM 24.0.0git
CallGraphUpdater.h
Go to the documentation of this file.
1//===- CallGraphUpdater.h - A (lazy) call graph update helper ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file provides interfaces used to manipulate a call graph, regardless
11/// if it is a "old style" CallGraph or an "new style" LazyCallGraph.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_UTILS_CALLGRAPHUPDATER_H
16#define LLVM_TRANSFORMS_UTILS_CALLGRAPHUPDATER_H
17
21
22namespace llvm {
23
24class CallGraph;
25
26/// Wrapper to unify "old style" CallGraph and "new style" LazyCallGraph. This
27/// simplifies the interface and the call sites, e.g., new and old pass manager
28/// passes can share the same code.
30 /// Containers for functions which we did replace or want to delete when
31 /// `finalize` is called. This can happen explicitly or as part of the
32 /// destructor. Dead functions in comdat sections are tracked separately
33 /// because a function with discardable linakage in a COMDAT should only
34 /// be dropped if the entire COMDAT is dropped, see git ac07703842cf.
35 ///{
36 SmallPtrSet<Function *, 16> ReplacedFunctions;
37 SmallVector<Function *, 16> DeadFunctions;
38 SmallVector<Function *, 16> DeadFunctionsInComdats;
39 ///}
40
41 /// New PM variables
42 ///{
43 LazyCallGraph *LCG = nullptr;
44 LazyCallGraph::SCC *SCC = nullptr;
45 CGSCCAnalysisManager *AM = nullptr;
46 CGSCCUpdateResult *UR = nullptr;
47 FunctionAnalysisManager *FAM = nullptr;
48 ///}
49
50public:
51 CallGraphUpdater() = default;
53
54 /// Initializers for usage outside of a CGSCC pass, inside a CGSCC pass in
55 /// the old and new pass manager (PM).
56 ///{
59 this->LCG = &LCG;
60 this->SCC = &SCC;
61 this->AM = &AM;
62 this->UR = &UR;
63 FAM =
64 &AM.getResult<FunctionAnalysisManagerCGSCCProxy>(SCC, LCG).getManager();
65 }
66
67 void initialize(FunctionAnalysisManager &FAM) { this->FAM = &FAM; }
68 ///}
69
70 /// Finalizer that will trigger actions like function removal from the CG.
71 LLVM_ABI bool finalize();
72
73 /// Remove \p Fn from the call graph.
75
76 /// After an CGSCC pass changes a function in ways that affect the call
77 /// graph, this method can be called to update it.
79
80 /// Add reference edges from \p Fn to the functions referenced by \p C, which
81 /// is newly used in \p Fn. Adding them before reanalyzing any function keeps
82 /// them trivial if another function drops the same references.
84
85 /// If a new function was created by outlining, this method can be called
86 /// to update the call graph for the new function. Note that the old one
87 /// still needs to be re-analyzed or manually updated.
88 LLVM_ABI void registerOutlinedFunction(Function &OriginalFn, Function &NewFn);
89
90 /// Replace \p OldFn in the call graph (and SCC) with \p NewFn. The uses
91 /// outside the call graph and the function \p OldFn are not modified.
92 /// Note that \p OldFn is also removed from the call graph
93 /// (\see removeFunction).
94 LLVM_ABI void replaceFunctionWith(Function &OldFn, Function &NewFn);
95};
96
97} // end namespace llvm
98
99#endif // LLVM_TRANSFORMS_UTILS_CALLGRAPHUPDATER_H
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This header provides classes for managing passes over SCCs of the call graph.
#define LLVM_ABI
Definition Compiler.h:211
Implements a lazy call graph analysis and related passes for the new pass manager.
LLVM_ABI void registerOutlinedFunction(Function &OriginalFn, Function &NewFn)
If a new function was created by outlining, this method can be called to update the call graph for th...
LLVM_ABI void addReferences(Function &Fn, Constant &C)
Add reference edges from Fn to the functions referenced by C, which is newly used in Fn.
LLVM_ABI void removeFunction(Function &Fn)
Remove Fn from the call graph.
LLVM_ABI void replaceFunctionWith(Function &OldFn, Function &NewFn)
Replace OldFn in the call graph (and SCC) with NewFn.
LLVM_ABI void reanalyzeFunction(Function &Fn)
After an CGSCC pass changes a function in ways that affect the call graph, this method can be called ...
void initialize(FunctionAnalysisManager &FAM)
void initialize(LazyCallGraph &LCG, LazyCallGraph::SCC &SCC, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR)
Initializers for usage outside of a CGSCC pass, inside a CGSCC pass in the old and new pass manager (...
CallGraphUpdater()=default
}
The basic data container for the call graph of a Module of IR.
Definition CallGraph.h:72
This is an important base class in LLVM.
Definition Constant.h:44
A proxy from a FunctionAnalysisManager to an SCC.
An SCC of the call graph.
A lazily constructed view of the call graph of a module.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...