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 /* optimization settings */
16 struct a_firm_opt firm_opt = {
18 /* debug_mode = */ DBG_MODE_NONE,
19 /* const_folding = */ TRUE,
22 /* control_flow = */ TRUE,
23 /* code_place = */ TRUE,
24 /* gvn_pre = */ FALSE, /* currently buggy */
25 /* cond_eval = */ FALSE,
26 /* if_conversion = */ FALSE,
27 /* loop_unrolling = */ FALSE, /* currently buggy */
28 /* func_calls = */ TRUE,
29 /* do_inline = */ FALSE,
30 /* auto_inline = */ TRUE,
31 /* tail_rec = */ TRUE,
32 /* strength_red = */ TRUE,
33 /* scalar_replace = */ TRUE,
38 /* fragile_ops = */ TRUE,
39 /* load_store = */ TRUE,
41 /* precise_exc = */ FALSE, /* never needed for C */
42 /* use_DivMod = */ FALSE,
43 /* remove_unused = */ TRUE,
44 /* jmp_tbls = */ TRUE,
45 /* cloning = */ FALSE,
46 /* auto_sync = */ TRUE,
47 /* alias_analysis = */ TRUE,
48 /* strict_alias = */ FALSE,
49 /* no_alias = */ FALSE,
53 /* bool_opt = */ FALSE,
54 /* freestanding; = */ FALSE,
55 /* fp_model = */ fp_model_precise,
56 /* lower_ll = */ FALSE,
57 /* vrfy = */ FIRM_VERIFICATION_ON,
58 /* check_all = */ FALSE,
60 /* os_support = */ OS_SUPPORT_LINUX,
61 /* honor_restrict = */ TRUE,
62 /* lower_bitfields = */ TRUE,
63 /* ycomp_dbg = */ FALSE,
64 /* ycomp_host = */ FIRM_YCOMP_DEFAULT_HOST,
65 /* ycomp_port = */ FIRM_YCOMP_DEFAULT_PORT,
66 /* clone_threshold = */ DEFAULT_CLONE_THRESHOLD,
67 /* vrfy_edges = */ FALSE,
68 /* grs_simd_opt = */ 0,
69 /* grs_create_pattern = */ 0,
70 /* spare_size = */ 128,
74 struct a_firm_dump firm_dump = {
75 /* debug_print = */ FALSE,
76 /* all_types = */ FALSE,
77 /* no_blocks = */ FALSE,
79 /* ir_graph = */ FALSE,
80 /* all_phases = */ FALSE,
81 /* edge_labels = */ FALSE,
82 /* statistic = */ STAT_NONE,
83 /* stat_pattern = */ 0,
85 /* gen_firm_asm = */ FALSE,
90 struct a_firm_ext_grs firm_ext_grs = {
91 /* simd_opt = */ FALSE,
92 /* create_pattern = */ FALSE
96 struct a_firm_be_opt firm_be_opt = {
97 /* selection = */ BE_FIRM_BE,
101 #define X(a) a, sizeof(a)-1
103 /** Parameter description structure */
104 static const struct params {
105 const char *option; /**< name of the option */
106 int opt_len; /**< length of the option string */
107 a_byte *flag; /**< address of variable to set/reset */
108 a_byte set; /**< iff true, variable will be set, else reset */
109 const char *description; /**< description of this option */
111 /* this must be first */
112 { X("help"), NULL, 0, "print FCC related help options" },
114 /* firm optimization options */
115 { X("g0"), &firm_opt.debug_mode, DBG_MODE_BACKSTORE, "firm: Debug Mode: use back stores" },
116 { X("g1"), &firm_opt.debug_mode, DBG_MODE_FULL, "firm: Debug Mode: no register variables" },
117 { X("no-opt"), NULL, 0, "firm: disable all FIRM optimizations" },
118 { X("cse"), &firm_opt.cse, 1, "firm: enable common subexpression elimination" },
119 { X("no-cse"), &firm_opt.cse, 0, "firm: disable common subexpression elimination" },
120 { X("const-fold"), &firm_opt.const_folding, 1, "firm: enable constant folding" },
121 { X("no-const-fold"), &firm_opt.const_folding, 0, "firm: disable constant folding" },
122 { X("control_flow"), &firm_opt.control_flow, 1, "firm: enable control flow optimization" },
123 { X("no-control-flow"), &firm_opt.control_flow, 0, "firm: disable control flow optimization" },
124 { X("code-place"), &firm_opt.code_place, 1, "firm: enable GCSE and code placement" },
125 { X("no-code-place"), &firm_opt.code_place, 0, "firm: disable GCSE and code placement" },
126 { X("gvn-pre"), &firm_opt.gvn_pre, 1, "firm: enable GVN partial redundancy elimination" },
127 { X("no-gvn-pre"), &firm_opt.gvn_pre, 0, "firm: disable GVN partial redundancy elimination" },
128 { X("cond-eval"), &firm_opt.cond_eval, 1, "firm: enable partial condition evaluation optimization" },
129 { X("no-cond-eval"), &firm_opt.cond_eval, 0, "firm: disable partial condition evaluation optimization" },
130 { X("if-conv"), &firm_opt.if_conversion, 1, "firm: enable if-conversion optimization" },
131 { X("no-if-conv"), &firm_opt.if_conversion, 0, "firm: disable if-conversion optimization" },
132 { X("opt-loop-unrolling"), &firm_opt.loop_unrolling, 1, "firm: enable loop-unrolling optimization" },
133 { X("no-opt-loop-unrolling"), &firm_opt.loop_unrolling, 0, "firm: disable loop-unrolling optimization" },
134 { X("opt-func-call"), &firm_opt.func_calls, 1, "firm: enable function call optimization" },
135 { X("no-opt-func-call"), &firm_opt.func_calls, 0, "firm: disable function call optimization" },
136 { X("reassociation"), &firm_opt.reassoc, 1, "firm: enable reassociation" },
137 { X("no-reassociation"), &firm_opt.reassoc, 0, "firm: disable reassociation" },
138 { X("inline"), &firm_opt.do_inline, 1, "firm: enable FIRM inlining" },
139 { X("no-inline"), &firm_opt.do_inline, 0, "firm: disable FIRM inlining" },
140 { X("tail-rec"), &firm_opt.tail_rec, 1, "firm: enable tail-recursion optimization" },
141 { X("no-tail-rec"), &firm_opt.tail_rec, 0, "firm: disable tail-recursion optimization" },
142 { X("strength-red"), &firm_opt.strength_red, 1, "firm: enable strength reduction for loops" },
143 { X("no-strength-red"), &firm_opt.strength_red, 0, "firm: disable strength reduction for loops" },
144 { X("scalar-replace"), &firm_opt.scalar_replace, 1, "firm: enable scalar replacement" },
145 { X("no-scalar-replace"), &firm_opt.scalar_replace, 0, "firm: disable scalar replacement" },
146 { X("confirm"), &firm_opt.confirm, 1, "firm: enable Confirm optimization" },
147 { X("no-confirm"), &firm_opt.confirm, 0, "firm: disable Confirm optimization" },
148 { X("opt-mul"), &firm_opt.muls, 0, "firm: enable multiplication optimization" },
149 { X("no-opt-mul"), &firm_opt.muls, 0, "firm: disable multiplication optimization" },
150 { X("opt-div"), &firm_opt.divs, 0, "firm: enable division optimization" },
151 { X("no-opt-div"), &firm_opt.divs, 0, "firm: disable division optimization" },
152 { X("opt-mod"), &firm_opt.mods, 0, "firm: enable remainder optimization" },
153 { X("no-opt-mod"), &firm_opt.mods, 0, "firm: disable remainder optimization" },
154 { X("opt-fragile-ops"), &firm_opt.fragile_ops, 1, "firm: enable fragile ops optimization" },
155 { X("no-opt-fragile-ops"), &firm_opt.fragile_ops, 0, "firm: disable fragile ops optimization" },
156 { X("opt-load-store"), &firm_opt.load_store, 1, "firm: enable load store optimization" },
157 { X("no-opt-load-store"), &firm_opt.load_store, 0, "firm: disable load store optimization" },
158 { X("opt-modes"), &firm_opt.modes, 1, "firm: optimize integer modes" },
159 { X("no-opt-modes"), &firm_opt.modes, 0, "firm: disable integer modes optimization" },
160 { X("jmptbls"), &firm_opt.jmp_tbls, 1, "firm: create jump table for switch" },
161 { X("no-jmptbls"), &firm_opt.jmp_tbls, 0, "firm: do not create jump table for switch" },
162 { X("sync"), &firm_opt.auto_sync, 1, "firm: automatically create Sync nodes" },
163 { X("no-sync"), &firm_opt.auto_sync, 0, "firm: do not create Sync nodes" },
164 { X("opt-alias"), &firm_opt.alias_analysis, 1, "firm: enable alias analysis" },
165 { X("no-opt-alias"), &firm_opt.alias_analysis, 0, "firm: disable alias analysis" },
166 { X("alias"), &firm_opt.no_alias, 0, "firm: aliasing occurs" },
167 { X("no-alias"), &firm_opt.no_alias, 1, "firm: no aliasing occurs" },
168 { X("strict-aliasing"), &firm_opt.strict_alias, 1, "firm: strict alias rules" },
169 { X("no-strict-aliasing"), &firm_opt.strict_alias, 0, "firm: strict alias rules" },
170 { X("opt-proc-clone"), &firm_opt.cloning, 1, "firm: enable procedure cloning" },
171 { X("no-opt-proc-clone"), &firm_opt.cloning, 0, "firm: disable procedure cloning" },
172 { X("clone-threshold=<value>"),NULL, 0, "firm: set clone threshold to <value>" },
173 { X("DivMod"), &firm_opt.use_DivMod, 1, "firm: use DivMod nodes" },
174 { X("no-DivMod"), &firm_opt.use_DivMod, 0, "firm: don't use DivMod nodes" },
175 { X("precise-except"), &firm_opt.precise_exc, 1, "firm: precise exception context" },
176 { X("no-precise-except"), &firm_opt.precise_exc, 0, "firm: no precise exception context" },
177 { X("remove-unused"), &firm_opt.remove_unused, 1, "firm: remove unused functions" },
178 { X("no-remove-unused"), &firm_opt.remove_unused, 0, "firm: dont't remove unused functions" },
179 { X("fp-precise"), &firm_opt.fp_model, fp_model_precise, "firm: precise fp model" },
180 { X("fp-fast"), &firm_opt.fp_model, fp_model_fast, "firm: fast fp model" },
181 { X("fp-strict"), &firm_opt.fp_model, fp_model_strict, "firm: strict fp model" },
182 { X("luffig"), &firm_opt.luffig, 1, "firm: enable the fluffy load/store optimization" },
183 { X("no-luffig"), &firm_opt.luffig, 0, "firm: disable the fluffy load/store optimization" },
184 { X("deconv"), &firm_opt.deconv, 1, "firm: enable the conv node optimization" },
185 { X("no-deconv"), &firm_opt.deconv, 0, "firm: disable the conv node optimization" },
186 { X("opt-cc"), &firm_opt.cc_opt, 1, "firm: enable calling conventions optimization" },
187 { X("no-opt-cc"), &firm_opt.cc_opt, 0, "firm: disable calling conventions optimization" },
188 { X("bool"), &firm_opt.bool_opt, 1, "firm: enable bool simplification optimization" },
189 { X("no-bool"), &firm_opt.bool_opt, 0, "firm: disable bool simplification optimization" },
190 { X("freestanding"), &firm_opt.freestanding, 1, "firm: freestanding environment" },
191 { X("hosted"), &firm_opt.freestanding, 0, "firm: hosted environment" },
193 /* other firm regarding options */
194 { X("restrict"), &firm_opt.honor_restrict, 1, "firm: honor restrict keyword" },
195 { X("no-restrict"), &firm_opt.honor_restrict, 1, "firm: restrict keyword is meaningless" },
196 { X("no-lower"), &firm_opt.lower, 0, "firm: disable lowering" },
197 { X("vrfy-off"), &firm_opt.vrfy, FIRM_VERIFICATION_OFF, "firm: disable node verification" },
198 { X("vrfy-on"), &firm_opt.vrfy, FIRM_VERIFICATION_ON, "firm: enable node verification" },
199 { X("vrfy-report"), &firm_opt.vrfy, FIRM_VERIFICATION_REPORT, "firm: node verification, report only" },
200 { X("check-all"), &firm_opt.check_all, 1, "firm: enable checking all Firm phases" },
201 { X("no-check-all"), &firm_opt.check_all, 0, "firm: disable checking all Firm phases" },
202 { X("vrfy-edges-on"), &firm_opt.vrfy_edges, 1, "firm: enable out edge verification" },
203 { X("vrfy-edges-off"), &firm_opt.vrfy_edges, 0, "firm: disable out edge verification" },
206 #if defined(_DEBUG) || defined(FIRM_DEBUG)
207 { X("debug"), &firm_dump.debug_print, 1, "firm: enable debug output" },
210 { X("dump-ir"), &firm_dump.ir_graph, 1, "firm: dump IR graph" },
211 { X("dump-all-types"), &firm_dump.all_types, 1, "firm: dump graph of all types" },
212 { X("dump-no-blocks"), &firm_dump.no_blocks, 1, "firm: dump non-blocked graph" },
213 { X("dump-extbb"), &firm_dump.extbb, 1, "firm: dump extended basic blocks" },
214 { X("dump-all-phases"), &firm_dump.all_phases, 1, "firm: dump graphs for all optimization phases" },
215 { X("dump-edge-labels"), &firm_dump.edge_labels, 1, "firm: dump edge labels" },
217 /* code generation */
218 { X("no-codegen"), &firm_be_opt.selection, BE_NONE, "cg: disable code generator" },
221 { X("grs-simd-opt"), &firm_ext_grs.simd_opt, 1, "firm: do simd optimization" },
222 { X("grs-create-pattern"), &firm_ext_grs.create_pattern, 1, "firm: create patterns for simd optimization" },
223 { X("no-grs-simd-opt"), &firm_ext_grs.simd_opt, 0, "firm: do simd optimization" },
224 { X("no-grs-create-pattern"), &firm_ext_grs.create_pattern, 0, "firm: create patterns for simd optimization" },
228 { X("be-firm"), &firm_be_opt.selection, BE_FIRM_BE, "backend: firm backend facility" },
229 #endif /* FIRM_BACKEND */
230 #ifdef FIRM2C_BACKEND
231 { X("be-firm2c"), &firm_be_opt.selection, BE_FIRM2C, "backend: firm2C" },
232 #endif /* FIRM2C_BACKEND */
235 { X("stat-before-opt"), &firm_dump.statistic, STAT_BEFORE_OPT, "misc: Firm statistic output before optimizations" },
236 { X("stat-after-opt"), &firm_dump.statistic, STAT_AFTER_OPT, "misc: Firm statistic output after optimizations" },
237 { X("stat-after-lower"), &firm_dump.statistic, STAT_AFTER_LOWER, "misc: Firm statistic output after lowering" },
238 { X("stat-final-ir"), &firm_dump.statistic, STAT_FINAL_IR, "misc: Firm statistic after final optimization" },
239 { X("stat-final"), &firm_dump.statistic, STAT_FINAL, "misc: Firm statistic after code generation" },
240 { X("stat-pattern"), &firm_dump.stat_pattern, 1, "misc: Firm statistic calculates most used pattern" },
241 { X("stat-dag"), &firm_dump.stat_dag, 1, "misc: Firm calculates DAG statistics" },
242 { X("firm-asm"), &firm_dump.gen_firm_asm, 1, "misc: output Firm assembler" },
243 { X("win32"), &firm_opt.os_support, OS_SUPPORT_MINGW, "misc: generate MinGW code" },
244 { X("ycomp"), &firm_opt.ycomp_dbg, 1, "misc: enable yComp debugger extension" },
245 { X("ycomp-host=<hostname>"), NULL, 0, "misc: yComp host" },
246 { X("ycomp-port=<port>"), NULL, 0, "misc: yComp port" },
249 { X("dump-filter=<string>"), NULL, 0, "misc: set dumper filter" },
254 /** A strdup replacement */
255 static char *StrDup(const char *s) {
257 char *r = malloc(l+1);
265 * Set a dumper filter.
267 static void set_dump_filter(const char *filter)
269 firm_dump.filter = StrDup(filter);
270 } /* set_dump_filter */
275 static void set_ycomp_host(const char *host)
277 firm_opt.ycomp_host = StrDup(host);
278 } /* set_ycomp_host */
280 /** Disable all optimizations. */
281 static void disable_opts(void) {
282 /* firm_opt.const_folding */
283 firm_opt.reassoc = FALSE;
284 firm_opt.cse = FALSE;
285 /* firm_opt.control_flow */
286 firm_opt.code_place = FALSE;
287 firm_opt.gvn_pre = FALSE;
288 firm_opt.cond_eval = FALSE;
289 firm_opt.if_conversion = FALSE;
290 firm_opt.loop_unrolling = FALSE;
291 firm_opt.func_calls = FALSE;
292 firm_opt.do_inline = FALSE;
293 firm_opt.auto_inline = FALSE;
294 firm_opt.tail_rec = FALSE;
295 firm_opt.strength_red = FALSE;
296 firm_opt.scalar_replace = FALSE;
297 firm_opt.confirm = FALSE;
298 firm_opt.muls = FALSE;
299 firm_opt.divs = FALSE;
300 firm_opt.mods = FALSE;
301 firm_opt.fragile_ops = FALSE;
302 firm_opt.load_store = FALSE;
303 firm_opt.remove_unused = FALSE;
304 /* firm_opt.jmp_tbls */
305 firm_opt.cloning = FALSE;
306 /* firm_opt.auto_sync */
307 firm_opt.alias_analysis = FALSE;
308 firm_opt.strict_alias = FALSE;
309 firm_opt.no_alias = FALSE;
310 firm_opt.luffig = FALSE;
311 firm_opt.deconv = FALSE;
312 firm_opt.cc_opt = FALSE;
313 firm_opt.bool_opt = FALSE;
314 firm_opt.freestanding = TRUE;
318 * Handles a firm option.
320 int firm_option(const char *opt)
322 int i, len = strlen(opt);
326 if (strncmp("dump-filter=", opt, 12) == 0) {
328 set_dump_filter(opt);
331 else if (strncmp("clone-threshold=", opt, 16) == 0) {
332 sscanf(&opt[16], "%d", &firm_opt.clone_threshold);
333 firm_opt.cloning = TRUE;
336 else if (strncmp("ycomp-host=", opt, 11) == 0) {
341 else if (strncmp("ycomp-port=", opt, 11) == 0) {
342 sscanf(&opt[11], "%d", &firm_opt.ycomp_port);
345 else if (strcmp("no-opt", opt) == 0) {
350 for (i = sizeof(firm_options) / sizeof(firm_options[0]) - 1; i >= 0; --i) {
351 if (len == firm_options[i].opt_len && strncmp(p, firm_options[i].option, len) == 0) {
352 if (!firm_options[i].flag) {
354 for (i = 0; i < (int) (sizeof(firm_options)/sizeof(firm_options[0])); ++i) {
355 printf("-f %-20s %s\n", firm_options[i].option,
356 firm_options[i].description);
360 /* statistic options do accumulate */
361 if (firm_options[i].flag == &firm_dump.statistic)
362 *firm_options[i].flag = (a_byte) (*firm_options[i].flag | firm_options[i].set);
364 *firm_options[i].flag = firm_options[i].set;
366 if (firm_options[i].flag == &firm_opt.debug_mode && firm_opt.debug_mode > DBG_MODE_NONE) {
367 if (firm_opt.debug_mode == DBG_MODE_FULL)
371 res &= firm_be_option("omitfp=0");
372 res &= firm_be_option("stabs");
373 #endif /* FIRM_BACKEND */
377 /* OS option must be set to the backend */
378 else if (firm_options[i].flag == &firm_opt.os_support)
379 firm_be_option(firm_opt.os_support == OS_SUPPORT_MINGW ?
380 "ia32-gasmode=mingw" : "ia32-gasmode=linux");
381 #endif /* FIRM_BACKEND */
392 * Handles a firm backend option.
394 * The options are here only checked for validity and later transmitted
395 * to the firm backend (in the hope they do not fail ...)
397 int firm_be_option(const char *opt) {
399 return be_parse_arg(opt);
402 #endif /* FIRM_BACKEND */
403 } /* firm_be_option */
406 * prints the firm version number
408 void print_firm_version(FILE *f) {
409 firm_version_t version;
411 firm_get_version(&version);
413 fprintf(f, "Firm C-Compiler using libFirm (%u.%u", version.major, version.minor);
414 if(version.revision[0] != 0) {
416 fputs(version.revision, f);
418 if(version.build[0] != 0) {
420 fputs(version.build, f);
423 fprintf(f, "(C) 2006-2007 Michael Beck\n"
424 "(C) 1995-2007 University of Karlsruhe\n"
426 } /* print_firm_version */