1 ; RUN: llvm-profgen --format=text --unsymbolized-profile=%S/Inputs/fs-discriminator.raw.prof --binary=%S/Inputs/fs-discriminator.perfbin --output=%t1
2 ; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK
3 ; RUN: llvm-profgen --unsymbolized-profile=%S/Inputs/fs-discriminator.raw.prof --binary=%S/Inputs/fs-discriminator.perfbin --output=%t1
4 ; RUN: llvm-profdata show --sample --show-sec-info-only %t1 | FileCheck %s --check-prefix=CHECK-SECTION
6 ;CHECK-SECTION: ProfileSummarySection - Offset: [[#]], Size: [[#]], Flags: {fs-discriminator}
8 ;CHECK: partition_pivot_last:507:1
20 ;CHECK: 4.3221238272: 2
52 ;CHECK: 8: 1 quick_sort:1
57 ;CHECK: partition_pivot_first:298:1
80 ;CHECK: quick_sort:122:2
84 ;CHECK: 2: 2 partition_pivot_first:1 partition_pivot_last:1
85 ;CHECK: 3: 1 quick_sort:1
92 ; clang -O3 -g -mllvm --enable-fs-discriminator -fdebug-info-for-profiling qsort.c -o a.out
96 void swap(int *a, int *b) {
102 int partition_pivot_last(int* array, int low, int high) {
103 int pivot = array[high];
105 for (int j = low; j < high; j++)
106 if (array[j] < pivot)
107 swap(&array[++i], &array[j]);
108 swap(&array[i + 1], &array[high]);
112 int partition_pivot_first(int* array, int low, int high) {
113 int pivot = array[low];
115 for (int j = low + 1; j <= high; j++)
116 if (array[j] < pivot) { if (j != i) swap(&array[i], &array[j]); i++;}
117 swap(&array[i - 1], &array[low]);
121 void quick_sort(int* array, int low, int high, int (*partition_func)(int *, int, int)) {
123 int pi = (*partition_func)(array, low, high);
124 quick_sort(array, low, pi - 1, partition_func);
125 quick_sort(array, pi + 1, high, partition_func);
130 const int size = 200;
132 int *array = malloc(size * sizeof(int));
133 for(int i = 0; i < 100 * 1000; i++) {
134 for(int j = 0; j < size; j++)
135 array[j] = j % 10 ? rand() % size: j;
136 int (*fptr)(int *, int, int) = i % 3 ? partition_pivot_last : partition_pivot_first;
137 quick_sort(array, 0, size - 1, fptr);
138 sum += array[i % size];
140 printf("sum=%d\n", sum);