[Mlir-commits] [mlir] Add a structured if operation (PR #67234)
Gil Rapaport
llvmlistbot at llvm.org
Tue Sep 26 01:27:45 PDT 2023
================
@@ -567,28 +580,19 @@ static LogicalResult printOperation(CppEmitter &emitter, scf::ForOp forOp) {
return success();
}
-static LogicalResult printOperation(CppEmitter &emitter, scf::IfOp ifOp) {
+static LogicalResult printOperation(CppEmitter &emitter, emitc::IfOp ifOp) {
raw_indented_ostream &os = emitter.ostream();
- if (!emitter.shouldDeclareVariablesAtTop()) {
- for (OpResult result : ifOp.getResults()) {
- if (failed(emitter.emitVariableDeclaration(result,
- /*trailingSemicolon=*/true)))
- return failure();
- }
- }
-
os << "if (";
if (failed(emitter.emitOperands(*ifOp.getOperation())))
return failure();
os << ") {\n";
os.indent();
Region &thenRegion = ifOp.getThenRegion();
- for (Operation &op : thenRegion.getOps()) {
- // Note: This prints a superfluous semicolon if the terminating yield op has
- // zero results.
- if (failed(emitter.emitOperation(op, /*trailingSemicolon=*/true)))
+ auto thenOps = thenRegion.getOps();
+ for (auto it = thenOps.begin(); std::next(it) != thenOps.end(); ++it) {
+ if (failed(emitter.emitOperation(*it, /*trailingSemicolon=*/true)))
----------------
aniragil wrote:
Yes, as in emitc::yield's case it's always superfluous. I actually took this code from scf::for's printOperation() without adding a similar comment. Will add a comment to clarify and outline into a lambda to be used for both 'then' and 'else' regions.
https://github.com/llvm/llvm-project/pull/67234
More information about the Mlir-commits
mailing list