1 ; RUN: llvm-profgen --format=text --perfscript=%s --binary=%S/Inputs/fs-discriminator-probe.perfbin --output=%t --show-pseudo-probe --show-disassembly-only | FileCheck %s
4 ; CHECK: [Probe]: FUNC: quick_sort Index: 1 Type: Block
5 ; CHECK: [Probe]: FUNC: quick_sort Index: 1 Discriminator: 15360 Type: Block
6 ; CHECK: [Probe]: FUNC: quick_sort Index: 4 Type: IndirectCall
7 ; CHECK: [Probe]: FUNC: quick_sort Index: 5 Type: DirectCall
11 ; clang -O3 -g -mllvm --enable-fs-discriminator -fdebug-info-for-profiling -fpseudo-probe-for-profiling qsort.c -o a.out
15 void swap(int *a, int *b) {
21 int partition_pivot_last(int* array, int low, int high) {
22 int pivot = array[high];
24 for (int j = low; j < high; j++)
26 swap(&array[++i], &array[j]);
27 swap(&array[i + 1], &array[high]);
31 int partition_pivot_first(int* array, int low, int high) {
32 int pivot = array[low];
34 for (int j = low + 1; j <= high; j++)
35 if (array[j] < pivot) { if (j != i) swap(&array[i], &array[j]); i++;}
36 swap(&array[i - 1], &array[low]);
40 void quick_sort(int* array, int low, int high, int (*partition_func)(int *, int, int)) {
42 int pi = (*partition_func)(array, low, high);
43 quick_sort(array, low, pi - 1, partition_func);
44 quick_sort(array, pi + 1, high, partition_func);
51 int *array = malloc(size * sizeof(int));
52 for(int i = 0; i < 100 * 1000; i++) {
53 for(int j = 0; j < size; j++)
54 array[j] = j % 10 ? rand() % size: j;
55 int (*fptr)(int *, int, int) = i % 3 ? partition_pivot_last : partition_pivot_first;
56 quick_sort(array, 0, size - 1, fptr);
57 sum += array[i % size];
59 printf("sum=%d\n", sum);