annotate gcc/brig/brigfrontend/brig-to-generic.h @ 111: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
111
kono
parents:
diff changeset
1 /* brig-to-generic.h -- brig to gcc generic conversion
kono
parents:
diff changeset
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
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);
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 void start_function (tree f);
kono
parents:
diff changeset
79 void finish_function ();
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 void append_private_variable (const std::string &name, size_t size,
kono
parents:
diff changeset
82 size_t alignment);
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 size_t
kono
parents:
diff changeset
85 private_variable_segment_offset (const std::string &name) const;
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 bool
kono
parents:
diff changeset
88 has_private_variable (const std::string &name) const;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 size_t private_variable_size (const std::string &name) const;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 template <typename T>
kono
parents:
diff changeset
93 std::string
kono
parents:
diff changeset
94 get_mangled_name_tmpl (const T *brigVar) const;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 std::string get_mangled_name (const BrigDirectiveFbarrier *fbar) const
kono
parents:
diff changeset
97 { return get_mangled_name_tmpl (fbar); }
kono
parents:
diff changeset
98 std::string get_mangled_name (const BrigDirectiveVariable *var) const
kono
parents:
diff changeset
99 { return get_mangled_name_tmpl (var); }
kono
parents:
diff changeset
100 std::string get_mangled_name (const BrigDirectiveExecutable *func) const;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 size_t private_segment_size () const;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 brig_function *get_finished_function (tree func_decl);
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 void add_group_variable (const std::string &name, size_t size,
kono
parents:
diff changeset
107 size_t alignment, bool function_scope);
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 static tree s_fp16_type;
kono
parents:
diff changeset
110 static tree s_fp32_type;
kono
parents:
diff changeset
111 static tree s_fp64_type;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 /* The default rounding mode that should be used for float instructions.
kono
parents:
diff changeset
114 This can be set in each BRIG module header. */
kono
parents:
diff changeset
115 BrigRound8_t m_default_float_rounding_mode;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 /* The currently built function. */
kono
parents:
diff changeset
118 brig_function *m_cf;
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 /* Stores the module and function scope group variable offsets. */
kono
parents:
diff changeset
121 group_variable_offset_index m_module_group_variables;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 /* The name of the currently handled BRIG module. */
kono
parents:
diff changeset
124 std::string m_module_name;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 /* Set to true if the compilation is in 'analyze' phase. */
kono
parents:
diff changeset
127 bool m_analyzing;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 /* Accumulates the total group segment usage. */
kono
parents:
diff changeset
130 size_t m_total_group_segment_usage;
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 private:
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 void find_brig_sections ();
kono
parents:
diff changeset
135 /* The BRIG blob and its different sections of the file currently being
kono
parents:
diff changeset
136 parsed. */
kono
parents:
diff changeset
137 const char *m_brig;
kono
parents:
diff changeset
138 const char *m_data;
kono
parents:
diff changeset
139 size_t m_data_size;
kono
parents:
diff changeset
140 const char *m_operand;
kono
parents:
diff changeset
141 size_t m_operand_size;
kono
parents:
diff changeset
142 const char *m_code;
kono
parents:
diff changeset
143 size_t m_code_size;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 tree m_globals;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 label_index m_global_variables;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 /* The size of each private variable, including the alignment padding. */
kono
parents:
diff changeset
150 std::map<std::string, size_t> m_private_data_sizes;
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 /* And private. */
kono
parents:
diff changeset
153 size_t m_next_private_offset;
kono
parents:
diff changeset
154 var_offset_table m_private_offsets;
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 /* Name index for declared functions. */
kono
parents:
diff changeset
157 label_index m_function_index;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 /* Stores all processed kernels in order. */
kono
parents:
diff changeset
160 std::vector<brig_function *> m_kernels;
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 /* Stores all already processed functions from the translation unit
kono
parents:
diff changeset
163 for some interprocedural analysis. */
kono
parents:
diff changeset
164 std::map<std::string, brig_function *> m_finished_functions;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 /* The original dump file. */
kono
parents:
diff changeset
167 FILE *m_dump_file;
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 /* The original dump file flags. */
kono
parents:
diff changeset
170 dump_flags_t m_dump_flags;
kono
parents:
diff changeset
171 };
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 /* Produce a "mangled name" for the given brig variable. The mangling is used
kono
parents:
diff changeset
174 to make unique global symbol names for module and function scope variables.
kono
parents:
diff changeset
175 The templated version is suitable for most of the variable types. Functions
kono
parents:
diff changeset
176 and kernels (BrigDirectiveExecutable) are handled with a specialized
kono
parents:
diff changeset
177 get_mangled_name() version. */
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 template <typename T>
kono
parents:
diff changeset
180 std::string
kono
parents:
diff changeset
181 brig_to_generic::get_mangled_name_tmpl (const T *brigVar) const
kono
parents:
diff changeset
182 {
kono
parents:
diff changeset
183 std::string var_name = get_string (brigVar->name).substr (1);
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 /* Mangle the variable name using the function name and the module name
kono
parents:
diff changeset
186 in case of a function scope variable. */
kono
parents:
diff changeset
187 if (m_cf != NULL
kono
parents:
diff changeset
188 && m_cf->has_function_scope_var (&brigVar->base))
kono
parents:
diff changeset
189 var_name = m_cf->m_name + "." + var_name;
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 if (brigVar->linkage == BRIG_LINKAGE_MODULE)
kono
parents:
diff changeset
192 var_name = "gccbrig." + m_module_name + "." + var_name;
kono
parents:
diff changeset
193 return var_name;
kono
parents:
diff changeset
194 }
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 /* An interface to organize the different types of BRIG element handlers. */
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 class brig_entry_handler
kono
parents:
diff changeset
199 {
kono
parents:
diff changeset
200 public:
kono
parents:
diff changeset
201 brig_entry_handler (brig_to_generic &parent) : m_parent (parent)
kono
parents:
diff changeset
202 {
kono
parents:
diff changeset
203 }
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 /* Handles the brig_code data at the given pointer and adds it to the
kono
parents:
diff changeset
206 currently built tree. Returns the number of consumed bytes; */
kono
parents:
diff changeset
207 virtual size_t operator () (const BrigBase *base) = 0;
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 protected:
kono
parents:
diff changeset
210 brig_to_generic &m_parent;
kono
parents:
diff changeset
211 };
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 tree call_builtin (tree pdecl, int nargs, tree rettype, ...);
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 tree build_reinterpret_cast (tree destination_type, tree source);
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 tree build_stmt (enum tree_code code, ...);
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 tree get_unsigned_int_type (tree type);
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 void dump_function (FILE *dump_file, brig_function *f);
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 #endif