Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:14

0001 //===- LoopPass.h - LoopPass class ----------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines LoopPass class. All loop optimization
0010 // and transformation passes are derived from LoopPass.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_ANALYSIS_LOOPPASS_H
0015 #define LLVM_ANALYSIS_LOOPPASS_H
0016 
0017 #include "llvm/IR/LegacyPassManagers.h"
0018 #include "llvm/Pass.h"
0019 #include <deque>
0020 
0021 namespace llvm {
0022 
0023 class Loop;
0024 class LoopInfo;
0025 class LPPassManager;
0026 class Function;
0027 
0028 class LoopPass : public Pass {
0029 public:
0030   explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
0031 
0032   /// getPrinterPass - Get a pass to print the function corresponding
0033   /// to a Loop.
0034   Pass *createPrinterPass(raw_ostream &O,
0035                           const std::string &Banner) const override;
0036 
0037   // runOnLoop - This method should be implemented by the subclass to perform
0038   // whatever action is necessary for the specified Loop.
0039   virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
0040 
0041   using llvm::Pass::doInitialization;
0042   using llvm::Pass::doFinalization;
0043 
0044   // Initialization and finalization hooks.
0045   virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
0046     return false;
0047   }
0048 
0049   // Finalization hook does not supply Loop because at this time
0050   // loop nest is completely different.
0051   virtual bool doFinalization() { return false; }
0052 
0053   // Check if this pass is suitable for the current LPPassManager, if
0054   // available. This pass P is not suitable for a LPPassManager if P
0055   // is not preserving higher level analysis info used by other
0056   // LPPassManager passes. In such case, pop LPPassManager from the
0057   // stack. This will force assignPassManager() to create new
0058   // LPPassManger as expected.
0059   void preparePassManager(PMStack &PMS) override;
0060 
0061   /// Assign pass manager to manage this pass
0062   void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
0063 
0064   ///  Return what kind of Pass Manager can manage this pass.
0065   PassManagerType getPotentialPassManagerType() const override {
0066     return PMT_LoopPassManager;
0067   }
0068 
0069 protected:
0070   /// Optional passes call this function to check whether the pass should be
0071   /// skipped. This is the case when Attribute::OptimizeNone is set or when
0072   /// optimization bisect is over the limit.
0073   bool skipLoop(const Loop *L) const;
0074 };
0075 
0076 class LPPassManager : public FunctionPass, public PMDataManager {
0077 public:
0078   static char ID;
0079   explicit LPPassManager();
0080 
0081   /// run - Execute all of the passes scheduled for execution.  Keep track of
0082   /// whether any of the passes modifies the module, and if so, return true.
0083   bool runOnFunction(Function &F) override;
0084 
0085   /// Pass Manager itself does not invalidate any analysis info.
0086   // LPPassManager needs LoopInfo.
0087   void getAnalysisUsage(AnalysisUsage &Info) const override;
0088 
0089   StringRef getPassName() const override { return "Loop Pass Manager"; }
0090 
0091   PMDataManager *getAsPMDataManager() override { return this; }
0092   Pass *getAsPass() override { return this; }
0093 
0094   /// Print passes managed by this manager
0095   void dumpPassStructure(unsigned Offset) override;
0096 
0097   LoopPass *getContainedPass(unsigned N) {
0098     assert(N < PassVector.size() && "Pass number out of range!");
0099     LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
0100     return LP;
0101   }
0102 
0103   PassManagerType getPassManagerType() const override {
0104     return PMT_LoopPassManager;
0105   }
0106 
0107 public:
0108   // Add a new loop into the loop queue.
0109   void addLoop(Loop &L);
0110 
0111   // Mark \p L as deleted.
0112   void markLoopAsDeleted(Loop &L);
0113 
0114 private:
0115   std::deque<Loop *> LQ;
0116   LoopInfo *LI;
0117   Loop *CurrentLoop;
0118   bool CurrentLoopDeleted;
0119 };
0120 
0121 // This pass is required by the LCSSA transformation. It is used inside
0122 // LPPassManager to check if current pass preserves LCSSA form, and if it does
0123 // pass manager calls lcssa verification for the current loop.
0124 struct LCSSAVerificationPass : public FunctionPass {
0125   static char ID;
0126   LCSSAVerificationPass();
0127 
0128   bool runOnFunction(Function &F) override { return false; }
0129 
0130   void getAnalysisUsage(AnalysisUsage &AU) const override {
0131     AU.setPreservesAll();
0132   }
0133 };
0134 
0135 } // End llvm namespace
0136 
0137 #endif