File: cold-profile-trimming.test

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (68 lines) | stat: -rw-r--r-- 2,224 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
; RUN: llvm-profgen --format=text --unsymbolized-profile=%S/Inputs/cold-profile-trimming.raw.prof --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t1 --use-offset=0 --trim-cold-profile=0
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK-NOTRIM
; RUN: llvm-profgen --format=text --unsymbolized-profile=%S/Inputs/cold-profile-trimming.raw.prof --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t1 --use-offset=0 --trim-cold-profile=1 --profile-summary-cold-count=1000
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK-TRIM

;CHECK-NOTRIM: partition_pivot_last:5187:7
;CHECK-NOTRIM: partition_pivot_first:3010:5
;CHECK-NOTRIM: quick_sort:903:25
;CHECK-NOTRIM: main:820:0

;CHECK-TRIM: partition_pivot_last:5187:7
;CHECK-TRIM: partition_pivot_first:3010:5
;CHECK-TRIM-NOT: quick_sort:903:25
;CHECK-TRIM-NOT: main:820:0

; original code:
; clang -O3 -g -fno-optimize-sibling-calls -fdebug-info-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;
}