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

Dead code eliminator: use default if other actions won't be executed #56

Merged
merged 7 commits into from
Feb 24, 2024

Conversation

RabbitWhite1
Copy link
Collaborator

No description provided.

Copy link
Owner

@fruffy fruffy left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

passes/elim_dead_code.cpp Outdated Show resolved Hide resolved
passes/elim_dead_code.cpp Outdated Show resolved Hide resolved
@fruffy
Copy link
Owner

fruffy commented Feb 23, 2024

Fixes #54.

@fruffy fruffy linked an issue Feb 23, 2024 that may be closed by this pull request
if (defaultAction != nullptr) {
auto decl = getActionDecl(refMap, *defaultAction);
if (decl.has_value() && !decl.value()->body->components.empty()) {
printInfo("Replacing table apply with default action %1%", defaultAction);
Copy link
Owner

Choose a reason for hiding this comment

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

Well, we can still add some form of eliminated node here. Otherwise we do not track that we have modified the table here. What do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

In the sense of eliminatedNodes.push_back(stmt); or something similar. Our current ref files do not quite capture this ambiguity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. I think a better way is to create another vector to store these because they are not simply eliminated. What do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

You could make it a vector of pairs, with the original node and the replaced node.

There is a question on the performance impact when we keep adding nodes. Recall that this code may run on every control-plane update message. But I do not think it will have much impact because we only invoke the elimination when the semantics have changed. Still, it's something we should keep in mind.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You could make it a vector of pairs, with the original node and the replaced node.

That sounds good. I will do it soon.

And yes, I agree on the performance thing.

@RabbitWhite1
Copy link
Collaborator Author

RabbitWhite1 commented Feb 23, 2024

Support recording replacement, and updated reference_checker and reference files accordingly. PTAL.

<< node->getSourceInfo().toPosition().sourceLine << ": "
<< sourceFragment;
} else {
// FIXME: any elegant solution to just print first line of `replaced->toString()`?
Copy link
Owner

Choose a reason for hiding this comment

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

Do not use toString it only gives incomplete node information, use the source fragment. I think it is fine to have multiple lines. But we need to check how that looks like. Let's fix that in a separate PR.

Also make sure the source info is valid. It should be by necessity of construction, but it is good to check that this invariant holds.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. Will do that.

@RabbitWhite1 RabbitWhite1 merged commit d8fba04 into master Feb 24, 2024
2 checks passed
@RabbitWhite1 RabbitWhite1 deleted the zhanghan/default-action branch February 24, 2024 00:52
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.

Does current table_executor consider default action reachability?
2 participants