brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · 3666c6a Raw
142 lines · c
1void callee_0() {}2void callee_1() {}3void callee_2() {}4void callee_3() {}5 6void *CalleeAddrs[] = {callee_0, callee_1, callee_2, callee_3};7extern void lprofSetMaxValsPerSite(unsigned);8 9// sequences of callee ids10 11// In the following sequences,12// there are two targets, the dominating target is13// target 0.14int CallSeqTwoTarget_1[] = {0, 0, 0, 0, 0, 1, 1};15int CallSeqTwoTarget_2[] = {1, 1, 0, 0, 0, 0, 0};16int CallSeqTwoTarget_3[] = {1, 0, 0, 1, 0, 0, 0};17int CallSeqTwoTarget_4[] = {0, 0, 0, 1, 0, 1, 0};18 19// In the following sequences, there are three targets20// The dominating target is 0 and has > 50% of total21// counts.22int CallSeqThreeTarget_1[] = {0, 0, 0, 0, 0, 0, 1, 2, 1};23int CallSeqThreeTarget_2[] = {1, 2, 1, 0, 0, 0, 0, 0, 0};24int CallSeqThreeTarget_3[] = {1, 0, 0, 2, 0, 0, 0, 1, 0};25int CallSeqThreeTarget_4[] = {0, 0, 0, 1, 0, 1, 0, 0, 2};26 27// Four target sequence --28// There are two cold targets which occupies the value counters29// early. There is also a very hot target and a medium hot target30// which are invoked in an interleaved fashion -- the length of each31// hot period in the sequence is shorter than the cold targets' count.32//  1. If only two values are tracked, the Hot and Medium hot targets33//     should surive in the end34//  2. If only three values are tracked, the top three targets should35//     surive in the end.36int CallSeqFourTarget_1[] = {1, 1, 1, 2, 2, 2, 2, 0, 0, 3, 0, 0, 3, 0, 0, 3,37                             0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 3};38 39// Same as above, but the cold entries are invoked later.40int CallSeqFourTarget_2[] = {0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 3, 0,41                             0, 3, 0, 0, 3, 0, 0, 3, 1, 1, 1, 2, 2, 2, 2};42 43// Same as above, but all the targets are interleaved.44int CallSeqFourTarget_3[] = {0, 3, 0, 0, 1, 3, 0, 0, 0, 2, 0, 0, 3, 3, 0, 3,45                             2, 2, 0, 3, 3, 1, 0, 0, 1, 0, 0, 3, 0, 2, 0};46 47typedef void (*FPT)(void);48 49 50// Testing value profiling eviction algorithm.51FPT getCalleeFunc(int I) { return CalleeAddrs[I]; }52 53int main() {54  int I;55 56#define INDIRECT_CALLSITE(Sequence, NumValsTracked)                            \57  lprofSetMaxValsPerSite(NumValsTracked);                                      \58  for (I = 0; I < sizeof(Sequence) / sizeof(*Sequence); I++) {                 \59    FPT FP = getCalleeFunc(Sequence[I]);                                       \60    FP();                                                                      \61  }62 63  // check site, target patterns64  // CHECK: 0, {{_?}}callee_065  INDIRECT_CALLSITE(CallSeqTwoTarget_1, 1);66 67  // CHECK-NEXT: 1, {{_?}}callee_068  INDIRECT_CALLSITE(CallSeqTwoTarget_2, 1);69 70  // CHECK-NEXT: 2, {{_?}}callee_071  INDIRECT_CALLSITE(CallSeqTwoTarget_3, 1);72 73  // CHECK-NEXT: 3, {{_?}}callee_074  INDIRECT_CALLSITE(CallSeqTwoTarget_4, 1);75 76  // CHECK-NEXT: 4, {{_?}}callee_077  INDIRECT_CALLSITE(CallSeqThreeTarget_1, 1);78 79  // CHECK-NEXT: 5, {{_?}}callee_080  INDIRECT_CALLSITE(CallSeqThreeTarget_2, 1);81 82  // CHECK-NEXT: 6, {{_?}}callee_083  INDIRECT_CALLSITE(CallSeqThreeTarget_3, 1);84 85  // CHECK-NEXT: 7, {{_?}}callee_086  INDIRECT_CALLSITE(CallSeqThreeTarget_4, 1);87 88  // CHECK-NEXT: 8, {{_?}}callee_089  // CHECK-NEXT: 8, {{_?}}callee_190  INDIRECT_CALLSITE(CallSeqThreeTarget_1, 2);91 92  // CHECK-NEXT: 9, {{_?}}callee_093  // CHECK-NEXT: 9, {{_?}}callee_194  INDIRECT_CALLSITE(CallSeqThreeTarget_2, 2);95 96  // CHECK-NEXT: 10, {{_?}}callee_097  // CHECK-NEXT: 10, {{_?}}callee_198  INDIRECT_CALLSITE(CallSeqThreeTarget_3, 2);99 100  // CHECK-NEXT: 11, {{_?}}callee_0101  // CHECK-NEXT: 11, {{_?}}callee_1102  INDIRECT_CALLSITE(CallSeqThreeTarget_4, 2);103 104  // CHECK-NEXT: 12, {{_?}}callee_0105  INDIRECT_CALLSITE(CallSeqFourTarget_1, 1);106 107  // CHECK-NEXT: 13, {{_?}}callee_0108  INDIRECT_CALLSITE(CallSeqFourTarget_2, 1);109 110  // CHECK-NEXT: 14, {{_?}}callee_0111  INDIRECT_CALLSITE(CallSeqFourTarget_3, 1);112 113  // CHECK-NEXT: 15, {{_?}}callee_0114  // CHECK-NEXT: 15, {{_?}}callee_3115  INDIRECT_CALLSITE(CallSeqFourTarget_1, 2);116 117  // CHECK-NEXT: 16, {{_?}}callee_0118  // CHECK-NEXT: 16, {{_?}}callee_3119  INDIRECT_CALLSITE(CallSeqFourTarget_2, 2);120 121  // CHECK-NEXT: 17, {{_?}}callee_0122  // CHECK-NEXT: 17, {{_?}}callee_3123  INDIRECT_CALLSITE(CallSeqFourTarget_3, 2);124 125  // CHECK-NEXT: 18, {{_?}}callee_0126  // CHECK-NEXT: 18, {{_?}}callee_3127  // CHECK-NEXT: 18, {{_?}}callee_2128  INDIRECT_CALLSITE(CallSeqFourTarget_1, 3);129 130  // CHECK-NEXT: 19, {{_?}}callee_0131  // CHECK-NEXT: 19, {{_?}}callee_3132  // CHECK-NEXT: 19, {{_?}}callee_2133  INDIRECT_CALLSITE(CallSeqFourTarget_2, 3);134 135  // CHECK-NEXT: 20, {{_?}}callee_0136  // CHECK-NEXT: 20, {{_?}}callee_3137  // CHECK-NEXT: 20, {{_?}}callee_2138  INDIRECT_CALLSITE(CallSeqFourTarget_3, 3);139 140  return 0;141}142