0747ada40ae510f0633eb926a5ba352fe1d28261
[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_END
60
61 #ifdef INSTR_PROF_DATA
62 #undef INSTR_PROF_DATA
63 #endif
64
65
66 #ifndef COVMAP_FUNC_RECORD
67 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
68 #endif
69
70 // COVMAP_FUNC_RECORD_START
71 COVMAP_FUNC_RECORD(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), \
72                    NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
73                    llvm::Type::getInt8PtrTy(Ctx))) 
74 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
75                    llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
76                    NameValue.size()))
77 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), DataSize, \
78                    llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
79                    CoverageMapping.size()))
80 COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
81                    llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), FuncHash))
82 // COVMAP_FUNC_RECORD_END
83
84 #ifdef COVMAP_FUNC_RECORD
85 #undef COVMAP_FUNC_RECORD
86 #endif
87
88