1//===- LegacyPassManagers.h - Legacy Pass Infrastructure --------*- C++ -*-===// 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 7//===----------------------------------------------------------------------===// 9// This file declares the LLVM Pass Manager infrastructure. 11//===----------------------------------------------------------------------===// 13#ifndef LLVM_IR_LEGACYPASSMANAGERS_H 14#define LLVM_IR_LEGACYPASSMANAGERS_H 23//===----------------------------------------------------------------------===// 25// The Pass Manager Infrastructure manages passes. It's responsibilities are: 27// o Manage optimization pass execution order 28// o Make required Analysis information available before pass P is run 29// o Release memory occupied by dead passes 30// o If Analysis information is dirtied by a pass then regenerate Analysis 31// information before it is consumed by another pass. 33// Pass Manager Infrastructure uses multiple pass managers. They are 34// PassManager, FunctionPassManager, MPPassManager, FPPassManager, BBPassManager. 35// This class hierarchy uses multiple inheritance but pass managers do not 36// derive from another pass manager. 38// PassManager and FunctionPassManager are two top-level pass manager that 39// represents the external interface of this entire pass manager infrastucture. 43// [o] class PMTopLevelManager; 45// Two top level managers, PassManager and FunctionPassManager, derive from 46// PMTopLevelManager. PMTopLevelManager manages information used by top level 47// managers such as last user info. 49// [o] class PMDataManager; 51// PMDataManager manages information, e.g. list of available analysis info, 52// used by a pass manager to manage execution order of passes. It also provides 53// a place to implement common pass manager APIs. All pass managers derive from 56// [o] class FunctionPassManager; 58// This is a external interface used to manage FunctionPasses. This 59// interface relies on FunctionPassManagerImpl to do all the tasks. 61// [o] class FunctionPassManagerImpl : public ModulePass, PMDataManager, 62// public PMTopLevelManager; 64// FunctionPassManagerImpl is a top level manager. It manages FPPassManagers 66// [o] class FPPassManager : public ModulePass, public PMDataManager; 68// FPPassManager manages FunctionPasses and BBPassManagers 70// [o] class MPPassManager : public Pass, public PMDataManager; 72// MPPassManager manages ModulePasses and FPPassManagers 74// [o] class PassManager; 76// This is a external interface used by various tools to manages passes. It 77// relies on PassManagerImpl to do all the tasks. 79// [o] class PassManagerImpl : public Pass, public PMDataManager, 80// public PMTopLevelManager 82// PassManagerImpl is a top level pass manager responsible for managing 84//===----------------------------------------------------------------------===// 95// enums for debugging strings 104ON_CG_MSG// "' on Call Graph Nodes '" + Msg + "'...\n'" 107/// PassManagerPrettyStackEntry - This is used to print informative information 108/// about what pass is running when/if a stack trace is generated. 116 :
P(p), V(nullptr), M(nullptr) {}
// When P is releaseMemory'd. 118 :
P(p), V(&v), M(nullptr) {}
// When P is run on V 120 :
P(p), V(nullptr), M(&m) {}
// When P is run on M 122 /// print - Emit information about this stack frame to OS. 126//===----------------------------------------------------------------------===// 129/// PMStack - This class implements a stack data structure of PMDataManager 132/// Top level pass managers (see PassManager.cpp) maintain active Pass Managers 133/// using PMStack. Each Pass implements assignPassManager() to connect itself 134/// with appropriate manager. assignPassManager() walks PMStack to find 138typedef std::vector<PMDataManager *>::const_reverse_iterator
iterator;
145boolempty()
const{
return S.empty(); }
150 std::vector<PMDataManager *> S;
153//===----------------------------------------------------------------------===// 156/// PMTopLevelManager manages LastUser info and collects common APIs used by 157/// top level pass managers. 173 /// Schedule pass P for execution. Make sure that passes required by 174 /// P are run before P is run. Update analysis info maintained by 175 /// the manager. Remove dead passes. This is a recursive function. 178 /// Set pass P as the last user of the given analysis passes. 181 /// Collect passes whose last user is P 184 /// Find the pass that implements Analysis AID. Search immutable 185 /// passes and all pass managers. If desired pass is not found 186 /// then return NULL. 189 /// Retrieve the PassInfo for an analysis. 192 /// Find analysis usage information for the pass P. 197 /// Add immutable pass and initialize it. 201return ImmutablePasses;
208// Add Manager into the list of managers that are not directly 209// maintained by this top level pass manager 211 IndirectPassManagers.push_back(Manager);
214// Print passes managed by this top level manager. 218// Active Pass Managers 222 /// Collection of pass managers 226 /// Collection of pass managers that are not directly maintained 227 /// by this pass manager 230// Map to keep track of last user of the analysis pass. 231// LastUser->second is the last user of Lastuser->first. 232// This is kept in sync with InversedLastUser. 235// Map to keep track of passes that are last used by a pass. 236// This is kept in sync with LastUser. 239 /// Immutable passes are managed by top level manager. 242 /// Map from ID to immutable passes. 246 /// A wrapper around AnalysisUsage for the purpose of uniqueing. The wrapper 247 /// is used to avoid needing to make AnalysisUsage itself a folding set node. 255// TODO: We could consider sorting the dependency arrays within the 256// AnalysisUsage (since they are conceptually unordered). 259ID.AddInteger(Vec.size());
270// Contains all of the unique combinations of AnalysisUsage. This is helpful 271// when we have multiple instances of the same pass since they'll usually 272// have the same analysis usage and can share storage. 275// Allocator used for allocating UAFoldingSetNodes. This handles deletion of 276// all allocated nodes in one fell swoop. 279// Maps from a pass to it's associated entry in UniqueAnalysisUsages. Does 280// not own the storage associated with either key or value.. 283 /// Collection of PassInfo objects found via analysis IDs and in this top 284 /// level manager. This is used to memoize queries to the pass registry. 285 /// FIXME: This is an egregious hack because querying the pass registry is 286 /// either slow or racy. 290//===----------------------------------------------------------------------===// 293/// PMDataManager provides the common place to manage the analysis data 294/// used by pass managers. 303 /// Augment AvailableAnalysis by adding analysis made available by pass P. 306 /// verifyPreservedAnalysis -- Verify analysis presreved by pass P. 309 /// Remove Analysis that is not preserved by the pass 312 /// Remove dead passes used by P. 320 /// Add pass P into the PassVector. Update 321 /// AvailableAnalysis appropriately if ProcessAnalysis is true. 322voidadd(
Pass *
P,
bool ProcessAnalysis =
true);
324 /// Add RequiredPass into list of lower level passes required by pass P. 325 /// RequiredPass is run on the fly by Pass Manager when P requests it 326 /// through getAnalysis interface. 332 /// Initialize available analysis information. 334 AvailableAnalysis.clear();
339// Return true if P preserves high level analysis used by other 340// passes that are managed by this manager. 343 /// Populate UsedPasses with analysis pass that are used or required by pass 344 /// P and are available. Populate ReqPassNotAvailable with analysis pass that 345 /// are required by pass P but are not available. 350 /// All Required analyses should be available to the pass as it runs! Here 351 /// we fill in the AnalysisImpls member of the pass so that it can 352 /// successfully use the getAnalysis() method to retrieve the 353 /// implementations it needs. 356 /// Find the pass that implements Analysis AID. If desired pass is not found 357 /// then return NULL. 360// Access toplevel manager 365voidsetDepth(
unsigned newDepth) { Depth = newDepth; }
367// Print routines used by debug-pass 381assert ( 0 &&
"Invalid use of getPassManagerType");
386return &AvailableAnalysis;
389// Collect AvailableAnalysis from all the active Pass Managers. 396 /// Set the initial size of the module if the user has specified that they 397 /// want remarks for size. 398 /// Returns 0 if the remark was not requested. 401StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount);
403 /// Emit a remark signifying that the number of IR instructions in the module 405 /// \p F is optionally passed by passes which run on Functions, and thus 406 /// always know whether or not a non-empty function is available. 408 /// \p FunctionToInstrCount maps the name of a \p Function to a pair. The 409 /// first member of the pair is the IR count of the \p Function before running 410 /// \p P, and the second member is the IR count of the \p Function after 413Pass *
P,
Module &M, int64_t Delta,
unsigned CountBefore,
414StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount,
421// Collection of pass that are managed by this manager 424// Collection of Analysis provided by Parent pass manager and 425// used by current pass manager. At any time there can not be more 426// then PMT_Last active pass managers. 429 /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions 430 /// or higher is specified. 437// Set of available Analysis. This information is used while scheduling 438// pass. If a pass requires an analysis which is not available then 439// the required analysis pass is scheduled to run before the pass itself is 443// Collection of higher level analysis used by the pass managed by 450//===----------------------------------------------------------------------===// 453/// FPPassManager manages BBPassManagers and FunctionPasses. 454/// It batches all function passes and basic block pass managers together and 455/// sequence them to process one function at a time before processing next 462 /// run - Execute all of the passes scheduled for execution. Keep track of 463 /// whether any of the passes modifies the module, and if so, return true. 467 /// cleanup - After running all passes, clean up pass manager cache. 470 /// doInitialization - Overrides ModulePass doInitialization for global 471 /// initialization tasks 475 /// doInitialization - Run all of the initializers for the function passes. 479 /// doFinalization - Overrides ModulePass doFinalization for global 480 /// finalization tasks 484 /// doFinalization - Run all of the finalizers for the function passes. 491 /// Pass Manager itself does not invalidate any analysis info. 493Info.setPreservesAll();
496// Print passes managed by this manager Analysis containing CSE Info
This file defines the DenseMap class.
This file defines a hash set that can be used to remove duplication of nodes in a graph.
Loop::LoopBounds::Direction Direction
Machine Check Debug Module
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
const VectorType & getRequiredSet() const
const VectorType & getRequiredTransitiveSet() const
const VectorType & getUsedSet() const
bool getPreservesAll() const
Determine whether a pass said it does not transform its input at all.
const VectorType & getPreservedSet() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
FPPassManager manages BBPassManagers and FunctionPasses.
bool runOnFunction(Function &F)
run - Execute all of the passes scheduled for execution.
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
FunctionPass * getContainedPass(unsigned N)
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Pass * getAsPass() override
PassManagerType getPassManagerType() const override
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
PMDataManager * getAsPMDataManager() override
void cleanup()
cleanup - After running all passes, clean up pass manager cache.
Node - This class is used to maintain the singly linked bucket list in a folding set.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
FunctionPass class - This class is used to implement most global optimizations.
ImmutablePass class - This class is used to provide information that does not need to be run.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
PMDataManager provides the common place to manage the analysis data used by pass managers.
void dumpPassArguments() const
void removeDeadPasses(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove dead passes used by P.
void dumpLastUses(Pass *P, unsigned Offset) const
virtual Pass * getAsPass()=0
virtual std::tuple< Pass *, bool > getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F)
void setDepth(unsigned newDepth)
void recordAvailableAnalysis(Pass *P)
Augment AvailableAnalysis by adding analysis made available by pass P.
Pass * findAnalysisPass(AnalysisID AID, bool Direction)
Find the pass that implements Analysis AID.
bool isPassDebuggingExecutionsOrMore() const
isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions or higher is specified.
unsigned getDepth() const
SmallVector< Pass *, 16 > PassVector
DenseMap< AnalysisID, Pass * > * InheritedAnalysis[PMT_Last]
virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass)
Add RequiredPass into list of lower level passes required by pass P.
PMTopLevelManager * getTopLevelManager()
unsigned initSizeRemarkInfo(Module &M, StringMap< std::pair< unsigned, unsigned > > &FunctionToInstrCount)
Set the initial size of the module if the user has specified that they want remarks for size.
void setTopLevelManager(PMTopLevelManager *T)
void dumpRequiredSet(const Pass *P) const
void initializeAnalysisImpl(Pass *P)
All Required analyses should be available to the pass as it runs! Here we fill in the AnalysisImpls m...
void verifyPreservedAnalysis(Pass *P)
verifyPreservedAnalysis – Verify analysis presreved by pass P.
void initializeAnalysisInfo()
Initialize available analysis information.
void freePass(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove P.
bool preserveHigherLevelAnalysis(Pass *P)
unsigned getNumContainedPasses() const
virtual PassManagerType getPassManagerType() const
void emitInstrCountChangedRemark(Pass *P, Module &M, int64_t Delta, unsigned CountBefore, StringMap< std::pair< unsigned, unsigned > > &FunctionToInstrCount, Function *F=nullptr)
Emit a remark signifying that the number of IR instructions in the module changed.
void add(Pass *P, bool ProcessAnalysis=true)
Add pass P into the PassVector.
DenseMap< AnalysisID, Pass * > * getAvailableAnalysis()
void collectRequiredAndUsedAnalyses(SmallVectorImpl< Pass * > &UsedPasses, SmallVectorImpl< AnalysisID > &ReqPassNotAvailable, Pass *P)
Populate UsedPasses with analysis pass that are used or required by pass P and are available.
void populateInheritedAnalysis(PMStack &PMS)
void dumpPreservedSet(const Pass *P) const
void dumpUsedSet(const Pass *P) const
void removeNotPreservedAnalysis(Pass *P)
Remove Analysis that is not preserved by the pass.
void dumpPassInfo(Pass *P, enum PassDebuggingString S1, enum PassDebuggingString S2, StringRef Msg)
PMStack - This class implements a stack data structure of PMDataManager pointers.
std::vector< PMDataManager * >::const_reverse_iterator iterator
PMDataManager * top() const
void push(PMDataManager *PM)
PMTopLevelManager manages LastUser info and collects common APIs used by top level pass managers.
void addIndirectPassManager(PMDataManager *Manager)
void addImmutablePass(ImmutablePass *P)
Add immutable pass and initialize it.
const PassInfo * findAnalysisPassInfo(AnalysisID AID) const
Retrieve the PassInfo for an analysis.
void setLastUser(ArrayRef< Pass * > AnalysisPasses, Pass *P)
Set pass P as the last user of the given analysis passes.
virtual ~PMTopLevelManager()
Destructor.
void schedulePass(Pass *P)
Schedule pass P for execution.
SmallVector< PMDataManager *, 8 > PassManagers
Collection of pass managers.
Pass * findAnalysisPass(AnalysisID AID)
Find the pass that implements Analysis AID.
void dumpArguments() const
AnalysisUsage * findAnalysisUsage(Pass *P)
Find analysis usage information for the pass P.
void addPassManager(PMDataManager *Manager)
unsigned getNumContainedManagers() const
void initializeAllAnalysisInfo()
SmallVectorImpl< ImmutablePass * > & getImmutablePasses()
void collectLastUses(SmallVectorImpl< Pass * > &LastUses, Pass *P)
Collect passes whose last user is P.
PassInfo class - An instance of this class exists for every pass known by the system,...
PassManagerPrettyStackEntry - This is used to print informative information about what pass is runnin...
PassManagerPrettyStackEntry(Pass *p, Value &v)
void print(raw_ostream &OS) const override
print - Emit information about this stack frame to OS.
PassManagerPrettyStackEntry(Pass *p)
PassManagerPrettyStackEntry(Pass *p, Module &m)
Pass interface - Implemented by all 'passes'.
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
PrettyStackTraceEntry - This class is used to represent a frame of the "pretty" stack trace that is d...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
PassManagerType
Different types of internal pass managers.
@ PMT_FunctionPassManager
FPPassManager.
ArrayRef(const T &OneElt) -> ArrayRef< T >