This is an archive of the discontinued LLVM Phabricator instance.

[Attributor] Share code for abstract interpretation of allocation sizes with getObjectSize [NFC-ish]
ClosedPublic

Authored by reames on Jan 13 2022, 12:05 PM.

Details

Summary

This is an alternative to (part of D116971). The basic idea is that we can parameterize the getObjectSize implementation with a callback which lets us replace the operand before analysis if desired. This is what Attributor is doing during it's abstract interpretation, and allows us to have one copy of the code.

Note this is not NFC for two reasons:

  1. The existing attributor code is wrong. (Well, this is under-specified to be honest, but at least inconsistent.) The intermediate math needs to be done in the index type of the pointer space. Imagine e.g. i64 arguments in a 32 bit address space.
  2. I did not preserve the behavior in getAPInt where we return 0 for a partially analyzed value. This looks simply wrong in the original code, and nothing test wise contradicts that.

Diff Detail

Event Timeline

reames created this revision.Jan 13 2022, 12:05 PM
reames requested review of this revision.Jan 13 2022, 12:05 PM
Herald added a reviewer: baziotis. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Bryce-MW accepted this revision.Jan 13 2022, 3:18 PM

I like this a lot better than my solution and it looks to be correct.

This revision is now accepted and ready to land.Jan 13 2022, 3:18 PM
This revision was landed with ongoing or failed builds.Jan 13 2022, 3:33 PM
This revision was automatically updated to reflect the committed changes.

LG, minor nits below though

llvm/lib/Analysis/MemoryBuiltins.cpp
360

nit: dyn_cast_or_null or document the mapper should not return a nullptr. I prefer the former.

372

same as above.

llvm/lib/Transforms/IPO/AttributorAttributes.cpp
6022

Nit: Not "Dead" but "UsedAssumedInformation". That will need to be exposed once we want to "fix" AllocationInfos in H2S early to avoid looking at them again in future updates. For now, I'd just use the canonical name here.

reames added inline comments.Jan 14 2022, 8:06 AM
llvm/lib/Analysis/MemoryBuiltins.cpp
360

I strongly prefer not allowing the mapper to return null for no reason.

The wording in the comment is "replace one Value* (operand to the allocation) with another" This already implies the result can't be null to me.

llvm/lib/Transforms/IPO/AttributorAttributes.cpp
6022

Bryce already got this.

Though I'll note that this appears to be a dead outparam, and the more general mechanism a bunch of code complexity which is unused. (I haven't looked at the general case closely, I might be missing something.)