CFGSCCPrinter.cpp 1.2 KB

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