[Mlir-commits] [mlir] 578122c - [mlir] Don't emit unused labels
    Marius Brehler 
    llvmlistbot at llvm.org
       
    Wed Jan 26 23:56:37 PST 2022
    
    
  
Author: Marius Brehler
Date: 2022-01-27T07:56:03Z
New Revision: 578122c18a2fd2765b4b07a6cf9d46719c638a60
URL: https://github.com/llvm/llvm-project/commit/578122c18a2fd2765b4b07a6cf9d46719c638a60
DIFF: https://github.com/llvm/llvm-project/commit/578122c18a2fd2765b4b07a6cf9d46719c638a60.diff
LOG: [mlir] Don't emit unused labels
Stop the Cpp target from emitting unused labels. The previosly generated
code generated warning if `-Wunused-label` is passed to a compiler.
Co-authored-by: Simon Camphausen <simon.camphausen at iml.fraunhofer.de>
Reviewed By: jpienaar
Differential Revision: https://reviews.llvm.org/D118154
Added: 
    
Modified: 
    mlir/lib/Target/Cpp/TranslateToCpp.cpp
    mlir/test/Target/Cpp/control_flow.mlir
Removed: 
    
################################################################################
diff  --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 1fc120a7dcd96..a332029a4cf81 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -631,8 +631,8 @@ static LogicalResult printOperation(CppEmitter &emitter, FuncOp functionOp) {
   }
 
   for (Block &block : blocks) {
-    // Only print a label if there is more than one block.
-    if (blocks.size() > 1) {
+    // Only print a label if the block has predecessors.
+    if (!block.hasNoPredecessors()) {
       if (failed(emitter.emitLabel(block)))
         return failure();
     }
diff  --git a/mlir/test/Target/Cpp/control_flow.mlir b/mlir/test/Target/Cpp/control_flow.mlir
index ed8ee08ff46d5..d73299e0a9621 100644
--- a/mlir/test/Target/Cpp/control_flow.mlir
+++ b/mlir/test/Target/Cpp/control_flow.mlir
@@ -22,7 +22,6 @@ func @simple(i64, i1) -> i64 {
     // CPP-DECLTOP-NEXT: int64_t [[C:[^ ]*]];
     // CPP-DECLTOP-NEXT: int64_t [[D:[^ ]*]];
     // CPP-DECLTOP-NEXT: int64_t [[E:[^ ]*]];
-    // CPP-DECLTOP-NEXT: [[BB0:[^ ]*]]:
     // CPP-DECLTOP-NEXT: if ([[COND]]) {
     // CPP-DECLTOP-NEXT: goto [[BB1:[^ ]*]];
     // CPP-DECLTOP-NEXT: } else {
@@ -51,7 +50,6 @@ func @block_labels0() {
     return
 }
 // CPP-DECLTOP: void block_labels0() {
-  // CPP-DECLTOP-NEXT: label1:
   // CPP-DECLTOP-NEXT: goto label2;
   // CPP-DECLTOP-NEXT: label2:
   // CPP-DECLTOP-NEXT: return;
@@ -66,7 +64,6 @@ func @block_labels1() {
     return
 }
 // CPP-DECLTOP: void block_labels1() {
-  // CPP-DECLTOP-NEXT: label1:
   // CPP-DECLTOP-NEXT: goto label2;
   // CPP-DECLTOP-NEXT: label2:
   // CPP-DECLTOP-NEXT: return;
        
    
    
More information about the Mlir-commits
mailing list