This is an archive of the discontinued LLVM Phabricator instance.

[StructurizeCfg] Update dominator info.
ClosedPublic

Authored by sepavloff on Dec 25 2016, 11:44 PM.

Details

Summary

In some cases StructurizeCfg updates root node, but dominator info
remains unchanges, it causes crash when expensive checks are enabled.

This change fixes PR27488.

Diff Detail

Repository
rL LLVM

Event Timeline

sepavloff updated this revision to Diff 82492.Dec 25 2016, 11:44 PM
sepavloff retitled this revision from to [StructurizeCfg] Update dominator info..
sepavloff updated this object.
sepavloff added reviewers: arsenm, chandlerc.
sepavloff added a subscriber: llvm-commits.
hfinkel added a subscriber: hfinkel.
hfinkel added inline comments.
include/llvm/Support/GenericDomTree.h
581 ↗(On Diff #82492)

you should add that the old root node is assumed to be a successor of the new root node. I'm somewhat concerned that this is not really workable for post-dom trees where multiple roots are possible. Thoughts?

587 ↗(On Diff #82492)

You're calling getNode on a null pointer? That seems wasteful, because you're doing a map lookup on a nullptr.

dberlin edited edge metadata.Jan 8 2017, 7:33 PM

I'm fairly confused.
Forward dominators should not have multiple roots at once without multiple actual entry blocks (which i didn't think we supported).
Yet you seem to be creating such a thing.
That seems ... wrong.
What am i missing?

Post-dom can have multiple roots due to multiple exit blocks, but honestly, we kind of mess this up, and would likely be much better off having a single virtual root, and removing the support for multiple real roots
(which is what everyone else does)

I'm fairly confused.
Forward dominators should not have multiple roots at once without multiple actual entry blocks (which i didn't think we supported).
Yet you seem to be creating such a thing.
That seems ... wrong.
What am i missing?

Post-dom can have multiple roots due to multiple exit blocks, but honestly, we kind of mess this up, and would likely be much better off having a single virtual root, and removing the support for multiple real roots
(which is what everyone else does)

Oh, forget it, i see that you are swapping the root node.

This still won't work well with post-dom unless we move to a virtual root.
(and then you'd never have to swap the root node in either case)

sepavloff updated this revision to Diff 83602.Jan 9 2017, 2:59 AM
sepavloff edited edge metadata.

Updated patch

As pointed out by @hfinkel and @dberlin, this code won't work with
post-dominator trees. It is possible to extend the fix to support
such trees also, but it is more complex. In the case of several exit
nodes we need to specify which root is replaced, and if the root is
virtual, this operation makes no sense. So the operation is now
confined to forward dominator trees by putting appropriate assertion
checks. There are some functions in DominatorTreeBase that impose
similar restriction.

Adding node as a new root is now implemented by a separate function
instead of reusing addNewBlock. It should prevent from accidental
root changes as a user have to explicitly specify the intent.

A small piece of unit test was added that is similar to the operation
made by StructurizeCfg pass.

Seems reasonable to me. @dberlin , what do you think?

I think this is fine for now. We can deal with the root issue itself later :)

hfinkel accepted this revision.Jan 9 2017, 2:47 PM
hfinkel added a reviewer: hfinkel.
This revision is now accepted and ready to land.Jan 9 2017, 2:47 PM
This revision was automatically updated to reflect the committed changes.