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

Clone empty blocks before def-use analysis #3653

Merged
merged 5 commits into from
Nov 3, 2022

Conversation

mihaibudiu
Copy link
Contributor

Signed-off-by: Mihai Budiu mbudiu@vmware.com
Fixes #3650
This was harder to fix than I expected. The visitor infra is too smart for its own good: it wouldn't duplicate empty blocks since it realizes they are identical. So you have to add annotations to empty blocks to make then different, then remove them again.

This also uncovered a bug in the frontend where RemoveUnusedDeclarations was called instead of RemoveAllUnusedDeclarations. That won't happen again, since I made the constructor private.

Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
@mihaibudiu
Copy link
Contributor Author

@fruffy this fails in testgen with the following error:
Required regular expression not found. Regex=[Duplicate objects of type '.*' with name '.*'

@fruffy
Copy link
Collaborator

fruffy commented Nov 2, 2022

It looks like this also fixes #3620.

@mihaibudiu
Copy link
Contributor Author

If it fixes #3620 it is a coincidence. That one I still have to work on.

Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
@fruffy
Copy link
Collaborator

fruffy commented Nov 3, 2022

If it fixes #3620 it is a coincidence. That one I still have to work on.

We can leave the issue open then, but I do not have a reproducing test for this right now. Either way, it must be removed from the xfails here.

class SimplifyDefUse : public PassManager {
class Cloner : public ClonePathExpressions {
public:
Cloner() { setName("Cloner"); }
const IR::Node* postorder(IR::EmptyStatement* stat) override {
// You cannot clone an empty statement, since
// the visitor claims it's equal to the original one.
// So we cheat and make an empty block.
// So we convert it to an empty block.
return new IR::BlockStatement(stat->srcInfo);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you not directly produce a block statement with an annotation here? I do not quite understand some of the tricks that are being used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do produce an empty block, but no annotation is needed here.
There is really no trick, except I need each statement to have its own IR node.

void clear() {
// This ensures that a clear map is never up-to-date,
// since the 'fake' node cannot appear in a program.
program = fake;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of this hack? To force a refresh of the program map every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would not call it a hack.
Each map stores the program that it was generated on. If the program hasn't changed, the map is good.
But an empty map is never up-to-date.

Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
@mihaibudiu
Copy link
Contributor Author

If it fixes #3620 it is a coincidence. That one I still have to work on.

We can leave the issue open then, but I do not have a reproducing test for this right now. Either way, it must be removed from the xfails here.

It should be easy to create a reproduction by having a metadata and a header structure with a common field name.

Mihai Budiu added 2 commits November 3, 2022 11:27
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
Copy link

@vhavel vhavel left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Defuse analysis fails with "Overwriting definitions"
3 participants