This is an archive of the discontinued LLVM Phabricator instance.

[CFLAA] Add support for field offset in CFLGraph
ClosedPublic

Authored by grievejia on Jul 20 2016, 2:50 PM.

Details

Summary

This patch introduces no functional changes.

We used to treat GEPs like bitcasts and ignore the offsets. Such an approach is inadequate if we were to move to a field-sensitive analysis. We use accumulateConstantOffset() in this patch to keep track of field offsets in CFLGraphBuilder when the given gep can be decomposed into a base and a constant offset.

To call accumulateConstantOffset() we need to perform a cast to GEPOperator in visitGetElementPtrInst(). This cast will fail when visitGetElementPtrInst() gets a ConstantExpr disguised as a GetElementPtrInst as its argument. I'm not 100% sure what the reason for the casting failure is, but a deeper problem here is that we handle ConstantExprs by casting them into their corresponding Instructions, and such a treatment is very hacky and fragile. I ended up fixing the problem by rewriting visitConstExpr() and letting it do its job in a proper manner.

More patches on field-sensitivity will come in the near future.

Diff Detail

Event Timeline

grievejia updated this revision to Diff 64768.Jul 20 2016, 2:50 PM
grievejia retitled this revision from to [CFLAA] Add support for field offset in CFLGraph.
grievejia updated this object.
grievejia added a subscriber: llvm-commits.

Thanks for the patch!

lib/Analysis/CFLGraph.h
30

IIRC, some MSVC versions we support don't have a constexpr max() function, so this will break those bots. Please either use a static LLVM_CONSTEXPR variable, or wrap this in a function. :)

312

Please use cast<GEPOperator> instead of dyn_cast + assert.

498

Same "please use cast" comment

grievejia updated this revision to Diff 64781.Jul 20 2016, 3:45 PM
grievejia edited edge metadata.
grievejia marked 3 inline comments as done.

Style fixes.

george.burgess.iv edited edge metadata.

LGTM; thanks again.

This revision is now accepted and ready to land.Jul 20 2016, 3:53 PM
This revision was automatically updated to reflect the committed changes.