1 //===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Devang Patel and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the LLVM Pass Manager infrastructure.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/PassManager.h"
16 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Support/Timer.h"
18 #include "llvm/Module.h"
19 #include "llvm/ModuleProvider.h"
20 #include "llvm/Support/Streams.h"
21 #include "llvm/Support/ManagedStatic.h"
26 class llvm::PMDataManager;
28 //===----------------------------------------------------------------------===//
30 // The Pass Manager Infrastructure manages passes. It's responsibilities are:
32 // o Manage optimization pass execution order
33 // o Make required Analysis information available before pass P is run
34 // o Release memory occupied by dead passes
35 // o If Analysis information is dirtied by a pass then regenerate Analysis
36 // information before it is consumed by another pass.
38 // Pass Manager Infrastructure uses multiple pass managers. They are
39 // PassManager, FunctionPassManager, ModulePassManager, BasicBlockPassManager.
40 // This class hierarcy uses multiple inheritance but pass managers do not derive
41 // from another pass manager.
43 // PassManager and FunctionPassManager are two top-level pass manager that
44 // represents the external interface of this entire pass manager infrastucture.
46 // Important classes :
48 // [o] class PMTopLevelManager;
50 // Two top level managers, PassManager and FunctionPassManager, derive from
51 // PMTopLevelManager. PMTopLevelManager manages information used by top level
52 // managers such as last user info.
54 // [o] class PMDataManager;
56 // PMDataManager manages information, e.g. list of available analysis info,
57 // used by a pass manager to manage execution order of passes. It also provides
58 // a place to implement common pass manager APIs. All pass managers derive from
61 // [o] class BasicBlockPassManager : public FunctionPass, public PMDataManager;
63 // BasicBlockPassManager manages BasicBlockPasses.
65 // [o] class FunctionPassManager;
67 // This is a external interface used by JIT to manage FunctionPasses. This
68 // interface relies on FunctionPassManagerImpl to do all the tasks.
70 // [o] class FunctionPassManagerImpl : public ModulePass, PMDataManager,
71 // public PMTopLevelManager;
73 // FunctionPassManagerImpl is a top level manager. It manages FunctionPasses
74 // and BasicBlockPassManagers.
76 // [o] class ModulePassManager : public Pass, public PMDataManager;
78 // ModulePassManager manages ModulePasses and FunctionPassManagerImpls.
80 // [o] class PassManager;
82 // This is a external interface used by various tools to manages passes. It
83 // relies on PassManagerImpl to do all the tasks.
85 // [o] class PassManagerImpl : public Pass, public PMDataManager,
86 // public PMDTopLevelManager
88 // PassManagerImpl is a top level pass manager responsible for managing
89 // ModulePassManagers.
90 //===----------------------------------------------------------------------===//
94 //===----------------------------------------------------------------------===//
95 // Pass debugging information. Often it is useful to find out what pass is
96 // running when a crash occurs in a utility. When this library is compiled with
97 // debugging on, a command line option (--debug-pass) is enabled that causes the
98 // pass name to be printed before it executes.
101 // Different debug levels that can be enabled...
102 enum PassDebugLevel {
103 None, Arguments, Structure, Executions, Details
106 static cl::opt<enum PassDebugLevel>
107 PassDebugging_New("debug-pass", cl::Hidden,
108 cl::desc("Print PassManager debugging information"),
110 clEnumVal(None , "disable debug output"),
111 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
112 clEnumVal(Structure , "print pass structure before run()"),
113 clEnumVal(Executions, "print pass name before it is executed"),
114 clEnumVal(Details , "print pass details when it is executed"),
116 } // End of llvm namespace
118 #ifndef USE_OLD_PASSMANAGER
121 //===----------------------------------------------------------------------===//
124 /// PMTopLevelManager manages LastUser info and collects common APIs used by
125 /// top level pass managers.
126 class VISIBILITY_HIDDEN PMTopLevelManager {
129 inline std::vector<Pass *>::iterator passManagersBegin() {
130 return PassManagers.begin();
133 inline std::vector<Pass *>::iterator passManagersEnd() {
134 return PassManagers.end();
137 /// Schedule pass P for execution. Make sure that passes required by
138 /// P are run before P is run. Update analysis info maintained by
139 /// the manager. Remove dead passes. This is a recursive function.
140 void schedulePass(Pass *P);
142 /// This is implemented by top level pass manager and used by
143 /// schedulePass() to add analysis info passes that are not available.
144 virtual void addTopLevelPass(Pass *P) = 0;
146 /// Set pass P as the last user of the given analysis passes.
147 void setLastUser(std::vector<Pass *> &AnalysisPasses, Pass *P);
149 /// Collect passes whose last user is P
150 void collectLastUses(std::vector<Pass *> &LastUses, Pass *P);
152 /// Find the pass that implements Analysis AID. Search immutable
153 /// passes and all pass managers. If desired pass is not found
154 /// then return NULL.
155 Pass *findAnalysisPass(AnalysisID AID);
157 inline void clearManagers() {
158 PassManagers.clear();
161 virtual ~PMTopLevelManager() {
162 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
163 E = PassManagers.end(); I != E; ++I)
166 for (std::vector<ImmutablePass *>::iterator
167 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
170 PassManagers.clear();
173 /// Add immutable pass and initialize it.
174 inline void addImmutablePass(ImmutablePass *P) {
176 ImmutablePasses.push_back(P);
179 inline std::vector<ImmutablePass *>& getImmutablePasses() {
180 return ImmutablePasses;
183 void addPassManager(Pass *Manager) {
184 PassManagers.push_back(Manager);
187 // Add Manager into the list of managers that are not directly
188 // maintained by this top level pass manager
189 inline void addIndirectPassManager(PMDataManager *Manager) {
190 IndirectPassManagers.push_back(Manager);
193 // Print passes managed by this top level manager.
194 void dumpPasses() const;
195 void dumpArguments() const;
199 /// Collection of pass managers
200 std::vector<Pass *> PassManagers;
202 /// Collection of pass managers that are not directly maintained
203 /// by this pass manager
204 std::vector<PMDataManager *> IndirectPassManagers;
206 // Map to keep track of last user of the analysis pass.
207 // LastUser->second is the last user of Lastuser->first.
208 std::map<Pass *, Pass *> LastUser;
210 /// Immutable passes are managed by top level manager.
211 std::vector<ImmutablePass *> ImmutablePasses;
214 } // End of anon namespace
216 //===----------------------------------------------------------------------===//
220 /// PMDataManager provides the common place to manage the analysis data
221 /// used by pass managers.
222 class PMDataManager {
224 PMDataManager(int D) : TPM(NULL), Depth(D) {
225 initializeAnalysisInfo();
228 virtual ~PMDataManager() {
230 for (std::vector<Pass *>::iterator I = PassVector.begin(),
231 E = PassVector.end(); I != E; ++I)
237 /// Return true IFF pass P's required analysis set does not required new
239 bool manageablePass(Pass *P);
241 /// Augment AvailableAnalysis by adding analysis made available by pass P.
242 void recordAvailableAnalysis(Pass *P);
244 /// Remove Analysis that is not preserved by the pass
245 void removeNotPreservedAnalysis(Pass *P);
247 /// Remove dead passes
248 void removeDeadPasses(Pass *P, std::string &Msg);
250 /// Add pass P into the PassVector. Update
251 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
252 void addPassToManager(Pass *P, bool ProcessAnalysis = true);
254 /// Initialize available analysis information.
255 void initializeAnalysisInfo() {
256 TransferLastUses.clear();
257 AvailableAnalysis.clear();
260 /// Populate RequiredPasses with the analysis pass that are required by
262 void collectRequiredAnalysisPasses(std::vector<Pass *> &RequiredPasses,
265 /// All Required analyses should be available to the pass as it runs! Here
266 /// we fill in the AnalysisImpls member of the pass so that it can
267 /// successfully use the getAnalysis() method to retrieve the
268 /// implementations it needs.
269 void initializeAnalysisImpl(Pass *P);
271 /// Find the pass that implements Analysis AID. If desired pass is not found
272 /// then return NULL.
273 Pass *findAnalysisPass(AnalysisID AID, bool Direction);
275 inline std::vector<Pass *>::iterator passVectorBegin() {
276 return PassVector.begin();
279 inline std::vector<Pass *>::iterator passVectorEnd() {
280 return PassVector.end();
283 // Access toplevel manager
284 PMTopLevelManager *getTopLevelManager() { return TPM; }
285 void setTopLevelManager(PMTopLevelManager *T) { TPM = T; }
287 unsigned getDepth() const { return Depth; }
289 // Print routines used by debug-pass
290 void dumpLastUses(Pass *P, unsigned Offset) const;
291 void dumpPassArguments() const;
292 void dumpPassInfo(Pass *P, std::string &Msg1, std::string &Msg2) const;
293 void dumpAnalysisSetInfo(const char *Msg, Pass *P,
294 const std::vector<AnalysisID> &Set) const;
296 std::vector<Pass *>& getTransferredLastUses() {
297 return TransferLastUses;
302 // If a FunctionPass F is the last user of ModulePass info M
303 // then the F's manager, not F, records itself as a last user of M.
304 // Current pass manage is requesting parent manager to record parent
305 // manager as the last user of these TrransferLastUses passes.
306 std::vector<Pass *> TransferLastUses;
308 // Top level manager.
309 PMTopLevelManager *TPM;
312 // Set of available Analysis. This information is used while scheduling
313 // pass. If a pass requires an analysis which is not not available then
314 // equired analysis pass is scheduled to run before the pass itself is
316 std::map<AnalysisID, Pass*> AvailableAnalysis;
318 // Collection of pass that are managed by this manager
319 std::vector<Pass *> PassVector;
324 //===----------------------------------------------------------------------===//
325 // BasicBlockPassManager
327 /// BasicBlockPassManager manages BasicBlockPass. It batches all the
328 /// pass together and sequence them to process one basic block before
329 /// processing next basic block.
330 class VISIBILITY_HIDDEN BasicBlockPassManager : public PMDataManager,
331 public FunctionPass {
334 BasicBlockPassManager(int D) : PMDataManager(D) { }
336 /// Add a pass into a passmanager queue.
337 bool addPass(Pass *p);
339 /// Execute all of the passes scheduled for execution. Keep track of
340 /// whether any of the passes modifies the function, and if so, return true.
341 bool runOnFunction(Function &F);
343 /// Pass Manager itself does not invalidate any analysis info.
344 void getAnalysisUsage(AnalysisUsage &Info) const {
345 Info.setPreservesAll();
348 bool doInitialization(Module &M);
349 bool doInitialization(Function &F);
350 bool doFinalization(Module &M);
351 bool doFinalization(Function &F);
353 // Print passes managed by this manager
354 void dumpPassStructure(unsigned Offset) {
355 llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
356 for (std::vector<Pass *>::iterator I = passVectorBegin(),
357 E = passVectorEnd(); I != E; ++I) {
358 (*I)->dumpPassStructure(Offset + 1);
359 dumpLastUses(*I, Offset+1);
364 //===----------------------------------------------------------------------===//
365 // FunctionPassManagerImpl_New
367 /// FunctionPassManagerImpl_New manages FunctionPasses and
368 /// BasicBlockPassManagers. It batches all function passes and basic block pass
369 /// managers together and sequence them to process one function at a time before
370 /// processing next function.
371 class FunctionPassManagerImpl_New : public ModulePass,
372 public PMDataManager,
373 public PMTopLevelManager {
375 FunctionPassManagerImpl_New(int D) : PMDataManager(D) {
376 activeBBPassManager = NULL;
378 ~FunctionPassManagerImpl_New() { /* TODO */ };
380 inline void addTopLevelPass(Pass *P) {
382 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
384 // P is a immutable pass then it will be managed by this
385 // top level manager. Set up analysis resolver to connect them.
386 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
388 initializeAnalysisImpl(P);
389 addImmutablePass(IP);
390 recordAvailableAnalysis(IP);
396 /// add - Add a pass to the queue of passes to run. This passes
397 /// ownership of the Pass to the PassManager. When the
398 /// PassManager_X is destroyed, the pass will be destroyed as well, so
399 /// there is no need to delete the pass. (TODO delete passes.)
400 /// This implies that all passes MUST be allocated with 'new'.
405 /// Add pass into the pass manager queue.
406 bool addPass(Pass *P);
408 /// Execute all of the passes scheduled for execution. Keep
409 /// track of whether any of the passes modifies the function, and if
411 bool runOnModule(Module &M);
412 bool runOnFunction(Function &F);
413 bool run(Function &F);
415 /// doInitialization - Run all of the initializers for the function passes.
417 bool doInitialization(Module &M);
419 /// doFinalization - Run all of the initializers for the function passes.
421 bool doFinalization(Module &M);
423 /// Pass Manager itself does not invalidate any analysis info.
424 void getAnalysisUsage(AnalysisUsage &Info) const {
425 Info.setPreservesAll();
428 // Print passes managed by this manager
429 void dumpPassStructure(unsigned Offset) {
430 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
431 for (std::vector<Pass *>::iterator I = passVectorBegin(),
432 E = passVectorEnd(); I != E; ++I) {
433 (*I)->dumpPassStructure(Offset + 1);
434 dumpLastUses(*I, Offset+1);
439 // Active Pass Managers
440 BasicBlockPassManager *activeBBPassManager;
443 //===----------------------------------------------------------------------===//
446 /// ModulePassManager manages ModulePasses and function pass managers.
447 /// It batches all Module passes passes and function pass managers together and
448 /// sequence them to process one module.
449 class ModulePassManager : public Pass, public PMDataManager {
452 ModulePassManager(int D) : PMDataManager(D) {
453 activeFunctionPassManager = NULL;
456 /// Add a pass into a passmanager queue.
457 bool addPass(Pass *p);
459 /// run - Execute all of the passes scheduled for execution. Keep track of
460 /// whether any of the passes modifies the module, and if so, return true.
461 bool runOnModule(Module &M);
463 /// Pass Manager itself does not invalidate any analysis info.
464 void getAnalysisUsage(AnalysisUsage &Info) const {
465 Info.setPreservesAll();
468 // Print passes managed by this manager
469 void dumpPassStructure(unsigned Offset) {
470 llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n";
471 for (std::vector<Pass *>::iterator I = passVectorBegin(),
472 E = passVectorEnd(); I != E; ++I) {
473 (*I)->dumpPassStructure(Offset + 1);
474 dumpLastUses(*I, Offset+1);
479 // Active Pass Manager
480 FunctionPassManagerImpl_New *activeFunctionPassManager;
483 //===----------------------------------------------------------------------===//
484 // PassManagerImpl_New
486 /// PassManagerImpl_New manages ModulePassManagers
487 class PassManagerImpl_New : public Pass,
488 public PMDataManager,
489 public PMTopLevelManager {
493 PassManagerImpl_New(int D) : PMDataManager(D) {
494 activeManager = NULL;
497 /// add - Add a pass to the queue of passes to run. This passes ownership of
498 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
499 /// will be destroyed as well, so there is no need to delete the pass. This
500 /// implies that all passes MUST be allocated with 'new'.
505 /// run - Execute all of the passes scheduled for execution. Keep track of
506 /// whether any of the passes modifies the module, and if so, return true.
509 /// Pass Manager itself does not invalidate any analysis info.
510 void getAnalysisUsage(AnalysisUsage &Info) const {
511 Info.setPreservesAll();
514 inline void addTopLevelPass(Pass *P) {
516 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
518 // P is a immutable pass and it will be managed by this
519 // top level manager. Set up analysis resolver to connect them.
520 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
522 initializeAnalysisImpl(P);
523 addImmutablePass(IP);
524 recordAvailableAnalysis(IP);
532 /// Add a pass into a passmanager queue.
533 bool addPass(Pass *p);
535 // Active Pass Manager
536 ModulePassManager *activeManager;
539 } // End of llvm namespace
543 //===----------------------------------------------------------------------===//
544 // TimingInfo Class - This class is used to calculate information about the
545 // amount of time each pass takes to execute. This only happens when
546 // -time-passes is enabled on the command line.
549 class VISIBILITY_HIDDEN TimingInfo {
550 std::map<Pass*, Timer> TimingData;
554 // Use 'create' member to get this.
555 TimingInfo() : TG("... Pass execution timing report ...") {}
557 // TimingDtor - Print out information about timing information
559 // Delete all of the timers...
561 // TimerGroup is deleted next, printing the report.
564 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
565 // to a non null value (if the -time-passes option is enabled) or it leaves it
566 // null. It may be called multiple times.
567 static void createTheTimeInfo();
569 void passStarted(Pass *P) {
571 if (dynamic_cast<PMDataManager *>(P))
574 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
575 if (I == TimingData.end())
576 I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
577 I->second.startTimer();
579 void passEnded(Pass *P) {
581 if (dynamic_cast<PMDataManager *>(P))
584 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
585 assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
586 I->second.stopTimer();
590 static TimingInfo *TheTimeInfo;
592 } // End of anon namespace
594 //===----------------------------------------------------------------------===//
595 // PMTopLevelManager implementation
597 /// Set pass P as the last user of the given analysis passes.
598 void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses,
601 for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(),
602 E = AnalysisPasses.end(); I != E; ++I) {
605 // If AP is the last user of other passes then make P last user of
607 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
608 LUE = LastUser.end(); LUI != LUE; ++LUI) {
609 if (LUI->second == AP)
610 LastUser[LUI->first] = P;
615 /// Collect passes whose last user is P
616 void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
618 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
619 LUE = LastUser.end(); LUI != LUE; ++LUI)
620 if (LUI->second == P)
621 LastUses.push_back(LUI->first);
624 /// Schedule pass P for execution. Make sure that passes required by
625 /// P are run before P is run. Update analysis info maintained by
626 /// the manager. Remove dead passes. This is a recursive function.
627 void PMTopLevelManager::schedulePass(Pass *P) {
629 // TODO : Allocate function manager for this pass, other wise required set
630 // may be inserted into previous function manager
632 AnalysisUsage AnUsage;
633 P->getAnalysisUsage(AnUsage);
634 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
635 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
636 E = RequiredSet.end(); I != E; ++I) {
638 Pass *AnalysisPass = findAnalysisPass(*I);
640 // Schedule this analysis run first.
641 AnalysisPass = (*I)->createPass();
642 schedulePass(AnalysisPass);
646 // Now all required passes are available.
650 /// Find the pass that implements Analysis AID. Search immutable
651 /// passes and all pass managers. If desired pass is not found
652 /// then return NULL.
653 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
656 // Check pass managers
657 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
658 E = PassManagers.end(); P == NULL && I != E; ++I) {
659 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
660 assert(PMD && "This is not a PassManager");
661 P = PMD->findAnalysisPass(AID, false);
664 // Check other pass managers
665 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
666 E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
667 P = (*I)->findAnalysisPass(AID, false);
669 for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
670 E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
671 const PassInfo *PI = (*I)->getPassInfo();
675 // If Pass not found then check the interfaces implemented by Immutable Pass
677 const std::vector<const PassInfo*> &ImmPI =
678 PI->getInterfacesImplemented();
679 for (unsigned Index = 0, End = ImmPI.size();
680 P == NULL && Index != End; ++Index)
681 if (ImmPI[Index] == AID)
689 // Print passes managed by this top level manager.
690 void PMTopLevelManager::dumpPasses() const {
692 // Print out the immutable passes
693 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
694 ImmutablePasses[i]->dumpPassStructure(0);
697 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
698 E = PassManagers.end(); I != E; ++I)
699 (*I)->dumpPassStructure(1);
702 void PMTopLevelManager::dumpArguments() const {
704 if (PassDebugging_New < Arguments)
707 cerr << "Pass Arguments: ";
708 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
709 E = PassManagers.end(); I != E; ++I) {
710 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
711 assert(PMD && "This is not a PassManager");
712 PMD->dumpPassArguments();
717 //===----------------------------------------------------------------------===//
718 // PMDataManager implementation
720 /// Return true IFF pass P's required analysis set does not required new
722 bool PMDataManager::manageablePass(Pass *P) {
725 // If this pass is not preserving information that is required by a
726 // pass maintained by higher level pass manager then do not insert
727 // this pass into current manager. Use new manager. For example,
728 // For example, If FunctionPass F is not preserving ModulePass Info M1
729 // that is used by another ModulePass M2 then do not insert F in
730 // current function pass manager.
734 /// Augement AvailableAnalysis by adding analysis made available by pass P.
735 void PMDataManager::recordAvailableAnalysis(Pass *P) {
737 if (const PassInfo *PI = P->getPassInfo()) {
738 AvailableAnalysis[PI] = P;
740 //This pass is the current implementation of all of the interfaces it
741 //implements as well.
742 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
743 for (unsigned i = 0, e = II.size(); i != e; ++i)
744 AvailableAnalysis[II[i]] = P;
748 /// Remove Analyss not preserved by Pass P
749 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
750 AnalysisUsage AnUsage;
751 P->getAnalysisUsage(AnUsage);
753 if (AnUsage.getPreservesAll())
756 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
757 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
758 E = AvailableAnalysis.end(); I != E; ) {
759 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) ==
760 PreservedSet.end()) {
761 // Remove this analysis
762 if (!dynamic_cast<ImmutablePass*>(I->second)) {
763 std::map<AnalysisID, Pass*>::iterator J = I++;
764 AvailableAnalysis.erase(J);
772 /// Remove analysis passes that are not used any longer
773 void PMDataManager::removeDeadPasses(Pass *P, std::string &Msg) {
775 std::vector<Pass *> DeadPasses;
776 TPM->collectLastUses(DeadPasses, P);
778 for (std::vector<Pass *>::iterator I = DeadPasses.begin(),
779 E = DeadPasses.end(); I != E; ++I) {
781 std::string Msg1 = " Freeing Pass '";
782 dumpPassInfo(*I, Msg1, Msg);
784 if (TheTimeInfo) TheTimeInfo->passStarted(P);
785 (*I)->releaseMemory();
786 if (TheTimeInfo) TheTimeInfo->passEnded(P);
788 std::map<AnalysisID, Pass*>::iterator Pos =
789 AvailableAnalysis.find((*I)->getPassInfo());
791 // It is possible that pass is already removed from the AvailableAnalysis
792 if (Pos != AvailableAnalysis.end())
793 AvailableAnalysis.erase(Pos);
797 /// Add pass P into the PassVector. Update
798 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
799 void PMDataManager::addPassToManager(Pass *P,
800 bool ProcessAnalysis) {
802 // This manager is going to manage pass P. Set up analysis resolver
804 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
807 if (ProcessAnalysis) {
809 // At the moment, this pass is the last user of all required passes.
810 std::vector<Pass *> LastUses;
811 std::vector<Pass *> RequiredPasses;
812 unsigned PDepth = this->getDepth();
814 collectRequiredAnalysisPasses(RequiredPasses, P);
815 for (std::vector<Pass *>::iterator I = RequiredPasses.begin(),
816 E = RequiredPasses.end(); I != E; ++I) {
817 Pass *PRequired = *I;
820 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
821 RDepth = DM.getDepth();
823 if (PDepth == RDepth)
824 LastUses.push_back(PRequired);
825 else if (PDepth > RDepth) {
826 // Let the parent claim responsibility of last use
827 TransferLastUses.push_back(PRequired);
829 // Note : This feature is not yet implemented
831 "Unable to handle Pass that requires lower level Analysis pass");
835 LastUses.push_back(P);
836 TPM->setLastUser(LastUses, P);
838 // Take a note of analysis required and made available by this pass.
839 // Remove the analysis not preserved by this pass
840 removeNotPreservedAnalysis(P);
841 recordAvailableAnalysis(P);
845 PassVector.push_back(P);
848 /// Populate RequiredPasses with the analysis pass that are required by
850 void PMDataManager::collectRequiredAnalysisPasses(std::vector<Pass *> &RP,
852 AnalysisUsage AnUsage;
853 P->getAnalysisUsage(AnUsage);
854 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
855 for (std::vector<AnalysisID>::const_iterator
856 I = RequiredSet.begin(), E = RequiredSet.end();
858 Pass *AnalysisPass = findAnalysisPass(*I, true);
859 assert (AnalysisPass && "Analysis pass is not available");
860 RP.push_back(AnalysisPass);
863 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
864 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
865 E = IDs.end(); I != E; ++I) {
866 Pass *AnalysisPass = findAnalysisPass(*I, true);
867 assert (AnalysisPass && "Analysis pass is not available");
868 RP.push_back(AnalysisPass);
872 // All Required analyses should be available to the pass as it runs! Here
873 // we fill in the AnalysisImpls member of the pass so that it can
874 // successfully use the getAnalysis() method to retrieve the
875 // implementations it needs.
877 void PMDataManager::initializeAnalysisImpl(Pass *P) {
878 AnalysisUsage AnUsage;
879 P->getAnalysisUsage(AnUsage);
881 for (std::vector<const PassInfo *>::const_iterator
882 I = AnUsage.getRequiredSet().begin(),
883 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
884 Pass *Impl = findAnalysisPass(*I, true);
886 assert(0 && "Analysis used but not available!");
887 AnalysisResolver_New *AR = P->getResolver();
888 AR->addAnalysisImplsPair(*I, Impl);
892 /// Find the pass that implements Analysis AID. If desired pass is not found
893 /// then return NULL.
894 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
896 // Check if AvailableAnalysis map has one entry.
897 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
899 if (I != AvailableAnalysis.end())
902 // Search Parents through TopLevelManager
904 return TPM->findAnalysisPass(AID);
909 // Print list of passes that are last used by P.
910 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
912 std::vector<Pass *> LUses;
914 assert (TPM && "Top Level Manager is missing");
915 TPM->collectLastUses(LUses, P);
917 for (std::vector<Pass *>::iterator I = LUses.begin(),
918 E = LUses.end(); I != E; ++I) {
919 llvm::cerr << "--" << std::string(Offset*2, ' ');
920 (*I)->dumpPassStructure(0);
924 void PMDataManager::dumpPassArguments() const {
925 for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
926 E = PassVector.end(); I != E; ++I) {
927 if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
928 PMD->dumpPassArguments();
930 if (const PassInfo *PI = (*I)->getPassInfo())
931 if (!PI->isAnalysisGroup())
932 cerr << " -" << PI->getPassArgument();
936 void PMDataManager:: dumpPassInfo(Pass *P, std::string &Msg1,
937 std::string &Msg2) const {
938 if (PassDebugging_New < Executions)
940 cerr << (void*)this << std::string(getDepth()*2+1, ' ');
942 cerr << P->getPassName();
946 void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
947 const std::vector<AnalysisID> &Set)
949 if (PassDebugging_New >= Details && !Set.empty()) {
950 cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
951 for (unsigned i = 0; i != Set.size(); ++i) {
953 cerr << " " << Set[i]->getPassName();
959 //===----------------------------------------------------------------------===//
960 // NOTE: Is this the right place to define this method ?
961 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
962 Pass *AnalysisResolver_New::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
963 return PM.findAnalysisPass(ID, dir);
966 //===----------------------------------------------------------------------===//
967 // BasicBlockPassManager implementation
969 /// Add pass P into PassVector and return true. If this pass is not
970 /// manageable by this manager then return false.
972 BasicBlockPassManager::addPass(Pass *P) {
974 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
978 // If this pass does not preserve anlysis that is used by other passes
979 // managed by this manager than it is not a suiable pass for this manager.
980 if (!manageablePass(P))
983 addPassToManager(BP);
988 /// Execute all of the passes scheduled for execution by invoking
989 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
990 /// the function, and if so, return true.
992 BasicBlockPassManager::runOnFunction(Function &F) {
997 bool Changed = doInitialization(F);
998 initializeAnalysisInfo();
1000 std::string Msg1 = "Executing Pass '";
1001 std::string Msg3 = "' Made Modification '";
1003 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
1004 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1005 e = passVectorEnd(); itr != e; ++itr) {
1007 AnalysisUsage AnUsage;
1008 P->getAnalysisUsage(AnUsage);
1010 std::string Msg2 = "' on BasicBlock '" + (*I).getName() + "'...\n";
1011 dumpPassInfo(P, Msg1, Msg2);
1012 dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet());
1014 initializeAnalysisImpl(P);
1016 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
1017 if (TheTimeInfo) TheTimeInfo->passStarted(P);
1018 Changed |= BP->runOnBasicBlock(*I);
1019 if (TheTimeInfo) TheTimeInfo->passEnded(P);
1022 dumpPassInfo(P, Msg3, Msg2);
1023 dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet());
1025 removeNotPreservedAnalysis(P);
1026 recordAvailableAnalysis(P);
1027 removeDeadPasses(P, Msg2);
1029 return Changed | doFinalization(F);
1032 // Implement doInitialization and doFinalization
1033 inline bool BasicBlockPassManager::doInitialization(Module &M) {
1034 bool Changed = false;
1036 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1037 e = passVectorEnd(); itr != e; ++itr) {
1039 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
1040 Changed |= BP->doInitialization(M);
1046 inline bool BasicBlockPassManager::doFinalization(Module &M) {
1047 bool Changed = false;
1049 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1050 e = passVectorEnd(); itr != e; ++itr) {
1052 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
1053 Changed |= BP->doFinalization(M);
1059 inline bool BasicBlockPassManager::doInitialization(Function &F) {
1060 bool Changed = false;
1062 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1063 e = passVectorEnd(); itr != e; ++itr) {
1065 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
1066 Changed |= BP->doInitialization(F);
1072 inline bool BasicBlockPassManager::doFinalization(Function &F) {
1073 bool Changed = false;
1075 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1076 e = passVectorEnd(); itr != e; ++itr) {
1078 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
1079 Changed |= BP->doFinalization(F);
1086 //===----------------------------------------------------------------------===//
1087 // FunctionPassManager implementation
1089 /// Create new Function pass manager
1090 FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
1091 FPM = new FunctionPassManagerImpl_New(0);
1092 // FPM is the top level manager.
1093 FPM->setTopLevelManager(FPM);
1095 PMDataManager *PMD = dynamic_cast<PMDataManager *>(FPM);
1096 AnalysisResolver_New *AR = new AnalysisResolver_New(*PMD);
1097 FPM->setResolver(AR);
1099 FPM->addPassManager(FPM);
1103 FunctionPassManager::~FunctionPassManager() {
1104 // Note : FPM maintains one entry in PassManagers vector.
1105 // This one entry is FPM itself. This is not ideal. One
1106 // alternative is have one additional layer between
1107 // FunctionPassManager and FunctionPassManagerImpl.
1108 // Meanwhile, to avoid going into infinte loop, first
1109 // remove FPM from its PassMangers vector.
1110 FPM->clearManagers();
1114 /// add - Add a pass to the queue of passes to run. This passes
1115 /// ownership of the Pass to the PassManager. When the
1116 /// PassManager_X is destroyed, the pass will be destroyed as well, so
1117 /// there is no need to delete the pass. (TODO delete passes.)
1118 /// This implies that all passes MUST be allocated with 'new'.
1119 void FunctionPassManager::add(Pass *P) {
1123 /// run - Execute all of the passes scheduled for execution. Keep
1124 /// track of whether any of the passes modifies the function, and if
1125 /// so, return true.
1127 bool FunctionPassManager::run(Function &F) {
1129 if (MP->materializeFunction(&F, &errstr)) {
1130 cerr << "Error reading bytecode file: " << errstr << "\n";
1137 /// doInitialization - Run all of the initializers for the function passes.
1139 bool FunctionPassManager::doInitialization() {
1140 return FPM->doInitialization(*MP->getModule());
1143 /// doFinalization - Run all of the initializers for the function passes.
1145 bool FunctionPassManager::doFinalization() {
1146 return FPM->doFinalization(*MP->getModule());
1149 //===----------------------------------------------------------------------===//
1150 // FunctionPassManagerImpl_New implementation
1152 /// Add pass P into the pass manager queue. If P is a BasicBlockPass then
1153 /// either use it into active basic block pass manager or create new basic
1154 /// block pass manager to handle pass P.
1156 FunctionPassManagerImpl_New::addPass(Pass *P) {
1158 // If P is a BasicBlockPass then use BasicBlockPassManager.
1159 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
1161 if (!activeBBPassManager || !activeBBPassManager->addPass(BP)) {
1163 // If active manager exists then clear its analysis info.
1164 if (activeBBPassManager)
1165 activeBBPassManager->initializeAnalysisInfo();
1167 // Create and add new manager
1168 activeBBPassManager =
1169 new BasicBlockPassManager(getDepth() + 1);
1170 // Inherit top level manager
1171 activeBBPassManager->setTopLevelManager(this->getTopLevelManager());
1173 // Add new manager into current manager's list.
1174 addPassToManager(activeBBPassManager, false);
1176 // Add new manager into top level manager's indirect passes list
1177 PMDataManager *PMD = dynamic_cast<PMDataManager *>(activeBBPassManager);
1178 assert (PMD && "Manager is not Pass Manager");
1179 TPM->addIndirectPassManager(PMD);
1181 // Add pass into new manager. This time it must succeed.
1182 if (!activeBBPassManager->addPass(BP))
1183 assert(0 && "Unable to add Pass");
1185 // If activeBBPassManager transfered any Last Uses then handle them here.
1186 std::vector<Pass *> &TLU = activeBBPassManager->getTransferredLastUses();
1188 TPM->setLastUser(TLU, this);
1196 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
1200 // If this pass does not preserve anlysis that is used by other passes
1201 // managed by this manager than it is not a suiable pass for this manager.
1202 if (!manageablePass(P))
1205 addPassToManager (FP);
1207 // If active manager exists then clear its analysis info.
1208 if (activeBBPassManager) {
1209 activeBBPassManager->initializeAnalysisInfo();
1210 activeBBPassManager = NULL;
1216 /// Execute all of the passes scheduled for execution by invoking
1217 /// runOnFunction method. Keep track of whether any of the passes modifies
1218 /// the function, and if so, return true.
1219 bool FunctionPassManagerImpl_New::runOnModule(Module &M) {
1221 bool Changed = doInitialization(M);
1222 initializeAnalysisInfo();
1224 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1225 this->runOnFunction(*I);
1227 return Changed | doFinalization(M);
1230 /// Execute all of the passes scheduled for execution by invoking
1231 /// runOnFunction method. Keep track of whether any of the passes modifies
1232 /// the function, and if so, return true.
1233 bool FunctionPassManagerImpl_New::runOnFunction(Function &F) {
1235 bool Changed = false;
1240 initializeAnalysisInfo();
1242 std::string Msg1 = "Executing Pass '";
1243 std::string Msg3 = "' Made Modification '";
1245 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1246 e = passVectorEnd(); itr != e; ++itr) {
1248 AnalysisUsage AnUsage;
1249 P->getAnalysisUsage(AnUsage);
1251 std::string Msg2 = "' on Function '" + F.getName() + "'...\n";
1252 dumpPassInfo(P, Msg1, Msg2);
1253 dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet());
1255 initializeAnalysisImpl(P);
1256 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
1258 if (TheTimeInfo) TheTimeInfo->passStarted(P);
1259 Changed |= FP->runOnFunction(F);
1260 if (TheTimeInfo) TheTimeInfo->passEnded(P);
1263 dumpPassInfo(P, Msg3, Msg2);
1264 dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet());
1266 removeNotPreservedAnalysis(P);
1267 recordAvailableAnalysis(P);
1268 removeDeadPasses(P, Msg2);
1274 inline bool FunctionPassManagerImpl_New::doInitialization(Module &M) {
1275 bool Changed = false;
1277 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1278 e = passVectorEnd(); itr != e; ++itr) {
1281 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
1282 Changed |= FP->doInitialization(M);
1288 inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) {
1289 bool Changed = false;
1291 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1292 e = passVectorEnd(); itr != e; ++itr) {
1295 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
1296 Changed |= FP->doFinalization(M);
1302 // Execute all the passes managed by this top level manager.
1303 // Return true if any function is modified by a pass.
1304 bool FunctionPassManagerImpl_New::run(Function &F) {
1306 bool Changed = false;
1307 for (std::vector<Pass *>::iterator I = passManagersBegin(),
1308 E = passManagersEnd(); I != E; ++I) {
1309 FunctionPassManagerImpl_New *FP =
1310 dynamic_cast<FunctionPassManagerImpl_New *>(*I);
1311 Changed |= FP->runOnFunction(F);
1316 //===----------------------------------------------------------------------===//
1317 // ModulePassManager implementation
1319 /// Add P into pass vector if it is manageble. If P is a FunctionPass
1320 /// then use FunctionPassManagerImpl_New to manage it. Return false if P
1321 /// is not manageable by this manager.
1323 ModulePassManager::addPass(Pass *P) {
1325 // If P is FunctionPass then use function pass maanager.
1326 if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
1328 if (!activeFunctionPassManager || !activeFunctionPassManager->addPass(P)) {
1330 // If active manager exists then clear its analysis info.
1331 if (activeFunctionPassManager)
1332 activeFunctionPassManager->initializeAnalysisInfo();
1334 // Create and add new manager
1335 activeFunctionPassManager =
1336 new FunctionPassManagerImpl_New(getDepth() + 1);
1338 // Add new manager into current manager's list
1339 addPassToManager(activeFunctionPassManager, false);
1341 // Inherit top level manager
1342 activeFunctionPassManager->setTopLevelManager(this->getTopLevelManager());
1344 // Add new manager into top level manager's indirect passes list
1345 PMDataManager *PMD =
1346 dynamic_cast<PMDataManager *>(activeFunctionPassManager);
1347 assert(PMD && "Manager is not Pass Manager");
1348 TPM->addIndirectPassManager(PMD);
1350 // Add pass into new manager. This time it must succeed.
1351 if (!activeFunctionPassManager->addPass(FP))
1352 assert(0 && "Unable to add pass");
1354 // If activeFunctionPassManager transfered any Last Uses then
1355 // handle them here.
1356 std::vector<Pass *> &TLU =
1357 activeFunctionPassManager->getTransferredLastUses();
1359 TPM->setLastUser(TLU, this);
1365 ModulePass *MP = dynamic_cast<ModulePass *>(P);
1369 // If this pass does not preserve anlysis that is used by other passes
1370 // managed by this manager than it is not a suiable pass for this manager.
1371 if (!manageablePass(P))
1374 addPassToManager(MP);
1375 // If active manager exists then clear its analysis info.
1376 if (activeFunctionPassManager) {
1377 activeFunctionPassManager->initializeAnalysisInfo();
1378 activeFunctionPassManager = NULL;
1385 /// Execute all of the passes scheduled for execution by invoking
1386 /// runOnModule method. Keep track of whether any of the passes modifies
1387 /// the module, and if so, return true.
1389 ModulePassManager::runOnModule(Module &M) {
1390 bool Changed = false;
1391 initializeAnalysisInfo();
1393 std::string Msg1 = "Executing Pass '";
1394 std::string Msg3 = "' Made Modification '";
1396 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
1397 e = passVectorEnd(); itr != e; ++itr) {
1399 AnalysisUsage AnUsage;
1400 P->getAnalysisUsage(AnUsage);
1402 std::string Msg2 = "' on Module '" + M.getModuleIdentifier() + "'...\n";
1403 dumpPassInfo(P, Msg1, Msg2);
1404 dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet());
1406 initializeAnalysisImpl(P);
1407 ModulePass *MP = dynamic_cast<ModulePass*>(P);
1409 if (TheTimeInfo) TheTimeInfo->passStarted(P);
1410 Changed |= MP->runOnModule(M);
1411 if (TheTimeInfo) TheTimeInfo->passEnded(P);
1414 dumpPassInfo(P, Msg3, Msg2);
1415 dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet());
1417 removeNotPreservedAnalysis(P);
1418 recordAvailableAnalysis(P);
1419 removeDeadPasses(P, Msg2);
1424 //===----------------------------------------------------------------------===//
1425 // PassManagerImpl implementation
1427 /// Add P into active pass manager or use new module pass manager to
1429 bool PassManagerImpl_New::addPass(Pass *P) {
1431 if (!activeManager || !activeManager->addPass(P)) {
1432 activeManager = new ModulePassManager(getDepth() + 1);
1433 // Inherit top level manager
1434 activeManager->setTopLevelManager(this->getTopLevelManager());
1436 // This top level manager is going to manage activeManager.
1437 // Set up analysis resolver to connect them.
1438 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
1439 activeManager->setResolver(AR);
1441 addPassManager(activeManager);
1442 return activeManager->addPass(P);
1447 /// run - Execute all of the passes scheduled for execution. Keep track of
1448 /// whether any of the passes modifies the module, and if so, return true.
1449 bool PassManagerImpl_New::run(Module &M) {
1451 bool Changed = false;
1453 TimingInfo::createTheTimeInfo();
1456 if (PassDebugging_New >= Structure)
1459 for (std::vector<Pass *>::iterator I = passManagersBegin(),
1460 E = passManagersEnd(); I != E; ++I) {
1461 ModulePassManager *MP = dynamic_cast<ModulePassManager *>(*I);
1462 Changed |= MP->runOnModule(M);
1467 //===----------------------------------------------------------------------===//
1468 // PassManager implementation
1470 /// Create new pass manager
1471 PassManager::PassManager() {
1472 PM = new PassManagerImpl_New(0);
1473 // PM is the top level manager
1474 PM->setTopLevelManager(PM);
1477 PassManager::~PassManager() {
1481 /// add - Add a pass to the queue of passes to run. This passes ownership of
1482 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
1483 /// will be destroyed as well, so there is no need to delete the pass. This
1484 /// implies that all passes MUST be allocated with 'new'.
1486 PassManager::add(Pass *P) {
1490 /// run - Execute all of the passes scheduled for execution. Keep track of
1491 /// whether any of the passes modifies the module, and if so, return true.
1493 PassManager::run(Module &M) {
1497 //===----------------------------------------------------------------------===//
1498 // TimingInfo Class - This class is used to calculate information about the
1499 // amount of time each pass takes to execute. This only happens with
1500 // -time-passes is enabled on the command line.
1502 bool llvm::TimePassesIsEnabled = false;
1503 static cl::opt<bool,true>
1504 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1505 cl::desc("Time each pass, printing elapsed time for each on exit"));
1507 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1508 // a non null value (if the -time-passes option is enabled) or it leaves it
1509 // null. It may be called multiple times.
1510 void TimingInfo::createTheTimeInfo() {
1511 if (!TimePassesIsEnabled || TheTimeInfo) return;
1513 // Constructed the first time this is called, iff -time-passes is enabled.
1514 // This guarantees that the object will be constructed before static globals,
1515 // thus it will be destroyed before them.
1516 static ManagedStatic<TimingInfo> TTI;
1517 TheTimeInfo = &*TTI;