Skip to content
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

dialects: (scf) add index_switch #3157

Merged
merged 8 commits into from
Sep 16, 2024
Merged

dialects: (scf) add index_switch #3157

merged 8 commits into from
Sep 16, 2024

Conversation

alexarice
Copy link
Collaborator

Adds scf.index_switch and test

@alexarice alexarice added dialects Changes on the dialects testing PRs that modify tests labels Sep 10, 2024
@alexarice alexarice self-assigned this Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.03%. Comparing base (80e2129) to head (f1400d8).
Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3157      +/-   ##
==========================================
+ Coverage   90.00%   90.03%   +0.03%     
==========================================
  Files         427      430       +3     
  Lines       53860    54067     +207     
  Branches     8344     8367      +23     
==========================================
+ Hits        48477    48681     +204     
- Misses       4036     4038       +2     
- Partials     1347     1348       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

xdsl/dialects/scf.py Outdated Show resolved Hide resolved
xdsl/dialects/scf.py Outdated Show resolved Hide resolved
Comment on lines 733 to 753
raise VerifyException("case values should have type i64")

if len(self.cases.data) != len(self.case_regions):
raise VerifyException(
f"has {len(self.case_regions)} case regions but {len(self.cases.data)} case values"
)

cases = self.cases.data.data
if len(set(cases)) != len(cases):
raise VerifyException("has duplicate case value")

def verify_region(region: Region, name: str):
yield_op = region.block.last_op
if not yield_op or not isinstance(yield_op, Yield):
raise VerifyException(f"expected region {name} to end with `scf.yield`")

if yield_op.operand_types != self.result_types:
raise VerifyException(
f"region {name} returns values of types {yield_op.operand_types}"
f"but expected {self.result_types}"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add tests for these?

Comment on lines 755 to 757
verify_region(self.default_region, "default")
for name, region in zip(cases, self.case_regions):
verify_region(region, str(name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verification is a direct translation of the verification for the mlir operation. It's as necessary as any verification I guess

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect I could use SingleBlockImplicitTerminator and leave it at that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My impression is that the regions of the operation are already verified by the time the custom verifier is called, is that not the case? Can you check that they're not verified twice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify_region is a custom function defined above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, I thought we had Operation.verify call into helper methods on the operation, and that this was also doing this manually. In that case all good, although maybe it might be better as a private method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, github hid this from me before merging, is the method not private anyway given it's defined locally in the function? (Given this is python I am expecting the answer to be no)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should really be a bit more attentive in PRs, I'm not sure how I missed it. It's private indeed, but that just means that you define it every time that you verify this operation. Ideally, it should be a static method with an underscore, so that it's defined only once, when the file is imported.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I'll make a quick pr

@alexarice
Copy link
Collaborator Author

Added the appropriate traits as they should have been there anyway

@alexarice alexarice merged commit b5dd78f into main Sep 16, 2024
14 checks passed
@alexarice alexarice deleted the alexarice/index_switch branch September 16, 2024 17:03
alexarice added a commit that referenced this pull request Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects testing PRs that modify tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants