[PATCH] D20148: Idea for avoiding memory allocation calls.

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Tue May 10 23:22:00 PDT 2016


On Tue, May 10, 2016 at 11:14 PM, Sean Silva <chisophugis at gmail.com> wrote:

> silvas created this revision.
> silvas added reviewers: davidxl, xur, vsk.
> silvas added a subscriber: llvm-commits.
> silvas set the repository for this revision to rL LLVM.
>
> 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?


yes.



> 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.
>

You can probably just declare malloc/calloc statically in test and trap if
it is called.


>
> [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.
>

yes -- a driver level option will be useful.

David


>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D20148
>
> Files:
>   lib/profile/InstrProfilingWriter.c
>
> Index: lib/profile/InstrProfilingWriter.c
> ===================================================================
> --- lib/profile/InstrProfilingWriter.c
> +++ lib/profile/InstrProfilingWriter.c
> @@ -91,6 +91,15 @@
>    return 0;
>  }
>
> +static int hasNoValueSites(const __llvm_profile_data *DataBegin,
> +                           const __llvm_profile_data *DataEnd) {
> +  for (; DataBegin != DataEnd; ++DataBegin)
> +    for (int I = 0; I <= IPVK_Last; I++)
> +      if (DataBegin->NumValueSites[I] != 0)
> +        return 0;
> +  return 1;
> +}
> +
>  #define VP_BUFFER_SIZE 8 * 1024
>  static int writeValueProfData(WriterCallback Writer, void *WriterCtx,
>                                VPGatherHookType VPDataGatherer,
> @@ -100,7 +109,10 @@
>    uint32_t BufferSz;
>    const __llvm_profile_data *DI = 0;
>
> -  if (!VPDataGatherer)
> +  /* Bail out early so that we don't attempt to call any memory allocation
> +   * functions.
> +   */
> +  if (!VPDataGatherer || hasNoValueSites(DataBegin, DataEnd))
>      return 0;
>
>    BufferSz = VPBufferSize ? VPBufferSize : VP_BUFFER_SIZE;
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160510/2f1a3314/attachment.html>


More information about the llvm-commits mailing list