This is an archive of the discontinued LLVM Phabricator instance.

Idea for avoiding memory allocation calls.
AbandonedPublic

Authored by silvas on May 10 2016, 11:14 PM.

Details

Reviewers
xur
davidxl
vsk
Summary

On PS4 we ideally will make no calls into malloc/calloc/free. Currently value profiling is the only source of such calls in libprofile, but even when the compiler emits no value profiling instrumentation we still end up making memory allocation calls.

What do you guys think about adding a check like this? It is conceptually similar to the check for VPDataGatherer which effectively is bailing out early for a somewhat related reason (in that case, it is more generally that some hooks will be null because they aren't present, rather than just "we shouldn't call them").

I've run tests on my Mac laptop and everything passes. I'll do some more thorough checking on PS4 when I'm back in the office on Thu (currently I'm at a conference and don't have easy access to my workstation / devkits).

Does this make sense? As far as testing I was thinking of something like using LD_PRELOAD (and whatever the mac one is) to interpose malloc/calloc/free and verify there are no calls to them.

[1] We'll need to have a separate discussion of controlling VP instrumentation (probably a decision at clang driver based on triple). On PS4 we need to have it off (at least by default) to avoid interacting with a game's dynamic memory allocation.

Diff Detail

Repository
rL LLVM

Event Timeline

silvas updated this revision to Diff 56852.May 10 2016, 11:14 PM
silvas retitled this revision from to Idea for avoiding memory allocation calls..
silvas updated this object.
silvas added reviewers: davidxl, xur, vsk.
silvas set the repository for this revision to rL LLVM.
silvas added a subscriber: llvm-commits.
xur edited edge metadata.May 11 2016, 12:25 AM

This avoids calloc in lprofCreateBufferIO() which is not used at all if there is not value profiles.

But how about the malloc calls from setFilenamePossiblyWithPid() and truncateCurrentFile(). They are not from value profiling, but they also call dynamic memory allocation.

Maybe we should convert all these into alloca or using pre-allocated memory.

David and I are working on to get the profile runtime malloc free (or at least avoiding re-entrance to malloc) in the past few days. Hopefully we can have some discussion on this soon.

silvas abandoned this revision.Jul 8 2016, 11:45 PM