]> gcc.gnu.org Git - gcc.git/blame - gcc/testsuite/lib/profopt.exp
vlad.exp: Remove trailing semicolons.
[gcc.git] / gcc / testsuite / lib / profopt.exp
CommitLineData
8304ad70 1# Copyright (C) 2001, 2004 Free Software Foundation, Inc.
3af636b2
JJ
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16#
17# This script was submitted by Janis Johnson <janis187@us.ibm.com>.
18
19# Test the functionality and optionally, performance improvement, of
20# programs compiled with profile-directed optimizations. Compile and
21# run a test with profile options, compile it with options using the
22# profile feedback, and then run the test again. Optionally compile
23# and run a third time without the profile-directed optimization and
24# compare timing results of the program with normal optimization and
25# with the profile-directed optimization. Each test is run using
26# multiple sets of optimization and/or code generation options in
27# addition to the profiling and feedback options.
28
29# If perf_ext is defined and the performance value for the
002b4ef1 30# profile-directed test run is nonzero then the performance check will
3af636b2
JJ
31# be done.
32
33global PROFOPT_OPTIONS perf_delta
34
35# The including .exp file must define these.
36global tool profile_option feedback_option prof_ext
37if ![info exists tool] {
38 error "Tools is not specified."
39}
3af636b2
JJ
40if ![info exists prof_ext] {
41 error "No profile data file extension specified."
42}
43
44# The maximum perforance degradation can be defined in the including file.
45if ![info exists perf_delta] {
46 set perf_delta 4
47}
48
49# The default option list can be overridden by
50# PROFOPT_OPTIONS="{ { list1 } ... { list2 } }"
51
52if ![info exists PROFOPT_OPTIONS] {
53 set PROFOPT_OPTIONS [list \
54 { -g } \
55 { -O0 } \
56 { -O1 } \
57 { -O2 } \
58 { -O3 } \
59 { -O3 -g } \
60 { -Os } ]
61}
62
5dc25517 63set prof_option_list $PROFOPT_OPTIONS
3af636b2
JJ
64
65#
66# profopt-cleanup -- remove profiling or performance results files.
67#
aaee784a
UW
68# TESTCASE is the name of the test
69# EXT is the extension of file to remove
3af636b2 70#
aaee784a
UW
71proc profopt-cleanup { testcase ext } {
72 set basename [file tail $testcase]
73 set base [file rootname $basename]
74 set files [glob -nocomplain $base.$ext]
3af636b2
JJ
75 if { $files != "" } {
76 eval "remote_file build delete $files"
77 }
78}
79
80#
81# profopt-perf-value -- get performance value for a test
82#
83# TESTCASE is the name of the test
84# PERF_EXT is the extension of the performance result file
85# OPTSTR is the string of compiler options
86#
87proc profopt-perf-value { testcase perf_ext optstr } {
88 set basename [file tail $testcase]
89 set base [file rootname $basename]
90 set files [glob -nocomplain $base.$perf_ext]
91 # The file doesn't exist; let the caller decide if that's a problem.
92 if { $files == "" } {
93 return -2
94 }
95 remote_upload host $base.$perf_ext $base.$perf_ext
96 set fd [open $base.$perf_ext r]
97 gets $fd line
98 set val -2
99 if [regexp "TIME" $line] {
100 if [regexp "TIME -1" $line] {
101 fail "$testcase perf check: no consistent time available, $optstr"
102 set val -1
103 } elseif ![regexp "(\[0-9\]+)" "$line" val] {
104 set val -2
105 }
106 }
107 # Report problems with an existing file.
108 if { $val == -2 } {
109 fail "$testcase perf check: file $base.$perf_ext has wrong format, $optstr"
110 }
111 close $fd
aaee784a 112 profopt-cleanup $testcase $perf_ext
3af636b2
JJ
113 return $val
114}
115
116#
117# c-prof-execute -- compile for profiling and then feedback, then normal
118#
119# SRC is the full pathname of the testcase.
120#
121proc profopt-execute { src } {
122 global srcdir tmpdir
5dc25517 123 global prof_option_list
3af636b2
JJ
124 global tool profile_option feedback_option prof_ext perf_ext perf_delta
125 global verbose
126
8304ad70
FCE
127 if ![info exists profile_option] {
128 error "No profile option specified for first compile."
129 }
130 if ![info exists feedback_option] {
131 error "No feedback option specified for second compile."
132 }
133
3af636b2
JJ
134 regsub "^$srcdir/?" $src "" testcase
135 # If we couldn't rip $srcdir out of `src' then just do the best we can.
136 # The point is to reduce the unnecessary noise in the logs. Don't strip
137 # out too much because different testcases with the same name can confuse
138 # `test-tool'.
139 if [string match "/*" $testcase] {
140 set testcase "[file tail [file dirname $src]]/[file tail $src]"
141 }
142
143 set executable $tmpdir/[file tail [file rootname $src].x]
144
145 set count 0
5dc25517 146 foreach option $prof_option_list {
3af636b2
JJ
147 set execname1 "${executable}${count}1"
148 set execname2 "${executable}${count}2"
149 set execname3 "${executable}${count}3"
150 incr count
151
152 remote_file build delete $execname1
153 remote_file build delete $execname2
154 remote_file build delete $execname3
155 verbose "Testing $testcase, $option" 1
156
aaee784a
UW
157 # Remove old profiling and performance data files.
158 profopt-cleanup $testcase $prof_ext
159 if [info exists perf_ext] {
160 profopt-cleanup $testcase $perf_ext
161 }
162
3af636b2
JJ
163 # Compile for profiling.
164
165 set options ""
166 lappend options "additional_flags=$option $profile_option"
167 set optstr "$option $profile_option"
11289ef9 168 set comp_output [${tool}_target_compile "$src" "$execname1" executable $options]
3af636b2
JJ
169 if ![${tool}_check_compile "$testcase compilation" $optstr $execname1 $comp_output] {
170 unresolved "$testcase execution, $optstr"
171 unresolved "$testcase compilation, $option $feedback_option"
172 unresolved "$testcase execution, $option $feedback_option"
173 continue
174 }
175
176 # Run the profiled test.
177
178 set result [${tool}_load $execname1 "" ""]
179 set status [lindex $result 0]
180 # Make sure the profile data was generated, and fail if not.
181 if { $status == "pass" } {
182 set basename [file tail $testcase]
183 set base [file rootname $basename]
184 set files [glob -nocomplain $base.$prof_ext]
185 if { $files == "" } {
186 set status "fail"
187 fail "$testcase execution: file $base.$prof_ext does not exist, $option $profile_option"
188 } else {
189 $status "$testcase execution, $optstr"
190 }
191 } else {
192 $status "$testcase execution, $optstr"
193 }
194 # Quit for this round if it failed
195 if { $status != "pass" } {
196 unresolved "$testcase compilation, $option $feedback_option"
197 unresolved "$testcase execution, $option $feedback_option"
198 continue
199 }
200 remote_file build delete $execname1
201
202 # Compile with feedback-directed optimizations.
203
204 set options ""
205 lappend options "additional_flags=$option $feedback_option"
206 set optstr "$option $feedback_option"
11289ef9 207 set comp_output [${tool}_target_compile "$src" "$execname2" "executable" $options]
3af636b2
JJ
208 if ![${tool}_check_compile "$testcase compilation" $optstr $execname2 $comp_output] {
209 unresolved "$testcase execution, $optstr"
210 continue
211 }
212
213 # Run the profile-directed optimized test.
214
215 set result [${tool}_load "$execname2" "" ""]
216 set status [lindex $result 0]
217 $status "$testcase execution, $optstr"
218 if { $status != "pass" } {
219 continue
220 }
221
222 # Remove the profiling data files.
aaee784a 223 profopt-cleanup $testcase $prof_ext
3af636b2
JJ
224
225 # If the test is not expected to produce performance data then
226 # we're done now.
227 if ![info exists perf_ext] {
228 remote_file build delete $execname2
229 continue
230 }
231
232 # Get the performance data from the test built with
233 # profile-directed optimization. If the file doesn't exist or if
234 # the value is zero, skip the performance comparison.
235 set val2 [profopt-perf-value $testcase $perf_ext $optstr]
236 if { $val2 <= 0 } {
237 remote_file build delete $execname2
238 continue
239 }
240
241 # Compile with normal optimizations.
242
243 set options ""
244 lappend options "additional_flags=$option"
245 set optstr "$option"
11289ef9 246 set comp_output [${tool}_target_compile "$src" "$execname3" "executable" $options]
3af636b2
JJ
247 if ![${tool}_check_compile "$testcase compilation" $optstr $execname3 $comp_output] {
248 unresolved "$testcase execution, $optstr"
249 unresolved "$testcase perf check, $optstr"
250 continue
251 }
252
253 # Run the test with normal optimizations.
254
255 set result [${tool}_load "$execname3" "" ""]
256 set status [lindex $result 0]
257 $status "$testcase execution, $optstr"
258 if { $status != "pass" } {
259 unresolved "$testcase perf check, $optstr"
260 continue
261 }
262
263 # Get the performance data from the test built with normal
264 # optimization.
265 set val1 [profopt-perf-value $testcase $perf_ext $optstr]
266 if { $val1 < 0 } {
267 if { $val1 == -2 } {
268 # The data file existed with the profile-directed
269 # optimization so this one should, too.
270 fail "$testcase perf check: file $base.$perf_ext does not exist, $optstr"
271 }
272 continue
273 }
274
275 # Compare results of the two runs and fail if the time with the
276 # profile-directed optimization is significantly more than the time
277 # without it.
278 set status "pass"
279 if { $val2 > $val1 } {
280 # Check for a performance degration outside of allowable limits.
281 if { [expr $val2 - $val1] > [expr [expr $val1 * $perf_delta] / 100] } {
282 set status "fail"
283 }
284 }
285 if { $status == "fail" } {
286 fail "$testcase perf check: orig: $val1 new: $val2, $optstr"
287 } else {
288 $status "$testcase perf check, $optstr"
289 verbose "$testcase orig: $val1 new: $val2, $optstr" 2
290 remote_file build delete $execname2
291 remote_file build delete $execname3
292 }
293 }
294}
This page took 1.454904 seconds and 5 git commands to generate.