2 * @file firm_cmdline.c -- Additional Firm generating backend parameters
4 * Compile when BACK_END_IS_CP_FIRM_BE is defined
6 * (C) 2005 Michael Beck beck@ipd.info.uni-karlsruhe.de
11 #include "firm_cmdline.h"
12 #include <libfirm/firm.h>
13 #include <libfirm/be.h>
15 #if defined(_WIN32) || defined(__CYGWIN__)
16 #define DEFAULT_OS OS_SUPPORT_MINGW
17 #elif defined(__APPLE__)
18 #define DEFAULT_OS OS_SUPPORT_MACHO
20 #define DEFAULT_OS OS_SUPPORT_LINUX
23 /* optimization settings */
24 struct a_firm_opt firm_opt = {
26 /* debug_mode = */ DBG_MODE_NONE,
27 /* const_folding = */ TRUE,
30 /* control_flow = */ TRUE,
33 /* gvn_pre = */ FALSE,
34 /* jumpthreading = */ FALSE,
35 /* if_conversion = */ FALSE,
36 /* func_calls = */ TRUE,
37 /* do_inline = */ FALSE,
38 /* auto_inline = */ TRUE,
39 /* tail_rec = */ TRUE,
40 /* strength_red = */ TRUE,
41 /* scalar_replace = */ TRUE,
46 /* fragile_ops = */ TRUE,
47 /* load_store = */ TRUE,
48 /* load_store_pre = */ FALSE,
50 /* precise_exc = */ FALSE, /* never needed for C */
51 /* use_DivMod = */ FALSE,
52 /* remove_unused = */ TRUE,
53 /* cloning = */ FALSE,
54 /* auto_sync = */ FALSE,
55 /* alias_analysis = */ TRUE,
56 /* strict_alias = */ FALSE,
57 /* no_alias = */ FALSE,
61 /* bool_opt = */ FALSE,
62 /* shape_blocks = */ FALSE,
63 /* freestanding; = */ FALSE,
64 /* fp_model = */ fp_model_precise,
65 /* lower_ll = */ FALSE,
66 /* vrfy = */ FIRM_VERIFICATION_ON,
67 /* check_all = */ FALSE,
69 /* os_support = */ DEFAULT_OS,
70 /* honor_restrict = */ TRUE,
71 /* lower_bitfields = */ TRUE,
73 /* clone_threshold = */ DEFAULT_CLONE_THRESHOLD,
74 /* inline_maxsize = */ 750,
75 /* inline_threshold= */ 0,
76 /* vrfy_edges = */ FALSE,
77 /* grs_simd_opt = */ 0,
78 /* grs_create_pattern = */ 0,
79 /* spare_size = */ 128,
80 /* enable_statev = */ FALSE,
81 /* statev_filter = */ "",
86 struct a_firm_dump firm_dump = {
87 /* debug_print = */ FALSE,
88 /* all_types = */ FALSE,
89 /* no_blocks = */ FALSE,
91 /* ir_graph = */ FALSE,
92 /* all_phases = */ FALSE,
93 /* edge_labels = */ FALSE,
94 /* statistic = */ STAT_NONE,
95 /* stat_pattern = */ 0,
97 /* gen_firm_asm = */ FALSE,
102 struct a_firm_ext_grs firm_ext_grs = {
103 /* simd_opt = */ FALSE,
104 /* create_pattern = */ FALSE
108 struct a_firm_be_opt firm_be_opt = {
109 /* selection = */ BE_FIRM_BE,
113 #define X(a) a, sizeof(a)-1
115 /** Parameter description structure */
116 static const struct params {
117 const char *option; /**< name of the option */
118 int opt_len; /**< length of the option string */
119 a_byte *flag; /**< address of variable to set/reset */
120 a_byte set; /**< iff true, variable will be set, else reset */
121 const char *description; /**< description of this option */
123 /* this must be first */
124 { X("help"), NULL, 0, "print FCC related help options" },
126 /* firm optimization options */
127 { X("pic"), &firm_opt.pic, 1, "firm: generate position independent code" },
128 { X("g0"), &firm_opt.debug_mode, DBG_MODE_BACKSTORE, "firm: Debug Mode: use back stores" },
129 { X("g1"), &firm_opt.debug_mode, DBG_MODE_FULL, "firm: Debug Mode: no register variables" },
130 { X("no-opt"), NULL, 0, "firm: disable all FIRM optimizations" },
131 { X("cse"), &firm_opt.cse, 1, "firm: enable common subexpression elimination" },
132 { X("no-cse"), &firm_opt.cse, 0, "firm: disable common subexpression elimination" },
133 { X("const-fold"), &firm_opt.const_folding, 1, "firm: enable constant folding" },
134 { X("no-const-fold"), &firm_opt.const_folding, 0, "firm: disable constant folding" },
135 { X("control_flow"), &firm_opt.control_flow, 1, "firm: enable control flow optimization" },
136 { X("no-control-flow"), &firm_opt.control_flow, 0, "firm: disable control flow optimization" },
137 { X("combo"), &firm_opt.combo, 1, "firm: enable combined CCE, UCE and GVN" },
138 { X("no-combo"), &firm_opt.combo, 0, "firm: disable combined CCE, UCE and GVN" },
139 { X("gcse"), &firm_opt.gcse, 1, "firm: enable global common subexpression elimination" },
140 { X("no-gcse"), &firm_opt.gcse, 0, "firm: disable global common subexpression elimination" },
141 { X("gvn-pre"), &firm_opt.gvn_pre, 1, "firm: enable GVN partial redundancy elimination" },
142 { X("no-gvn-pre"), &firm_opt.gvn_pre, 0, "firm: disable GVN partial redundancy elimination" },
143 { X("thread-jumps"), &firm_opt.jumpthreading, 1, "firm: enable path-sensitive jumpthreading optimization" },
144 { X("no-thread-jumps"), &firm_opt.jumpthreading, 0, "firm: disable path-sensitive jumpthreading optimization" },
145 { X("if-conv"), &firm_opt.if_conversion, 1, "firm: enable if-conversion optimization" },
146 { X("no-if-conv"), &firm_opt.if_conversion, 0, "firm: disable if-conversion optimization" },
147 { X("opt-func-call"), &firm_opt.func_calls, 1, "firm: enable function call optimization" },
148 { X("no-opt-func-call"), &firm_opt.func_calls, 0, "firm: disable function call optimization" },
149 { X("reassociation"), &firm_opt.reassoc, 1, "firm: enable reassociation" },
150 { X("no-reassociation"), &firm_opt.reassoc, 0, "firm: disable reassociation" },
151 { X("inline"), &firm_opt.do_inline, 1, "firm: enable FIRM inlining" },
152 { X("no-inline"), &firm_opt.do_inline, 0, "firm: disable FIRM inlining" },
153 { X("inline-max-size=<size>"), NULL, 0, "firm: set maximum size for function inlining" },
154 { X("inline-threshold=<size>"),NULL, 0, "firm: set benefice threshold for function inlining" },
155 { X("tail-rec"), &firm_opt.tail_rec, 1, "firm: enable tail-recursion optimization" },
156 { X("no-tail-rec"), &firm_opt.tail_rec, 0, "firm: disable tail-recursion optimization" },
157 { X("strength-red"), &firm_opt.strength_red, 1, "firm: enable strength reduction for loops" },
158 { X("no-strength-red"), &firm_opt.strength_red, 0, "firm: disable strength reduction for loops" },
159 { X("scalar-replace"), &firm_opt.scalar_replace, 1, "firm: enable scalar replacement" },
160 { X("no-scalar-replace"), &firm_opt.scalar_replace, 0, "firm: disable scalar replacement" },
161 { X("confirm"), &firm_opt.confirm, 1, "firm: enable Confirm optimization" },
162 { X("no-confirm"), &firm_opt.confirm, 0, "firm: disable Confirm optimization" },
163 { X("opt-mul"), &firm_opt.muls, 0, "firm: enable multiplication optimization" },
164 { X("no-opt-mul"), &firm_opt.muls, 0, "firm: disable multiplication optimization" },
165 { X("opt-div"), &firm_opt.divs, 0, "firm: enable division optimization" },
166 { X("no-opt-div"), &firm_opt.divs, 0, "firm: disable division optimization" },
167 { X("opt-mod"), &firm_opt.mods, 0, "firm: enable remainder optimization" },
168 { X("no-opt-mod"), &firm_opt.mods, 0, "firm: disable remainder optimization" },
169 { X("opt-fragile-ops"), &firm_opt.fragile_ops, 1, "firm: enable fragile ops optimization" },
170 { X("no-opt-fragile-ops"), &firm_opt.fragile_ops, 0, "firm: disable fragile ops optimization" },
171 { X("opt-load-store"), &firm_opt.load_store, 1, "firm: enable load store optimization" },
172 { X("no-opt-load-store"), &firm_opt.load_store, 0, "firm: disable load store optimization" },
173 { X("opt-load-store-pre"), &firm_opt.load_store_pre, 1, "firm: enable load store optimization and PRE" },
174 { X("no-opt-load-store-pre"), &firm_opt.load_store_pre, 0, "firm: disable load store optimization and PRE" },
175 { X("opt-modes"), &firm_opt.modes, 1, "firm: optimize integer modes" },
176 { X("no-opt-modes"), &firm_opt.modes, 0, "firm: disable integer modes optimization" },
177 { X("sync"), &firm_opt.auto_sync, 1, "firm: automatically create Sync nodes" },
178 { X("no-sync"), &firm_opt.auto_sync, 0, "firm: do not create Sync nodes" },
179 { X("opt-alias"), &firm_opt.alias_analysis, 1, "firm: enable alias analysis" },
180 { X("no-opt-alias"), &firm_opt.alias_analysis, 0, "firm: disable alias analysis" },
181 { X("alias"), &firm_opt.no_alias, 0, "firm: aliasing occurs" },
182 { X("no-alias"), &firm_opt.no_alias, 1, "firm: no aliasing occurs" },
183 { X("strict-aliasing"), &firm_opt.strict_alias, 1, "firm: strict alias rules" },
184 { X("no-strict-aliasing"), &firm_opt.strict_alias, 0, "firm: strict alias rules" },
185 { X("opt-proc-clone"), &firm_opt.cloning, 1, "firm: enable procedure cloning" },
186 { X("no-opt-proc-clone"), &firm_opt.cloning, 0, "firm: disable procedure cloning" },
187 { X("clone-threshold=<value>"),NULL, 0, "firm: set clone threshold to <value>" },
188 { X("DivMod"), &firm_opt.use_DivMod, 1, "firm: use DivMod nodes" },
189 { X("no-DivMod"), &firm_opt.use_DivMod, 0, "firm: don't use DivMod nodes" },
190 { X("precise-except"), &firm_opt.precise_exc, 1, "firm: precise exception context" },
191 { X("no-precise-except"), &firm_opt.precise_exc, 0, "firm: no precise exception context" },
192 { X("remove-unused"), &firm_opt.remove_unused, 1, "firm: remove unused functions" },
193 { X("no-remove-unused"), &firm_opt.remove_unused, 0, "firm: dont't remove unused functions" },
194 { X("fp-precise"), &firm_opt.fp_model, fp_model_precise, "firm: precise fp model" },
195 { X("fp-fast"), &firm_opt.fp_model, fp_model_fast, "firm: fast fp model" },
196 { X("fp-strict"), &firm_opt.fp_model, fp_model_strict, "firm: strict fp model" },
197 { X("sync"), &firm_opt.sync, 1, "firm: use Syncs to remove unnecesary memory dependencies" },
198 { X("no-sync"), &firm_opt.sync, 0, "firm: do not use Syncs to remove unnecesary memory dependencies" },
199 { X("deconv"), &firm_opt.deconv, 1, "firm: enable the conv node optimization" },
200 { X("no-deconv"), &firm_opt.deconv, 0, "firm: disable the conv node optimization" },
201 { X("opt-cc"), &firm_opt.cc_opt, 1, "firm: enable calling conventions optimization" },
202 { X("no-opt-cc"), &firm_opt.cc_opt, 0, "firm: disable calling conventions optimization" },
203 { X("bool"), &firm_opt.bool_opt, 1, "firm: enable bool simplification optimization" },
204 { X("no-bool"), &firm_opt.bool_opt, 0, "firm: disable bool simplification optimization" },
205 { X("shape-blocks"), &firm_opt.shape_blocks, 1, "firm: enable block shaping" },
206 { X("no-shape-blocks"), &firm_opt.shape_blocks, 0, "firm: disable block shaping" },
207 { X("freestanding"), &firm_opt.freestanding, 1, "firm: freestanding environment" },
208 { X("hosted"), &firm_opt.freestanding, 0, "firm: hosted environment" },
209 { X("loop"), &firm_opt.loop, 1, "firm: enable loop peeling and unrolling" },
210 { X("no-loop"), &firm_opt.loop, 0, "firm: disable loop peeling and unrolling" },
212 /* other firm regarding options */
213 { X("restrict"), &firm_opt.honor_restrict, 1, "firm: honor restrict keyword" },
214 { X("no-restrict"), &firm_opt.honor_restrict, 1, "firm: restrict keyword is meaningless" },
215 { X("no-lower"), &firm_opt.lower, 0, "firm: disable lowering" },
216 { X("vrfy-off"), &firm_opt.vrfy, FIRM_VERIFICATION_OFF, "firm: disable node verification" },
217 { X("vrfy-on"), &firm_opt.vrfy, FIRM_VERIFICATION_ON, "firm: enable node verification" },
218 { X("vrfy-report"), &firm_opt.vrfy, FIRM_VERIFICATION_REPORT, "firm: node verification, report only" },
219 { X("check-all"), &firm_opt.check_all, 1, "firm: enable checking all Firm phases" },
220 { X("no-check-all"), &firm_opt.check_all, 0, "firm: disable checking all Firm phases" },
221 { X("vrfy-edges-on"), &firm_opt.vrfy_edges, 1, "firm: enable out edge verification" },
222 { X("vrfy-edges-off"), &firm_opt.vrfy_edges, 0, "firm: disable out edge verification" },
225 #if defined(_DEBUG) || defined(FIRM_DEBUG)
226 { X("debug"), &firm_dump.debug_print, 1, "firm: enable debug output" },
229 { X("dump-ir"), &firm_dump.ir_graph, 1, "firm: dump IR graph" },
230 { X("dump-all-types"), &firm_dump.all_types, 1, "firm: dump graph of all types" },
231 { X("dump-no-blocks"), &firm_dump.no_blocks, 1, "firm: dump non-blocked graph" },
232 { X("dump-extbb"), &firm_dump.extbb, 1, "firm: dump extended basic blocks" },
233 { X("dump-all-phases"), &firm_dump.all_phases, 1, "firm: dump graphs for all optimization phases" },
234 { X("dump-edge-labels"), &firm_dump.edge_labels, 1, "firm: dump edge labels" },
236 /* code generation */
237 { X("no-codegen"), &firm_be_opt.selection, BE_NONE, "cg: disable code generator" },
240 { X("grs-simd-opt"), &firm_ext_grs.simd_opt, 1, "firm: do simd optimization" },
241 { X("grs-create-pattern"), &firm_ext_grs.create_pattern, 1, "firm: create patterns for simd optimization" },
242 { X("no-grs-simd-opt"), &firm_ext_grs.simd_opt, 0, "firm: do simd optimization" },
243 { X("no-grs-create-pattern"), &firm_ext_grs.create_pattern, 0, "firm: create patterns for simd optimization" },
247 { X("be-firm"), &firm_be_opt.selection, BE_FIRM_BE, "backend: firm backend facility" },
248 #endif /* FIRM_BACKEND */
249 #ifdef FIRM2C_BACKEND
250 { X("be-firm2c"), &firm_be_opt.selection, BE_FIRM2C, "backend: firm2C" },
251 #endif /* FIRM2C_BACKEND */
254 { X("stat-before-opt"), &firm_dump.statistic, STAT_BEFORE_OPT, "misc: Firm statistic output before optimizations" },
255 { X("stat-after-opt"), &firm_dump.statistic, STAT_AFTER_OPT, "misc: Firm statistic output after optimizations" },
256 { X("stat-after-lower"), &firm_dump.statistic, STAT_AFTER_LOWER, "misc: Firm statistic output after lowering" },
257 { X("stat-final-ir"), &firm_dump.statistic, STAT_FINAL_IR, "misc: Firm statistic after final optimization" },
258 { X("stat-final"), &firm_dump.statistic, STAT_FINAL, "misc: Firm statistic after code generation" },
259 { X("stat-pattern"), &firm_dump.stat_pattern, 1, "misc: Firm statistic calculates most used pattern" },
260 { X("stat-dag"), &firm_dump.stat_dag, 1, "misc: Firm calculates DAG statistics" },
261 { X("firm-asm"), &firm_dump.gen_firm_asm, 1, "misc: output Firm assembler" },
262 { X("win32"), &firm_opt.os_support, OS_SUPPORT_MINGW, "misc: generate MinGW Win32 code" },
263 { X("mac"), &firm_opt.os_support, OS_SUPPORT_MACHO, "misc: generate MacOS code" },
264 { X("linux"), &firm_opt.os_support, OS_SUPPORT_LINUX, "misc: generate Linux-ELF code" },
267 { X("dump-filter=<string>"), NULL, 0, "misc: set dumper filter" },
272 /** A strdup replacement */
273 static char *StrDup(const char *s) {
275 char *r = malloc(l+1);
283 * Set a dumper filter.
285 static void set_dump_filter(const char *filter)
287 firm_dump.filter = StrDup(filter);
288 } /* set_dump_filter */
290 /** Disable all optimizations. */
291 static void disable_opts(void) {
292 /* firm_opt.const_folding */
293 firm_opt.reassoc = FALSE;
294 firm_opt.cse = FALSE;
295 /* firm_opt.control_flow */
296 firm_opt.gcse = FALSE;
297 firm_opt.gvn_pre = FALSE;
298 firm_opt.jumpthreading = FALSE;
299 firm_opt.if_conversion = FALSE;
300 firm_opt.func_calls = FALSE;
301 firm_opt.do_inline = FALSE;
302 firm_opt.auto_inline = FALSE;
303 firm_opt.tail_rec = FALSE;
304 firm_opt.strength_red = FALSE;
305 firm_opt.scalar_replace = FALSE;
306 firm_opt.confirm = FALSE;
307 firm_opt.muls = FALSE;
308 firm_opt.divs = FALSE;
309 firm_opt.mods = FALSE;
310 firm_opt.fragile_ops = FALSE;
311 firm_opt.load_store = FALSE;
312 firm_opt.remove_unused = FALSE;
313 /* firm_opt.jmp_tbls */
314 firm_opt.cloning = FALSE;
315 /* firm_opt.auto_sync */
316 firm_opt.alias_analysis = FALSE;
317 firm_opt.strict_alias = FALSE;
318 firm_opt.no_alias = FALSE;
319 firm_opt.sync = FALSE;
320 firm_opt.deconv = FALSE;
321 firm_opt.cc_opt = FALSE;
322 firm_opt.bool_opt = FALSE;
323 firm_opt.shape_blocks = FALSE;
324 firm_opt.freestanding = TRUE;
325 firm_opt.loop = FALSE;
329 * Handles a firm option.
331 int firm_option(const char *opt)
333 int i, len = strlen(opt);
337 if (strncmp("dump-filter=", opt, 12) == 0) {
339 set_dump_filter(opt);
342 else if (strncmp("clone-threshold=", opt, 16) == 0) {
343 sscanf(&opt[16], "%d", &firm_opt.clone_threshold);
344 firm_opt.cloning = TRUE;
347 else if (strncmp("inline-max-size=", opt, 16) == 0) {
348 sscanf(&opt[16], "%u", &firm_opt.inline_maxsize);
351 else if (strncmp("inline-threshold=", opt, 17) == 0) {
352 sscanf(&opt[17], "%u", &firm_opt.inline_threshold);
355 else if (strcmp("no-opt", opt) == 0) {
360 for (i = sizeof(firm_options) / sizeof(firm_options[0]) - 1; i >= 0; --i) {
361 if (len == firm_options[i].opt_len && strncmp(p, firm_options[i].option, len) == 0) {
362 if (!firm_options[i].flag) {
364 for (i = 0; i < (int) (sizeof(firm_options)/sizeof(firm_options[0])); ++i) {
365 printf("-f %-20s %s\n", firm_options[i].option,
366 firm_options[i].description);
370 /* statistic options do accumulate */
371 if (firm_options[i].flag == &firm_dump.statistic)
372 *firm_options[i].flag = (a_byte) (*firm_options[i].flag | firm_options[i].set);
374 *firm_options[i].flag = firm_options[i].set;
376 if (firm_options[i].flag == &firm_opt.debug_mode && firm_opt.debug_mode > DBG_MODE_NONE) {
377 if (firm_opt.debug_mode == DBG_MODE_FULL)
380 res &= firm_be_option("omitfp=0");
381 res &= firm_be_option("stabs");
394 * Handles a firm backend option.
396 * The options are here only checked for validity and later transmitted
397 * to the firm backend (in the hope they do not fail ...)
399 int firm_be_option(const char *opt) {
401 return be_parse_arg(opt);
404 #endif /* FIRM_BACKEND */
405 } /* firm_be_option */
408 * prints the firm version number
410 void print_firm_version(FILE *f) {
411 const char *revision = ir_get_version_revision();
412 const char *build = ir_get_version_build();
414 fprintf(f, "Firm C-Compiler using libFirm (%u.%u",
415 ir_get_version_major(), ir_get_version_minor());
416 if (revision[0] != 0) {
425 "(C) 2005-2008 Michael Beck\n"
426 "(C) 1995-2008 University of Karlsruhe\n"
428 } /* print_firm_version */