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