llvm.org GIT mirror llvm / 1465d61
Rename getAnalysisToUpdate to getAnalysisIfAvailable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63198 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 11 years ago
29 changed file(s) with 88 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
610610 Mikhail Glushenkov
611611 LLVM Compiler Infrastructure
612612
613 Last modified: $Date: 2008-12-11 11:34:48 -0600 (Thu, 11 Dec 2008) $
613 Last modified: $Date$
614614
615615
616616
7777
  • The AnalysisUsage::addRequired<> and AnalysisUsage::addRequiredTransitive<> methods
  • 7878
  • The AnalysisUsage::addPreserved<> method
  • 7979
  • Example implementations of getAnalysisUsage
  • 80
  • The getAnalysis<> and getAnalysisToUpdate<> methods
  • 80
  • The getAnalysis<> and
  • 81 getAnalysisIfAvailable<> methods
    8182
    8283
  • Implementing Analysis Groups
  • 8384
    11301131
    11311132
    11321133
    1133 The getAnalysis<> and getAnalysisToUpdate<> methods
    1134 The getAnalysis<> and
    1135 getAnalysisIfAvailable<> methods
    11341136
    11351137
    11361138
    11721174

    11731175 If your pass is capable of updating analyses if they exist (e.g.,
    11741176 BreakCriticalEdges, as described above), you can use the
    1175 getAnalysisToUpdate method, which returns a pointer to the analysis if
    1176 it is active. For example:

    1177 getAnalysisIfAvailable method, which returns a pointer to the analysis
    1178 if it is active. For example:

    11771179
    11781180
    
                      
                    
    11791181 ...
    1180 if (DominatorSet *DS = getAnalysisToUpdate<DominatorSet>()) {
    1182 if (DominatorSet *DS = getAnalysisIfAvailable<DominatorSet>()) {
    11811183 // A DominatorSet is active. This code will update it.
    11821184 }
    11831185 ...
    168168 // or null if it is not known.
    169169 static const PassInfo *lookupPassInfo(intptr_t TI);
    170170
    171 /// getAnalysisToUpdate() - This function is used by subclasses
    172 /// to get to the analysis information that might be around that needs to be
    173 /// updated. This is different than getAnalysis in that it can fail (ie the
    174 /// analysis results haven't been computed), so should only be used if you
    175 /// provide the capability to update an analysis that exists. This method is
    176 /// often used by transformation APIs to update analysis results for a pass
    177 /// automatically as the transform is performed.
    178 ///
    179 template
    180 AnalysisType *getAnalysisToUpdate() const; // Defined in PassAnalysisSupport.h
    171 /// getAnalysisIfAvailable() - Subclasses use this function to
    172 /// get analysis information that might be around, for example to update it.
    173 /// This is different than getAnalysis in that it can fail (if the analysis
    174 /// results haven't been computed), so should only be used if you can handle
    175 /// the case when the analysis is not available. This method is often used by
    176 /// transformation APIs to update analysis results for a pass automatically as
    177 /// the transform is performed.
    178 ///
    179 template AnalysisType *
    180 getAnalysisIfAvailable() const; // Defined in PassAnalysisSupport.h
    181181
    182182 /// mustPreserveAnalysisID - This method serves the same function as
    183 /// getAnalysisToUpdate, but works if you just have an AnalysisID. This
    183 /// getAnalysisIfAvailable, but works if you just have an AnalysisID. This
    184184 /// obviously cannot give you a properly typed instance of the class if you
    185 /// don't have the class name available (use getAnalysisToUpdate if you do),
    186 /// but it can tell you if you need to preserve the pass at least.
    185 /// don't have the class name available (use getAnalysisIfAvailable if you
    186 /// do), but it can tell you if you need to preserve the pass at least.
    187187 ///
    188188 bool mustPreserveAnalysisID(const PassInfo *AnalysisID) const;
    189189
    142142 AnalysisImpls.push_back(pir);
    143143 }
    144144
    145 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
    146 Pass *getAnalysisToUpdate(AnalysisID ID, bool Direction) const;
    145 // getAnalysisIfAvailable - Return analysis result or null if it doesn't exist
    146 Pass *getAnalysisIfAvailable(AnalysisID ID, bool Direction) const;
    147147
    148148 // AnalysisImpls - This keeps track of which passes implements the interfaces
    149149 // that are required by the current pass (to implement getAnalysis()).
    156156 PMDataManager &PM;
    157157 };
    158158
    159 /// getAnalysisToUpdate() - This function is used by subclasses
    160 /// to get to the analysis information that might be around that needs to be
    161 /// updated. This is different than getAnalysis in that it can fail (ie the
    162 /// analysis results haven't been computed), so should only be used if you
    163 /// provide the capability to update an analysis that exists. This method is
    164 /// often used by transformation APIs to update analysis results for a pass
    165 /// automatically as the transform is performed.
    159 /// getAnalysisIfAvailable() - Subclasses use this function to
    160 /// get analysis information that might be around, for example to update it.
    161 /// This is different than getAnalysis in that it can fail (if the analysis
    162 /// results haven't been computed), so should only be used if you can handle
    163 /// the case when the analysis is not available. This method is often used by
    164 /// transformation APIs to update analysis results for a pass automatically as
    165 /// the transform is performed.
    166166 ///
    167167 template
    168 AnalysisType *Pass::getAnalysisToUpdate() const {
    168 AnalysisType *Pass::getAnalysisIfAvailable() const {
    169169 assert(Resolver && "Pass not resident in a PassManager object!");
    170170
    171171 const PassInfo *PI = getClassPassInfo();
    172172 if (PI == 0) return 0;
    173173 return dynamic_cast
    174 (Resolver->getAnalysisToUpdate(PI, true));
    174 (Resolver->getAnalysisIfAvailable(PI, true));
    175175 }
    176176
    177177 /// getAnalysis() - This function is used by subclasses to get
    140140 bool AsmPrinter::doInitialization(Module &M) {
    141141 Mang = new Mangler(M, TAI->getGlobalPrefix(), TAI->getPrivateGlobalPrefix());
    142142
    143 GCModuleInfo *MI = getAnalysisToUpdate();
    143 GCModuleInfo *MI = getAnalysisIfAvailable();
    144144 assert(MI && "AsmPrinter didn't require GCModuleInfo?");
    145145
    146146 if (TAI->hasSingleParameterDotFile()) {
    162162
    163163 SwitchToDataSection(""); // Reset back to no section.
    164164
    165 MachineModuleInfo *MMI = getAnalysisToUpdate();
    165 MachineModuleInfo *MMI = getAnalysisIfAvailable();
    166166 if (MMI) MMI->AnalyzeModule(M);
    167 DW = getAnalysisToUpdate();
    167 DW = getAnalysisIfAvailable();
    168168 return false;
    169169 }
    170170
    217217 }
    218218 }
    219219
    220 GCModuleInfo *MI = getAnalysisToUpdate();
    220 GCModuleInfo *MI = getAnalysisIfAvailable();
    221221 assert(MI && "AsmPrinter didn't require GCModuleInfo?");
    222222 for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
    223223 if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
    197197
    198198 RS = RegInfo->requiresRegisterScavenging(MF) ? new RegScavenger() : NULL;
    199199
    200 MMI = getAnalysisToUpdate();
    200 MMI = getAnalysisIfAvailable();
    201201
    202202 bool MadeChangeThisIteration = true;
    203203 while (MadeChangeThisIteration) {
    204204 }
    205205
    206206 bool Deleter::doFinalization(Module &M) {
    207 GCModuleInfo *GMI = getAnalysisToUpdate();
    207 GCModuleInfo *GMI = getAnalysisIfAvailable();
    208208 assert(GMI && "Deleter didn't require GCModuleInfo?!");
    209209 GMI->clear();
    210210 return false;
    143143 // work against the entire module. But this cannot be done at
    144144 // runFunction time (initializeCustomLowering likely needs to change
    145145 // the module).
    146 GCModuleInfo *MI = getAnalysisToUpdate();
    146 GCModuleInfo *MI = getAnalysisIfAvailable();
    147147 assert(MI && "LowerIntrinsics didn't require GCModuleInfo!?");
    148148 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
    149149 if (!I->isDeclaration() && I->hasGC())
    319319
    320320 bool DebugLabelFolder::runOnMachineFunction(MachineFunction &MF) {
    321321 // Get machine module info.
    322 MachineModuleInfo *MMI = getAnalysisToUpdate();
    322 MachineModuleInfo *MMI = getAnalysisIfAvailable();
    323323 if (!MMI) return false;
    324324
    325325 // Track if change is made.
    173173 }
    174174
    175175 // Update live variable information if there is any.
    176 LiveVariables *LV = getAnalysisToUpdate();
    176 LiveVariables *LV = getAnalysisIfAvailable();
    177177 if (LV) {
    178178 MachineInstr *PHICopy = prior(AfterPHIsIt);
    179179
    5555
    5656 // Get MachineModuleInfo so that we can track the construction of the
    5757 // frame.
    58 if (MachineModuleInfo *MMI = getAnalysisToUpdate())
    58 if (MachineModuleInfo *MMI = getAnalysisIfAvailable())
    5959 Fn.getFrameInfo()->setMachineModuleInfo(MMI);
    6060
    6161 // Allow the target machine to make some adjustments to the function
    313313 DOUT << "\n\n\n=== " << Fn.getName() << "\n";
    314314
    315315 FuncInfo->set(Fn, *MF, EnableFastISel);
    316 MachineModuleInfo *MMI = getAnalysisToUpdate();
    317 DwarfWriter *DW = getAnalysisToUpdate>();
    316 MachineModuleInfo *MMI = getAnalysisIfAvailable>();
    317 DwarfWriter *DW = getAnalysisIfAvailable();
    318318 CurDAG->init(*MF, MMI, DW);
    319319 SDL->init(GFI, *AA);
    320320
    378378 MRI = &MF.getRegInfo();
    379379 TII = TM.getInstrInfo();
    380380 TRI = TM.getRegisterInfo();
    381 LV = getAnalysisToUpdate();
    381 LV = getAnalysisIfAvailable();
    382382
    383383 bool MadeChange = false;
    384384
    104104 bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
    105105 SmallPtrSet Reachable;
    106106
    107 MMI = getAnalysisToUpdate();
    107 MMI = getAnalysisIfAvailable();
    108108
    109109 // Mark all reachable blocks.
    110110 for (df_ext_iterator >
    781781 bool Result = AsmPrinter::doInitialization(M);
    782782
    783783 // Emit initial debug information.
    784 MMI = getAnalysisToUpdate();
    784 MMI = getAnalysisIfAvailable();
    785785 assert(MMI);
    786 DW = getAnalysisToUpdate();
    786 DW = getAnalysisIfAvailable();
    787787 assert(DW && "Dwarf Writer is not available");
    788788 DW->BeginModule(&M, MMI, O, this, TAI);
    789789
    490490 bool Result = AsmPrinter::doInitialization(M);
    491491 SwitchToTextSection("\t.text");
    492492 // Emit initial debug information.
    493 DW = getAnalysisToUpdate();
    493 DW = getAnalysisIfAvailable();
    494494 assert(DW && "Dwarf Writer is not available");
    495 MMI = getAnalysisToUpdate();
    495 MMI = getAnalysisIfAvailable();
    496496 DW->BeginModule(&M, MMI, O, this, TAI);
    497497 return Result;
    498498 }
    640640 bool Result = AsmPrinter::doInitialization(M);
    641641
    642642 // Emit initial debug information.
    643 MMI = getAnalysisToUpdate();
    643 MMI = getAnalysisIfAvailable();
    644644 assert(MMI);
    645 DW = getAnalysisToUpdate();
    645 DW = getAnalysisIfAvailable();
    646646 assert(DW && "DwarfWriter is not available");
    647647 DW->BeginModule(&M, MMI, O, this, TAI);
    648648
    858858 // Emit initial debug information.
    859859 // We need this for Personality functions.
    860860 // AsmPrinter::doInitialization should have done this analysis.
    861 MMI = getAnalysisToUpdate();
    861 MMI = getAnalysisIfAvailable();
    862862 assert(MMI);
    863 DW = getAnalysisToUpdate();
    863 DW = getAnalysisIfAvailable();
    864864 assert(DW && "DwarfWriter is not available");
    865865 DW->BeginModule(&M, MMI, O, this, TAI);
    866866
    736736 // Let PassManager know we need debug information and relay
    737737 // the MachineModuleInfo address on to DwarfWriter.
    738738 // AsmPrinter::doInitialization did this analysis.
    739 MMI = getAnalysisToUpdate();
    740 DW = getAnalysisToUpdate>();
    739 MMI = getAnalysisIfAvailable>();
    740 DW = getAnalysisIfAvailable();
    741741 DW->BeginModule(&M, MMI, O, this, TAI);
    742742 }
    743743
    974974 }
    975975
    976976 // Emit final debug information.
    977 DwarfWriter *DW = getAnalysisToUpdate();
    977 DwarfWriter *DW = getAnalysisIfAvailable();
    978978 DW->EndModule();
    979979
    980980 // Funny Darwin hack: This flag tells the linker that no global symbols
    994994 }
    995995
    996996 // Emit final debug information.
    997 DwarfWriter *DW = getAnalysisToUpdate();
    997 DwarfWriter *DW = getAnalysisIfAvailable();
    998998 DW->EndModule();
    999999 } else if (Subtarget->isTargetELF()) {
    10001000 // Emit final debug information.
    1001 DwarfWriter *DW = getAnalysisToUpdate();
    1001 DwarfWriter *DW = getAnalysisIfAvailable();
    10021002 DW->EndModule();
    10031003 }
    10041004
    440440 }
    441441
    442442 // Emit initial debug information.
    443 DW = getAnalysisToUpdate();
    443 DW = getAnalysisIfAvailable();
    444444 assert(DW && "Dwarf Writer is not available");
    445 DW->BeginModule(&M, getAnalysisToUpdate(),
    445 DW->BeginModule(&M, getAnalysisIfAvailable(),
    446446 O, this, TAI);
    447447 return Result;
    448448 }
    9898 }
    9999
    100100 bool InternalizePass::runOnModule(Module &M) {
    101 CallGraph *CG = getAnalysisToUpdate();
    101 CallGraph *CG = getAnalysisIfAvailable();
    102102 CallGraphNode *ExternalNode = CG ? CG->getExternalCallingNode() : 0;
    103103
    104104 if (ExternalNames.empty()) {
    456456 "Expected only one incoming value from Original PreHeader");
    457457 }
    458458
    459 if (DominatorTree *DT = getAnalysisToUpdate()) {
    459 if (DominatorTree *DT = getAnalysisIfAvailable()) {
    460460 DT->addNewBlock(NewPreHeader, OrigPreHeader);
    461461 DT->changeImmediateDominator(L->getHeader(), NewPreHeader);
    462462 DT->changeImmediateDominator(Exit, OrigPreHeader);
    472472 DT->changeImmediateDominator(OrigHeader, OrigLatch);
    473473 }
    474474
    475 if (DominanceFrontier *DF = getAnalysisToUpdate()) {
    475 if (DominanceFrontier *DF = getAnalysisIfAvailable()) {
    476476 // New Preheader's dominance frontier is Exit block.
    477477 DominanceFrontier::DomSetType NewPHSet;
    478478 NewPHSet.insert(Exit);
    508508 // If a loop block dominates new loop latch then its frontier is
    509509 // new header and Exit.
    510510 BasicBlock *NewLatch = L->getLoopLatch();
    511 DominatorTree *DT = getAnalysisToUpdate();
    511 DominatorTree *DT = getAnalysisIfAvailable();
    512512 for (Loop::block_iterator BI = L->block_begin(), BE = L->block_end();
    513513 BI != BE; ++BI) {
    514514 BasicBlock *B = *BI;
    169169 return false;
    170170
    171171 // FIXME: Reconstruct dom info, because it is not preserved properly.
    172 DominatorTree *DT = getAnalysisToUpdate();
    172 DominatorTree *DT = getAnalysisIfAvailable();
    173173 if (DT) {
    174174 DT->runOnFunction(*F);
    175 DominanceFrontier *DF = getAnalysisToUpdate();
    175 DominanceFrontier *DF = getAnalysisIfAvailable();
    176176 if (DF)
    177177 DF->runOnFunction(*F);
    178178 }
    187187 bool LoopUnswitch::runOnLoop(Loop *L, LPPassManager &LPM_Ref) {
    188188 LI = &getAnalysis();
    189189 LPM = &LPM_Ref;
    190 DF = getAnalysisToUpdate();
    191 DT = getAnalysisToUpdate>();
    190 DF = getAnalysisIfAvailable>();
    191 DT = getAnalysisIfAvailable();
    192192 currentLoop = L;
    193193 Function *F = currentLoop->getHeader()->getParent();
    194194 bool Changed = false;
    135135
    136136 // Finally, erase the old block and update dominator info.
    137137 if (P) {
    138 if (DominatorTree* DT = P->getAnalysisToUpdate()) {
    138 if (DominatorTree* DT = P->getAnalysisIfAvailable()) {
    139139 DomTreeNode* DTN = DT->getNode(BB);
    140140 DomTreeNode* PredDTN = DT->getNode(PredBB);
    141141
    298298 BasicBlock *New = Old->splitBasicBlock(SplitIt, Old->getName()+".split");
    299299
    300300 // The new block lives in whichever loop the old one did.
    301 if (LoopInfo* LI = P->getAnalysisToUpdate())
    301 if (LoopInfo* LI = P->getAnalysisIfAvailable())
    302302 if (Loop *L = LI->getLoopFor(Old))
    303303 L->addBasicBlockToLoop(New, LI->getBase());
    304304
    305 if (DominatorTree *DT = P->getAnalysisToUpdate())
    305 if (DominatorTree *DT = P->getAnalysisIfAvailable())
    306306 {
    307307 // Old dominates New. New node domiantes all other nodes dominated by Old.
    308308 DomTreeNode *OldNode = DT->getNode(Old);
    318318 DT->changeImmediateDominator(*I, NewNode);
    319319 }
    320320
    321 if (DominanceFrontier *DF = P->getAnalysisToUpdate())
    321 if (DominanceFrontier *DF = P->getAnalysisIfAvailable())
    322322 DF->splitBlock(Old);
    323323
    324324 return New;
    349349 Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB);
    350350
    351351 // Update dominator tree and dominator frontier if available.
    352 DominatorTree *DT = P ? P->getAnalysisToUpdate() : 0;
    352 DominatorTree *DT = P ? P->getAnalysisIfAvailable() : 0;
    353353 if (DT)
    354354 DT->splitBlock(NewBB);
    355 if (DominanceFrontier *DF = P ? P->getAnalysisToUpdate():0)
    355 if (DominanceFrontier *DF = P ? P->getAnalysisIfAvailable():0)
    356356 DF->splitBlock(NewBB);
    357 AliasAnalysis *AA = P ? P->getAnalysisToUpdate() : 0;
    357 AliasAnalysis *AA = P ? P->getAnalysisIfAvailable() : 0;
    358358
    359359
    360360 // Insert a new PHI node into NewBB for every PHI node in BB and that new PHI
    186186 bool NewBBDominatesDestBB = true;
    187187
    188188 // Should we update DominatorTree information?
    189 if (DominatorTree *DT = P->getAnalysisToUpdate()) {
    189 if (DominatorTree *DT = P->getAnalysisIfAvailable()) {
    190190 DomTreeNode *TINode = DT->getNode(TIBB);
    191191
    192192 // The new block is not the immediate dominator for any other nodes, but
    217217 }
    218218
    219219 // Should we update DominanceFrontier information?
    220 if (DominanceFrontier *DF = P->getAnalysisToUpdate()) {
    220 if (DominanceFrontier *DF = P->getAnalysisIfAvailable()) {
    221221 // If NewBBDominatesDestBB hasn't been computed yet, do so with DF.
    222222 if (!OtherPreds.empty()) {
    223223 // FIXME: IMPLEMENT THIS!
    251251 }
    252252
    253253 // Update LoopInfo if it is around.
    254 if (LoopInfo *LI = P->getAnalysisToUpdate()) {
    254 if (LoopInfo *LI = P->getAnalysisIfAvailable()) {
    255255 // If one or the other blocks were not in a loop, the new block is not
    256256 // either, and thus LI doesn't need to be updated.
    257257 if (Loop *TIL = LI->getLoopFor(TIBB))
    7878 DominatorTree *DT = NULL;
    7979 DominanceFrontier *DF = NULL;
    8080 if (P) {
    81 DT = P->getAnalysisToUpdate();
    82 DF = P->getAnalysisToUpdate>();
    81 DT = P->getAnalysisIfAvailable>();
    82 DF = P->getAnalysisIfAvailable();
    8383 }
    8484
    8585 SmallVector NewBlocks;
    111111 bool LoopSimplify::runOnFunction(Function &F) {
    112112 bool Changed = false;
    113113 LI = &getAnalysis();
    114 AA = getAnalysisToUpdate();
    114 AA = getAnalysisIfAvailable();
    115115 DT = &getAnalysis();
    116116
    117117 // Check to see that no blocks (other than the header) in loops have
    594594
    595595 // Update dominator information
    596596 DT->splitBlock(BEBlock);
    597 if (DominanceFrontier *DF = getAnalysisToUpdate())
    597 if (DominanceFrontier *DF = getAnalysisIfAvailable())
    598598 DF->splitBlock(BEBlock);
    599599 }
    3636 ModulePass::~ModulePass() { }
    3737
    3838 bool Pass::mustPreserveAnalysisID(const PassInfo *AnalysisID) const {
    39 return Resolver->getAnalysisToUpdate(AnalysisID, true) != 0;
    39 return Resolver->getAnalysisIfAvailable(AnalysisID, true) != 0;
    4040 }
    4141
    4242 // dumpPassStructure - Implement the -debug-passes=Structure option
    678678 if (!VerifyDomInfo || !P.getResolver())
    679679 return;
    680680
    681 DominatorTree *DT = P.getAnalysisToUpdate();
    681 DominatorTree *DT = P.getAnalysisIfAvailable();
    682682 if (!DT)
    683683 return;
    684684
    694694 assert (0 && "Invalid dominator info");
    695695 }
    696696
    697 DominanceFrontier *DF = P.getAnalysisToUpdate();
    697 DominanceFrontier *DF = P.getAnalysisIfAvailable();
    698698 if (!DF)
    699699 return;
    700700
    10871087
    10881088 //===----------------------------------------------------------------------===//
    10891089 // NOTE: Is this the right place to define this method ?
    1090 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
    1091 Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
    1090 // getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
    1091 Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const {
    10921092 return PM.findAnalysisPass(ID, dir);
    10931093 }
    10941094