1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- llvm/PassManager.h - Container for Passes ----------------*- C++ -*-===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file defines the PassManager class. This class is used to hold, 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// maintain, and optimize execution of Passes. The PassManager class ensures 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// that analysis results are available before a pass runs, and that Pass's are 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// destroyed when the PassManager is destroyed. 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_PASSMANAGER_H 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_PASSMANAGER_H 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Pass.h" 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass Pass; 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass Module; 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass PassManagerImpl; 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass FunctionPassManagerImpl; 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// PassManagerBase - An abstract interface to allow code to add passes to 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// a pass manager without having to hard-code what kind of pass manager 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// it is. 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass PassManagerBase { 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic: 35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman virtual ~PassManagerBase(); 36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// add - Add a pass to the queue of passes to run. This passes ownership of 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// the Pass to the PassManager. When the PassManager is destroyed, the pass 39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// will be destroyed as well, so there is no need to delete the pass. This 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// implies that all passes MUST be allocated with 'new'. 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman virtual void add(Pass *P) = 0; 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}; 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// PassManager manages ModulePassManagers 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass PassManager : public PassManagerBase { 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic: 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman PassManager(); 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ~PassManager(); 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// add - Add a pass to the queue of passes to run. This passes ownership of 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// the Pass to the PassManager. When the PassManager is destroyed, the pass 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// will be destroyed as well, so there is no need to delete the pass. This 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// implies that all passes MUST be allocated with 'new'. 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void add(Pass *P); 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// run - Execute all of the passes scheduled for execution. Keep track of 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// whether any of the passes modifies the module, and if so, return true. 59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool run(Module &M); 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanprivate: 62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// addImpl - Add a pass to the queue of passes to run, without 63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// checking whether to add a printer pass. 64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void addImpl(Pass *P); 65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// PassManagerImpl_New is the actual class. PassManager is just the 67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// wraper to publish simple pass manager interface 68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman PassManagerImpl *PM; 69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}; 70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers. 72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass FunctionPassManager : public PassManagerBase { 73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic: 74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// FunctionPassManager ctor - This initializes the pass manager. It needs, 75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// but does not take ownership of, the specified Module. 76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman explicit FunctionPassManager(Module *M); 77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ~FunctionPassManager(); 78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// add - Add a pass to the queue of passes to run. This passes 80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// ownership of the Pass to the PassManager. When the 81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// PassManager_X is destroyed, the pass will be destroyed as well, so 82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// there is no need to delete the pass. (TODO delete passes.) 83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// This implies that all passes MUST be allocated with 'new'. 84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void add(Pass *P); 85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// run - Execute all of the passes scheduled for execution. Keep 87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// track of whether any of the passes modifies the function, and if 88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// so, return true. 89894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool run(Function &F); 91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// doInitialization - Run all of the initializers for the function passes. 93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool doInitialization(); 95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// doFinalization - Run all of the finalizers for the function passes. 97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool doFinalization(); 99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanprivate: 101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// addImpl - Add a pass to the queue of passes to run, without 102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// checking whether to add a printer pass. 103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void addImpl(Pass *P); 104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman FunctionPassManagerImpl *FPM; 106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Module *M; 107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}; 108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // End llvm namespace 110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif 112