//===- RegionPass.cpp - Region Pass and Region Pass Manager ---------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements RegionPass and RGPassManager. All region optimization // and transformation passes are derived from RegionPass. RGPassManager is // responsible for managing RegionPasses. // Most of this code has been COPIED from LoopPass.cpp // //===----------------------------------------------------------------------===// #include "llvm/Analysis/RegionPass.h" #include "llvm/Analysis/RegionInfo.h" #include "llvm/IR/OptBisect.h" #include "llvm/IR/PassTimingInfo.h" #include "llvm/IR/PrintPasses.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" usingnamespacellvm; #define DEBUG_TYPE … //===----------------------------------------------------------------------===// // RGPassManager // char RGPassManager::ID = …; RGPassManager::RGPassManager() : … { … } // Recurse through all subregions and all regions into RQ. static void addRegionIntoQueue(Region &R, std::deque<Region *> &RQ) { … } /// Pass Manager itself does not invalidate any analysis info. void RGPassManager::getAnalysisUsage(AnalysisUsage &Info) const { … } /// run - Execute all of the passes scheduled for execution. Keep track of /// whether any of the passes modifies the function, and if so, return true. bool RGPassManager::runOnFunction(Function &F) { … } /// Print passes managed by this manager void RGPassManager::dumpPassStructure(unsigned Offset) { … } namespace { //===----------------------------------------------------------------------===// // PrintRegionPass class PrintRegionPass : public RegionPass { … }; char PrintRegionPass::ID = …; } //end anonymous namespace //===----------------------------------------------------------------------===// // RegionPass // Check if this pass is suitable for the current RGPassManager, if // available. This pass P is not suitable for a RGPassManager if P // is not preserving higher level analysis info used by other // RGPassManager passes. In such case, pop RGPassManager from the // stack. This will force assignPassManager() to create new // LPPassManger as expected. void RegionPass::preparePassManager(PMStack &PMS) { … } /// Assign pass manager to manage this pass. void RegionPass::assignPassManager(PMStack &PMS, PassManagerType PreferredType) { … } /// Get the printer pass Pass *RegionPass::createPrinterPass(raw_ostream &O, const std::string &Banner) const { … } static std::string getDescription(const Region &R) { … } bool RegionPass::skipRegion(Region &R) const { … }