9893c59b1393d5a21b5d42ef2ddbb7114e604dbc
[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 /* INSTR_PROF_DATA start. */
42 /* Definition of member fields of the per-function control structure. */
43 #ifndef INSTR_PROF_DATA
44 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer)
45 #else
46 #define INSTR_PROF_DATA_DEFINED
47 #endif
48
49 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
50                 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
51                 NamePtr->getType()->getPointerElementType()->getArrayNumElements()))
52 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumCounters, \
53                 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumCounters))
54 INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
55                 ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
56                 Inc->getHash()->getZExtValue()))
57 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), NamePtr, \
58                 ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx)))
59 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt64PtrTy(Ctx), CounterPtr, \
60                 ConstantExpr::getBitCast(CounterPtr, \
61                 llvm::Type::getInt64PtrTy(Ctx)))
62 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), FunctionPointer, \
63                 FunctionAddr)
64 INSTR_PROF_DATA(IntPtrT, llvm::Type::getInt8PtrTy(Ctx), Values, \
65                 ConstantPointerNull::get(Int8PtrTy))
66 INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
67                 ConstantArray::get(Int16ArrayTy, Int16ArrayVals))
68 #undef INSTR_PROF_DATA
69
70 /* INSTR_PROF_DATA end. */
71
72 /* INSTR_PROF_RAW_HEADER  start */
73 /* Definition of member fields of the raw profile header data structure. */
74 #ifndef INSTR_PROF_RAW_HEADER
75 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer)
76 #else
77 #define INSTR_PROF_DATA_DEFINED
78 #endif
79 INSTR_PROF_RAW_HEADER(const uint64_t, Magic, __llvm_profile_get_magic())
80 INSTR_PROF_RAW_HEADER(const uint64_t, Version, __llvm_profile_get_version())
81 INSTR_PROF_RAW_HEADER(const uint64_t, DataSize, DataSize)
82 INSTR_PROF_RAW_HEADER(const uint64_t, CountersSize, CountersSize)
83 INSTR_PROF_RAW_HEADER(const uint64_t, NamesSize,  NameSize)
84 INSTR_PROF_RAW_HEADER(const uint64_t, CountersDelta, (uintptr_t)CountersBegin)
85 INSTR_PROF_RAW_HEADER(const uint64_t, NamesDelta, (uintptr_t)NamesBegin)
86 INSTR_PROF_RAW_HEADER(const uint64_t, ValueKindLast, IPVK_Last)
87 INSTR_PROF_RAW_HEADER(const uint64_t, ValueDataSize, ValueDataSize)
88 INSTR_PROF_RAW_HEADER(const uint64_t, ValueDataDelta, (uintptr_t)ValueDataBegin)
89 #undef INSTR_PROF_RAW_HEADER
90 /* INSTR_PROF_RAW_HEADER  end */
91
92
93 /* COVMAP_FUNC_RECORD start */
94 /* Definition of member fields of the function record structure in coverage
95  * map.
96  */
97 #ifndef COVMAP_FUNC_RECORD
98 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
99 #else
100 #define INSTR_PROF_DATA_DEFINED
101 #endif
102 COVMAP_FUNC_RECORD(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), \
103                    NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
104                    llvm::Type::getInt8PtrTy(Ctx))) 
105 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
106                    llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
107                    NameValue.size()))
108 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), DataSize, \
109                    llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
110                    CoverageMapping.size()))
111 COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
112                    llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), FuncHash))
113 #undef COVMAP_FUNC_RECORD
114 /* COVMAP_FUNC_RECORD end.  */
115
116