This is an archive of the discontinued LLVM Phabricator instance.

[CFLAA] Teach CFLAndersAliasAnalysis to discern reads from writes
ClosedPublic

Authored by grievejia on Jul 15 2016, 4:34 PM.

Details

Summary

This patch introduces no functional changes.

The original 4-state state machine we used previously does not provide us with enough information to tell value reads from value writes. When given a reachable value alias pair (X, Y), we want to be able to tell if the function (transitively) assigns X to Y, or if the function (transitively) assigns Y to X, or if the function (transitively) assigns a third value Z to both, or if X and Y alias each other only because someone above X and someone above Y alias each other. The "directions" of assignments are very important to us since we need them to generate precise function summaries and yield better mod/ref results.

To keep track of assignment directions, I tried to add more states to the state machine. The semantics of the new machine should be exactly the same as before, except that given a particular state there's no ambiguities any more regarding what is read and what is written. Please refer to the codes for more details on the meaning of those newly added states.

I also tried to simplify the state machine matching codes with some macro abuses. We might want to get rid of those macros someday, but for now I think they do make things cleaner.

Diff Detail

Event Timeline

grievejia updated this revision to Diff 64210.Jul 15 2016, 4:34 PM
grievejia retitled this revision from to [CFLAA] Teach CFLAndersAliasAnalysis to discern reads from writes.
grievejia updated this object.
grievejia added a subscriber: llvm-commits.

Thanks for the patch!

lib/Analysis/CFLAndersAliasAnalysis.cpp
86

Why are we now starting from 1?

92

Out of curiosity, do we gain anything from having FlowToWriteOnly on something that already has FlowToReadWrite on it?

Specifically, given:

ReachabilitySet R = whatever;
R.insert(FromVal, ToVal, FlowToReadWrite);
R.insert(FromVal, ToVal, FlowToWriteOnly);

Is the second insert at all meaningful to us? If not, can we add a FIXME or TODO somewhere noting that we may be able to do less propagations if we check for this later?

(Same question for FlowFromMemAliasNoReadWrite vs FlowFromMemAliasReadOnly, and FlowToMemAliasWriteOnly vs FlowToMemAliasReadWrite)

356

Can this be a lambda instead?

377

Can this (and the 2 below) be lambdas instead?

grievejia added inline comments.Jul 18 2016, 3:58 PM
lib/Analysis/CFLAndersAliasAnalysis.cpp
86

There was a state "FlowFromNoReadWrite" which was labelled 0. It was supposed to be the starting state. Later I found that we don't really need it since we do not store identity mapping (X, X) in ReachabilitySet, so I removed that state.

I thought the starting index doesn't really matter that much. I'm OK with any choice here.

92

The state FlowToWriteOnly does carry important information: if x is reachable from y at FlowToWriteOnly state, we know that y is (transitively) assigned to x. If x is reachable from y at FlowToReadWrite state, then there's a third value z which gets assigned to both x and y. The distinction here is basically what motivates this patch.

377

... I think you are right. Let me change them to lambdas.

lib/Analysis/CFLAndersAliasAnalysis.cpp
86

The only reason I asked is because we're using these as indices into a bitset. 7 bits vs 8 bits is a wash; I was just making sure we weren't sneakily using the bits[0] bit in some way. :)

92

Ahh, now that makes sense. Thanks for clarifying!

grievejia marked 2 inline comments as done.Jul 19 2016, 9:21 AM
grievejia added inline comments.
lib/Analysis/CFLAndersAliasAnalysis.cpp
92

Now that you mentioned it, maybe XXXReadWrite is not a good name for those states. At a first glance it looks like if X is reachable from Y at XXXReadWrite states it means that X is both read from and written to Y, yet this is not true: what it really means is that the path from X to Y contains both assignment edges and reverse assignment edges, which implies a third value written to both.

Let me add some comments that try to clarify this.

grievejia updated this revision to Diff 64512.Jul 19 2016, 9:22 AM
grievejia edited edge metadata.

Replace macros with lambdas.

george.burgess.iv edited edge metadata.

LGTM; thanks for adding the clarification!

This revision is now accepted and ready to land.Jul 19 2016, 1:37 PM
This revision was automatically updated to reflect the committed changes.