Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 1 | //===- MustExecute.cpp - Printer for isGuaranteedToExecute ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Philip Reames | e4b728e | 2018-03-29 19:22:12 +0000 | [diff] [blame] | 10 | #include "llvm/Analysis/MustExecute.h" |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 11 | #include "llvm/Analysis/InstructionSimplify.h" |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 12 | #include "llvm/Analysis/LoopInfo.h" |
| 13 | #include "llvm/Analysis/Passes.h" |
| 14 | #include "llvm/Analysis/ValueTracking.h" |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 15 | #include "llvm/IR/AssemblyAnnotationWriter.h" |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 16 | #include "llvm/IR/DataLayout.h" |
| 17 | #include "llvm/IR/InstIterator.h" |
| 18 | #include "llvm/IR/LLVMContext.h" |
| 19 | #include "llvm/IR/Module.h" |
| 20 | #include "llvm/Support/ErrorHandling.h" |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 21 | #include "llvm/Support/FormattedStream.h" |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 23 | using namespace llvm; |
| 24 | |
Max Kazantsev | 8d56be7 | 2018-10-16 08:07:14 +0000 | [diff] [blame] | 25 | const DenseMap<BasicBlock *, ColorVector> & |
| 26 | LoopSafetyInfo::getBlockColors() const { |
| 27 | return BlockColors; |
| 28 | } |
| 29 | |
| 30 | void LoopSafetyInfo::copyColors(BasicBlock *New, BasicBlock *Old) { |
| 31 | ColorVector &ColorsForNewBlock = BlockColors[New]; |
| 32 | ColorVector &ColorsForOldBlock = BlockColors[Old]; |
| 33 | ColorsForNewBlock = ColorsForOldBlock; |
| 34 | } |
| 35 | |
Max Kazantsev | 530b8d1 | 2018-08-15 05:55:43 +0000 | [diff] [blame] | 36 | bool LoopSafetyInfo::headerMayThrow() const { |
| 37 | return HeaderMayThrow; |
| 38 | } |
| 39 | |
Max Kazantsev | 6a4f5e2 | 2018-10-16 07:50:14 +0000 | [diff] [blame] | 40 | bool LoopSafetyInfo::blockMayThrow(const BasicBlock *BB) const { |
| 41 | (void)BB; |
| 42 | return anyBlockMayThrow(); |
| 43 | } |
| 44 | |
Max Kazantsev | 530b8d1 | 2018-08-15 05:55:43 +0000 | [diff] [blame] | 45 | bool LoopSafetyInfo::anyBlockMayThrow() const { |
| 46 | return MayThrow; |
| 47 | } |
| 48 | |
Max Kazantsev | 8d56be7 | 2018-10-16 08:07:14 +0000 | [diff] [blame] | 49 | void LoopSafetyInfo::computeLoopSafetyInfo(const Loop *CurLoop) { |
Shoaib Meenai | a57d713 | 2018-07-19 19:11:29 +0000 | [diff] [blame] | 50 | assert(CurLoop != nullptr && "CurLoop can't be null"); |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 51 | BasicBlock *Header = CurLoop->getHeader(); |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 52 | // Iterate over header and compute safety info. |
Max Kazantsev | 530b8d1 | 2018-08-15 05:55:43 +0000 | [diff] [blame] | 53 | HeaderMayThrow = !isGuaranteedToTransferExecutionToSuccessor(Header); |
| 54 | MayThrow = HeaderMayThrow; |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 55 | // Iterate over loop instructions and compute safety info. |
| 56 | // Skip header as it has been computed and stored in HeaderMayThrow. |
| 57 | // The first block in loopinfo.Blocks is guaranteed to be the header. |
| 58 | assert(Header == *CurLoop->getBlocks().begin() && |
| 59 | "First block must be header"); |
| 60 | for (Loop::block_iterator BB = std::next(CurLoop->block_begin()), |
| 61 | BBE = CurLoop->block_end(); |
Max Kazantsev | 530b8d1 | 2018-08-15 05:55:43 +0000 | [diff] [blame] | 62 | (BB != BBE) && !MayThrow; ++BB) |
| 63 | MayThrow |= !isGuaranteedToTransferExecutionToSuccessor(*BB); |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 64 | |
Max Kazantsev | 8d56be7 | 2018-10-16 08:07:14 +0000 | [diff] [blame] | 65 | computeBlockColors(CurLoop); |
| 66 | } |
| 67 | |
| 68 | void LoopSafetyInfo::computeBlockColors(const Loop *CurLoop) { |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 69 | // Compute funclet colors if we might sink/hoist in a function with a funclet |
| 70 | // personality routine. |
| 71 | Function *Fn = CurLoop->getHeader()->getParent(); |
| 72 | if (Fn->hasPersonalityFn()) |
| 73 | if (Constant *PersonalityFn = Fn->getPersonalityFn()) |
Heejin Ahn | b4be38f | 2018-05-17 20:52:03 +0000 | [diff] [blame] | 74 | if (isScopedEHPersonality(classifyEHPersonality(PersonalityFn))) |
Max Kazantsev | 530b8d1 | 2018-08-15 05:55:43 +0000 | [diff] [blame] | 75 | BlockColors = colorEHFunclets(*Fn); |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /// Return true if we can prove that the given ExitBlock is not reached on the |
| 79 | /// first iteration of the given loop. That is, the backedge of the loop must |
| 80 | /// be executed before the ExitBlock is executed in any dynamic execution trace. |
Max Kazantsev | a741587 | 2018-08-16 06:28:04 +0000 | [diff] [blame] | 81 | static bool CanProveNotTakenFirstIteration(const BasicBlock *ExitBlock, |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 82 | const DominatorTree *DT, |
| 83 | const Loop *CurLoop) { |
| 84 | auto *CondExitBlock = ExitBlock->getSinglePredecessor(); |
| 85 | if (!CondExitBlock) |
| 86 | // expect unique exits |
| 87 | return false; |
| 88 | assert(CurLoop->contains(CondExitBlock) && "meaning of exit block"); |
| 89 | auto *BI = dyn_cast<BranchInst>(CondExitBlock->getTerminator()); |
| 90 | if (!BI || !BI->isConditional()) |
| 91 | return false; |
Serguei Katkov | 5095883 | 2018-05-18 04:56:28 +0000 | [diff] [blame] | 92 | // If condition is constant and false leads to ExitBlock then we always |
| 93 | // execute the true branch. |
| 94 | if (auto *Cond = dyn_cast<ConstantInt>(BI->getCondition())) |
| 95 | return BI->getSuccessor(Cond->getZExtValue() ? 1 : 0) == ExitBlock; |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 96 | auto *Cond = dyn_cast<CmpInst>(BI->getCondition()); |
| 97 | if (!Cond) |
| 98 | return false; |
| 99 | // todo: this would be a lot more powerful if we used scev, but all the |
| 100 | // plumbing is currently missing to pass a pointer in from the pass |
| 101 | // Check for cmp (phi [x, preheader] ...), y where (pred x, y is known |
| 102 | auto *LHS = dyn_cast<PHINode>(Cond->getOperand(0)); |
| 103 | auto *RHS = Cond->getOperand(1); |
| 104 | if (!LHS || LHS->getParent() != CurLoop->getHeader()) |
| 105 | return false; |
| 106 | auto DL = ExitBlock->getModule()->getDataLayout(); |
| 107 | auto *IVStart = LHS->getIncomingValueForBlock(CurLoop->getLoopPreheader()); |
| 108 | auto *SimpleValOrNull = SimplifyCmpInst(Cond->getPredicate(), |
| 109 | IVStart, RHS, |
| 110 | {DL, /*TLI*/ nullptr, |
| 111 | DT, /*AC*/ nullptr, BI}); |
| 112 | auto *SimpleCst = dyn_cast_or_null<Constant>(SimpleValOrNull); |
| 113 | if (!SimpleCst) |
| 114 | return false; |
| 115 | if (ExitBlock == BI->getSuccessor(0)) |
| 116 | return SimpleCst->isZeroValue(); |
| 117 | assert(ExitBlock == BI->getSuccessor(1) && "implied by above"); |
| 118 | return SimpleCst->isAllOnesValue(); |
| 119 | } |
| 120 | |
Max Kazantsev | bfbd4d1 | 2018-08-21 07:15:06 +0000 | [diff] [blame] | 121 | void LoopSafetyInfo::collectTransitivePredecessors( |
| 122 | const Loop *CurLoop, const BasicBlock *BB, |
| 123 | SmallPtrSetImpl<const BasicBlock *> &Predecessors) const { |
| 124 | assert(Predecessors.empty() && "Garbage in predecessors set?"); |
Max Kazantsev | 7b78d39 | 2018-08-17 06:19:17 +0000 | [diff] [blame] | 125 | assert(CurLoop->contains(BB) && "Should only be called for loop blocks!"); |
Max Kazantsev | 7b78d39 | 2018-08-17 06:19:17 +0000 | [diff] [blame] | 126 | if (BB == CurLoop->getHeader()) |
Max Kazantsev | bfbd4d1 | 2018-08-21 07:15:06 +0000 | [diff] [blame] | 127 | return; |
Max Kazantsev | 7b78d39 | 2018-08-17 06:19:17 +0000 | [diff] [blame] | 128 | SmallVector<const BasicBlock *, 4> WorkList; |
| 129 | for (auto *Pred : predecessors(BB)) { |
| 130 | Predecessors.insert(Pred); |
| 131 | WorkList.push_back(Pred); |
| 132 | } |
| 133 | while (!WorkList.empty()) { |
| 134 | auto *Pred = WorkList.pop_back_val(); |
| 135 | assert(CurLoop->contains(Pred) && "Should only reach loop blocks!"); |
| 136 | // We are not interested in backedges and we don't want to leave loop. |
| 137 | if (Pred == CurLoop->getHeader()) |
| 138 | continue; |
| 139 | // TODO: If BB lies in an inner loop of CurLoop, this will traverse over all |
| 140 | // blocks of this inner loop, even those that are always executed AFTER the |
| 141 | // BB. It may make our analysis more conservative than it could be, see test |
| 142 | // @nested and @nested_no_throw in test/Analysis/MustExecute/loop-header.ll. |
| 143 | // We can ignore backedge of all loops containing BB to get a sligtly more |
| 144 | // optimistic result. |
| 145 | for (auto *PredPred : predecessors(Pred)) |
| 146 | if (Predecessors.insert(PredPred).second) |
| 147 | WorkList.push_back(PredPred); |
| 148 | } |
Max Kazantsev | bfbd4d1 | 2018-08-21 07:15:06 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop, |
| 152 | const BasicBlock *BB, |
| 153 | const DominatorTree *DT) const { |
| 154 | assert(CurLoop->contains(BB) && "Should only be called for loop blocks!"); |
| 155 | |
| 156 | // Fast path: header is always reached once the loop is entered. |
| 157 | if (BB == CurLoop->getHeader()) |
| 158 | return true; |
| 159 | |
| 160 | // Collect all transitive predecessors of BB in the same loop. This set will |
| 161 | // be a subset of the blocks within the loop. |
| 162 | SmallPtrSet<const BasicBlock *, 4> Predecessors; |
| 163 | collectTransitivePredecessors(CurLoop, BB, Predecessors); |
Max Kazantsev | 7b78d39 | 2018-08-17 06:19:17 +0000 | [diff] [blame] | 164 | |
| 165 | // Make sure that all successors of all predecessors of BB are either: |
| 166 | // 1) BB, |
| 167 | // 2) Also predecessors of BB, |
| 168 | // 3) Exit blocks which are not taken on 1st iteration. |
| 169 | // Memoize blocks we've already checked. |
| 170 | SmallPtrSet<const BasicBlock *, 4> CheckedSuccessors; |
Max Kazantsev | 6a4f5e2 | 2018-10-16 07:50:14 +0000 | [diff] [blame] | 171 | for (auto *Pred : Predecessors) { |
| 172 | // Predecessor block may throw, so it has a side exit. |
| 173 | if (blockMayThrow(Pred)) |
| 174 | return false; |
Max Kazantsev | 7b78d39 | 2018-08-17 06:19:17 +0000 | [diff] [blame] | 175 | for (auto *Succ : successors(Pred)) |
| 176 | if (CheckedSuccessors.insert(Succ).second && |
| 177 | Succ != BB && !Predecessors.count(Succ)) |
| 178 | // By discharging conditions that are not executed on the 1st iteration, |
| 179 | // we guarantee that *at least* on the first iteration all paths from |
| 180 | // header that *may* execute will lead us to the block of interest. So |
| 181 | // that if we had virtually peeled one iteration away, in this peeled |
| 182 | // iteration the set of predecessors would contain only paths from |
| 183 | // header to BB without any exiting edges that may execute. |
| 184 | // |
| 185 | // TODO: We only do it for exiting edges currently. We could use the |
| 186 | // same function to skip some of the edges within the loop if we know |
| 187 | // that they will not be taken on the 1st iteration. |
| 188 | // |
| 189 | // TODO: If we somehow know the number of iterations in loop, the same |
| 190 | // check may be done for any arbitrary N-th iteration as long as N is |
| 191 | // not greater than minimum number of iterations in this loop. |
| 192 | if (CurLoop->contains(Succ) || |
| 193 | !CanProveNotTakenFirstIteration(Succ, DT, CurLoop)) |
| 194 | return false; |
Max Kazantsev | 6a4f5e2 | 2018-10-16 07:50:14 +0000 | [diff] [blame] | 195 | } |
Max Kazantsev | 7b78d39 | 2018-08-17 06:19:17 +0000 | [diff] [blame] | 196 | |
| 197 | // All predecessors can only lead us to BB. |
| 198 | return true; |
| 199 | } |
| 200 | |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 201 | /// Returns true if the instruction in a loop is guaranteed to execute at least |
| 202 | /// once. |
Max Kazantsev | c8466f9 | 2018-10-16 06:34:53 +0000 | [diff] [blame] | 203 | bool LoopSafetyInfo::isGuaranteedToExecute(const Instruction &Inst, |
| 204 | const DominatorTree *DT, |
| 205 | const Loop *CurLoop) const { |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 206 | // We have to check to make sure that the instruction dominates all |
| 207 | // of the exit blocks. If it doesn't, then there is a path out of the loop |
| 208 | // which does not execute this instruction, so we can't hoist it. |
| 209 | |
| 210 | // If the instruction is in the header block for the loop (which is very |
| 211 | // common), it is always guaranteed to dominate the exit blocks. Since this |
| 212 | // is a common case, and can save some work, check it now. |
| 213 | if (Inst.getParent() == CurLoop->getHeader()) |
| 214 | // If there's a throw in the header block, we can't guarantee we'll reach |
Philip Reames | e4ec473 | 2018-04-27 20:44:01 +0000 | [diff] [blame] | 215 | // Inst unless we can prove that Inst comes before the potential implicit |
| 216 | // exit. At the moment, we use a (cheap) hack for the common case where |
| 217 | // the instruction of interest is the first one in the block. |
Max Kazantsev | c8466f9 | 2018-10-16 06:34:53 +0000 | [diff] [blame] | 218 | return !headerMayThrow() || |
| 219 | Inst.getParent()->getFirstNonPHIOrDbg() == &Inst; |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 220 | |
Max Kazantsev | 7b78d39 | 2018-08-17 06:19:17 +0000 | [diff] [blame] | 221 | // If there is a path from header to exit or latch that doesn't lead to our |
| 222 | // instruction's block, return false. |
Max Kazantsev | c8466f9 | 2018-10-16 06:34:53 +0000 | [diff] [blame] | 223 | if (!allLoopPathsLeadToBlock(CurLoop, Inst.getParent(), DT)) |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 224 | return false; |
| 225 | |
Philip Reames | 23aed5e | 2018-03-20 22:45:23 +0000 | [diff] [blame] | 226 | return true; |
| 227 | } |
| 228 | |
| 229 | |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 230 | namespace { |
| 231 | struct MustExecutePrinter : public FunctionPass { |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 232 | |
| 233 | static char ID; // Pass identification, replacement for typeid |
| 234 | MustExecutePrinter() : FunctionPass(ID) { |
| 235 | initializeMustExecutePrinterPass(*PassRegistry::getPassRegistry()); |
| 236 | } |
| 237 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 238 | AU.setPreservesAll(); |
| 239 | AU.addRequired<DominatorTreeWrapperPass>(); |
| 240 | AU.addRequired<LoopInfoWrapperPass>(); |
| 241 | } |
| 242 | bool runOnFunction(Function &F) override; |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 243 | }; |
| 244 | } |
| 245 | |
| 246 | char MustExecutePrinter::ID = 0; |
| 247 | INITIALIZE_PASS_BEGIN(MustExecutePrinter, "print-mustexecute", |
| 248 | "Instructions which execute on loop entry", false, true) |
| 249 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
| 250 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) |
| 251 | INITIALIZE_PASS_END(MustExecutePrinter, "print-mustexecute", |
| 252 | "Instructions which execute on loop entry", false, true) |
| 253 | |
| 254 | FunctionPass *llvm::createMustExecutePrinter() { |
| 255 | return new MustExecutePrinter(); |
| 256 | } |
| 257 | |
Benjamin Kramer | 1fc0da4 | 2018-04-04 11:45:11 +0000 | [diff] [blame] | 258 | static bool isMustExecuteIn(const Instruction &I, Loop *L, DominatorTree *DT) { |
Philip Reames | 37a1a29 | 2018-03-20 23:00:54 +0000 | [diff] [blame] | 259 | // TODO: merge these two routines. For the moment, we display the best |
| 260 | // result obtained by *either* implementation. This is a bit unfair since no |
| 261 | // caller actually gets the full power at the moment. |
| 262 | LoopSafetyInfo LSI; |
Max Kazantsev | 530b8d1 | 2018-08-15 05:55:43 +0000 | [diff] [blame] | 263 | LSI.computeLoopSafetyInfo(L); |
Max Kazantsev | c8466f9 | 2018-10-16 06:34:53 +0000 | [diff] [blame] | 264 | return LSI.isGuaranteedToExecute(I, DT, L) || |
Philip Reames | 37a1a29 | 2018-03-20 23:00:54 +0000 | [diff] [blame] | 265 | isGuaranteedToExecuteForEveryIteration(&I, L); |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Benjamin Kramer | 1fc0da4 | 2018-04-04 11:45:11 +0000 | [diff] [blame] | 268 | namespace { |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 269 | /// An assembly annotator class to print must execute information in |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 270 | /// comments. |
| 271 | class MustExecuteAnnotatedWriter : public AssemblyAnnotationWriter { |
| 272 | DenseMap<const Value*, SmallVector<Loop*, 4> > MustExec; |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 273 | |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 274 | public: |
| 275 | MustExecuteAnnotatedWriter(const Function &F, |
| 276 | DominatorTree &DT, LoopInfo &LI) { |
| 277 | for (auto &I: instructions(F)) { |
| 278 | Loop *L = LI.getLoopFor(I.getParent()); |
| 279 | while (L) { |
| 280 | if (isMustExecuteIn(I, L, &DT)) { |
| 281 | MustExec[&I].push_back(L); |
| 282 | } |
| 283 | L = L->getParentLoop(); |
| 284 | }; |
| 285 | } |
| 286 | } |
| 287 | MustExecuteAnnotatedWriter(const Module &M, |
| 288 | DominatorTree &DT, LoopInfo &LI) { |
| 289 | for (auto &F : M) |
| 290 | for (auto &I: instructions(F)) { |
| 291 | Loop *L = LI.getLoopFor(I.getParent()); |
| 292 | while (L) { |
| 293 | if (isMustExecuteIn(I, L, &DT)) { |
| 294 | MustExec[&I].push_back(L); |
| 295 | } |
| 296 | L = L->getParentLoop(); |
| 297 | }; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 302 | void printInfoComment(const Value &V, formatted_raw_ostream &OS) override { |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 303 | if (!MustExec.count(&V)) |
| 304 | return; |
| 305 | |
| 306 | const auto &Loops = MustExec.lookup(&V); |
| 307 | const auto NumLoops = Loops.size(); |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 308 | if (NumLoops > 1) |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 309 | OS << " ; (mustexec in " << NumLoops << " loops: "; |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 310 | else |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 311 | OS << " ; (mustexec in: "; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 312 | |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 313 | bool first = true; |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 314 | for (const Loop *L : Loops) { |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 315 | if (!first) |
| 316 | OS << ", "; |
| 317 | first = false; |
| 318 | OS << L->getHeader()->getName(); |
| 319 | } |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 320 | OS << ")"; |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 321 | } |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 322 | }; |
Benjamin Kramer | 1fc0da4 | 2018-04-04 11:45:11 +0000 | [diff] [blame] | 323 | } // namespace |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 324 | |
| 325 | bool MustExecutePrinter::runOnFunction(Function &F) { |
| 326 | auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
| 327 | auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
| 328 | |
| 329 | MustExecuteAnnotatedWriter Writer(F, DT, LI); |
| 330 | F.print(dbgs(), &Writer); |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 331 | |
Philip Reames | ce998ad | 2018-03-20 18:43:44 +0000 | [diff] [blame] | 332 | return false; |
Philip Reames | 89f2241 | 2018-03-20 17:09:21 +0000 | [diff] [blame] | 333 | } |