Split can_vec_perm_p into can_vec_perm_{var,const}_p
[official-gcc.git] / gcc / brig / brigfrontend / brig-function.h
blob3ed58cdc67a7fa870ee4a70a22c8afe5c161ff24
1 /* brig-function.h -- declaration of brig_function class.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
4 for General Processor Tech.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef BRIG_FUNCTION_H
23 #define BRIG_FUNCTION_H
25 #include "config.h"
26 #include "system.h"
27 #include "ansidecl.h"
28 #include "coretypes.h"
29 #include "opts.h"
30 #include "tree.h"
31 #include "tree-iterator.h"
32 #include "hsa-brig-format.h"
33 #include "brig-util.h"
35 #include <map>
36 #include <string>
37 #include <vector>
38 #include <set>
40 #include "phsa.h"
42 class brig_to_generic;
44 typedef std::map<std::string, tree> label_index;
45 typedef std::map<const BrigDirectiveVariable *, tree> variable_index;
46 typedef std::vector<tree> tree_stl_vec;
48 /* Holds data for the currently built GENERIC function. */
50 class brig_function
52 public:
53 typedef std::map<const BrigDirectiveVariable *, size_t> var_offset_table;
55 private:
56 struct reg_decl_index_entry
58 tree m_var_decl;
61 public:
62 brig_function (const BrigDirectiveExecutable *exec, brig_to_generic *parent);
63 ~brig_function ();
65 tree arg_variable (const BrigDirectiveVariable *var) const;
66 void add_arg_variable (const BrigDirectiveVariable *brigVar, tree treeDecl);
68 void append_kernel_arg (const BrigDirectiveVariable *var, size_t size,
69 size_t alignment);
71 size_t kernel_arg_offset (const BrigDirectiveVariable *var) const;
73 void add_id_variables ();
75 tree label (const std::string &name);
77 tree add_local_variable (std::string name, tree type);
79 size_t group_variable_segment_offset (const std::string &name) const;
81 bool has_group_variable (const std::string &name) const;
83 size_t group_segment_size () const;
85 tree get_m_var_declfor_reg (const BrigOperandRegister *reg);
87 bool convert_to_wg_function ();
89 void add_wi_loop (int dim, tree_stmt_iterator *header_entry,
90 tree_stmt_iterator *branch_after);
92 tree emit_metadata (tree stmt_list);
93 tree emit_launcher_and_metadata ();
95 tree append_statement (tree stmt);
97 void create_alloca_frame ();
99 void finish ();
100 void finish_kernel ();
102 void append_return_stmt ();
104 bool has_function_scope_var (const BrigBase* var) const;
106 void analyze_calls ();
108 const BrigDirectiveExecutable *m_brig_def;
110 bool m_is_kernel;
111 bool m_is_finished;
112 std::string m_name;
113 tree m_current_bind_expr;
114 tree m_func_decl;
115 tree m_entry_label_stmt;
116 tree m_exit_label;
118 /* The __context function argument. */
119 tree m_context_arg;
121 /* The __group_base_ptr argument in the current function.
122 Points to the start of the group segment for the work-group. */
123 tree m_group_base_arg;
125 /* The __group_local_offset_ptr argument in the current function. It
126 contains the offset related to the group_base_ptr where the function's
127 local area for group variables resides. */
128 tree m_group_local_offset_arg;
130 /* The __private_base_ptr argument in the current function.
131 Points to the start of the private segment. */
132 tree m_private_base_arg;
134 /* The return value variable for the current function. */
135 tree m_ret_value;
137 /* The offsets of the kernel arguments in the __arg blob
138 pointing to the kernel argument space. */
139 size_t m_next_kernarg_offset;
141 /* The largest kernel argument variable alignment. */
142 size_t m_kernarg_max_align;
144 var_offset_table m_kernarg_offsets;
146 /* Argument variables in the currently handled binding expression
147 (argument segment). */
148 variable_index m_arg_variables;
150 /* The brig variable for the function return value. */
151 const BrigDirectiveVariable *m_ret_value_brig_var;
153 /* The function local temporary variable for the return value. */
154 tree m_ret_temp;
156 /* Labels in the current function are collected here so we can refer
157 to them from jumps before they have been placed to the function. */
158 label_index m_label_index;
160 /* If the kernel contains at least one barrier, this is set to true. */
161 bool m_has_barriers;
163 /* True if the function has at least one alloca instruction. */
164 bool m_has_allocas;
166 /* If the kernel contains at least one function call that _may_
167 contain a barrier call, this is set to true. */
168 bool m_has_function_calls_with_barriers;
170 /* Set to true after this function has been analyzed for barrier and
171 dispatch packet instruction usage in the final call graph analysis. */
172 bool m_calls_analyzed;
174 /* True in case the function was successfully converted to a WG function. */
175 bool m_is_wg_function;
177 /* Work-item ID related variables are cached in the entry of the kernel
178 function in order to use them directly in address computations, leading
179 to more efficient optimizations. The references to the local variables
180 are stored here. */
181 tree m_local_id_vars[3];
182 tree m_cur_wg_size_vars[3];
183 tree m_wg_id_vars[3];
184 tree m_wg_size_vars[3];
185 tree m_grid_size_vars[3];
187 /* Set to true in case the kernel contains at least one dispatch packet
188 (work-item ID-related) builtin call that could not be expanded to
189 tree nodes. */
190 bool m_has_unexpanded_dp_builtins;
192 /* Points to the instruction after which the real kernel code starts.
193 Usually points to the last WI ID variable initialization statement. */
194 tree_stmt_iterator m_kernel_entry;
196 /* True if we are currently generating the contents of an arg block. */
197 bool m_generating_arg_block;
199 /* A collection of function scope variables seen so far for resolving
200 variable references vs. module scope declarations. */
201 std::set<const BrigBase*> m_function_scope_vars;
203 /* The functions called by this function. */
204 std::vector<tree> m_called_functions;
206 /* Stores the kernel scope group variable offsets if the function is
207 a kernel. */
208 group_variable_offset_index m_local_group_variables;
210 brig_to_generic *m_parent;
211 /* The metadata of the function that should be stored with the binary and
212 passed to the HSA runtime: */
213 phsa_descriptor m_descriptor;
215 private:
217 tree get_tree_type_for_hsa_reg (const BrigOperandRegister *reg) const;
219 /* Bookkeeping for the different HSA registers and their tree declarations
220 for the currently generated function. */
221 reg_decl_index_entry *m_regs[BRIG_2_TREE_HSAIL_TOTAL_REG_COUNT];
224 #endif