Can MemorySSA obtain a def-use chain or a use-def chain?

Hi. I’m a beginner of LLVM and recently digging into MemorySSA, but still confused by its design. Hope someone can give me some hints.

In MemorySSA, given a MemoryUse, how can I get all the potential definitions of it? Should I use getClobberingMemoryAccess to find its direct definition, and search into arguments when encountering MemoryPhi?

Similarly, given a MemoryDef, is there any way to get all (may-alias or must-alias) uses of it?

For the first question, yes. You can do it recursively and using the walker.

For the second question, there shouldn’t be any difference with a regular Value. You can just do

for (User *U : YOUR_DEF->users()) {
  if (MemoryPhi *MemPhi = dyn_cast<MemoryPhi>(U)) {
  } else if (MemoryUse ...)
1 Like