[llvm] dfc8244 - [PrintSCC] Fix printing a basic-block without a name

Ehud Katz via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 10:14:31 PDT 2020


Author: Ehud Katz
Date: 2020-05-29T20:14:19+03:00
New Revision: dfc8244c24631169630399a640ab526acd678346

URL: https://github.com/llvm/llvm-project/commit/dfc8244c24631169630399a640ab526acd678346
DIFF: https://github.com/llvm/llvm-project/commit/dfc8244c24631169630399a640ab526acd678346.diff

LOG: [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

Added: 
    llvm/test/Other/print-cfg-sccs.ll

Modified: 
    llvm/tools/opt/PrintSCC.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/Other/print-cfg-sccs.ll b/llvm/test/Other/print-cfg-sccs.ll
new file mode 100644
index 000000000000..43e885476bca
--- /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 5ab4a00552f3..1ca52745ff40 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<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).";
   }


        


More information about the llvm-commits mailing list