This is an archive of the discontinued LLVM Phabricator instance.

[CodeMoverUtils] Move OrderedInstructions to CodeMoverUtils
ClosedPublic

Authored by RithikSharma on May 27 2020, 9:27 AM.

Details

Summary

This patch moves OrderedInstructions to CodeMoverUtils as It was the only place where OrderedInstructions is required.

Diff Detail

Event Timeline

RithikSharma created this revision.May 27 2020, 9:27 AM
nikic added a comment.EditedMay 27 2020, 9:46 AM

You don't need an actual OrderedInstructions class. You can simply make domTreeLevelBefore() a static function in CodeMoverUtils.cpp. Replace the localDominates() call with Instruction::comesBefore().

Whitney retitled this revision from Move OrderedInstructions to CodeMoverUtils to [CodeMoverUtils] Move OrderedInstructions to CodeMoverUtils.May 27 2020, 11:22 AM

You don't need an actual OrderedInstructions class. You can simply make domTreeLevelBefore() a static function in CodeMoverUtils.cpp. Replace the localDominates() call with Instruction::comesBefore().

Moving OrderedInstructions functions to CodeMoverUtils.cpp and making them static doesn't allow the unittest to pass! The unittest requires the call of "dominates" and the only way to fulfill is to define "dominates" into CodeMoverUtils.h which is not the preferred step!

nikic added a comment.Jun 5 2020, 1:28 PM

Moving OrderedInstructions functions to CodeMoverUtils.cpp and making them static doesn't allow the unittest to pass! The unittest requires the call of "dominates" and the only way to fulfill is to define "dominates" into CodeMoverUtils.h which is not the preferred step!

Not sure I follow. As far as I know, OrderedInstructions::dominates() is same as DominatorTree::dominates() at this point, so you can just use the DominatorTree method. I'm also not sure what the added DominanceTest is force. It doesn't seem related to CodeMoverUtils and only tests dominance queries, for which we already have dedicated domtree construction tests.

Whitney added inline comments.Jun 8 2020, 7:36 AM
llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
103

No need, is not doing anything extra compare to DominatorTree::dominates defined in lib/IR/Dominators.cpp

116

As suggested by @nikic , change this call to comesBefore. And remove OrderedInstructions::localDominates.

119

Did you accidentally removed the line: return DA->getLevel() < DB->getLevel();?
Don't forget to build and test your change before updating your patch.

333

Please update the base of your diff. It is already calling domTreeLevelBefore before this patch.

llvm/unittests/Transforms/Utils/CodeMoverUtilsTest.cpp
652 ↗(On Diff #266576)

remove this test.

This update removes the OrderedInstructions class from CodeMoverUtils and also removes it's exposure to other transformation passes, both localDominates and domTreeLevelBefore is made as static functions and are present in CodeMoverUtils.cpp. OrderedInstructions::dominates() has been removed from CodeMoverUtils.cpp due to it's existance in DominatorTree::dominates(), the dominance test moved from OrderedInstructionsTest.cpp to CodeMoverUtilsTest.cpp is also removed.

Whitney added inline comments.Jun 9 2020, 4:02 AM
llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
96

Am I right that function localDominates is now dead? If so, can you remove it as well?

This update removes localDominates which is not required, only one OrderedInstructions is required which is domTreeLevelBefore which is now a part of CodeMoverUtils.cpp

Whitney added inline comments.Jun 9 2020, 7:00 AM
llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
343

Why const is removed?

RithikSharma marked 2 inline comments as done.

This update fixes the existing errors in the patch.

Whitney accepted this revision.Jun 9 2020, 11:06 AM

The patch LGTM. @nikic What do you think?

This revision is now accepted and ready to land.Jun 9 2020, 11:06 AM
nikic accepted this revision.Jun 17 2020, 10:29 AM

Sorry for the delay, this LGTM as well.

RithikSharma closed this revision.Jul 22 2020, 5:36 AM
RithikSharma marked 3 inline comments as done.
llvm/unittests/Analysis/CMakeLists.txt