xref: /freebsd/contrib/llvm-project/compiler-rt/lib/profile/InstrProfilingMergeFile.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1 /*===- InstrProfilingMergeFile.c - Profile in-process Merging  ------------===*\
2 |*
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 |* See https://llvm.org/LICENSE.txt for license information.
5 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 |*
7 |*===----------------------------------------------------------------------===
8 |* This file defines APIs needed to support in-process merging for profile data
9 |* stored in files.
10 \*===----------------------------------------------------------------------===*/
11 
12 #if !defined(__Fuchsia__)
13 
14 #include "InstrProfiling.h"
15 #include "InstrProfilingInternal.h"
16 #include "InstrProfilingUtil.h"
17 
18 #define INSTR_PROF_VALUE_PROF_DATA
19 #include "profile/InstrProfData.inc"
20 
21 /* Merge value profile data pointed to by SrcValueProfData into
22  * in-memory profile counters pointed by to DstData.  */
23 COMPILER_RT_VISIBILITY
24 void lprofMergeValueProfData(ValueProfData *SrcValueProfData,
25                              __llvm_profile_data *DstData) {
26   unsigned I, S, V, DstIndex = 0;
27   InstrProfValueData *VData;
28   ValueProfRecord *VR = getFirstValueProfRecord(SrcValueProfData);
29   for (I = 0; I < SrcValueProfData->NumValueKinds; I++) {
30     VData = getValueProfRecordValueData(VR);
31     unsigned SrcIndex = 0;
32     for (S = 0; S < VR->NumValueSites; S++) {
33       uint8_t NV = VR->SiteCountArray[S];
34       for (V = 0; V < NV; V++) {
35         __llvm_profile_instrument_target_value(VData[SrcIndex].Value, DstData,
36                                                DstIndex, VData[SrcIndex].Count);
37         ++SrcIndex;
38       }
39       ++DstIndex;
40     }
41     VR = getValueProfRecordNext(VR);
42   }
43 }
44 
45 #endif
46