| # Copyright (C) 2020-2026 Free Software Foundation, Inc. | |
| # This program is free software; you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation; either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with GCC; see the file COPYING3. If not see | |
| # <http://www.gnu.org/licenses/>. | |
| # Utility for scanning offloading dump output, used by libgomp.exp. | |
| # Format an offload dump suffix given the offload target name in | |
| # OFFTGT and any suffix, probably empty, in SUFFIX. | |
| proc scoff-format { offtgt suffix } { | |
| return ".x$offtgt.mkoffload$suffix" | |
| } | |
| # Adjust an offload dump TESTNAME for offload TARGET. | |
| proc scoff-testname { target testname } { | |
| return "$target-$testname" | |
| } | |
| # Adjust the arglist ARGS, so that argument IDX gets scoff-formatted, | |
| # and argument 0 (the test name) gets scoff-testnamed. | |
| proc scoff-adjust { args idx target } { | |
| lset args $idx "[scoff-format $target [lindex $args $idx]]" | |
| lset args 0 "[scoff-testname $target [lindex $args 0]]" | |
| return $args | |
| } | |
| # Wrapper for scan procs. | |
| # Argument 0 is the index of the argument to replace when calling | |
| # argument 1 with the remaining arguments. Use end-1 or end or so. | |
| # If set, the 'global offload_target' specifies one specific offload target to | |
| # test, otherwise iterate over all 'global offload_targets'. | |
| proc scoff { args } { | |
| set idx [lindex $args 0] | |
| set prc [lindex $args 1] | |
| set args [lreplace $args 0 1] | |
| global offload_target | |
| if [info exists offload_target] { | |
| set target $offload_target | |
| if { "$target" != "disable" } { | |
| eval $prc [scoff-adjust $args $idx $target] | |
| } | |
| } else { | |
| global offload_targets | |
| foreach target [split $offload_targets ","] { | |
| # HSA offloading is doing things differently, doesn't use 'mkoffload'. | |
| if { "$target" == "hsa" } continue | |
| eval $prc [scoff-adjust $args $idx $target] | |
| } | |
| } | |
| } | |
| # Wrapper so that only for a specific offload target (first argument) we | |
| # execute a 'dg-final' command (remaining arguments). | |
| proc only_for_offload_target { args } { | |
| set override_offload_target [lindex $args 0] | |
| set cmd [lreplace $args 0 0] | |
| global offload_target | |
| if [info exists offload_target] { | |
| set original_offload_target $offload_target | |
| } | |
| set offload_target $override_offload_target | |
| eval $cmd | |
| if [info exists original_offload_target] { | |
| set offload_target $original_offload_target | |
| } else { | |
| unset offload_target | |
| } | |
| } |