From dfc8244c24631169630399a640ab526acd678346 Mon Sep 17 00:00:00 2001 From: Ehud Katz Date: Fri, 29 May 2020 20:12:44 +0300 Subject: [PATCH] [PrintSCC] Fix printing a basic-block without a name Print a basic-block as an operand to handle the case where it has no name. Differential Revision: https://reviews.llvm.org/D80552 --- llvm/test/Other/print-cfg-sccs.ll | 27 +++++++++++++++++++++++++++ llvm/tools/opt/PrintSCC.cpp | 7 ++++--- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Other/print-cfg-sccs.ll diff --git a/llvm/test/Other/print-cfg-sccs.ll b/llvm/test/Other/print-cfg-sccs.ll new file mode 100644 index 0000000..43e8854 --- /dev/null +++ b/llvm/test/Other/print-cfg-sccs.ll @@ -0,0 +1,27 @@ +; RUN: opt -print-cfg-sccs -disable-output < %s 2>&1 | FileCheck %s + +; CHECK: SCCs for Function test in PostOrder: +; CHECK-NEXT: SCC #1 : %exit, +; CHECK-NEXT: SCC #2 : %0, +; CHECK-NEXT: SCC #3 : %3, +; CHECK-NEXT: SCC #4 : %2, %1, +; CHECK-NEXT: SCC #5 : %entry, +define void @test(i1 %cond) { +entry: + br i1 %cond, label %0, label %1 + +0: + br label %exit + +1: + br label %2 + +2: + br i1 %cond, label %1, label %3 + +3: + br label %exit + +exit: + ret void +} diff --git a/llvm/tools/opt/PrintSCC.cpp b/llvm/tools/opt/PrintSCC.cpp index 5ab4a00..1ca5274 100644 --- a/llvm/tools/opt/PrintSCC.cpp +++ b/llvm/tools/opt/PrintSCC.cpp @@ -76,9 +76,10 @@ bool CFGSCC::runOnFunction(Function &F) { for (scc_iterator SCCI = scc_begin(&F); !SCCI.isAtEnd(); ++SCCI) { const std::vector &nextSCC = *SCCI; errs() << "\nSCC #" << ++sccNum << " : "; - for (std::vector::const_iterator I = nextSCC.begin(), - E = nextSCC.end(); I != E; ++I) - errs() << (*I)->getName() << ", "; + for (BasicBlock *BB : nextSCC) { + BB->printAsOperand(errs(), false); + errs() << ", "; + } if (nextSCC.size() == 1 && SCCI.hasCycle()) errs() << " (Has self-loop)."; } -- 2.7.4