This is an archive of the discontinued LLVM Phabricator instance.

[CFLAA] Propagate StratifiedAttrs from callee to caller
ClosedPublic

Authored by grievejia on Jun 23 2016, 9:10 AM.

Details

Summary

This patch adds yet another entry in CFLAAResult::FunctionInfo that keeps track of what StratifiedAttrs we should propagate for those InterfaceValues. This is crucial for the soundness of the analysis since otherwise the caller won't be able to know if the arguments they pass to the callee will escape/alias globals/alias unknown pointers or not.

Previously, anything below the arguments of the callee is marked with "AttrUnknown". This is too conservative, because although the callee doesn't know what's below those arguments, the caller has a perfect idea. It would be nice to distinguish between "things the caller knows but the callee doesn't" and "things that both caller and callee don't know". In this patch, we introduce another StratifiedAttr called "AttrCaller" to represent the former case, and let "AttrUnknown" to represent only the latter case. We also handle these two attributes differently in our interprocedural analysis: AttrUnknown needs to be propagated to the caller, while AttrCaller doesn't have to.

In addition to AttrUnknown, AttrEscaped and AttrGlobal are also propagated. Those are the three attributes that I think are meaningful to the caller.

With this patch I am finally able to turn the last two remaining xfail test cases into xpass. Yay!

Diff Detail

Event Timeline

grievejia updated this revision to Diff 61683.Jun 23 2016, 9:10 AM
grievejia retitled this revision from to [CFLAA] Propagate StratifiedAttrs from callee to caller.
grievejia updated this object.
grievejia added a subscriber: llvm-commits.

Thanks for the patch!

lib/Analysis/CFLAliasAnalysis.cpp
94

Nit: Please add a period.

107

Nit: Period, please.

151

Is there a reason this isn't a StratifiedAttrs? (The more we add here, the more I think having a separate type for a single bit and a set of bits was a dumb decision, but we can deal with that later)

267

Please rebase -- GCC didn't like the name of this variable. :)

(Don't worry about compiling with GCC before you throw a patch up for review; I'm happy to do it prior to submitting)

645

Nit: Is there a reason this isn't a member of the CFLGraphBuilder?

736

Do we need a .reset(AttrCallerIndex) here, as well?

828

Please remove the extra brackets

test/Analysis/CFLAliasAnalysis/interproc-store-arg-unknown.ll
20

Yay accuracy

grievejia updated this revision to Diff 61745.Jun 23 2016, 4:47 PM
grievejia edited edge metadata.
grievejia marked 6 inline comments as done.

Merged master, and updated several places according to the review.

lib/Analysis/CFLAliasAnalysis.cpp
645

Can you elaborate? Which variable did you refer to?

george.burgess.iv edited edge metadata.

LGTM. Thanks for the patch!

lib/Analysis/CFLAliasAnalysis.cpp
645–647

Sure -- why doesn't CFLGraphBuilder have a member of type GetEdgesVisitor, instead of constructing it in-place here? It doesn't really matter either way, I'm just wondering if there's a reason, since all we're basically doing is loading it up with member variables and calling visit.

This revision is now accepted and ready to land.Jun 23 2016, 5:47 PM
grievejia added inline comments.Jun 23 2016, 6:02 PM
lib/Analysis/CFLAliasAnalysis.cpp
645–647

But even if GetEdgeVisitor becomes a member of CFLGraphBuilder, we still have to load the member up and call visit, no?

Thanks for the review!

This revision was automatically updated to reflect the committed changes.