-
Notifications
You must be signed in to change notification settings - Fork 305
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
[Sim] Flatten format string concatenations in canonicalizer #7316
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
// RUN: circt-opt %s --split-input-file --verify-diagnostics | ||
// RUN: circt-opt %s --split-input-file --verify-diagnostics --canonicalize | ||
|
||
hw.module @fmt_infinite_concat() { | ||
hw.module @fmt_infinite_concat_verify() { | ||
%lp = sim.fmt.lit ", {" | ||
%rp = sim.fmt.lit "}" | ||
// expected-error @below {{op is infinitely recursive.}} | ||
%ordinal = sim.fmt.concat (%ordinal, %lp, %ordinal, %rp) | ||
} | ||
// ----- | ||
|
||
hw.module @fmt_infinite_concat_canonicalize(in %val : i8, out res: !sim.fstring) { | ||
%c = sim.fmt.char %val : i8 | ||
%0 = sim.fmt.lit "Here we go round the" | ||
%1 = sim.fmt.lit "prickly pear" | ||
// expected-warning @below {{Cyclic concatenation detected.}} | ||
%2 = sim.fmt.concat (%1, %c, %4) | ||
// expected-warning @below {{Cyclic concatenation detected.}} | ||
%3 = sim.fmt.concat (%1, %c, %1, %c, %2, %c) | ||
// expected-warning @below {{Cyclic concatenation detected.}} | ||
%4 = sim.fmt.concat (%0, %c, %3) | ||
%5 = sim.fmt.lit "At five o'clock in the morning." | ||
// expected-warning @below {{Cyclic concatenation detected.}} | ||
%cat = sim.fmt.concat (%4, %c, %5) | ||
hw.output %cat : !sim.fstring | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm wondering if we even have to emit diagnostics and handled failure cases here. I think the canonicalization is intended to be purely opportunistic, so if we encounter a cycle we should be able to just silently not canonicalize and return failure. Or in case
getFlattenedInputs
creates a valid list of operands even if a cycle is present, we could just work with that and ignore the cycle altogether. Especially since the verifier catches this already 😃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.
That is actually how I had done this originally. I then threw it out for a potentially silly reason: If we flatten despite the presence of cycles, it becomes difficult to test as it is hard to predict (and potentially unstable for future LLVM bumps?) which op is going to fail the verification first. And annoyingly I could not find any way to tell the
-verify-diagnostics
framework that the error may be produced at different locations. Quite possibly I'm overthinking this (I usually do). But in the end I decided to just keep it as simple as possible, given that:I kept the warning in case something goes wrong and the cycle causes an infinite loop, so it doesn't just freeze quietly.
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.
That makes sense! Very cool stuff in any case 😎 🥳!