Index: mlir/lib/Target/Cpp/TranslateToCpp.cpp =================================================================== --- mlir/lib/Target/Cpp/TranslateToCpp.cpp +++ mlir/lib/Target/Cpp/TranslateToCpp.cpp @@ -248,13 +248,15 @@ 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 @@ 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 @@ << "unable to find label for successor block"; } os << emitter.getOrCreateName(falseSuccessor) << ";\n"; - os << "}"; + os.unindent() << "}"; return success(); } @@ -873,7 +876,8 @@ LogicalResult CppEmitter::emitLabel(Block &block) { if (!hasBlockLabel(block)) return block.getParentOp()->emitError("label for block not found"); - os << getOrCreateName(block) << ":\n"; + // Using `getOStream()` to ignore indent for block label. + os.getOStream() << getOrCreateName(block) << ":\n"; return success(); }