PandA-2024.02
compiler_wrapper.hpp
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  */
46 #ifndef COMPILER_WRAPPER_HPP
47 #define COMPILER_WRAPPER_HPP
48 
49 #include "custom_map.hpp"
50 #include "custom_set.hpp"
51 #include "dbgPrintHelper.hpp"
52 #include "refcount.hpp"
53 
54 #include <filesystem>
55 #include <iosfwd>
56 #include <vector>
57 
62 
65 {
66  O0,
67  O1,
68  O2,
69  O3,
70  O4,
71  O5,
72  Og,
73  Os,
74  Oz,
75  Ofast,
76  OBAMBU,
77  OSF,
78 };
79 
84 {
85  CT_NO_COMPILER = 0,
86  CT_I386_GCC49 = 16,
87  CT_I386_GCC5 = 32,
88  CT_I386_GCC6 = 64,
89  CT_I386_GCC7 = 128,
90  CT_I386_GCC8 = 256,
91  CT_I386_CLANG4 = 512,
92  CT_I386_CLANG5 = 1024,
93  CT_I386_CLANG6 = 2048,
94  CT_I386_CLANG7 = 4096,
95  CT_I386_CLANG8 = 8192,
96  CT_I386_CLANG9 = 16384,
97  CT_I386_CLANG10 = 32768,
98  CT_I386_CLANG11 = 65536,
99  CT_I386_CLANG12 = 131072,
100  CT_I386_CLANG13 = 262144,
101  CT_I386_CLANG16 = 524288,
102  CT_I386_CLANGVVD = 1048576
103 };
104 
111 {
112  private:
114  class Compiler
115  {
116  public:
118  std::string cpp;
119 
121  std::string gcc;
122 
124  std::string extra_options;
125 
127  std::string empty_plugin_obj;
128  std::string empty_plugin_name;
129 
131  std::string ssa_plugin_obj;
132  std::string ssa_plugin_name;
133 
137 
139  std::string GepiCanon_plugin_obj;
141 
143  std::string CSROA_plugin_obj;
144  std::string CSROA_plugin_name;
145 
147  std::string topfname_plugin_obj;
148  std::string topfname_plugin_name;
149 
153 
155  std::string llvm_link;
156 
158  std::string llvm_opt;
159 
161  bool is_clang;
162 
163  Compiler() : is_clang(false)
164  {
165  }
166  };
167 
170 
173 
176 
179 
182 
185 
188 
191 
193  std::map<std::string, int> parameter_values;
194 
196  std::map<std::string, bool> optimization_flags;
197 
199  std::map<std::string, int> optimization_values;
200 
209  void CompileFile(std::string& input_filename, const std::string& output_file, const std::string& parameters_line,
210  int cm, const std::string& costTable);
211 
212  std::string GetAnalyzeCompiler() const;
213 
219  void InitializeCompilerParameters();
220 
224  void ReadParameters();
225 
229  void SetCompilerDefault();
230 
234  void SetBambuDefault();
235 
240  std::string WriteOptimizationsString();
241 
247  const std::string AddSourceCodeIncludes(const std::list<std::string>& source_files) const;
248 
249  std::string readExternalSymbols(const std::string& filename) const;
250 
251  std::string clang_recipes(const CompilerWrapper_OptimizationSet optimization_level, const std::string& fname) const;
252 
253  std::string load_plugin(const std::string& plugin_obj, CompilerWrapper_CompilerTarget target) const;
254 
255  std::string load_plugin_opt(std::string plugin_obj, CompilerWrapper_CompilerTarget target) const;
256 
257  std::string add_plugin_prefix(CompilerWrapper_CompilerTarget target, std::string O_level = "") const;
258 
259  public:
261  static std::string bambu_ir_info;
262 
269  CompilerWrapper(const ParameterConstRef Param, const CompilerWrapper_CompilerTarget _compiler_target,
271 
275  ~CompilerWrapper();
276 
281  Compiler GetCompiler() const;
282 
289  void FillTreeManager(const tree_managerRef TM, std::vector<std::string>& source_files, const std::string& costTable);
290 
295  void GetSystemIncludes(std::vector<std::string>& includes) const;
296 
300  void GetCompilerConfig() const;
301 
305  void QueryCompilerConfig(const std::string& compiler_option) const;
306 
307  std::string GetCompilerParameters(const std::string& extra_compiler_options,
308  bool no_frontend_compiler_parameters = false) const;
309 
316  void CreateExecutable(const std::list<std::string>& file_names, const std::string& executable_name,
317  const std::string& extra_compiler_options, bool no_frontend_compiler_parameters = false) const;
318 
325  void CreateExecutable(const CustomSet<std::string>& file_names, const std::string& executable_name,
326  const std::string& extra_compiler_options, bool no_frontend_compiler_parameters = false) const;
327 
332  void ReadXml(const std::string& file_name);
333 
338  void WriteXml(const std::string& file_name) const;
339 
345  static std::string WriteOptimizationLevel(const CompilerWrapper_OptimizationSet optimization_level);
346 
352  static size_t CGetPointerSize(const ParameterConstRef parameters);
353 
354  static bool isCurrentOrNewer(CompilerWrapper_CompilerTarget ct, CompilerWrapper_CompilerTarget compare);
355  static bool isClangCheck(CompilerWrapper_CompilerTarget ct);
356  static bool isGccCheck(CompilerWrapper_CompilerTarget ct);
357  static int getCompatibleCompilers();
358  static int getDefaultCompiler();
359  static std::string getCompilerSuffix(CompilerWrapper_CompilerTarget pc);
360  static bool hasCompilerM64(CompilerWrapper_CompilerTarget ct);
361  static bool hasCompilerMX32(CompilerWrapper_CompilerTarget ct);
362  static bool hasCompilerGCCM32(CompilerWrapper_CompilerTarget ct);
363  static bool hasCompilerCLANGM32(CompilerWrapper_CompilerTarget ct);
364  static std::string getCompilerVersion(int ct);
365 };
366 
370 
371 #endif
int debug_level
debug level
std::map< std::string, int > parameter_values
The values of optimizations parameters.
std::string expandMemOps_plugin_obj
The plugin expanding MemOps calls.
File containing functions and utilities to support the printing of debug messagges.
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.
std::string CSROA_plugin_obj
The plugin performing Custom Scalar Replacement of Aggregates.
std::string gcc
The compiler frontend executable.
This class manages the tree structures extracted from the raw file.
CONSTREF_FORWARD_DECL(Parameter)
std::map< std::string, int > optimization_values
The value of parametric activate optimizations.
std::string ssa_plugin_obj
The plugin to dump ssa gimple.
redefinition of map to manage ordered/unordered structures
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.
const CompilerWrapper_CompilerTarget compiler_target
The target compiler to be used.
std::string llvm_opt
The clang llvm-opt executable.
const ParameterConstRef Param
The set of input parameters.
std::string GepiCanon_plugin_obj
The plugin canocalizing GEPIs.
std::string topfname_plugin_obj
The plugin making visible only the top function.
REF_FORWARD_DECL(application_manager)
redefinition of set to manage ordered/unordered structures
CompilerWrapper_CompilerTarget
target of the compiler
std::string ASTAnalyzer_plugin_obj
AST analysis.
Template definition of refcount.
CustomSet< std::string > already_processed_files
The set of files for which tree manager has already been computed.
std::string empty_plugin_obj
The plugin to dump empty gimple.
std::string extra_options
The extra_options.
Bambu optimizations for soft float: O3 + -finline-limit=10000.
std::string compiler_linking_parameters
The compiler parameters for executable creation.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
int output_level
debug level
std::string llvm_link
The clang llvm-link executable.
Bambu optimizationss + OPT_compiler_opt_level.
Main class for wrapping the frontend compiler.
std::string cpp
The cpp executable.
std::string frontend_compiler_parameters
The frontend compiler parameters line for compiling a file.
bool is_clang
true when compiler is based on clang/llvm

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