[Mlir-commits] [mlir] [mlir][emitc][cf] add 'cf.switch' support in CppEmitter (PR #101478)
Simon Camphausen
llvmlistbot at llvm.org
Thu Aug 1 05:29:16 PDT 2024
================
@@ -774,6 +774,41 @@ static LogicalResult printOperation(CppEmitter &emitter,
return printBinaryOperation(emitter, operation, "||");
}
+static LogicalResult printOperation(CppEmitter &emitter,
+ cf::SwitchOp switchOp) {
+ raw_indented_ostream &os = emitter.ostream();
+ auto iteratorCaseValues = (*switchOp.getCaseValues()).begin();
+ auto iteratorCaseValuesEnd = (*switchOp.getCaseValues()).end();
+
+ os << "\nswitch(" << emitter.getOrCreateName(switchOp.getFlag()) << ") {";
+
+ for (const auto caseBlock : switchOp.getCaseDestinations()) {
+ if (iteratorCaseValues == iteratorCaseValuesEnd)
+ return switchOp.emitOpError("case's value is absent for case block");
+
+ os << "\ncase " << *(iteratorCaseValues++) << ": {\n";
+ os.indent() << "goto ";
----------------
simon-camp wrote:
You need to copy the operands into the variables for the successor block arguments like [here](https://github.com/llvm/llvm-project/blob/2feb0586b75bae87bb6e053b502ec7739da37837/mlir/lib/Target/Cpp/TranslateToCpp.cpp#L548-L554).
https://github.com/llvm/llvm-project/pull/101478
More information about the Mlir-commits
mailing list