annotate gcc/hsa-common.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
kono
parents:
diff changeset
1 /* Implementation of commonly needed HSAIL related functions and methods.
kono
parents:
diff changeset
2 Copyright (C) 2013-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3 Contributed by Martin Jambor <mjambor@suse.cz> and
kono
parents:
diff changeset
4 Martin Liska <mliska@suse.cz>.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 This file is part of GCC.
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
10 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
11 any later version.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
16 GNU General Public License for more details.
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
19 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
20 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 #include "config.h"
kono
parents:
diff changeset
23 #include "system.h"
kono
parents:
diff changeset
24 #include "coretypes.h"
kono
parents:
diff changeset
25 #include "tm.h"
kono
parents:
diff changeset
26 #include "is-a.h"
kono
parents:
diff changeset
27 #include "hash-set.h"
kono
parents:
diff changeset
28 #include "hash-map.h"
kono
parents:
diff changeset
29 #include "vec.h"
kono
parents:
diff changeset
30 #include "tree.h"
kono
parents:
diff changeset
31 #include "dumpfile.h"
kono
parents:
diff changeset
32 #include "gimple-pretty-print.h"
kono
parents:
diff changeset
33 #include "diagnostic-core.h"
kono
parents:
diff changeset
34 #include "alloc-pool.h"
kono
parents:
diff changeset
35 #include "cgraph.h"
kono
parents:
diff changeset
36 #include "print-tree.h"
kono
parents:
diff changeset
37 #include "stringpool.h"
kono
parents:
diff changeset
38 #include "symbol-summary.h"
kono
parents:
diff changeset
39 #include "hsa-common.h"
kono
parents:
diff changeset
40 #include "internal-fn.h"
kono
parents:
diff changeset
41 #include "ctype.h"
kono
parents:
diff changeset
42 #include "builtins.h"
kono
parents:
diff changeset
43 #include "stringpool.h"
kono
parents:
diff changeset
44 #include "attribs.h"
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 /* Structure containing intermediate HSA representation of the generated
kono
parents:
diff changeset
47 function. */
kono
parents:
diff changeset
48 class hsa_function_representation *hsa_cfun;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 /* Element of the mapping vector between a host decl and an HSA kernel. */
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 struct GTY(()) hsa_decl_kernel_map_element
kono
parents:
diff changeset
53 {
kono
parents:
diff changeset
54 /* The decl of the host function. */
kono
parents:
diff changeset
55 tree decl;
kono
parents:
diff changeset
56 /* Name of the HSA kernel in BRIG. */
kono
parents:
diff changeset
57 char * GTY((skip)) name;
kono
parents:
diff changeset
58 /* Size of OMP data, if the kernel contains a kernel dispatch. */
kono
parents:
diff changeset
59 unsigned omp_data_size;
kono
parents:
diff changeset
60 /* True if the function is gridified kernel. */
kono
parents:
diff changeset
61 bool gridified_kernel_p;
kono
parents:
diff changeset
62 };
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 /* Mapping between decls and corresponding HSA kernels in this compilation
kono
parents:
diff changeset
65 unit. */
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 static GTY (()) vec<hsa_decl_kernel_map_element, va_gc>
kono
parents:
diff changeset
68 *hsa_decl_kernel_mapping;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 /* Mapping between decls and corresponding HSA kernels
kono
parents:
diff changeset
71 called by the function. */
kono
parents:
diff changeset
72 hash_map <tree, vec <const char *> *> *hsa_decl_kernel_dependencies;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 /* Hash function to lookup a symbol for a decl. */
kono
parents:
diff changeset
75 hash_table <hsa_noop_symbol_hasher> *hsa_global_variable_symbols;
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 /* HSA summaries. */
kono
parents:
diff changeset
78 hsa_summary_t *hsa_summaries = NULL;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 /* HSA number of threads. */
kono
parents:
diff changeset
81 hsa_symbol *hsa_num_threads = NULL;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 /* HSA function that cannot be expanded to HSAIL. */
kono
parents:
diff changeset
84 hash_set <tree> *hsa_failed_functions = NULL;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 /* True if compilation unit-wide data are already allocated and initialized. */
kono
parents:
diff changeset
87 static bool compilation_unit_data_initialized;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 /* Return true if FNDECL represents an HSA-callable function. */
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 bool
kono
parents:
diff changeset
92 hsa_callable_function_p (tree fndecl)
kono
parents:
diff changeset
93 {
kono
parents:
diff changeset
94 return (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (fndecl))
kono
parents:
diff changeset
95 && !lookup_attribute ("oacc function", DECL_ATTRIBUTES (fndecl)));
kono
parents:
diff changeset
96 }
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 /* Allocate HSA structures that are are used when dealing with different
kono
parents:
diff changeset
99 functions. */
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 void
kono
parents:
diff changeset
102 hsa_init_compilation_unit_data (void)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 if (compilation_unit_data_initialized)
kono
parents:
diff changeset
105 return;
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 compilation_unit_data_initialized = true;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 hsa_global_variable_symbols = new hash_table <hsa_noop_symbol_hasher> (8);
kono
parents:
diff changeset
110 hsa_failed_functions = new hash_set <tree> ();
kono
parents:
diff changeset
111 hsa_emitted_internal_decls = new hash_table <hsa_internal_fn_hasher> (2);
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 /* Free data structures that are used when dealing with different
kono
parents:
diff changeset
115 functions. */
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 void
kono
parents:
diff changeset
118 hsa_deinit_compilation_unit_data (void)
kono
parents:
diff changeset
119 {
kono
parents:
diff changeset
120 gcc_assert (compilation_unit_data_initialized);
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 delete hsa_failed_functions;
kono
parents:
diff changeset
123 delete hsa_emitted_internal_decls;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 for (hash_table <hsa_noop_symbol_hasher>::iterator it
kono
parents:
diff changeset
126 = hsa_global_variable_symbols->begin ();
kono
parents:
diff changeset
127 it != hsa_global_variable_symbols->end ();
kono
parents:
diff changeset
128 ++it)
kono
parents:
diff changeset
129 {
kono
parents:
diff changeset
130 hsa_symbol *sym = *it;
kono
parents:
diff changeset
131 delete sym;
kono
parents:
diff changeset
132 }
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 delete hsa_global_variable_symbols;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 if (hsa_num_threads)
kono
parents:
diff changeset
137 {
kono
parents:
diff changeset
138 delete hsa_num_threads;
kono
parents:
diff changeset
139 hsa_num_threads = NULL;
kono
parents:
diff changeset
140 }
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 compilation_unit_data_initialized = false;
kono
parents:
diff changeset
143 }
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 /* Return true if we are generating large HSA machine model. */
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 bool
kono
parents:
diff changeset
148 hsa_machine_large_p (void)
kono
parents:
diff changeset
149 {
kono
parents:
diff changeset
150 /* FIXME: I suppose this is technically wrong but should work for me now. */
kono
parents:
diff changeset
151 return (GET_MODE_BITSIZE (Pmode) == 64);
kono
parents:
diff changeset
152 }
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 /* Return the HSA profile we are using. */
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 bool
kono
parents:
diff changeset
157 hsa_full_profile_p (void)
kono
parents:
diff changeset
158 {
kono
parents:
diff changeset
159 return true;
kono
parents:
diff changeset
160 }
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 /* Return true if a register in operand number OPNUM of instruction
kono
parents:
diff changeset
163 is an output. False if it is an input. */
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 bool
kono
parents:
diff changeset
166 hsa_insn_basic::op_output_p (unsigned opnum)
kono
parents:
diff changeset
167 {
kono
parents:
diff changeset
168 switch (m_opcode)
kono
parents:
diff changeset
169 {
kono
parents:
diff changeset
170 case HSA_OPCODE_PHI:
kono
parents:
diff changeset
171 case BRIG_OPCODE_CBR:
kono
parents:
diff changeset
172 case BRIG_OPCODE_SBR:
kono
parents:
diff changeset
173 case BRIG_OPCODE_ST:
kono
parents:
diff changeset
174 case BRIG_OPCODE_SIGNALNORET:
kono
parents:
diff changeset
175 case BRIG_OPCODE_DEBUGTRAP:
kono
parents:
diff changeset
176 /* FIXME: There are probably missing cases here, double check. */
kono
parents:
diff changeset
177 return false;
kono
parents:
diff changeset
178 case BRIG_OPCODE_EXPAND:
kono
parents:
diff changeset
179 /* Example: expand_v4_b32_b128 (dest0, dest1, dest2, dest3), src0. */
kono
parents:
diff changeset
180 return opnum < operand_count () - 1;
kono
parents:
diff changeset
181 default:
kono
parents:
diff changeset
182 return opnum == 0;
kono
parents:
diff changeset
183 }
kono
parents:
diff changeset
184 }
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 /* Return true if OPCODE is an floating-point bit instruction opcode. */
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 bool
kono
parents:
diff changeset
189 hsa_opcode_floating_bit_insn_p (BrigOpcode16_t opcode)
kono
parents:
diff changeset
190 {
kono
parents:
diff changeset
191 switch (opcode)
kono
parents:
diff changeset
192 {
kono
parents:
diff changeset
193 case BRIG_OPCODE_NEG:
kono
parents:
diff changeset
194 case BRIG_OPCODE_ABS:
kono
parents:
diff changeset
195 case BRIG_OPCODE_CLASS:
kono
parents:
diff changeset
196 case BRIG_OPCODE_COPYSIGN:
kono
parents:
diff changeset
197 return true;
kono
parents:
diff changeset
198 default:
kono
parents:
diff changeset
199 return false;
kono
parents:
diff changeset
200 }
kono
parents:
diff changeset
201 }
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 /* Return the number of destination operands for this INSN. */
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 unsigned
kono
parents:
diff changeset
206 hsa_insn_basic::input_count ()
kono
parents:
diff changeset
207 {
kono
parents:
diff changeset
208 switch (m_opcode)
kono
parents:
diff changeset
209 {
kono
parents:
diff changeset
210 default:
kono
parents:
diff changeset
211 return 1;
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 case BRIG_OPCODE_NOP:
kono
parents:
diff changeset
214 return 0;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 case BRIG_OPCODE_EXPAND:
kono
parents:
diff changeset
217 return 2;
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 case BRIG_OPCODE_LD:
kono
parents:
diff changeset
220 /* ld_v[234] not yet handled. */
kono
parents:
diff changeset
221 return 1;
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 case BRIG_OPCODE_ST:
kono
parents:
diff changeset
224 return 0;
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 case BRIG_OPCODE_ATOMICNORET:
kono
parents:
diff changeset
227 return 0;
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 case BRIG_OPCODE_SIGNAL:
kono
parents:
diff changeset
230 return 1;
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 case BRIG_OPCODE_SIGNALNORET:
kono
parents:
diff changeset
233 return 0;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 case BRIG_OPCODE_MEMFENCE:
kono
parents:
diff changeset
236 return 0;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 case BRIG_OPCODE_RDIMAGE:
kono
parents:
diff changeset
239 case BRIG_OPCODE_LDIMAGE:
kono
parents:
diff changeset
240 case BRIG_OPCODE_STIMAGE:
kono
parents:
diff changeset
241 case BRIG_OPCODE_QUERYIMAGE:
kono
parents:
diff changeset
242 case BRIG_OPCODE_QUERYSAMPLER:
kono
parents:
diff changeset
243 sorry ("HSA image ops not handled");
kono
parents:
diff changeset
244 return 0;
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 case BRIG_OPCODE_CBR:
kono
parents:
diff changeset
247 case BRIG_OPCODE_BR:
kono
parents:
diff changeset
248 return 0;
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 case BRIG_OPCODE_SBR:
kono
parents:
diff changeset
251 return 0; /* ??? */
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 case BRIG_OPCODE_WAVEBARRIER:
kono
parents:
diff changeset
254 return 0; /* ??? */
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 case BRIG_OPCODE_BARRIER:
kono
parents:
diff changeset
257 case BRIG_OPCODE_ARRIVEFBAR:
kono
parents:
diff changeset
258 case BRIG_OPCODE_INITFBAR:
kono
parents:
diff changeset
259 case BRIG_OPCODE_JOINFBAR:
kono
parents:
diff changeset
260 case BRIG_OPCODE_LEAVEFBAR:
kono
parents:
diff changeset
261 case BRIG_OPCODE_RELEASEFBAR:
kono
parents:
diff changeset
262 case BRIG_OPCODE_WAITFBAR:
kono
parents:
diff changeset
263 return 0;
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 case BRIG_OPCODE_LDF:
kono
parents:
diff changeset
266 return 1;
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 case BRIG_OPCODE_ACTIVELANECOUNT:
kono
parents:
diff changeset
269 case BRIG_OPCODE_ACTIVELANEID:
kono
parents:
diff changeset
270 case BRIG_OPCODE_ACTIVELANEMASK:
kono
parents:
diff changeset
271 case BRIG_OPCODE_ACTIVELANEPERMUTE:
kono
parents:
diff changeset
272 return 1; /* ??? */
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 case BRIG_OPCODE_CALL:
kono
parents:
diff changeset
275 case BRIG_OPCODE_SCALL:
kono
parents:
diff changeset
276 case BRIG_OPCODE_ICALL:
kono
parents:
diff changeset
277 return 0;
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 case BRIG_OPCODE_RET:
kono
parents:
diff changeset
280 return 0;
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 case BRIG_OPCODE_ALLOCA:
kono
parents:
diff changeset
283 return 1;
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 case BRIG_OPCODE_CLEARDETECTEXCEPT:
kono
parents:
diff changeset
286 return 0;
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 case BRIG_OPCODE_SETDETECTEXCEPT:
kono
parents:
diff changeset
289 return 0;
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 case BRIG_OPCODE_PACKETCOMPLETIONSIG:
kono
parents:
diff changeset
292 case BRIG_OPCODE_PACKETID:
kono
parents:
diff changeset
293 case BRIG_OPCODE_CASQUEUEWRITEINDEX:
kono
parents:
diff changeset
294 case BRIG_OPCODE_LDQUEUEREADINDEX:
kono
parents:
diff changeset
295 case BRIG_OPCODE_LDQUEUEWRITEINDEX:
kono
parents:
diff changeset
296 case BRIG_OPCODE_STQUEUEREADINDEX:
kono
parents:
diff changeset
297 case BRIG_OPCODE_STQUEUEWRITEINDEX:
kono
parents:
diff changeset
298 return 1; /* ??? */
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 case BRIG_OPCODE_ADDQUEUEWRITEINDEX:
kono
parents:
diff changeset
301 return 1;
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 case BRIG_OPCODE_DEBUGTRAP:
kono
parents:
diff changeset
304 return 0;
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 case BRIG_OPCODE_GROUPBASEPTR:
kono
parents:
diff changeset
307 case BRIG_OPCODE_KERNARGBASEPTR:
kono
parents:
diff changeset
308 return 1; /* ??? */
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 case HSA_OPCODE_ARG_BLOCK:
kono
parents:
diff changeset
311 return 0;
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 case BRIG_KIND_DIRECTIVE_COMMENT:
kono
parents:
diff changeset
314 return 0;
kono
parents:
diff changeset
315 }
kono
parents:
diff changeset
316 }
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 /* Return the number of source operands for this INSN. */
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 unsigned
kono
parents:
diff changeset
321 hsa_insn_basic::num_used_ops ()
kono
parents:
diff changeset
322 {
kono
parents:
diff changeset
323 gcc_checking_assert (input_count () <= operand_count ());
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 return operand_count () - input_count ();
kono
parents:
diff changeset
326 }
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 /* Set alignment to VALUE. */
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 void
kono
parents:
diff changeset
331 hsa_insn_mem::set_align (BrigAlignment8_t value)
kono
parents:
diff changeset
332 {
kono
parents:
diff changeset
333 /* TODO: Perhaps remove this dump later on: */
kono
parents:
diff changeset
334 if (dump_file && (dump_flags & TDF_DETAILS) && value < m_align)
kono
parents:
diff changeset
335 {
kono
parents:
diff changeset
336 fprintf (dump_file, "Decreasing alignment to %u in instruction ", value);
kono
parents:
diff changeset
337 dump_hsa_insn (dump_file, this);
kono
parents:
diff changeset
338 }
kono
parents:
diff changeset
339 m_align = value;
kono
parents:
diff changeset
340 }
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 /* Return size of HSA type T in bits. */
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 unsigned
kono
parents:
diff changeset
345 hsa_type_bit_size (BrigType16_t t)
kono
parents:
diff changeset
346 {
kono
parents:
diff changeset
347 switch (t)
kono
parents:
diff changeset
348 {
kono
parents:
diff changeset
349 case BRIG_TYPE_B1:
kono
parents:
diff changeset
350 return 1;
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 case BRIG_TYPE_U8:
kono
parents:
diff changeset
353 case BRIG_TYPE_S8:
kono
parents:
diff changeset
354 case BRIG_TYPE_B8:
kono
parents:
diff changeset
355 return 8;
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 case BRIG_TYPE_U16:
kono
parents:
diff changeset
358 case BRIG_TYPE_S16:
kono
parents:
diff changeset
359 case BRIG_TYPE_B16:
kono
parents:
diff changeset
360 case BRIG_TYPE_F16:
kono
parents:
diff changeset
361 return 16;
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 case BRIG_TYPE_U32:
kono
parents:
diff changeset
364 case BRIG_TYPE_S32:
kono
parents:
diff changeset
365 case BRIG_TYPE_B32:
kono
parents:
diff changeset
366 case BRIG_TYPE_F32:
kono
parents:
diff changeset
367 case BRIG_TYPE_U8X4:
kono
parents:
diff changeset
368 case BRIG_TYPE_U16X2:
kono
parents:
diff changeset
369 case BRIG_TYPE_S8X4:
kono
parents:
diff changeset
370 case BRIG_TYPE_S16X2:
kono
parents:
diff changeset
371 case BRIG_TYPE_F16X2:
kono
parents:
diff changeset
372 return 32;
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 case BRIG_TYPE_U64:
kono
parents:
diff changeset
375 case BRIG_TYPE_S64:
kono
parents:
diff changeset
376 case BRIG_TYPE_F64:
kono
parents:
diff changeset
377 case BRIG_TYPE_B64:
kono
parents:
diff changeset
378 case BRIG_TYPE_U8X8:
kono
parents:
diff changeset
379 case BRIG_TYPE_U16X4:
kono
parents:
diff changeset
380 case BRIG_TYPE_U32X2:
kono
parents:
diff changeset
381 case BRIG_TYPE_S8X8:
kono
parents:
diff changeset
382 case BRIG_TYPE_S16X4:
kono
parents:
diff changeset
383 case BRIG_TYPE_S32X2:
kono
parents:
diff changeset
384 case BRIG_TYPE_F16X4:
kono
parents:
diff changeset
385 case BRIG_TYPE_F32X2:
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 return 64;
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 case BRIG_TYPE_B128:
kono
parents:
diff changeset
390 case BRIG_TYPE_U8X16:
kono
parents:
diff changeset
391 case BRIG_TYPE_U16X8:
kono
parents:
diff changeset
392 case BRIG_TYPE_U32X4:
kono
parents:
diff changeset
393 case BRIG_TYPE_U64X2:
kono
parents:
diff changeset
394 case BRIG_TYPE_S8X16:
kono
parents:
diff changeset
395 case BRIG_TYPE_S16X8:
kono
parents:
diff changeset
396 case BRIG_TYPE_S32X4:
kono
parents:
diff changeset
397 case BRIG_TYPE_S64X2:
kono
parents:
diff changeset
398 case BRIG_TYPE_F16X8:
kono
parents:
diff changeset
399 case BRIG_TYPE_F32X4:
kono
parents:
diff changeset
400 case BRIG_TYPE_F64X2:
kono
parents:
diff changeset
401 return 128;
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403 default:
kono
parents:
diff changeset
404 gcc_assert (hsa_seen_error ());
kono
parents:
diff changeset
405 return t;
kono
parents:
diff changeset
406 }
kono
parents:
diff changeset
407 }
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 /* Return BRIG bit-type with BITSIZE length. */
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 BrigType16_t
kono
parents:
diff changeset
412 hsa_bittype_for_bitsize (unsigned bitsize)
kono
parents:
diff changeset
413 {
kono
parents:
diff changeset
414 switch (bitsize)
kono
parents:
diff changeset
415 {
kono
parents:
diff changeset
416 case 1:
kono
parents:
diff changeset
417 return BRIG_TYPE_B1;
kono
parents:
diff changeset
418 case 8:
kono
parents:
diff changeset
419 return BRIG_TYPE_B8;
kono
parents:
diff changeset
420 case 16:
kono
parents:
diff changeset
421 return BRIG_TYPE_B16;
kono
parents:
diff changeset
422 case 32:
kono
parents:
diff changeset
423 return BRIG_TYPE_B32;
kono
parents:
diff changeset
424 case 64:
kono
parents:
diff changeset
425 return BRIG_TYPE_B64;
kono
parents:
diff changeset
426 case 128:
kono
parents:
diff changeset
427 return BRIG_TYPE_B128;
kono
parents:
diff changeset
428 default:
kono
parents:
diff changeset
429 gcc_unreachable ();
kono
parents:
diff changeset
430 }
kono
parents:
diff changeset
431 }
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 /* Return BRIG unsigned int type with BITSIZE length. */
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 BrigType16_t
kono
parents:
diff changeset
436 hsa_uint_for_bitsize (unsigned bitsize)
kono
parents:
diff changeset
437 {
kono
parents:
diff changeset
438 switch (bitsize)
kono
parents:
diff changeset
439 {
kono
parents:
diff changeset
440 case 8:
kono
parents:
diff changeset
441 return BRIG_TYPE_U8;
kono
parents:
diff changeset
442 case 16:
kono
parents:
diff changeset
443 return BRIG_TYPE_U16;
kono
parents:
diff changeset
444 case 32:
kono
parents:
diff changeset
445 return BRIG_TYPE_U32;
kono
parents:
diff changeset
446 case 64:
kono
parents:
diff changeset
447 return BRIG_TYPE_U64;
kono
parents:
diff changeset
448 default:
kono
parents:
diff changeset
449 gcc_unreachable ();
kono
parents:
diff changeset
450 }
kono
parents:
diff changeset
451 }
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 /* Return BRIG float type with BITSIZE length. */
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 BrigType16_t
kono
parents:
diff changeset
456 hsa_float_for_bitsize (unsigned bitsize)
kono
parents:
diff changeset
457 {
kono
parents:
diff changeset
458 switch (bitsize)
kono
parents:
diff changeset
459 {
kono
parents:
diff changeset
460 case 16:
kono
parents:
diff changeset
461 return BRIG_TYPE_F16;
kono
parents:
diff changeset
462 case 32:
kono
parents:
diff changeset
463 return BRIG_TYPE_F32;
kono
parents:
diff changeset
464 case 64:
kono
parents:
diff changeset
465 return BRIG_TYPE_F64;
kono
parents:
diff changeset
466 default:
kono
parents:
diff changeset
467 gcc_unreachable ();
kono
parents:
diff changeset
468 }
kono
parents:
diff changeset
469 }
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 /* Return HSA bit-type with the same size as the type T. */
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 BrigType16_t
kono
parents:
diff changeset
474 hsa_bittype_for_type (BrigType16_t t)
kono
parents:
diff changeset
475 {
kono
parents:
diff changeset
476 return hsa_bittype_for_bitsize (hsa_type_bit_size (t));
kono
parents:
diff changeset
477 }
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 /* Return HSA unsigned integer type with the same size as the type T. */
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 BrigType16_t
kono
parents:
diff changeset
482 hsa_unsigned_type_for_type (BrigType16_t t)
kono
parents:
diff changeset
483 {
kono
parents:
diff changeset
484 return hsa_uint_for_bitsize (hsa_type_bit_size (t));
kono
parents:
diff changeset
485 }
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 /* Return true if TYPE is a packed HSA type. */
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 bool
kono
parents:
diff changeset
490 hsa_type_packed_p (BrigType16_t type)
kono
parents:
diff changeset
491 {
kono
parents:
diff changeset
492 return (type & BRIG_TYPE_PACK_MASK) != BRIG_TYPE_PACK_NONE;
kono
parents:
diff changeset
493 }
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 /* Return true if and only if TYPE is a floating point number type. */
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 bool
kono
parents:
diff changeset
498 hsa_type_float_p (BrigType16_t type)
kono
parents:
diff changeset
499 {
kono
parents:
diff changeset
500 switch (type & BRIG_TYPE_BASE_MASK)
kono
parents:
diff changeset
501 {
kono
parents:
diff changeset
502 case BRIG_TYPE_F16:
kono
parents:
diff changeset
503 case BRIG_TYPE_F32:
kono
parents:
diff changeset
504 case BRIG_TYPE_F64:
kono
parents:
diff changeset
505 return true;
kono
parents:
diff changeset
506 default:
kono
parents:
diff changeset
507 return false;
kono
parents:
diff changeset
508 }
kono
parents:
diff changeset
509 }
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 /* Return true if and only if TYPE is an integer number type. */
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 bool
kono
parents:
diff changeset
514 hsa_type_integer_p (BrigType16_t type)
kono
parents:
diff changeset
515 {
kono
parents:
diff changeset
516 switch (type & BRIG_TYPE_BASE_MASK)
kono
parents:
diff changeset
517 {
kono
parents:
diff changeset
518 case BRIG_TYPE_U8:
kono
parents:
diff changeset
519 case BRIG_TYPE_U16:
kono
parents:
diff changeset
520 case BRIG_TYPE_U32:
kono
parents:
diff changeset
521 case BRIG_TYPE_U64:
kono
parents:
diff changeset
522 case BRIG_TYPE_S8:
kono
parents:
diff changeset
523 case BRIG_TYPE_S16:
kono
parents:
diff changeset
524 case BRIG_TYPE_S32:
kono
parents:
diff changeset
525 case BRIG_TYPE_S64:
kono
parents:
diff changeset
526 return true;
kono
parents:
diff changeset
527 default:
kono
parents:
diff changeset
528 return false;
kono
parents:
diff changeset
529 }
kono
parents:
diff changeset
530 }
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 /* Return true if and only if TYPE is an bit-type. */
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 bool
kono
parents:
diff changeset
535 hsa_btype_p (BrigType16_t type)
kono
parents:
diff changeset
536 {
kono
parents:
diff changeset
537 switch (type & BRIG_TYPE_BASE_MASK)
kono
parents:
diff changeset
538 {
kono
parents:
diff changeset
539 case BRIG_TYPE_B8:
kono
parents:
diff changeset
540 case BRIG_TYPE_B16:
kono
parents:
diff changeset
541 case BRIG_TYPE_B32:
kono
parents:
diff changeset
542 case BRIG_TYPE_B64:
kono
parents:
diff changeset
543 case BRIG_TYPE_B128:
kono
parents:
diff changeset
544 return true;
kono
parents:
diff changeset
545 default:
kono
parents:
diff changeset
546 return false;
kono
parents:
diff changeset
547 }
kono
parents:
diff changeset
548 }
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 /* Return HSA alignment encoding alignment to N bits. */
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 BrigAlignment8_t
kono
parents:
diff changeset
554 hsa_alignment_encoding (unsigned n)
kono
parents:
diff changeset
555 {
kono
parents:
diff changeset
556 gcc_assert (n >= 8 && !(n & (n - 1)));
kono
parents:
diff changeset
557 if (n >= 256)
kono
parents:
diff changeset
558 return BRIG_ALIGNMENT_32;
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 switch (n)
kono
parents:
diff changeset
561 {
kono
parents:
diff changeset
562 case 8:
kono
parents:
diff changeset
563 return BRIG_ALIGNMENT_1;
kono
parents:
diff changeset
564 case 16:
kono
parents:
diff changeset
565 return BRIG_ALIGNMENT_2;
kono
parents:
diff changeset
566 case 32:
kono
parents:
diff changeset
567 return BRIG_ALIGNMENT_4;
kono
parents:
diff changeset
568 case 64:
kono
parents:
diff changeset
569 return BRIG_ALIGNMENT_8;
kono
parents:
diff changeset
570 case 128:
kono
parents:
diff changeset
571 return BRIG_ALIGNMENT_16;
kono
parents:
diff changeset
572 default:
kono
parents:
diff changeset
573 gcc_unreachable ();
kono
parents:
diff changeset
574 }
kono
parents:
diff changeset
575 }
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 /* Return HSA alignment encoding alignment of T got
kono
parents:
diff changeset
578 by get_object_alignment. */
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 BrigAlignment8_t
kono
parents:
diff changeset
581 hsa_object_alignment (tree t)
kono
parents:
diff changeset
582 {
kono
parents:
diff changeset
583 return hsa_alignment_encoding (get_object_alignment (t));
kono
parents:
diff changeset
584 }
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 /* Return byte alignment for given BrigAlignment8_t value. */
kono
parents:
diff changeset
587
kono
parents:
diff changeset
588 unsigned
kono
parents:
diff changeset
589 hsa_byte_alignment (BrigAlignment8_t alignment)
kono
parents:
diff changeset
590 {
kono
parents:
diff changeset
591 gcc_assert (alignment != BRIG_ALIGNMENT_NONE);
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 return 1 << (alignment - 1);
kono
parents:
diff changeset
594 }
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 /* Return natural alignment of HSA TYPE. */
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 BrigAlignment8_t
kono
parents:
diff changeset
599 hsa_natural_alignment (BrigType16_t type)
kono
parents:
diff changeset
600 {
kono
parents:
diff changeset
601 return hsa_alignment_encoding (hsa_type_bit_size (type & ~BRIG_TYPE_ARRAY));
kono
parents:
diff changeset
602 }
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 /* Call the correct destructor of a HSA instruction. */
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 void
kono
parents:
diff changeset
607 hsa_destroy_insn (hsa_insn_basic *insn)
kono
parents:
diff changeset
608 {
kono
parents:
diff changeset
609 if (hsa_insn_phi *phi = dyn_cast <hsa_insn_phi *> (insn))
kono
parents:
diff changeset
610 phi->~hsa_insn_phi ();
kono
parents:
diff changeset
611 else if (hsa_insn_cbr *br = dyn_cast <hsa_insn_cbr *> (insn))
kono
parents:
diff changeset
612 br->~hsa_insn_cbr ();
kono
parents:
diff changeset
613 else if (hsa_insn_cmp *cmp = dyn_cast <hsa_insn_cmp *> (insn))
kono
parents:
diff changeset
614 cmp->~hsa_insn_cmp ();
kono
parents:
diff changeset
615 else if (hsa_insn_mem *mem = dyn_cast <hsa_insn_mem *> (insn))
kono
parents:
diff changeset
616 mem->~hsa_insn_mem ();
kono
parents:
diff changeset
617 else if (hsa_insn_atomic *atomic = dyn_cast <hsa_insn_atomic *> (insn))
kono
parents:
diff changeset
618 atomic->~hsa_insn_atomic ();
kono
parents:
diff changeset
619 else if (hsa_insn_seg *seg = dyn_cast <hsa_insn_seg *> (insn))
kono
parents:
diff changeset
620 seg->~hsa_insn_seg ();
kono
parents:
diff changeset
621 else if (hsa_insn_call *call = dyn_cast <hsa_insn_call *> (insn))
kono
parents:
diff changeset
622 call->~hsa_insn_call ();
kono
parents:
diff changeset
623 else if (hsa_insn_arg_block *block = dyn_cast <hsa_insn_arg_block *> (insn))
kono
parents:
diff changeset
624 block->~hsa_insn_arg_block ();
kono
parents:
diff changeset
625 else if (hsa_insn_sbr *sbr = dyn_cast <hsa_insn_sbr *> (insn))
kono
parents:
diff changeset
626 sbr->~hsa_insn_sbr ();
kono
parents:
diff changeset
627 else if (hsa_insn_br *br = dyn_cast <hsa_insn_br *> (insn))
kono
parents:
diff changeset
628 br->~hsa_insn_br ();
kono
parents:
diff changeset
629 else if (hsa_insn_comment *comment = dyn_cast <hsa_insn_comment *> (insn))
kono
parents:
diff changeset
630 comment->~hsa_insn_comment ();
kono
parents:
diff changeset
631 else
kono
parents:
diff changeset
632 insn->~hsa_insn_basic ();
kono
parents:
diff changeset
633 }
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 /* Call the correct destructor of a HSA operand. */
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 void
kono
parents:
diff changeset
638 hsa_destroy_operand (hsa_op_base *op)
kono
parents:
diff changeset
639 {
kono
parents:
diff changeset
640 if (hsa_op_code_list *list = dyn_cast <hsa_op_code_list *> (op))
kono
parents:
diff changeset
641 list->~hsa_op_code_list ();
kono
parents:
diff changeset
642 else if (hsa_op_operand_list *list = dyn_cast <hsa_op_operand_list *> (op))
kono
parents:
diff changeset
643 list->~hsa_op_operand_list ();
kono
parents:
diff changeset
644 else if (hsa_op_reg *reg = dyn_cast <hsa_op_reg *> (op))
kono
parents:
diff changeset
645 reg->~hsa_op_reg ();
kono
parents:
diff changeset
646 else if (hsa_op_immed *immed = dyn_cast <hsa_op_immed *> (op))
kono
parents:
diff changeset
647 immed->~hsa_op_immed ();
kono
parents:
diff changeset
648 else
kono
parents:
diff changeset
649 op->~hsa_op_base ();
kono
parents:
diff changeset
650 }
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 /* Create a mapping between the original function DECL and kernel name NAME. */
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 void
kono
parents:
diff changeset
655 hsa_add_kern_decl_mapping (tree decl, char *name, unsigned omp_data_size,
kono
parents:
diff changeset
656 bool gridified_kernel_p)
kono
parents:
diff changeset
657 {
kono
parents:
diff changeset
658 hsa_decl_kernel_map_element dkm;
kono
parents:
diff changeset
659 dkm.decl = decl;
kono
parents:
diff changeset
660 dkm.name = name;
kono
parents:
diff changeset
661 dkm.omp_data_size = omp_data_size;
kono
parents:
diff changeset
662 dkm.gridified_kernel_p = gridified_kernel_p;
kono
parents:
diff changeset
663 vec_safe_push (hsa_decl_kernel_mapping, dkm);
kono
parents:
diff changeset
664 }
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 /* Return the number of kernel decl name mappings. */
kono
parents:
diff changeset
667
kono
parents:
diff changeset
668 unsigned
kono
parents:
diff changeset
669 hsa_get_number_decl_kernel_mappings (void)
kono
parents:
diff changeset
670 {
kono
parents:
diff changeset
671 return vec_safe_length (hsa_decl_kernel_mapping);
kono
parents:
diff changeset
672 }
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 /* Return the decl in the Ith kernel decl name mapping. */
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 tree
kono
parents:
diff changeset
677 hsa_get_decl_kernel_mapping_decl (unsigned i)
kono
parents:
diff changeset
678 {
kono
parents:
diff changeset
679 return (*hsa_decl_kernel_mapping)[i].decl;
kono
parents:
diff changeset
680 }
kono
parents:
diff changeset
681
kono
parents:
diff changeset
682 /* Return the name in the Ith kernel decl name mapping. */
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 char *
kono
parents:
diff changeset
685 hsa_get_decl_kernel_mapping_name (unsigned i)
kono
parents:
diff changeset
686 {
kono
parents:
diff changeset
687 return (*hsa_decl_kernel_mapping)[i].name;
kono
parents:
diff changeset
688 }
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 /* Return maximum OMP size for kernel decl name mapping. */
kono
parents:
diff changeset
691
kono
parents:
diff changeset
692 unsigned
kono
parents:
diff changeset
693 hsa_get_decl_kernel_mapping_omp_size (unsigned i)
kono
parents:
diff changeset
694 {
kono
parents:
diff changeset
695 return (*hsa_decl_kernel_mapping)[i].omp_data_size;
kono
parents:
diff changeset
696 }
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 /* Return if the function is gridified kernel in decl name mapping. */
kono
parents:
diff changeset
699
kono
parents:
diff changeset
700 bool
kono
parents:
diff changeset
701 hsa_get_decl_kernel_mapping_gridified (unsigned i)
kono
parents:
diff changeset
702 {
kono
parents:
diff changeset
703 return (*hsa_decl_kernel_mapping)[i].gridified_kernel_p;
kono
parents:
diff changeset
704 }
kono
parents:
diff changeset
705
kono
parents:
diff changeset
706 /* Free the mapping between original decls and kernel names. */
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 void
kono
parents:
diff changeset
709 hsa_free_decl_kernel_mapping (void)
kono
parents:
diff changeset
710 {
kono
parents:
diff changeset
711 if (hsa_decl_kernel_mapping == NULL)
kono
parents:
diff changeset
712 return;
kono
parents:
diff changeset
713
kono
parents:
diff changeset
714 for (unsigned i = 0; i < hsa_decl_kernel_mapping->length (); ++i)
kono
parents:
diff changeset
715 free ((*hsa_decl_kernel_mapping)[i].name);
kono
parents:
diff changeset
716 ggc_free (hsa_decl_kernel_mapping);
kono
parents:
diff changeset
717 }
kono
parents:
diff changeset
718
kono
parents:
diff changeset
719 /* Add new kernel dependency. */
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 void
kono
parents:
diff changeset
722 hsa_add_kernel_dependency (tree caller, const char *called_function)
kono
parents:
diff changeset
723 {
kono
parents:
diff changeset
724 if (hsa_decl_kernel_dependencies == NULL)
kono
parents:
diff changeset
725 hsa_decl_kernel_dependencies = new hash_map<tree, vec<const char *> *> ();
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 vec <const char *> *s = NULL;
kono
parents:
diff changeset
728 vec <const char *> **slot = hsa_decl_kernel_dependencies->get (caller);
kono
parents:
diff changeset
729 if (slot == NULL)
kono
parents:
diff changeset
730 {
kono
parents:
diff changeset
731 s = new vec <const char *> ();
kono
parents:
diff changeset
732 hsa_decl_kernel_dependencies->put (caller, s);
kono
parents:
diff changeset
733 }
kono
parents:
diff changeset
734 else
kono
parents:
diff changeset
735 s = *slot;
kono
parents:
diff changeset
736
kono
parents:
diff changeset
737 s->safe_push (called_function);
kono
parents:
diff changeset
738 }
kono
parents:
diff changeset
739
kono
parents:
diff changeset
740 /* Expansion to HSA needs a few gc roots to hold types, constructors etc. In
kono
parents:
diff changeset
741 order to minimize the number of GTY roots, we'll root them all in the
kono
parents:
diff changeset
742 following array. The individual elements should only be accessed by the
kono
parents:
diff changeset
743 very simple getters (of a pointer-to-tree) below. */
kono
parents:
diff changeset
744
kono
parents:
diff changeset
745 static GTY(()) tree hsa_tree_gt_roots[3];
kono
parents:
diff changeset
746
kono
parents:
diff changeset
747 tree *
kono
parents:
diff changeset
748 hsa_get_ctor_statements (void)
kono
parents:
diff changeset
749 {
kono
parents:
diff changeset
750 return &hsa_tree_gt_roots[0];
kono
parents:
diff changeset
751 }
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 tree *
kono
parents:
diff changeset
754 hsa_get_dtor_statements (void)
kono
parents:
diff changeset
755 {
kono
parents:
diff changeset
756 return &hsa_tree_gt_roots[1];
kono
parents:
diff changeset
757 }
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 tree *
kono
parents:
diff changeset
760 hsa_get_kernel_dispatch_type (void)
kono
parents:
diff changeset
761 {
kono
parents:
diff changeset
762 return &hsa_tree_gt_roots[2];
kono
parents:
diff changeset
763 }
kono
parents:
diff changeset
764
kono
parents:
diff changeset
765 /* Modify the name P in-place so that it is a valid HSA identifier. */
kono
parents:
diff changeset
766
kono
parents:
diff changeset
767 void
kono
parents:
diff changeset
768 hsa_sanitize_name (char *p)
kono
parents:
diff changeset
769 {
kono
parents:
diff changeset
770 for (; *p; p++)
kono
parents:
diff changeset
771 if (*p == '.' || *p == '-')
kono
parents:
diff changeset
772 *p = '_';
kono
parents:
diff changeset
773 }
kono
parents:
diff changeset
774
kono
parents:
diff changeset
775 /* Clone the name P, set trailing ampersand and sanitize the name. */
kono
parents:
diff changeset
776
kono
parents:
diff changeset
777 char *
kono
parents:
diff changeset
778 hsa_brig_function_name (const char *p)
kono
parents:
diff changeset
779 {
kono
parents:
diff changeset
780 unsigned len = strlen (p);
kono
parents:
diff changeset
781 char *buf = XNEWVEC (char, len + 2);
kono
parents:
diff changeset
782
kono
parents:
diff changeset
783 buf[0] = '&';
kono
parents:
diff changeset
784 buf[len + 1] = '\0';
kono
parents:
diff changeset
785 memcpy (buf + 1, p, len);
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 hsa_sanitize_name (buf);
kono
parents:
diff changeset
788 return buf;
kono
parents:
diff changeset
789 }
kono
parents:
diff changeset
790
kono
parents:
diff changeset
791 /* Add a flatten attribute and disable vectorization for gpu implementation
kono
parents:
diff changeset
792 function decl GDECL. */
kono
parents:
diff changeset
793
kono
parents:
diff changeset
794 void hsa_summary_t::process_gpu_implementation_attributes (tree gdecl)
kono
parents:
diff changeset
795 {
kono
parents:
diff changeset
796 DECL_ATTRIBUTES (gdecl)
kono
parents:
diff changeset
797 = tree_cons (get_identifier ("flatten"), NULL_TREE,
kono
parents:
diff changeset
798 DECL_ATTRIBUTES (gdecl));
kono
parents:
diff changeset
799
kono
parents:
diff changeset
800 tree fn_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (gdecl);
kono
parents:
diff changeset
801 if (fn_opts == NULL_TREE)
kono
parents:
diff changeset
802 fn_opts = optimization_default_node;
kono
parents:
diff changeset
803 fn_opts = copy_node (fn_opts);
kono
parents:
diff changeset
804 TREE_OPTIMIZATION (fn_opts)->x_flag_tree_loop_vectorize = false;
kono
parents:
diff changeset
805 TREE_OPTIMIZATION (fn_opts)->x_flag_tree_slp_vectorize = false;
kono
parents:
diff changeset
806 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (gdecl) = fn_opts;
kono
parents:
diff changeset
807 }
kono
parents:
diff changeset
808
kono
parents:
diff changeset
809 void
kono
parents:
diff changeset
810 hsa_summary_t::link_functions (cgraph_node *gpu, cgraph_node *host,
kono
parents:
diff changeset
811 hsa_function_kind kind, bool gridified_kernel_p)
kono
parents:
diff changeset
812 {
kono
parents:
diff changeset
813 hsa_function_summary *gpu_summary = get (gpu);
kono
parents:
diff changeset
814 hsa_function_summary *host_summary = get (host);
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 gpu_summary->m_kind = kind;
kono
parents:
diff changeset
817 host_summary->m_kind = kind;
kono
parents:
diff changeset
818
kono
parents:
diff changeset
819 gpu_summary->m_gpu_implementation_p = true;
kono
parents:
diff changeset
820 host_summary->m_gpu_implementation_p = false;
kono
parents:
diff changeset
821
kono
parents:
diff changeset
822 gpu_summary->m_gridified_kernel_p = gridified_kernel_p;
kono
parents:
diff changeset
823 host_summary->m_gridified_kernel_p = gridified_kernel_p;
kono
parents:
diff changeset
824
kono
parents:
diff changeset
825 gpu_summary->m_bound_function = host;
kono
parents:
diff changeset
826 host_summary->m_bound_function = gpu;
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 process_gpu_implementation_attributes (gpu->decl);
kono
parents:
diff changeset
829
kono
parents:
diff changeset
830 /* Create reference between a kernel and a corresponding host implementation
kono
parents:
diff changeset
831 to quarantee LTO streaming to a same LTRANS. */
kono
parents:
diff changeset
832 if (kind == HSA_KERNEL)
kono
parents:
diff changeset
833 gpu->create_reference (host, IPA_REF_ADDR);
kono
parents:
diff changeset
834 }
kono
parents:
diff changeset
835
kono
parents:
diff changeset
836 /* Add a HOST function to HSA summaries. */
kono
parents:
diff changeset
837
kono
parents:
diff changeset
838 void
kono
parents:
diff changeset
839 hsa_register_kernel (cgraph_node *host)
kono
parents:
diff changeset
840 {
kono
parents:
diff changeset
841 if (hsa_summaries == NULL)
kono
parents:
diff changeset
842 hsa_summaries = new hsa_summary_t (symtab);
kono
parents:
diff changeset
843 hsa_function_summary *s = hsa_summaries->get (host);
kono
parents:
diff changeset
844 s->m_kind = HSA_KERNEL;
kono
parents:
diff changeset
845 }
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 /* Add a pair of functions to HSA summaries. GPU is an HSA implementation of
kono
parents:
diff changeset
848 a HOST function. */
kono
parents:
diff changeset
849
kono
parents:
diff changeset
850 void
kono
parents:
diff changeset
851 hsa_register_kernel (cgraph_node *gpu, cgraph_node *host)
kono
parents:
diff changeset
852 {
kono
parents:
diff changeset
853 if (hsa_summaries == NULL)
kono
parents:
diff changeset
854 hsa_summaries = new hsa_summary_t (symtab);
kono
parents:
diff changeset
855 hsa_summaries->link_functions (gpu, host, HSA_KERNEL, true);
kono
parents:
diff changeset
856 }
kono
parents:
diff changeset
857
kono
parents:
diff changeset
858 /* Return true if expansion of the current HSA function has already failed. */
kono
parents:
diff changeset
859
kono
parents:
diff changeset
860 bool
kono
parents:
diff changeset
861 hsa_seen_error (void)
kono
parents:
diff changeset
862 {
kono
parents:
diff changeset
863 return hsa_cfun->m_seen_error;
kono
parents:
diff changeset
864 }
kono
parents:
diff changeset
865
kono
parents:
diff changeset
866 /* Mark current HSA function as failed. */
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 void
kono
parents:
diff changeset
869 hsa_fail_cfun (void)
kono
parents:
diff changeset
870 {
kono
parents:
diff changeset
871 hsa_failed_functions->add (hsa_cfun->m_decl);
kono
parents:
diff changeset
872 hsa_cfun->m_seen_error = true;
kono
parents:
diff changeset
873 }
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 char *
kono
parents:
diff changeset
876 hsa_internal_fn::name ()
kono
parents:
diff changeset
877 {
kono
parents:
diff changeset
878 char *name = xstrdup (internal_fn_name (m_fn));
kono
parents:
diff changeset
879 for (char *ptr = name; *ptr; ptr++)
kono
parents:
diff changeset
880 *ptr = TOLOWER (*ptr);
kono
parents:
diff changeset
881
kono
parents:
diff changeset
882 const char *suffix = NULL;
kono
parents:
diff changeset
883 if (m_type_bit_size == 32)
kono
parents:
diff changeset
884 suffix = "f";
kono
parents:
diff changeset
885
kono
parents:
diff changeset
886 if (suffix)
kono
parents:
diff changeset
887 {
kono
parents:
diff changeset
888 char *name2 = concat (name, suffix, NULL);
kono
parents:
diff changeset
889 free (name);
kono
parents:
diff changeset
890 name = name2;
kono
parents:
diff changeset
891 }
kono
parents:
diff changeset
892
kono
parents:
diff changeset
893 hsa_sanitize_name (name);
kono
parents:
diff changeset
894 return name;
kono
parents:
diff changeset
895 }
kono
parents:
diff changeset
896
kono
parents:
diff changeset
897 unsigned
kono
parents:
diff changeset
898 hsa_internal_fn::get_arity ()
kono
parents:
diff changeset
899 {
kono
parents:
diff changeset
900 switch (m_fn)
kono
parents:
diff changeset
901 {
kono
parents:
diff changeset
902 case IFN_ACOS:
kono
parents:
diff changeset
903 case IFN_ASIN:
kono
parents:
diff changeset
904 case IFN_ATAN:
kono
parents:
diff changeset
905 case IFN_COS:
kono
parents:
diff changeset
906 case IFN_EXP:
kono
parents:
diff changeset
907 case IFN_EXP10:
kono
parents:
diff changeset
908 case IFN_EXP2:
kono
parents:
diff changeset
909 case IFN_EXPM1:
kono
parents:
diff changeset
910 case IFN_LOG:
kono
parents:
diff changeset
911 case IFN_LOG10:
kono
parents:
diff changeset
912 case IFN_LOG1P:
kono
parents:
diff changeset
913 case IFN_LOG2:
kono
parents:
diff changeset
914 case IFN_LOGB:
kono
parents:
diff changeset
915 case IFN_SIGNIFICAND:
kono
parents:
diff changeset
916 case IFN_SIN:
kono
parents:
diff changeset
917 case IFN_SQRT:
kono
parents:
diff changeset
918 case IFN_TAN:
kono
parents:
diff changeset
919 case IFN_CEIL:
kono
parents:
diff changeset
920 case IFN_FLOOR:
kono
parents:
diff changeset
921 case IFN_NEARBYINT:
kono
parents:
diff changeset
922 case IFN_RINT:
kono
parents:
diff changeset
923 case IFN_ROUND:
kono
parents:
diff changeset
924 case IFN_TRUNC:
kono
parents:
diff changeset
925 return 1;
kono
parents:
diff changeset
926 case IFN_ATAN2:
kono
parents:
diff changeset
927 case IFN_COPYSIGN:
kono
parents:
diff changeset
928 case IFN_FMOD:
kono
parents:
diff changeset
929 case IFN_POW:
kono
parents:
diff changeset
930 case IFN_REMAINDER:
kono
parents:
diff changeset
931 case IFN_SCALB:
kono
parents:
diff changeset
932 case IFN_LDEXP:
kono
parents:
diff changeset
933 return 2;
kono
parents:
diff changeset
934 case IFN_CLRSB:
kono
parents:
diff changeset
935 case IFN_CLZ:
kono
parents:
diff changeset
936 case IFN_CTZ:
kono
parents:
diff changeset
937 case IFN_FFS:
kono
parents:
diff changeset
938 case IFN_PARITY:
kono
parents:
diff changeset
939 case IFN_POPCOUNT:
kono
parents:
diff changeset
940 default:
kono
parents:
diff changeset
941 /* As we produce sorry message for unknown internal functions,
kono
parents:
diff changeset
942 reaching this label is definitely a bug. */
kono
parents:
diff changeset
943 gcc_unreachable ();
kono
parents:
diff changeset
944 }
kono
parents:
diff changeset
945 }
kono
parents:
diff changeset
946
kono
parents:
diff changeset
947 BrigType16_t
kono
parents:
diff changeset
948 hsa_internal_fn::get_argument_type (int n)
kono
parents:
diff changeset
949 {
kono
parents:
diff changeset
950 switch (m_fn)
kono
parents:
diff changeset
951 {
kono
parents:
diff changeset
952 case IFN_ACOS:
kono
parents:
diff changeset
953 case IFN_ASIN:
kono
parents:
diff changeset
954 case IFN_ATAN:
kono
parents:
diff changeset
955 case IFN_COS:
kono
parents:
diff changeset
956 case IFN_EXP:
kono
parents:
diff changeset
957 case IFN_EXP10:
kono
parents:
diff changeset
958 case IFN_EXP2:
kono
parents:
diff changeset
959 case IFN_EXPM1:
kono
parents:
diff changeset
960 case IFN_LOG:
kono
parents:
diff changeset
961 case IFN_LOG10:
kono
parents:
diff changeset
962 case IFN_LOG1P:
kono
parents:
diff changeset
963 case IFN_LOG2:
kono
parents:
diff changeset
964 case IFN_LOGB:
kono
parents:
diff changeset
965 case IFN_SIGNIFICAND:
kono
parents:
diff changeset
966 case IFN_SIN:
kono
parents:
diff changeset
967 case IFN_SQRT:
kono
parents:
diff changeset
968 case IFN_TAN:
kono
parents:
diff changeset
969 case IFN_CEIL:
kono
parents:
diff changeset
970 case IFN_FLOOR:
kono
parents:
diff changeset
971 case IFN_NEARBYINT:
kono
parents:
diff changeset
972 case IFN_RINT:
kono
parents:
diff changeset
973 case IFN_ROUND:
kono
parents:
diff changeset
974 case IFN_TRUNC:
kono
parents:
diff changeset
975 case IFN_ATAN2:
kono
parents:
diff changeset
976 case IFN_COPYSIGN:
kono
parents:
diff changeset
977 case IFN_FMOD:
kono
parents:
diff changeset
978 case IFN_POW:
kono
parents:
diff changeset
979 case IFN_REMAINDER:
kono
parents:
diff changeset
980 case IFN_SCALB:
kono
parents:
diff changeset
981 return hsa_float_for_bitsize (m_type_bit_size);
kono
parents:
diff changeset
982 case IFN_LDEXP:
kono
parents:
diff changeset
983 {
kono
parents:
diff changeset
984 if (n == -1 || n == 0)
kono
parents:
diff changeset
985 return hsa_float_for_bitsize (m_type_bit_size);
kono
parents:
diff changeset
986 else
kono
parents:
diff changeset
987 return BRIG_TYPE_S32;
kono
parents:
diff changeset
988 }
kono
parents:
diff changeset
989 default:
kono
parents:
diff changeset
990 /* As we produce sorry message for unknown internal functions,
kono
parents:
diff changeset
991 reaching this label is definitely a bug. */
kono
parents:
diff changeset
992 gcc_unreachable ();
kono
parents:
diff changeset
993 }
kono
parents:
diff changeset
994 }
kono
parents:
diff changeset
995
kono
parents:
diff changeset
996 #include "gt-hsa-common.h"