annotate gcc/brig/brigfrontend/brig-function.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* brig-function.h -- declaration of brig_function class.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
kono
parents:
diff changeset
4 for General Processor Tech.
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 it under
kono
parents:
diff changeset
9 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
10 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
11 version.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
16 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 #ifndef BRIG_FUNCTION_H
kono
parents:
diff changeset
23 #define BRIG_FUNCTION_H
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include "config.h"
kono
parents:
diff changeset
26 #include "system.h"
kono
parents:
diff changeset
27 #include "ansidecl.h"
kono
parents:
diff changeset
28 #include "coretypes.h"
kono
parents:
diff changeset
29 #include "opts.h"
kono
parents:
diff changeset
30 #include "tree.h"
kono
parents:
diff changeset
31 #include "tree-iterator.h"
kono
parents:
diff changeset
32 #include "hsa-brig-format.h"
kono
parents:
diff changeset
33 #include "brig-util.h"
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 #include <map>
kono
parents:
diff changeset
36 #include <string>
kono
parents:
diff changeset
37 #include <vector>
kono
parents:
diff changeset
38 #include <set>
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 #include "phsa.h"
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 class brig_to_generic;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 typedef std::map<std::string, tree> label_index;
kono
parents:
diff changeset
45 typedef std::map<const BrigDirectiveVariable *, tree> variable_index;
kono
parents:
diff changeset
46 typedef std::vector<tree> tree_stl_vec;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* Holds data for the currently built GENERIC function. */
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 class brig_function
kono
parents:
diff changeset
51 {
kono
parents:
diff changeset
52 public:
kono
parents:
diff changeset
53 typedef std::map<const BrigDirectiveVariable *, size_t> var_offset_table;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 private:
kono
parents:
diff changeset
56 struct reg_decl_index_entry
kono
parents:
diff changeset
57 {
kono
parents:
diff changeset
58 tree m_var_decl;
kono
parents:
diff changeset
59 };
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 public:
kono
parents:
diff changeset
62 brig_function (const BrigDirectiveExecutable *exec, brig_to_generic *parent);
kono
parents:
diff changeset
63 ~brig_function ();
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 tree arg_variable (const BrigDirectiveVariable *var) const;
kono
parents:
diff changeset
66 void add_arg_variable (const BrigDirectiveVariable *brigVar, tree treeDecl);
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 void append_kernel_arg (const BrigDirectiveVariable *var, size_t size,
kono
parents:
diff changeset
69 size_t alignment);
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 size_t kernel_arg_offset (const BrigDirectiveVariable *var) const;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 void add_id_variables ();
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 tree label (const std::string &name);
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 tree add_local_variable (std::string name, tree type);
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 size_t group_variable_segment_offset (const std::string &name) const;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 bool has_group_variable (const std::string &name) const;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 size_t group_segment_size () const;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 tree get_m_var_declfor_reg (const BrigOperandRegister *reg);
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 bool convert_to_wg_function ();
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 void add_wi_loop (int dim, tree_stmt_iterator *header_entry,
kono
parents:
diff changeset
90 tree_stmt_iterator *branch_after);
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 tree emit_metadata (tree stmt_list);
kono
parents:
diff changeset
93 tree emit_launcher_and_metadata ();
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 tree append_statement (tree stmt);
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 void create_alloca_frame ();
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 void finish ();
kono
parents:
diff changeset
100 void finish_kernel ();
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 void append_return_stmt ();
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 bool has_function_scope_var (const BrigBase* var) const;
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 void analyze_calls ();
kono
parents:
diff changeset
107
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 tree expand_builtin (BrigOpcode16_t brig_opcode, tree_stl_vec &operands);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110 tree expand_or_call_builtin (BrigOpcode16_t brig_opcode,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
111 BrigType16_t brig_type, tree arith_type,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
112 tree_stl_vec &operands);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
113 bool can_expand_builtin (BrigOpcode16_t brig_opcode) const;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
114
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
115 tree get_builtin_for_hsa_opcode (tree type, BrigOpcode16_t brig_opcode,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
116 BrigType16_t brig_type) const;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
117
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
118 void unpack (tree value, tree_stl_vec &elements);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
119 tree pack (tree_stl_vec &elements);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
120 tree add_temp_var (std::string name, tree expr);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
121
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
122 static bool needs_workitem_context_data (BrigOpcode16_t brig_opcode);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
123 static HOST_WIDE_INT int_constant_value (tree node);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
124 static tree_code get_tree_code_for_hsa_opcode (BrigOpcode16_t brig_opcode,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
125 BrigType16_t brig_type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
126
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
127 void start_new_bb ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
128 void add_reg_var_update (tree reg_var, tree val);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
129 bool is_id_val (tree reg_var);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
130 tree id_val (tree reg_var);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
131
111
kono
parents:
diff changeset
132 const BrigDirectiveExecutable *m_brig_def;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 bool m_is_kernel;
kono
parents:
diff changeset
135 bool m_is_finished;
kono
parents:
diff changeset
136 std::string m_name;
kono
parents:
diff changeset
137 tree m_current_bind_expr;
kono
parents:
diff changeset
138 tree m_func_decl;
kono
parents:
diff changeset
139 tree m_entry_label_stmt;
kono
parents:
diff changeset
140 tree m_exit_label;
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 /* The __context function argument. */
kono
parents:
diff changeset
143 tree m_context_arg;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 /* The __group_base_ptr argument in the current function.
kono
parents:
diff changeset
146 Points to the start of the group segment for the work-group. */
kono
parents:
diff changeset
147 tree m_group_base_arg;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 /* The __group_local_offset_ptr argument in the current function. It
kono
parents:
diff changeset
150 contains the offset related to the group_base_ptr where the function's
kono
parents:
diff changeset
151 local area for group variables resides. */
kono
parents:
diff changeset
152 tree m_group_local_offset_arg;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 /* The __private_base_ptr argument in the current function.
kono
parents:
diff changeset
155 Points to the start of the private segment. */
kono
parents:
diff changeset
156 tree m_private_base_arg;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 /* The return value variable for the current function. */
kono
parents:
diff changeset
159 tree m_ret_value;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 /* The offsets of the kernel arguments in the __arg blob
kono
parents:
diff changeset
162 pointing to the kernel argument space. */
kono
parents:
diff changeset
163 size_t m_next_kernarg_offset;
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 /* The largest kernel argument variable alignment. */
kono
parents:
diff changeset
166 size_t m_kernarg_max_align;
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 var_offset_table m_kernarg_offsets;
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 /* Argument variables in the currently handled binding expression
kono
parents:
diff changeset
171 (argument segment). */
kono
parents:
diff changeset
172 variable_index m_arg_variables;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 /* The brig variable for the function return value. */
kono
parents:
diff changeset
175 const BrigDirectiveVariable *m_ret_value_brig_var;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 /* The function local temporary variable for the return value. */
kono
parents:
diff changeset
178 tree m_ret_temp;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 /* Labels in the current function are collected here so we can refer
kono
parents:
diff changeset
181 to them from jumps before they have been placed to the function. */
kono
parents:
diff changeset
182 label_index m_label_index;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 /* If the kernel contains at least one barrier, this is set to true. */
kono
parents:
diff changeset
185 bool m_has_barriers;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 /* True if the function has at least one alloca instruction. */
kono
parents:
diff changeset
188 bool m_has_allocas;
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 /* If the kernel contains at least one function call that _may_
kono
parents:
diff changeset
191 contain a barrier call, this is set to true. */
kono
parents:
diff changeset
192 bool m_has_function_calls_with_barriers;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 /* Set to true after this function has been analyzed for barrier and
kono
parents:
diff changeset
195 dispatch packet instruction usage in the final call graph analysis. */
kono
parents:
diff changeset
196 bool m_calls_analyzed;
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 /* True in case the function was successfully converted to a WG function. */
kono
parents:
diff changeset
199 bool m_is_wg_function;
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 /* Work-item ID related variables are cached in the entry of the kernel
kono
parents:
diff changeset
202 function in order to use them directly in address computations, leading
kono
parents:
diff changeset
203 to more efficient optimizations. The references to the local variables
kono
parents:
diff changeset
204 are stored here. */
kono
parents:
diff changeset
205 tree m_local_id_vars[3];
kono
parents:
diff changeset
206 tree m_cur_wg_size_vars[3];
kono
parents:
diff changeset
207 tree m_wg_id_vars[3];
kono
parents:
diff changeset
208 tree m_wg_size_vars[3];
kono
parents:
diff changeset
209 tree m_grid_size_vars[3];
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
210 /* Explicitly computed WG base for the absolute IDs which is used
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
211 as the initial value when looping that dimension. We update
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
212 the abs id with ++ to make it easy for the vectorizer. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
213 tree m_abs_id_base_vars[3];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
214 tree m_abs_id_vars[3];
111
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 /* Set to true in case the kernel contains at least one dispatch packet
kono
parents:
diff changeset
217 (work-item ID-related) builtin call that could not be expanded to
kono
parents:
diff changeset
218 tree nodes. */
kono
parents:
diff changeset
219 bool m_has_unexpanded_dp_builtins;
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 /* Points to the instruction after which the real kernel code starts.
kono
parents:
diff changeset
222 Usually points to the last WI ID variable initialization statement. */
kono
parents:
diff changeset
223 tree_stmt_iterator m_kernel_entry;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 /* True if we are currently generating the contents of an arg block. */
kono
parents:
diff changeset
226 bool m_generating_arg_block;
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 /* A collection of function scope variables seen so far for resolving
kono
parents:
diff changeset
229 variable references vs. module scope declarations. */
kono
parents:
diff changeset
230 std::set<const BrigBase*> m_function_scope_vars;
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 /* The functions called by this function. */
kono
parents:
diff changeset
233 std::vector<tree> m_called_functions;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* Stores the kernel scope group variable offsets if the function is
kono
parents:
diff changeset
236 a kernel. */
kono
parents:
diff changeset
237 group_variable_offset_index m_local_group_variables;
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 brig_to_generic *m_parent;
kono
parents:
diff changeset
240 /* The metadata of the function that should be stored with the binary and
kono
parents:
diff changeset
241 passed to the HSA runtime: */
kono
parents:
diff changeset
242 phsa_descriptor m_descriptor;
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 private:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
245
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
246 tree get_tree_type_for_hsa_reg (const BrigOperandRegister *reg) const;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
247
111
kono
parents:
diff changeset
248 /* Bookkeeping for the different HSA registers and their tree declarations
kono
parents:
diff changeset
249 for the currently generated function. */
kono
parents:
diff changeset
250 reg_decl_index_entry *m_regs[BRIG_2_TREE_HSAIL_TOTAL_REG_COUNT];
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
251
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
252 /* Map for keeping book reads of ID variables, which can be propagated
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
253 to uses in address expressions to produce cleaner indexing functions
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
254 with unnecessary casts stripped off, etc. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
255 typedef std::map<tree, tree> id_val_map;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
256
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
257 /* Keeps track of ID values alive in registers in the currently
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
258 processed BB. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
259 id_val_map m_id_val_defs;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
260
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
261 /* HSAIL-specific builtin functions not yet integrated to gcc. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
262 typedef std::map<std::pair<BrigOpcode16_t, BrigType16_t>, tree> builtin_map;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
263
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
264 static builtin_map s_custom_builtins;
111
kono
parents:
diff changeset
265 };
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 #endif