-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[CIR] Add the ability to detect enum argument for switch op #172236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1216,7 +1216,8 @@ def CIR_SwitchOp : CIR_Op<"switch", [ | |||||
|
|
||||||
| let arguments = (ins | ||||||
| CIR_IntType:$condition, | ||||||
| UnitAttr:$allEnumCasesCovered | ||||||
| UnitAttr:$allEnumCasesCovered, | ||||||
| UnitAttr:$handling_enum | ||||||
| ); | ||||||
|
|
||||||
| let regions = (region AnyRegion:$body); | ||||||
|
|
@@ -1230,6 +1231,7 @@ def CIR_SwitchOp : CIR_Op<"switch", [ | |||||
| let assemblyFormat = [{ | ||||||
| `(` $condition `:` qualified(type($condition)) `)` | ||||||
| (`allEnumCasesCovered` $allEnumCasesCovered^)? | ||||||
| (`handling_enum` $handling_enum^)? | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $body | ||||||
| attr-dict | ||||||
| }]; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1106,6 +1106,7 @@ mlir::LogicalResult CIRGenFunction::emitSwitchStmt(const clang::SwitchStmt &s) { | |
| terminateBody(builder, caseOp.getCaseRegion(), caseOp.getLoc()); | ||
| terminateBody(builder, swop.getBody(), swop.getLoc()); | ||
|
|
||
| swop.setHandlingEnum(s.getCond()->IgnoreParenImpCasts()->getType()->isEnumeralType()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming |
||
| swop.setAllEnumCasesCovered(s.isAllEnumCasesCovered()); | ||
|
|
||
| return res; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1282,7 +1282,7 @@ void testSwitchCoverAllCase(M m) { | |
| break; | ||
| } | ||
| } | ||
| // CIR: cir.switch(%[[ARG:.*]] : !s32i) allEnumCasesCovered { | ||
| // CIR: cir.switch(%[[ARG:.*]] : !s32i) allEnumCasesCovered handling_enum { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it feels a bit off that this reads as "all enum cases are covered and this is also an enum", should the first just be allCasesCovered as part of this change?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is not rebased on on master where there are already |
||
|
|
||
| void testSwitchNotCoverAllCase(M m) { | ||
| switch (m) { | ||
|
|
@@ -1291,4 +1291,4 @@ void testSwitchNotCoverAllCase(M m) { | |
| break; | ||
| } | ||
| } | ||
| // CIR: cir.switch(%[[ARG:.*]] : !s32i) { | ||
| // CIR: cir.switch(%[[ARG:.*]] : !s32i) handling_enum { | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another nit here: stick to one of the styles, the previous arg is using camelCase, the new one isn't.