8000 [DC] Add canonicalization patterns by mortbopet · Pull Request #5158 · llvm/circt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[DC] Add canonicalization patterns #5158

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

Merged
merged 3 commits into from
May 15, 2023
Merged

[DC] Add canonicalization patterns #5158

merged 3 commits into from
May 15, 2023

Conversation

mortbopet
Copy link
Contributor

No description provided.

Copy link
Contributor
@teqdruid teqdruid left a comment

Choose a reason for hiding this comment

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

Very partial review before I head out for the day.

A question: do tokens and values have implicit fork semantics? A quick skim through these seem to imply that they do. For instance, you can't have two joins with all the same inputs without said input (token) having at least two consumers. Similarly for values (which are basically token + data if I understand correctly), it's not possible to have two identical unpacks unless you have implicit fork semantics.

@@ -121,8 +121,152 @@ FunctionType CallOp::getCalleeType() {
// JoinOp
// =============================================================================

class IdenticalJoinCanonicalizationPattern : public OpRewritePattern<JoinOp> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put these in a separate file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also the folds to be consistent with CombFolds.cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

def HasOneOperand : Constraint<CPred<"$_self.size() == 1">, "has one operand">;
def HasOneResult : Constraint<CPred<"$_self.size() == 1">, "has one result">;

def EliminateSimpleJoinPattern : Pat<(JoinOp $arg), (replaceWithValue $arg),
Copy link
Contributor

Choose a reason for hiding this comment

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

These could be folds, correct? There are a bunch of advantages to using folds rather than canonicalization patterns, which I'm pretty sure are the only way these can be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bear in mind that we're gonna want to do constant propagation analysis which uses folds. Dunno if that applies here -- just a general comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These have been converted to folds.

@mortbopet mortbopet force-pushed the dev/mpetersen/dc_2 branch 4 times, most recently from 9bd020d to 6ffd187 Compare May 10, 2023 11:02
@mortbopet mortbopet force-pushed the dev/mpetersen/dc_3 branch 2 times, most recently from 6c5f33b to a81d295 Compare May 10, 2023 11:33
@mortbopet mortbopet force-pushed the dev/mpetersen/dc_2 branch from 6ffd187 to 4b77a0a Compare May 11, 2023 07:25
@mortbopet
Copy link
Contributor Author

do tokens and values have implicit fork semantics?

Yep - i should add that to the rationale. Fork semantics, as well as sink semantics (i.e. values with 0 uses are legal) are implicit in the IR. Some lowering (e.g. to hardware) then have an additional requirement that this is made explicit. I think this is a fair design point, seeing as it makes writing canonicalization a fair bit easier, not having to peek through forks everywhere, and then later (if you indeed need forks in your IR), you can easily materialize those using #5159.

@mortbopet mortbopet changed the base branch from dev/mpetersen/dc_2 to main May 11, 2023 07:55
@mortbopet mortbopet force-pushed the dev/mpetersen/dc_3 branch from a81d295 to 6404ef2 Compare May 11, 2023 07:56
@mortbopet
Copy link
Contributor Author
mortbopet commented May 12, 2023

Will remove the "duplicate pack" canonicalization - this is just CSE. Furthermore, join canonicalization can be simplified by marking it as commutative.

@mortbopet mortbopet merged commit 3aed4df into main May 15, 2023
@@ -118,8 +304,52 @@ LogicalResult UnpackOp::inferReturnTypes(
// PackOp
// =============================================================================

class EliminateMultiplePackPattern : public OpRewritePattern<PackOp> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does something like this exist upstream and would be automatically generated with some trait on pack? This seems like CSE to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right - i actually already removed this canonicalization on my dev branch given that it's CSE'd automatically.

@teqdruid
Copy link
Contributor

Sorry about the delinquent review. That's what happens when you tell me you're not in a rush to merge :P

@darthscsi darthscsi deleted the dev/mpetersen/dc_3 branch June 4, 2024 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0