Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:42

0001 //===- CallGraphUpdater.h - A (lazy) call graph update helper ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 /// \file
0009 ///
0010 /// This file provides interfaces used to manipulate a call graph, regardless
0011 /// if it is a "old style" CallGraph or an "new style" LazyCallGraph.
0012 ///
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_TRANSFORMS_UTILS_CALLGRAPHUPDATER_H
0016 #define LLVM_TRANSFORMS_UTILS_CALLGRAPHUPDATER_H
0017 
0018 #include "llvm/Analysis/CGSCCPassManager.h"
0019 #include "llvm/Analysis/LazyCallGraph.h"
0020 
0021 namespace llvm {
0022 
0023 class CallGraph;
0024 class CallGraphSCC;
0025 
0026 /// Wrapper to unify "old style" CallGraph and "new style" LazyCallGraph. This
0027 /// simplifies the interface and the call sites, e.g., new and old pass manager
0028 /// passes can share the same code.
0029 class CallGraphUpdater {
0030   /// Containers for functions which we did replace or want to delete when
0031   /// `finalize` is called. This can happen explicitly or as part of the
0032   /// destructor. Dead functions in comdat sections are tracked separately
0033   /// because a function with discardable linakage in a COMDAT should only
0034   /// be dropped if the entire COMDAT is dropped, see git ac07703842cf.
0035   ///{
0036   SmallPtrSet<Function *, 16> ReplacedFunctions;
0037   SmallVector<Function *, 16> DeadFunctions;
0038   SmallVector<Function *, 16> DeadFunctionsInComdats;
0039   ///}
0040 
0041   /// New PM variables
0042   ///{
0043   LazyCallGraph *LCG = nullptr;
0044   LazyCallGraph::SCC *SCC = nullptr;
0045   CGSCCAnalysisManager *AM = nullptr;
0046   CGSCCUpdateResult *UR = nullptr;
0047   FunctionAnalysisManager *FAM = nullptr;
0048   ///}
0049 
0050 public:
0051   CallGraphUpdater() = default;
0052   ~CallGraphUpdater() { finalize(); }
0053 
0054   /// Initializers for usage outside of a CGSCC pass, inside a CGSCC pass in
0055   /// the old and new pass manager (PM).
0056   ///{
0057   void initialize(LazyCallGraph &LCG, LazyCallGraph::SCC &SCC,
0058                   CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR) {
0059     this->LCG = &LCG;
0060     this->SCC = &SCC;
0061     this->AM = &AM;
0062     this->UR = &UR;
0063     FAM =
0064         &AM.getResult<FunctionAnalysisManagerCGSCCProxy>(SCC, LCG).getManager();
0065   }
0066   ///}
0067 
0068   /// Finalizer that will trigger actions like function removal from the CG.
0069   bool finalize();
0070 
0071   /// Remove \p Fn from the call graph.
0072   void removeFunction(Function &Fn);
0073 
0074   /// After an CGSCC pass changes a function in ways that affect the call
0075   /// graph, this method can be called to update it.
0076   void reanalyzeFunction(Function &Fn);
0077 
0078   /// If a new function was created by outlining, this method can be called
0079   /// to update the call graph for the new function. Note that the old one
0080   /// still needs to be re-analyzed or manually updated.
0081   void registerOutlinedFunction(Function &OriginalFn, Function &NewFn);
0082 
0083   /// Replace \p OldFn in the call graph (and SCC) with \p NewFn. The uses
0084   /// outside the call graph and the function \p OldFn are not modified.
0085   /// Note that \p OldFn is also removed from the call graph
0086   /// (\see removeFunction).
0087   void replaceFunctionWith(Function &OldFn, Function &NewFn);
0088 };
0089 
0090 } // end namespace llvm
0091 
0092 #endif // LLVM_TRANSFORMS_UTILS_CALLGRAPHUPDATER_H