Instroduce a template file to define InstrPGO core data structures.
[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, LLVMTypeVar, LLVMType, Name, Initializer) \
21 //    Type Name;
22 // #include "ProfileData/InstrProfData.inc"
23 // };
24 //
25 // 2. To define local variables for struct member's LLVM types"
26 //
27 // #define INSTR_PROF_DATA(Type, LLVMTypeVar, LLVMType, Name, Initializer) \
28 //   LLVMTypeVar = LLVMType;
29 // #include "ProfileData/InstrProfData.inc"
30 //
31 // 3. To construct LLVM type arrays for the struct type:
32 //
33 // Type *DataTypes[] = {
34 // #define INSTR_PROF_DATA(Type, LLVMTypeVar, LLVMType, Name, Initializer) \
35 //   LLVMTypeVar,
36 // #include "ProfileData/InstrProfData.inc"
37 // };
38 //
39 // 4. To construct constant array for the initializers:
40 // #define INSTR_PROF_DATA(Type, LLVMTypeVar, LLVMType, Name, Initializer) \
41 //   Initializer,
42 // Constant *ConstantVals[] = {
43 // #include "ProfileData/InstrProfData.inc"
44 // };
45 //===----------------------------------------------------------------------===//
46
47 #ifndef INSTR_PROF_DATA
48 #define INSTR_PROF_DATA(Type, LLVMTypeVar, LLVMType, Name, Initializer)
49 #endif
50
51 // INSTR_PROF_DATA_START
52 INSTR_PROF_DATA(const uint32_t, Int32Ty, llvm::Type::getInt32Ty(Ctx), NameSize, \
53                 ConstantInt::get(Int32Ty, NameSize))
54 INSTR_PROF_DATA(const uint32_t, Int32Ty, llvm::Type::getInt32Ty(Ctx), NumCounters, \
55                 ConstantInt::get(Int32Ty, NumCounters))
56 INSTR_PROF_DATA(const uint64_t, Int64Ty, llvm::Type::getInt64Ty(Ctx), FuncHash, \
57                 ConstantInt::get(Int64Ty, FuncHash))
58 INSTR_PROF_DATA(const IntPtrT, Int8PtrTy,llvm::Type::getInt8PtrTy(Ctx), NamePtr, \
59                 ConstantExpr::getBitCast(Name, Int8PtrTy))
60 INSTR_PROF_DATA(const IntPtrT, Int64PtrTy, llvm::Type::getInt64PtrTy(Ctx), CounterPtr, \
61                 ConstantExpr::getBitCast(CounterPtr, Int8PtrTy))
62 // INSTR_PROF_DATA_END
63
64 #ifdef INSTR_PROF_DATA
65 #undef INSTR_PROF_DATA
66 #endif
67
68
69 #ifndef COVMAP_FUNC_RECORD
70 #define COVMAP_FUNC_RECORD(Type, LLVMTypeVar, LLVMType, Name, Initializer)
71 #endif
72
73 // COVMAP_FUNC_RECORD_START
74 COVMAP_FUNC_RECORD(const IntPtrT, Int8PtrTy, llvm::Type::getInt8PtrTy(Ctx), \
75                    NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, Int8PtrTy))
76 COVMAP_FUNC_RECORD(const uint32_t, Int32Ty, llvm::Type::getInt32Ty(Ctx), \
77                    NameSize, llvm::ConstantInt::get(Int32Ty, NameSize))
78 COVMAP_FUNC_RECORD(const uint32_t, Int32Ty, llvm::Type::getInt32Ty(Ctx), \
79                    DataSize, llvm::ConstantInt::get(Int32Ty, DataSize))
80 COVMAP_FUNC_RECORD(const uint64_t, Int64Ty, llvm::Type::getInt64Ty(Ctx), \
81                    FuncHash, llvm::ConstantInt::get(Int64Ty, FuncSize))
82 // COVMAP_FUNC_RECORD_END
83
84 #ifdef COVMAP_FUNC_RECORD
85 #undef COVMAP_FUNC_RECORD
86 #endif
87
88