annotate gcc/brig/brigfrontend/brig-to-generic.h @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* brig-to-generic.h -- brig to gcc generic conversion
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2016-2020 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_TO_GENERIC_H
kono
parents:
diff changeset
23 #define BRIG_TO_GENERIC_H
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include <string>
kono
parents:
diff changeset
26 #include <map>
kono
parents:
diff changeset
27 #include <vector>
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 #include "config.h"
kono
parents:
diff changeset
30 #include "system.h"
kono
parents:
diff changeset
31 #include "ansidecl.h"
kono
parents:
diff changeset
32 #include "coretypes.h"
kono
parents:
diff changeset
33 #include "opts.h"
kono
parents:
diff changeset
34 #include "tree.h"
kono
parents:
diff changeset
35 #include "tree-iterator.h"
kono
parents:
diff changeset
36 #include "hsa-brig-format.h"
kono
parents:
diff changeset
37 #include "brig-function.h"
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 struct reg_decl_index_entry;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 /* Converts an HSAIL BRIG input to GENERIC. This class holds global state
kono
parents:
diff changeset
42 for the translation process. Handling of the smaller pieces of BRIG data
kono
parents:
diff changeset
43 is delegated to various handler classes declared in
kono
parents:
diff changeset
44 brig-code-entry-handlers.h. */
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 class brig_to_generic
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 public:
kono
parents:
diff changeset
49 typedef std::map<const BrigDirectiveVariable *, tree> variable_index;
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 private:
kono
parents:
diff changeset
52 typedef std::map<std::string, size_t> var_offset_table;
kono
parents:
diff changeset
53 typedef std::map<const BrigBase *, std::string> name_index;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 public:
kono
parents:
diff changeset
56 brig_to_generic ();
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 void analyze (const char *brig_blob);
kono
parents:
diff changeset
59 void parse (const char *brig_blob);
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 void write_globals ();
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 std::string get_string (size_t entry_offset) const;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 const BrigData *get_brig_data_entry (size_t entry_offset) const;
kono
parents:
diff changeset
66 const BrigBase *get_brig_operand_entry (size_t entry_offset) const;
kono
parents:
diff changeset
67 const BrigBase *get_brig_code_entry (size_t entry_offset) const;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 void append_global (tree g);
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 tree function_decl (const std::string &name);
kono
parents:
diff changeset
72 void add_function_decl (const std::string &name, tree func_decl);
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 tree global_variable (const std::string &name) const;
kono
parents:
diff changeset
75 void add_global_variable (const std::string &name, tree var_decl);
kono
parents:
diff changeset
76 void add_host_def_var_ptr (const std::string &name, tree var_decl);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
77 void add_decl_call (tree call);
111
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 void start_function (tree f);
kono
parents:
diff changeset
80 void finish_function ();
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 void append_private_variable (const std::string &name, size_t size,
kono
parents:
diff changeset
83 size_t alignment);
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 size_t
kono
parents:
diff changeset
86 private_variable_segment_offset (const std::string &name) const;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 bool
kono
parents:
diff changeset
89 has_private_variable (const std::string &name) const;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 size_t private_variable_size (const std::string &name) const;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 template <typename T>
kono
parents:
diff changeset
94 std::string
kono
parents:
diff changeset
95 get_mangled_name_tmpl (const T *brigVar) const;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 std::string get_mangled_name (const BrigDirectiveFbarrier *fbar) const
kono
parents:
diff changeset
98 { return get_mangled_name_tmpl (fbar); }
kono
parents:
diff changeset
99 std::string get_mangled_name (const BrigDirectiveVariable *var) const
kono
parents:
diff changeset
100 { return get_mangled_name_tmpl (var); }
kono
parents:
diff changeset
101 std::string get_mangled_name (const BrigDirectiveExecutable *func) const;
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 size_t private_segment_size () const;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 brig_function *get_finished_function (tree func_decl);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 void add_group_variable (const std::string &name, size_t size,
kono
parents:
diff changeset
108 size_t alignment, bool function_scope);
kono
parents:
diff changeset
109
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110 void add_reg_used_as_type (const BrigOperandRegister &brig_reg,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
111 tree operand_type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
112
111
kono
parents:
diff changeset
113 static tree s_fp16_type;
kono
parents:
diff changeset
114 static tree s_fp32_type;
kono
parents:
diff changeset
115 static tree s_fp64_type;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 /* The default rounding mode that should be used for float instructions.
kono
parents:
diff changeset
118 This can be set in each BRIG module header. */
kono
parents:
diff changeset
119 BrigRound8_t m_default_float_rounding_mode;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 /* The currently built function. */
kono
parents:
diff changeset
122 brig_function *m_cf;
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 /* Stores the module and function scope group variable offsets. */
kono
parents:
diff changeset
125 group_variable_offset_index m_module_group_variables;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 /* The name of the currently handled BRIG module. */
kono
parents:
diff changeset
128 std::string m_module_name;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 /* Set to true if the compilation is in 'analyze' phase. */
kono
parents:
diff changeset
131 bool m_analyzing;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 /* Accumulates the total group segment usage. */
kono
parents:
diff changeset
134 size_t m_total_group_segment_usage;
kono
parents:
diff changeset
135
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
136 /* Statistics about register uses per function. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137 std::map<std::string, regs_use_index> m_fn_regs_use_index;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138
111
kono
parents:
diff changeset
139 private:
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 void find_brig_sections ();
kono
parents:
diff changeset
142 /* The BRIG blob and its different sections of the file currently being
kono
parents:
diff changeset
143 parsed. */
kono
parents:
diff changeset
144 const char *m_brig;
kono
parents:
diff changeset
145 const char *m_data;
kono
parents:
diff changeset
146 size_t m_data_size;
kono
parents:
diff changeset
147 const char *m_operand;
kono
parents:
diff changeset
148 size_t m_operand_size;
kono
parents:
diff changeset
149 const char *m_code;
kono
parents:
diff changeset
150 size_t m_code_size;
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 tree m_globals;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 label_index m_global_variables;
kono
parents:
diff changeset
155
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
156 /* Calls to declarations to be fixed in the end of processing to call
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
157 defs instead. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
158 std::vector<tree> m_decl_call;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
159
111
kono
parents:
diff changeset
160 /* The size of each private variable, including the alignment padding. */
kono
parents:
diff changeset
161 std::map<std::string, size_t> m_private_data_sizes;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 /* And private. */
kono
parents:
diff changeset
164 size_t m_next_private_offset;
kono
parents:
diff changeset
165 var_offset_table m_private_offsets;
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 /* Name index for declared functions. */
kono
parents:
diff changeset
168 label_index m_function_index;
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 /* Stores all processed kernels in order. */
kono
parents:
diff changeset
171 std::vector<brig_function *> m_kernels;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 /* Stores all already processed functions from the translation unit
kono
parents:
diff changeset
174 for some interprocedural analysis. */
kono
parents:
diff changeset
175 std::map<std::string, brig_function *> m_finished_functions;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 /* The original dump file. */
kono
parents:
diff changeset
178 FILE *m_dump_file;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 /* The original dump file flags. */
kono
parents:
diff changeset
181 dump_flags_t m_dump_flags;
kono
parents:
diff changeset
182 };
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 /* Produce a "mangled name" for the given brig variable. The mangling is used
kono
parents:
diff changeset
185 to make unique global symbol names for module and function scope variables.
kono
parents:
diff changeset
186 The templated version is suitable for most of the variable types. Functions
kono
parents:
diff changeset
187 and kernels (BrigDirectiveExecutable) are handled with a specialized
kono
parents:
diff changeset
188 get_mangled_name() version. */
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 template <typename T>
kono
parents:
diff changeset
191 std::string
kono
parents:
diff changeset
192 brig_to_generic::get_mangled_name_tmpl (const T *brigVar) const
kono
parents:
diff changeset
193 {
kono
parents:
diff changeset
194 std::string var_name = get_string (brigVar->name).substr (1);
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 /* Mangle the variable name using the function name and the module name
kono
parents:
diff changeset
197 in case of a function scope variable. */
kono
parents:
diff changeset
198 if (m_cf != NULL
kono
parents:
diff changeset
199 && m_cf->has_function_scope_var (&brigVar->base))
kono
parents:
diff changeset
200 var_name = m_cf->m_name + "." + var_name;
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 if (brigVar->linkage == BRIG_LINKAGE_MODULE)
kono
parents:
diff changeset
203 var_name = "gccbrig." + m_module_name + "." + var_name;
kono
parents:
diff changeset
204 return var_name;
kono
parents:
diff changeset
205 }
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 /* An interface to organize the different types of BRIG element handlers. */
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 class brig_entry_handler
kono
parents:
diff changeset
210 {
kono
parents:
diff changeset
211 public:
kono
parents:
diff changeset
212 brig_entry_handler (brig_to_generic &parent) : m_parent (parent)
kono
parents:
diff changeset
213 {
kono
parents:
diff changeset
214 }
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 /* Handles the brig_code data at the given pointer and adds it to the
kono
parents:
diff changeset
217 currently built tree. Returns the number of consumed bytes; */
kono
parents:
diff changeset
218 virtual size_t operator () (const BrigBase *base) = 0;
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 protected:
kono
parents:
diff changeset
221 brig_to_generic &m_parent;
kono
parents:
diff changeset
222 };
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 tree call_builtin (tree pdecl, int nargs, tree rettype, ...);
kono
parents:
diff changeset
225
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
226 tree build_resize_convert_view (tree destination_type, tree source);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
227 tree build_reinterpret_to_uint (tree source);
111
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 tree build_stmt (enum tree_code code, ...);
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 tree get_unsigned_int_type (tree type);
kono
parents:
diff changeset
232
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
233 tree get_scalar_unsigned_int_type (tree type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
234 void set_externally_visible (tree decl);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
235
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
236 void set_inline (tree decl);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
237
111
kono
parents:
diff changeset
238 void dump_function (FILE *dump_file, brig_function *f);
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 #endif