LCOV - code coverage report
Current view: top level - include/llvm/Analysis - LoopPass.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 23 24 95.8 %
Date: 2017-09-14 15:23:50 Functions: 14 16 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- LoopPass.h - LoopPass class ----------------------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file defines LoopPass class. All loop optimization
      11             : // and transformation passes are derived from LoopPass.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_ANALYSIS_LOOPPASS_H
      16             : #define LLVM_ANALYSIS_LOOPPASS_H
      17             : 
      18             : #include "llvm/Analysis/LoopInfo.h"
      19             : #include "llvm/IR/LegacyPassManagers.h"
      20             : #include "llvm/Pass.h"
      21             : #include <deque>
      22             : 
      23             : namespace llvm {
      24             : 
      25             : class LPPassManager;
      26             : class Function;
      27             : class PMStack;
      28             : 
      29       44446 : class LoopPass : public Pass {
      30             : public:
      31       89304 :   explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
      32             : 
      33             :   /// getPrinterPass - Get a pass to print the function corresponding
      34             :   /// to a Loop.
      35             :   Pass *createPrinterPass(raw_ostream &O,
      36             :                           const std::string &Banner) const override;
      37             : 
      38             :   // runOnLoop - This method should be implemented by the subclass to perform
      39             :   // whatever action is necessary for the specified Loop.
      40             :   virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
      41             : 
      42             :   using llvm::Pass::doInitialization;
      43             :   using llvm::Pass::doFinalization;
      44             : 
      45             :   // Initialization and finalization hooks.
      46       47917 :   virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
      47       47917 :     return false;
      48             :   }
      49             : 
      50             :   // Finalization hook does not supply Loop because at this time
      51             :   // loop nest is completely different.
      52       23760 :   virtual bool doFinalization() { return false; }
      53             : 
      54             :   // Check if this pass is suitable for the current LPPassManager, if
      55             :   // available. This pass P is not suitable for a LPPassManager if P
      56             :   // is not preserving higher level analysis info used by other
      57             :   // LPPassManager passes. In such case, pop LPPassManager from the
      58             :   // stack. This will force assignPassManager() to create new
      59             :   // LPPassManger as expected.
      60             :   void preparePassManager(PMStack &PMS) override;
      61             : 
      62             :   /// Assign pass manager to manage this pass
      63             :   void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
      64             : 
      65             :   ///  Return what kind of Pass Manager can manage this pass.
      66      186215 :   PassManagerType getPotentialPassManagerType() const override {
      67      186215 :     return PMT_LoopPassManager;
      68             :   }
      69             : 
      70             :   //===--------------------------------------------------------------------===//
      71             :   /// SimpleAnalysis - Provides simple interface to update analysis info
      72             :   /// maintained by various passes. Note, if required this interface can
      73             :   /// be extracted into a separate abstract class but it would require
      74             :   /// additional use of multiple inheritance in Pass class hierarchy, something
      75             :   /// we are trying to avoid.
      76             : 
      77             :   /// Each loop pass can override these simple analysis hooks to update
      78             :   /// desired analysis information.
      79             :   /// cloneBasicBlockAnalysis - Clone analysis info associated with basic block.
      80         408 :   virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L) {}
      81             : 
      82             :   /// deleteAnalysisValue - Delete analysis info associated with value V.
      83         142 :   virtual void deleteAnalysisValue(Value *V, Loop *L) {}
      84             : 
      85             :   /// Delete analysis info associated with Loop L.
      86             :   /// Called to notify a Pass that a loop has been deleted and any
      87             :   /// associated analysis values can be deleted.
      88        1019 :   virtual void deleteAnalysisLoop(Loop *L) {}
      89             : 
      90             : protected:
      91             :   /// Optional passes call this function to check whether the pass should be
      92             :   /// skipped. This is the case when Attribute::OptimizeNone is set or when
      93             :   /// optimization bisect is over the limit.
      94             :   bool skipLoop(const Loop *L) const;
      95             : };
      96             : 
      97       96036 : class LPPassManager : public FunctionPass, public PMDataManager {
      98             : public:
      99             :   static char ID;
     100             :   explicit LPPassManager();
     101             : 
     102             :   /// run - Execute all of the passes scheduled for execution.  Keep track of
     103             :   /// whether any of the passes modifies the module, and if so, return true.
     104             :   bool runOnFunction(Function &F) override;
     105             : 
     106             :   /// Pass Manager itself does not invalidate any analysis info.
     107             :   // LPPassManager needs LoopInfo.
     108             :   void getAnalysisUsage(AnalysisUsage &Info) const override;
     109             : 
     110           0 :   StringRef getPassName() const override { return "Loop Pass Manager"; }
     111             : 
     112       24291 :   PMDataManager *getAsPMDataManager() override { return this; }
     113       84390 :   Pass *getAsPass() override { return this; }
     114             : 
     115             :   /// Print passes managed by this manager
     116             :   void dumpPassStructure(unsigned Offset) override;
     117             : 
     118             :   LoopPass *getContainedPass(unsigned N) {
     119             :     assert(N < PassVector.size() && "Pass number out of range!");
     120      255738 :     LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
     121             :     return LP;
     122             :   }
     123             : 
     124       74852 :   PassManagerType getPassManagerType() const override {
     125       74852 :     return PMT_LoopPassManager;
     126             :   }
     127             : 
     128             : public:
     129             :   // Add a new loop into the loop queue.
     130             :   void addLoop(Loop &L);
     131             : 
     132             :   //===--------------------------------------------------------------------===//
     133             :   /// SimpleAnalysis - Provides simple interface to update analysis info
     134             :   /// maintained by various passes. Note, if required this interface can
     135             :   /// be extracted into a separate abstract class but it would require
     136             :   /// additional use of multiple inheritance in Pass class hierarchy, something
     137             :   /// we are trying to avoid.
     138             : 
     139             :   /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
     140             :   /// all passes that implement simple analysis interface.
     141             :   void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L);
     142             : 
     143             :   /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
     144             :   /// that implement simple analysis interface.
     145             :   void deleteSimpleAnalysisValue(Value *V, Loop *L);
     146             : 
     147             :   /// Invoke deleteAnalysisLoop hook for all passes that implement simple
     148             :   /// analysis interface.
     149             :   void deleteSimpleAnalysisLoop(Loop *L);
     150             : 
     151             : private:
     152             :   std::deque<Loop *> LQ;
     153             :   LoopInfo *LI;
     154             :   Loop *CurrentLoop;
     155             : };
     156             : 
     157             : // This pass is required by the LCSSA transformation. It is used inside
     158             : // LPPassManager to check if current pass preserves LCSSA form, and if it does
     159             : // pass manager calls lcssa verification for the current loop.
     160       16784 : struct LCSSAVerificationPass : public FunctionPass {
     161             :   static char ID;
     162       16804 :   LCSSAVerificationPass() : FunctionPass(ID) {
     163        8402 :     initializeLCSSAVerificationPassPass(*PassRegistry::getPassRegistry());
     164             :   }
     165             : 
     166      151465 :   bool runOnFunction(Function &F) override { return false; }
     167             : 
     168        8402 :   void getAnalysisUsage(AnalysisUsage &AU) const override {
     169        8402 :     AU.setPreservesAll();
     170        8402 :   }
     171             : };
     172             : 
     173             : } // End llvm namespace
     174             : 
     175             : #endif

Generated by: LCOV version 1.13