[PrintSCC] Fix printing a basic-block without a name
authorEhud Katz <ehudkatz@gmail.com>
Fri, 29 May 2020 17:12:44 +0000 (20:12 +0300)
committerEhud Katz <ehudkatz@gmail.com>
Fri, 29 May 2020 17:14:19 +0000 (20:14 +0300)
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 [new file with mode: 0644]
llvm/tools/opt/PrintSCC.cpp

diff --git a/llvm/test/Other/print-cfg-sccs.ll b/llvm/test/Other/print-cfg-sccs.ll
new file mode 100644 (file)
index 0000000..43e8854
--- /dev/null
@@ -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
+}
index 5ab4a00..1ca5274 100644 (file)
@@ -76,9 +76,10 @@ bool CFGSCC::runOnFunction(Function &F) {
   for (scc_iterator<Function*> SCCI = scc_begin(&F); !SCCI.isAtEnd(); ++SCCI) {
     const std::vector<BasicBlock *> &nextSCC = *SCCI;
     errs() << "\nSCC #" << ++sccNum << " : ";
-    for (std::vector<BasicBlock*>::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).";
   }