================ @@ -428,6 +429,52 @@ mlir::LogicalResult CIRGenFunction::emitBreakStmt(const clang::BreakStmt &s) { return mlir::success(); } +const CaseStmt *CIRGenFunction::foldCaseStmt(const clang::CaseStmt &s, + mlir::Type condType, + mlir::ArrayAttr &value, + cir::CaseOpKind &kind) { + const CaseStmt *caseStmt = &s; + const CaseStmt *lastCase = &s; + SmallVector<mlir::Attribute, 4> caseEltValueListAttr; + + // Fold cascading cases whenever possible to simplify codegen a bit. + while (caseStmt) { + lastCase = caseStmt; + + auto intVal = caseStmt->getLHS()->EvaluateKnownConstInt(getContext()); + + if (auto *rhs = caseStmt->getRHS()) { + auto endVal = rhs->EvaluateKnownConstInt(getContext()); + SmallVector<mlir::Attribute, 4> rangeCaseAttr = { + cir::IntAttr::get(condType, intVal), + cir::IntAttr::get(condType, endVal)}; + value = builder.getArrayAttr(rangeCaseAttr); + kind = cir::CaseOpKind::Range; + + // We may not be able to fold rangaes. Due to we can't present range case + // with other trivial cases now. + return caseStmt; ---------------- andykaylor wrote:
It took me a while to figure this out, but the check on line 465 guarantees that we will never get here unless this was the first case we are trying to fold. Can you add an assertion that verifies that? If the code is ever changed to make this untrue, we could easily lose cases. https://github.com/llvm/llvm-project/pull/138003 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits