annotate gcc/hsa-common.h @ 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 /* HSAIL and BRIG related macros and definitions.
kono
parents:
diff changeset
2 Copyright (C) 2013-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 GNU General Public License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #ifndef HSA_H
kono
parents:
diff changeset
21 #define HSA_H
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #include "hsa-brig-format.h"
kono
parents:
diff changeset
24 #include "is-a.h"
kono
parents:
diff changeset
25 #include "predict.h"
kono
parents:
diff changeset
26 #include "tree.h"
kono
parents:
diff changeset
27 #include "vec.h"
kono
parents:
diff changeset
28 #include "hash-table.h"
kono
parents:
diff changeset
29 #include "basic-block.h"
kono
parents:
diff changeset
30 #include "bitmap.h"
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 /* Return true if the compiler should produce HSAIL. */
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 static inline bool
kono
parents:
diff changeset
36 hsa_gen_requested_p (void)
kono
parents:
diff changeset
37 {
kono
parents:
diff changeset
38 #ifndef ENABLE_HSA
kono
parents:
diff changeset
39 return false;
kono
parents:
diff changeset
40 #endif
kono
parents:
diff changeset
41 return !flag_disable_hsa;
kono
parents:
diff changeset
42 }
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* Standard warning message if we failed to generate HSAIL for a function. */
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 #define HSA_SORRY_MSG "could not emit HSAIL for the function"
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 class hsa_op_immed;
kono
parents:
diff changeset
49 class hsa_op_cst_list;
kono
parents:
diff changeset
50 class hsa_insn_basic;
kono
parents:
diff changeset
51 class hsa_op_address;
kono
parents:
diff changeset
52 class hsa_op_reg;
kono
parents:
diff changeset
53 class hsa_bb;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 /* Class representing an input argument, output argument (result) or a
kono
parents:
diff changeset
56 variable, that will eventually end up being a symbol directive. */
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 struct hsa_symbol
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 /* Constructor. */
kono
parents:
diff changeset
61 hsa_symbol (BrigType16_t type, BrigSegment8_t segment,
kono
parents:
diff changeset
62 BrigLinkage8_t linkage, bool global_scope_p = false,
kono
parents:
diff changeset
63 BrigAllocation allocation = BRIG_ALLOCATION_AUTOMATIC,
kono
parents:
diff changeset
64 BrigAlignment8_t align = BRIG_ALIGNMENT_8);
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 /* Return total size of the symbol. */
kono
parents:
diff changeset
67 unsigned HOST_WIDE_INT total_byte_size ();
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 /* Fill in those values into the symbol according to DECL, which are
kono
parents:
diff changeset
70 determined independently from whether it is parameter, result,
kono
parents:
diff changeset
71 or a variable, local or global. */
kono
parents:
diff changeset
72 void fillup_for_decl (tree decl);
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 /* Pointer to the original tree, which is PARM_DECL for input parameters and
kono
parents:
diff changeset
75 RESULT_DECL for the output parameters. Also can be CONST_DECL for Fortran
kono
parents:
diff changeset
76 constants which need to be put into readonly segment. */
kono
parents:
diff changeset
77 tree m_decl;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* Name of the symbol, that will be written into output and dumps. Can be
kono
parents:
diff changeset
80 NULL, see name_number below. */
kono
parents:
diff changeset
81 const char *m_name;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 /* If name is NULL, artificial name will be formed from the segment name and
kono
parents:
diff changeset
84 this number. */
kono
parents:
diff changeset
85 int m_name_number;
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 /* Once written, this is the offset of the associated symbol directive. Zero
kono
parents:
diff changeset
88 means the symbol has not been written yet. */
kono
parents:
diff changeset
89 unsigned m_directive_offset;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 /* HSA type of the parameter. */
kono
parents:
diff changeset
92 BrigType16_t m_type;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 /* The HSA segment this will eventually end up in. */
kono
parents:
diff changeset
95 BrigSegment8_t m_segment;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 /* The HSA kind of linkage. */
kono
parents:
diff changeset
98 BrigLinkage8_t m_linkage;
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 /* Array dimension, if non-zero. */
kono
parents:
diff changeset
101 unsigned HOST_WIDE_INT m_dim;
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 /* Constant value, used for string constants. */
kono
parents:
diff changeset
104 hsa_op_immed *m_cst_value;
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 /* Is in global scope. */
kono
parents:
diff changeset
107 bool m_global_scope_p;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 /* True if an error has been seen for the symbol. */
kono
parents:
diff changeset
110 bool m_seen_error;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 /* Symbol allocation. */
kono
parents:
diff changeset
113 BrigAllocation m_allocation;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 /* Flag used for global variables if a variable is already emitted or not. */
kono
parents:
diff changeset
116 bool m_emitted_to_brig;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 /* Alignment of the symbol. */
kono
parents:
diff changeset
119 BrigAlignment8_t m_align;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 private:
kono
parents:
diff changeset
122 /* Default constructor. */
kono
parents:
diff changeset
123 hsa_symbol ();
kono
parents:
diff changeset
124 };
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 /* Abstract class for HSA instruction operands. */
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 class hsa_op_base
kono
parents:
diff changeset
129 {
kono
parents:
diff changeset
130 public:
kono
parents:
diff changeset
131 /* Next operand scheduled to be written when writing BRIG operand
kono
parents:
diff changeset
132 section. */
kono
parents:
diff changeset
133 hsa_op_base *m_next;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 /* Offset to which the associated operand structure will be written. Zero if
kono
parents:
diff changeset
136 yet not scheduled for writing. */
kono
parents:
diff changeset
137 unsigned m_brig_op_offset;
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 /* The type of a particular operand. */
kono
parents:
diff changeset
140 BrigKind16_t m_kind;
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 protected:
kono
parents:
diff changeset
143 hsa_op_base (BrigKind16_t k);
kono
parents:
diff changeset
144 private:
kono
parents:
diff changeset
145 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
146 hsa_op_base () {}
kono
parents:
diff changeset
147 };
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 /* Common abstract ancestor for operands which have a type. */
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 class hsa_op_with_type : public hsa_op_base
kono
parents:
diff changeset
152 {
kono
parents:
diff changeset
153 public:
kono
parents:
diff changeset
154 /* The type. */
kono
parents:
diff changeset
155 BrigType16_t m_type;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 /* Convert an operand to a destination type DTYPE and attach insns
kono
parents:
diff changeset
158 to HBB if needed. */
kono
parents:
diff changeset
159 hsa_op_with_type *get_in_type (BrigType16_t dtype, hsa_bb *hbb);
kono
parents:
diff changeset
160 /* If this operand has integer type smaller than 32 bits, extend it to 32
kono
parents:
diff changeset
161 bits, adding instructions to HBB if needed. */
kono
parents:
diff changeset
162 hsa_op_with_type *extend_int_to_32bit (hsa_bb *hbb);
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 protected:
kono
parents:
diff changeset
165 hsa_op_with_type (BrigKind16_t k, BrigType16_t t);
kono
parents:
diff changeset
166 private:
kono
parents:
diff changeset
167 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
168 hsa_op_with_type () : hsa_op_base (BRIG_KIND_NONE) {}
kono
parents:
diff changeset
169 };
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 /* An immediate HSA operand. */
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 class hsa_op_immed : public hsa_op_with_type
kono
parents:
diff changeset
174 {
kono
parents:
diff changeset
175 public:
kono
parents:
diff changeset
176 hsa_op_immed (tree tree_val, bool min32int = true);
kono
parents:
diff changeset
177 hsa_op_immed (HOST_WIDE_INT int_value, BrigType16_t type);
kono
parents:
diff changeset
178 void *operator new (size_t);
kono
parents:
diff changeset
179 ~hsa_op_immed ();
kono
parents:
diff changeset
180 void set_type (BrigKind16_t t);
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 /* Function returns pointer to a buffer that contains binary representation
kono
parents:
diff changeset
183 of the immeadiate value. The buffer has length of BRIG_SIZE and
kono
parents:
diff changeset
184 a caller is responsible for deallocation of the buffer. */
kono
parents:
diff changeset
185 char *emit_to_buffer (unsigned *brig_size);
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 /* Value as represented by middle end. */
kono
parents:
diff changeset
188 tree m_tree_value;
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 /* Integer value representation. */
kono
parents:
diff changeset
191 HOST_WIDE_INT m_int_value;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 private:
kono
parents:
diff changeset
194 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
195 hsa_op_immed ();
kono
parents:
diff changeset
196 /* All objects are deallocated by destroying their pool, so make delete
kono
parents:
diff changeset
197 inaccessible too. */
kono
parents:
diff changeset
198 void operator delete (void *) {}
kono
parents:
diff changeset
199 };
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 /* Report whether or not P is a an immediate operand. */
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 template <>
kono
parents:
diff changeset
204 template <>
kono
parents:
diff changeset
205 inline bool
kono
parents:
diff changeset
206 is_a_helper <hsa_op_immed *>::test (hsa_op_base *p)
kono
parents:
diff changeset
207 {
kono
parents:
diff changeset
208 return p->m_kind == BRIG_KIND_OPERAND_CONSTANT_BYTES;
kono
parents:
diff changeset
209 }
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 /* Likewise, but for a more specified base. */
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 template <>
kono
parents:
diff changeset
214 template <>
kono
parents:
diff changeset
215 inline bool
kono
parents:
diff changeset
216 is_a_helper <hsa_op_immed *>::test (hsa_op_with_type *p)
kono
parents:
diff changeset
217 {
kono
parents:
diff changeset
218 return p->m_kind == BRIG_KIND_OPERAND_CONSTANT_BYTES;
kono
parents:
diff changeset
219 }
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 /* HSA register operand. */
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 class hsa_op_reg : public hsa_op_with_type
kono
parents:
diff changeset
225 {
kono
parents:
diff changeset
226 friend class hsa_insn_basic;
kono
parents:
diff changeset
227 friend class hsa_insn_phi;
kono
parents:
diff changeset
228 public:
kono
parents:
diff changeset
229 hsa_op_reg (BrigType16_t t);
kono
parents:
diff changeset
230 void *operator new (size_t);
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 /* Verify register operand. */
kono
parents:
diff changeset
233 void verify_ssa ();
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* If NON-NULL, gimple SSA that we come from. NULL if none. */
kono
parents:
diff changeset
236 tree m_gimple_ssa;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 /* Defining instruction while still in the SSA. */
kono
parents:
diff changeset
239 hsa_insn_basic *m_def_insn;
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 /* If the register allocator decides to spill the register, this is the
kono
parents:
diff changeset
242 appropriate spill symbol. */
kono
parents:
diff changeset
243 hsa_symbol *m_spill_sym;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 /* Number of this register structure in the order in which they were
kono
parents:
diff changeset
246 allocated. */
kono
parents:
diff changeset
247 int m_order;
kono
parents:
diff changeset
248 int m_lr_begin, m_lr_end;
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 /* Zero if the register is not yet allocated. After, allocation, this must
kono
parents:
diff changeset
251 be 'c', 's', 'd' or 'q'. */
kono
parents:
diff changeset
252 char m_reg_class;
kono
parents:
diff changeset
253 /* If allocated, the number of the HW register (within its HSA register
kono
parents:
diff changeset
254 class). */
kono
parents:
diff changeset
255 char m_hard_num;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 private:
kono
parents:
diff changeset
258 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
259 hsa_op_reg () : hsa_op_with_type (BRIG_KIND_NONE, BRIG_TYPE_NONE) {}
kono
parents:
diff changeset
260 /* All objects are deallocated by destroying their pool, so make delete
kono
parents:
diff changeset
261 inaccessible too. */
kono
parents:
diff changeset
262 void operator delete (void *) {}
kono
parents:
diff changeset
263 /* Set definition where the register is defined. */
kono
parents:
diff changeset
264 void set_definition (hsa_insn_basic *insn);
kono
parents:
diff changeset
265 /* Uses of the value while still in SSA. */
kono
parents:
diff changeset
266 auto_vec <hsa_insn_basic *> m_uses;
kono
parents:
diff changeset
267 };
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 /* Report whether or not P is a register operand. */
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 template <>
kono
parents:
diff changeset
272 template <>
kono
parents:
diff changeset
273 inline bool
kono
parents:
diff changeset
274 is_a_helper <hsa_op_reg *>::test (hsa_op_base *p)
kono
parents:
diff changeset
275 {
kono
parents:
diff changeset
276 return p->m_kind == BRIG_KIND_OPERAND_REGISTER;
kono
parents:
diff changeset
277 }
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 /* Report whether or not P is a register operand. */
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 template <>
kono
parents:
diff changeset
282 template <>
kono
parents:
diff changeset
283 inline bool
kono
parents:
diff changeset
284 is_a_helper <hsa_op_reg *>::test (hsa_op_with_type *p)
kono
parents:
diff changeset
285 {
kono
parents:
diff changeset
286 return p->m_kind == BRIG_KIND_OPERAND_REGISTER;
kono
parents:
diff changeset
287 }
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 /* An address HSA operand. */
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 class hsa_op_address : public hsa_op_base
kono
parents:
diff changeset
292 {
kono
parents:
diff changeset
293 public:
kono
parents:
diff changeset
294 /* set up a new address operand consisting of base symbol SYM, register R and
kono
parents:
diff changeset
295 immediate OFFSET. If the machine model is not large and offset is 64 bit,
kono
parents:
diff changeset
296 the upper, 32 bits have to be zero. */
kono
parents:
diff changeset
297 hsa_op_address (hsa_symbol *sym, hsa_op_reg *reg,
kono
parents:
diff changeset
298 HOST_WIDE_INT offset = 0);
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 void *operator new (size_t);
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 /* Set up a new address operand consisting of base symbol SYM and
kono
parents:
diff changeset
303 immediate OFFSET. If the machine model is not large and offset is 64 bit,
kono
parents:
diff changeset
304 the upper, 32 bits have to be zero. */
kono
parents:
diff changeset
305 hsa_op_address (hsa_symbol *sym, HOST_WIDE_INT offset = 0);
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 /* Set up a new address operand consisting of register R and
kono
parents:
diff changeset
308 immediate OFFSET. If the machine model is not large and offset is 64 bit,
kono
parents:
diff changeset
309 the upper, 32 bits have to be zero. */
kono
parents:
diff changeset
310 hsa_op_address (hsa_op_reg *reg, HOST_WIDE_INT offset = 0);
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 /* Symbol base of the address. Can be NULL if there is none. */
kono
parents:
diff changeset
313 hsa_symbol *m_symbol;
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 /* Register offset. Can be NULL if there is none. */
kono
parents:
diff changeset
316 hsa_op_reg *m_reg;
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 /* Immediate byte offset. */
kono
parents:
diff changeset
319 HOST_WIDE_INT m_imm_offset;
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 private:
kono
parents:
diff changeset
322 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
323 hsa_op_address () : hsa_op_base (BRIG_KIND_NONE) {}
kono
parents:
diff changeset
324 /* All objects are deallocated by destroying their pool, so make delete
kono
parents:
diff changeset
325 inaccessible too. */
kono
parents:
diff changeset
326 void operator delete (void *) {}
kono
parents:
diff changeset
327 };
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 /* Report whether or not P is an address operand. */
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 template <>
kono
parents:
diff changeset
332 template <>
kono
parents:
diff changeset
333 inline bool
kono
parents:
diff changeset
334 is_a_helper <hsa_op_address *>::test (hsa_op_base *p)
kono
parents:
diff changeset
335 {
kono
parents:
diff changeset
336 return p->m_kind == BRIG_KIND_OPERAND_ADDRESS;
kono
parents:
diff changeset
337 }
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 /* A reference to code HSA operand. It can be either reference
kono
parents:
diff changeset
340 to a start of a BB or a start of a function. */
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 class hsa_op_code_ref : public hsa_op_base
kono
parents:
diff changeset
343 {
kono
parents:
diff changeset
344 public:
kono
parents:
diff changeset
345 hsa_op_code_ref ();
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 /* Offset in the code section that this refers to. */
kono
parents:
diff changeset
348 unsigned m_directive_offset;
kono
parents:
diff changeset
349 };
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 /* Report whether or not P is a code reference operand. */
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 template <>
kono
parents:
diff changeset
354 template <>
kono
parents:
diff changeset
355 inline bool
kono
parents:
diff changeset
356 is_a_helper <hsa_op_code_ref *>::test (hsa_op_base *p)
kono
parents:
diff changeset
357 {
kono
parents:
diff changeset
358 return p->m_kind == BRIG_KIND_OPERAND_CODE_REF;
kono
parents:
diff changeset
359 }
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 /* Code list HSA operand. */
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 class hsa_op_code_list: public hsa_op_base
kono
parents:
diff changeset
364 {
kono
parents:
diff changeset
365 public:
kono
parents:
diff changeset
366 hsa_op_code_list (unsigned elements);
kono
parents:
diff changeset
367 void *operator new (size_t);
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 /* Offset to variable-sized array in hsa_data section, where
kono
parents:
diff changeset
370 are offsets to entries in the hsa_code section. */
kono
parents:
diff changeset
371 auto_vec<unsigned> m_offsets;
kono
parents:
diff changeset
372 private:
kono
parents:
diff changeset
373 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
374 hsa_op_code_list () : hsa_op_base (BRIG_KIND_NONE) {}
kono
parents:
diff changeset
375 /* All objects are deallocated by destroying their pool, so make delete
kono
parents:
diff changeset
376 inaccessible too. */
kono
parents:
diff changeset
377 void operator delete (void *) {}
kono
parents:
diff changeset
378 };
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 /* Report whether or not P is a code list operand. */
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 template <>
kono
parents:
diff changeset
383 template <>
kono
parents:
diff changeset
384 inline bool
kono
parents:
diff changeset
385 is_a_helper <hsa_op_code_list *>::test (hsa_op_base *p)
kono
parents:
diff changeset
386 {
kono
parents:
diff changeset
387 return p->m_kind == BRIG_KIND_OPERAND_CODE_LIST;
kono
parents:
diff changeset
388 }
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 /* Operand list HSA operand. */
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 class hsa_op_operand_list: public hsa_op_base
kono
parents:
diff changeset
393 {
kono
parents:
diff changeset
394 public:
kono
parents:
diff changeset
395 hsa_op_operand_list (unsigned elements);
kono
parents:
diff changeset
396 ~hsa_op_operand_list ();
kono
parents:
diff changeset
397 void *operator new (size_t);
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 /* Offset to variable-sized array in hsa_data section, where
kono
parents:
diff changeset
400 are offsets to entries in the hsa_code section. */
kono
parents:
diff changeset
401 auto_vec<unsigned> m_offsets;
kono
parents:
diff changeset
402 private:
kono
parents:
diff changeset
403 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
404 hsa_op_operand_list () : hsa_op_base (BRIG_KIND_NONE) {}
kono
parents:
diff changeset
405 /* All objects are deallocated by destroying their pool, so make delete
kono
parents:
diff changeset
406 inaccessible too. */
kono
parents:
diff changeset
407 void operator delete (void *) {}
kono
parents:
diff changeset
408 };
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 /* Report whether or not P is a code list operand. */
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 template <>
kono
parents:
diff changeset
413 template <>
kono
parents:
diff changeset
414 inline bool
kono
parents:
diff changeset
415 is_a_helper <hsa_op_operand_list *>::test (hsa_op_base *p)
kono
parents:
diff changeset
416 {
kono
parents:
diff changeset
417 return p->m_kind == BRIG_KIND_OPERAND_OPERAND_LIST;
kono
parents:
diff changeset
418 }
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 /* Opcodes of instructions that are not part of HSA but that we use to
kono
parents:
diff changeset
421 represent it nevertheless. */
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 #define HSA_OPCODE_PHI (-1)
kono
parents:
diff changeset
424 #define HSA_OPCODE_ARG_BLOCK (-2)
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 /* The number of operand pointers we can directly in an instruction. */
kono
parents:
diff changeset
427 #define HSA_BRIG_INT_STORAGE_OPERANDS 5
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 /* Class representing an HSA instruction. Unlike typical ancestors for
kono
parents:
diff changeset
430 specialized classes, this one is also directly used for all instructions
kono
parents:
diff changeset
431 that are then represented as BrigInstBasic. */
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 class hsa_insn_basic
kono
parents:
diff changeset
434 {
kono
parents:
diff changeset
435 public:
kono
parents:
diff changeset
436 hsa_insn_basic (unsigned nops, int opc);
kono
parents:
diff changeset
437 hsa_insn_basic (unsigned nops, int opc, BrigType16_t t,
kono
parents:
diff changeset
438 hsa_op_base *arg0 = NULL,
kono
parents:
diff changeset
439 hsa_op_base *arg1 = NULL,
kono
parents:
diff changeset
440 hsa_op_base *arg2 = NULL,
kono
parents:
diff changeset
441 hsa_op_base *arg3 = NULL);
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 void *operator new (size_t);
kono
parents:
diff changeset
444 void set_op (int index, hsa_op_base *op);
kono
parents:
diff changeset
445 hsa_op_base *get_op (int index);
kono
parents:
diff changeset
446 hsa_op_base **get_op_addr (int index);
kono
parents:
diff changeset
447 unsigned int operand_count ();
kono
parents:
diff changeset
448 void verify ();
kono
parents:
diff changeset
449 unsigned input_count ();
kono
parents:
diff changeset
450 unsigned num_used_ops ();
kono
parents:
diff changeset
451 void set_output_in_type (hsa_op_reg *dest, unsigned op_index, hsa_bb *hbb);
kono
parents:
diff changeset
452 bool op_output_p (unsigned opnum);
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 /* The previous and next instruction in the basic block. */
kono
parents:
diff changeset
455 hsa_insn_basic *m_prev, *m_next;
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 /* Basic block this instruction belongs to. */
kono
parents:
diff changeset
458 basic_block m_bb;
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 /* Operand code distinguishing different types of instructions. Eventually
kono
parents:
diff changeset
461 these should only be BRIG_INST_* values from the BrigOpcode16_t range but
kono
parents:
diff changeset
462 initially we use negative values for PHI nodes and such. */
kono
parents:
diff changeset
463 int m_opcode;
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 /* Linearized number assigned to the instruction by HSA RA. */
kono
parents:
diff changeset
466 int m_number;
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 /* Type of the destination of the operations. */
kono
parents:
diff changeset
469 BrigType16_t m_type;
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 /* BRIG offset of the instruction in code section. */
kono
parents:
diff changeset
472 unsigned int m_brig_offset;
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 private:
kono
parents:
diff changeset
475 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
476 hsa_insn_basic () {}
kono
parents:
diff changeset
477 /* All objects are deallocated by destroying their pool, so make delete
kono
parents:
diff changeset
478 inaccessible too. */
kono
parents:
diff changeset
479 void operator delete (void *) {}
kono
parents:
diff changeset
480 /* The individual operands. All instructions but PHI nodes have five or
kono
parents:
diff changeset
481 fewer instructions and so will fit the internal storage. */
kono
parents:
diff changeset
482 /* TODO: Vast majority of instructions have three or fewer operands, so we
kono
parents:
diff changeset
483 may actually try reducing it. */
kono
parents:
diff changeset
484 auto_vec<hsa_op_base *, HSA_BRIG_INT_STORAGE_OPERANDS> m_operands;
kono
parents:
diff changeset
485 };
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 /* Class representing a PHI node of the SSA form of HSA virtual
kono
parents:
diff changeset
488 registers. */
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 class hsa_insn_phi : public hsa_insn_basic
kono
parents:
diff changeset
491 {
kono
parents:
diff changeset
492 public:
kono
parents:
diff changeset
493 hsa_insn_phi (unsigned nops, hsa_op_reg *dst);
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 /* Destination. */
kono
parents:
diff changeset
496 hsa_op_reg *m_dest;
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 private:
kono
parents:
diff changeset
499 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
500 hsa_insn_phi () : hsa_insn_basic (1, HSA_OPCODE_PHI) {}
kono
parents:
diff changeset
501 };
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 /* Report whether or not P is a PHI node. */
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 template <>
kono
parents:
diff changeset
506 template <>
kono
parents:
diff changeset
507 inline bool
kono
parents:
diff changeset
508 is_a_helper <hsa_insn_phi *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
509 {
kono
parents:
diff changeset
510 return p->m_opcode == HSA_OPCODE_PHI;
kono
parents:
diff changeset
511 }
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 /* HSA instruction for */
kono
parents:
diff changeset
514 class hsa_insn_br : public hsa_insn_basic
kono
parents:
diff changeset
515 {
kono
parents:
diff changeset
516 public:
kono
parents:
diff changeset
517 hsa_insn_br (unsigned nops, int opc, BrigType16_t t, BrigWidth8_t width,
kono
parents:
diff changeset
518 hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
kono
parents:
diff changeset
519 hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 /* Number of work-items affected in the same way by the instruction. */
kono
parents:
diff changeset
522 BrigWidth8_t m_width;
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 private:
kono
parents:
diff changeset
525 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
526 hsa_insn_br () : hsa_insn_basic (0, BRIG_OPCODE_BR) {}
kono
parents:
diff changeset
527 };
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 /* Return true if P is a branching/synchronization instruction. */
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 template <>
kono
parents:
diff changeset
532 template <>
kono
parents:
diff changeset
533 inline bool
kono
parents:
diff changeset
534 is_a_helper <hsa_insn_br *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
535 {
kono
parents:
diff changeset
536 return p->m_opcode == BRIG_OPCODE_BARRIER
kono
parents:
diff changeset
537 || p->m_opcode == BRIG_OPCODE_BR;
kono
parents:
diff changeset
538 }
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 /* HSA instruction for conditional branches. Structurally the same as
kono
parents:
diff changeset
541 hsa_insn_br but we represent it specially because of inherent control
kono
parents:
diff changeset
542 flow it represents. */
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 class hsa_insn_cbr : public hsa_insn_br
kono
parents:
diff changeset
545 {
kono
parents:
diff changeset
546 public:
kono
parents:
diff changeset
547 hsa_insn_cbr (hsa_op_reg *ctrl);
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 private:
kono
parents:
diff changeset
550 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
551 hsa_insn_cbr () : hsa_insn_br (0, BRIG_OPCODE_CBR, BRIG_TYPE_B1,
kono
parents:
diff changeset
552 BRIG_WIDTH_1) {}
kono
parents:
diff changeset
553 };
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 /* Report whether P is a contitional branching instruction. */
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 template <>
kono
parents:
diff changeset
558 template <>
kono
parents:
diff changeset
559 inline bool
kono
parents:
diff changeset
560 is_a_helper <hsa_insn_cbr *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
561 {
kono
parents:
diff changeset
562 return p->m_opcode == BRIG_OPCODE_CBR;
kono
parents:
diff changeset
563 }
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 /* HSA instruction for switch branches. */
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 class hsa_insn_sbr : public hsa_insn_basic
kono
parents:
diff changeset
568 {
kono
parents:
diff changeset
569 public:
kono
parents:
diff changeset
570 hsa_insn_sbr (hsa_op_reg *index, unsigned jump_count);
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 /* Default destructor. */
kono
parents:
diff changeset
573 ~hsa_insn_sbr ();
kono
parents:
diff changeset
574
kono
parents:
diff changeset
575 void replace_all_labels (basic_block old_bb, basic_block new_bb);
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 /* Width as described in HSA documentation. */
kono
parents:
diff changeset
578 BrigWidth8_t m_width;
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 /* Jump table. */
kono
parents:
diff changeset
581 vec <basic_block> m_jump_table;
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 /* Code list for label references. */
kono
parents:
diff changeset
584 hsa_op_code_list *m_label_code_list;
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 private:
kono
parents:
diff changeset
587 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
588 hsa_insn_sbr () : hsa_insn_basic (1, BRIG_OPCODE_SBR) {}
kono
parents:
diff changeset
589 };
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 /* Report whether P is a switch branching instruction. */
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 template <>
kono
parents:
diff changeset
594 template <>
kono
parents:
diff changeset
595 inline bool
kono
parents:
diff changeset
596 is_a_helper <hsa_insn_sbr *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
597 {
kono
parents:
diff changeset
598 return p->m_opcode == BRIG_OPCODE_SBR;
kono
parents:
diff changeset
599 }
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 /* HSA instruction for comparisons. */
kono
parents:
diff changeset
602
kono
parents:
diff changeset
603 class hsa_insn_cmp : public hsa_insn_basic
kono
parents:
diff changeset
604 {
kono
parents:
diff changeset
605 public:
kono
parents:
diff changeset
606 hsa_insn_cmp (BrigCompareOperation8_t cmp, BrigType16_t t,
kono
parents:
diff changeset
607 hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
kono
parents:
diff changeset
608 hsa_op_base *arg2 = NULL);
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 /* Source type should be derived from operand types. */
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 /* The comparison operation. */
kono
parents:
diff changeset
613 BrigCompareOperation8_t m_compare;
kono
parents:
diff changeset
614
kono
parents:
diff changeset
615 /* TODO: Modifiers and packing control are missing but so are everywhere
kono
parents:
diff changeset
616 else. */
kono
parents:
diff changeset
617 private:
kono
parents:
diff changeset
618 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
619 hsa_insn_cmp () : hsa_insn_basic (1, BRIG_OPCODE_CMP) {}
kono
parents:
diff changeset
620 };
kono
parents:
diff changeset
621
kono
parents:
diff changeset
622 /* Report whether or not P is a comparison instruction. */
kono
parents:
diff changeset
623
kono
parents:
diff changeset
624 template <>
kono
parents:
diff changeset
625 template <>
kono
parents:
diff changeset
626 inline bool
kono
parents:
diff changeset
627 is_a_helper <hsa_insn_cmp *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
628 {
kono
parents:
diff changeset
629 return p->m_opcode == BRIG_OPCODE_CMP;
kono
parents:
diff changeset
630 }
kono
parents:
diff changeset
631
kono
parents:
diff changeset
632 /* HSA instruction for memory operations. */
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 class hsa_insn_mem : public hsa_insn_basic
kono
parents:
diff changeset
635 {
kono
parents:
diff changeset
636 public:
kono
parents:
diff changeset
637 hsa_insn_mem (int opc, BrigType16_t t, hsa_op_base *arg0, hsa_op_base *arg1);
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 /* Set alignment to VALUE. */
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 void set_align (BrigAlignment8_t value);
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 /* The segment is of the memory access is either the segment of the symbol in
kono
parents:
diff changeset
644 the address operand or flat address is there is no symbol there. */
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 /* Required alignment of the memory operation. */
kono
parents:
diff changeset
647 BrigAlignment8_t m_align;
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 /* HSA equiv class, basically an alias set number. */
kono
parents:
diff changeset
650 uint8_t m_equiv_class;
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 /* TODO: Add width modifier, perhaps also other things. */
kono
parents:
diff changeset
653 protected:
kono
parents:
diff changeset
654 hsa_insn_mem (unsigned nops, int opc, BrigType16_t t,
kono
parents:
diff changeset
655 hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
kono
parents:
diff changeset
656 hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
kono
parents:
diff changeset
657
kono
parents:
diff changeset
658 private:
kono
parents:
diff changeset
659 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
660 hsa_insn_mem () : hsa_insn_basic (1, BRIG_OPCODE_LD) {}
kono
parents:
diff changeset
661 };
kono
parents:
diff changeset
662
kono
parents:
diff changeset
663 /* Report whether or not P is a memory instruction. */
kono
parents:
diff changeset
664
kono
parents:
diff changeset
665 template <>
kono
parents:
diff changeset
666 template <>
kono
parents:
diff changeset
667 inline bool
kono
parents:
diff changeset
668 is_a_helper <hsa_insn_mem *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
669 {
kono
parents:
diff changeset
670 return (p->m_opcode == BRIG_OPCODE_LD
kono
parents:
diff changeset
671 || p->m_opcode == BRIG_OPCODE_ST);
kono
parents:
diff changeset
672 }
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 /* HSA instruction for atomic operations. */
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 class hsa_insn_atomic : public hsa_insn_mem
kono
parents:
diff changeset
677 {
kono
parents:
diff changeset
678 public:
kono
parents:
diff changeset
679 hsa_insn_atomic (int nops, int opc, enum BrigAtomicOperation aop,
kono
parents:
diff changeset
680 BrigType16_t t, BrigMemoryOrder memorder,
kono
parents:
diff changeset
681 hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
kono
parents:
diff changeset
682 hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 /* The operation itself. */
kono
parents:
diff changeset
685 enum BrigAtomicOperation m_atomicop;
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 /* Things like acquire/release/aligned. */
kono
parents:
diff changeset
688 enum BrigMemoryOrder m_memoryorder;
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 /* Scope of the atomic operation. */
kono
parents:
diff changeset
691 enum BrigMemoryScope m_memoryscope;
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 private:
kono
parents:
diff changeset
694 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
695 hsa_insn_atomic () : hsa_insn_mem (1, BRIG_KIND_NONE, BRIG_TYPE_NONE) {}
kono
parents:
diff changeset
696 };
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 /* Report whether or not P is an atomic instruction. */
kono
parents:
diff changeset
699
kono
parents:
diff changeset
700 template <>
kono
parents:
diff changeset
701 template <>
kono
parents:
diff changeset
702 inline bool
kono
parents:
diff changeset
703 is_a_helper <hsa_insn_atomic *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
704 {
kono
parents:
diff changeset
705 return (p->m_opcode == BRIG_OPCODE_ATOMIC
kono
parents:
diff changeset
706 || p->m_opcode == BRIG_OPCODE_ATOMICNORET);
kono
parents:
diff changeset
707 }
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 /* HSA instruction for signal operations. */
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 class hsa_insn_signal : public hsa_insn_basic
kono
parents:
diff changeset
712 {
kono
parents:
diff changeset
713 public:
kono
parents:
diff changeset
714 hsa_insn_signal (int nops, int opc, enum BrigAtomicOperation sop,
kono
parents:
diff changeset
715 BrigType16_t t, BrigMemoryOrder memorder,
kono
parents:
diff changeset
716 hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
kono
parents:
diff changeset
717 hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
kono
parents:
diff changeset
718
kono
parents:
diff changeset
719 /* Things like acquire/release/aligned. */
kono
parents:
diff changeset
720 enum BrigMemoryOrder m_memory_order;
kono
parents:
diff changeset
721
kono
parents:
diff changeset
722 /* The operation itself. */
kono
parents:
diff changeset
723 enum BrigAtomicOperation m_signalop;
kono
parents:
diff changeset
724 };
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 /* Report whether or not P is a signal instruction. */
kono
parents:
diff changeset
727
kono
parents:
diff changeset
728 template <>
kono
parents:
diff changeset
729 template <>
kono
parents:
diff changeset
730 inline bool
kono
parents:
diff changeset
731 is_a_helper <hsa_insn_signal *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
732 {
kono
parents:
diff changeset
733 return (p->m_opcode == BRIG_OPCODE_SIGNAL
kono
parents:
diff changeset
734 || p->m_opcode == BRIG_OPCODE_SIGNALNORET);
kono
parents:
diff changeset
735 }
kono
parents:
diff changeset
736
kono
parents:
diff changeset
737 /* HSA instruction to convert between flat addressing and segments. */
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 class hsa_insn_seg : public hsa_insn_basic
kono
parents:
diff changeset
740 {
kono
parents:
diff changeset
741 public:
kono
parents:
diff changeset
742 hsa_insn_seg (int opc, BrigType16_t destt, BrigType16_t srct,
kono
parents:
diff changeset
743 BrigSegment8_t seg, hsa_op_base *arg0, hsa_op_base *arg1);
kono
parents:
diff changeset
744
kono
parents:
diff changeset
745 /* Source type. Depends on the source addressing/segment. */
kono
parents:
diff changeset
746 BrigType16_t m_src_type;
kono
parents:
diff changeset
747 /* The segment we are converting from or to. */
kono
parents:
diff changeset
748 BrigSegment8_t m_segment;
kono
parents:
diff changeset
749 private:
kono
parents:
diff changeset
750 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
751 hsa_insn_seg () : hsa_insn_basic (1, BRIG_OPCODE_STOF) {}
kono
parents:
diff changeset
752 };
kono
parents:
diff changeset
753
kono
parents:
diff changeset
754 /* Report whether or not P is a segment conversion instruction. */
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 template <>
kono
parents:
diff changeset
757 template <>
kono
parents:
diff changeset
758 inline bool
kono
parents:
diff changeset
759 is_a_helper <hsa_insn_seg *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
760 {
kono
parents:
diff changeset
761 return (p->m_opcode == BRIG_OPCODE_STOF
kono
parents:
diff changeset
762 || p->m_opcode == BRIG_OPCODE_FTOS);
kono
parents:
diff changeset
763 }
kono
parents:
diff changeset
764
kono
parents:
diff changeset
765 /* Class for internal functions for purpose of HSA emission. */
kono
parents:
diff changeset
766
kono
parents:
diff changeset
767 class hsa_internal_fn
kono
parents:
diff changeset
768 {
kono
parents:
diff changeset
769 public:
kono
parents:
diff changeset
770 hsa_internal_fn (enum internal_fn fn, unsigned type_bit_size):
kono
parents:
diff changeset
771 m_fn (fn), m_type_bit_size (type_bit_size), m_offset (0) {}
kono
parents:
diff changeset
772
kono
parents:
diff changeset
773 hsa_internal_fn (const hsa_internal_fn *f):
kono
parents:
diff changeset
774 m_fn (f->m_fn), m_type_bit_size (f->m_type_bit_size),
kono
parents:
diff changeset
775 m_offset (f->m_offset) {}
kono
parents:
diff changeset
776
kono
parents:
diff changeset
777 /* Return arity of the internal function. */
kono
parents:
diff changeset
778 unsigned get_arity ();
kono
parents:
diff changeset
779
kono
parents:
diff changeset
780 /* Return BRIG type of N-th argument, if -1 is passed, return value type
kono
parents:
diff changeset
781 is received. */
kono
parents:
diff changeset
782 BrigType16_t get_argument_type (int n);
kono
parents:
diff changeset
783
kono
parents:
diff changeset
784 /* Return function name. The memory must be released by a caller. */
kono
parents:
diff changeset
785 char *name ();
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 /* Internal function. */
kono
parents:
diff changeset
788 enum internal_fn m_fn;
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 /* Bit width of return type. */
kono
parents:
diff changeset
791 unsigned m_type_bit_size;
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 /* BRIG offset of declaration of the function. */
kono
parents:
diff changeset
794 BrigCodeOffset32_t m_offset;
kono
parents:
diff changeset
795 };
kono
parents:
diff changeset
796
kono
parents:
diff changeset
797 /* HSA instruction for function call. */
kono
parents:
diff changeset
798
kono
parents:
diff changeset
799 class hsa_insn_call : public hsa_insn_basic
kono
parents:
diff changeset
800 {
kono
parents:
diff changeset
801 public:
kono
parents:
diff changeset
802 hsa_insn_call (tree callee);
kono
parents:
diff changeset
803 hsa_insn_call (hsa_internal_fn *fn);
kono
parents:
diff changeset
804
kono
parents:
diff changeset
805 /* Default destructor. */
kono
parents:
diff changeset
806 ~hsa_insn_call ();
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 /* Called function. */
kono
parents:
diff changeset
809 tree m_called_function;
kono
parents:
diff changeset
810
kono
parents:
diff changeset
811 /* Called internal function. */
kono
parents:
diff changeset
812 hsa_internal_fn *m_called_internal_fn;
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814 /* Input formal arguments. */
kono
parents:
diff changeset
815 auto_vec <hsa_symbol *> m_input_args;
kono
parents:
diff changeset
816
kono
parents:
diff changeset
817 /* Input arguments store instructions. */
kono
parents:
diff changeset
818 auto_vec <hsa_insn_mem *> m_input_arg_insns;
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 /* Output argument, can be NULL for void functions. */
kono
parents:
diff changeset
821 hsa_symbol *m_output_arg;
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 /* Called function code reference. */
kono
parents:
diff changeset
824 hsa_op_code_ref m_func;
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 /* Code list for arguments of the function. */
kono
parents:
diff changeset
827 hsa_op_code_list *m_args_code_list;
kono
parents:
diff changeset
828
kono
parents:
diff changeset
829 /* Code list for result of the function. */
kono
parents:
diff changeset
830 hsa_op_code_list *m_result_code_list;
kono
parents:
diff changeset
831 private:
kono
parents:
diff changeset
832 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
833 hsa_insn_call () : hsa_insn_basic (0, BRIG_OPCODE_CALL) {}
kono
parents:
diff changeset
834 };
kono
parents:
diff changeset
835
kono
parents:
diff changeset
836 /* Report whether or not P is a call instruction. */
kono
parents:
diff changeset
837
kono
parents:
diff changeset
838 template <>
kono
parents:
diff changeset
839 template <>
kono
parents:
diff changeset
840 inline bool
kono
parents:
diff changeset
841 is_a_helper <hsa_insn_call *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
842 {
kono
parents:
diff changeset
843 return (p->m_opcode == BRIG_OPCODE_CALL);
kono
parents:
diff changeset
844 }
kono
parents:
diff changeset
845
kono
parents:
diff changeset
846 /* HSA call instruction block encapsulates definition of arguments,
kono
parents:
diff changeset
847 result type, corresponding loads and a possible store.
kono
parents:
diff changeset
848 Moreover, it contains a single call instruction.
kono
parents:
diff changeset
849 Emission of the instruction will produce multiple
kono
parents:
diff changeset
850 HSAIL instructions. */
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 class hsa_insn_arg_block : public hsa_insn_basic
kono
parents:
diff changeset
853 {
kono
parents:
diff changeset
854 public:
kono
parents:
diff changeset
855 hsa_insn_arg_block (BrigKind brig_kind, hsa_insn_call * call);
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 /* Kind of argument block. */
kono
parents:
diff changeset
858 BrigKind m_kind;
kono
parents:
diff changeset
859
kono
parents:
diff changeset
860 /* Call instruction. */
kono
parents:
diff changeset
861 hsa_insn_call *m_call_insn;
kono
parents:
diff changeset
862 };
kono
parents:
diff changeset
863
kono
parents:
diff changeset
864 /* Report whether or not P is a call block instruction. */
kono
parents:
diff changeset
865
kono
parents:
diff changeset
866 template <>
kono
parents:
diff changeset
867 template <>
kono
parents:
diff changeset
868 inline bool
kono
parents:
diff changeset
869 is_a_helper <hsa_insn_arg_block *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
870 {
kono
parents:
diff changeset
871 return (p->m_opcode == HSA_OPCODE_ARG_BLOCK);
kono
parents:
diff changeset
872 }
kono
parents:
diff changeset
873
kono
parents:
diff changeset
874 /* HSA comment instruction. */
kono
parents:
diff changeset
875
kono
parents:
diff changeset
876 class hsa_insn_comment: public hsa_insn_basic
kono
parents:
diff changeset
877 {
kono
parents:
diff changeset
878 public:
kono
parents:
diff changeset
879 /* Constructor of class representing the comment in HSAIL. */
kono
parents:
diff changeset
880 hsa_insn_comment (const char *s);
kono
parents:
diff changeset
881
kono
parents:
diff changeset
882 /* Default destructor. */
kono
parents:
diff changeset
883 ~hsa_insn_comment ();
kono
parents:
diff changeset
884
kono
parents:
diff changeset
885 char *m_comment;
kono
parents:
diff changeset
886 };
kono
parents:
diff changeset
887
kono
parents:
diff changeset
888 /* Report whether or not P is a call block instruction. */
kono
parents:
diff changeset
889
kono
parents:
diff changeset
890 template <>
kono
parents:
diff changeset
891 template <>
kono
parents:
diff changeset
892 inline bool
kono
parents:
diff changeset
893 is_a_helper <hsa_insn_comment *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
894 {
kono
parents:
diff changeset
895 return (p->m_opcode == BRIG_KIND_DIRECTIVE_COMMENT);
kono
parents:
diff changeset
896 }
kono
parents:
diff changeset
897
kono
parents:
diff changeset
898 /* HSA queue instruction. */
kono
parents:
diff changeset
899
kono
parents:
diff changeset
900 class hsa_insn_queue: public hsa_insn_basic
kono
parents:
diff changeset
901 {
kono
parents:
diff changeset
902 public:
kono
parents:
diff changeset
903 hsa_insn_queue (int nops, int opcode, BrigSegment segment,
kono
parents:
diff changeset
904 BrigMemoryOrder memory_order,
kono
parents:
diff changeset
905 hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
kono
parents:
diff changeset
906 hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
kono
parents:
diff changeset
907
kono
parents:
diff changeset
908 /* Destructor. */
kono
parents:
diff changeset
909 ~hsa_insn_queue ();
kono
parents:
diff changeset
910
kono
parents:
diff changeset
911 /* Segment used to refer to the queue. Must be global or flat. */
kono
parents:
diff changeset
912 BrigSegment m_segment;
kono
parents:
diff changeset
913 /* Memory order used to specify synchronization. */
kono
parents:
diff changeset
914 BrigMemoryOrder m_memory_order;
kono
parents:
diff changeset
915 };
kono
parents:
diff changeset
916
kono
parents:
diff changeset
917 /* Report whether or not P is a queue instruction. */
kono
parents:
diff changeset
918
kono
parents:
diff changeset
919 template <>
kono
parents:
diff changeset
920 template <>
kono
parents:
diff changeset
921 inline bool
kono
parents:
diff changeset
922 is_a_helper <hsa_insn_queue *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
923 {
kono
parents:
diff changeset
924 return (p->m_opcode == BRIG_OPCODE_ADDQUEUEWRITEINDEX
kono
parents:
diff changeset
925 || p->m_opcode == BRIG_OPCODE_CASQUEUEWRITEINDEX
kono
parents:
diff changeset
926 || p->m_opcode == BRIG_OPCODE_LDQUEUEREADINDEX
kono
parents:
diff changeset
927 || p->m_opcode == BRIG_OPCODE_LDQUEUEWRITEINDEX
kono
parents:
diff changeset
928 || p->m_opcode == BRIG_OPCODE_STQUEUEREADINDEX
kono
parents:
diff changeset
929 || p->m_opcode == BRIG_OPCODE_STQUEUEWRITEINDEX);
kono
parents:
diff changeset
930 }
kono
parents:
diff changeset
931
kono
parents:
diff changeset
932 /* HSA source type instruction. */
kono
parents:
diff changeset
933
kono
parents:
diff changeset
934 class hsa_insn_srctype: public hsa_insn_basic
kono
parents:
diff changeset
935 {
kono
parents:
diff changeset
936 public:
kono
parents:
diff changeset
937 hsa_insn_srctype (int nops, BrigOpcode opcode, BrigType16_t destt,
kono
parents:
diff changeset
938 BrigType16_t srct, hsa_op_base *arg0, hsa_op_base *arg1,
kono
parents:
diff changeset
939 hsa_op_base *arg2);
kono
parents:
diff changeset
940
kono
parents:
diff changeset
941 /* Source type. */
kono
parents:
diff changeset
942 BrigType16_t m_source_type;
kono
parents:
diff changeset
943
kono
parents:
diff changeset
944 /* Destructor. */
kono
parents:
diff changeset
945 ~hsa_insn_srctype ();
kono
parents:
diff changeset
946 };
kono
parents:
diff changeset
947
kono
parents:
diff changeset
948 /* Report whether or not P is a source type instruction. */
kono
parents:
diff changeset
949
kono
parents:
diff changeset
950 template <>
kono
parents:
diff changeset
951 template <>
kono
parents:
diff changeset
952 inline bool
kono
parents:
diff changeset
953 is_a_helper <hsa_insn_srctype *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
954 {
kono
parents:
diff changeset
955 return (p->m_opcode == BRIG_OPCODE_POPCOUNT
kono
parents:
diff changeset
956 || p->m_opcode == BRIG_OPCODE_FIRSTBIT
kono
parents:
diff changeset
957 || p->m_opcode == BRIG_OPCODE_LASTBIT);
kono
parents:
diff changeset
958 }
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 /* HSA packed instruction. */
kono
parents:
diff changeset
961
kono
parents:
diff changeset
962 class hsa_insn_packed : public hsa_insn_srctype
kono
parents:
diff changeset
963 {
kono
parents:
diff changeset
964 public:
kono
parents:
diff changeset
965 hsa_insn_packed (int nops, BrigOpcode opcode, BrigType16_t destt,
kono
parents:
diff changeset
966 BrigType16_t srct, hsa_op_base *arg0, hsa_op_base *arg1,
kono
parents:
diff changeset
967 hsa_op_base *arg2);
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 /* Operand list for an operand of the instruction. */
kono
parents:
diff changeset
970 hsa_op_operand_list *m_operand_list;
kono
parents:
diff changeset
971
kono
parents:
diff changeset
972 /* Destructor. */
kono
parents:
diff changeset
973 ~hsa_insn_packed ();
kono
parents:
diff changeset
974 };
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 /* Report whether or not P is a combine instruction. */
kono
parents:
diff changeset
977
kono
parents:
diff changeset
978 template <>
kono
parents:
diff changeset
979 template <>
kono
parents:
diff changeset
980 inline bool
kono
parents:
diff changeset
981 is_a_helper <hsa_insn_packed *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
982 {
kono
parents:
diff changeset
983 return (p->m_opcode == BRIG_OPCODE_COMBINE
kono
parents:
diff changeset
984 || p->m_opcode == BRIG_OPCODE_EXPAND);
kono
parents:
diff changeset
985 }
kono
parents:
diff changeset
986
kono
parents:
diff changeset
987 /* HSA convert instruction. */
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 class hsa_insn_cvt: public hsa_insn_basic
kono
parents:
diff changeset
990 {
kono
parents:
diff changeset
991 public:
kono
parents:
diff changeset
992 hsa_insn_cvt (hsa_op_with_type *dest, hsa_op_with_type *src);
kono
parents:
diff changeset
993 };
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 /* Report whether or not P is a convert instruction. */
kono
parents:
diff changeset
996
kono
parents:
diff changeset
997 template <>
kono
parents:
diff changeset
998 template <>
kono
parents:
diff changeset
999 inline bool
kono
parents:
diff changeset
1000 is_a_helper <hsa_insn_cvt *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
1001 {
kono
parents:
diff changeset
1002 return (p->m_opcode == BRIG_OPCODE_CVT);
kono
parents:
diff changeset
1003 }
kono
parents:
diff changeset
1004
kono
parents:
diff changeset
1005 /* HSA alloca instruction. */
kono
parents:
diff changeset
1006
kono
parents:
diff changeset
1007 class hsa_insn_alloca: public hsa_insn_basic
kono
parents:
diff changeset
1008 {
kono
parents:
diff changeset
1009 public:
kono
parents:
diff changeset
1010 hsa_insn_alloca (hsa_op_with_type *dest, hsa_op_with_type *size,
kono
parents:
diff changeset
1011 unsigned alignment = 0);
kono
parents:
diff changeset
1012
kono
parents:
diff changeset
1013 /* Required alignment of the allocation. */
kono
parents:
diff changeset
1014 BrigAlignment8_t m_align;
kono
parents:
diff changeset
1015 };
kono
parents:
diff changeset
1016
kono
parents:
diff changeset
1017 /* Report whether or not P is an alloca instruction. */
kono
parents:
diff changeset
1018
kono
parents:
diff changeset
1019 template <>
kono
parents:
diff changeset
1020 template <>
kono
parents:
diff changeset
1021 inline bool
kono
parents:
diff changeset
1022 is_a_helper <hsa_insn_alloca *>::test (hsa_insn_basic *p)
kono
parents:
diff changeset
1023 {
kono
parents:
diff changeset
1024 return (p->m_opcode == BRIG_OPCODE_ALLOCA);
kono
parents:
diff changeset
1025 }
kono
parents:
diff changeset
1026
kono
parents:
diff changeset
1027 /* Basic block of HSA instructions. */
kono
parents:
diff changeset
1028
kono
parents:
diff changeset
1029 class hsa_bb
kono
parents:
diff changeset
1030 {
kono
parents:
diff changeset
1031 public:
kono
parents:
diff changeset
1032 hsa_bb (basic_block cfg_bb);
kono
parents:
diff changeset
1033 hsa_bb (basic_block cfg_bb, int idx);
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 /* Append an instruction INSN into the basic block. */
kono
parents:
diff changeset
1036 void append_insn (hsa_insn_basic *insn);
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 /* Add a PHI instruction. */
kono
parents:
diff changeset
1039 void append_phi (hsa_insn_phi *phi);
kono
parents:
diff changeset
1040
kono
parents:
diff changeset
1041 /* The real CFG BB that this HBB belongs to. */
kono
parents:
diff changeset
1042 basic_block m_bb;
kono
parents:
diff changeset
1043
kono
parents:
diff changeset
1044 /* The operand that refers to the label to this BB. */
kono
parents:
diff changeset
1045 hsa_op_code_ref m_label_ref;
kono
parents:
diff changeset
1046
kono
parents:
diff changeset
1047 /* The first and last instruction. */
kono
parents:
diff changeset
1048 hsa_insn_basic *m_first_insn, *m_last_insn;
kono
parents:
diff changeset
1049 /* The first and last phi node. */
kono
parents:
diff changeset
1050 hsa_insn_phi *m_first_phi, *m_last_phi;
kono
parents:
diff changeset
1051
kono
parents:
diff changeset
1052 /* Just a number to construct names from. */
kono
parents:
diff changeset
1053 int m_index;
kono
parents:
diff changeset
1054
kono
parents:
diff changeset
1055 auto_bitmap m_liveout, m_livein;
kono
parents:
diff changeset
1056 private:
kono
parents:
diff changeset
1057 /* Make the default constructor inaccessible. */
kono
parents:
diff changeset
1058 hsa_bb ();
kono
parents:
diff changeset
1059 /* All objects are deallocated by destroying their pool, so make delete
kono
parents:
diff changeset
1060 inaccessible too. */
kono
parents:
diff changeset
1061 void operator delete (void *) {}
kono
parents:
diff changeset
1062 };
kono
parents:
diff changeset
1063
kono
parents:
diff changeset
1064 /* Return the corresponding HSA basic block structure for the given control
kono
parents:
diff changeset
1065 flow basic_block BB. */
kono
parents:
diff changeset
1066
kono
parents:
diff changeset
1067 static inline hsa_bb *
kono
parents:
diff changeset
1068 hsa_bb_for_bb (basic_block bb)
kono
parents:
diff changeset
1069 {
kono
parents:
diff changeset
1070 return (struct hsa_bb *) bb->aux;
kono
parents:
diff changeset
1071 }
kono
parents:
diff changeset
1072
kono
parents:
diff changeset
1073 /* Class for hashing local hsa_symbols. */
kono
parents:
diff changeset
1074
kono
parents:
diff changeset
1075 struct hsa_noop_symbol_hasher : nofree_ptr_hash <hsa_symbol>
kono
parents:
diff changeset
1076 {
kono
parents:
diff changeset
1077 static inline hashval_t hash (const value_type);
kono
parents:
diff changeset
1078 static inline bool equal (const value_type, const compare_type);
kono
parents:
diff changeset
1079 };
kono
parents:
diff changeset
1080
kono
parents:
diff changeset
1081 /* Hash hsa_symbol. */
kono
parents:
diff changeset
1082
kono
parents:
diff changeset
1083 inline hashval_t
kono
parents:
diff changeset
1084 hsa_noop_symbol_hasher::hash (const value_type item)
kono
parents:
diff changeset
1085 {
kono
parents:
diff changeset
1086 return DECL_UID (item->m_decl);
kono
parents:
diff changeset
1087 }
kono
parents:
diff changeset
1088
kono
parents:
diff changeset
1089 /* Return true if the DECL_UIDs of decls both symbols refer to are equal. */
kono
parents:
diff changeset
1090
kono
parents:
diff changeset
1091 inline bool
kono
parents:
diff changeset
1092 hsa_noop_symbol_hasher::equal (const value_type a, const compare_type b)
kono
parents:
diff changeset
1093 {
kono
parents:
diff changeset
1094 return (DECL_UID (a->m_decl) == DECL_UID (b->m_decl));
kono
parents:
diff changeset
1095 }
kono
parents:
diff changeset
1096
kono
parents:
diff changeset
1097 /* Structure that encapsulates intermediate representation of a HSA
kono
parents:
diff changeset
1098 function. */
kono
parents:
diff changeset
1099
kono
parents:
diff changeset
1100 class hsa_function_representation
kono
parents:
diff changeset
1101 {
kono
parents:
diff changeset
1102 public:
kono
parents:
diff changeset
1103 hsa_function_representation (tree fdecl, bool kernel_p,
kono
parents:
diff changeset
1104 unsigned ssa_names_count,
kono
parents:
diff changeset
1105 bool modified_cfg = false);
kono
parents:
diff changeset
1106 hsa_function_representation (hsa_internal_fn *fn);
kono
parents:
diff changeset
1107 ~hsa_function_representation ();
kono
parents:
diff changeset
1108
kono
parents:
diff changeset
1109 /* Builds a shadow register that is utilized to a kernel dispatch. */
kono
parents:
diff changeset
1110 hsa_op_reg *get_shadow_reg ();
kono
parents:
diff changeset
1111
kono
parents:
diff changeset
1112 /* Return true if we are in a function that has kernel dispatch
kono
parents:
diff changeset
1113 shadow register. */
kono
parents:
diff changeset
1114 bool has_shadow_reg_p ();
kono
parents:
diff changeset
1115
kono
parents:
diff changeset
1116 /* The entry/exit blocks don't contain incoming code,
kono
parents:
diff changeset
1117 but the HSA generator might use them to put code into,
kono
parents:
diff changeset
1118 so we need hsa_bb instances of them. */
kono
parents:
diff changeset
1119 void init_extra_bbs ();
kono
parents:
diff changeset
1120
kono
parents:
diff changeset
1121 /* Update CFG dominators if m_modified_cfg flag is set. */
kono
parents:
diff changeset
1122 void update_dominance ();
kono
parents:
diff changeset
1123
kono
parents:
diff changeset
1124 /* Return linkage of the representation. */
kono
parents:
diff changeset
1125 BrigLinkage8_t get_linkage ();
kono
parents:
diff changeset
1126
kono
parents:
diff changeset
1127 /* Create a private symbol of requested TYPE. */
kono
parents:
diff changeset
1128 hsa_symbol *create_hsa_temporary (BrigType16_t type);
kono
parents:
diff changeset
1129
kono
parents:
diff changeset
1130 /* Lookup or create a HSA pseudo register for a given gimple SSA name. */
kono
parents:
diff changeset
1131 hsa_op_reg *reg_for_gimple_ssa (tree ssa);
kono
parents:
diff changeset
1132
kono
parents:
diff changeset
1133 /* Name of the function. */
kono
parents:
diff changeset
1134 char *m_name;
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 /* Number of allocated register structures. */
kono
parents:
diff changeset
1137 int m_reg_count;
kono
parents:
diff changeset
1138
kono
parents:
diff changeset
1139 /* Input arguments. */
kono
parents:
diff changeset
1140 vec <hsa_symbol *> m_input_args;
kono
parents:
diff changeset
1141
kono
parents:
diff changeset
1142 /* Output argument or NULL if there is none. */
kono
parents:
diff changeset
1143 hsa_symbol *m_output_arg;
kono
parents:
diff changeset
1144
kono
parents:
diff changeset
1145 /* Hash table of local variable symbols. */
kono
parents:
diff changeset
1146 hash_table <hsa_noop_symbol_hasher> *m_local_symbols;
kono
parents:
diff changeset
1147
kono
parents:
diff changeset
1148 /* Hash map for string constants. */
kono
parents:
diff changeset
1149 hash_map <tree, hsa_symbol *> m_string_constants_map;
kono
parents:
diff changeset
1150
kono
parents:
diff changeset
1151 /* Vector of pointers to spill symbols. */
kono
parents:
diff changeset
1152 vec <struct hsa_symbol *> m_spill_symbols;
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 /* Vector of pointers to global variables and transformed string constants
kono
parents:
diff changeset
1155 that are used by the function. */
kono
parents:
diff changeset
1156 vec <struct hsa_symbol *> m_global_symbols;
kono
parents:
diff changeset
1157
kono
parents:
diff changeset
1158 /* Private function artificial variables. */
kono
parents:
diff changeset
1159 vec <struct hsa_symbol *> m_private_variables;
kono
parents:
diff changeset
1160
kono
parents:
diff changeset
1161 /* Vector of called function declarations. */
kono
parents:
diff changeset
1162 vec <tree> m_called_functions;
kono
parents:
diff changeset
1163
kono
parents:
diff changeset
1164 /* Vector of used internal functions. */
kono
parents:
diff changeset
1165 vec <hsa_internal_fn *> m_called_internal_fns;
kono
parents:
diff changeset
1166
kono
parents:
diff changeset
1167 /* Number of HBB BBs. */
kono
parents:
diff changeset
1168 int m_hbb_count;
kono
parents:
diff changeset
1169
kono
parents:
diff changeset
1170 /* Whether or not we could check and enforce SSA properties. */
kono
parents:
diff changeset
1171 bool m_in_ssa;
kono
parents:
diff changeset
1172
kono
parents:
diff changeset
1173 /* True if the function is kernel function. */
kono
parents:
diff changeset
1174 bool m_kern_p;
kono
parents:
diff changeset
1175
kono
parents:
diff changeset
1176 /* True if the function representation is a declaration. */
kono
parents:
diff changeset
1177 bool m_declaration_p;
kono
parents:
diff changeset
1178
kono
parents:
diff changeset
1179 /* Function declaration tree. */
kono
parents:
diff changeset
1180 tree m_decl;
kono
parents:
diff changeset
1181
kono
parents:
diff changeset
1182 /* Internal function info is used for declarations of internal functions. */
kono
parents:
diff changeset
1183 hsa_internal_fn *m_internal_fn;
kono
parents:
diff changeset
1184
kono
parents:
diff changeset
1185 /* Runtime shadow register. */
kono
parents:
diff changeset
1186 hsa_op_reg *m_shadow_reg;
kono
parents:
diff changeset
1187
kono
parents:
diff changeset
1188 /* Number of kernel dispatched which take place in the function. */
kono
parents:
diff changeset
1189 unsigned m_kernel_dispatch_count;
kono
parents:
diff changeset
1190
kono
parents:
diff changeset
1191 /* If the function representation contains a kernel dispatch,
kono
parents:
diff changeset
1192 OMP data size is necessary memory that is used for copying before
kono
parents:
diff changeset
1193 a kernel dispatch. */
kono
parents:
diff changeset
1194 unsigned m_maximum_omp_data_size;
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 /* Return true if there's an HSA-specific warning already seen. */
kono
parents:
diff changeset
1197 bool m_seen_error;
kono
parents:
diff changeset
1198
kono
parents:
diff changeset
1199 /* Counter for temporary symbols created in the function representation. */
kono
parents:
diff changeset
1200 unsigned m_temp_symbol_count;
kono
parents:
diff changeset
1201
kono
parents:
diff changeset
1202 /* SSA names mapping. */
kono
parents:
diff changeset
1203 vec <hsa_op_reg *> m_ssa_map;
kono
parents:
diff changeset
1204
kono
parents:
diff changeset
1205 /* Flag whether a function needs update of dominators before RA. */
kono
parents:
diff changeset
1206 bool m_modified_cfg;
kono
parents:
diff changeset
1207 };
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 enum hsa_function_kind
kono
parents:
diff changeset
1210 {
kono
parents:
diff changeset
1211 HSA_NONE,
kono
parents:
diff changeset
1212 HSA_KERNEL,
kono
parents:
diff changeset
1213 HSA_FUNCTION
kono
parents:
diff changeset
1214 };
kono
parents:
diff changeset
1215
kono
parents:
diff changeset
1216 struct hsa_function_summary
kono
parents:
diff changeset
1217 {
kono
parents:
diff changeset
1218 /* Default constructor. */
kono
parents:
diff changeset
1219 hsa_function_summary ();
kono
parents:
diff changeset
1220
kono
parents:
diff changeset
1221 /* Kind of GPU/host function. */
kono
parents:
diff changeset
1222 hsa_function_kind m_kind;
kono
parents:
diff changeset
1223
kono
parents:
diff changeset
1224 /* Pointer to a cgraph node which is a HSA implementation of the function.
kono
parents:
diff changeset
1225 In case of the function is a HSA function, the bound function points
kono
parents:
diff changeset
1226 to the host function. */
kono
parents:
diff changeset
1227 cgraph_node *m_bound_function;
kono
parents:
diff changeset
1228
kono
parents:
diff changeset
1229 /* Identifies if the function is an HSA function or a host function. */
kono
parents:
diff changeset
1230 bool m_gpu_implementation_p;
kono
parents:
diff changeset
1231
kono
parents:
diff changeset
1232 /* True if the function is a gridified kernel. */
kono
parents:
diff changeset
1233 bool m_gridified_kernel_p;
kono
parents:
diff changeset
1234 };
kono
parents:
diff changeset
1235
kono
parents:
diff changeset
1236 inline
kono
parents:
diff changeset
1237 hsa_function_summary::hsa_function_summary (): m_kind (HSA_NONE),
kono
parents:
diff changeset
1238 m_bound_function (NULL), m_gpu_implementation_p (false)
kono
parents:
diff changeset
1239 {
kono
parents:
diff changeset
1240 }
kono
parents:
diff changeset
1241
kono
parents:
diff changeset
1242 /* Function summary for HSA functions. */
kono
parents:
diff changeset
1243 class hsa_summary_t: public function_summary <hsa_function_summary *>
kono
parents:
diff changeset
1244 {
kono
parents:
diff changeset
1245 public:
kono
parents:
diff changeset
1246 hsa_summary_t (symbol_table *table):
kono
parents:
diff changeset
1247 function_summary<hsa_function_summary *> (table) { }
kono
parents:
diff changeset
1248
kono
parents:
diff changeset
1249 /* Couple GPU and HOST as gpu-specific and host-specific implementation of
kono
parents:
diff changeset
1250 the same function. KIND determines whether GPU is a host-invokable kernel
kono
parents:
diff changeset
1251 or gpu-callable function and GRIDIFIED_KERNEL_P is set if the function was
kono
parents:
diff changeset
1252 gridified in OMP. */
kono
parents:
diff changeset
1253
kono
parents:
diff changeset
1254 void link_functions (cgraph_node *gpu, cgraph_node *host,
kono
parents:
diff changeset
1255 hsa_function_kind kind, bool gridified_kernel_p);
kono
parents:
diff changeset
1256
kono
parents:
diff changeset
1257 private:
kono
parents:
diff changeset
1258 void process_gpu_implementation_attributes (tree gdecl);
kono
parents:
diff changeset
1259 };
kono
parents:
diff changeset
1260
kono
parents:
diff changeset
1261 /* OMP simple builtin describes behavior that should be done for
kono
parents:
diff changeset
1262 the routine. */
kono
parents:
diff changeset
1263 class omp_simple_builtin
kono
parents:
diff changeset
1264 {
kono
parents:
diff changeset
1265 public:
kono
parents:
diff changeset
1266 omp_simple_builtin (const char *name, const char *warning_message,
kono
parents:
diff changeset
1267 bool sorry, hsa_op_immed *return_value = NULL):
kono
parents:
diff changeset
1268 m_name (name), m_warning_message (warning_message), m_sorry (sorry),
kono
parents:
diff changeset
1269 m_return_value (return_value)
kono
parents:
diff changeset
1270 {}
kono
parents:
diff changeset
1271
kono
parents:
diff changeset
1272 /* Generate HSAIL instructions for the builtin or produce warning message. */
kono
parents:
diff changeset
1273 void generate (gimple *stmt, hsa_bb *hbb);
kono
parents:
diff changeset
1274
kono
parents:
diff changeset
1275 /* Name of function. */
kono
parents:
diff changeset
1276 const char *m_name;
kono
parents:
diff changeset
1277
kono
parents:
diff changeset
1278 /* Warning message. */
kono
parents:
diff changeset
1279 const char *m_warning_message;
kono
parents:
diff changeset
1280
kono
parents:
diff changeset
1281 /* Flag if we should sorry after the warning message is printed. */
kono
parents:
diff changeset
1282 bool m_sorry;
kono
parents:
diff changeset
1283
kono
parents:
diff changeset
1284 /* Return value of the function. */
kono
parents:
diff changeset
1285 hsa_op_immed *m_return_value;
kono
parents:
diff changeset
1286
kono
parents:
diff changeset
1287 /* Emission function. */
kono
parents:
diff changeset
1288 void (*m_emit_func) (gimple *stmt, hsa_bb *);
kono
parents:
diff changeset
1289 };
kono
parents:
diff changeset
1290
kono
parents:
diff changeset
1291 /* Class for hashing hsa_internal_fn. */
kono
parents:
diff changeset
1292
kono
parents:
diff changeset
1293 struct hsa_internal_fn_hasher: free_ptr_hash <hsa_internal_fn>
kono
parents:
diff changeset
1294 {
kono
parents:
diff changeset
1295 static inline hashval_t hash (const value_type);
kono
parents:
diff changeset
1296 static inline bool equal (const value_type, const compare_type);
kono
parents:
diff changeset
1297 };
kono
parents:
diff changeset
1298
kono
parents:
diff changeset
1299 /* Hash hsa_symbol. */
kono
parents:
diff changeset
1300
kono
parents:
diff changeset
1301 inline hashval_t
kono
parents:
diff changeset
1302 hsa_internal_fn_hasher::hash (const value_type item)
kono
parents:
diff changeset
1303 {
kono
parents:
diff changeset
1304 return item->m_fn;
kono
parents:
diff changeset
1305 }
kono
parents:
diff changeset
1306
kono
parents:
diff changeset
1307 /* Return true if the DECL_UIDs of decls both symbols refer to are equal. */
kono
parents:
diff changeset
1308
kono
parents:
diff changeset
1309 inline bool
kono
parents:
diff changeset
1310 hsa_internal_fn_hasher::equal (const value_type a, const compare_type b)
kono
parents:
diff changeset
1311 {
kono
parents:
diff changeset
1312 return a->m_fn == b->m_fn && a->m_type_bit_size == b->m_type_bit_size;
kono
parents:
diff changeset
1313 }
kono
parents:
diff changeset
1314
kono
parents:
diff changeset
1315 /* in hsa-common.c */
kono
parents:
diff changeset
1316 extern struct hsa_function_representation *hsa_cfun;
kono
parents:
diff changeset
1317 extern hash_map <tree, vec <const char *> *> *hsa_decl_kernel_dependencies;
kono
parents:
diff changeset
1318 extern hsa_summary_t *hsa_summaries;
kono
parents:
diff changeset
1319 extern hsa_symbol *hsa_num_threads;
kono
parents:
diff changeset
1320 extern unsigned hsa_kernel_calls_counter;
kono
parents:
diff changeset
1321 extern hash_set <tree> *hsa_failed_functions;
kono
parents:
diff changeset
1322 extern hash_table <hsa_noop_symbol_hasher> *hsa_global_variable_symbols;
kono
parents:
diff changeset
1323
kono
parents:
diff changeset
1324 bool hsa_callable_function_p (tree fndecl);
kono
parents:
diff changeset
1325 void hsa_init_compilation_unit_data (void);
kono
parents:
diff changeset
1326 void hsa_deinit_compilation_unit_data (void);
kono
parents:
diff changeset
1327 bool hsa_machine_large_p (void);
kono
parents:
diff changeset
1328 bool hsa_full_profile_p (void);
kono
parents:
diff changeset
1329 bool hsa_opcode_floating_bit_insn_p (BrigOpcode16_t);
kono
parents:
diff changeset
1330 unsigned hsa_type_bit_size (BrigType16_t t);
kono
parents:
diff changeset
1331 BrigType16_t hsa_bittype_for_bitsize (unsigned bitsize);
kono
parents:
diff changeset
1332 BrigType16_t hsa_uint_for_bitsize (unsigned bitsize);
kono
parents:
diff changeset
1333 BrigType16_t hsa_float_for_bitsize (unsigned bitsize);
kono
parents:
diff changeset
1334 BrigType16_t hsa_bittype_for_type (BrigType16_t t);
kono
parents:
diff changeset
1335 BrigType16_t hsa_unsigned_type_for_type (BrigType16_t t);
kono
parents:
diff changeset
1336 bool hsa_type_packed_p (BrigType16_t type);
kono
parents:
diff changeset
1337 bool hsa_type_float_p (BrigType16_t type);
kono
parents:
diff changeset
1338 bool hsa_type_integer_p (BrigType16_t type);
kono
parents:
diff changeset
1339 bool hsa_btype_p (BrigType16_t type);
kono
parents:
diff changeset
1340 BrigAlignment8_t hsa_alignment_encoding (unsigned n);
kono
parents:
diff changeset
1341 BrigAlignment8_t hsa_natural_alignment (BrigType16_t type);
kono
parents:
diff changeset
1342 BrigAlignment8_t hsa_object_alignment (tree t);
kono
parents:
diff changeset
1343 unsigned hsa_byte_alignment (BrigAlignment8_t alignment);
kono
parents:
diff changeset
1344 void hsa_destroy_operand (hsa_op_base *op);
kono
parents:
diff changeset
1345 void hsa_destroy_insn (hsa_insn_basic *insn);
kono
parents:
diff changeset
1346 void hsa_add_kern_decl_mapping (tree decl, char *name, unsigned, bool);
kono
parents:
diff changeset
1347 unsigned hsa_get_number_decl_kernel_mappings (void);
kono
parents:
diff changeset
1348 tree hsa_get_decl_kernel_mapping_decl (unsigned i);
kono
parents:
diff changeset
1349 char *hsa_get_decl_kernel_mapping_name (unsigned i);
kono
parents:
diff changeset
1350 unsigned hsa_get_decl_kernel_mapping_omp_size (unsigned i);
kono
parents:
diff changeset
1351 bool hsa_get_decl_kernel_mapping_gridified (unsigned i);
kono
parents:
diff changeset
1352 void hsa_free_decl_kernel_mapping (void);
kono
parents:
diff changeset
1353 tree *hsa_get_ctor_statements (void);
kono
parents:
diff changeset
1354 tree *hsa_get_dtor_statements (void);
kono
parents:
diff changeset
1355 tree *hsa_get_kernel_dispatch_type (void);
kono
parents:
diff changeset
1356 void hsa_add_kernel_dependency (tree caller, const char *called_function);
kono
parents:
diff changeset
1357 void hsa_sanitize_name (char *p);
kono
parents:
diff changeset
1358 char *hsa_brig_function_name (const char *p);
kono
parents:
diff changeset
1359 const char *hsa_get_declaration_name (tree decl);
kono
parents:
diff changeset
1360 void hsa_register_kernel (cgraph_node *host);
kono
parents:
diff changeset
1361 void hsa_register_kernel (cgraph_node *gpu, cgraph_node *host);
kono
parents:
diff changeset
1362 bool hsa_seen_error (void);
kono
parents:
diff changeset
1363 void hsa_fail_cfun (void);
kono
parents:
diff changeset
1364
kono
parents:
diff changeset
1365 /* In hsa-gen.c. */
kono
parents:
diff changeset
1366 void hsa_build_append_simple_mov (hsa_op_reg *, hsa_op_base *, hsa_bb *);
kono
parents:
diff changeset
1367 hsa_symbol *hsa_get_spill_symbol (BrigType16_t);
kono
parents:
diff changeset
1368 hsa_symbol *hsa_get_string_cst_symbol (BrigType16_t);
kono
parents:
diff changeset
1369 hsa_op_reg *hsa_spill_in (hsa_insn_basic *, hsa_op_reg *, hsa_op_reg **);
kono
parents:
diff changeset
1370 hsa_op_reg *hsa_spill_out (hsa_insn_basic *, hsa_op_reg *, hsa_op_reg **);
kono
parents:
diff changeset
1371 hsa_bb *hsa_init_new_bb (basic_block);
kono
parents:
diff changeset
1372 hsa_function_representation *hsa_generate_function_declaration (tree decl);
kono
parents:
diff changeset
1373 hsa_function_representation *hsa_generate_internal_fn_decl (hsa_internal_fn *);
kono
parents:
diff changeset
1374 tree hsa_get_host_function (tree decl);
kono
parents:
diff changeset
1375
kono
parents:
diff changeset
1376 /* In hsa-regalloc.c. */
kono
parents:
diff changeset
1377 void hsa_regalloc (void);
kono
parents:
diff changeset
1378
kono
parents:
diff changeset
1379 /* In hsa-brig.c. */
kono
parents:
diff changeset
1380 extern hash_table <hsa_internal_fn_hasher> *hsa_emitted_internal_decls;
kono
parents:
diff changeset
1381 void hsa_brig_emit_function (void);
kono
parents:
diff changeset
1382 void hsa_output_brig (void);
kono
parents:
diff changeset
1383 unsigned hsa_get_imm_brig_type_len (BrigType16_t type);
kono
parents:
diff changeset
1384 void hsa_brig_emit_omp_symbols (void);
kono
parents:
diff changeset
1385
kono
parents:
diff changeset
1386 /* In hsa-dump.c. */
kono
parents:
diff changeset
1387 const char *hsa_seg_name (BrigSegment8_t);
kono
parents:
diff changeset
1388 void dump_hsa_insn (FILE *f, hsa_insn_basic *insn);
kono
parents:
diff changeset
1389 void dump_hsa_bb (FILE *, hsa_bb *);
kono
parents:
diff changeset
1390 void dump_hsa_cfun (FILE *);
kono
parents:
diff changeset
1391 DEBUG_FUNCTION void debug_hsa_operand (hsa_op_base *opc);
kono
parents:
diff changeset
1392 DEBUG_FUNCTION void debug_hsa_insn (hsa_insn_basic *insn);
kono
parents:
diff changeset
1393
kono
parents:
diff changeset
1394 union hsa_bytes
kono
parents:
diff changeset
1395 {
kono
parents:
diff changeset
1396 uint8_t b8;
kono
parents:
diff changeset
1397 uint16_t b16;
kono
parents:
diff changeset
1398 uint32_t b32;
kono
parents:
diff changeset
1399 uint64_t b64;
kono
parents:
diff changeset
1400 };
kono
parents:
diff changeset
1401
kono
parents:
diff changeset
1402 /* Return true if a function DECL is an HSA implementation. */
kono
parents:
diff changeset
1403
kono
parents:
diff changeset
1404 static inline bool
kono
parents:
diff changeset
1405 hsa_gpu_implementation_p (tree decl)
kono
parents:
diff changeset
1406 {
kono
parents:
diff changeset
1407 if (hsa_summaries == NULL)
kono
parents:
diff changeset
1408 return false;
kono
parents:
diff changeset
1409
kono
parents:
diff changeset
1410 hsa_function_summary *s = hsa_summaries->get (cgraph_node::get_create (decl));
kono
parents:
diff changeset
1411
kono
parents:
diff changeset
1412 return s->m_gpu_implementation_p;
kono
parents:
diff changeset
1413 }
kono
parents:
diff changeset
1414
kono
parents:
diff changeset
1415 #endif /* HSA_H */