Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- RegionPass.h - RegionPass class --------------------------*- C++ -*-===//
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 the RegionPass class. All region based analysis,
0010 // optimization and transformation passes are derived from RegionPass.
0011 // This class is implemented following the some ideas of the LoopPass.h class.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_ANALYSIS_REGIONPASS_H
0016 #define LLVM_ANALYSIS_REGIONPASS_H
0017 
0018 #include "llvm/IR/LegacyPassManagers.h"
0019 #include "llvm/Pass.h"
0020 #include <deque>
0021 
0022 namespace llvm {
0023 class Function;
0024 class RGPassManager;
0025 class Region;
0026 class RegionInfo;
0027 
0028 //===----------------------------------------------------------------------===//
0029 /// A pass that runs on each Region in a function.
0030 ///
0031 /// RegionPass is managed by RGPassManager.
0032 class RegionPass : public Pass {
0033 public:
0034   explicit RegionPass(char &pid) : Pass(PT_Region, pid) {}
0035 
0036   //===--------------------------------------------------------------------===//
0037   /// @name To be implemented by every RegionPass
0038   ///
0039   //@{
0040   /// Run the pass on a specific Region
0041   ///
0042   /// Accessing regions not contained in the current region is not allowed.
0043   ///
0044   /// @param R The region this pass is run on.
0045   /// @param RGM The RegionPassManager that manages this Pass.
0046   ///
0047   /// @return True if the pass modifies this Region.
0048   virtual bool runOnRegion(Region *R, RGPassManager &RGM) = 0;
0049 
0050   /// Get a pass to print the LLVM IR in the region.
0051   ///
0052   /// @param O      The output stream to print the Region.
0053   /// @param Banner The banner to separate different printed passes.
0054   ///
0055   /// @return The pass to print the LLVM IR in the region.
0056   Pass *createPrinterPass(raw_ostream &O,
0057                           const std::string &Banner) const override;
0058 
0059   using llvm::Pass::doInitialization;
0060   using llvm::Pass::doFinalization;
0061 
0062   virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; }
0063   virtual bool doFinalization() { return false; }
0064   //@}
0065 
0066   //===--------------------------------------------------------------------===//
0067   /// @name PassManager API
0068   ///
0069   //@{
0070   void preparePassManager(PMStack &PMS) override;
0071 
0072   void assignPassManager(PMStack &PMS,
0073                          PassManagerType PMT = PMT_RegionPassManager) override;
0074 
0075   PassManagerType getPotentialPassManagerType() const override {
0076     return PMT_RegionPassManager;
0077   }
0078   //@}
0079 
0080 protected:
0081   /// Optional passes call this function to check whether the pass should be
0082   /// skipped. This is the case when optimization bisect is over the limit.
0083   bool skipRegion(Region &R) const;
0084 };
0085 
0086 /// The pass manager to schedule RegionPasses.
0087 class RGPassManager : public FunctionPass, public PMDataManager {
0088   std::deque<Region*> RQ;
0089   RegionInfo *RI;
0090   Region *CurrentRegion;
0091 
0092 public:
0093   static char ID;
0094   explicit RGPassManager();
0095 
0096   /// Execute all of the passes scheduled for execution.
0097   ///
0098   /// @return True if any of the passes modifies the function.
0099   bool runOnFunction(Function &F) override;
0100 
0101   /// Pass Manager itself does not invalidate any analysis info.
0102   /// RGPassManager needs RegionInfo.
0103   void getAnalysisUsage(AnalysisUsage &Info) const override;
0104 
0105   StringRef getPassName() const override { return "Region Pass Manager"; }
0106 
0107   PMDataManager *getAsPMDataManager() override { return this; }
0108   Pass *getAsPass() override { return this; }
0109 
0110   /// Print passes managed by this manager.
0111   void dumpPassStructure(unsigned Offset) override;
0112 
0113   /// Get passes contained by this manager.
0114   Pass *getContainedPass(unsigned N) {
0115     assert(N < PassVector.size() && "Pass number out of range!");
0116     Pass *FP = static_cast<Pass *>(PassVector[N]);
0117     return FP;
0118   }
0119 
0120   PassManagerType getPassManagerType() const override {
0121     return PMT_RegionPassManager;
0122   }
0123 };
0124 
0125 } // End llvm namespace
0126 
0127 #endif