<div dir="ltr">I will take care of this.<div><br></div><div>David</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 26, 2016 at 11:11 AM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">----- Original Message -----<br>
> From: "Xinliang David Li via llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>><br>
> To: <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> Sent: Thursday, March 3, 2016 12:54:46 PM<br>
> Subject: [compiler-rt] r262644 - [PGO] Add API for profile merge from buffer<br>
><br>
> Author: davidxl<br>
> Date: Thu Mar  3 12:54:46 2016<br>
> New Revision: 262644<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=262644&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=262644&view=rev</a><br>
> Log:<br>
> [PGO] Add API for profile merge from buffer<br>
><br>
> Differential Revision: <a href="http://reviews.llvm.org/D17831" rel="noreferrer" target="_blank">http://reviews.llvm.org/D17831</a><br>
><br>
> Added:<br>
>     compiler-rt/trunk/lib/profile/InstrProfilingMerge.c<br>
>     compiler-rt/trunk/lib/profile/InstrProfilingMergeFile.c<br>
>     compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c<br>
>     compiler-rt/trunk/test/profile/instrprof-merge.c<br>
> Modified:<br>
>     compiler-rt/trunk/lib/profile/CMakeLists.txt<br>
>     compiler-rt/trunk/lib/profile/InstrProfiling.h<br>
>     compiler-rt/trunk/lib/profile/InstrProfilingInternal.h<br>
>     compiler-rt/trunk/make/platform/<a href="http://clang_linux.mk" rel="noreferrer" target="_blank">clang_linux.mk</a><br>
>     compiler-rt/trunk/test/profile/instrprof-without-libc.c<br>
><br>
> Modified: compiler-rt/trunk/lib/profile/CMakeLists.txt<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/CMakeLists.txt?rev=262644&r1=262643&r2=262644&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/CMakeLists.txt?rev=262644&r1=262643&r2=262644&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/CMakeLists.txt (original)<br>
> +++ compiler-rt/trunk/lib/profile/CMakeLists.txt Thu Mar  3 12:54:46<br>
> 2016<br>
> @@ -30,6 +30,8 @@ set(PROFILE_SOURCES<br>
>    InstrProfilingValue.c<br>
>    InstrProfilingBuffer.c<br>
>    InstrProfilingFile.c<br>
> +  InstrProfilingMerge.c<br>
> +  InstrProfilingMergeFile.c<br>
>    InstrProfilingWriter.c<br>
>    InstrProfilingPlatformDarwin.c<br>
>    InstrProfilingPlatformLinux.c<br>
><br>
> Modified: compiler-rt/trunk/lib/profile/InstrProfiling.h<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=262644&r1=262643&r2=262644&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=262644&r1=262643&r2=262644&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/InstrProfiling.h (original)<br>
> +++ compiler-rt/trunk/lib/profile/InstrProfiling.h Thu Mar  3<br>
> 12:54:46 2016<br>
> @@ -63,6 +63,15 @@ uint64_t *__llvm_profile_end_counters(vo<br>
>  void __llvm_profile_reset_counters(void);<br>
><br>
>  /*!<br>
> + * \brief Read profile data form buffer and merge with<br>
> + * in-process profile counters. The client is expected to<br>
> + * have checked or already knows the profile data in the<br>
> + * buffer matches the in-process counter structure before<br>
> + * calling it.<br>
> + */<br>
> +void __llvm_profile_merge_from_buffer(const char *Profile, uint64_t<br>
> Size);<br>
> +<br>
> +/*!<br>
>   * \brief Counts the number of times a target value is seen.<br>
>   *<br>
>   * Records the target value for the CounterIndex if not seen before.<br>
>   Otherwise,<br>
><br>
> Modified: compiler-rt/trunk/lib/profile/InstrProfilingInternal.h<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingInternal.h?rev=262644&r1=262643&r2=262644&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingInternal.h?rev=262644&r1=262643&r2=262644&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/InstrProfilingInternal.h (original)<br>
> +++ compiler-rt/trunk/lib/profile/InstrProfilingInternal.h Thu Mar  3<br>
> 12:54:46 2016<br>
> @@ -109,10 +109,15 @@ int llvmWriteProfDataImpl(WriterCallback<br>
>                            struct ValueProfData<br>
>                            **ValueDataBeginArray,<br>
>                            const uint64_t ValueDataSize, const char<br>
>                            *NamesBegin,<br>
>                            const char *NamesEnd);<br>
> +/* Merge value profile data pointed to by SrcValueProfData into<br>
> + * in-memory profile counters pointed by to DstData.  */<br>
> +void mergeValueProfData(struct ValueProfData *SrcValueProfData,<br>
> +                        __llvm_profile_data *DstData);<br>
><br>
>  extern char *(*GetEnvHook)(const char *);<br>
>  extern void (*FreeHook)(void *);<br>
> -extern void* (*CallocHook)(size_t, size_t);<br>
> +extern void *(*CallocHook)(size_t, size_t);<br>
> +extern void (*VPMergeHook)(struct ValueProfData *,<br>
> __llvm_profile_data *);<br>
>  extern uint32_t VPBufferSize;<br>
><br>
>  #endif<br>
><br>
> Added: compiler-rt/trunk/lib/profile/InstrProfilingMerge.c<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingMerge.c?rev=262644&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingMerge.c?rev=262644&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/InstrProfilingMerge.c (added)<br>
> +++ compiler-rt/trunk/lib/profile/InstrProfilingMerge.c Thu Mar  3<br>
> 12:54:46 2016<br>
> @@ -0,0 +1,70 @@<br>
> +/*===- InstrProfilingMerge.c - Profile in-process Merging<br>
>  ---------------===*\<br>
> +|*<br>
> +|*                     The LLVM Compiler Infrastructure<br>
> +|*<br>
> +|* This file is distributed under the University of Illinois Open<br>
> Source<br>
> +|* License. See LICENSE.TXT for details.<br>
> +|*<br>
> +|*===----------------------------------------------------------------------===*<br>
> +|* This file defines the API needed for in-process merging of<br>
> profile data<br>
> +|* stored in memory buffer.<br>
> +\*===---------------------------------------------------------------------===*/<br>
> +<br>
> +#include "InstrProfiling.h"<br>
> +#include "InstrProfilingInternal.h"<br>
> +#include "InstrProfilingUtil.h"<br>
> +<br>
> +#define INSTR_PROF_VALUE_PROF_DATA<br>
> +#include "InstrProfData.inc"<br>
> +<br>
> +COMPILER_RT_WEAK void (*VPMergeHook)(ValueProfData *,<br>
> +                                     __llvm_profile_data *) = NULL;<br>
> +<br>
> +void __llvm_profile_merge_from_buffer(const char *ProfileData,<br>
> +                                      uint64_t ProfileSize) {<br>
> +  __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData,<br>
> *DstData;<br>
> +  __llvm_profile_header *Header = (__llvm_profile_header<br>
> *)ProfileData;<br>
> +  uint64_t *SrcCountersStart;<br>
> +  const char *SrcNameStart;<br>
> +  ValueProfData *SrcValueProfDataStart, *SrcValueProfData;<br>
> +<br>
> +  SrcDataStart =<br>
> +      (__llvm_profile_data *)(ProfileData +<br>
> sizeof(__llvm_profile_header));<br>
> +  SrcDataEnd = SrcDataStart + Header->DataSize;<br>
> +  SrcCountersStart = (uint64_t *)SrcDataEnd;<br>
> +  SrcNameStart = (const char *)(SrcCountersStart +<br>
> Header->CountersSize);<br>
> +  SrcValueProfDataStart =<br>
> +      (ValueProfData *)(SrcNameStart + Header->NamesSize +<br>
> +                        __llvm_profile_get_num_padding_bytes(<br>
> +                            Header->NamesSize));<br>
> +<br>
> +  for (SrcData = SrcDataStart,<br>
> +      DstData = (__llvm_profile_data *)__llvm_profile_begin_data(),<br>
> +      SrcValueProfData = SrcValueProfDataStart;<br>
> +       SrcData < SrcDataEnd; ++SrcData, ++DstData) {<br>
> +    uint64_t *SrcCounters;<br>
> +    uint64_t *DstCounters = (uint64_t *)DstData->CounterPtr;<br>
> +    unsigned I, NC, NVK = 0;<br>
> +<br>
> +    NC = SrcData->NumCounters;<br>
> +    SrcCounters = SrcCountersStart +<br>
> +                  ((size_t)SrcData->CounterPtr -<br>
> Header->CountersDelta) /<br>
> +                      sizeof(uint64_t);<br>
> +    for (I = 0; I < NC; I++)<br>
> +      DstCounters[I] += SrcCounters[I];<br>
> +<br>
> +    /* Now merge value profile data.  */<br>
> +    if (!VPMergeHook)<br>
> +      continue;<br>
> +<br>
> +    for (I = 0; I <= IPVK_Last; I++)<br>
> +      NVK += (SrcData->NumValueSites[I] != 0);<br>
> +<br>
> +    if (!NVK)<br>
> +      continue;<br>
> +<br>
> +    VPMergeHook(SrcValueProfData, DstData);<br>
> +    SrcValueProfData = (ValueProfData *)((char *)SrcValueProfData +<br>
> +<br>
>                                         SrcValueProfData->TotalSize);<br>
> +  }<br>
> +}<br>
><br>
> Added: compiler-rt/trunk/lib/profile/InstrProfilingMergeFile.c<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingMergeFile.c?rev=262644&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingMergeFile.c?rev=262644&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/InstrProfilingMergeFile.c (added)<br>
> +++ compiler-rt/trunk/lib/profile/InstrProfilingMergeFile.c Thu Mar<br>
>  3 12:54:46 2016<br>
> @@ -0,0 +1,41 @@<br>
> +/*===- InstrProfilingMergeFile.c - Profile in-process Merging<br>
>  ------------===*\<br>
> +|*<br>
> +|*                     The LLVM Compiler Infrastructure<br>
> +|*<br>
> +|* This file is distributed under the University of Illinois Open<br>
> Source<br>
> +|* License. See LICENSE.TXT for details.<br>
> +|*<br>
> +|*===----------------------------------------------------------------------===<br>
> +|* This file defines APIs needed to support in-process merging for<br>
> profile data<br>
> +|* stored in files.<br>
> +\*===----------------------------------------------------------------------===*/<br>
> +<br>
> +#include "InstrProfiling.h"<br>
> +#include "InstrProfilingInternal.h"<br>
> +#include "InstrProfilingUtil.h"<br>
> +<br>
> +#define INSTR_PROF_VALUE_PROF_DATA<br>
> +#include "InstrProfData.inc"<br>
> +<br>
> +void (*VPMergeHook)(ValueProfData *,<br>
> +                    __llvm_profile_data *) = &mergeValueProfData;<br>
> +<br>
> +/* Merge value profile data pointed to by SrcValueProfData into<br>
> + * in-memory profile counters pointed by to DstData.  */<br>
> +void mergeValueProfData(ValueProfData *SrcValueProfData,<br>
> +                        __llvm_profile_data *DstData) {<br>
> +  unsigned I, S, V, C;<br>
> +  InstrProfValueData *VData;<br>
> +  ValueProfRecord *VR = getFirstValueProfRecord(SrcValueProfData);<br>
> +  for (I = 0; I < SrcValueProfData->NumValueKinds; I++) {<br>
> +    VData = getValueProfRecordValueData(VR);<br>
> +    for (S = 0; S < VR->NumValueSites; S++) {<br>
> +      uint8_t NV = VR->SiteCountArray[S];<br>
> +      for (V = 0; V < NV; V++) {<br>
> +        for (C = 0; C < VData[V].Count; C++)<br>
> +          __llvm_profile_instrument_target(VData[V].Value, DstData,<br>
> S);<br>
> +      }<br>
> +    }<br>
> +    VR = getValueProfRecordNext(VR);<br>
> +  }<br>
> +}<br>
><br>
> Modified: compiler-rt/trunk/make/platform/<a href="http://clang_linux.mk" rel="noreferrer" target="_blank">clang_linux.mk</a><br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_linux.mk?rev=262644&r1=262643&r2=262644&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_linux.mk?rev=262644&r1=262643&r2=262644&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/make/platform/<a href="http://clang_linux.mk" rel="noreferrer" target="_blank">clang_linux.mk</a> (original)<br>
> +++ compiler-rt/trunk/make/platform/<a href="http://clang_linux.mk" rel="noreferrer" target="_blank">clang_linux.mk</a> Thu Mar  3<br>
> 12:54:46 2016<br>
> @@ -79,7 +79,8 @@ FUNCTIONS.builtins-x86_64 := $(CommonFun<br>
>  FUNCTIONS.profile-i386 := GCDAProfiling InstrProfiling<br>
>  InstrProfilingBuffer \<br>
>                            InstrProfilingFile<br>
>                            InstrProfilingPlatformOther \<br>
>                            InstrProfilingRuntime InstrProfilingUtil \<br>
> -                          InstrProfilingWriter InstrProfilingValue<br>
> +                          InstrProfilingWriter InstrProfilingValue \<br>
> +                          InstrProfilingMerge<br>
> InstrProfilingMergeFile<br>
>  FUNCTIONS.profile-x86_64 := $(FUNCTIONS.profile-i386)<br>
><br>
>  # Always use optimized variants.<br>
><br>
> Added: compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c?rev=262644&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c?rev=262644&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c (added)<br>
> +++ compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c Thu Mar<br>
>  3 12:54:46 2016<br>
> @@ -0,0 +1,110 @@<br>
> +// RUN: %clang_profgen -mllvm --enable-value-profiling=true -O2 -o<br>
> %t %s<br>
> +// RUN: %run %t %t.profraw<br>
> +// RUN: llvm-profdata merge -o %t.profdata %t.profraw<br>
> +// RUN: llvm-profdata show --all-functions --counts --ic-targets<br>
> %t.profdata | FileCheck %s<br>
> +<br>
> +#include <stdint.h><br>
> +#include <stdio.h><br>
> +#include <stdlib.h><br>
> +#include <sys/types.h><br>
> +#include <unistd.h><br>
> +<br>
> +int __llvm_profile_runtime = 0;<br>
> +int __llvm_profile_write_file();<br>
> +void __llvm_profile_reset_counters(void);<br>
> +void __llvm_profile_merge_from_buffer(const char *, uint64_t);<br>
> +void __llvm_profile_set_filename(const char *);<br>
> +struct __llvm_profile_data;<br>
> +struct ValueProfData;<br>
> +void mergeValueProfData(struct ValueProfData *, struct<br>
> __llvm_profile_data *);<br>
> +/* Force the vp merger module to be linked in.  */<br>
> +void *Dummy = &mergeValueProfData;<br>
> +<br>
> +void callee1() {}<br>
> +void callee2() {}<br>
> +void callee3() {}<br>
> +<br>
> +typedef void (*FP)(void);<br>
> +FP Fps[3] = {callee1, callee2, callee3};<br>
> +<br>
> +void foo(int N) {<br>
> +  int I, J;<br>
> +  for (I = 0; I < 3; I++)<br>
> +    for (J = 0; J < I * 2 + 1; J++)<br>
> +      Fps[I]();<br>
> +<br>
> +  if (N < 2)<br>
> +    return;<br>
> +<br>
> +  for (I = 0; I < 3; I++)<br>
> +    for (J = 0; J < I * 2 + 1; J++)<br>
> +      Fps[2 - I]();<br>
> +}<br>
> +<br>
> +/* This function is not profiled */<br>
> +void bar(void) {<br>
> +  int I;<br>
> +  for (I = 0; I < 20; I++)<br>
> +    Fps[I % 3]();<br>
> +}<br>
> +<br>
> +int main(int argc, const char *argv[]) {<br>
> +  int i;<br>
> +  if (argc < 2)<br>
> +    return 1;<br>
> +<br>
> +  const char *FileN = argv[1];<br>
> +  __llvm_profile_set_filename(FileN);<br>
> +  /* Start profiling. */<br>
> +  __llvm_profile_reset_counters();<br>
> +  foo(1);<br>
> +  /* End profiling by freezing counters and<br>
> +   * dump them to the file. */<br>
> +  if (__llvm_profile_write_file())<br>
> +    return 1;<br>
> +<br>
> +  /* Read profile data into buffer. */<br>
> +  FILE *File = fopen(FileN, "r");<br>
> +  if (!File)<br>
> +    return 1;<br>
> +  fseek(File, 0, SEEK_END);<br>
> +  uint64_t Size = ftell(File);<br>
> +  fseek(File, 0, SEEK_SET);<br>
> +  char *Buffer = (char *)malloc(Size);<br>
> +  if (Size != fread(Buffer, 1, Size, File))<br>
> +    return 1;<br>
> +  fclose(File);<br>
> +<br>
> +  /* Its profile will be discarded. */<br>
> +  for (i = 0; i < 10; i++)<br>
> +    bar();<br>
> +<br>
> +  /* Start profiling again and merge in previously<br>
> +     saved counters in buffer. */<br>
> +  __llvm_profile_reset_counters();<br>
> +  __llvm_profile_merge_from_buffer(Buffer, Size);<br>
> +  foo(2);<br>
> +  /* End profiling. */<br>
> +  truncate(FileN, 0);<br>
> +  if (__llvm_profile_write_file())<br>
> +    return 1;<br>
> +<br>
> +  /* Its profile will be discarded. */<br>
> +  bar();<br>
> +<br>
> +  return 0;<br>
> +}<br>
> +<br>
> +// CHECK-LABEL:  foo:<br>
> +// CHECK:    Indirect Target Results:<br>
> +// CHECK-NEXT:       [ 0, callee3, 10 ]<br>
> +// CHECK-NEXT:       [ 0, callee2, 6 ]<br>
> +// CHECK-NEXT:       [ 0, callee1, 2 ]<br>
> +// CHECK-NEXT:       [ 1, callee1, 5 ]<br>
> +// CHECK-NEXT:       [ 1, callee2, 3 ]<br>
> +// CHECK-NEXT:       [ 1, callee3, 1 ]<br>
> +<br>
> +// CHECK-LABEL: bar:<br>
> +// CHECK:         [ 0, callee1, 0 ]<br>
> +// CHECK-NEXT:    [ 0, callee2, 0 ]<br>
> +// CHECK-NEXT:    [ 0, callee3, 0 ]<br>
<br>
This test just failed for me on an x86_64 self host...<br>
<br>
FAIL: Profile-x86_64 :: Linux/instrprof-merge-vp.c (26913 of 32924)<br>
******************** TEST 'Profile-x86_64 :: Linux/instrprof-merge-vp.c' FAILED ********************<br>
Script:<br>
--<br>
/build/llvm-stage1/./bin/clang -m64 -ldl  -fprofile-instr-generate -mllvm --enable-value-profiling=true -O2 -o /build/llvm-stage1/projects/compiler-rt/test/profile/Profile-x86_64/Linux/Output/instrprof-merge-vp.c.tmp /src/llvm/projects/compiler-rt/test/profile/Linux/instrprof-merge-vp.c<br>
/build/llvm-stage1/projects/compiler-rt/test/profile/Profile-x86_64/Linux/Output/instrprof-merge-vp.c.tmp /build/llvm-stage1/projects/compiler-rt/test/profile/Profile-x86_64/Linux/Output/instrprof-merge-vp.c.tmp.profraw<br>
llvm-profdata merge -o /build/llvm-stage1/projects/compiler-rt/test/profile/Profile-x86_64/Linux/Output/instrprof-merge-vp.c.tmp.profdata /build/llvm-stage1/projects/compiler-rt/test/profile/Profile-x86_64/Linux/Output/instrprof-merge-vp.c.tmp.profraw<br>
llvm-profdata show --all-functions --counts --ic-targets /build/llvm-stage1/projects/compiler-rt/test/profile/Profile-x86_64/Linux/Output/instrprof-merge-vp.c.tmp.profdata | FileCheck /src/llvm/projects/compiler-rt/test/profile/Linux/instrprof-merge-vp.c<br>
--<br>
Exit Code: 1<br>
<br>
Command Output (stderr):<br>
--<br>
/src/llvm/projects/compiler-rt/test/profile/Linux/instrprof-merge-vp.c:107:17: error: expected string not found in input<br>
// CHECK-LABEL: bar:<br>
                ^<br>
<stdin>:41:2: note: scanning from here<br>
 Hash: 0x000000000410a104<br>
 ^<br>
<stdin>:46:11: note: possible intended match here<br>
 Indirect Target Results:<br>
          ^<br>
<br>
The full output from llvm-profdata is:<br>
<br>
Counters:<br>
  callee1:<br>
    Hash: 0x0000000000000000<br>
    Counters: 1<br>
    Function count: 7<br>
    Indirect Call Site Count: 0<br>
    Block counts: []<br>
    Indirect Target Results:<br>
  callee2:<br>
    Hash: 0x0000000000000000<br>
    Counters: 1<br>
    Function count: 9<br>
    Indirect Call Site Count: 0<br>
    Block counts: []<br>
    Indirect Target Results:<br>
  callee3:<br>
    Hash: 0x0000000000000000<br>
    Counters: 1<br>
    Function count: 11<br>
    Indirect Call Site Count: 0<br>
    Block counts: []<br>
    Indirect Target Results:<br>
  bar:<br>
    Hash: 0x0000000000000004<br>
    Counters: 2<br>
    Function count: 0<br>
    Indirect Call Site Count: 1<br>
    Block counts: [0]<br>
    Indirect Target Results:<br>
        [ 0, callee1, 0 ]<br>
        [ 0, callee2, 0 ]<br>
        [ 0, callee3, 0 ]<br>
  main:<br>
    Hash: 0x000000028a28a10a<br>
    Counters: 7<br>
    Function count: 0<br>
    Indirect Call Site Count: 0<br>
    Block counts: [0, 0, 0, 0, 0, 0]<br>
    Indirect Target Results:<br>
  foo:<br>
    Hash: 0x000000000410a104<br>
    Counters: 6<br>
    Function count: 2<br>
    Indirect Call Site Count: 2<br>
    Block counts: [6, 18, 1, 3, 9]<br>
    Indirect Target Results:<br>
        [ 0, callee3, 10 ]<br>
        [ 0, callee2, 6 ]<br>
        [ 0, callee1, 2 ]<br>
        [ 1, callee1, 5 ]<br>
        [ 1, callee2, 3 ]<br>
        [ 1, callee3, 1 ]<br>
Functions shown: 6<br>
Total functions: 6<br>
Maximum function count: 11<br>
Maximum internal block count: 18<br>
<br>
So it looks like foo and bar occur in an order different from what the test checks expect? xfailing this test made it pass both this stage 1 build and also my stage 2 -O0 build, so it is deterministic at least in that sense.<br>
<br>
 -Hal<br>
<br>
><br>
> Added: compiler-rt/trunk/test/profile/instrprof-merge.c<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-merge.c?rev=262644&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-merge.c?rev=262644&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/test/profile/instrprof-merge.c (added)<br>
> +++ compiler-rt/trunk/test/profile/instrprof-merge.c Thu Mar  3<br>
> 12:54:46 2016<br>
> @@ -0,0 +1,96 @@<br>
> +// RUN: %clang_profgen -O2 -o %t %s<br>
> +// RUN: %run %t %t.profraw 1 1<br>
> +// RUN: llvm-profdata show --all-functions --counts %t.profraw  |<br>
> FileCheck %s<br>
> +<br>
> +#include <stdint.h><br>
> +#include <stdio.h><br>
> +#include <stdlib.h><br>
> +<br>
> +int __llvm_profile_runtime = 0;<br>
> +uint64_t __llvm_profile_get_size_for_buffer(void);<br>
> +int __llvm_profile_write_buffer(char *);<br>
> +void __llvm_profile_reset_counters(void);<br>
> +void __llvm_profile_merge_from_buffer(const char *, uint64_t);<br>
> +<br>
> +int dumpBuffer(const char *FileN, const char *Buffer, uint64_t Size)<br>
> {<br>
> +  FILE *File = fopen(FileN, "w");<br>
> +  if (!File)<br>
> +    return 1;<br>
> +  if (fwrite(Buffer, 1, Size, File) != Size)<br>
> +    return 1;<br>
> +  return fclose(File);<br>
> +}<br>
> +<br>
> +int g = 0;<br>
> +void foo(char c) {<br>
> +  if (c == '1')<br>
> +    g++;<br>
> +  else<br>
> +    g--;<br>
> +}<br>
> +<br>
> +/* This function is not profiled */<br>
> +void bar(int M) { g += M; }<br>
> +<br>
> +int main(int argc, const char *argv[]) {<br>
> +  int i;<br>
> +  if (argc < 4)<br>
> +    return 1;<br>
> +<br>
> +  const uint64_t MaxSize = 10000;<br>
> +  static char Buffer[MaxSize];<br>
> +<br>
> +  uint64_t Size = __llvm_profile_get_size_for_buffer();<br>
> +  if (Size > MaxSize)<br>
> +    return 1;<br>
> +<br>
> +  /* Start profiling. */<br>
> +  __llvm_profile_reset_counters();<br>
> +  foo(argv[2][0]);<br>
> +  /* End profiling by freezing counters. */<br>
> +  if (__llvm_profile_write_buffer(Buffer))<br>
> +    return 1;<br>
> +<br>
> +  /* Its profile will be discarded. */<br>
> +  for (i = 0; i < 10; i++)<br>
> +    bar(1);<br>
> +<br>
> +  /* Start profiling again and merge in previously<br>
> +     saved counters in buffer. */<br>
> +  __llvm_profile_reset_counters();<br>
> +  __llvm_profile_merge_from_buffer(Buffer, Size);<br>
> +  foo(argv[3][0]);<br>
> +  /* End profiling */<br>
> +  if (__llvm_profile_write_buffer(Buffer))<br>
> +    return 1;<br>
> +<br>
> +  /* Its profile will be discarded. */<br>
> +  bar(2);<br>
> +<br>
> +  /* Now it is time to dump the profile to file.  */<br>
> +  return dumpBuffer(argv[1], Buffer, Size);<br>
> +}<br>
> +<br>
> +// Not profiled<br>
> +// CHECK-LABEL: dumpBuffer:<br>
> +// CHECK:        Counters: 3<br>
> +// CHECK-NEXT:   Function count: 0<br>
> +// CHECK-NEXT:   Block counts: [0, 0]<br>
> +<br>
> +// Profiled with entry count == 2<br>
> +// CHECK-LABEL:  foo:<br>
> +// CHECK:         Counters: 2<br>
> +// CHECK-NEXT:    Function count: 2<br>
> +// CHECK-NEXT:    Block counts: [2]<br>
> +<br>
> +// Not profiled<br>
> +// CHECK-LABEL:  bar:<br>
> +// CHECK:         Counters: 1<br>
> +// CHECK-NEXT     Function count: 0<br>
> +// CHECK-NEXT     Block counts: []<br>
> +<br>
> +// Not profiled<br>
> +// CHECK-LABEL:  main:<br>
> +// CHECK:         Counters: 6<br>
> +// CHECK-NEXT:    Function count: 0<br>
> +// CHECK-NEXT:    Block counts: [0, 0, 0, 0, 0]<br>
><br>
> Modified: compiler-rt/trunk/test/profile/instrprof-without-libc.c<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-without-libc.c?rev=262644&r1=262643&r2=262644&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-without-libc.c?rev=262644&r1=262643&r2=262644&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/test/profile/instrprof-without-libc.c<br>
> (original)<br>
> +++ compiler-rt/trunk/test/profile/instrprof-without-libc.c Thu Mar<br>
>  3 12:54:46 2016<br>
> @@ -15,6 +15,8 @@<br>
>  int __llvm_profile_runtime = 0;<br>
>  uint64_t __llvm_profile_get_size_for_buffer(void);<br>
>  int __llvm_profile_write_buffer(char *);<br>
> +void __llvm_profile_merge_from_buffer(const char *, uint64_t Size);<br>
> +<br>
>  int write_buffer(uint64_t, const char *);<br>
>  int main(int argc, const char *argv[]) {<br>
>    // CHECK-LABEL: define {{.*}} @main(<br>
> @@ -35,6 +37,8 @@ int main(int argc, const char *argv[]) {<br>
>  #ifdef CHECK_SYMBOLS<br>
>    // Don't write it out.  Since we're checking the symbols, we don't<br>
>    have libc<br>
>    // available.<br>
> +  // Call merge function to make sure it does not bring in libc<br>
> deps:<br>
> +  __llvm_profile_merge_from_buffer(Buffer, Size);<br>
>    return 0;<br>
>  #else<br>
>    // Actually write it out so we can FileCheck the output.<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</font></span></blockquote></div><br></div>