Debian Codegraph @

benchmarks.larceny/optimize-gcc-options.scm

raw
1 (define bench "")
2
3 (define pop-size 25)
4
5 (define goal <)
6
7 (define (evaluate options)
8 (let ((p (open-process (list path: "./evaluate"
9 arguments: (list bench options)))))
10 (let ((x (read p)))
11 (close-port p)
12 (let ((t (cadr x)))
13 (display ";") (pp (list t options))
14 t))))
15
16 (define options '(
17 ("" " -fno-merge-constants")
18 ("" " -fno-defer-pop")
19 ("" " -fno-thread-jumps")
20 ("" " -fno-guess-branch-probability")
21 ("" " -fno-cprop-registers")
22 ("" " -fno-if-conversion")
23 ("" " -fno-if-conversion2")
24 ("" " -fno-delayed-branch")
25 ("" " -fno-loop-optimize" " -floop-optimize2")
26 ("" " -ftree-ccp")
27 ("" " -ftree-dce")
28 ("" " -ftree-dominator-opts")
29 ("" " -ftree-dse")
30 ("" " -ftree-ter")
31 ("" " -ftree-lrs")
32 ("" " -ftree-sra")
33 ("" " -ftree-copyrename")
34 ("" " -ftree-fre")
35 ("" " -ftree-ch")
36 ("" " -fmerge-constants")
37
38 ("" " -fcrossjumping")
39 ("" " -foptimize-sibling-calls")
40 ("" " -fcse-follow-jumps")
41 ("" " -fcse-skip-blocks")
42 ("" " -fgcse")
43 ("" " -fexpensive-optimizations")
44 ("" " -fstrength-reduce")
45 ("" " -frerun-cse-after-loop")
46 ("" " -frerun-loop-opt")
47 ("" " -fcaller-saves")
48 ("" " -fforce-mem" " -fforce-addr")
49 ("" " -fpeephole2")
50 ("" " -fschedule-insns")
51 ("" " -fschedule-insns2")
52 ("" " -fregmove")
53 ;;;(" -fno-strict-aliasing" " -fstrict-aliasing")
54 ("" " -fdelete-null-pointer-checks")
55 ("" " -freorder-blocks")
56 ("" " -fthread-jumps")
57 ("" " -fgcse-lm")
58 ("" " -fsched-interblock")
59 ("" " -fsched-spec")
60 ("" " -freorder-blocks")
61 ("" " -freorder-functions")
62 ("" " -funit-at-a-time")
63 ("" " -falign-functions")
64 ("" " -falign-jumps")
65 ("" " -falign-loops")
66 ("" " -falign-labels")
67 ("" " -ftree-pre")
68
69 ("" " -finline-functions")
70 ("" " -funswitch-loops")
71 ("" " -fgcse-after-reload")
72
73 ;;;("" " -fomit-frame-pointer" " -momit-leaf-frame-pointer")
74 ("" " -ffloat-store")
75 ("" " -fprefetch-loop-arrays")
76 ("" " -fno-inline")
77 ("" " -fpeel-loops")
78 ("" " -ftracer")
79 ("" " -funroll-loops" " -funroll-all-loops")
80 ("" " -fbranch-target-load-optimize" " -fbranch-target-load-optimize2")
81 ("" " -fmodulo-sched")
82 ("" " -fno-function-cse")
83 ("" " -fgcse-sm")
84 ("" " -fgcse-las")
85 ("" " -freschedule-modulo-scheduled-loops")
86 ("" " -ftree-loop-im")
87 ("" " -ftree-loop-ivcanon")
88 ("" " -fivopts")
89 ("" " -ftree-vectorize")
90 ("" " -fvariable-expansion-in-unroller")
91 ))
92
93 (define (sort-list l <?)
94
95 (define (mergesort l)
96
97 (define (merge l1 l2)
98 (cond ((null? l1) l2)
99 ((null? l2) l1)
100 (else
101 (let ((e1 (car l1)) (e2 (car l2)))
102 (if (<? e1 e2)
103 (cons e1 (merge (cdr l1) l2))
104 (cons e2 (merge l1 (cdr l2))))))))
105
106 (define (split l)
107 (if (or (null? l) (null? (cdr l)))
108 l
109 (cons (car l) (split (cddr l)))))
110
111 (if (or (null? l) (null? (cdr l)))
112 l
113 (let* ((l1 (mergesort (split l)))
114 (l2 (mergesort (split (cdr l)))))
115 (merge l1 l2))))
116
117 (mergesort l))
118
119 (define (iota n)
120 (let loop ((i (- n 1)) (lst '()))
121 (if (>= i 0)
122 (loop (- i 1) (cons i lst))
123 lst)))
124
125 (define (random-options)
126 (map (lambda (x) (list-ref x (random-integer (length x))))
127 options))
128
129 (define (options->string options)
130 (apply string-append options))
131
132 (define (cross options1 options2)
133 (map (lambda (o1 o2 o)
134 (cond ((= 0 (random-integer 35))
135 (list-ref o (random-integer (length o))))
136 ((= 0 (random-integer 2))
137 o1)
138 (else
139 o2)))
140 options1
141 options2
142 options))
143
144 (define (evaluated options)
145 (let* ((t (evaluate (options->string options)))
146 (x (cons t options)))
147 (if (< t (car best))
148 (set! best x))
149 x))
150
151 (define (value evaluated-options)
152 (car evaluated-options))
153
154 (define (opts evaluated-options)
155 (cdr evaluated-options))
156
157 (define (order evaluated-options)
158 (sort-list evaluated-options
159 (lambda (x y) (goal (value x) (value y)))))
160
161 (define (select)
162 (let* ((n (quotient (* pop-size 2) 3))
163 (x (apply + (map (lambda (x) (random-integer 2))
164 (iota (* 2 n)))))
165 (i (abs (- x n))))
166 i))
167
168 (define (new-generation pop)
169 (order
170 (map (lambda (x) (evaluated x))
171 (map (lambda (_)
172 (let ((x (select)))
173 (let loop ()
174 (let ((y (select)))
175 (if (= x y)
176 (loop)
177 (cross (opts (list-ref pop x))
178 (opts (list-ref pop y))))))))
179 pop))))
180
181 (define best '())
182
183 (define (optimize)
184 (set! best (list 99999999999))
185 (let ((initial-pop
186 (order
187 (map (lambda (i) (evaluated (random-options)))
188 (iota pop-size)))))
189 (let loop ((i 0) (pop initial-pop))
190 ; (display ";")(write (list i (map value pop)))(newline)
191 (if (< i 10)
192 (loop (+ i 1)
193 (new-generation pop))
194 best))))
195
196 (for-each
197 (lambda (b)
198 (set! bench b)
199 (pretty-print (list b (optimize))))
200 '("lattice"
201 "ray"
202 "boyer"
203 "diviter"
204 "puzzle"
205 "takl"
206 "fft"
207 "conform"
208 "graphs"
209 "simplex"))