PassManager.h revision e89f1c4ee74349fbe08a2c1f8060a7d3b049b5ab
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===- llvm/PassManager.h - Container for Passes ----------------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the PassManager class. This class is used to hold, 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// maintain, and optimize execution of Passes. The PassManager class ensures 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// that analysis results are available before a pass runs, and that Pass's are 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// destroyed when the PassManager is destroyed. 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 16a4ae2294b6ebfb2554aacb6a6a0682fb5ed1f276Peter Collingbourne 174c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall#ifndef LLVM_PASSMANAGER_H 183f2af1002249c8acc9ce17f1fc50324864feb8e1Eli Friedman#define LLVM_PASSMANAGER_H 19f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Pass.h" 2131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner 22de7fb8413b13651fd85b7125d08b3c9ac2816d9dDaniel Dunbarnamespace llvm { 23c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar 242b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlssonclass Pass; 256a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stumpclass ModulePass; 267255a2d997b15beae82e627052fdb1b2474495c2Chris Lattnerclass Module; 274e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 287255a2d997b15beae82e627052fdb1b2474495c2Chris Lattnerclass PassManagerImpl; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionPassManagerImpl; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// PassManagerBase - An abstract interface to allow code to add passes to 321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a pass manager without having to hard-code what kind of pass manager 335936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall/// it is. 34bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregorclass PassManagerBase { 35f85e193739c953358c865005855253af4f68a497John McCallpublic: 36777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall virtual ~PassManagerBase(); 37777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall 3893c332a8ba2c193c435b293966d343dab15f555bJohn McCall /// add - Add a pass to the queue of passes to run. This passes ownership of 3993c332a8ba2c193c435b293966d343dab15f555bJohn McCall /// the Pass to the PassManager. When the PassManager is destroyed, the pass 402504941793b549323f9d29c62507cf21d865fadeJohn McCall /// will be destroyed as well, so there is no need to delete the pass. This 41150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// implies that all passes MUST be allocated with 'new'. 4283252dcfe61aaebcb6bc117e71dc12968729513fChris Lattner virtual void add(Pass *P) = 0; 43c1cfdf8647a499b6b3024f4bd14a236cddb23988Anders Carlsson}; 449c276ae0f24d4cee8f7954069d4b8eae45d0447dMike Stump 454c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall/// PassManager manages ModulePassManagers 464111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattnerclass PassManager : public PassManagerBase { 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 499cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner PassManager(); 508b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar ~PassManager(); 518b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar 528b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar /// add - Add a pass to the queue of passes to run. This passes ownership of 539cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner /// the Pass to the PassManager. When the PassManager is destroyed, the pass 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// will be destroyed as well, so there is no need to delete the pass. This 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// implies that all passes MUST be allocated with 'new'. 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void add(Pass *P); 57f2aac84709c418189e476ad591848dad50291885John McCall 58f2aac84709c418189e476ad591848dad50291885John McCall /// run - Execute all of the passes scheduled for execution. Keep track of 59f2aac84709c418189e476ad591848dad50291885John McCall /// whether any of the passes modifies the module, and if so, return true. 60f2aac84709c418189e476ad591848dad50291885John McCall bool run(Module &M); 61f2aac84709c418189e476ad591848dad50291885John McCall 62f2aac84709c418189e476ad591848dad50291885John McCallprivate: 63f2aac84709c418189e476ad591848dad50291885John McCall /// addImpl - Add a pass to the queue of passes to run, without 64f2aac84709c418189e476ad591848dad50291885John McCall /// checking whether to add a printer pass. 65f2aac84709c418189e476ad591848dad50291885John McCall void addImpl(Pass *P); 66f2aac84709c418189e476ad591848dad50291885John McCall 67f2aac84709c418189e476ad591848dad50291885John McCall /// PassManagerImpl_New is the actual class. PassManager is just the 68f2aac84709c418189e476ad591848dad50291885John McCall /// wraper to publish simple pass manager interface 69f2aac84709c418189e476ad591848dad50291885John McCall PassManagerImpl *PM; 70f2aac84709c418189e476ad591848dad50291885John McCall}; 71f2aac84709c418189e476ad591848dad50291885John McCall 72f2aac84709c418189e476ad591848dad50291885John McCall/// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers. 73f2aac84709c418189e476ad591848dad50291885John McCallclass FunctionPassManager : public PassManagerBase { 74f2aac84709c418189e476ad591848dad50291885John McCallpublic: 75f2aac84709c418189e476ad591848dad50291885John McCall /// FunctionPassManager ctor - This initializes the pass manager. It needs, 76f2aac84709c418189e476ad591848dad50291885John McCall /// but does not take ownership of, the specified Module. 77f2aac84709c418189e476ad591848dad50291885John McCall explicit FunctionPassManager(Module *M); 78f2aac84709c418189e476ad591848dad50291885John McCall ~FunctionPassManager(); 79f2aac84709c418189e476ad591848dad50291885John McCall 80f2aac84709c418189e476ad591848dad50291885John McCall /// add - Add a pass to the queue of passes to run. This passes 81f2aac84709c418189e476ad591848dad50291885John McCall /// ownership of the Pass to the PassManager. When the 82f2aac84709c418189e476ad591848dad50291885John McCall /// PassManager_X is destroyed, the pass will be destroyed as well, so 83f2aac84709c418189e476ad591848dad50291885John McCall /// there is no need to delete the pass. (TODO delete passes.) 84f2aac84709c418189e476ad591848dad50291885John McCall /// This implies that all passes MUST be allocated with 'new'. 85f2aac84709c418189e476ad591848dad50291885John McCall void add(Pass *P); 86f2aac84709c418189e476ad591848dad50291885John McCall 87f2aac84709c418189e476ad591848dad50291885John McCall /// run - Execute all of the passes scheduled for execution. Keep 88f2aac84709c418189e476ad591848dad50291885John McCall /// track of whether any of the passes modifies the function, and if 89f2aac84709c418189e476ad591848dad50291885John McCall /// so, return true. 90f2aac84709c418189e476ad591848dad50291885John McCall /// 91f2aac84709c418189e476ad591848dad50291885John McCall bool run(Function &F); 924111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 93391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner /// doInitialization - Run all of the initializers for the function passes. 941c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar /// 951c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar bool doInitialization(); 961c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar 971c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar /// doFinalization - Run all of the finalizers for the function passes. 981c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar /// 991c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar bool doFinalization(); 1001c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar 1011c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbarprivate: 10296e18b05ea6b55aa92a1a576f29e9cee73a7e20bDaniel Dunbar /// addImpl - Add a pass to the queue of passes to run, without 10396e18b05ea6b55aa92a1a576f29e9cee73a7e20bDaniel Dunbar /// checking whether to add a printer pass. 104ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void addImpl(Pass *P); 105ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 106ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall FunctionPassManagerImpl *FPM; 10796e18b05ea6b55aa92a1a576f29e9cee73a7e20bDaniel Dunbar Module *M; 108ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall}; 1091c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar 1101c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar} // End llvm namespace 1111c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar 1121c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar#endif 1131c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar