[Mlir-commits] [mlir] 9de88fc - [mlir][emitc] Fix indent in CondBranchOp and block label

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Sep 19 05:08:39 PDT 2021


Author: xndcn
Date: 2021-09-19T20:03:42+08:00
New Revision: 9de88fc0eac1bfc719dfd63a32b7eb069489407e

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

LOG: [mlir][emitc] Fix indent in CondBranchOp and block label

1. Add missing indent in CondBranchOp
2. Remove indent in block label

Differential Revision: https://reviews.llvm.org/D109805

Added: 
    

Modified: 
    mlir/lib/Target/Cpp/TranslateToCpp.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 859c6f015109f..f2d5002a9e85a 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -248,13 +248,15 @@ static LogicalResult printOperation(CppEmitter &emitter, BranchOp branchOp) {
 
 static LogicalResult printOperation(CppEmitter &emitter,
                                     CondBranchOp condBranchOp) {
-  raw_ostream &os = emitter.ostream();
+  raw_indented_ostream &os = emitter.ostream();
   Block &trueSuccessor = *condBranchOp.getTrueDest();
   Block &falseSuccessor = *condBranchOp.getFalseDest();
 
   os << "if (" << emitter.getOrCreateName(condBranchOp.getCondition())
      << ") {\n";
 
+  os.indent();
+
   // If condition is true.
   for (auto pair : llvm::zip(condBranchOp.getTrueOperands(),
                              trueSuccessor.getArguments())) {
@@ -269,7 +271,8 @@ static LogicalResult printOperation(CppEmitter &emitter,
     return condBranchOp.emitOpError("unable to find label for successor block");
   }
   os << emitter.getOrCreateName(trueSuccessor) << ";\n";
-  os << "} else {\n";
+  os.unindent() << "} else {\n";
+  os.indent();
   // If condition is false.
   for (auto pair : llvm::zip(condBranchOp.getFalseOperands(),
                              falseSuccessor.getArguments())) {
@@ -285,7 +288,7 @@ static LogicalResult printOperation(CppEmitter &emitter,
            << "unable to find label for successor block";
   }
   os << emitter.getOrCreateName(falseSuccessor) << ";\n";
-  os << "}";
+  os.unindent() << "}";
   return success();
 }
 
@@ -876,7 +879,9 @@ LogicalResult CppEmitter::emitAssignPrefix(Operation &op) {
 LogicalResult CppEmitter::emitLabel(Block &block) {
   if (!hasBlockLabel(block))
     return block.getParentOp()->emitError("label for block not found");
-  os << getOrCreateName(block) << ":\n";
+  // FIXME: Add feature in `raw_indented_ostream` to ignore indent for block
+  // label instead of using `getOStream`.
+  os.getOStream() << getOrCreateName(block) << ":\n";
   return success();
 }
 


        


More information about the Mlir-commits mailing list