|
| 1 | +//===- LoopNestTutorial.cpp - Loop Nest Tutorial Pass ---------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +// |
| 9 | +// This pass interchanges perfect loop nest with loop depth two. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "llvm/Transforms/Scalar/LoopNestTutorial.h" |
| 14 | +#include "llvm/IR/Verifier.h" |
| 15 | + |
| 16 | +using namespace llvm; |
| 17 | + |
| 18 | +#define DEBUG_TYPE "loop-nest-tutorial" |
| 19 | + |
| 20 | +class LoopNestTutorial { |
| 21 | +public: |
| 22 | + LoopNestTutorial(LoopInfo *LI, DominatorTree *DT) : LI(LI), DT(DT) {} |
| 23 | + |
| 24 | + bool run(LoopNest &LN) const { |
| 25 | + LLVM_DEBUG(dbgs() << "Entering LoopNestTutorial::run\n"); |
| 26 | + LLVM_DEBUG( |
| 27 | + dbgs() << "TODO: Need to check if LoopNest is a valid candidate\n"); |
| 28 | + (void)LI; |
| 29 | + (void)DT; |
| 30 | + return false; |
| 31 | + } |
| 32 | + |
| 33 | +private: |
| 34 | + LoopInfo *LI = nullptr; |
| 35 | + DominatorTree *DT = nullptr; |
| 36 | +}; |
| 37 | + |
| 38 | +static void verify(const LoopInfo &LI, const DominatorTree &DT) { |
| 39 | + Function &F = *(*LI.begin())->getHeader()->getParent(); |
| 40 | + assert(!verifyFunction(F, &errs()) && "Incorrect Function"); |
| 41 | + assert(DT.verify() && "Incorrect DT"); |
| 42 | + LI.verify(DT); |
| 43 | +} |
| 44 | + |
| 45 | +PreservedAnalyses LoopNestTutorialPass::run(LoopNest &LN, |
| 46 | + LoopAnalysisManager &LAM, |
| 47 | + LoopStandardAnalysisResults &AR, |
| 48 | + LPMUpdater &U) { |
| 49 | + |
| 50 | + LLVM_DEBUG(dbgs() << "Entering LoopNestTutorialPass::run\n"); |
| 51 | + |
| 52 | + // auto *DT = &AM.getResult<DominatorTreeAnalysis>(F); |
| 53 | + // auto *LI = &AM.getResult<LoopAnalysis>(F); |
| 54 | + // auto *SE = &AM.getResult<ScalarEvolutionAnalysis>(F); |
| 55 | + // bool Simplified = false; |
| 56 | + // for (const auto *L : *LI) { |
| 57 | + // Simplified |= simplifyLoop(L, DT, LI, SE, nullptr, nullptr, true); |
| 58 | + // LoopNest LN(*L, *SE); |
| 59 | + LLVM_DEBUG(dbgs() << "LoopNest: " << LN << "\n"); |
| 60 | + bool Changed = LoopNestTutorial(&AR.LI, &AR.DT).run(LN); |
| 61 | + // } |
| 62 | + |
| 63 | + if (!Changed) |
| 64 | + return PreservedAnalyses::all(); |
| 65 | + |
| 66 | + verify(AR.LI, AR.DT); |
| 67 | + |
| 68 | + return getLoopPassPreservedAnalyses(); |
| 69 | +} |
0 commit comments