Skip to content

Commit c772736

Browse files
Add foldCascadingCases to MissingFeatures and update case handling
1 parent 39861dd commit c772736

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct MissingFeatures {
9898
static bool opUnaryPromotionType() { return false; }
9999

100100
// SwitchOp handling
101+
static bool foldCascadingCases() { return false; }
101102
static bool foldRangeCase() { return false; }
102103

103104
// Clang early optimizations or things defered to LLVM lowering.

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,7 @@ CIRGenFunction::emitCaseDefaultCascade(const T *stmt, mlir::Type condType,
456456
if (isa<DefaultStmt>(sub) && isa<CaseStmt>(stmt)) {
457457
subStmtKind = SubStmtKind::Default;
458458
builder.createYield(loc);
459-
} else if ((isa<CaseStmt>(sub) && isa<DefaultStmt>(stmt)) ||
460-
(isa<CaseStmt>(sub) && isa<CaseStmt>(stmt))) {
459+
} else if (isa<CaseStmt>(sub) && isa<DefaultStmt, CaseStmt>(stmt)) {
461460
subStmtKind = SubStmtKind::Case;
462461
builder.createYield(loc);
463462
} else {
@@ -536,8 +535,10 @@ mlir::LogicalResult CIRGenFunction::emitCaseStmt(const CaseStmt &s,
536535
kind = cir::CaseOpKind::Range;
537536

538537
// We don't currently fold case range statements with other case statements.
539-
// TODO(cir): Add this capability.
538+
// TODO(cir): Add this capability. Folding these cases is going to be
539+
// implemented in CIRSimplify when it is upstreamed.
540540
assert(!cir::MissingFeatures::foldRangeCase());
541+
assert(!cir::MissingFeatures::foldCascadingCases());
541542
} else {
542543
caseEltValueListAttr.push_back(cir::IntAttr::get(condType, intVal));
543544
value = builder.getArrayAttr(caseEltValueListAttr);

0 commit comments

Comments
 (0)