aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/lib/scanoffload.exp
blob: 383e95cd240400b2e7fd1f27cc688b56d4167c56 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#   Copyright (C) 2020-2025 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
    }
}