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