This is an archive of the discontinued LLVM Phabricator instance.

Change AllocType representation to be more general
AbandonedPublicDraft

Authored by Bryce-MW on Jan 7 2022, 1:05 AM.

Details

Reviewers
None
Summary

The existing AllocType enum only allows for functions which emulate C-style allocators. The users of AllocType are generally only interested in one specific propery of the allocator. These changes don't make a difference currently but it opens future allocators that work differently. There are also some versions of operator new that take alignment values. They can not be added now because of some hardcoding of arguement positions. Which brings me to the caveat of this change which is that there are a number of places where the "like" functions are hardcoded to have arguments in specific positions. I'll add a comment with where those are. I'm happy to work on those but I wanted to hear if this new design of AllocType is even desired before I put in the effort.

Diff Detail

Event Timeline

Bryce-MW created this revision.Jan 7 2022, 1:05 AM
Bryce-MW edited the summary of this revision. (Show Details)Jan 7 2022, 1:07 AM
Bryce-MW added a project: Restricted Project.

Here are the places where there are hardcoded argument positions or other special cases that will need to be updated.

Heap-To-Stack Conversion in llvm/lib/Transforms/IPO/AttributorAttributes.cpp has hardcoded argument positions. It supports malloc, calloc, and aligned_alloc but the position of the arguments is hardcoded. Needs separate fields for allocated value (to determine if memset is needed), if the allocation is aligned (and position of alignment arg which we don't have), and the positions of the two size args. This will be a larger refactor so I will do it later.

InstCombinerImpl::annotateAnyAllocSite in llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp hardcodes which arguments it looks at and hardcodes special cases for strdup and strndup.

ObjectSizeOffsetVisitor::visitCallBase in llvm/lib/Analysis/MemoryBuiltins.cpp has special-casing for strdup and strndup. Could also possibly work on the TODO there.

For line 1005 of llvm/lib/Analysis/BasicAliasAnalysis.cpp, is inaccessiblememonly implemented? It's mentioned on the IR documentation page as if it is. This would be better than the current call which would need to have the mentioned special case put in (and we would need to require that allocation functions must have inaccessiblememonly semantics anyway). Same thing with visitCallBase in llvm/lib/Analysis/CFLGraph.h

Bryce-MW abandoned this revision.Jan 7 2022, 11:22 PM