[Mlir-commits] [mlir] [mlir][emitc] Add 'emitc.switch' op to the dialect (PR #102331)

Andrey Timonin llvmlistbot at llvm.org
Thu Aug 8 02:14:52 PDT 2024


================
@@ -449,6 +449,49 @@ static LogicalResult printOperation(CppEmitter &emitter, emitc::SubOp subOp) {
   return printBinaryOperation(emitter, operation, "-");
 }
 
+static LogicalResult emitAllExceptLast(CppEmitter &emitter,
+                                       raw_indented_ostream &os,
+                                       Region &region) {
+  for (Region::OpIterator iteratorOp = region.op_begin(), end = region.op_end();
+       std::next(iteratorOp) != end; ++iteratorOp) {
+    if (failed(emitter.emitOperation(*iteratorOp, /*trailingSemicolon=*/true)))
+      return failure();
+  }
+  os << "break;\n";
+  return success();
+}
+
+static LogicalResult printOperation(CppEmitter &emitter,
+                                    emitc::SwitchOp switchOp) {
+  raw_indented_ostream &os = emitter.ostream();
+  auto iteratorCaseValues = switchOp.getCases().begin();
+  size_t caseIndex = 0;
+
+  os << "\nswitch(" << emitter.getOrCreateName(switchOp.getArg()) << ") {";
+
+  while (caseIndex != switchOp.getNumCases()) {
----------------
EtoAndruwa wrote:

I will refactor this using `llvm::zip(getCases(), getCaseBlocks())`.

https://github.com/llvm/llvm-project/pull/102331


More information about the Mlir-commits mailing list