| 1 | //===- CFGSCCPrinter.cpp --------------------------------------------------===// |
|---|---|
| 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 | #include "llvm/Analysis/CFGSCCPrinter.h" |
| 10 | #include "llvm/ADT/SCCIterator.h" |
| 11 | #include "llvm/ADT/StringExtras.h" |
| 12 | #include "llvm/IR/CFG.h" |
| 13 | |
| 14 | using namespace llvm; |
| 15 | |
| 16 | PreservedAnalyses CFGSCCPrinterPass::run(Function &F, |
| 17 | FunctionAnalysisManager &AM) { |
| 18 | unsigned SccNum = 0; |
| 19 | OS << "SCCs for Function "<< F.getName() << " in PostOrder:"; |
| 20 | for (scc_iterator<Function *> SCCI = scc_begin(G: &F); !SCCI.isAtEnd(); ++SCCI) { |
| 21 | const std::vector<BasicBlock *> &NextSCC = *SCCI; |
| 22 | OS << "\nSCC #"<< ++SccNum << ": "; |
| 23 | ListSeparator LS; |
| 24 | for (BasicBlock *BB : NextSCC) { |
| 25 | OS << LS; |
| 26 | BB->printAsOperand(O&: OS, PrintType: false); |
| 27 | } |
| 28 | if (NextSCC.size() == 1 && SCCI.hasCycle()) |
| 29 | OS << " (Has self-loop)."; |
| 30 | } |
| 31 | OS << "\n"; |
| 32 | |
| 33 | return PreservedAnalyses::all(); |
| 34 | } |
| 35 |