; RUN: llvm-profgen --unsymbolized-profile=%S/Inputs/fs-discriminator-probe.raw.prof --binary=%S/Inputs/fs-discriminator-probe.perfbin --output=%t1
; RUN: llvm-profdata show --sample --show-sec-info-only %t1 | FileCheck %s --check-prefix=CHECK-SECTION
; RUN: llvm-profdata merge --sample %t1 -o %t2 --text
; RUN: FileCheck %s --input-file %t2 --check-prefix=CHECK
; CHECK-SECTION: ProfileSummarySection - Offset: [[#]], Size: [[#]], Flags: {fs-discriminator}
; CHECK: partition_pivot_first:29661:2739
; CHECK-NEXT: 1: 2739
; CHECK-NEXT: 2.1: 2739
; CHECK-NEXT: 2.11265: 0
; CHECK-NEXT: 3: 6457
; CHECK-NEXT: 4: 508
; CHECK-NEXT: 5.1: 508
; CHECK-NEXT: 6.2: 508
; CHECK-NEXT: 7.3: 2780
; CHECK-NEXT: 8.4: 0
; CHECK-NEXT: 9.2: 0
; CHECK-NEXT: 10: 6457
; CHECK-NEXT: 11: swap:508
; CHECK-NEXT: 1.7680: 508
; CHECK-NEXT: !CFGChecksum: 4294967295
; CHECK-NEXT: 12: swap:6457
; CHECK-NEXT: 1.7168: 6457
; CHECK-NEXT: !CFGChecksum: 4294967295
; CHECK-NEXT: !CFGChecksum: 563159988274199
; CHECK-NEXT: main:16724:1478
; CHECK-NEXT: 1: 1478
; CHECK-NEXT: 2.1: 1478
; CHECK-NEXT: 2.3585: 0
; CHECK-NEXT: 3: 3105
; CHECK-NEXT: 5.1: 9
; CHECK-NEXT: 5.1537: 0
; CHECK-NEXT: 6: 0
; CHECK-NEXT: 7: 2859
; CHECK-NEXT: 8.1: 9
; CHECK-NEXT: 10.3: 0
; CHECK-NEXT: 11.2: 0
; CHECK-NEXT: 12: 0
; CHECK-NEXT: 13.2: 0
; CHECK-NEXT: 14: 3105
; CHECK-NEXT: 15: 1567
; CHECK-NEXT: 16: 9
; CHECK-NEXT: 17: 0
; CHECK-NEXT: 18: 3105
; CHECK-NEXT: !CFGChecksum: 1126178599120658
; CHECK-NEXT: partition_pivot_last:10497:0
; CHECK-NEXT: 1: 0
; CHECK-NEXT: 2.1: 0
; CHECK-NEXT: 2.6145: 1095
; CHECK-NEXT: 2.7681: 241
; CHECK-NEXT: 2.8193: 0
; CHECK-NEXT: 3: 1095
; CHECK-NEXT: 4: 0
; CHECK-NEXT: 4.3072: 1098
; CHECK-NEXT: 4.12800: 0
; CHECK-NEXT: 5: 0
; CHECK-NEXT: 5.5632: 0
; CHECK-NEXT: 5.6144: 1053
; CHECK-NEXT: 6.1: 1095
; CHECK-NEXT: 6.12801: 0
; CHECK-NEXT: 6.13825: 241
; CHECK-NEXT: 7.2: 1095
; CHECK-NEXT: 7.7170: 241
; CHECK-NEXT: 7.7682: 0
; CHECK-NEXT: 8: 1095
; CHECK-NEXT: 9: swap:1053
; CHECK-NEXT: 1.1024: 1053
; CHECK-NEXT: 1.4608: 0
; CHECK-NEXT: 1.15360: 0
; CHECK-NEXT: !CFGChecksum: 4294967295
; CHECK-NEXT: 10: swap:1095
; CHECK-NEXT: 1.14848: 1095
; CHECK-NEXT: !CFGChecksum: 4294967295
; CHECK-NEXT: !CFGChecksum: 563108639284859
; CHECK-NEXT: quick_sort:4881:2519
; CHECK-NEXT: 1: 2016
; CHECK-NEXT: 1.15360: 503
; CHECK-NEXT: 2: 503
; CHECK-NEXT: 3: 678
; CHECK-NEXT: 4: 503
; CHECK-NEXT: 5: 678
; CHECK-NEXT: !CFGChecksum: 844480566202114
; original code:
; clang -O3 -g -mllvm --enable-fs-discriminator -fdebug-info-for-profiling -fpseudo-probe-for-profiling qsort.c -o a.out
#include <stdio.h>
#include <stdlib.h>
void swap(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
int partition_pivot_last(int* array, int low, int high) {
int pivot = array[high];
int i = low - 1;
for (int j = low; j < high; j++)
if (array[j] < pivot)
swap(&array[++i], &array[j]);
swap(&array[i + 1], &array[high]);
return (i + 1);
}
int partition_pivot_first(int* array, int low, int high) {
int pivot = array[low];
int i = low + 1;
for (int j = low + 1; j <= high; j++)
if (array[j] < pivot) { if (j != i) swap(&array[i], &array[j]); i++;}
swap(&array[i - 1], &array[low]);
return i - 1;
}
void quick_sort(int* array, int low, int high, int (*partition_func)(int *, int, int)) {
if (low < high) {
int pi = (*partition_func)(array, low, high);
quick_sort(array, low, pi - 1, partition_func);
quick_sort(array, pi + 1, high, partition_func);
}
}
int main() {
const int size = 200;
int sum = 0;
int *array = malloc(size * sizeof(int));
for(int i = 0; i < 100 * 1000; i++) {
for(int j = 0; j < size; j++)
array[j] = j % 10 ? rand() % size: j;
int (*fptr)(int *, int, int) = i % 3 ? partition_pivot_last : partition_pivot_first;
quick_sort(array, 0, size - 1, fptr);
sum += array[i % size];
}
printf("sum=%d\n", sum);
return 0;
}