Debian Codegraph @

gcc/config/gcn/gen-gcn-device-macros.awk

raw
1 # Generate $objdir/gcn-device-macros.h from gcn-devices.def
2 #
3 # Copyright (C) 2024-2025 Free Software Foundation, Inc.
4 #
5 # This file is part of GCC.
6 #
7 # GCC is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11 #
12 # GCC is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING3. If not see
19 # <http://www.gnu.org/licenses/>.
20
21 BEGIN {
22 FS= "[(,] *"
23
24 print "/* Generated by gen-gcn-device-macros.awk from gcn-devices.def."
25 print " Do not edit. */"
26
27 list=""
28 generic_list=""
29 }
30
31 /^GCN_DEVICE\(/ {
32 gfx=$2
33 NAME=$3
34 list=(list " OPT_" NAME)
35
36 print ""
37 next
38 }
39
40 /XNACK default.*HSACO_ATTR_UNSUPPORTED/ {
41 printf "\n#define XNACK_%s \"march=%s:;\"", NAME, gfx
42 next
43 }
44
45 /XNACK default.*HSACO_ATTR_OFF/ {
46 printf "\n#define XNACK_%s \"march=%s:%{!mxnack*|mxnack=default|mxnack=off:-mattr=-xnack;mxnack=on:-mattr=+xnack};\"", NAME, gfx
47 next
48 }
49
50 /XNACK default.*HSACO_ATTR_ANY/ {
51 printf "\n#define XNACK_%s \"march=%s:%{mxnack=off:-mattr=-xnack;mxnack=on:-mattr=+xnack};\"", NAME, gfx
52 next
53 }
54
55 /XNACK default.*HSACO/ {
56 print FILENAME ":" NR ": error: unhandled HSACO default at line (gen-gcn-device-macros.awk)" > "/dev/stderr"
57 exit 1
58 }
59
60 /SRAM_ECC default.*HSACO_ATTR_UNSUPPORTED/ {
61 printf "\n#define SRAM_%s \"march=%s:;\"", NAME, gfx
62 next
63 }
64
65 /SRAM_ECC default.*HSACO_ATTR_ANY/ {
66 printf "\n#define SRAM_%s \"march=%s:%{msram-ecc=on:-mattr=+sramecc;msram-ecc=off:-mattr=-sramecc};\"", NAME, gfx
67 next
68 }
69
70 /SRAM_ECC default.*HSACO/ {
71 print FILENAME ":" NR ": error: unhandled HSACO default at line (gen-gcn-device-macros.awk)" > "/dev/stderr"
72 exit 1
73 }
74
75 /WAVE64 mode.*HSACO_ATTR_UNSUPPORTED/ {
76 printf "\n#define WAVE64_%s \"march=%s:;\"", NAME, gfx
77 next
78 }
79
80 /WAVE64 mode.*HSACO_ATTR_ON/ {
81 printf "\n#define WAVE64_%s \"march=%s:-mattr=+wavefrontsize64;\"", NAME, gfx
82 next
83 }
84
85 /WAVE64 mode.*HSACO/ {
86 print FILENAME ":" NR ": error: unhandled HSACO default at line (gen-gcn-device-macros.awk)" > "/dev/stderr"
87 exit 1
88 }
89
90 /CU mode.*HSACO_ATTR_UNSUPPORTED/ {
91 printf "\n#define CU_%s \"march=%s:;\"", NAME, gfx
92 next
93 }
94
95 /CU mode.*HSACO_ATTR_ON/ {
96 printf "\n#define CU_%s \"march=%s:-mattr=+cumode;\"", NAME, gfx
97 next
98 }
99
100 /CU mode.*HSACO/ {
101 print FILENAME ":" NR ": error: unhandled HSACO default at line (gen-gcn-device-macros.awk)" > "/dev/stderr"
102 exit 1
103 }
104
105 /Generic code obj version/ {
106 match($0,/Generic code obj version[^\/]*\/[\t ]*([0-9]+)/,m)
107 if (m[1] > 0) {
108 printf "\n#define GENERIC_%s \"march=%s:--amdhsa-code-object-version=6;\"", NAME, gfx
109 generic_list=(generic_list " GENERIC_" NAME)
110 }
111 next
112 }
113
114 # ABI Version: In principle, the LLVM default would work. However,
115 # however, when debugging symbols are turned on, mkoffload.cc
116 # writes a new AMD GPU object file and the ABI version needs to be the
117 # same. - LLVM <= 17 defaults to 4 while LLVM >= 18 defaults to 5.
118 # GCC supports LLVM >= 13.0.1 and only LLVM >= 14 supports version 5.
119 # Code object V6 is supported since LLVM 19.
120 #
121 # Keep in sync with 'amdhsa.version' in gcn.cc
122 #
123 END {
124 print ""
125 print ""
126 printf "#define ABI_VERSION_OPT \"%%{\"%s \"!march=*|march=*:--amdhsa-code-object-version=4} \"\n", generic_list
127 printf "#define XNACKOPT \"%%{\"%s \":%%eexpected march\\n} \"\n", gensub (/OPT/, "XNACK", "g", list)
128 printf "#define SRAMOPT \"%%{\"%s \":%%eexpected march\\n} \"\n", gensub (/OPT/, "SRAM", "g", list)
129 printf "#define WAVE64OPT \"%%{\"%s \":%%eexpected march\\n} \"\n", gensub (/OPT/, "WAVE64", "g", list)
130 printf "#define CUMODEOPT \"%%{\"%s \":%%eexpected march\\n} \"\n", gensub (/OPT/, "CU", "g", list)
131 }