xref: /llvm-project/compiler-rt/lib/profile/InstrProfilingMergeFile.c (revision f35032e03d9263b1d2a8ac2e675fc94cb43b608b)
1dd12e9a8SXinliang David Li /*===- InstrProfilingMergeFile.c - Profile in-process Merging  ------------===*\
2dd12e9a8SXinliang David Li |*
32946cd70SChandler Carruth |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth |* See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6dd12e9a8SXinliang David Li |*
7dd12e9a8SXinliang David Li |*===----------------------------------------------------------------------===
8dd12e9a8SXinliang David Li |* This file defines APIs needed to support in-process merging for profile data
9dd12e9a8SXinliang David Li |* stored in files.
10dd12e9a8SXinliang David Li \*===----------------------------------------------------------------------===*/
11dd12e9a8SXinliang David Li 
1247e5fcbaSPetr Hosek #if !defined(__Fuchsia__)
1347e5fcbaSPetr Hosek 
14dd12e9a8SXinliang David Li #include "InstrProfiling.h"
15dd12e9a8SXinliang David Li #include "InstrProfilingInternal.h"
16dd12e9a8SXinliang David Li #include "InstrProfilingUtil.h"
17dd12e9a8SXinliang David Li 
18dd12e9a8SXinliang David Li #define INSTR_PROF_VALUE_PROF_DATA
19*f35032e0SPetr Hosek #include "profile/InstrProfData.inc"
20dd12e9a8SXinliang David Li 
21dd12e9a8SXinliang David Li /* Merge value profile data pointed to by SrcValueProfData into
22dd12e9a8SXinliang David Li  * in-memory profile counters pointed by to DstData.  */
23bbb8129bSAna Pazos COMPILER_RT_VISIBILITY
lprofMergeValueProfData(ValueProfData * SrcValueProfData,__llvm_profile_data * DstData)24cf1a8d69SXinliang David Li void lprofMergeValueProfData(ValueProfData *SrcValueProfData,
25dd12e9a8SXinliang David Li                              __llvm_profile_data *DstData) {
2695ab7582SRong Xu   unsigned I, S, V, DstIndex = 0;
27dd12e9a8SXinliang David Li   InstrProfValueData *VData;
28dd12e9a8SXinliang David Li   ValueProfRecord *VR = getFirstValueProfRecord(SrcValueProfData);
29dd12e9a8SXinliang David Li   for (I = 0; I < SrcValueProfData->NumValueKinds; I++) {
30dd12e9a8SXinliang David Li     VData = getValueProfRecordValueData(VR);
3195ab7582SRong Xu     unsigned SrcIndex = 0;
32dd12e9a8SXinliang David Li     for (S = 0; S < VR->NumValueSites; S++) {
33dd12e9a8SXinliang David Li       uint8_t NV = VR->SiteCountArray[S];
34dd12e9a8SXinliang David Li       for (V = 0; V < NV; V++) {
3595ab7582SRong Xu         __llvm_profile_instrument_target_value(VData[SrcIndex].Value, DstData,
3695ab7582SRong Xu                                                DstIndex, VData[SrcIndex].Count);
3795ab7582SRong Xu         ++SrcIndex;
38dd12e9a8SXinliang David Li       }
3995ab7582SRong Xu       ++DstIndex;
40dd12e9a8SXinliang David Li     }
41dd12e9a8SXinliang David Li     VR = getValueProfRecordNext(VR);
42dd12e9a8SXinliang David Li   }
43dd12e9a8SXinliang David Li }
4447e5fcbaSPetr Hosek 
4547e5fcbaSPetr Hosek #endif
46