This is an archive of the discontinued LLVM Phabricator instance.

[StructurizeCFG] Refactor NearestCommonDominator.
ClosedPublic

Authored by jlebar on Nov 22 2016, 1:47 PM.

Details

Summary

As far as I can tell, doing our own computations in
NearestCommonDominator is a false optimization -- DomTree will build up
what appears to be exactly this data when it decides it's worthwhile.
Moreover, by building the cache ourselves, we cannot take advantage of
the cache that the domtree might have available.

In addition, I am not convinced of the correctness of the original code.
In particular, setting ResultIndex = 1 on the first addBlock instead of
setting it to 0 is quite fishy. Similarly, it's not clear to me that
setting IndexMap[Node] = 0 for every node as we walk up the tree finding
a common parent is correct. But rather than ponder over these
questions, I'd rather just make the code do the obviously-correct thing.

This patch also changes the NearestCommonDominator API a bit, improving
the names and getting rid of the boolean parameter in addBlock -- see
http://jlebar.com/2011/12/16/Boolean_parameters_to_API_functions_considered_harmful..html

Diff Detail

Repository
rL LLVM

Event Timeline

jlebar updated this revision to Diff 78943.Nov 22 2016, 1:47 PM
jlebar retitled this revision from to [StructurizeCFG] Refactor NearestCommonDominator..
jlebar updated this object.
jlebar added a reviewer: arsenm.
jlebar added a subscriber: llvm-commits.
arsenm edited edge metadata.Nov 22 2016, 1:50 PM

Have you done any compile time measurements of this?

Have you done any compile time measurements of this?

I compiled Sema.cpp and X86ISelLowering.cpp to bitcode with -O0 and -O3, then ran opt --time-passes -structurizecfg. No difference before and after this change.

nhaehnle accepted this revision.Nov 28 2016, 6:40 AM
nhaehnle added a reviewer: nhaehnle.
nhaehnle added a subscriber: nhaehnle.

I agree, this is a nice conceptual simplification. LGTM.

This revision is now accepted and ready to land.Nov 28 2016, 6:40 AM

Thank you for the review!

This revision was automatically updated to reflect the committed changes.