tensorflow / mlir

"Multi-Level Intermediate Representation" Compiler Infrastructure
1.74k stars 260 forks source link

Refactor / improve replaceAllMemRefUsesWith #87

Closed bondhugula closed 5 years ago

bondhugula commented 5 years ago

Refactor replaceAllMemRefUsesWith to split it into two methods: the new method does the replacement on a single op, and is used by the existing one.

Signed-off-by: Uday Bondhugula uday@polymagelabs.com

bondhugula commented 5 years ago

We should be able to expose such fix independently through tests: can one of the test passes be improved to expose this?

None of the current users of this method are actually affected by this fix, but there is another PR that I am about to submit on scalar replacement which relies on this (i.e., replaceAllMemRefUsesWith can fail and the failure is handled), and have a test case for that. However that PR is too big in itself and separate from this.

The reason the existing users always make sure that this methods succeeds is that replaceAllMemRefUsesWith is typically called by a pass/utility after a bunch of IR actions have already been performed (new op creation, etc.). So, if it were to fail, one would have to undo/clear up all of those actions. As a result, those clients always first check from the outside a-priori whether it'd succeed (by checking for non-dereferencing uses) and then call it.

bondhugula commented 5 years ago

Just found a way to test this - PipelineDataTransfer does check for and handle the failure. Added a test case - with this change, the IR remains correct after the replacement failure now with this PR.

Thanks!

antiagainst commented 5 years ago

Hey @joker-eph or @River707, could you take another look over this PR?

bondhugula commented 5 years ago

Anything more on this?