[PGO] Value profiling support
[oota-llvm.git] / include / llvm / ProfileData / InstrProfData.inc
1 //===-- InstrProfData.inc - instr profiling runtime structures-----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines templates for core runtime data structures used by  
11 // instrumentation based profiling and coverage mapping. The instrumentation  
12 // runtime library, the compiler IR lowering, and profile reader/writer need
13 // to use the same template to make sure the same data structure is defined
14 // consistently.
15 //
16 // Examples of how the template is used:
17 // 1. To declare a structure:
18 // 
19 // struct ProfData {
20 // #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
21 //    Type Name;
22 // #include "llvm/ProfileData/InstrProfData.inc"
23 // };
24 //
25 // 2. To construct LLVM type arrays for the struct type:
26 //
27 // Type *DataTypes[] = {
28 // #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
29 //   LLVMType,
30 // #include "llvm/ProfileData/InstrProfData.inc"
31 // };
32 //
33 // 4. To construct constant array for the initializers:
34 // #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
35 //   Initializer,
36 // Constant *ConstantVals[] = {
37 // #include "llvm/ProfileData/InstrProfData.inc"
38 // };
39 //===----------------------------------------------------------------------===//
40
41 #ifndef INSTR_PROF_DATA
42 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer)
43 #endif
44
45 // INSTR_PROF_DATA_START
46 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
47                 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
48                 NamePtr->getType()->getPointerElementType()->getArrayNumElements()))
49 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumCounters, \
50                 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumCounters))
51 INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
52                 ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
53                 Inc->getHash()->getZExtValue()))
54 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), NamePtr, \
55                 ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx)))
56 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt64PtrTy(Ctx), CounterPtr, \
57                 ConstantExpr::getBitCast(CounterPtr, \
58                 llvm::Type::getInt64PtrTy(Ctx)))
59 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), FunctionPointer, \
60                 FunctionAddr)
61 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), Values, \
62                 ConstantPointerNull::get(Int8PtrTy))
63 INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
64                 ConstantArray::get(Int16ArrayTy, Int16ArrayVals))
65 // INSTR_PROF_DATA_END
66
67 #ifdef INSTR_PROF_DATA
68 #undef INSTR_PROF_DATA
69 #endif
70
71
72 #ifndef COVMAP_FUNC_RECORD
73 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
74 #endif
75
76 // COVMAP_FUNC_RECORD_START
77 COVMAP_FUNC_RECORD(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), \
78                    NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
79                    llvm::Type::getInt8PtrTy(Ctx))) 
80 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
81                    llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
82                    NameValue.size()))
83 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), DataSize, \
84                    llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
85                    CoverageMapping.size()))
86 COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
87                    llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), FuncHash))
88 // COVMAP_FUNC_RECORD_END
89
90 #ifdef COVMAP_FUNC_RECORD
91 #undef COVMAP_FUNC_RECORD
92 #endif
93
94