This is an archive of the discontinued LLVM Phabricator instance.

Add new MemoryAccess creation API to MemorySSA, use it for updating
AbandonedPublic

Authored by dberlin on Mar 11 2016, 9:58 AM.

Details

Summary

Not yet ready for committing, want to make sure i'm going in the right direction before i go too much further :)

This patch adds a new access creation API to MemorySSA. It also shows how it gets used in MergedLoadStoreMotion (the only relevant part is in hoistInstruction. Note that this code works and passes the testcases).

Essentially, it allows one to create new accesses that have a known clobbering definition (such as when you hoist a load). This handles pretty much every case an existing pass comes up with for hoisting/replacement.

Creating MemoryAccesses for *sinking*, in the case of MLSM, simply requires an API to create phi nodes where you want them as well (we already know what all of the phi operands should be, etc).

Making this more generic, and creating MemoryAccesses *without* knowing the clobbering definition ahead of time would require, for MemoryUse's and MemoryDef's:
Normal case - finding dominating definition
Worst case - possible insertion of phi nodes to merge clobbering definitions, if you insert below the last point a group of memorydefs were used.

At least for all passes currently being converted (MLSM, GVN, MemCpyOptimizer, etc), from what i see, we know when we would have to insert MemoryPhi nodes, and so, with a CreateMemoryPhi API (not added yet), combined with this API, we could handle updates.

This would leave it to the passes to find the right clobbering definition (we could provide a utility) when they don't know it. We could also create a version of createMemoryAccess that finds the dominating definition given an insertion point (it's pretty easy), under the *assumption* that it does not require phi node insertion.

In any case, thoughts and nitpicks on the API welcome.

Unit tests and other things to come once that is settled (and then re-review will be requested).

Diff Detail

Event Timeline

dberlin retitled this revision from to Add new MemoryAccess creation API to MemorySSA, use it for updating.
dberlin updated this object.

Thoughts/bikeshedding on MemSSA parts

include/llvm/Transforms/Utils/MemorySSA.h
530

Nit: Would createMemoryAccessIn be better to differentiate this (which handles BB insertion) from the other ones (which don't)?

lib/Transforms/Utils/MemorySSA.cpp
366

...That we have to have this cast is both obnoxious and a mistake on my part. r263286 makes createNewAccess return a UseOrDef (since that's what it was doing anyway)

379

Nit: std::find_if?

dberlin marked 2 inline comments as done.Mar 12 2016, 10:12 AM
dberlin added inline comments.
include/llvm/Transforms/Utils/MemorySSA.h
530

Sounds good.
To be honest, i hate the names i came up with, but can't think of anything better :)

dberlin abandoned this revision.Jul 6 2016, 9:22 PM