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

[ExtractTestCode] Specify non-empty unqiue port names #6283

Merged
merged 7 commits into from
Oct 12, 2023

Conversation

prithayan
Copy link
Contributor

Update ETC to add non-empty and unique port names. The name itself is not important, but this exposes a bug in inconsistent port names with the hw.instance and the ModuleType.
This is a temporary fix, to unblock downstream tools, while the actual bug is fixed.

auto name = getNameForPort(port.value(), srcPorts);
// Append the port index to create unique names.
auto name =
b.getStringAttr(getNameForPort(port.value(), srcPorts).getValue() +
Copy link
Member

Choose a reason for hiding this comment

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

Maybe can we do something simpler and more stable naming like this?

Suggested change
b.getStringAttr(getNameForPort(port.value(), srcPorts).getValue() +
auto name = getNameForPort(port.value(), srcPorts);
name = name.getValue().empty()? b.getStringAttr("arg" + Twine(port.index()));

Copy link
Member

Choose a reason for hiding this comment

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

Also “arg” seems to be a bit weird to me, can we do name this “port”?

@prithayan
Copy link
Contributor Author

So, the ETC introduces port name conflicts, that exposes the same bug, inconsistent port names on instance and module. So, we either check and rename only conflicting port names or create unique names by suffixing with the port index. I assumed the port names donot matter here, so suffixed with the index for all ports, instead of adding a check.
I am working on another PR to fix the LegalizeNames to update argNames on the instance op also. So, we could skip the unique names logic here.

@prithayan
Copy link
Contributor Author

After looking at LegalizeNames realized the conflicting port names case cannot be handled there. This is inherently a problem of SSA names leaking to the module type and port names.
Fixed the logic here to create unique names only on name conflict.

@jackkoenig
Copy link
Contributor

LGTM but may want someone who knows the code better than me to review

Comment on lines 207 to 208
llvm::SmallSetVector<StringRef, 8> portNames;
portNames.insert("");
Copy link
Member

Choose a reason for hiding this comment

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

Can we use Namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, we should use the Namespace. Also added a check for empty string to use a stable and deterministic naming for them.
For such use cases, we need a Namespace::newName which adds a given suffix only on conflict, the current version always adds the suffix.

Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

LGTM

@prithayan prithayan merged commit cbe82b9 into main Oct 12, 2023
5 checks passed
@prithayan prithayan deleted the dev/nandor/no-empty-ports branch October 12, 2023 14:21
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.

5 participants