PandA-2024.02
compiler_wrapper.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
47 #include "compiler_wrapper.hpp"
48 
49 #include "Parameter.hpp"
50 #include "compiler_constants.hpp"
51 #include "compiler_xml.hpp"
52 #include "cpu_stats.hpp"
53 #include "cpu_time.hpp"
54 #include "dbgPrintHelper.hpp"
55 #include "exceptions.hpp"
56 #include "fileIO.hpp"
57 #include "file_IO_constants.hpp"
58 #include "hls_step.hpp"
59 #include "parse_tree.hpp"
60 #include "polixml.hpp"
61 #include "string_manipulation.hpp"
62 #include "tree_manager.hpp"
63 #include "tree_node.hpp"
64 #include "tree_reindex.hpp"
65 #include "utility.hpp"
66 #include "xml_dom_parser.hpp"
67 #include "xml_helper.hpp"
68 
69 #include "config_CLANG_PLUGIN_DIR.hpp"
70 #include "config_EXTRA_CLANGPP_COMPILER_OPTION.hpp"
71 #include "config_GCC_PLUGIN_DIR.hpp"
72 #include "config_HAVE_I386_CLANG10_COMPILER.hpp"
73 #include "config_HAVE_I386_CLANG10_M32.hpp"
74 #include "config_HAVE_I386_CLANG10_M64.hpp"
75 #include "config_HAVE_I386_CLANG10_MX32.hpp"
76 #include "config_HAVE_I386_CLANG11_COMPILER.hpp"
77 #include "config_HAVE_I386_CLANG11_M32.hpp"
78 #include "config_HAVE_I386_CLANG11_M64.hpp"
79 #include "config_HAVE_I386_CLANG11_MX32.hpp"
80 #include "config_HAVE_I386_CLANG12_COMPILER.hpp"
81 #include "config_HAVE_I386_CLANG12_M32.hpp"
82 #include "config_HAVE_I386_CLANG12_M64.hpp"
83 #include "config_HAVE_I386_CLANG12_MX32.hpp"
84 #include "config_HAVE_I386_CLANG13_COMPILER.hpp"
85 #include "config_HAVE_I386_CLANG13_M32.hpp"
86 #include "config_HAVE_I386_CLANG13_M64.hpp"
87 #include "config_HAVE_I386_CLANG13_MX32.hpp"
88 #include "config_HAVE_I386_CLANG16_COMPILER.hpp"
89 #include "config_HAVE_I386_CLANG16_M32.hpp"
90 #include "config_HAVE_I386_CLANG16_M64.hpp"
91 #include "config_HAVE_I386_CLANG16_MX32.hpp"
92 #include "config_HAVE_I386_CLANG4_COMPILER.hpp"
93 #include "config_HAVE_I386_CLANG4_M32.hpp"
94 #include "config_HAVE_I386_CLANG4_M64.hpp"
95 #include "config_HAVE_I386_CLANG4_MX32.hpp"
96 #include "config_HAVE_I386_CLANG5_COMPILER.hpp"
97 #include "config_HAVE_I386_CLANG5_M32.hpp"
98 #include "config_HAVE_I386_CLANG5_M64.hpp"
99 #include "config_HAVE_I386_CLANG5_MX32.hpp"
100 #include "config_HAVE_I386_CLANG6_COMPILER.hpp"
101 #include "config_HAVE_I386_CLANG6_M32.hpp"
102 #include "config_HAVE_I386_CLANG6_M64.hpp"
103 #include "config_HAVE_I386_CLANG6_MX32.hpp"
104 #include "config_HAVE_I386_CLANG7_COMPILER.hpp"
105 #include "config_HAVE_I386_CLANG7_M32.hpp"
106 #include "config_HAVE_I386_CLANG7_M64.hpp"
107 #include "config_HAVE_I386_CLANG7_MX32.hpp"
108 #include "config_HAVE_I386_CLANG8_COMPILER.hpp"
109 #include "config_HAVE_I386_CLANG8_M32.hpp"
110 #include "config_HAVE_I386_CLANG8_M64.hpp"
111 #include "config_HAVE_I386_CLANG8_MX32.hpp"
112 #include "config_HAVE_I386_CLANG9_COMPILER.hpp"
113 #include "config_HAVE_I386_CLANG9_M32.hpp"
114 #include "config_HAVE_I386_CLANG9_M64.hpp"
115 #include "config_HAVE_I386_CLANG9_MX32.hpp"
116 #include "config_HAVE_I386_CLANGVVD_COMPILER.hpp"
117 #include "config_HAVE_I386_CLANGVVD_M32.hpp"
118 #include "config_HAVE_I386_CLANGVVD_M64.hpp"
119 #include "config_HAVE_I386_CLANGVVD_MX32.hpp"
120 #include "config_HAVE_I386_GCC49_COMPILER.hpp"
121 #include "config_HAVE_I386_GCC49_M32.hpp"
122 #include "config_HAVE_I386_GCC49_M64.hpp"
123 #include "config_HAVE_I386_GCC49_MX32.hpp"
124 #include "config_HAVE_I386_GCC5_COMPILER.hpp"
125 #include "config_HAVE_I386_GCC5_M32.hpp"
126 #include "config_HAVE_I386_GCC5_M64.hpp"
127 #include "config_HAVE_I386_GCC5_MX32.hpp"
128 #include "config_HAVE_I386_GCC6_COMPILER.hpp"
129 #include "config_HAVE_I386_GCC6_M32.hpp"
130 #include "config_HAVE_I386_GCC6_M64.hpp"
131 #include "config_HAVE_I386_GCC6_MX32.hpp"
132 #include "config_HAVE_I386_GCC7_COMPILER.hpp"
133 #include "config_HAVE_I386_GCC7_M32.hpp"
134 #include "config_HAVE_I386_GCC7_M64.hpp"
135 #include "config_HAVE_I386_GCC7_MX32.hpp"
136 #include "config_HAVE_I386_GCC8_COMPILER.hpp"
137 #include "config_HAVE_I386_GCC8_M32.hpp"
138 #include "config_HAVE_I386_GCC8_M64.hpp"
139 #include "config_HAVE_I386_GCC8_MX32.hpp"
140 #include "config_I386_CLANG10_ASTANALYZER_PLUGIN.hpp"
141 #include "config_I386_CLANG10_CSROA_PLUGIN.hpp"
142 #include "config_I386_CLANG10_EMPTY_PLUGIN.hpp"
143 #include "config_I386_CLANG10_EXE.hpp"
144 #include "config_I386_CLANG10_EXPANDMEMOPS_PLUGIN.hpp"
145 #include "config_I386_CLANG10_GEPICANON_PLUGIN.hpp"
146 #include "config_I386_CLANG10_SSA_PLUGIN.hpp"
147 #include "config_I386_CLANG10_SSA_PLUGINCPP.hpp"
148 #include "config_I386_CLANG10_TOPFNAME_PLUGIN.hpp"
149 #include "config_I386_CLANG10_VERSION.hpp"
150 #include "config_I386_CLANG11_ASTANALYZER_PLUGIN.hpp"
151 #include "config_I386_CLANG11_CSROA_PLUGIN.hpp"
152 #include "config_I386_CLANG11_EMPTY_PLUGIN.hpp"
153 #include "config_I386_CLANG11_EXE.hpp"
154 #include "config_I386_CLANG11_EXPANDMEMOPS_PLUGIN.hpp"
155 #include "config_I386_CLANG11_GEPICANON_PLUGIN.hpp"
156 #include "config_I386_CLANG11_SSA_PLUGIN.hpp"
157 #include "config_I386_CLANG11_SSA_PLUGINCPP.hpp"
158 #include "config_I386_CLANG11_TOPFNAME_PLUGIN.hpp"
159 #include "config_I386_CLANG11_VERSION.hpp"
160 #include "config_I386_CLANG12_ASTANALYZER_PLUGIN.hpp"
161 #include "config_I386_CLANG12_CSROA_PLUGIN.hpp"
162 #include "config_I386_CLANG12_EMPTY_PLUGIN.hpp"
163 #include "config_I386_CLANG12_EXE.hpp"
164 #include "config_I386_CLANG12_EXPANDMEMOPS_PLUGIN.hpp"
165 #include "config_I386_CLANG12_GEPICANON_PLUGIN.hpp"
166 #include "config_I386_CLANG12_SSA_PLUGIN.hpp"
167 #include "config_I386_CLANG12_SSA_PLUGINCPP.hpp"
168 #include "config_I386_CLANG12_TOPFNAME_PLUGIN.hpp"
169 #include "config_I386_CLANG12_VERSION.hpp"
170 #include "config_I386_CLANG13_ASTANALYZER_PLUGIN.hpp"
171 #include "config_I386_CLANG13_CSROA_PLUGIN.hpp"
172 #include "config_I386_CLANG13_EMPTY_PLUGIN.hpp"
173 #include "config_I386_CLANG13_EXE.hpp"
174 #include "config_I386_CLANG13_EXPANDMEMOPS_PLUGIN.hpp"
175 #include "config_I386_CLANG13_GEPICANON_PLUGIN.hpp"
176 #include "config_I386_CLANG13_SSA_PLUGIN.hpp"
177 #include "config_I386_CLANG13_SSA_PLUGINCPP.hpp"
178 #include "config_I386_CLANG13_TOPFNAME_PLUGIN.hpp"
179 #include "config_I386_CLANG13_VERSION.hpp"
180 #include "config_I386_CLANG16_ASTANALYZER_PLUGIN.hpp"
181 #include "config_I386_CLANG16_CSROA_PLUGIN.hpp"
182 #include "config_I386_CLANG16_EMPTY_PLUGIN.hpp"
183 #include "config_I386_CLANG16_EXE.hpp"
184 #include "config_I386_CLANG16_EXPANDMEMOPS_PLUGIN.hpp"
185 #include "config_I386_CLANG16_GEPICANON_PLUGIN.hpp"
186 #include "config_I386_CLANG16_SSA_PLUGIN.hpp"
187 #include "config_I386_CLANG16_SSA_PLUGINCPP.hpp"
188 #include "config_I386_CLANG16_TOPFNAME_PLUGIN.hpp"
189 #include "config_I386_CLANG16_VERSION.hpp"
190 #include "config_I386_CLANG4_ASTANALYZER_PLUGIN.hpp"
191 #include "config_I386_CLANG4_CSROA_PLUGIN.hpp"
192 #include "config_I386_CLANG4_EMPTY_PLUGIN.hpp"
193 #include "config_I386_CLANG4_EXE.hpp"
194 #include "config_I386_CLANG4_EXPANDMEMOPS_PLUGIN.hpp"
195 #include "config_I386_CLANG4_GEPICANON_PLUGIN.hpp"
196 #include "config_I386_CLANG4_SSA_PLUGIN.hpp"
197 #include "config_I386_CLANG4_SSA_PLUGINCPP.hpp"
198 #include "config_I386_CLANG4_TOPFNAME_PLUGIN.hpp"
199 #include "config_I386_CLANG4_VERSION.hpp"
200 #include "config_I386_CLANG5_ASTANALYZER_PLUGIN.hpp"
201 #include "config_I386_CLANG5_CSROA_PLUGIN.hpp"
202 #include "config_I386_CLANG5_EMPTY_PLUGIN.hpp"
203 #include "config_I386_CLANG5_EXE.hpp"
204 #include "config_I386_CLANG5_EXPANDMEMOPS_PLUGIN.hpp"
205 #include "config_I386_CLANG5_GEPICANON_PLUGIN.hpp"
206 #include "config_I386_CLANG5_SSA_PLUGIN.hpp"
207 #include "config_I386_CLANG5_SSA_PLUGINCPP.hpp"
208 #include "config_I386_CLANG5_TOPFNAME_PLUGIN.hpp"
209 #include "config_I386_CLANG5_VERSION.hpp"
210 #include "config_I386_CLANG6_ASTANALYZER_PLUGIN.hpp"
211 #include "config_I386_CLANG6_CSROA_PLUGIN.hpp"
212 #include "config_I386_CLANG6_EMPTY_PLUGIN.hpp"
213 #include "config_I386_CLANG6_EXE.hpp"
214 #include "config_I386_CLANG6_EXPANDMEMOPS_PLUGIN.hpp"
215 #include "config_I386_CLANG6_GEPICANON_PLUGIN.hpp"
216 #include "config_I386_CLANG6_SSA_PLUGIN.hpp"
217 #include "config_I386_CLANG6_SSA_PLUGINCPP.hpp"
218 #include "config_I386_CLANG6_TOPFNAME_PLUGIN.hpp"
219 #include "config_I386_CLANG6_VERSION.hpp"
220 #include "config_I386_CLANG7_ASTANALYZER_PLUGIN.hpp"
221 #include "config_I386_CLANG7_CSROA_PLUGIN.hpp"
222 #include "config_I386_CLANG7_EMPTY_PLUGIN.hpp"
223 #include "config_I386_CLANG7_EXE.hpp"
224 #include "config_I386_CLANG7_EXPANDMEMOPS_PLUGIN.hpp"
225 #include "config_I386_CLANG7_GEPICANON_PLUGIN.hpp"
226 #include "config_I386_CLANG7_SSA_PLUGIN.hpp"
227 #include "config_I386_CLANG7_SSA_PLUGINCPP.hpp"
228 #include "config_I386_CLANG7_TOPFNAME_PLUGIN.hpp"
229 #include "config_I386_CLANG7_VERSION.hpp"
230 #include "config_I386_CLANG8_ASTANALYZER_PLUGIN.hpp"
231 #include "config_I386_CLANG8_CSROA_PLUGIN.hpp"
232 #include "config_I386_CLANG8_EMPTY_PLUGIN.hpp"
233 #include "config_I386_CLANG8_EXE.hpp"
234 #include "config_I386_CLANG8_EXPANDMEMOPS_PLUGIN.hpp"
235 #include "config_I386_CLANG8_GEPICANON_PLUGIN.hpp"
236 #include "config_I386_CLANG8_SSA_PLUGIN.hpp"
237 #include "config_I386_CLANG8_SSA_PLUGINCPP.hpp"
238 #include "config_I386_CLANG8_TOPFNAME_PLUGIN.hpp"
239 #include "config_I386_CLANG8_VERSION.hpp"
240 #include "config_I386_CLANG9_ASTANALYZER_PLUGIN.hpp"
241 #include "config_I386_CLANG9_CSROA_PLUGIN.hpp"
242 #include "config_I386_CLANG9_EMPTY_PLUGIN.hpp"
243 #include "config_I386_CLANG9_EXE.hpp"
244 #include "config_I386_CLANG9_EXPANDMEMOPS_PLUGIN.hpp"
245 #include "config_I386_CLANG9_GEPICANON_PLUGIN.hpp"
246 #include "config_I386_CLANG9_SSA_PLUGIN.hpp"
247 #include "config_I386_CLANG9_SSA_PLUGINCPP.hpp"
248 #include "config_I386_CLANG9_TOPFNAME_PLUGIN.hpp"
249 #include "config_I386_CLANG9_VERSION.hpp"
250 #include "config_I386_CLANGPP10_EXE.hpp"
251 #include "config_I386_CLANGPP11_EXE.hpp"
252 #include "config_I386_CLANGPP12_EXE.hpp"
253 #include "config_I386_CLANGPP13_EXE.hpp"
254 #include "config_I386_CLANGPP16_EXE.hpp"
255 #include "config_I386_CLANGPP4_EXE.hpp"
256 #include "config_I386_CLANGPP5_EXE.hpp"
257 #include "config_I386_CLANGPP6_EXE.hpp"
258 #include "config_I386_CLANGPP7_EXE.hpp"
259 #include "config_I386_CLANGPP8_EXE.hpp"
260 #include "config_I386_CLANGPP9_EXE.hpp"
261 #include "config_I386_CLANGPPVVD_EXE.hpp"
262 #include "config_I386_CLANGVVD_ASTANALYZER_PLUGIN.hpp"
263 #include "config_I386_CLANGVVD_CSROA_PLUGIN.hpp"
264 #include "config_I386_CLANGVVD_EMPTY_PLUGIN.hpp"
265 #include "config_I386_CLANGVVD_EXE.hpp"
266 #include "config_I386_CLANGVVD_EXPANDMEMOPS_PLUGIN.hpp"
267 #include "config_I386_CLANGVVD_GEPICANON_PLUGIN.hpp"
268 #include "config_I386_CLANGVVD_SSA_PLUGIN.hpp"
269 #include "config_I386_CLANGVVD_SSA_PLUGINCPP.hpp"
270 #include "config_I386_CLANGVVD_TOPFNAME_PLUGIN.hpp"
271 #include "config_I386_CLANGVVD_VERSION.hpp"
272 #include "config_I386_CLANG_CPP10_EXE.hpp"
273 #include "config_I386_CLANG_CPP11_EXE.hpp"
274 #include "config_I386_CLANG_CPP12_EXE.hpp"
275 #include "config_I386_CLANG_CPP13_EXE.hpp"
276 #include "config_I386_CLANG_CPP16_EXE.hpp"
277 #include "config_I386_CLANG_CPP4_EXE.hpp"
278 #include "config_I386_CLANG_CPP5_EXE.hpp"
279 #include "config_I386_CLANG_CPP6_EXE.hpp"
280 #include "config_I386_CLANG_CPP7_EXE.hpp"
281 #include "config_I386_CLANG_CPP8_EXE.hpp"
282 #include "config_I386_CLANG_CPP9_EXE.hpp"
283 #include "config_I386_CLANG_CPPVVD_EXE.hpp"
284 #include "config_I386_CPP49_EXE.hpp"
285 #include "config_I386_CPP5_EXE.hpp"
286 #include "config_I386_CPP6_EXE.hpp"
287 #include "config_I386_CPP7_EXE.hpp"
288 #include "config_I386_CPP8_EXE.hpp"
289 #include "config_I386_GCC49_EMPTY_PLUGIN.hpp"
290 #include "config_I386_GCC49_EXE.hpp"
291 #include "config_I386_GCC49_SSA_PLUGIN.hpp"
292 #include "config_I386_GCC49_SSA_PLUGINCPP.hpp"
293 #include "config_I386_GCC49_TOPFNAME_PLUGIN.hpp"
294 #include "config_I386_GCC49_VERSION.hpp"
295 #include "config_I386_GCC5_EMPTY_PLUGIN.hpp"
296 #include "config_I386_GCC5_EXE.hpp"
297 #include "config_I386_GCC5_SSA_PLUGIN.hpp"
298 #include "config_I386_GCC5_SSA_PLUGINCPP.hpp"
299 #include "config_I386_GCC5_TOPFNAME_PLUGIN.hpp"
300 #include "config_I386_GCC5_VERSION.hpp"
301 #include "config_I386_GCC6_EMPTY_PLUGIN.hpp"
302 #include "config_I386_GCC6_EXE.hpp"
303 #include "config_I386_GCC6_SSA_PLUGIN.hpp"
304 #include "config_I386_GCC6_SSA_PLUGINCPP.hpp"
305 #include "config_I386_GCC6_TOPFNAME_PLUGIN.hpp"
306 #include "config_I386_GCC6_VERSION.hpp"
307 #include "config_I386_GCC7_EMPTY_PLUGIN.hpp"
308 #include "config_I386_GCC7_EXE.hpp"
309 #include "config_I386_GCC7_SSA_PLUGIN.hpp"
310 #include "config_I386_GCC7_SSA_PLUGINCPP.hpp"
311 #include "config_I386_GCC7_TOPFNAME_PLUGIN.hpp"
312 #include "config_I386_GCC7_VERSION.hpp"
313 #include "config_I386_GCC8_EMPTY_PLUGIN.hpp"
314 #include "config_I386_GCC8_EXE.hpp"
315 #include "config_I386_GCC8_SSA_PLUGIN.hpp"
316 #include "config_I386_GCC8_SSA_PLUGINCPP.hpp"
317 #include "config_I386_GCC8_TOPFNAME_PLUGIN.hpp"
318 #include "config_I386_GCC8_VERSION.hpp"
319 #include "config_I386_GPP49_EXE.hpp"
320 #include "config_I386_GPP5_EXE.hpp"
321 #include "config_I386_GPP6_EXE.hpp"
322 #include "config_I386_GPP7_EXE.hpp"
323 #include "config_I386_GPP8_EXE.hpp"
324 #include "config_I386_LLVM10_LINK_EXE.hpp"
325 #include "config_I386_LLVM10_OPT_EXE.hpp"
326 #include "config_I386_LLVM11_LINK_EXE.hpp"
327 #include "config_I386_LLVM11_OPT_EXE.hpp"
328 #include "config_I386_LLVM12_LINK_EXE.hpp"
329 #include "config_I386_LLVM12_OPT_EXE.hpp"
330 #include "config_I386_LLVM13_LINK_EXE.hpp"
331 #include "config_I386_LLVM13_OPT_EXE.hpp"
332 #include "config_I386_LLVM16_LINK_EXE.hpp"
333 #include "config_I386_LLVM16_OPT_EXE.hpp"
334 #include "config_I386_LLVM4_LINK_EXE.hpp"
335 #include "config_I386_LLVM4_OPT_EXE.hpp"
336 #include "config_I386_LLVM5_LINK_EXE.hpp"
337 #include "config_I386_LLVM5_OPT_EXE.hpp"
338 #include "config_I386_LLVM6_LINK_EXE.hpp"
339 #include "config_I386_LLVM6_OPT_EXE.hpp"
340 #include "config_I386_LLVM7_LINK_EXE.hpp"
341 #include "config_I386_LLVM7_OPT_EXE.hpp"
342 #include "config_I386_LLVM8_LINK_EXE.hpp"
343 #include "config_I386_LLVM8_OPT_EXE.hpp"
344 #include "config_I386_LLVM9_LINK_EXE.hpp"
345 #include "config_I386_LLVM9_OPT_EXE.hpp"
346 #include "config_I386_LLVMVVD_LINK_EXE.hpp"
347 #include "config_I386_LLVMVVD_OPT_EXE.hpp"
348 #include "config_NPROFILE.hpp"
349 
350 #include <cerrno>
351 #include <list>
352 #include <random>
353 #include <regex>
354 #include <string>
355 #include <unistd.h>
356 
357 enum CompilerMode : int
358 {
359  CM_EMPTY = 1 << 0, // Empty file compilation
360  CM_ANALYZER_INTERFACE = 1 << 1, // Enable frontend code analyzer plugins
361  CM_ANALYZER_OPTIMIZE = 1 << 2, // Enable frontend code optimizer plugins
362  CM_ANALYZER_ALL = 3 << 1, // Enable all frontend plugins
363  CM_OPT_INTERNALIZE = 1 << 8, // Enable symbol internalize plugin
364  CM_OPT_EXPANDMEMOPS = 1 << 9, // Enable memory operation optimizer plugin
365  CM_OPT_DUMPGIMPLE = 1 << 10, // Enable IR dump plugin
366  CM_OPT_ALL = (7 << 8), // Enable backend HLS optimization plugins
367  CM_LTO_FLAG = 1 << 16, // Enable LTO optimization flags
368  CM_COMPILER_STD = 1 << 24, // Use default compiler
369  CM_COMPILER_OPT = 1 << 25, // Use compiler optimizer
370  CM_COMPILER_LTO = 1 << 26, // Use compiler linker
371 };
372 
373 static std::string __escape_define(const std::string& str)
374 {
375  return std::regex_replace(str, std::regex("([\\(\\) ])"), "\\$1");
376 }
377 
379 
382  : Param(_Param),
383  compiler_target(_compiler_target),
384  OS(_OS),
385  output_level(_Param->getOption<int>(OPT_output_level)),
386  debug_level(_Param->get_class_debug_level("CompilerWrapper"))
387 {
389  if(Param->isOption(OPT_gcc_write_xml))
390  {
391  WriteXml(Param->getOption<std::string>(OPT_gcc_write_xml));
392  }
393 }
394 
395 // destructor
397 
398 void CompilerWrapper::CompileFile(std::string& input_filename, const std::string& output_filename,
399  const std::string& parameters_line, int cm, const std::string& costTable)
400 {
401  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Compiling " + input_filename);
402  THROW_ASSERT(cm == CM_EMPTY || (cm & ~CM_EMPTY) == cm,
403  "Empty compilation must not require any other compilation mode.");
404 
405  const auto compiler = GetCompiler();
406  const auto output_temporary_directory = Param->getOption<std::string>(OPT_output_temporary_directory);
407  const auto compiler_output_filename = output_temporary_directory + STR_CST_gcc_output;
408 
409  const auto isWholeProgram =
410  Param->isOption(OPT_gcc_optimizations) &&
411  Param->getOption<std::string>(OPT_gcc_optimizations).find("whole-program") != std::string::npos &&
412  Param->getOption<std::string>(OPT_gcc_optimizations).find("no-whole-program") == std::string::npos;
413  const auto top_fnames = [&]() -> std::string {
414  if(Param->isOption(OPT_top_functions_names))
415  {
416  auto fnames = Param->getOption<std::string>(OPT_top_functions_names);
417  boost::replace_all(fnames, STR_CST_string_separator, ",");
418  return fnames;
419  }
420  return "";
421  }();
422  THROW_ASSERT(!isWholeProgram || top_fnames == "main", "Unexpected -fwhole-program with non-main top function.");
423 
424  std::string real_filename = input_filename;
425  std::string command;
426  if(cm & CM_COMPILER_OPT)
427  {
428  THROW_ASSERT(!(cm & CM_ANALYZER_ALL), "Analyzer plugin requires compiler frontend to run");
429  command = compiler.llvm_opt;
430  }
431  else if(cm & CM_COMPILER_LTO)
432  {
433  THROW_ASSERT(cm == CM_COMPILER_LTO, "Plugins must not be enabled when linker is required");
434  command = compiler.llvm_link;
435  }
436  else
437  {
438  cm |= CM_COMPILER_STD;
439  if((cm & CM_ANALYZER_ALL) && !compiler.is_clang)
440  {
441  THROW_ASSERT(!(cm & CM_OPT_ALL), "Optimization must not be performed with analyze compiler");
442  command = GetAnalyzeCompiler();
443  }
444  else
445  {
446  command = compiler.gcc;
447  }
448  command += " -c";
449  command += " -D__NO_INLINE__";
450  command += " " + compiler.extra_options;
451 #ifdef _WIN32
452  if(compiler.is_clang || (cm & CM_ANALYZER_ALL))
453  {
454  command += " -isystem /mingw64/include -isystem /mingw64/x86_64-w64-mingw32/include -isystem "
455  "/mingw64/include/c++/v1/";
456  }
457 #endif
458 
459  if(!(Param->getOption<bool>(OPT_compute_size_of)))
460  {
461  command += " -D\"" STR_CST_panda_sizeof "(arg)=" STR_CST_string_sizeof "(#arg)\"";
462  }
463  if((Param->isOption(OPT_discrepancy) && Param->getOption<bool>(OPT_discrepancy)) ||
464  (Param->isOption(OPT_discrepancy_hw) && Param->getOption<bool>(OPT_discrepancy_hw)))
465  {
466  command += " -D__BAMBU_DISCREPANCY__";
467  }
468  }
469 
470  if(cm & CM_LTO_FLAG)
471  {
472  THROW_ASSERT(cm & CM_COMPILER_STD, "Unexpected compiler type");
473  if(compiler.is_clang)
474  {
475  command += " -flto";
476  }
477  }
478 
479  if(cm & CM_EMPTY)
480  {
481  if(input_filename == "-")
482  {
483  THROW_ERROR("Reading from standard input which does not contain any function definition");
484  }
485  static int empty_counter = 0;
486  real_filename = output_temporary_directory + "/empty_" + std::to_string(empty_counter++) + ".c";
487  CopyFile(input_filename, real_filename);
488  {
489  std::ofstream empty_file(real_filename, std::ios_base::app);
490  empty_file << "\nvoid __bambu_empty_function__(){}\n";
491  }
492  if(compiler.is_clang)
493  {
494  command += " " + load_plugin(compiler.empty_plugin_obj, compiler_target) +
495  " -mllvm -pandaGE-outputdir=" + output_temporary_directory +
496  " -mllvm -pandaGE-infile=" + real_filename;
497  }
498  else
499  {
500  command += " -fplugin=" + compiler.empty_plugin_obj + " -fplugin-arg-" + compiler.empty_plugin_name +
501  "-outputdir=" + output_temporary_directory;
502  }
503  }
504 
505  if(cm & CM_ANALYZER_ALL)
506  {
508  boost::replace_all(command, "-mlong-double-64", "");
510  {
511  boost::replace_all(command, "-fhls", "");
512  boost::replace_all(command, "-target fpga64-xilinx-linux-gnu", "");
513  }
514  command += " -fplugin=" + compiler.ASTAnalyzer_plugin_obj;
515  command += " -Xclang -add-plugin -Xclang " + compiler.ASTAnalyzer_plugin_name;
516 
517  if(cm & CM_ANALYZER_INTERFACE)
518  {
519  command += " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang -action";
520  command += " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang analyze";
521  command += " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang -outputdir";
522  command +=
523  " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang " + output_temporary_directory;
524 
525  if(Param->isOption(OPT_input_format) &&
526  (Param->getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_CPP ||
527  Param->getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_LLVM_CPP))
528  {
529  command += " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang -cppflag";
530  }
531  if(top_fnames.size())
532  {
533  command += " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang -topfname";
534  command += " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang " + top_fnames;
535  }
536  }
537  if(cm & CM_ANALYZER_OPTIMIZE)
538  {
539  command += " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang -action";
540  command += " -Xclang -plugin-arg-" + compiler.ASTAnalyzer_plugin_name + " -Xclang optimize";
541  }
542  }
543 
544  const auto load_plugin = [&](const std::string& plugin_obj) {
545  if(cm & CM_COMPILER_STD)
546  {
547  command += this->load_plugin(plugin_obj, compiler_target);
548  }
549  else
550  {
551  command += this->load_plugin_opt(plugin_obj, compiler_target);
552  }
553  };
554  const auto append_arg = [&](const std::string& arg) {
555  if(cm & CM_COMPILER_STD)
556  {
557  command += " -mllvm " + arg;
558  }
559  else
560  {
561  command += " " + arg;
562  }
563  };
564  if((cm & CM_OPT_INTERNALIZE) && top_fnames.size())
565  {
566  THROW_ASSERT(!(cm & CM_LTO_FLAG), "Internalizing symbols in partial object files is not expected");
567  if(compiler.is_clang)
568  {
569  load_plugin(compiler.topfname_plugin_obj);
570  append_arg("-internalize-outputdir=" + output_temporary_directory);
571  append_arg("-panda-TFN=" + top_fnames);
572  if(Param->getOption<HLSFlowStep_Type>(OPT_interface_type) == HLSFlowStep_Type::INFERRED_INTERFACE_GENERATION)
573  {
574  append_arg("-add-noalias");
575  }
576  const auto extern_symbols = readExternalSymbols(input_filename);
577  if(!extern_symbols.empty())
578  {
579  append_arg("-panda-ESL=" + extern_symbols);
580  }
581  if(isWholeProgram || !Param->getOption<bool>(OPT_expose_globals))
582  {
583  append_arg("-panda-Internalize");
584  }
585  if(Param->IsParameter("enable-CSROA") && Param->GetParameter<int>("enable-CSROA") == 1 &&
586  !compiler.CSROA_plugin_obj.empty() && !compiler.expandMemOps_plugin_obj.empty())
587  {
588  load_plugin(compiler.CSROA_plugin_obj);
589  append_arg("-panda-KN=" + top_fnames);
590  if(Param->IsParameter("max-CSROA"))
591  {
592  auto max_CSROA = Param->GetParameter<int>("max-CSROA");
593  append_arg("-csroa-max-transformations=" + STR(max_CSROA));
594  }
595  }
596  }
597  else
598  {
599  if(!isWholeProgram)
600  {
602  command += " -fplugin=" + compiler.topfname_plugin_obj + " -fplugin-arg-" + compiler.topfname_plugin_name +
603  "-topfname=" + top_fnames;
604  }
605  }
606  }
607  if(cm & CM_OPT_EXPANDMEMOPS)
608  {
609  if(compiler.is_clang)
610  {
611  load_plugin(compiler.expandMemOps_plugin_obj);
612  }
613  }
614  if(cm & CM_OPT_DUMPGIMPLE)
615  {
616  if(compiler.is_clang)
617  {
618  load_plugin(compiler.ssa_plugin_obj);
619  append_arg("-panda-outputdir=" + output_temporary_directory);
620  append_arg("-panda-infile=" + input_filename);
621  append_arg("-panda-cost-table=\"" + costTable + "\"");
622  if(top_fnames.size())
623  {
624  append_arg("-panda-topfname=" + top_fnames);
625  }
626  // command += " -emit-llvm";
627  }
628  else
629  {
630  command += " -fplugin=" + compiler.ssa_plugin_obj + " -fplugin-arg-" + compiler.ssa_plugin_name +
631  "-outputdir=" + output_temporary_directory;
632  }
633  }
634 
635  command += " " + parameters_line;
636 
637  const auto _output_filename = output_filename.size() ?
638  output_filename :
639  std::filesystem::path(output_temporary_directory + "/" +
640  unique_path(std::string(STR_CST_gcc_obj_file)).string())
641  .string();
642  command += " -o " + _output_filename;
643 
644  if(real_filename == "-" || real_filename == "/dev/null")
645  {
646  command += " " + real_filename;
647  }
648  else
649  {
650  const auto srcs = string_to_container<std::vector<std::string>>(real_filename, STR_CST_string_separator);
651  for(const auto& src : srcs)
652  {
653  const auto extension = std::filesystem::path(src).extension().string();
655  if(extension == ".S")
656  {
657  command += "-x c ";
658  }
659  command += " \"" + src + "\"";
660  }
661  }
662 
663  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "---Invoke: " + command);
664 #if !NPROFILE
665  long int gcc_compilation_time = 0;
667  {
668  START_TIME(gcc_compilation_time);
669  }
670 #endif
671  int ret = PandaSystem(Param, command, false, compiler_output_filename);
672 #if !NPROFILE
674  {
675  STOP_TIME(gcc_compilation_time);
676  dump_exec_time("Compilation time", gcc_compilation_time);
677  }
678 #endif
679 
680  if(output_filename.empty())
681  {
682  std::remove(_output_filename.c_str());
683  }
684  if(IsError(ret))
685  {
686  PRINT_OUT_MEX(OUTPUT_LEVEL_NONE, 0, "Error in compilation");
687  if(std::filesystem::exists(std::filesystem::path(compiler_output_filename)))
688  {
689  CopyStdout(compiler_output_filename);
691  "Front-end compiler returns an error during compilation " + std::to_string(errno));
692  THROW_ERROR("Front-end compiler returns an error during compilation " + std::to_string(errno));
693  }
694  else
695  {
696  THROW_ERROR("Error in front-end compiler invocation");
697  }
698  }
699  else
700  {
702  {
703  CopyStdout(compiler_output_filename);
704  }
705  }
706  input_filename = real_filename;
708 }
709 
710 void CompilerWrapper::FillTreeManager(const tree_managerRef TM, std::vector<std::string>& source_files,
711  const std::string& costTable)
712 {
713  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Invoking front-end compiler");
715  if(source_files.size() == 0)
716  {
717  THROW_ERROR("No files specified for parsing");
718  }
719 
720  const auto compiler = GetCompiler();
721  const auto multi_source = source_files.size() > 1;
722  const auto enable_LTO = (compiler.is_clang && multi_source);
723  const auto compile_only = Param->isOption(OPT_gcc_S) && Param->getOption<bool>(OPT_gcc_S);
724  const auto preprocess_only = Param->isOption(OPT_gcc_E) && Param->getOption<bool>(OPT_gcc_E);
725  const auto optimization_set = Param->getOption<CompilerWrapper_OptimizationSet>(OPT_compiler_opt_level);
726  const auto output_temporary_directory = Param->getOption<std::string>(OPT_output_temporary_directory);
727 
729  if(optimization_set == CompilerWrapper_OptimizationSet::O3 ||
730  optimization_set == CompilerWrapper_OptimizationSet::O4 ||
731  optimization_set == CompilerWrapper_OptimizationSet::O5)
732  {
733  if((optimization_flags.find("tree-vectorize") == optimization_flags.end() ||
734  optimization_flags.find("tree-vectorize")->second) ||
735  (optimization_flags.find("vectorize") == optimization_flags.end() ||
736  optimization_flags.find("vectorize")->second) ||
737  (optimization_flags.find("slp-vectorize") == optimization_flags.end() ||
738  optimization_flags.find("slp-vectorize")->second))
739  {
740  if(Param->isOption(OPT_aligned_access) && Param->getOption<bool>(OPT_aligned_access))
741  {
742  THROW_ERROR("Option --aligned-access cannot be used with -O3 or vectorization");
743  }
744  }
745  }
746 
747 #if HAVE_I386_CLANG4_COMPILER || HAVE_I386_CLANG5_COMPILER || HAVE_I386_CLANG6_COMPILER || \
748  HAVE_I386_CLANG7_COMPILER || HAVE_I386_CLANG8_COMPILER || HAVE_I386_CLANG9_COMPILER || \
749  HAVE_I386_CLANG10_COMPILER || HAVE_I386_CLANG11_COMPILER || HAVE_I386_CLANG12_COMPILER || \
750  HAVE_I386_CLANG13_COMPILER || HAVE_I386_CLANG16_COMPILER || HAVE_I386_CLANGVVD_COMPILER
751  if(Param->IsParameter("disable-pragma-parsing") && Param->GetParameter<int>("disable-pragma-parsing") == 1)
752  {
753  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "Pragma analysis disabled");
754  }
755  else if(!compiler.is_clang)
756  {
757  std::string analyzing_compiling_parameters;
758  if(Param->isOption(OPT_gcc_standard))
759  {
760  analyzing_compiling_parameters += " --std=" + Param->getOption<std::string>(OPT_gcc_standard);
761  }
762  if(Param->isOption(OPT_gcc_defines))
763  {
764  const auto defines = Param->getOption<std::list<std::string>>(OPT_gcc_defines);
765  for(const auto& define : defines)
766  {
767  analyzing_compiling_parameters += " -D" + __escape_define(define);
768  }
769  }
770  if(Param->isOption(OPT_gcc_undefines))
771  {
772  const auto undefines = Param->getOption<std::list<std::string>>(OPT_gcc_undefines);
773  for(const auto& undefine : undefines)
774  {
775  analyzing_compiling_parameters += " -U" + __escape_define(undefine);
776  }
777  }
778  if(Param->isOption(OPT_gcc_warnings))
779  {
780  const auto warnings = Param->getOption<std::list<std::string>>(OPT_gcc_warnings);
781  for(const auto& warning : warnings)
782  {
783  if(!warning.empty())
784  {
785  analyzing_compiling_parameters += " -W" + warning;
786  }
787  }
788  }
789  if(Param->isOption(OPT_gcc_includes))
790  {
791  analyzing_compiling_parameters += " " + Param->getOption<std::string>(OPT_gcc_includes);
792  }
793  for(auto& source_file : source_files)
794  {
795  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Analyze file " + source_file);
796  CompileFile(source_file, "", analyzing_compiling_parameters, CM_ANALYZER_INTERFACE, costTable);
797  }
798  }
799 #else
800  THROW_WARNING("Pragma analysis is not available without Clang/LLVM compiler");
801 #endif
802 
803  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Starting compilation of single files");
804  const auto compiler_mode = [&]() -> int {
805  int flags = CM_COMPILER_STD;
806  if(preprocess_only || compile_only)
807  {
808  return flags;
809  }
810  if(compiler.is_clang)
811  {
812  flags |= CM_ANALYZER_ALL;
813  }
814  if(multi_source)
815  {
816  flags |= CM_LTO_FLAG;
817  if(!enable_LTO)
818  {
819  flags |= CM_OPT_DUMPGIMPLE;
820  }
821  }
822  else
823  {
824  flags |= CM_OPT_ALL;
825  }
826  return flags;
827  }();
828  std::list<std::string> obj_files;
829  THROW_ASSERT(!multi_source || !(compile_only || preprocess_only), "");
830  for(auto& source_file : source_files)
831  {
832  const auto leaf_name = source_file == "-" ? "stdin-" : std::filesystem::path(source_file).filename().string();
833  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Compiling file " + source_file);
834  const auto obj_file = ((compile_only || preprocess_only) && Param->isOption(OPT_output_file)) ?
835  Param->getOption<std::string>(OPT_output_file) :
836  unique_path(output_temporary_directory + "/" + leaf_name + ".%%%%%%.o").string();
837  CompileFile(source_file, obj_file, frontend_compiler_parameters, compiler_mode, costTable);
838  if(enable_LTO)
839  {
840  obj_files.push_back(obj_file);
841  }
842  else if(!(compile_only || preprocess_only))
843  {
844  auto gimple_file = output_temporary_directory + "/" + leaf_name + STR_CST_bambu_ir_suffix;
845  if(!std::filesystem::exists(gimple_file))
846  {
847  CompileFile(source_file, "", frontend_compiler_parameters, CM_EMPTY, costTable);
848  // source_file has been changed by previous call to CompileFile
849  gimple_file = output_temporary_directory + "/" + std::filesystem::path(source_file).filename().string() +
851  }
852  obj_files.push_back(gimple_file);
853  }
854  }
855 
856  if(enable_LTO)
857  {
858  const auto leaf_name = std::filesystem::path(source_files.front()).filename().string();
859  const auto ext_symbols_filename = output_temporary_directory + "external-symbols.txt";
860  std::string lto_source = container_to_string(obj_files, STR_CST_string_separator);
861  std::string lto_obj = output_temporary_directory + "/" + leaf_name + ".lto.bc";
862  CompileFile(lto_source, lto_obj, "", CM_COMPILER_LTO, "");
863 
864  lto_source = lto_obj;
865  lto_obj = output_temporary_directory + "/" + leaf_name + ".lto-opt.bc";
866  std::string opt_command = add_plugin_prefix(compiler_target, "1");
867 
868  CompileFile(lto_source, lto_obj, opt_command, CM_COMPILER_OPT | CM_OPT_INTERNALIZE, costTable);
869 
870  lto_source = lto_obj;
871  lto_obj = output_temporary_directory + "/" + leaf_name + ".lto-dump.bc";
872  THROW_ASSERT(std::filesystem::exists(ext_symbols_filename), "File not found: " + ext_symbols_filename);
873  const auto plugin_prefix = add_plugin_prefix(compiler_target);
874  opt_command = " -panda-infile=" + container_to_string(source_files, ",") +
875  " --internalize-public-api-file=" + ext_symbols_filename + " " + plugin_prefix + "internalize " +
876  clang_recipes(optimization_set, "") + plugin_prefix + compiler.ssa_plugin_name;
877  CompileFile(lto_source, lto_obj, opt_command, CM_COMPILER_OPT | CM_OPT_DUMPGIMPLE, costTable);
878 
879  const auto gimple_obj = output_temporary_directory + "/" + leaf_name + STR_CST_bambu_ir_suffix;
880  if(!std::filesystem::exists(gimple_obj))
881  {
882  THROW_ERROR("Object file not found: " + gimple_obj);
883  }
884  tree_managerRef TreeM = ParseTreeFile(Param, gimple_obj);
885 #if !NPROFILE
886  long int merge_time = 0;
887  START_TIME(merge_time);
888 #endif
889  TM->merge_tree_managers(TreeM);
890 #if !NPROFILE
891  STOP_TIME(merge_time);
893  {
894  dump_exec_time("Tree merging time", merge_time);
895  }
896 #endif
897  }
898  else if(!Param->isOption(OPT_gcc_E) && !Param->isOption(OPT_gcc_S))
899  {
900  for(const auto& obj_file : obj_files)
901  {
902  if(!std::filesystem::exists(obj_file))
903  {
904  THROW_ERROR("Object file not found: " + obj_file);
905  }
906  tree_managerRef TreeM = ParseTreeFile(Param, obj_file);
907 
908 #if !NPROFILE
909  long int merge_time = 0;
910  START_TIME(merge_time);
911 #endif
912  TM->merge_tree_managers(TreeM);
913 #if !NPROFILE
914  STOP_TIME(merge_time);
916  {
917  dump_exec_time("Tree merging time", merge_time);
918  }
919 #endif
920  }
921  }
922  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Ended compilation of single files");
924  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Front-end compiler finished");
925 }
926 
928 {
929  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Initializing gcc parameters");
930  CompilerWrapper_OptimizationSet optimization_set = OS;
931 
932  if(Param->isOption(OPT_gcc_read_xml))
933  {
934  ReadXml(Param->getOption<std::string>(OPT_gcc_read_xml));
935  }
936  else
937  {
938  switch(optimization_set)
939  {
950  frontend_compiler_parameters += (" -O" + WriteOptimizationLevel(optimization_set) + " ");
951  break;
953  frontend_compiler_parameters += (" -O3 -finline-limit=10000 --param inline-unit-growth=100000 ");
954  break;
958 
959  switch(OS)
960  {
962  SetBambuDefault();
963  break;
975  {
976  THROW_UNREACHABLE("Unsupported optimization level " + WriteOptimizationLevel(OS));
977  break;
978  }
979  default:
980  {
981  THROW_UNREACHABLE("");
982  }
983  }
984  ReadParameters();
985 
986 #if HAVE_I386_CLANG4_COMPILER || HAVE_I386_CLANG5_COMPILER || HAVE_I386_CLANG6_COMPILER || \
987  HAVE_I386_CLANG7_COMPILER || HAVE_I386_CLANG8_COMPILER || HAVE_I386_CLANG9_COMPILER || \
988  HAVE_I386_CLANG10_COMPILER || HAVE_I386_CLANG11_COMPILER || HAVE_I386_CLANG12_COMPILER || \
989  HAVE_I386_CLANG13_COMPILER || HAVE_I386_CLANG16_COMPILER || HAVE_I386_CLANGVVD_COMPILER
990  {
992  Param->getOption<CompilerWrapper_CompilerTarget>(OPT_default_compiler);
993 
994  if(isClangCheck(compiler))
995  {
997  if(optimization_flags.find("tree-dominator-opts") != optimization_flags.end())
998  {
999  optimization_flags.erase(optimization_flags.find("tree-dominator-opts"));
1000  }
1001  if(optimization_flags.find("tree-pre") != optimization_flags.end())
1002  {
1003  optimization_flags.erase(optimization_flags.find("tree-pre"));
1004  }
1005  if(optimization_flags.find("tree-pre") != optimization_flags.end())
1006  {
1007  optimization_flags.erase(optimization_flags.find("tree-pre"));
1008  }
1009  if(optimization_flags.find("ipa-cp-clone") != optimization_flags.end())
1010  {
1011  optimization_flags.erase(optimization_flags.find("ipa-cp-clone"));
1012  }
1013  if(optimization_flags.find("ipa-cp") != optimization_flags.end())
1014  {
1015  optimization_flags.erase(optimization_flags.find("ipa-cp"));
1016  }
1017  }
1018  }
1019 #endif
1020 
1022 
1023  break;
1024  default:
1025  {
1026  THROW_UNREACHABLE("Unexpected optimization level");
1027  }
1028  }
1029  }
1030 
1032  if(Param->isOption(OPT_gcc_standard))
1033  {
1034  auto standard = Param->getOption<std::string>(OPT_gcc_standard);
1035  frontend_compiler_parameters += "--std=" + standard + " ";
1036  }
1037 
1038  if(Param->isOption(OPT_gcc_E) && Param->getOption<bool>(OPT_gcc_E))
1039  {
1041  }
1042  if(Param->isOption(OPT_gcc_S) && Param->getOption<bool>(OPT_gcc_S))
1043  {
1045  }
1047  if(Param->isOption(OPT_gcc_defines))
1048  {
1049  const auto defines = Param->getOption<CustomSet<std::string>>(OPT_gcc_defines);
1050  for(const auto& define : defines)
1051  {
1052  frontend_compiler_parameters += "-D" + __escape_define(define) + " ";
1053  }
1054  }
1055 
1057  if(Param->isOption(OPT_gcc_undefines))
1058  {
1059  const auto undefines = Param->getOption<CustomSet<std::string>>(OPT_gcc_undefines);
1060  for(const auto& undefine : undefines)
1061  {
1062  frontend_compiler_parameters += "-U" + __escape_define(undefine) + " ";
1063  }
1064  }
1065 
1067  if(Param->isOption(OPT_gcc_warnings))
1068  {
1069  const auto warnings = Param->getOption<CustomSet<std::string>>(OPT_gcc_warnings);
1070  for(const auto& warning : warnings)
1071  {
1072  if(!warning.empty())
1073  {
1074  frontend_compiler_parameters += "-W" + warning + " ";
1075  }
1076  }
1077  }
1079  {
1080  frontend_compiler_parameters += "-Wuninitialized ";
1081  }
1082 
1084  if(Param->isOption(OPT_gcc_includes))
1085  {
1086  frontend_compiler_parameters += Param->getOption<std::string>(OPT_gcc_includes) + " ";
1087  }
1088 
1090  if(Param->isOption(OPT_gcc_libraries))
1091  {
1092  const auto libraries = Param->getOption<CustomSet<std::string>>(OPT_gcc_libraries);
1093  for(const auto& library : libraries)
1094  {
1095  compiler_linking_parameters += "-l" + library + " ";
1096  }
1097  }
1098 
1100  if(Param->isOption(OPT_gcc_library_directories))
1101  {
1102  const auto library_directories = Param->getOption<CustomSet<std::string>>(OPT_gcc_library_directories);
1103  for(const auto& library_directory : library_directories)
1104  {
1105  compiler_linking_parameters += "-L" + library_directory + " ";
1106  }
1107  }
1108  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Initialized gcc parameters");
1109 }
1110 
1112 {
1113  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "-->Setting parameters for Bambu tool...");
1115  Param->getOption<CompilerWrapper_OptimizationSet>(OPT_compiler_opt_level);
1116  CompilerWrapper_CompilerTarget compiler = Param->getOption<CompilerWrapper_CompilerTarget>(OPT_default_compiler);
1117  bool is_clang = false;
1118 
1120  optimization_flags["wrapv"] = true;
1121 
1125  {
1126  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "<--Set parameters for bambu tool");
1127  is_clang = true;
1128  optimization_flags["builtin-memset"] = false;
1129  optimization_flags["builtin-memcpy"] = false;
1130  optimization_flags["builtin-memmove"] = false;
1133  {
1134  optimization_flags["unroll-loops"] =
1135  false; // it is preferable to have unrolling disabled by default as with GCC
1136  }
1137  return;
1138  }
1141  {
1142  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "<--Set parameters for bambu tool");
1143  is_clang = true;
1144  optimization_flags["builtin-memset"] = false;
1145  optimization_flags["builtin-memcpy"] = false;
1146  optimization_flags["builtin-memmove"] = false;
1147  return;
1148  }
1155  {
1156  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "<--Set parameters for bambu tool");
1157  is_clang = true;
1158  optimization_flags["builtin-memset"] = false;
1159  optimization_flags["builtin-memcpy"] = false;
1160  optimization_flags["builtin-memmove"] = false;
1161  optimization_flags["builtin-bcmp"] = false;
1163  {
1164  optimization_flags["fp-contract"] = false;
1165  }
1166  return;
1167  }
1169  {
1170  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "<--Set parameters for bambu tool");
1171  is_clang = true;
1172  optimization_flags["builtin-memset"] = false;
1173  optimization_flags["builtin-memcpy"] = false;
1174  optimization_flags["builtin-memmove"] = false;
1175  optimization_flags["builtin-bcmp"] = false;
1176  optimization_flags["hls"] = true;
1177  return;
1178  }
1179 
1180  if(!is_clang)
1181  {
1183  // optimization_flags["builtin"] = false;
1184  // optimization_flags["ipa-type-escape"] = true; /// no more supported starting from gcc 4.6.1
1185  optimization_flags["tree-copy-prop"] =
1186  true;
1187  optimization_flags["ipa-pta"] = true;
1189  }
1190 
1196  {
1197  optimization_flags["tree-loop-if-convert"] = true;
1198  optimization_flags["tree-loop-if-convert-stores"] = true;
1199  optimization_flags["tree-loop-distribute-patterns"] = false;
1200  optimization_flags["partial-inlining"] = false;
1201  }
1202  if(isGccCheck(compiler))
1203  {
1204  if(Param->getOption<HLSFlowStep_Type>(OPT_interface_type) == HLSFlowStep_Type::INFERRED_INTERFACE_GENERATION)
1205  {
1206  optimization_flags["tree-vectorize"] = false;
1207  }
1208  }
1209 
1214  {
1215  optimization_flags["tree-builtin-call-dce"] = false;
1216  optimization_flags["ivopts"] = false;
1217  optimization_flags["ipa-icf"] = false;
1218  }
1219  if(opt_level == CompilerWrapper_OptimizationSet::O4)
1220  {
1221  optimization_flags["ivopts"] = true;
1222  optimization_flags["tree-loop-ivcanon"] = true;
1223  optimization_flags["tree-loop-im"] = true;
1224  optimization_flags["vect-cost-model"] = false;
1225  optimization_flags["fast-math"] = true;
1226  }
1228  {
1230  {
1231  optimization_flags["tree-loop-linear"] = true;
1232  optimization_flags["graphite-identity"] = true;
1233  }
1234  }
1236  // optimization_values["tree-parallelize-loops"]=1;///requires tree-loop-optimize
1243  {
1244  parameter_values["tree-reassoc-width"] =
1245  128; // Set the maximum number of instructions executed in parallel in reassociated tree.
1246  }
1252  {
1253  parameter_values["max-completely-peeled-insns"] = 250; // Set the maximum number of insns of a peeled loop.
1254  }
1255 
1256  if(Param->getOption<bool>(OPT_parse_pragma))
1257  {
1259  optimization_flags["tree-ch"] = false;
1260  }
1261 
1262  if(Param->getOption<int>(OPT_gcc_openmp_simd) && !is_clang)
1263  {
1265  optimization_flags["tree-pre"] = false;
1266  optimization_flags["tree-vrp"] = false;
1267  optimization_flags["ivopts"] = false;
1268  optimization_flags["tree-dominator-opts"] = false;
1269  }
1270 
1271  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "<--Set parameters for bambu tool");
1272 }
1273 
1275 {
1276  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "-->Setting front-end compiler defaults");
1277  const auto optimization_set = Param->getOption<CompilerWrapper_OptimizationSet>(OPT_compiler_opt_level);
1278  optimization_flags["stack-protector"] =
1279  false; // In Ubuntu 6.10 and later versions this option is enabled by default for C, C++, ObjC, ObjC++
1280 
1281  switch(optimization_set)
1282  {
1292  {
1293  frontend_compiler_parameters += (" -O" + WriteOptimizationLevel(optimization_set) + " ");
1294  break;
1295  }
1297  frontend_compiler_parameters += (" -O3 -finline-limit=10000");
1298  break;
1300  {
1301  frontend_compiler_parameters += " -O1 ";
1302 
1304  {
1305  optimization_flags["auto-inc-dec"] = false;
1306  optimization_flags["cprop-registers"] = false;
1307  optimization_flags["dce"] = false;
1308  optimization_flags["defer-pop"] = false;
1309  optimization_flags["delayed-branch"] = false;
1310  optimization_flags["dse"] = false;
1311  optimization_flags["guess-branch-probability"] = false;
1312  optimization_flags["if-conversion"] = false;
1313  optimization_flags["if-conversion2"] = false;
1314  optimization_flags["ipa-pure-const"] = false;
1315  optimization_flags["ipa-reference"] = false;
1316  optimization_flags["merge-constants"] = false;
1317  optimization_flags["split-wide-types"] = false;
1318  optimization_flags["tree-builtin-call-dce"] = false;
1319  optimization_flags["tree-ccp"] = false;
1320  optimization_flags["tree-ch"] = false;
1321  optimization_flags["tree-dce"] = false;
1322  optimization_flags["tree-dominator-opts"] = false;
1323  optimization_flags["tree-dse"] = false;
1324  optimization_flags["tree-forwprop"] = false;
1325  optimization_flags["tree-fre"] = false;
1326  optimization_flags["tree-phiprop"] = false;
1327  optimization_flags["tree-pta"] = false;
1328  optimization_flags["tree-sra"] = false;
1329  optimization_flags["tree-ter"] = false;
1334  switch(compiler_target)
1336  {
1338  {
1339  optimization_flags["compare-elim"] = false;
1340  optimization_flags["ipa-profile"] = false;
1341  optimization_flags["tree-bit-ccp"] = false;
1342  optimization_flags["tree-copy-prop"] = false;
1343  optimization_flags["tree-copyrename"] = false;
1344  optimization_flags["tree-slsr"] = false;
1345  break;
1346  }
1348  {
1349  optimization_flags["compare-elim"] = false;
1350  optimization_flags["ipa-profile"] = false;
1351  optimization_flags["tree-bit-ccp"] = false;
1352  optimization_flags["tree-copy-prop"] = false;
1353  optimization_flags["tree-copyrename"] = false;
1354  optimization_flags["tree-slsr"] = false;
1355  break;
1356  }
1358  {
1359  optimization_flags["compare-elim"] = false;
1360  optimization_flags["ipa-profile"] = false;
1361  optimization_flags["tree-bit-ccp"] = false;
1362  optimization_flags["tree-copy-prop"] = false;
1363  optimization_flags["tree-copyrename"] = false;
1364  optimization_flags["tree-slsr"] = false;
1365  break;
1366  }
1368  {
1369  optimization_flags["compare-elim"] = false;
1370  optimization_flags["ipa-profile"] = false;
1371  optimization_flags["tree-bit-ccp"] = false;
1372  optimization_flags["tree-copy-prop"] = false;
1373  optimization_flags["tree-copyrename"] = false;
1374  optimization_flags["tree-slsr"] = false;
1375  break;
1376  }
1378  {
1379  optimization_flags["compare-elim"] = false;
1380  optimization_flags["ipa-profile"] = false;
1381  optimization_flags["tree-bit-ccp"] = false;
1382  optimization_flags["tree-copy-prop"] = false;
1383  optimization_flags["tree-copyrename"] = false;
1384  optimization_flags["tree-slsr"] = false;
1385  break;
1386  }
1388  {
1389  break;
1390  }
1392  {
1393  break;
1394  }
1396  {
1397  break;
1398  }
1400  {
1401  break;
1402  }
1404  {
1405  break;
1406  }
1408  {
1409  break;
1410  }
1412  {
1413  break;
1414  }
1416  {
1417  break;
1418  }
1420  {
1421  break;
1422  }
1424  {
1425  break;
1426  }
1428  {
1429  break;
1430  }
1432  {
1433  break;
1434  }
1436  {
1437  THROW_UNREACHABLE("Unexpected gcc target");
1438  break;
1439  }
1440  default:
1441  {
1442  THROW_UNREACHABLE("");
1443  }
1444  }
1445  }
1446  break;
1447  }
1449  {
1450  THROW_UNREACHABLE("Unepected optimization level: " + WriteOptimizationLevel(optimization_set));
1451  break;
1452  }
1453  default:
1454  {
1455  THROW_UNREACHABLE("");
1456  }
1457  }
1460  {
1461  optimization_flags["ipa-pure-const"] = true;
1462  optimization_flags["tree-dce"] = true;
1463  }
1464  else
1465  {
1466  optimization_flags["vectorize"] = false;
1467  optimization_flags["slp-vectorize"] = false;
1468  }
1469 
1470  const auto flag_cpp =
1471  Param->isOption(OPT_input_format) &&
1472  (Param->getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_CPP ||
1473  Param->getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_LLVM_CPP);
1475  if(flag_cpp)
1476  {
1477  optimization_flags["exceptions"] = false;
1478  optimization_flags["threadsafe-statics"] = false;
1479  optimization_flags["use-cxa-atexit"] = false;
1480  }
1481 
1482  INDENT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "<--Set front-end compiler defaults");
1483 }
1484 
1486 {
1487  Compiler compiler;
1488 #ifndef NDEBUG
1489  CompilerWrapper_CompilerTarget compatible_compilers =
1490  Param->getOption<CompilerWrapper_CompilerTarget>(OPT_compatible_compilers);
1491 #endif
1492 
1493  const auto flag_cpp =
1494  Param->isOption(OPT_input_format) &&
1495  (Param->getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_CPP ||
1496  Param->getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_LLVM_CPP);
1497 
1498  std::string gcc_extra_options;
1499  if(Param->isOption(OPT_gcc_extra_options))
1500  {
1501  gcc_extra_options = Param->getOption<std::string>(OPT_gcc_extra_options);
1502  }
1503 
1504  CompilerWrapper_CompilerTarget preferred_compiler;
1506  {
1507  preferred_compiler = Param->getOption<CompilerWrapper_CompilerTarget>(OPT_default_compiler);
1508  }
1509  else
1510  {
1511 #ifndef NDEBUG
1512  const bool debug_condition = static_cast<int>(compiler_target) & static_cast<int>(compatible_compilers);
1513  THROW_ASSERT(debug_condition,
1514  "Required compiler is not among the compatible one: " + STR(static_cast<int>(compiler_target)) +
1515  " vs " + STR(static_cast<int>(compatible_compilers)));
1516 #endif
1517  preferred_compiler = compiler_target;
1518  }
1519  const std::string gcc_plugin_dir =
1520  (Param->isOption(OPT_gcc_plugindir) ? Param->getOption<std::string>(OPT_gcc_plugindir) :
1521  relocate_compiler_path(GCC_PLUGIN_DIR)) +
1522  "/";
1523  const std::string clang_plugin_dir =
1524  (Param->isOption(OPT_gcc_plugindir) ? Param->getOption<std::string>(OPT_gcc_plugindir) + "/../clang_plugin" :
1525  relocate_compiler_path(CLANG_PLUGIN_DIR)) +
1526  "/";
1527  const std::string plugin_ext = ".so";
1528 
1529 #if HAVE_I386_GCC49_COMPILER || HAVE_I386_GCC5_COMPILER || HAVE_I386_GCC6_COMPILER || HAVE_I386_GCC7_COMPILER || \
1530  HAVE_I386_GCC8_COMPILER
1531  auto fillASTAnalyzer_plugin = [&] {
1532 #if HAVE_I386_CLANG16_COMPILER
1533  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG16_ASTANALYZER_PLUGIN + plugin_ext;
1534  compiler.ASTAnalyzer_plugin_name = I386_CLANG16_ASTANALYZER_PLUGIN;
1535 #elif HAVE_I386_CLANG13_COMPILER
1536  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG13_ASTANALYZER_PLUGIN + plugin_ext;
1537  compiler.ASTAnalyzer_plugin_name = I386_CLANG13_ASTANALYZER_PLUGIN;
1538 #elif HAVE_I386_CLANG12_COMPILER
1539  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG12_ASTANALYZER_PLUGIN + plugin_ext;
1540  compiler.ASTAnalyzer_plugin_name = I386_CLANG12_ASTANALYZER_PLUGIN;
1541 #elif HAVE_I386_CLANG11_COMPILER
1542  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG11_ASTANALYZER_PLUGIN + plugin_ext;
1543  compiler.ASTAnalyzer_plugin_name = I386_CLANG11_ASTANALYZER_PLUGIN;
1544 #elif HAVE_I386_CLANG10_COMPILER
1545  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG10_ASTANALYZER_PLUGIN + plugin_ext;
1546  compiler.ASTAnalyzer_plugin_name = I386_CLANG10_ASTANALYZER_PLUGIN;
1547 #elif HAVE_I386_CLANG9_COMPILER
1548  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG9_ASTANALYZER_PLUGIN + plugin_ext;
1549  compiler.ASTAnalyzer_plugin_name = I386_CLANG9_ASTANALYZER_PLUGIN;
1550 #elif HAVE_I386_CLANG8_COMPILER
1551  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG8_ASTANALYZER_PLUGIN + plugin_ext;
1552  compiler.ASTAnalyzer_plugin_name = I386_CLANG8_ASTANALYZER_PLUGIN;
1553 #elif HAVE_I386_CLANG7_COMPILER
1554  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG7_ASTANALYZER_PLUGIN + plugin_ext;
1555  compiler.ASTAnalyzer_plugin_name = I386_CLANG7_ASTANALYZER_PLUGIN;
1556 #elif HAVE_I386_CLANG6_COMPILER
1557  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG6_ASTANALYZER_PLUGIN + plugin_ext;
1558  compiler.ASTAnalyzer_plugin_name = I386_CLANG6_ASTANALYZER_PLUGIN;
1559 #elif HAVE_I386_CLANG5_COMPILER
1560  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG5_ASTANALYZER_PLUGIN + plugin_ext;
1561  compiler.ASTAnalyzer_plugin_name = I386_CLANG5_ASTANALYZER_PLUGIN;
1562 #elif HAVE_I386_CLANG4_COMPILER
1563  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG4_ASTANALYZER_PLUGIN + plugin_ext;
1564  compiler.ASTAnalyzer_plugin_name = I386_CLANG4_ASTANALYZER_PLUGIN;
1565 #elif HAVE_I386_CLANGVVD_COMPILER
1566  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANGVVD_ASTANALYZER_PLUGIN + plugin_ext;
1567  compiler.ASTAnalyzer_plugin_name = I386_CLANG4_ASTANALYZER_PLUGIN;
1568 #endif
1569  };
1570 #endif
1571 #if HAVE_I386_GCC49_COMPILER
1572  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC49))
1573  {
1574  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_GPP49_EXE) : relocate_compiler_path(I386_GCC49_EXE);
1575  compiler.cpp = relocate_compiler_path(I386_CPP49_EXE);
1576  compiler.extra_options = " -mlong-double-64 -D_FORTIFY_SOURCE=0 " + gcc_extra_options;
1577  if(optimization_flags.find("tree-vectorize") != optimization_flags.end() &&
1578  optimization_flags.find("tree-vectorize")->second)
1579  {
1580 #if HAVE_I386_GCC49_MX32
1581  compiler.extra_options += " -mx32";
1582 #else
1583  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1584 #endif
1585  compiler.extra_options += " -msse2 -mfpmath=sse";
1586  }
1587  else
1588  {
1589  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1590  }
1591  compiler.empty_plugin_obj = gcc_plugin_dir + I386_GCC49_EMPTY_PLUGIN + plugin_ext;
1592  compiler.empty_plugin_name = I386_GCC49_EMPTY_PLUGIN;
1593  compiler.ssa_plugin_obj =
1594  gcc_plugin_dir + (flag_cpp ? I386_GCC49_SSA_PLUGINCPP : I386_GCC49_SSA_PLUGIN) + plugin_ext;
1595  compiler.ssa_plugin_name = (flag_cpp ? I386_GCC49_SSA_PLUGINCPP : I386_GCC49_SSA_PLUGIN);
1596  compiler.topfname_plugin_obj = gcc_plugin_dir + I386_GCC49_TOPFNAME_PLUGIN + plugin_ext;
1597  compiler.topfname_plugin_name = I386_GCC49_TOPFNAME_PLUGIN;
1598  fillASTAnalyzer_plugin();
1599  }
1600 #endif
1601 #if HAVE_I386_GCC5_COMPILER
1602  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC5))
1603  {
1604  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_GPP5_EXE) : relocate_compiler_path(I386_GCC5_EXE);
1605  compiler.cpp = relocate_compiler_path(I386_CPP5_EXE);
1606  compiler.extra_options = " -mlong-double-64 -D_FORTIFY_SOURCE=0 " + gcc_extra_options;
1607  if(optimization_flags.find("tree-vectorize") != optimization_flags.end() &&
1608  optimization_flags.find("tree-vectorize")->second)
1609  {
1610 #if HAVE_I386_GCC5_MX32
1611  compiler.extra_options += " -mx32";
1612 #else
1613  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1614 #endif
1615  compiler.extra_options += " -msse2 -mfpmath=sse";
1616  }
1617  else
1618  {
1619  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1620  }
1621  compiler.empty_plugin_obj = gcc_plugin_dir + I386_GCC5_EMPTY_PLUGIN + plugin_ext;
1622  compiler.empty_plugin_name = I386_GCC5_EMPTY_PLUGIN;
1623  compiler.ssa_plugin_obj =
1624  gcc_plugin_dir + (flag_cpp ? I386_GCC5_SSA_PLUGINCPP : I386_GCC5_SSA_PLUGIN) + plugin_ext;
1625  compiler.ssa_plugin_name = (flag_cpp ? I386_GCC5_SSA_PLUGINCPP : I386_GCC5_SSA_PLUGIN);
1626  compiler.topfname_plugin_obj = gcc_plugin_dir + I386_GCC5_TOPFNAME_PLUGIN + plugin_ext;
1627  compiler.topfname_plugin_name = I386_GCC5_TOPFNAME_PLUGIN;
1628  fillASTAnalyzer_plugin();
1629  }
1630 #endif
1631 
1632 #if HAVE_I386_GCC6_COMPILER
1633  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC6))
1634  {
1635  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_GPP6_EXE) : relocate_compiler_path(I386_GCC6_EXE);
1636  compiler.cpp = relocate_compiler_path(I386_CPP6_EXE);
1637  compiler.extra_options = " -mlong-double-64 -D_FORTIFY_SOURCE=0 " + gcc_extra_options;
1638  if(optimization_flags.find("tree-vectorize") != optimization_flags.end() &&
1639  optimization_flags.find("tree-vectorize")->second)
1640  {
1641 #if HAVE_I386_GCC6_MX32
1642  compiler.extra_options += " -mx32";
1643 #else
1644  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1645 #endif
1646  compiler.extra_options += " -msse2 -mfpmath=sse";
1647  }
1648  else
1649  {
1650  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1651  }
1652  compiler.empty_plugin_obj = gcc_plugin_dir + I386_GCC6_EMPTY_PLUGIN + plugin_ext;
1653  compiler.empty_plugin_name = I386_GCC6_EMPTY_PLUGIN;
1654  compiler.ssa_plugin_obj =
1655  gcc_plugin_dir + (flag_cpp ? I386_GCC6_SSA_PLUGINCPP : I386_GCC6_SSA_PLUGIN) + plugin_ext;
1656  compiler.ssa_plugin_name = (flag_cpp ? I386_GCC6_SSA_PLUGINCPP : I386_GCC6_SSA_PLUGIN);
1657  compiler.topfname_plugin_obj = gcc_plugin_dir + I386_GCC6_TOPFNAME_PLUGIN + plugin_ext;
1658  compiler.topfname_plugin_name = I386_GCC6_TOPFNAME_PLUGIN;
1659  fillASTAnalyzer_plugin();
1660  }
1661 #endif
1662 
1663 #if HAVE_I386_GCC7_COMPILER
1664  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC7))
1665  {
1666  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_GPP7_EXE) : relocate_compiler_path(I386_GCC7_EXE);
1667  compiler.cpp = relocate_compiler_path(I386_CPP7_EXE);
1668  compiler.extra_options = " -mlong-double-64 -D_FORTIFY_SOURCE=0 " + gcc_extra_options;
1669  if(optimization_flags.find("tree-vectorize") != optimization_flags.end() &&
1670  optimization_flags.find("tree-vectorize")->second)
1671  {
1672 #if HAVE_I386_GCC7_MX32
1673  compiler.extra_options += " -mx32";
1674 #else
1675  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1676 #endif
1677  compiler.extra_options += " -msse2 -mfpmath=sse";
1678  }
1679  else
1680  {
1681  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1682  }
1683  compiler.empty_plugin_obj = gcc_plugin_dir + I386_GCC7_EMPTY_PLUGIN + plugin_ext;
1684  compiler.empty_plugin_name = I386_GCC7_EMPTY_PLUGIN;
1685  compiler.ssa_plugin_obj =
1686  gcc_plugin_dir + (flag_cpp ? I386_GCC7_SSA_PLUGINCPP : I386_GCC7_SSA_PLUGIN) + plugin_ext;
1687  compiler.ssa_plugin_name = (flag_cpp ? I386_GCC7_SSA_PLUGINCPP : I386_GCC7_SSA_PLUGIN);
1688  compiler.topfname_plugin_obj = gcc_plugin_dir + I386_GCC7_TOPFNAME_PLUGIN + plugin_ext;
1689  compiler.topfname_plugin_name = I386_GCC7_TOPFNAME_PLUGIN;
1690  fillASTAnalyzer_plugin();
1691  }
1692 #endif
1693 
1694 #if HAVE_I386_GCC8_COMPILER
1695  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC8))
1696  {
1697  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_GPP8_EXE) : relocate_compiler_path(I386_GCC8_EXE);
1698  compiler.cpp = relocate_compiler_path(I386_CPP8_EXE);
1699  compiler.extra_options = " -mlong-double-64 -D_FORTIFY_SOURCE=0 " + gcc_extra_options;
1700  if(optimization_flags.find("tree-vectorize") != optimization_flags.end() &&
1701  optimization_flags.find("tree-vectorize")->second)
1702  {
1703 #if HAVE_I386_GCC8_MX32
1704  compiler.extra_options += " -mx32";
1705 #else
1706  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1707 #endif
1708  compiler.extra_options += " -msse2 -mfpmath=sse";
1709  }
1710  else
1711  {
1712  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1713  }
1714  compiler.empty_plugin_obj = gcc_plugin_dir + I386_GCC8_EMPTY_PLUGIN + plugin_ext;
1715  compiler.empty_plugin_name = I386_GCC8_EMPTY_PLUGIN;
1716  compiler.ssa_plugin_obj =
1717  gcc_plugin_dir + (flag_cpp ? I386_GCC8_SSA_PLUGINCPP : I386_GCC8_SSA_PLUGIN) + plugin_ext;
1718  compiler.ssa_plugin_name = (flag_cpp ? I386_GCC8_SSA_PLUGINCPP : I386_GCC8_SSA_PLUGIN);
1719  compiler.topfname_plugin_obj = gcc_plugin_dir + I386_GCC8_TOPFNAME_PLUGIN + plugin_ext;
1720  compiler.topfname_plugin_name = I386_GCC8_TOPFNAME_PLUGIN;
1721  fillASTAnalyzer_plugin();
1722  }
1723 #endif
1724 
1725 #if HAVE_I386_CLANG4_COMPILER
1726  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG4))
1727  {
1728  compiler.is_clang = true;
1729  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP4_EXE) : relocate_compiler_path(I386_CLANG4_EXE);
1730  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP4_EXE);
1731  compiler.extra_options =
1732  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1733  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1734  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG4_EMPTY_PLUGIN + plugin_ext;
1735  compiler.empty_plugin_name = I386_CLANG4_EMPTY_PLUGIN;
1736  compiler.ssa_plugin_obj =
1737  clang_plugin_dir + (flag_cpp ? I386_CLANG4_SSA_PLUGINCPP : I386_CLANG4_SSA_PLUGIN) + plugin_ext;
1738  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG4_SSA_PLUGINCPP : I386_CLANG4_SSA_PLUGIN);
1739  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG4_EXPANDMEMOPS_PLUGIN + plugin_ext;
1740  compiler.expandMemOps_plugin_name = I386_CLANG4_EXPANDMEMOPS_PLUGIN;
1741  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG4_GEPICANON_PLUGIN + plugin_ext;
1742  compiler.GepiCanon_plugin_name = I386_CLANG4_GEPICANON_PLUGIN;
1743  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG4_CSROA_PLUGIN + plugin_ext;
1744  compiler.CSROA_plugin_name = I386_CLANG4_CSROA_PLUGIN;
1745  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG4_TOPFNAME_PLUGIN + plugin_ext;
1746  compiler.topfname_plugin_name = I386_CLANG4_TOPFNAME_PLUGIN;
1747  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG4_ASTANALYZER_PLUGIN + plugin_ext;
1748  compiler.ASTAnalyzer_plugin_name = I386_CLANG4_ASTANALYZER_PLUGIN;
1749  compiler.llvm_link = relocate_compiler_path(I386_LLVM4_LINK_EXE);
1750  compiler.llvm_opt = relocate_compiler_path(I386_LLVM4_OPT_EXE);
1751  }
1752 #endif
1753 
1754 #if HAVE_I386_CLANG5_COMPILER
1755  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG5))
1756  {
1757  compiler.is_clang = true;
1758  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP5_EXE) : relocate_compiler_path(I386_CLANG5_EXE);
1759  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP5_EXE);
1760  compiler.extra_options =
1761  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1762  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1763  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG5_EMPTY_PLUGIN + plugin_ext;
1764  compiler.empty_plugin_name = I386_CLANG5_EMPTY_PLUGIN;
1765  compiler.ssa_plugin_obj =
1766  clang_plugin_dir + (flag_cpp ? I386_CLANG5_SSA_PLUGINCPP : I386_CLANG5_SSA_PLUGIN) + plugin_ext;
1767  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG5_SSA_PLUGINCPP : I386_CLANG5_SSA_PLUGIN);
1768  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG5_EXPANDMEMOPS_PLUGIN + plugin_ext;
1769  compiler.expandMemOps_plugin_name = I386_CLANG5_EXPANDMEMOPS_PLUGIN;
1770  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG5_GEPICANON_PLUGIN + plugin_ext;
1771  compiler.GepiCanon_plugin_name = I386_CLANG5_GEPICANON_PLUGIN;
1772  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG5_CSROA_PLUGIN + plugin_ext;
1773  compiler.CSROA_plugin_name = I386_CLANG5_CSROA_PLUGIN;
1774  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG5_TOPFNAME_PLUGIN + plugin_ext;
1775  compiler.topfname_plugin_name = I386_CLANG5_TOPFNAME_PLUGIN;
1776  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG5_ASTANALYZER_PLUGIN + plugin_ext;
1777  compiler.ASTAnalyzer_plugin_name = I386_CLANG5_ASTANALYZER_PLUGIN;
1778  compiler.llvm_link = relocate_compiler_path(I386_LLVM5_LINK_EXE);
1779  compiler.llvm_opt = relocate_compiler_path(I386_LLVM5_OPT_EXE);
1780  }
1781 #endif
1782 
1783 #if HAVE_I386_CLANG6_COMPILER
1784  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG6))
1785  {
1786  compiler.is_clang = true;
1787  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP6_EXE) : relocate_compiler_path(I386_CLANG6_EXE);
1788  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP6_EXE);
1789  compiler.extra_options =
1790  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1791  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1792  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG6_EMPTY_PLUGIN + plugin_ext;
1793  compiler.empty_plugin_name = I386_CLANG6_EMPTY_PLUGIN;
1794  compiler.ssa_plugin_obj =
1795  clang_plugin_dir + (flag_cpp ? I386_CLANG6_SSA_PLUGINCPP : I386_CLANG6_SSA_PLUGIN) + plugin_ext;
1796  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG6_SSA_PLUGINCPP : I386_CLANG6_SSA_PLUGIN);
1797  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG6_EXPANDMEMOPS_PLUGIN + plugin_ext;
1798  compiler.expandMemOps_plugin_name = I386_CLANG6_EXPANDMEMOPS_PLUGIN;
1799  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG6_GEPICANON_PLUGIN + plugin_ext;
1800  compiler.GepiCanon_plugin_name = I386_CLANG6_GEPICANON_PLUGIN;
1801  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG6_CSROA_PLUGIN + plugin_ext;
1802  compiler.CSROA_plugin_name = I386_CLANG6_CSROA_PLUGIN;
1803  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG6_TOPFNAME_PLUGIN + plugin_ext;
1804  compiler.topfname_plugin_name = I386_CLANG6_TOPFNAME_PLUGIN;
1805  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG6_ASTANALYZER_PLUGIN + plugin_ext;
1806  compiler.ASTAnalyzer_plugin_name = I386_CLANG6_ASTANALYZER_PLUGIN;
1807  compiler.llvm_link = relocate_compiler_path(I386_LLVM6_LINK_EXE);
1808  compiler.llvm_opt = relocate_compiler_path(I386_LLVM6_OPT_EXE);
1809  }
1810 #endif
1811 
1812 #if HAVE_I386_CLANG7_COMPILER
1813  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG7))
1814  {
1815  compiler.is_clang = true;
1816  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP7_EXE) : relocate_compiler_path(I386_CLANG7_EXE);
1817  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP7_EXE);
1818  compiler.extra_options =
1819  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1820  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1821  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG7_EMPTY_PLUGIN + plugin_ext;
1822  compiler.empty_plugin_name = I386_CLANG7_EMPTY_PLUGIN;
1823  compiler.ssa_plugin_obj =
1824  clang_plugin_dir + (flag_cpp ? I386_CLANG7_SSA_PLUGINCPP : I386_CLANG7_SSA_PLUGIN) + plugin_ext;
1825  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG7_SSA_PLUGINCPP : I386_CLANG7_SSA_PLUGIN);
1826  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG7_EXPANDMEMOPS_PLUGIN + plugin_ext;
1827  compiler.expandMemOps_plugin_name = I386_CLANG7_EXPANDMEMOPS_PLUGIN;
1828  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG7_GEPICANON_PLUGIN + plugin_ext;
1829  compiler.GepiCanon_plugin_name = I386_CLANG7_GEPICANON_PLUGIN;
1830  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG7_CSROA_PLUGIN + plugin_ext;
1831  compiler.CSROA_plugin_name = I386_CLANG7_CSROA_PLUGIN;
1832  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG7_TOPFNAME_PLUGIN + plugin_ext;
1833  compiler.topfname_plugin_name = I386_CLANG7_TOPFNAME_PLUGIN;
1834  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG7_ASTANALYZER_PLUGIN + plugin_ext;
1835  compiler.ASTAnalyzer_plugin_name = I386_CLANG7_ASTANALYZER_PLUGIN;
1836  compiler.llvm_link = relocate_compiler_path(I386_LLVM7_LINK_EXE);
1837  compiler.llvm_opt = relocate_compiler_path(I386_LLVM7_OPT_EXE);
1838  }
1839 #endif
1840 
1841 #if HAVE_I386_CLANG8_COMPILER
1842  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG8))
1843  {
1844  compiler.is_clang = true;
1845  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP8_EXE) : relocate_compiler_path(I386_CLANG8_EXE);
1846  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP8_EXE);
1847  compiler.extra_options =
1848  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1849  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1850  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG8_EMPTY_PLUGIN + plugin_ext;
1851  compiler.empty_plugin_name = I386_CLANG8_EMPTY_PLUGIN;
1852  compiler.ssa_plugin_obj =
1853  clang_plugin_dir + (flag_cpp ? I386_CLANG8_SSA_PLUGINCPP : I386_CLANG8_SSA_PLUGIN) + plugin_ext;
1854  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG8_SSA_PLUGINCPP : I386_CLANG8_SSA_PLUGIN);
1855  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG8_EXPANDMEMOPS_PLUGIN + plugin_ext;
1856  compiler.expandMemOps_plugin_name = I386_CLANG8_EXPANDMEMOPS_PLUGIN;
1857  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG8_GEPICANON_PLUGIN + plugin_ext;
1858  compiler.GepiCanon_plugin_name = I386_CLANG8_GEPICANON_PLUGIN;
1859  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG8_CSROA_PLUGIN + plugin_ext;
1860  compiler.CSROA_plugin_name = I386_CLANG8_CSROA_PLUGIN;
1861  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG8_TOPFNAME_PLUGIN + plugin_ext;
1862  compiler.topfname_plugin_name = I386_CLANG8_TOPFNAME_PLUGIN;
1863  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG8_ASTANALYZER_PLUGIN + plugin_ext;
1864  compiler.ASTAnalyzer_plugin_name = I386_CLANG8_ASTANALYZER_PLUGIN;
1865  compiler.llvm_link = relocate_compiler_path(I386_LLVM8_LINK_EXE);
1866  compiler.llvm_opt = relocate_compiler_path(I386_LLVM8_OPT_EXE);
1867  }
1868 #endif
1869 
1870 #if HAVE_I386_CLANG9_COMPILER
1871  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG9))
1872  {
1873  compiler.is_clang = true;
1874  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP9_EXE) : relocate_compiler_path(I386_CLANG9_EXE);
1875  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP9_EXE);
1876  compiler.extra_options =
1877  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1878  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1879  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG9_EMPTY_PLUGIN + plugin_ext;
1880  compiler.empty_plugin_name = I386_CLANG9_EMPTY_PLUGIN;
1881  compiler.ssa_plugin_obj =
1882  clang_plugin_dir + (flag_cpp ? I386_CLANG9_SSA_PLUGINCPP : I386_CLANG9_SSA_PLUGIN) + plugin_ext;
1883  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG9_SSA_PLUGINCPP : I386_CLANG9_SSA_PLUGIN);
1884  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG9_EXPANDMEMOPS_PLUGIN + plugin_ext;
1885  compiler.expandMemOps_plugin_name = I386_CLANG9_EXPANDMEMOPS_PLUGIN;
1886  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG9_GEPICANON_PLUGIN + plugin_ext;
1887  compiler.GepiCanon_plugin_name = I386_CLANG9_GEPICANON_PLUGIN;
1888  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG9_CSROA_PLUGIN + plugin_ext;
1889  compiler.CSROA_plugin_name = I386_CLANG9_CSROA_PLUGIN;
1890  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG9_TOPFNAME_PLUGIN + plugin_ext;
1891  compiler.topfname_plugin_name = I386_CLANG9_TOPFNAME_PLUGIN;
1892  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG9_ASTANALYZER_PLUGIN + plugin_ext;
1893  compiler.ASTAnalyzer_plugin_name = I386_CLANG9_ASTANALYZER_PLUGIN;
1894  compiler.llvm_link = relocate_compiler_path(I386_LLVM9_LINK_EXE);
1895  compiler.llvm_opt = relocate_compiler_path(I386_LLVM9_OPT_EXE);
1896  }
1897 #endif
1898 
1899 #if HAVE_I386_CLANG10_COMPILER
1900  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG10))
1901  {
1902  compiler.is_clang = true;
1903  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP10_EXE) : relocate_compiler_path(I386_CLANG10_EXE);
1904  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP10_EXE);
1905  compiler.extra_options =
1906  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1907  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1908  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG10_EMPTY_PLUGIN + plugin_ext;
1909  compiler.empty_plugin_name = I386_CLANG10_EMPTY_PLUGIN;
1910  compiler.ssa_plugin_obj =
1911  clang_plugin_dir + (flag_cpp ? I386_CLANG10_SSA_PLUGINCPP : I386_CLANG10_SSA_PLUGIN) + plugin_ext;
1912  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG10_SSA_PLUGINCPP : I386_CLANG10_SSA_PLUGIN);
1913  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG10_EXPANDMEMOPS_PLUGIN + plugin_ext;
1914  compiler.expandMemOps_plugin_name = I386_CLANG10_EXPANDMEMOPS_PLUGIN;
1915  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG10_GEPICANON_PLUGIN + plugin_ext;
1916  compiler.GepiCanon_plugin_name = I386_CLANG10_GEPICANON_PLUGIN;
1917  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG10_CSROA_PLUGIN + plugin_ext;
1918  compiler.CSROA_plugin_name = I386_CLANG10_CSROA_PLUGIN;
1919  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG10_TOPFNAME_PLUGIN + plugin_ext;
1920  compiler.topfname_plugin_name = I386_CLANG10_TOPFNAME_PLUGIN;
1921  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG10_ASTANALYZER_PLUGIN + plugin_ext;
1922  compiler.ASTAnalyzer_plugin_name = I386_CLANG10_ASTANALYZER_PLUGIN;
1923  compiler.llvm_link = relocate_compiler_path(I386_LLVM10_LINK_EXE);
1924  compiler.llvm_opt = relocate_compiler_path(I386_LLVM10_OPT_EXE);
1925  }
1926 #endif
1927 
1928 #if HAVE_I386_CLANG11_COMPILER
1929  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG11))
1930  {
1931  compiler.is_clang = true;
1932  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP11_EXE) : relocate_compiler_path(I386_CLANG11_EXE);
1933  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP11_EXE);
1934  compiler.extra_options =
1935  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1936  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1937  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG11_EMPTY_PLUGIN + plugin_ext;
1938  compiler.empty_plugin_name = I386_CLANG11_EMPTY_PLUGIN;
1939  compiler.ssa_plugin_obj =
1940  clang_plugin_dir + (flag_cpp ? I386_CLANG11_SSA_PLUGINCPP : I386_CLANG11_SSA_PLUGIN) + plugin_ext;
1941  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG11_SSA_PLUGINCPP : I386_CLANG11_SSA_PLUGIN);
1942  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG11_EXPANDMEMOPS_PLUGIN + plugin_ext;
1943  compiler.expandMemOps_plugin_name = I386_CLANG11_EXPANDMEMOPS_PLUGIN;
1944  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG11_GEPICANON_PLUGIN + plugin_ext;
1945  compiler.GepiCanon_plugin_name = I386_CLANG11_GEPICANON_PLUGIN;
1946  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG11_CSROA_PLUGIN + plugin_ext;
1947  compiler.CSROA_plugin_name = I386_CLANG11_CSROA_PLUGIN;
1948  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG11_TOPFNAME_PLUGIN + plugin_ext;
1949  compiler.topfname_plugin_name = I386_CLANG11_TOPFNAME_PLUGIN;
1950  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG11_ASTANALYZER_PLUGIN + plugin_ext;
1951  compiler.ASTAnalyzer_plugin_name = I386_CLANG11_ASTANALYZER_PLUGIN;
1952  compiler.llvm_link = relocate_compiler_path(I386_LLVM11_LINK_EXE);
1953  compiler.llvm_opt = relocate_compiler_path(I386_LLVM11_OPT_EXE);
1954  }
1955 #endif
1956 
1957 #if HAVE_I386_CLANG12_COMPILER
1958  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG12))
1959  {
1960  compiler.is_clang = true;
1961  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP12_EXE) : relocate_compiler_path(I386_CLANG12_EXE);
1962  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP12_EXE);
1963  compiler.extra_options =
1964  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1965  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1966  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG12_EMPTY_PLUGIN + plugin_ext;
1967  compiler.empty_plugin_name = I386_CLANG12_EMPTY_PLUGIN;
1968  compiler.ssa_plugin_obj =
1969  clang_plugin_dir + (flag_cpp ? I386_CLANG12_SSA_PLUGINCPP : I386_CLANG12_SSA_PLUGIN) + plugin_ext;
1970  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG12_SSA_PLUGINCPP : I386_CLANG12_SSA_PLUGIN);
1971  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG12_EXPANDMEMOPS_PLUGIN + plugin_ext;
1972  compiler.expandMemOps_plugin_name = I386_CLANG12_EXPANDMEMOPS_PLUGIN;
1973  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG12_GEPICANON_PLUGIN + plugin_ext;
1974  compiler.GepiCanon_plugin_name = I386_CLANG12_GEPICANON_PLUGIN;
1975  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG12_CSROA_PLUGIN + plugin_ext;
1976  compiler.CSROA_plugin_name = I386_CLANG12_CSROA_PLUGIN;
1977  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG12_TOPFNAME_PLUGIN + plugin_ext;
1978  compiler.topfname_plugin_name = I386_CLANG12_TOPFNAME_PLUGIN;
1979  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG12_ASTANALYZER_PLUGIN + plugin_ext;
1980  compiler.ASTAnalyzer_plugin_name = I386_CLANG12_ASTANALYZER_PLUGIN;
1981  compiler.llvm_link = relocate_compiler_path(I386_LLVM12_LINK_EXE);
1982  compiler.llvm_opt = relocate_compiler_path(I386_LLVM12_OPT_EXE);
1983  }
1984 #endif
1985 
1986 #if HAVE_I386_CLANG13_COMPILER
1987  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG13))
1988  {
1989  compiler.is_clang = true;
1990  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP13_EXE) : relocate_compiler_path(I386_CLANG13_EXE);
1991  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP13_EXE);
1992  compiler.extra_options =
1993  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
1994  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
1995  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG13_EMPTY_PLUGIN + plugin_ext;
1996  compiler.empty_plugin_name = I386_CLANG13_EMPTY_PLUGIN;
1997  compiler.ssa_plugin_obj =
1998  clang_plugin_dir + (flag_cpp ? I386_CLANG13_SSA_PLUGINCPP : I386_CLANG13_SSA_PLUGIN) + plugin_ext;
1999  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG13_SSA_PLUGINCPP : I386_CLANG13_SSA_PLUGIN);
2000  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG13_EXPANDMEMOPS_PLUGIN + plugin_ext;
2001  compiler.expandMemOps_plugin_name = I386_CLANG13_EXPANDMEMOPS_PLUGIN;
2002  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG13_GEPICANON_PLUGIN + plugin_ext;
2003  compiler.GepiCanon_plugin_name = I386_CLANG13_GEPICANON_PLUGIN;
2004  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG13_CSROA_PLUGIN + plugin_ext;
2005  compiler.CSROA_plugin_name = I386_CLANG13_CSROA_PLUGIN;
2006  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG13_TOPFNAME_PLUGIN + plugin_ext;
2007  compiler.topfname_plugin_name = I386_CLANG13_TOPFNAME_PLUGIN;
2008  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG13_ASTANALYZER_PLUGIN + plugin_ext;
2009  compiler.ASTAnalyzer_plugin_name = I386_CLANG13_ASTANALYZER_PLUGIN;
2010  compiler.llvm_link = relocate_compiler_path(I386_LLVM13_LINK_EXE);
2011  compiler.llvm_opt = relocate_compiler_path(I386_LLVM13_OPT_EXE);
2012  }
2013 #endif
2014 
2015 #if HAVE_I386_CLANG16_COMPILER
2016  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG16))
2017  {
2018  compiler.is_clang = true;
2019  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPP16_EXE) : relocate_compiler_path(I386_CLANG16_EXE);
2020  compiler.cpp = relocate_compiler_path(I386_CLANG_CPP16_EXE);
2021  compiler.extra_options =
2022  " -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
2023  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
2024  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANG16_EMPTY_PLUGIN + plugin_ext;
2025  compiler.empty_plugin_name = I386_CLANG16_EMPTY_PLUGIN;
2026  compiler.ssa_plugin_obj =
2027  clang_plugin_dir + (flag_cpp ? I386_CLANG16_SSA_PLUGINCPP : I386_CLANG16_SSA_PLUGIN) + plugin_ext;
2028  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANG16_SSA_PLUGINCPP : I386_CLANG16_SSA_PLUGIN);
2029  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANG16_EXPANDMEMOPS_PLUGIN + plugin_ext;
2030  compiler.expandMemOps_plugin_name = I386_CLANG16_EXPANDMEMOPS_PLUGIN;
2031  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANG16_GEPICANON_PLUGIN + plugin_ext;
2032  compiler.GepiCanon_plugin_name = I386_CLANG16_GEPICANON_PLUGIN;
2033  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANG16_CSROA_PLUGIN + plugin_ext;
2034  compiler.CSROA_plugin_name = I386_CLANG16_CSROA_PLUGIN;
2035  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANG16_TOPFNAME_PLUGIN + plugin_ext;
2036  compiler.topfname_plugin_name = I386_CLANG16_TOPFNAME_PLUGIN;
2037  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANG16_ASTANALYZER_PLUGIN + plugin_ext;
2038  compiler.ASTAnalyzer_plugin_name = I386_CLANG16_ASTANALYZER_PLUGIN;
2039  compiler.llvm_link = relocate_compiler_path(I386_LLVM16_LINK_EXE);
2040  compiler.llvm_opt = relocate_compiler_path(I386_LLVM16_OPT_EXE);
2041  }
2042 #endif
2043 
2044 #if HAVE_I386_CLANGVVD_COMPILER
2045  if(static_cast<int>(preferred_compiler) & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANGVVD))
2046  {
2047  compiler.is_clang = true;
2048  compiler.gcc = flag_cpp ? relocate_compiler_path(I386_CLANGPPVVD_EXE) : relocate_compiler_path(I386_CLANGVVD_EXE);
2049  compiler.cpp = relocate_compiler_path(I386_CLANG_CPPVVD_EXE);
2050  compiler.extra_options =
2051  " -D__VIVADO__ -D_FORTIFY_SOURCE=0 " + gcc_extra_options + (flag_cpp ? EXTRA_CLANGPP_COMPILER_OPTION : "");
2052  compiler.extra_options += " " + Param->getOption<std::string>(OPT_gcc_m32_mx32);
2053  compiler.extra_options += " -target fpga64-xilinx-linux-gnu";
2054  compiler.empty_plugin_obj = clang_plugin_dir + I386_CLANGVVD_EMPTY_PLUGIN + plugin_ext;
2055  compiler.empty_plugin_name = I386_CLANGVVD_EMPTY_PLUGIN;
2056  compiler.ssa_plugin_obj =
2057  clang_plugin_dir + (flag_cpp ? I386_CLANGVVD_SSA_PLUGINCPP : I386_CLANGVVD_SSA_PLUGIN) + plugin_ext;
2058  compiler.ssa_plugin_name = (flag_cpp ? I386_CLANGVVD_SSA_PLUGINCPP : I386_CLANGVVD_SSA_PLUGIN);
2059  compiler.expandMemOps_plugin_obj = clang_plugin_dir + I386_CLANGVVD_EXPANDMEMOPS_PLUGIN + plugin_ext;
2060  compiler.expandMemOps_plugin_name = I386_CLANGVVD_EXPANDMEMOPS_PLUGIN;
2061  compiler.GepiCanon_plugin_obj = clang_plugin_dir + I386_CLANGVVD_GEPICANON_PLUGIN + plugin_ext;
2062  compiler.GepiCanon_plugin_name = I386_CLANGVVD_GEPICANON_PLUGIN;
2063  compiler.CSROA_plugin_obj = clang_plugin_dir + I386_CLANGVVD_CSROA_PLUGIN + plugin_ext;
2064  compiler.CSROA_plugin_name = I386_CLANGVVD_CSROA_PLUGIN;
2065  compiler.topfname_plugin_obj = clang_plugin_dir + I386_CLANGVVD_TOPFNAME_PLUGIN + plugin_ext;
2066  compiler.topfname_plugin_name = I386_CLANGVVD_TOPFNAME_PLUGIN;
2067  compiler.ASTAnalyzer_plugin_obj = clang_plugin_dir + I386_CLANGVVD_ASTANALYZER_PLUGIN + plugin_ext;
2068  compiler.ASTAnalyzer_plugin_name = I386_CLANGVVD_ASTANALYZER_PLUGIN;
2069  compiler.llvm_link = relocate_compiler_path(I386_LLVMVVD_LINK_EXE);
2070  compiler.llvm_opt = relocate_compiler_path(I386_LLVMVVD_OPT_EXE);
2071  }
2072 #endif
2073 
2074  if(compiler.gcc == "")
2075  {
2076  THROW_ERROR("Not found any compatible compiler");
2077  }
2078 
2079  return compiler;
2080 }
2081 
2083 {
2084  const auto flag_cpp =
2085  Param->isOption(OPT_input_format) &&
2086  (Param->getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_CPP ||
2087  Param->getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_LLVM_CPP);
2088 
2089 #if HAVE_I386_CLANG16_COMPILER
2090  return flag_cpp ? relocate_compiler_path(I386_CLANGPP16_EXE) : relocate_compiler_path(I386_CLANG16_EXE);
2091 #elif HAVE_I386_CLANG13_COMPILER
2092  return flag_cpp ? relocate_compiler_path(I386_CLANGPP13_EXE) : relocate_compiler_path(I386_CLANG13_EXE);
2093 #elif HAVE_I386_CLANG12_COMPILER
2094  return flag_cpp ? relocate_compiler_path(I386_CLANGPP12_EXE) : relocate_compiler_path(I386_CLANG12_EXE);
2095 #elif HAVE_I386_CLANG11_COMPILER
2096  return flag_cpp ? relocate_compiler_path(I386_CLANGPP11_EXE) : relocate_compiler_path(I386_CLANG11_EXE);
2097 #elif HAVE_I386_CLANG10_COMPILER
2098  return flag_cpp ? relocate_compiler_path(I386_CLANGPP10_EXE) : relocate_compiler_path(I386_CLANG10_EXE);
2099 #elif HAVE_I386_CLANG9_COMPILER
2100  return flag_cpp ? relocate_compiler_path(I386_CLANGPP9_EXE) : relocate_compiler_path(I386_CLANG9_EXE);
2101 #elif HAVE_I386_CLANG8_COMPILER
2102  return flag_cpp ? relocate_compiler_path(I386_CLANGPP8_EXE) : relocate_compiler_path(I386_CLANG8_EXE);
2103 #elif HAVE_I386_CLANG7_COMPILER
2104  return flag_cpp ? relocate_compiler_path(I386_CLANGPP7_EXE) : relocate_compiler_path(I386_CLANG7_EXE);
2105 #elif HAVE_I386_CLANG6_COMPILER
2106  return flag_cpp ? relocate_compiler_path(I386_CLANGPP6_EXE) : relocate_compiler_path(I386_CLANG6_EXE);
2107 #elif HAVE_I386_CLANG5_COMPILER
2108  return flag_cpp ? relocate_compiler_path(I386_CLANGPP5_EXE) : relocate_compiler_path(I386_CLANG5_EXE);
2109 #elif HAVE_I386_CLANG4_COMPILER
2110  return flag_cpp ? relocate_compiler_path(I386_CLANGPP4_EXE) : relocate_compiler_path(I386_CLANG4_EXE);
2111 #elif HAVE_I386_CLANGVVD_COMPILER
2112  return flag_cpp ? relocate_compiler_path(I386_CLANGPPVVD_EXE) : relocate_compiler_path(I386_CLANGVVD_EXE);
2113 #else
2114  THROW_ERROR("unexpected condition");
2115  return "";
2116 #endif
2117 }
2118 
2119 void CompilerWrapper::GetSystemIncludes(std::vector<std::string>& includes) const
2120 {
2122  const std::string cpp = GetCompiler().cpp;
2123 
2124  std::string command =
2125  cpp + " -v < /dev/null 2>&1 | grep -v -E \"(#|Configured with|Using built-in|Target|Thread model|gcc "
2126  "version|End of "
2127  "search list|ignoring nonexistent directory|cc1 -E -quiet|cc1.exe -E "
2128  "-quiet|COMPILER_PATH|LIBRARY_PATH|COLLECT_GCC|OFFLOAD_TARGET_NAMES|OFFLOAD_TARGET_DEFAULT|ignoring "
2129  "duplicate "
2130  "directory|ignoring nonexistent directory|InstalledDir|clang version|Found candidate|Selected GCC "
2131  "installation|Candidate multilib|Selected multilib|-cc1)\" | tr '\\n' ' ' | tr '\\r' ' ' | sed "
2132  "'s/\\\\/\\//g'";
2133  int ret = PandaSystem(Param, command, false, STR_CST_gcc_include);
2135  if(IsError(ret))
2136  {
2137  util_print_cpu_stats(std::cerr);
2138  THROW_ERROR("Error in retrieving gcc system include. Error is " + std::to_string(ret));
2139  }
2140 
2141  std::string list_of_dirs;
2142 
2143  std::ifstream includefile(GetPath(STR_CST_gcc_include));
2144  if(includefile.is_open())
2145  {
2146  std::string line;
2147  while(!includefile.eof())
2148  {
2149  getline(includefile, line);
2150  if(line.size())
2151  {
2152  list_of_dirs += line;
2153  }
2154  }
2155  }
2156  else
2157  {
2158  THROW_ERROR("Error in retrieving gcc system include");
2159  }
2160 
2161  std::remove(GetPath(STR_CST_gcc_include).c_str());
2162 
2163  // Ok, now here there are the list of the system paths in which
2164  // the system includes are found
2165  includes = SplitString(list_of_dirs, " ");
2166 }
2167 
2169 {
2170  QueryCompilerConfig("-v");
2171 }
2172 
2173 void CompilerWrapper::QueryCompilerConfig(const std::string& compiler_option) const
2174 {
2175  const std::string gcc = GetCompiler().gcc;
2176  const std::string command = gcc + " " + compiler_option;
2177  const std::string output_file_name =
2178  Param->getOption<std::string>(OPT_output_temporary_directory) + STR_CST_file_IO_shell_output_file;
2179  int ret = PandaSystem(Param, command, false, output_file_name);
2180  if(IsError(ret))
2181  {
2182  THROW_ERROR("Error in retrieving gcc configuration");
2183  }
2184  CopyStdout(output_file_name);
2185 }
2186 
2187 std::string CompilerWrapper::GetCompilerParameters(const std::string& extra_compiler_options,
2188  bool no_frontend_compiler_parameters) const
2189 {
2190  const auto compiler = GetCompiler();
2191  std::string command =
2192  (no_frontend_compiler_parameters ? "" : frontend_compiler_parameters) + " " + compiler_linking_parameters + " ";
2193  command += "-D__NO_INLINE__ ";
2194 
2195  std::string local_compiler_extra_options = no_frontend_compiler_parameters ? "" : compiler.extra_options;
2196  if(extra_compiler_options.find("-m32") != std::string::npos)
2197  {
2198  boost::replace_all(local_compiler_extra_options, "-mx32", "");
2199  }
2200 
2201 #ifdef _WIN32
2202  if(local_compiler_extra_options.find("-m32") != std::string::npos)
2203  {
2204  boost::replace_all(local_compiler_extra_options, "-m32", "");
2205  }
2206 #endif
2207 
2208  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Extra options are " + local_compiler_extra_options);
2209  command += local_compiler_extra_options + " " + extra_compiler_options + " ";
2210  boost::replace_all(command, "-target fpga64-xilinx-linux-gnu", "");
2211 
2212  return command;
2213 }
2214 
2215 void CompilerWrapper::CreateExecutable(const CustomSet<std::string>& file_names, const std::string& executable_name,
2216  const std::string& extra_compiler_options,
2217  bool no_frontend_compiler_parameters) const
2218 {
2219  std::list<std::string> sorted_file_names;
2220  for(const auto& file_name : file_names)
2221  {
2222  sorted_file_names.push_back(file_name);
2223  }
2224  CreateExecutable(sorted_file_names, executable_name, extra_compiler_options, no_frontend_compiler_parameters);
2225 }
2226 
2227 void CompilerWrapper::CreateExecutable(const std::list<std::string>& file_names, const std::string& executable_name,
2228  const std::string& extra_compiler_options,
2229  bool no_frontend_compiler_parameters) const
2230 {
2231  std::string file_names_string;
2232  bool has_cpp_file = false;
2233  for(const auto& file_name : file_names)
2234  {
2235  auto file_format = Param->GetFileFormat(file_name, false);
2236  if(file_format == Parameters_FileFormat::FF_CPP || file_format == Parameters_FileFormat::FF_LLVM_CPP)
2237  {
2238  has_cpp_file = true;
2239  }
2240  file_names_string += file_name + " ";
2241  }
2243  "-->Creating executable " + executable_name + " from " + file_names_string);
2244 
2245  const auto compiler = GetCompiler();
2246  std::string command = compiler.gcc + " ";
2247  command += GetCompilerParameters(extra_compiler_options, no_frontend_compiler_parameters);
2248  command += "-o " + executable_name + " ";
2249  command += file_names_string + " ";
2250  command += AddSourceCodeIncludes(file_names) + " ";
2251 
2252  if(!has_cpp_file)
2253  {
2254  command = std::regex_replace(command, std::regex("[-]{1,2}std=c\\+\\+\\w+"), "");
2255  }
2256 
2257  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Compilation command is " + command);
2258  const auto compiler_output_filename =
2259  Param->getOption<std::string>(OPT_output_temporary_directory) + STR_CST_gcc_output;
2260 
2261  int ret = PandaSystem(Param, command, false, compiler_output_filename);
2262  if(IsError(ret))
2263  {
2264  CopyStdout(compiler_output_filename);
2265  THROW_ERROR_CODE(COMPILING_EC, "Front-end compiler returns an error during compilation " + std::to_string(errno) +
2266  " - Command is " + command);
2267  }
2268  else
2269  {
2271  {
2272  CopyStdout(compiler_output_filename);
2273  }
2274  }
2276 }
2277 
2279 {
2280  if(Param->isOption(OPT_gcc_optimizations))
2281  {
2282  const auto parameters = Param->getOption<CustomSet<std::string>>(OPT_gcc_optimizations);
2283  for(const auto& parameter : parameters)
2284  {
2285  THROW_ASSERT(parameter != "", "unexpected condition:" + Param->getOption<std::string>(OPT_gcc_optimizations));
2286  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Examining parameter " + parameter);
2287  const size_t found = parameter.find("no-");
2288  // if the token starts with "no-", the optimization has to be disabled
2289  if(found == 0)
2290  {
2291  std::string str = parameter.substr(found + std::string("no-").size());
2292  optimization_flags[str] = false;
2293  }
2294  else
2295  {
2296  optimization_flags[parameter] = true;
2297  }
2299  }
2300  }
2301  if(Param->isOption(OPT_gcc_parameters))
2302  {
2303  const auto parameters = Param->getOption<CustomSet<std::string>>(OPT_gcc_parameters);
2304  for(const auto& parameter : parameters)
2305  {
2306  const size_t equal_size = parameter.find('=');
2307  if(equal_size == std::string::npos)
2308  {
2309  THROW_ERROR("--param argument without value " + parameter);
2310  }
2311  const std::string key = parameter.substr(0, equal_size);
2312  const std::string value = parameter.substr(equal_size + 1, parameter.size() - equal_size + 1);
2313  parameter_values[key] = std::stoi(value);
2314  }
2315  }
2316 }
2317 
2319 {
2320  switch(optimization_set)
2321  {
2323  return "0";
2325  return "1";
2327  return "2";
2329  return "3";
2331  return "4";
2333  return "5";
2335  return "g";
2337  return "s";
2339  return "fast";
2341  return "z";
2343  return "bambu";
2345  return "softfloat";
2346  default:
2347  {
2348  THROW_UNREACHABLE("");
2349  }
2350  }
2351  return "";
2352 }
2353 
2355 {
2356  std::string optimizations;
2358  bool argument_noalias = optimization_flags.find("argument-noalias") != optimization_flags.end() &&
2359  optimization_flags.find("argument-noalias")->second;
2360  bool argument_noalias_global = optimization_flags.find("argument-noalias-global") != optimization_flags.end() &&
2361  optimization_flags.find("argument-noalias-global")->second;
2362  bool argument_noalias_anything = optimization_flags.find("argument-noalias-anything") != optimization_flags.end() &&
2363  optimization_flags.find("argument-noalias-anything")->second;
2364  bool strict_aliasing = optimization_flags.find("strict-aliasing") != optimization_flags.end() &&
2365  optimization_flags.find("strict-aliasing")->second;
2366  std::map<std::string, bool>::const_iterator it, it_end = optimization_flags.end();
2367  if(strict_aliasing)
2368  {
2369  optimizations += std::string("-Wstrict-aliasing ");
2370  }
2371  for(it = optimization_flags.begin(); it != it_end; ++it)
2372  {
2373  /*argument aliasing should be treated in a different way*/
2374  if(it->first == "argument-alias" && (argument_noalias || argument_noalias_global || argument_noalias_anything))
2375  {
2376  continue;
2377  }
2378  else if(it->first == "argument-noalias" && (argument_noalias_global || argument_noalias_anything))
2379  {
2380  continue;
2381  }
2382  else if(it->first == "argument-noalias-global" && (argument_noalias_anything))
2383  {
2384  continue;
2385  }
2386  THROW_ASSERT(it->first != "", "unexpected condition");
2387  if(it->first == "fp-contract")
2388  {
2389  if(it->second)
2390  {
2391  optimizations += std::string("-f") + it->first + "=on ";
2392  }
2393  else
2394  {
2395  optimizations += std::string("-f") + it->first + "=off ";
2396  }
2397  }
2398  else if(it->second)
2399  {
2400  optimizations += std::string("-f") + it->first + " "; // enable optimizations set to true
2401  }
2402  else
2403  {
2404  optimizations += std::string("-fno-") + it->first + " "; // disable optimizations set to false
2405  }
2406  }
2407  std::map<std::string, int>::const_iterator it2, it2_end = optimization_values.end();
2408  for(it2 = optimization_values.begin(); it2 != it2_end; ++it2)
2409  {
2410  optimizations += std::string("-f") + it2->first + "=" + std::to_string(it2->second) + " ";
2411  }
2412  std::map<std::string, int>::const_iterator it3, it3_end = parameter_values.end();
2413  for(it3 = parameter_values.begin(); it3 != it3_end; ++it3)
2414  {
2415  optimizations += "--param " + it3->first + "=" + std::to_string(it3->second) + " ";
2416  }
2417  return optimizations;
2418 }
2419 
2420 void CompilerWrapper::ReadXml(const std::string& file_name)
2421 {
2422  try
2423  {
2424  XMLDomParser parser(file_name);
2425  parser.Exec();
2426  if(parser)
2427  {
2428  const xml_element* root = parser.get_document()->get_root_node();
2429 
2430  const xml_node::node_list root_children = root->get_children();
2431  xml_node::node_list::const_iterator root_child, root_child_end = root_children.end();
2432  for(root_child = root_children.begin(); root_child != root_child_end; ++root_child)
2433  {
2434  const auto* root_child_element = GetPointer<const xml_element>(*root_child);
2435  if(!root_child_element)
2436  {
2437  continue;
2438  }
2439  if(root_child_element->get_name() == STR_XML_gcc_optimizations)
2440  {
2441  const xml_node::node_list optimizations_children = root_child_element->get_children();
2442  xml_node::node_list::const_iterator optimizations_child,
2443  optimizations_child_end = optimizations_children.end();
2444  for(optimizations_child = optimizations_children.begin(); optimizations_child != optimizations_child_end;
2445  ++optimizations_child)
2446  {
2447  const auto* optimizations_child_element = GetPointer<const xml_element>(*optimizations_child);
2448  if(!optimizations_child_element)
2449  {
2450  continue;
2451  }
2452  if(optimizations_child_element->get_name() == STR_XML_gcc_parameter_values)
2453  {
2454  const xml_node::node_list parameter_values_children = optimizations_child_element->get_children();
2455  xml_node::node_list::const_iterator parameter_value,
2456  parameter_value_end = parameter_values_children.end();
2457  for(parameter_value = parameter_values_children.begin(); parameter_value != parameter_value_end;
2458  ++parameter_value)
2459  {
2460  const auto* parameter_value_element = GetPointer<const xml_element>(*parameter_value);
2461  if(!parameter_value_element)
2462  {
2463  continue;
2464  }
2465  if(not(parameter_value_element->get_attribute(STR_XML_gcc_name) &&
2466  parameter_value_element->get_attribute(STR_XML_gcc_value)))
2467  {
2468  THROW_ERROR("Parameter value node without name or value");
2469  }
2470  parameter_values[parameter_value_element->get_attribute(STR_XML_gcc_name)->get_name()] =
2471  std::stoi(parameter_value_element->get_attribute(STR_XML_gcc_value)->get_value());
2472  }
2473  }
2474  else if(optimizations_child_element->get_name() == STR_XML_gcc_optimization_flags)
2475  {
2476  const xml_node::node_list optimization_flags_children =
2477  optimizations_child_element->get_children();
2478  xml_node::node_list::const_iterator optimization_flag,
2479  optimization_flag_end = optimization_flags_children.end();
2480  for(optimization_flag = optimization_flags_children.begin();
2481  optimization_flag != optimization_flag_end; ++optimization_flag)
2482  {
2483  const auto* optimization_flag_element = GetPointer<const xml_element>(*optimization_flag);
2484  if(!optimization_flag_element)
2485  {
2486  continue;
2487  }
2488  if(!(optimization_flag_element->get_attribute(STR_XML_gcc_name) &&
2489  optimization_flag_element->get_attribute(STR_XML_gcc_value)))
2490  {
2491  THROW_ERROR("Optimization flag node without name or value");
2492  }
2493  optimization_flags[optimization_flag_element->get_attribute(STR_XML_gcc_name)->get_value()] =
2494  static_cast<bool>(
2495  std::stoi(optimization_flag_element->get_attribute(STR_XML_gcc_value)->get_value()));
2496  }
2497  }
2498  else if(optimizations_child_element->get_name() == STR_XML_gcc_optimization_values)
2499  {
2500  const xml_node::node_list optimization_value_children =
2501  optimizations_child_element->get_children();
2502  xml_node::node_list::const_iterator optimization_value,
2503  optimization_value_end = optimization_value_children.end();
2504  for(optimization_value = optimization_value_children.begin();
2505  optimization_value != optimization_value_end; ++optimization_value)
2506  {
2507  const auto* optimization_value_element = GetPointer<const xml_element>(*optimization_value);
2508  if(!optimization_value_element)
2509  {
2510  continue;
2511  }
2512  if(!(optimization_value_element->get_attribute(STR_XML_gcc_name) &&
2513  optimization_value_element->get_attribute(STR_XML_gcc_value)))
2514  {
2515  THROW_ERROR("Optimization value node without name or value");
2516  }
2517  optimization_values[optimization_value_element->get_attribute(STR_XML_gcc_name)->get_name()] =
2518  std::stoi(optimization_value_element->get_attribute(STR_XML_gcc_value)->get_value());
2519  }
2520  }
2521  }
2523  }
2524  else if(root_child_element->get_name() == STR_XML_gcc_standard)
2525  {
2526  const xml_element* standard = root_child_element;
2527  if(!standard->get_attribute(STR_XML_gcc_value))
2528  {
2529  THROW_ERROR("Standard node without value");
2530  }
2531  frontend_compiler_parameters += "--std=" + standard->get_attribute(STR_XML_gcc_value)->get_value() + " ";
2532  }
2533  else if(root_child_element->get_name() == STR_XML_gcc_defines)
2534  {
2535  const xml_node::node_list defines = root_child_element->get_children();
2536  xml_node::node_list::const_iterator define, define_end = defines.end();
2537  for(define = defines.begin(); define != define_end; ++define)
2538  {
2539  const auto* define_element = GetPointer<const xml_element>(*define);
2540  if(!define_element)
2541  {
2542  continue;
2543  }
2544  if(!define_element->get_attribute(STR_XML_gcc_value))
2545  {
2546  THROW_ERROR("Optimization value node without name or value");
2547  }
2549  "-D" + define_element->get_attribute(STR_XML_gcc_value)->get_value() + " ";
2550  }
2551  }
2552  else if(root_child_element->get_name() == STR_XML_gcc_undefines)
2553  {
2554  const xml_node::node_list undefines = root_child_element->get_children();
2555  xml_node::node_list::const_iterator undefine, undefine_end = undefines.end();
2556  for(undefine = undefines.begin(); undefine != undefine_end; ++undefine)
2557  {
2558  const auto* undefine_element = GetPointer<const xml_element>(*undefine);
2559  if(!undefine_element)
2560  {
2561  continue;
2562  }
2563  if(!undefine_element->get_attribute(STR_XML_gcc_value))
2564  {
2565  THROW_ERROR("Optimization value node without name or value");
2566  }
2568  "-U" + undefine_element->get_attribute(STR_XML_gcc_value)->get_value() + " ";
2569  }
2570  }
2571  else if(root_child_element->get_name() == STR_XML_gcc_warnings)
2572  {
2573  const xml_node::node_list warnings = root_child_element->get_children();
2574  xml_node::node_list::const_iterator warning, warning_end = warnings.end();
2575  for(warning = warnings.begin(); warning != warning_end; ++warning)
2576  {
2577  const auto* warning_element = GetPointer<const xml_element>(*warning);
2578  if(!warning_element)
2579  {
2580  continue;
2581  }
2582  if(!warning_element->get_attribute(STR_XML_gcc_value))
2583  {
2584  THROW_ERROR("Optimization value node without name or value");
2585  }
2587  "-W" + warning_element->get_attribute(STR_XML_gcc_value)->get_value() + " ";
2588  }
2589  }
2590  else if(root_child_element->get_name() == STR_XML_gcc_includes)
2591  {
2592  const xml_node::node_list includes = root_child_element->get_children();
2593  xml_node::node_list::const_iterator include, include_end = includes.end();
2594  for(include = includes.begin(); include != include_end; ++include)
2595  {
2596  const auto* include_element = GetPointer<const xml_element>(*include);
2597  if(!include_element)
2598  {
2599  continue;
2600  }
2601  if(!include_element->get_attribute(STR_XML_gcc_value))
2602  {
2603  THROW_ERROR("Optimization value node without name or value");
2604  }
2606  "-I" + include_element->get_attribute(STR_XML_gcc_value)->get_value() + " ";
2607  }
2608  }
2609  else if(root_child_element->get_name() == STR_XML_gcc_libraries)
2610  {
2611  const xml_node::node_list libraries = root_child_element->get_children();
2612  xml_node::node_list::const_iterator library, library_end = libraries.end();
2613  for(library = libraries.begin(); library != library_end; ++library)
2614  {
2615  const auto* library_element = GetPointer<const xml_element>(*library);
2616  if(!library_element)
2617  {
2618  continue;
2619  }
2620  if(!library_element->get_attribute(STR_XML_gcc_value))
2621  {
2622  THROW_ERROR("Optimization value node without name or value");
2623  }
2625  "-l" + library_element->get_attribute(STR_XML_gcc_value)->get_value() + " ";
2626  }
2627  }
2628  else if(root_child_element->get_name() == STR_XML_gcc_library_directories)
2629  {
2630  const xml_node::node_list library_directories = root_child_element->get_children();
2631  xml_node::node_list::const_iterator library_directory, library_directory_end = library_directories.end();
2632  for(library_directory = library_directories.begin(); library_directory != library_directory_end;
2633  ++library_directory)
2634  {
2635  const auto* library_directory_element = GetPointer<const xml_element>(*library_directory);
2636  if(!library_directory_element)
2637  {
2638  continue;
2639  }
2640  if(!library_directory_element->get_attribute(STR_XML_gcc_value))
2641  {
2642  THROW_ERROR("Optimization value node without name or value");
2643  }
2645  "-L" + library_directory_element->get_attribute(STR_XML_gcc_value)->get_value() + " ";
2646  }
2647  }
2648  }
2649  }
2650  }
2651  catch(const char* msg)
2652  {
2653  THROW_ERROR("Error " + std::string(msg) + " during reading of gcc configuration from " + file_name);
2654  }
2655  catch(const std::string& msg)
2656  {
2657  THROW_ERROR("Error " + msg + " during reading of gcc configuration from " + file_name);
2658  }
2659  catch(const std::exception& ex)
2660  {
2661  THROW_ERROR("Error " + std::string(ex.what()) + " during reading of gcc configuration from " + file_name);
2662  }
2663  catch(...)
2664  {
2665  THROW_ERROR("Unknown exception during reading of gcc configuration from " + file_name);
2666  }
2667 }
2668 
2669 void CompilerWrapper::WriteXml(const std::string& file_name) const
2670 {
2671  xml_document document;
2672  xml_element* root = document.create_root_node(STR_XML_gcc_root);
2674  xml_element* parameter_values_xml = optimizations->add_child_element(STR_XML_gcc_parameter_values);
2675  std::map<std::string, int>::const_iterator parameter_value, parameter_value_end = this->parameter_values.end();
2676  for(parameter_value = this->parameter_values.begin(); parameter_value != parameter_value_end; ++parameter_value)
2677  {
2678  xml_element* parameter_value_xml = parameter_values_xml->add_child_element(STR_XML_gcc_parameter_value);
2679  parameter_value_xml->set_attribute(STR_XML_gcc_name, parameter_value->first);
2680  parameter_value_xml->set_attribute(STR_XML_gcc_value, std::to_string(parameter_value->second));
2681  }
2682  xml_element* optimization_flags_xml = optimizations->add_child_element(STR_XML_gcc_parameter_values);
2683  std::map<std::string, bool>::const_iterator optimization_flag,
2684  optimization_flag_end = this->optimization_flags.end();
2685  for(optimization_flag = this->optimization_flags.begin(); optimization_flag != optimization_flag_end;
2686  ++optimization_flag)
2687  {
2688  xml_element* optimization_flag_xml = optimization_flags_xml->add_child_element(STR_XML_gcc_optimization_flag);
2689  optimization_flag_xml->set_attribute(STR_XML_gcc_name, optimization_flag->first);
2690  optimization_flag_xml->set_attribute(STR_XML_gcc_value, STR(optimization_flag->second));
2691  }
2692  xml_element* optimization_values_xml = optimizations->add_child_element(STR_XML_gcc_parameter_values);
2693  std::map<std::string, int>::const_iterator optimization_value,
2694  optimization_value_end = this->optimization_values.end();
2695  for(optimization_value = this->optimization_values.begin(); optimization_value != optimization_value_end;
2696  ++optimization_value)
2697  {
2698  xml_element* optimization_value_xml = optimization_values_xml->add_child_element(STR_XML_gcc_optimization_value);
2699  optimization_value_xml->set_attribute(STR_XML_gcc_name, optimization_value->first);
2700  optimization_value_xml->set_attribute(STR_XML_gcc_value, STR(optimization_value->second));
2701  }
2702  document.write_to_file_formatted(file_name);
2703 }
2704 
2705 const std::string CompilerWrapper::AddSourceCodeIncludes(const std::list<std::string>& source_files) const
2706 {
2707  std::string includes;
2709  for(const auto& source_file : source_files)
2710  {
2711  std::filesystem::path absolute_path = std::filesystem::absolute(source_file);
2712  std::string new_path = "-iquote " + absolute_path.parent_path().string() + " ";
2713 #ifdef _WIN32
2714  boost::replace_all(new_path, "\\", "/");
2715 #endif
2716  if(frontend_compiler_parameters.find(new_path) == std::string::npos &&
2717  includes.find(new_path) == std::string::npos)
2718  {
2719  includes += new_path;
2720  }
2721  }
2722  return includes;
2723 }
2724 
2726  const std::string& fname) const
2727 {
2728  const auto& compiler = GetCompiler();
2729  auto plugin_prefix = add_plugin_prefix(compiler_target);
2730  const auto& expandMemOps_plugin_name = compiler.expandMemOps_plugin_name;
2731  const auto& GepiCanon_plugin_name = compiler.GepiCanon_plugin_name;
2732  const auto& CSROA_plugin_name = compiler.CSROA_plugin_name;
2733 #ifndef _WIN32
2734  const auto& expandMemOps_plugin_obj = compiler.expandMemOps_plugin_obj;
2735  const auto& GepiCanon_plugin_obj = compiler.GepiCanon_plugin_obj;
2736  const auto& CSROA_plugin_obj = compiler.CSROA_plugin_obj;
2737 #endif
2738 
2739  const auto opt_level = WriteOptimizationLevel(optimization_set == CompilerWrapper_OptimizationSet::O0 ?
2741  optimization_set);
2742 
2743  std::string recipe;
2744 #ifndef _WIN32
2745  recipe += load_plugin_opt(expandMemOps_plugin_obj, compiler_target);
2746 
2747  if(Param->IsParameter("enable-CSROA") && Param->GetParameter<int>("enable-CSROA") == 1 &&
2748  !GepiCanon_plugin_obj.empty())
2749  {
2750  recipe += load_plugin_opt(GepiCanon_plugin_obj, compiler_target);
2751  }
2752 #endif
2753 
2754  if(Param->IsParameter("enable-CSROA") && Param->GetParameter<int>("enable-CSROA") == 1
2755 #ifndef _WIN32
2756  && !CSROA_plugin_obj.empty()
2757 #endif
2758  )
2759  {
2760 #ifndef _WIN32
2761  recipe += load_plugin_opt(CSROA_plugin_obj, compiler_target);
2762 #endif
2763  recipe += " -panda-KN=" + fname;
2764  if(Param->IsParameter("max-CSROA"))
2765  {
2766  auto max_CSROA = Param->GetParameter<int>("max-CSROA");
2767  recipe += " -csroa-max-transformations=" + STR(max_CSROA);
2768  }
2769  }
2770 
2772  {
2773  if(optimization_set == CompilerWrapper_OptimizationSet::O2 ||
2774  optimization_set == CompilerWrapper_OptimizationSet::O3)
2775  {
2776  std::string complex_recipe;
2777  complex_recipe += " -tti -targetlibinfo -tbaa -scoped-noalias -assumption-cache-tracker -profile-summary-info "
2778  "-forceattrs -inferattrs " +
2779  ("-" + expandMemOps_plugin_name) + " -domtree -mem2reg ";
2780  if(Param->IsParameter("enable-CSROA") && Param->GetParameter<int>("enable-CSROA") == 1
2781 #ifndef _WIN32
2782  && !GepiCanon_plugin_obj.empty() && !CSROA_plugin_obj.empty()
2783 #endif
2784  )
2785  {
2786  complex_recipe +=
2787  ("-" + GepiCanon_plugin_name + "PS ") + ("-" + GepiCanon_plugin_name + "COL ") +
2788  ("-" + GepiCanon_plugin_name + "BVR ") +
2789  "-loops -loop-simplify -lcssa-verification -lcssa -basicaa -aa -scalar-evolution -loop-unroll " +
2790  ("-" + CSROA_plugin_name + "FV ") +
2791  "-ipsccp -globaldce -domtree -mem2reg -deadargelim -basiccg -argpromotion -domtree -loops "
2792  "-loop-simplify -lcssa-verification -lcssa -basicaa -aa -scalar-evolution -loop-unroll "
2793  "-simplifycfg ";
2794  }
2795  if(Param->IsParameter("enable-CSROA") && Param->GetParameter<int>("enable-CSROA") == 1
2796 #ifndef _WIN32
2797  && !GepiCanon_plugin_obj.empty() && !CSROA_plugin_obj.empty()
2798 #endif
2799  )
2800  {
2801  complex_recipe += "-" + expandMemOps_plugin_name + (" -" + GepiCanon_plugin_name + "PS ") +
2802  ("-" + GepiCanon_plugin_name + "COL ") + ("-" + GepiCanon_plugin_name + "BVR ") +
2803  ("-" + CSROA_plugin_name + "D ");
2804  }
2805  complex_recipe +=
2806  "-ipsccp -globalopt -dse -loop-unroll -instcombine -libcalls-shrinkwrap -tailcallelim -simplifycfg "
2807  "-reassociate -domtree -loops -loop-simplify -lcssa-verification -lcssa -basicaa -aa -scalar-evolution "
2808  "-loop-rotate -licm -loop-unswitch -simplifycfg -domtree -basicaa -aa -dse -loop-unroll -instcombine "
2809  "-loops -loop-simplify -lcssa-verification -lcssa -scalar-evolution -indvars -loop-idiom "
2810  "-loop-deletion "
2811  "-loop-unroll -mldst-motion -aa -memdep -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -gvn "
2812  "-basicaa -aa -memdep -memcpyopt -sccp -domtree -demanded-bits -bdce -basicaa -aa -dse -loop-unroll "
2813  "-instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -basicaa -aa -memdep "
2814  "-dse "
2815  "-loops -loop-simplify -lcssa-verification -lcssa -aa -scalar-evolution -licm -postdomtree -adce "
2816  "-simplifycfg -domtree -basicaa -aa -loop-unroll -instcombine -barrier -elim-avail-extern -basiccg "
2817  "-rpo-functionattrs -globals-aa -float2int -domtree -loops -loop-simplify -lcssa-verification -lcssa "
2818  "-basicaa -aa -scalar-evolution -loop-rotate -loop-accesses -lazy-branch-prob -lazy-block-freq "
2819  "-opt-remark-emitter -loop-distribute -loop-simplify -lcssa-verification -lcssa -branch-prob "
2820  "-block-freq "
2821  "-scalar-evolution -basicaa -aa -loop-accesses -demanded-bits -lazy-branch-prob -lazy-block-freq "
2822  "-opt-remark-emitter -disable-slp-vectorization -disable-loop-vectorization -scalarizer-loop-simplify "
2823  "-scalar-evolution -aa -loop-accesses -loop-load-elim -basicaa -aa -dse -loop-unroll -instcombine "
2824  "-simplifycfg -domtree -basicaa -aa -dse -loop-unroll -instcombine -loops -loop-simplify "
2825  "-lcssa-verification -lcssa -scalar-evolution -loop-unroll ";
2826  if(Param->IsParameter("enable-CSROA") && Param->GetParameter<int>("enable-CSROA") == 1
2827 #ifndef _WIN32
2828  && !GepiCanon_plugin_obj.empty() && !CSROA_plugin_obj.empty()
2829 #endif
2830  )
2831  {
2832  complex_recipe += " -" + expandMemOps_plugin_name + " -" + CSROA_plugin_name + "WI ";
2833  }
2834  complex_recipe +=
2835  "-domtree -basicaa -aa -memdep -dse -aa -memoryssa -early-cse-memssa -constprop -ipsccp -globaldce "
2836  "-domtree -mem2reg -deadargelim -basiccg -argpromotion -domtree -loops -loop-simplify "
2837  "-lcssa-verification "
2838  "-lcssa -basicaa -aa -scalar-evolution -loop-unroll -dse -loop-unroll -instcombine -loop-simplify "
2839  "-lcssa-verification -lcssa -scalar-evolution -licm -alignment-from-assumptions -strip-dead-prototypes "
2840  "-globaldce -constmerge -domtree -loops -branch-prob -block-freq -loop-simplify -lcssa-verification "
2841  "-lcssa -basicaa -aa -scalar-evolution -branch-prob -block-freq -loop-sink -instsimplify ";
2842  recipe += complex_recipe;
2843  }
2844  else
2845  {
2846  recipe += " -O" + opt_level + " -disable-slp-vectorization -disable-loop-vectorization -scalarizer";
2847  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2848  }
2849  }
2851  {
2852  recipe += " -O" + opt_level + " -disable-slp-vectorization -disable-loop-vectorization -scalarizer";
2853  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2854  }
2856  {
2857  recipe += " -O" + opt_level + " -disable-slp-vectorization -disable-loop-vectorization -scalarizer";
2858  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2859  }
2861  {
2862  recipe += " -O" + opt_level + " -disable-slp-vectorization -disable-loop-vectorization -scalarizer";
2863  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2864  }
2866  {
2867  recipe += " -O" + opt_level + " -disable-slp-vectorization -disable-loop-vectorization -scalarizer";
2868  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2869  }
2871  {
2872  recipe += " -O" + opt_level + " -disable-slp-vectorization -scalarizer";
2873  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2874  }
2876  {
2877  recipe += " -O" + opt_level + " -disable-slp-vectorization -scalarizer";
2878  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2879  }
2881  {
2882  recipe += " -O" + opt_level + " --disable-vector-combine -vectorize-loops=false -vectorize-slp=false -scalarizer";
2883  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2884  }
2886  {
2887  recipe += " -O" + opt_level + " --disable-vector-combine -vectorize-loops=false -vectorize-slp=false -scalarizer";
2888  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2889  }
2891  {
2892  recipe += " -O" + opt_level + " --disable-vector-combine -vectorize-loops=false -vectorize-slp=false -scalarizer";
2893  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2894  }
2896  {
2898  " --disable-vector-combine -vectorize-loops=false -vectorize-slp=false " + plugin_prefix + "scalarizer";
2899  recipe += plugin_prefix + expandMemOps_plugin_name + plugin_prefix + "simplifycfg ";
2900  }
2902  {
2903  recipe += " -O" + opt_level + " --disable-vector-combine -scalarizer";
2904  recipe += " -" + expandMemOps_plugin_name + " -simplifycfg ";
2905  }
2906  else
2907  {
2908  THROW_ERROR("Clang compiler not yet supported");
2909  }
2910  return " " + recipe;
2911 }
2912 
2914 {
2915  const auto gcc_m32_mx32 = parameters->getOption<std::string>(OPT_gcc_m32_mx32);
2916  if(gcc_m32_mx32 == "-m32" || gcc_m32_mx32 == "-m32 -mno-sse2")
2917  {
2918  return 32;
2919  }
2920  else if(gcc_m32_mx32 == "-mx32")
2921  {
2922  return 32;
2923  }
2924  else if(gcc_m32_mx32 == "-m64")
2925  {
2926  return 64;
2927  }
2928  else
2929  {
2930  THROW_ERROR("-m parameter not supported: " + gcc_m32_mx32);
2931  }
2932  return 0;
2933 }
2934 
2936 {
2937  if(isGccCheck(ct) ^ isGccCheck(compare))
2938  {
2939  THROW_ERROR("Comparisong between different compiler families not possible");
2940  }
2941  return ct >= compare;
2942 }
2943 
2945 {
2958 }
2959 
2961 {
2965 }
2966 
2968 {
2969  return 0
2970 #if HAVE_I386_GCC49_COMPILER
2972 #endif
2973 #if HAVE_I386_GCC5_COMPILER
2975 #endif
2976 #if HAVE_I386_GCC6_COMPILER
2978 #endif
2979 #if HAVE_I386_GCC7_COMPILER
2981 #endif
2982 #if HAVE_I386_GCC8_COMPILER
2984 #endif
2985 #if HAVE_I386_CLANG4_COMPILER
2987 #endif
2988 #if HAVE_I386_CLANG5_COMPILER
2990 #endif
2991 #if HAVE_I386_CLANG6_COMPILER
2993 #endif
2994 #if HAVE_I386_CLANG7_COMPILER
2996 #endif
2997 #if HAVE_I386_CLANG8_COMPILER
2999 #endif
3000 #if HAVE_I386_CLANG9_COMPILER
3002 #endif
3003 #if HAVE_I386_CLANG10_COMPILER
3005 #endif
3006 #if HAVE_I386_CLANG11_COMPILER
3008 #endif
3009 #if HAVE_I386_CLANG12_COMPILER
3011 #endif
3012 #if HAVE_I386_CLANG13_COMPILER
3014 #endif
3015 #if HAVE_I386_CLANG16_COMPILER
3017 #endif
3018 #if HAVE_I386_CLANGVVD_COMPILER
3020 #endif
3021  ;
3022 }
3023 
3025 {
3026  return
3027 #if HAVE_I386_CLANG7_COMPILER && defined(_WIN32)
3029 #elif HAVE_I386_GCC49_COMPILER
3031 #elif HAVE_I386_GCC8_COMPILER
3033 #elif HAVE_I386_GCC7_COMPILER
3035 #elif HAVE_I386_GCC6_COMPILER
3037 #elif HAVE_I386_GCC5_COMPILER
3039 #elif HAVE_I386_CLANG4_COMPILER
3041 #elif HAVE_I386_CLANG5_COMPILER
3043 #elif HAVE_I386_CLANG6_COMPILER
3045 #elif HAVE_I386_CLANG7_COMPILER
3047 #elif HAVE_I386_CLANG8_COMPILER
3049 #elif HAVE_I386_CLANG9_COMPILER
3051 #elif HAVE_I386_CLANG10_COMPILER
3053 #elif HAVE_I386_CLANG11_COMPILER
3055 #elif HAVE_I386_CLANG12_COMPILER
3057 #elif HAVE_I386_CLANG13_COMPILER
3059 #elif HAVE_I386_CLANG16_COMPILER
3061 #elif HAVE_I386_CLANGVVD_COMPILER
3063 #else
3064  0;
3065  THROW_ERROR("No frontend compiler available");
3066 #endif
3067 }
3068 
3070 {
3071  switch(pc)
3072  {
3074  return "gcc49";
3076  return "gcc5";
3078  return "gcc6";
3080  return "gcc7";
3082  return "gcc8";
3084  return "clang4";
3086  return "clang5";
3088  return "clang6";
3090  return "clang7";
3092  return "clang8";
3094  return "clang9";
3096  return "clang10";
3098  return "clang11";
3100  return "clang12";
3102  return "clang13";
3104  return "clang16";
3106  return "clangvvd";
3108  default:
3109  THROW_ERROR("no compiler supported");
3110  return "";
3111  }
3112 }
3113 
3114 #pragma GCC diagnostic push
3115 #pragma GCC diagnostic ignored "-Wunused-parameter"
3116 
3118 {
3119  return false
3120 #if(HAVE_I386_GCC49_COMPILER && HAVE_I386_GCC49_M64)
3122 #endif
3123 #if(HAVE_I386_GCC5_COMPILER && HAVE_I386_GCC5_M64)
3125 #endif
3126 #if(HAVE_I386_GCC6_COMPILER && HAVE_I386_GCC6_M64)
3128 #endif
3129 #if(HAVE_I386_GCC7_COMPILER && HAVE_I386_GCC7_M64)
3131 #endif
3132 #if(HAVE_I386_GCC8_COMPILER && HAVE_I386_GCC8_M64)
3134 #endif
3135 #if(HAVE_I386_CLANG4_COMPILER && HAVE_I386_CLANG4_M64)
3137 #endif
3138 #if(HAVE_I386_CLANG5_COMPILER && HAVE_I386_CLANG5_M64)
3140 #endif
3141 #if(HAVE_I386_CLANG6_COMPILER && HAVE_I386_CLANG6_M64)
3143 #endif
3144 #if(HAVE_I386_CLANG7_COMPILER && HAVE_I386_CLANG7_M64)
3146 #endif
3147 #if(HAVE_I386_CLANG8_COMPILER && HAVE_I386_CLANG8_M64)
3149 #endif
3150 #if(HAVE_I386_CLANG9_COMPILER && HAVE_I386_CLANG9_M64)
3152 #endif
3153 #if(HAVE_I386_CLANG10_COMPILER && HAVE_I386_CLANG10_M64)
3155 #endif
3156 #if(HAVE_I386_CLANG11_COMPILER && HAVE_I386_CLANG11_M64)
3158 #endif
3159 #if(HAVE_I386_CLANG12_COMPILER && HAVE_I386_CLANG12_M64)
3161 #endif
3162 #if(HAVE_I386_CLANG13_COMPILER && HAVE_I386_CLANG13_M64)
3164 #endif
3165 #if(HAVE_I386_CLANG16_COMPILER && HAVE_I386_CLANG16_M64)
3167 #endif
3168 #if(HAVE_I386_CLANGVVD_COMPILER && HAVE_I386_CLANGVVD_M64)
3170 #endif
3171  ;
3172 }
3173 
3175 {
3176  return false
3177 #if(HAVE_I386_GCC49_COMPILER && HAVE_I386_GCC49_MX32)
3179 #endif
3180 #if(HAVE_I386_GCC5_COMPILER && HAVE_I386_GCC5_MX32)
3182 #endif
3183 #if(HAVE_I386_GCC6_COMPILER && HAVE_I386_GCC6_MX32)
3185 #endif
3186 #if(HAVE_I386_GCC7_COMPILER && HAVE_I386_GCC7_MX32)
3188 #endif
3189 #if(HAVE_I386_GCC8_COMPILER && HAVE_I386_GCC8_MX32)
3191 #endif
3192 #if(HAVE_I386_CLANG4_COMPILER && HAVE_I386_CLANG4_MX32)
3194 #endif
3195 #if(HAVE_I386_CLANG5_COMPILER && HAVE_I386_CLANG5_MX32)
3197 #endif
3198 #if(HAVE_I386_CLANG6_COMPILER && HAVE_I386_CLANG6_MX32)
3200 #endif
3201 #if(HAVE_I386_CLANG7_COMPILER && HAVE_I386_CLANG7_MX32)
3203 #endif
3204 #if(HAVE_I386_CLANG8_COMPILER && HAVE_I386_CLANG8_MX32)
3206 #endif
3207 #if(HAVE_I386_CLANG9_COMPILER && HAVE_I386_CLANG9_MX32)
3209 #endif
3210 #if(HAVE_I386_CLANG10_COMPILER && HAVE_I386_CLANG10_MX32)
3212 #endif
3213 #if(HAVE_I386_CLANG11_COMPILER && HAVE_I386_CLANG11_MX32)
3215 #endif
3216 #if(HAVE_I386_CLANG12_COMPILER && HAVE_I386_CLANG12_MX32)
3218 #endif
3219 #if(HAVE_I386_CLANG13_COMPILER && HAVE_I386_CLANG13_MX32)
3221 #endif
3222 #if(HAVE_I386_CLANG16_COMPILER && HAVE_I386_CLANG16_MX32)
3224 #endif
3225 #if(HAVE_I386_CLANGVVD_COMPILER && HAVE_I386_CLANGVVD_MX32)
3227 #endif
3228  ;
3229 }
3230 
3232 {
3233  return false
3234 #if(HAVE_I386_GCC49_COMPILER && HAVE_I386_GCC49_M32)
3236 #endif
3237 #if(HAVE_I386_GCC5_COMPILER && HAVE_I386_GCC5_M32)
3239 #endif
3240 #if(HAVE_I386_GCC6_COMPILER && HAVE_I386_GCC6_M32)
3242 #endif
3243 #if(HAVE_I386_GCC7_COMPILER && HAVE_I386_GCC7_M32)
3245 #endif
3246 #if(HAVE_I386_GCC8_COMPILER && HAVE_I386_GCC8_M32)
3248 #endif
3249  ;
3250 }
3251 
3253 {
3254  return false
3255 #if(HAVE_I386_CLANG4_COMPILER && HAVE_I386_CLANG4_M32)
3257 #endif
3258 #if(HAVE_I386_CLANG5_COMPILER && HAVE_I386_CLANG5_M32)
3260 #endif
3261 #if(HAVE_I386_CLANG6_COMPILER && HAVE_I386_CLANG6_M32)
3263 #endif
3264 #if(HAVE_I386_CLANG7_COMPILER && HAVE_I386_CLANG7_M32)
3266 #endif
3267 #if(HAVE_I386_CLANG8_COMPILER && HAVE_I386_CLANG8_M32)
3269 #endif
3270 #if(HAVE_I386_CLANG9_COMPILER && HAVE_I386_CLANG9_M32)
3272 #endif
3273 #if(HAVE_I386_CLANG10_COMPILER && HAVE_I386_CLANG10_M32)
3275 #endif
3276 #if(HAVE_I386_CLANG11_COMPILER && HAVE_I386_CLANG11_M32)
3278 #endif
3279 #if(HAVE_I386_CLANG12_COMPILER && HAVE_I386_CLANG12_M32)
3281 #endif
3282 #if(HAVE_I386_CLANG13_COMPILER && HAVE_I386_CLANG13_M32)
3284 #endif
3285 #if(HAVE_I386_CLANG16_COMPILER && HAVE_I386_CLANG16_M32)
3287 #endif
3288 #if(HAVE_I386_CLANGVVD_COMPILER && HAVE_I386_CLANGVVD_M32)
3290 #endif
3291  ;
3292 }
3293 
3294 #pragma GCC diagnostic pop
3295 
3297 {
3298 #if HAVE_I386_GCC49_COMPILER
3299  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC49))
3300  {
3301  return I386_GCC49_VERSION;
3302  }
3303 #endif
3304 #if HAVE_I386_GCC5_COMPILER
3305  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC5))
3306  {
3307  return I386_GCC5_VERSION;
3308  }
3309 #endif
3310 #if HAVE_I386_GCC6_COMPILER
3311  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC6))
3312  {
3313  return I386_GCC6_VERSION;
3314  }
3315 #endif
3316 #if HAVE_I386_GCC7_COMPILER
3317  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC7))
3318  {
3319  return I386_GCC7_VERSION;
3320  }
3321 #endif
3322 #if HAVE_I386_GCC8_COMPILER
3323  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC8))
3324  {
3325  return I386_GCC8_VERSION;
3326  }
3327 #endif
3328 #if HAVE_I386_CLANG4_COMPILER
3329  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG4))
3330  {
3331  return I386_CLANG4_VERSION;
3332  }
3333 #endif
3334 #if HAVE_I386_CLANG5_COMPILER
3335  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG5))
3336  {
3337  return I386_CLANG5_VERSION;
3338  }
3339 #endif
3340 #if HAVE_I386_CLANG6_COMPILER
3341  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG6))
3342  {
3343  return I386_CLANG6_VERSION;
3344  }
3345 #endif
3346 #if HAVE_I386_CLANG7_COMPILER
3347  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG7))
3348  {
3349  return I386_CLANG7_VERSION;
3350  }
3351 #endif
3352 #if HAVE_I386_CLANG8_COMPILER
3353  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG8))
3354  {
3355  return I386_CLANG8_VERSION;
3356  }
3357 #endif
3358 #if HAVE_I386_CLANG9_COMPILER
3359  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG9))
3360  {
3361  return I386_CLANG9_VERSION;
3362  }
3363 #endif
3364 #if HAVE_I386_CLANG10_COMPILER
3365  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG10))
3366  {
3367  return I386_CLANG10_VERSION;
3368  }
3369 #endif
3370 #if HAVE_I386_CLANG11_COMPILER
3371  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG11))
3372  {
3373  return I386_CLANG11_VERSION;
3374  }
3375 #endif
3376 #if HAVE_I386_CLANG12_COMPILER
3377  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG12))
3378  {
3379  return I386_CLANG12_VERSION;
3380  }
3381 #endif
3382 #if HAVE_I386_CLANG13_COMPILER
3383  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG13))
3384  {
3385  return I386_CLANG13_VERSION;
3386  }
3387 #endif
3388 #if HAVE_I386_CLANG16_COMPILER
3389  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG16))
3390  {
3391  return I386_CLANG16_VERSION;
3392  }
3393 #endif
3394 #if HAVE_I386_CLANGVVD_COMPILER
3395  if(pc & static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANGVVD))
3396  {
3397  return I386_CLANGVVD_VERSION;
3398  }
3399 #endif
3400  THROW_ERROR("");
3401  return "";
3402 }
3403 
3404 std::string CompilerWrapper::readExternalSymbols(const std::string& filename) const
3405 {
3406  std::string extern_symbols;
3407  const auto XMLfilename = [&]() -> std::string {
3408  if(Param->isOption(OPT_xml_memory_allocation))
3409  {
3410  return Param->getOption<std::string>(OPT_xml_memory_allocation);
3411  }
3413  const auto output_temporary_directory = Param->getOption<std::string>(OPT_output_temporary_directory);
3414  const auto leaf_name = std::filesystem::path(filename).filename().string();
3415  const auto generate_xml = output_temporary_directory + "/" + leaf_name + ".memory_allocation.xml";
3416  if((std::filesystem::exists(std::filesystem::path(generate_xml))))
3417  {
3418  return generate_xml;
3419  }
3420  return std::string("");
3421  }();
3422  if(XMLfilename.size())
3423  {
3424  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->parsing " + XMLfilename);
3425  XMLDomParser parser(XMLfilename);
3426  parser.Exec();
3427  if(parser)
3428  {
3429  const xml_element* node = parser.get_document()->get_root_node(); // deleted by DomParser.
3430  const xml_node::node_list list = node->get_children();
3431  for(const auto& l : list)
3432  {
3433  if(const auto* child = GetPointer<xml_element>(l))
3434  {
3435  if(child->get_name() == "memory_allocation")
3436  {
3437  for(const auto& it : child->get_children())
3438  {
3439  if(const auto* mem_node = GetPointer<xml_element>(it))
3440  {
3441  if(mem_node->get_name() == "object")
3442  {
3443  std::string is_internal;
3444  if(!CE_XVM(is_internal, mem_node))
3445  {
3446  THROW_ERROR("expected the is_internal attribute");
3447  }
3448  LOAD_XVM(is_internal, mem_node);
3449  if(is_internal == "T")
3450  {
3451  }
3452  else if(is_internal == "F")
3453  {
3454  if(!CE_XVM(name, mem_node))
3455  {
3456  THROW_ERROR("expected the name attribute");
3457  }
3458  std::string name;
3459  LOAD_XVM(name, mem_node);
3460  extern_symbols += name + ",";
3461  }
3462  else
3463  {
3464  THROW_ERROR("unexpected value for is_internal attribute");
3465  }
3466  }
3467  }
3468  }
3469  }
3470  }
3471  }
3472  }
3473  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--parsed file " + XMLfilename);
3474  }
3475  return extern_symbols;
3476 }
3477 
3478 std::string CompilerWrapper::load_plugin(const std::string& plugin_obj, CompilerWrapper_CompilerTarget target) const
3479 {
3482  {
3483  return " -fpass-plugin=" + plugin_obj + " -Xclang -load -Xclang " + plugin_obj;
3484  }
3485  return " -fplugin=" + plugin_obj;
3486 }
3487 
3489 {
3490  boost::replace_all(plugin_obj, ".so", "_opt.so");
3491  auto flags = " -load=" + plugin_obj;
3494  {
3495  flags += " -load-pass-plugin=" + plugin_obj;
3496  }
3497  return flags;
3498 }
3499 
3501 {
3502  std::string flags;
3503  if(O_level.size())
3504  {
3506  {
3507  flags += " -p 'default<O" + O_level + ">'";
3508  }
3509  else
3510  {
3511  flags += " -O" + O_level;
3512  }
3513  }
3514  else
3515  {
3517  {
3518  flags += " -p ";
3519  }
3520  else
3521  {
3522  flags += " -";
3523  }
3524  }
3525  return flags;
3526 }
int debug_level
debug level
static size_t CGetPointerSize(const ParameterConstRef parameters)
Return the size of the pointer in bit.
std::string load_plugin_opt(std::string plugin_obj, CompilerWrapper_CompilerTarget target) const
std::string get_value() const
Get the value of this attribute.
void InitializeCompilerParameters()
Initialize the frontend compiler parameters line.
std::map< std::string, int > parameter_values
The values of optimizations parameters.
std::string expandMemOps_plugin_obj
The plugin expanding MemOps calls.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
std::string GetAnalyzeCompiler() const
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
static int getCompatibleCompilers()
void SetCompilerDefault()
Set the default options for the frontend compiler.
const std::string AddSourceCodeIncludes(const std::list< std::string > &source_files) const
Add includes of source file directories.
File containing functions and utilities to support the printing of debug messagges.
std::string WriteOptimizationsString()
Write the string containing the frontend compiler optimization options.
void GetSystemIncludes(std::vector< std::string > &includes) const
Return the list of the frontend compiler system includes.
#define OUTPUT_LEVEL_NONE
no output print is performed.
#define STR_CST_string_separator
The character used to separate concatenated string.
Definition: utility.hpp:61
error during compilation
Definition: exceptions.hpp:332
#define STR_XML_gcc_undefines
Node containing information about undefines.
#define STR_XML_gcc_includes
Node containing information about includes.
string target
Definition: lenet_tvm.py:16
std::string filename
static std::string bambu_ir_info
The version of the frontend compiler.
Class storing information of a compiler.
#define STR_XML_gcc_parameter_value
Node containing information about a parameter value.
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
#define STR_XML_gcc_name
Attribute containing information about name of optimization/parameter.
std::string CSROA_plugin_obj
The plugin performing Custom Scalar Replacement of Aggregates.
std::string gcc
The compiler frontend executable.
#define INDENT_OUT_MEX(outLevel, curOutLevel, mex)
std::string clang_recipes(const CompilerWrapper_OptimizationSet optimization_level, const std::string &fname) const
std::map< std::string, int > optimization_values
The value of parametric activate optimizations.
#define STR_CST_string_sizeof
The string used to replace sizeof keyword in the original source code (second step) ...
exceptions managed by PandA
#define STR_XML_gcc_optimization_flag
Node containing information about an optimization flag.
static int getDefaultCompiler()
static bool hasCompilerM64(CompilerWrapper_CompilerTarget ct)
void WriteXml(const std::string &file_name) const
Write the frontend compiler configuration on file.
CompilerWrapper(const ParameterConstRef Param, const CompilerWrapper_CompilerTarget _compiler_target, const CompilerWrapper_OptimizationSet OS)
Constructor.
Specification of the tree (GCC raw) parsing interface function.
#define CE_XVM(variable, node)
Check existence XML Value Macro. Check if an XML attribute is present in the XML tree.
Definition: xml_helper.hpp:88
static bool isCurrentOrNewer(CompilerWrapper_CompilerTarget ct, CompilerWrapper_CompilerTarget compare)
static bool isGccCheck(CompilerWrapper_CompilerTarget ct)
std::string ssa_plugin_obj
The plugin to dump ssa gimple.
#define STR_XML_gcc_defines
Node containing information about defines.
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
Include a set of utilities used to manage CPU time measures.
CompilerWrapper_OptimizationSet
Possible optimization sets.
const CompilerWrapper_OptimizationSet OS
The set of optimizations to be applied.
std::map< std::string, bool > optimization_flags
The set of activated optimizations.
#define STR_XML_gcc_parameter_values
Node containing information about parameter values.
#define THROW_WARNING(str_expr)
helper function used to throw a warning in a standard way: though it uses PRINT_DBG_MEX, the debug level used is such that the message is always printed
Definition: exceptions.hpp:300
#define STR(s)
Macro which performs a lexical_cast to a string.
void line(int x1, int y1, int x2, int y2, unsigned int color)
Definition: main.c:110
Auxiliary methods for manipulating string.
const CompilerWrapper_CompilerTarget compiler_target
The target compiler to be used.
int key[32]
Definition: aes.h:67
bool IsError(const int error_value)
Utility include.
Definition: exceptions.cpp:58
std::string llvm_opt
The clang llvm-opt executable.
const ParameterConstRef Param
The set of input parameters.
void CompileFile(std::string &input_filename, const std::string &output_file, const std::string &parameters_line, int cm, const std::string &costTable)
Invoke the frontend compiler to compile file(s)
std::string GetCompilerParameters(const std::string &extra_compiler_options, bool no_frontend_compiler_parameters=false) const
std::string GepiCanon_plugin_obj
The plugin canocalizing GEPIs.
std::filesystem::path unique_path(const std::filesystem::path &model)
Definition: fileIO.cpp:286
void ReadParameters()
Analyze the command line options.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
#define START_TIME(time_var)
Macro used to store the start time into time_var.
Definition: cpu_time.hpp:133
#define STR_XML_gcc_warnings
Node containing information about warnings.
std::string topfname_plugin_obj
The plugin making visible only the top function.
#define STR_CST_file_IO_shell_output_file
The file used to store shell output.
#define STR_CST_gcc_output
The file where output messages of gcc are saved.
void CopyFile(std::filesystem::path file_source, std::filesystem::path file_target)
Copy file; if target already exist, overwrite.
Definition: fileIO.hpp:187
#define STR_CST_bambu_ir_suffix
The suffix of gimple files.
void dump_exec_time(const std::string &thing, long et)
Definition: cpu_time.hpp:126
#define STR_XML_gcc_optimization_values
Node containing information about optimization values.
#define STR_CST_gcc_obj_file
The output file for tree-panda-gcc.
HLSFlowStep_Type
Definition: hls_step.hpp:95
constants used in Input/Output
void QueryCompilerConfig(const std::string &compiler_option) const
Function that print of stdout some useful information passing the given option.
void write_to_file_formatted(const std::filesystem::path &filename)
Write the document to a file.
#define STOP_TIME(time_var)
Macro used to store the elapsed time into time_var.
Definition: cpu_time.hpp:136
xml_element * create_root_node(const std::string &_name)
Creates the root node.
XML DOM parser.
XML DOM parser.
utility function used to read files.
CompilerWrapper_CompilerTarget
target of the compiler
#define STR_XML_gcc_root
The root node of a gcc configuration.
Classes specification of the tree_node data structures.
#define STR_XML_gcc_standard
Node containing information about standard.
xml_attribute * get_attribute(const std::string &name) const
Obtain the attribute with this name.
void merge_tree_managers(const tree_managerRef &source_tree_manager)
merge two tree manager: this with TM_source
This file collects some utility functions and macros.
void Exec()
Parse an XML document from a file.
static bool isClangCheck(CompilerWrapper_CompilerTarget ct)
std::list< xml_nodeRef > node_list
type for list of xml nodes
Definition: xml_node.hpp:90
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
std::string load_plugin(const std::string &plugin_obj, CompilerWrapper_CompilerTarget target) const
#define STR_XML_gcc_optimization_value
Node containing information about an optimization value.
std::string ASTAnalyzer_plugin_obj
AST analysis.
list command
Definition: test_panda.py:921
static bool hasCompilerGCCM32(CompilerWrapper_CompilerTarget ct)
static bool hasCompilerMX32(CompilerWrapper_CompilerTarget ct)
static std::string WriteOptimizationLevel(const CompilerWrapper_OptimizationSet optimization_level)
Writes the optimization level as a string.
void ReadXml(const std::string &file_name)
Read the frontend compiler configuration from file.
std::string empty_plugin_obj
The plugin to dump empty gimple.
#define STR_CST_gcc_include
The temporary directory used by compiler.
#define STR_XML_gcc_value
Attribute containing information about value stored in a node.
std::string add_plugin_prefix(CompilerWrapper_CompilerTarget target, std::string O_level="") const
static bool hasCompilerCLANGM32(CompilerWrapper_CompilerTarget ct)
int PandaSystem(const ParameterConstRef Param, const std::string &system_command, bool host_exec, const std::string &output, const unsigned int type, const bool background, const size_t timeout)
System call forcing execution with bash.
Definition: fileIO.cpp:78
std::string extra_options
The extra_options.
Compiler GetCompiler() const
Return the compiler for a given target.
#define OUTPUT_LEVEL_PEDANTIC
verbose debugging print is performed.
std::string GetPath(std::filesystem::path path)
Definition: fileIO.hpp:140
#define STR_CST_panda_sizeof
The string used to replace sizeof keyword in the original source code (first step) ...
Class specification of the tree_reindex support class.
static std::string getCompilerVersion(int ct)
Bambu optimizations for soft float: O3 + -finline-limit=10000.
std::string compiler_linking_parameters
The compiler parameters for executable creation.
#define STR_XML_gcc_library_directories
Node containing information about library_directories.
void FillTreeManager(const tree_managerRef TM, std::vector< std::string > &source_files, const std::string &costTable)
This function fills the tree manager with the nodes created from a set of source files.
CompilerMode
#define STR_XML_gcc_libraries
Node containing information about libraries.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
char str[25]
Definition: fixedptc.c:8
xml_documentRef get_document()
Obtain the parsed document.
void CreateExecutable(const std::list< std::string > &file_names, const std::string &executable_name, const std::string &extra_compiler_options, bool no_frontend_compiler_parameters=false) const
Create an executable starting from source code.
Parameters_FileFormat
File formats.
Definition: Parameter.hpp:261
#define THROW_ERROR_CODE(code, str_expr)
helper function used to throw an error with a code error
Definition: exceptions.hpp:266
int output_level
debug level
std::string llvm_link
The clang llvm-link executable.
static std::string __escape_define(const std::string &str)
this class is used to manage the command-line or XML options.
Bambu optimizationss + OPT_compiler_opt_level.
#define LOAD_XVM(variable, node)
LOAD XML Value Macro. Set a variable starting from an XML value. Conversion is performed if needed...
Definition: xml_helper.hpp:65
Some macro used to interface with the XML library.
node_list const & get_children()
Obtain the list of child nodes.
Definition: xml_node.hpp:310
void util_print_cpu_stats(std::ostream &os)
Definition: cpu_stats.cpp:80
std::string container_to_string(_InputIt first, _InputIt last, const std::string &separator, bool trim_empty=true)
Definition: utility.hpp:122
#define STR_XML_gcc_optimization_flags
Node containing information about optimization flags.
std::string readExternalSymbols(const std::string &filename) const
std::string cpp
The cpp executable.
#define PRINT_OUT_MEX(profLevel, curprofLevel, mex)
void CopyStdout(const std::string &filename)
Copy a file to the standard output.
Definition: fileIO.hpp:106
#define OUTPUT_LEVEL_VERBOSE
verbose debugging print is performed.
void SetBambuDefault()
Set the default options for the frontend compiler in bambu.
Utility managing CPU statistics.
void GetCompilerConfig() const
Dump the frontend compiler configuration.
~CompilerWrapper()
Destructor.
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
std::string relocate_compiler_path(const std::string &path, bool resolve_path=false)
Definition: fileIO.hpp:149
int opt_level
Definition: lenet_tvm.py:15
xml_element * add_child_element(const std::string &name)
Add a child element to this node.
Definition: xml_node.cpp:54
xml_attribute * set_attribute(const std::string &name, const std::string &value)
Set the value of the attribute with this name, and optionally with this namespace.
std::string frontend_compiler_parameters
The frontend compiler parameters line for compiling a file.
tree_managerRef ParseTreeFile(const ParameterConstRef &Param, const std::string &f)
Function that parse the dump of the patched GCC.
Definition: parse_tree.cpp:59
Class specification of the manager of the tree structures extracted from the raw file.
#define STR_XML_gcc_optimizations
Node containing information about optimizations.
static std::string getCompilerSuffix(CompilerWrapper_CompilerTarget pc)
bool is_clang
true when compiler is based on clang/llvm
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289
Implementation of the wrapper to Gcc for C sources.

Generated on Mon Feb 12 2024 13:02:56 for PandA-2024.02 by doxygen 1.8.13