//===- LoopPass.cpp - Loop Pass and Loop 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 LoopPass and LPPassManager. All loop optimization // and transformation passes are derived from LoopPass. LPPassManager is // responsible for managing LoopPasses. // //===----------------------------------------------------------------------===// #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/OptBisect.h" #include "llvm/IR/PassTimingInfo.h" #include "llvm/IR/PrintPasses.h" #include "llvm/InitializePasses.h" #include "llvm/Support/Debug.h" #include "llvm/Support/TimeProfiler.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" usingnamespacellvm; #define DEBUG_TYPE … namespace { /// PrintLoopPass - Print a Function corresponding to a Loop. /// class PrintLoopPassWrapper : public LoopPass { … }; char PrintLoopPassWrapper::ID = …; } // namespace //===----------------------------------------------------------------------===// // LPPassManager // char LPPassManager::ID = …; LPPassManager::LPPassManager() : … { … } // Insert loop into loop nest (LoopInfo) and loop queue (LQ). void LPPassManager::addLoop(Loop &L) { … } // Recurse through all subloops and all loops into LQ. static void addLoopIntoQueue(Loop *L, std::deque<Loop *> &LQ) { … } /// Pass Manager itself does not invalidate any analysis info. void LPPassManager::getAnalysisUsage(AnalysisUsage &Info) const { … } void LPPassManager::markLoopAsDeleted(Loop &L) { … } /// 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 LPPassManager::runOnFunction(Function &F) { … } /// Print passes managed by this manager void LPPassManager::dumpPassStructure(unsigned Offset) { … } //===----------------------------------------------------------------------===// // LoopPass Pass *LoopPass::createPrinterPass(raw_ostream &O, const std::string &Banner) const { … } // Check if this pass is suitable for the current LPPassManager, if // available. This pass P is not suitable for a LPPassManager if P // is not preserving higher level analysis info used by other // LPPassManager passes. In such case, pop LPPassManager from the // stack. This will force assignPassManager() to create new // LPPassManger as expected. void LoopPass::preparePassManager(PMStack &PMS) { … } /// Assign pass manager to manage this pass. void LoopPass::assignPassManager(PMStack &PMS, PassManagerType PreferredType) { … } static std::string getDescription(const Loop &L) { … } bool LoopPass::skipLoop(const Loop *L) const { … } LCSSAVerificationPass::LCSSAVerificationPass() : … { … } char LCSSAVerificationPass::ID = …; INITIALIZE_PASS(…)