reorganize firm_cmdline, implement --help-optimization
authorMatthias Braun <matze@braunis.de>
Fri, 10 Jun 2011 13:25:26 +0000 (15:25 +0200)
committerMatthias Braun <matze@braunis.de>
Fri, 10 Jun 2011 13:29:18 +0000 (15:29 +0200)
driver/firm_cmdline.c [deleted file]
driver/firm_cmdline.h [deleted file]
driver/firm_codegen.h [deleted file]
driver/firm_opt.c
driver/firm_opt.h
main.c

diff --git a/driver/firm_cmdline.c b/driver/firm_cmdline.c
deleted file mode 100644 (file)
index 4365e53..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/**
- * @file firm_cmdline.c -- Additional Firm generating backend parameters
- *
- * Compile when BACK_END_IS_CP_FIRM_BE is defined
- *
- * (C) 2005  Michael Beck  beck@ipd.info.uni-karlsruhe.de
- *
- * $Id$
- */
-#include <string.h>
-#include "../adt/strutil.h"
-#include "../adt/util.h"
-#include "firm_cmdline.h"
-#include "firm_opt.h"
-#include <libfirm/firm.h>
-#include <libfirm/be.h>
-
-/* optimization settings */
-struct a_firm_opt firm_opt = {
-  /* const_folding   = */ true,
-  /* cse             = */ true,
-  /* confirm         = */ true,
-  /* muls            = */ true,
-  /* divs            = */ true,
-  /* mods            = */ true,
-  /* alias_analysis  = */ true,
-  /* strict_alias    = */ false,
-  /* no_alias        = */ false,
-  /* verify          = */ FIRM_VERIFICATION_ON,
-  /* check_all       = */ true,
-  /* clone_threshold = */ DEFAULT_CLONE_THRESHOLD,
-  /* inline_maxsize  = */ 750,
-  /* inline_threshold= */ 0,
-  /* verify_edges    = */ false,
-};
-
-/* dumping options */
-struct a_firm_dump firm_dump = {
-  /* debug_print  = */ false,
-  /* all_types    = */ false,
-  /* no_blocks    = */ false,
-  /* extbb        = */ false,
-  /* ir_graph     = */ false,
-  /* all_phases   = */ false,
-  /* statistic    = */ STAT_NONE,
-  /* stat_pattern = */ 0,
-  /* stat_dag     = */ 0,
-  /* filter       = */ NULL
-};
-
-#define X(a)  a, sizeof(a)-1
-
-/** Parameter description structure */
-static const struct params {
-  const char *option;      /**< name of the option */
-  size_t     opt_len;      /**< length of the option string */
-  bool       *flag;        /**< address of variable to set/reset */
-  bool       set;          /**< iff true, variable will be set, else reset */
-  const char *description; /**< description of this option */
-} firm_options[] = {
-  /* this must be first */
-  { X("help"),                   NULL,                       0, "print FCC related help options" },
-
-  /* firm optimization options */
-  { X("no-opt"),                 NULL,                       0, "firm: disable all FIRM optimizations" },
-  { X("cse"),                    &firm_opt.cse,              1, "firm: enable common subexpression elimination" },
-  { X("no-cse"),                 &firm_opt.cse,              0, "firm: disable common subexpression elimination" },
-  { X("const-fold"),             &firm_opt.const_folding,    1, "firm: enable constant folding" },
-  { X("no-const-fold"),          &firm_opt.const_folding,    0, "firm: disable constant folding" },
-  { X("inline-max-size=<size>"), NULL,                       0, "firm: set maximum size for function inlining" },
-  { X("inline-threshold=<size>"),NULL,                       0, "firm: set benefice threshold for function inlining" },
-  { X("confirm"),                &firm_opt.confirm,          1, "firm: enable Confirm optimization" },
-  { X("no-confirm"),             &firm_opt.confirm,          0, "firm: disable Confirm optimization" },
-  { X("opt-mul"),                &firm_opt.muls,             0, "firm: enable multiplication optimization" },
-  { X("no-opt-mul"),             &firm_opt.muls,             0, "firm: disable multiplication optimization" },
-  { X("opt-div"),                &firm_opt.divs,             0, "firm: enable division optimization" },
-  { X("no-opt-div"),             &firm_opt.divs,             0, "firm: disable division optimization" },
-  { X("opt-mod"),                &firm_opt.mods,             0, "firm: enable remainder optimization" },
-  { X("no-opt-mod"),             &firm_opt.mods,             0, "firm: disable remainder optimization" },
-  { X("opt-alias"),              &firm_opt.alias_analysis,   1, "firm: enable alias analysis" },
-  { X("no-opt-alias"),           &firm_opt.alias_analysis,   0, "firm: disable alias analysis" },
-  { X("alias"),                  &firm_opt.no_alias,         0, "firm: aliasing occurs" },
-  { X("no-alias"),               &firm_opt.no_alias,         1, "firm: no aliasing occurs" },
-  { X("strict-aliasing"),        &firm_opt.strict_alias,     1, "firm: strict alias rules" },
-  { X("no-strict-aliasing"),     &firm_opt.strict_alias,     0, "firm: strict alias rules" },
-  { X("clone-threshold=<value>"),NULL,                       0, "firm: set clone threshold to <value>" },
-
-  /* other firm regarding options */
-  { X("verify-off"),             &firm_opt.verify,           FIRM_VERIFICATION_OFF, "firm: disable node verification" },
-  { X("verify-on"),              &firm_opt.verify,           FIRM_VERIFICATION_ON, "firm: enable node verification" },
-  { X("verify-report"),          &firm_opt.verify,           FIRM_VERIFICATION_REPORT, "firm: node verification, report only" },
-  { X("check-all"),              &firm_opt.check_all,        1, "firm: enable checking all Firm phases" },
-  { X("no-check-all"),           &firm_opt.check_all,        0, "firm: disable checking all Firm phases" },
-  { X("verify-edges-on"),        &firm_opt.verify_edges,     1, "firm: enable out edge verification" },
-  { X("verify-edges-off"),       &firm_opt.verify_edges,     0, "firm: disable out edge verification" },
-
-  /* dumping */
-  { X("dump-ir"),                &firm_dump.ir_graph,        1, "firm: dump IR graph" },
-  { X("dump-all-types"),         &firm_dump.all_types,       1, "firm: dump graph of all types" },
-  { X("dump-no-blocks"),         &firm_dump.no_blocks,       1, "firm: dump non-blocked graph" },
-  { X("dump-extbb"),             &firm_dump.extbb,           1, "firm: dump extended basic blocks" },
-  { X("dump-all-phases"),        &firm_dump.all_phases,      1, "firm: dump graphs for all optimization phases" },
-
-  /* misc */
-  { X("stat-before-opt"),        &firm_dump.statistic,       STAT_BEFORE_OPT,  "misc: Firm statistic output before optimizations" },
-  { X("stat-after-opt"),         &firm_dump.statistic,       STAT_AFTER_OPT,   "misc: Firm statistic output after optimizations" },
-  { X("stat-after-lower"),       &firm_dump.statistic,       STAT_AFTER_LOWER, "misc: Firm statistic output after lowering" },
-  { X("stat-final-ir"),          &firm_dump.statistic,       STAT_FINAL_IR,    "misc: Firm statistic after final optimization" },
-  { X("stat-final"),             &firm_dump.statistic,       STAT_FINAL,       "misc: Firm statistic after code generation" },
-  { X("stat-pattern"),           &firm_dump.stat_pattern,    1, "misc: Firm statistic calculates most used pattern" },
-  { X("stat-dag"),               &firm_dump.stat_dag,        1, "misc: Firm calculates DAG statistics" },
-
-  /* string options */
-  { X("dump-filter=<string>"),   NULL,                       0, "misc: set dumper filter" },
-};
-
-#undef X
-
-/** A strdup replacement */
-static char *StrDup(const char *s) {
-  int   l = strlen(s);
-  char *r = malloc(l+1);
-
-  if (r != NULL)
-    memcpy(r, s, l+1);
-  return r;
-}
-
-/**
- * Set a dumper filter.
- */
-static void set_dump_filter(const char *filter)
-{
-  firm_dump.filter = StrDup(filter);
-}  /* set_dump_filter */
-
-/** Disable all optimizations. */
-static void disable_opts(void) {
-  firm_opt.cse             = false;
-  firm_opt.confirm         = false;
-  firm_opt.muls            = false;
-  firm_opt.divs            = false;
-  firm_opt.mods            = false;
-  firm_opt.alias_analysis  = false;
-  firm_opt.strict_alias    = false;
-  firm_opt.no_alias        = false;
-  disable_all_opts();
-}  /* disable_opts */
-
-void print_option_help(const char *name, const char *description)
-{
-       printf("-f %-20s %s\n", name, description);
-}
-
-/**
- * Handles a firm option.
- */
-int firm_option(char const *const opt)
-{
-       char const* val;
-  if ((val = strstart(opt, "dump-filter="))) {
-    set_dump_filter(val);
-    return 1;
-  } else if ((val = strstart(opt, "clone-threshold="))) {
-    sscanf(val, "%d", &firm_opt.clone_threshold);
-    return 1;
-  } else if ((val = strstart(opt, "inline-max-size="))) {
-    sscanf(val, "%u", &firm_opt.inline_maxsize);
-    return 1;
-  } else if ((val = strstart(opt, "inline-threshold="))) {
-    sscanf(val, "%u", &firm_opt.inline_threshold);
-    return 1;
-  } else if (streq(opt, "no-opt")) {
-    disable_opts();
-    return 1;
-  }
-
-  size_t const len = strlen(opt);
-  for (size_t i = lengthof(firm_options); i != 0;) {
-    struct params const* const o = &firm_options[--i];
-    if (len == o->opt_len && strncmp(opt, o->option, len) == 0) {
-      if (!o->flag) {
-        /* help option */
-        print_option_help(firm_options[0].option, firm_options[0].description);
-        firm_opt_option_help();
-        for (size_t k = 1; k != lengthof(firm_options); ++k) {
-          print_option_help(firm_options[k].option, firm_options[k].description);
-        }
-        return -1;
-      }
-
-      /* statistic options do accumulate */
-      if (o->flag == &firm_dump.statistic)
-        *o->flag = (bool) (*o->flag | o->set);
-      else
-        *o->flag = o->set;
-
-      return 1;
-    }
-  }
-
-  /* maybe this enables/disables optimisations */
-  if (firm_opt_option(opt))
-    return 1;
-
-  return 0;
-}
diff --git a/driver/firm_cmdline.h b/driver/firm_cmdline.h
deleted file mode 100644 (file)
index a0c7370..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * @file firm_cmdline.h -- Additional Firm generating backend parameters
- *
- * Generates Firm fro the IL.  It works with both C++ and C programs.
- */
-#ifndef FIRM_CMDLINE_H
-#define FIRM_CMDLINE_H
-
-#include <stdbool.h>
-
-/* optimization settings */
-struct a_firm_opt {
-  bool     const_folding;   /**< enable constant folding */
-  bool     cse;             /**< enable common-subexpression elimination */
-  bool     confirm;         /**< enable Confirm optimization */
-  bool     muls;            /**< enable architecture dependent mul optimization */
-  bool     divs;            /**< enable architecture dependent div optimization */
-  bool     mods;            /**< enable architecture dependent mod optimization */
-  bool     alias_analysis;  /**< enable Alias Analysis */
-  bool     strict_alias;    /**< enable strict Alias Analysis (using type based AA) */
-  bool     no_alias;        /**< no aliasing possible. */
-  bool     verify;          /**< Firm verifier setting */
-  bool     check_all;       /**< enable checking all Firm phases */
-  int      clone_threshold; /**< The threshold value for procedure cloning. */
-  unsigned inline_maxsize;  /**< Maximum function size for inlining. */
-  unsigned inline_threshold;/**< Inlining benefice threshold. */
-  bool     verify_edges;    /**< verify edges */
-};
-
-/** statistic options */
-typedef enum a_firmstat_selection_tag {
-  STAT_NONE        = 0x00000000,
-  STAT_BEFORE_OPT  = 0x00000001,
-  STAT_AFTER_OPT   = 0x00000002,
-  STAT_AFTER_LOWER = 0x00000004,
-  STAT_FINAL_IR    = 0x00000008,
-  STAT_FINAL       = 0x00000010,
-} a_firmstat_selection;
-
-/* dumping options */
-struct a_firm_dump {
-  bool debug_print;   /**< enable debug print */
-  bool all_types;     /**< dump the All_types graph */
-  bool no_blocks;     /**< dump non-blocked graph */
-  bool extbb;         /**< dumps extended basic blocks */
-  bool ir_graph;      /**< dump all graphs */
-  bool all_phases;    /**< dump the IR graph after all phases */
-  bool statistic;     /**< Firm statistic setting */
-  bool stat_pattern;  /**< enable Firm statistic pattern */
-  bool stat_dag;      /**< enable Firm DAG statistic */
-  char *filter;       /**< the dump filter */
-};
-
-struct a_firm_be_opt {
-  bool selection;
-  bool node_stat;
-};
-
-extern struct a_firm_be_opt firm_be_opt;
-extern struct a_firm_opt firm_opt;
-extern struct a_firm_dump firm_dump;
-extern struct a_firm_ext_grs firm_ext_grs;
-
-void print_option_help(const char *name, const char *description);
-
-/**
- * called by the generic command line parser
- * to handle the --firm= or -f options
- */
-int firm_option(const char *opt);
-
-#endif
diff --git a/driver/firm_codegen.h b/driver/firm_codegen.h
deleted file mode 100644 (file)
index 931320a..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef FIRM_CODEGEN_H
-#define FIRM_CODEGEN_H
-
-/* Calls the specified backend. */
-void do_codegen(FILE *out, const char *asm_file_name);
-
-#endif
index 5534c25..966139e 100644 (file)
 #include <libfirm/firm.h>
 
 #include "firm_opt.h"
-#include "firm_codegen.h"
-#include "firm_cmdline.h"
 #include "firm_timing.h"
 #include "ast2firm.h"
+#include "adt/strutil.h"
+
+/* optimization settings */
+struct a_firm_opt {
+       bool     const_folding;   /**< enable constant folding */
+       bool     cse;             /**< enable common-subexpression elimination */
+       bool     confirm;         /**< enable Confirm optimization */
+       bool     muls;            /**< enable architecture dependent mul optimization */
+       bool     divs;            /**< enable architecture dependent div optimization */
+       bool     mods;            /**< enable architecture dependent mod optimization */
+       bool     alias_analysis;  /**< enable Alias Analysis */
+       bool     strict_alias;    /**< enable strict Alias Analysis (using type based AA) */
+       bool     no_alias;        /**< no aliasing possible. */
+       bool     verify;          /**< Firm verifier setting */
+       bool     check_all;       /**< enable checking all Firm phases */
+       int      clone_threshold; /**< The threshold value for procedure cloning. */
+       unsigned inline_maxsize;  /**< Maximum function size for inlining. */
+       unsigned inline_threshold;/**< Inlining benefice threshold. */
+       bool     verify_edges;    /**< verify edges */
+};
+
+/** statistic options */
+typedef enum a_firmstat_selection_tag {
+       STAT_NONE        = 0x00000000,
+       STAT_BEFORE_OPT  = 0x00000001,
+       STAT_AFTER_OPT   = 0x00000002,
+       STAT_AFTER_LOWER = 0x00000004,
+       STAT_FINAL_IR    = 0x00000008,
+       STAT_FINAL       = 0x00000010,
+} a_firmstat_selection;
+
+/* dumping options */
+struct a_firm_dump {
+       bool debug_print;   /**< enable debug print */
+       bool all_types;     /**< dump the All_types graph */
+       bool no_blocks;     /**< dump non-blocked graph */
+       bool extbb;         /**< dumps extended basic blocks */
+       bool ir_graph;      /**< dump all graphs */
+       bool all_phases;    /**< dump the IR graph after all phases */
+       bool statistic;     /**< Firm statistic setting */
+       bool stat_pattern;  /**< enable Firm statistic pattern */
+       bool stat_dag;      /**< enable Firm DAG statistic */
+};
+
+struct a_firm_be_opt {
+       bool selection;
+       bool node_stat;
+};
+
+/* optimization settings */
+struct a_firm_opt firm_opt = {
+       .const_folding    =  true,
+       .cse              =  true,
+       .confirm          =  true,
+       .muls             =  true,
+       .divs             =  true,
+       .mods             =  true,
+       .alias_analysis   =  true,
+       .strict_alias     =  false,
+       .no_alias         =  false,
+       .verify           =  FIRM_VERIFICATION_ON,
+       .check_all        =  true,
+       .clone_threshold  =  DEFAULT_CLONE_THRESHOLD,
+       .inline_maxsize   =  750,
+       .inline_threshold =  0,
+       .verify_edges     =  false,
+};
+
+/* dumping options */
+struct a_firm_dump firm_dump = {
+       .debug_print  = false,
+       .all_types    = false,
+       .no_blocks    = false,
+       .extbb        = false,
+       .ir_graph     = false,
+       .all_phases   = false,
+       .statistic    = STAT_NONE,
+       .stat_pattern = 0,
+       .stat_dag     = 0,
+};
+
+#define X(a)  a, sizeof(a)-1
+
+/** Parameter description structure */
+static const struct params {
+  const char *option;      /**< name of the option */
+  size_t     opt_len;      /**< length of the option string */
+  bool       *flag;        /**< address of variable to set/reset */
+  bool       set;          /**< iff true, variable will be set, else reset */
+  const char *description; /**< description of this option */
+} firm_options[] = {
+  /* firm optimization options */
+  { X("no-opt"),                 NULL,                       0, "disable all FIRM optimizations" },
+  { X("cse"),                    &firm_opt.cse,              1, "enable common subexpression elimination" },
+  { X("no-cse"),                 &firm_opt.cse,              0, "disable common subexpression elimination" },
+  { X("const-fold"),             &firm_opt.const_folding,    1, "enable constant folding" },
+  { X("no-const-fold"),          &firm_opt.const_folding,    0, "disable constant folding" },
+  { X("inline-max-size=<size>"), NULL,                       0, "set maximum size for function inlining" },
+  { X("inline-threshold=<size>"),NULL,                       0, "set benefice threshold for function inlining" },
+  { X("confirm"),                &firm_opt.confirm,          1, "enable Confirm optimization" },
+  { X("no-confirm"),             &firm_opt.confirm,          0, "disable Confirm optimization" },
+  { X("opt-mul"),                &firm_opt.muls,             0, "enable multiplication optimization" },
+  { X("no-opt-mul"),             &firm_opt.muls,             0, "disable multiplication optimization" },
+  { X("opt-div"),                &firm_opt.divs,             0, "enable division optimization" },
+  { X("no-opt-div"),             &firm_opt.divs,             0, "disable division optimization" },
+  { X("opt-mod"),                &firm_opt.mods,             0, "enable remainder optimization" },
+  { X("no-opt-mod"),             &firm_opt.mods,             0, "disable remainder optimization" },
+  { X("opt-alias"),              &firm_opt.alias_analysis,   1, "enable alias analysis" },
+  { X("no-opt-alias"),           &firm_opt.alias_analysis,   0, "disable alias analysis" },
+  { X("alias"),                  &firm_opt.no_alias,         0, "aliasing occurs" },
+  { X("no-alias"),               &firm_opt.no_alias,         1, "no aliasing occurs" },
+  { X("strict-aliasing"),        &firm_opt.strict_alias,     1, "strict alias rules" },
+  { X("no-strict-aliasing"),     &firm_opt.strict_alias,     0, "strict alias rules" },
+  { X("clone-threshold=<value>"),NULL,                       0, "set clone threshold to <value>" },
+
+  /* other firm regarding options */
+  { X("verify-off"),             &firm_opt.verify,           FIRM_VERIFICATION_OFF,    "disable node verification" },
+  { X("verify-on"),              &firm_opt.verify,           FIRM_VERIFICATION_ON,     "enable node verification" },
+  { X("verify-report"),          &firm_opt.verify,           FIRM_VERIFICATION_REPORT, "node verification, report only" },
+  { X("check-all"),              &firm_opt.check_all,        1, "enable checking all Firm phases" },
+  { X("no-check-all"),           &firm_opt.check_all,        0, "disable checking all Firm phases" },
+  { X("verify-edges-on"),        &firm_opt.verify_edges,     1, "enable out edge verification" },
+  { X("verify-edges-off"),       &firm_opt.verify_edges,     0, "disable out edge verification" },
+
+  /* dumping */
+  { X("dump-ir"),                &firm_dump.ir_graph,        1, "dump IR graph" },
+  { X("dump-all-types"),         &firm_dump.all_types,       1, "dump graph of all types" },
+  { X("dump-no-blocks"),         &firm_dump.no_blocks,       1, "dump non-blocked graph" },
+  { X("dump-extbb"),             &firm_dump.extbb,           1, "dump extended basic blocks" },
+  { X("dump-all-phases"),        &firm_dump.all_phases,      1, "dump graphs for all optimization phases" },
+  { X("dump-filter=<string>"),   NULL,                       0, "set dumper filter" },
+
+  /* misc */
+  { X("stat-before-opt"),        &firm_dump.statistic,       STAT_BEFORE_OPT,  "Firm statistic output before optimizations" },
+  { X("stat-after-opt"),         &firm_dump.statistic,       STAT_AFTER_OPT,   "Firm statistic output after optimizations" },
+  { X("stat-after-lower"),       &firm_dump.statistic,       STAT_AFTER_LOWER, "Firm statistic output after lowering" },
+  { X("stat-final-ir"),          &firm_dump.statistic,       STAT_FINAL_IR,    "Firm statistic after final optimization" },
+  { X("stat-final"),             &firm_dump.statistic,       STAT_FINAL,       "Firm statistic after code generation" },
+  { X("stat-pattern"),           &firm_dump.stat_pattern,    1, "Firm statistic calculates most used pattern" },
+  { X("stat-dag"),               &firm_dump.stat_dag,        1, "Firm calculates DAG statistics" },
+};
+
+#undef X
 
 static ir_timer_t *t_vcg_dump;
 static ir_timer_t *t_verify;
@@ -636,8 +777,6 @@ void gen_firm_init(void)
        arch_dep_set_opts(arch_dep_none);
 
        do_node_verification((firm_verification_t) firm_opt.verify);
-       if (firm_dump.filter != NULL)
-               ir_set_dump_filter(firm_dump.filter);
        if (firm_dump.extbb)
                ir_add_dump_flags(ir_dump_flag_group_extbb);
        if (firm_dump.no_blocks)
@@ -724,8 +863,17 @@ void gen_firm_finish(FILE *out, const char *input_filename)
                stat_dump_snapshot(input_filename, "final");
 }
 
-void disable_all_opts(void)
+static void disable_all_opts(void)
 {
+       firm_opt.cse             = false;
+       firm_opt.confirm         = false;
+       firm_opt.muls            = false;
+       firm_opt.divs            = false;
+       firm_opt.mods            = false;
+       firm_opt.alias_analysis  = false;
+       firm_opt.strict_alias    = false;
+       firm_opt.no_alias        = false;
+
        for (int i = 0; i < n_opts; ++i) {
                opt_config_t *config = &opts[i];
                if (config->flags & OPT_FLAG_ESSENTIAL) {
@@ -736,7 +884,7 @@ void disable_all_opts(void)
        }
 }
 
-int firm_opt_option(const char *opt)
+static bool firm_opt_option(const char *opt)
 {
        bool enable = true;
        if (strncmp(opt, "no-", 3) == 0) {
@@ -746,18 +894,18 @@ int firm_opt_option(const char *opt)
 
        opt_config_t *config = get_opt(opt);
        if (config == NULL || (config->flags & OPT_FLAG_HIDE_OPTIONS))
-               return 0;
+               return false;
 
        config->flags &= ~OPT_FLAG_ENABLED;
        config->flags |= enable ? OPT_FLAG_ENABLED : 0;
-       return 1;
+       return true;
 }
 
-void firm_opt_option_help(void)
+void firm_option_help(print_option_help_func print_option_help)
 {
-       int i;
+       print_option_help(firm_options[0].option, firm_options[0].description);
 
-       for (i = 0; i < n_opts; ++i) {
+       for (int i = 0; i < n_opts; ++i) {
                char buf[1024];
                char buf2[1024];
 
@@ -765,14 +913,66 @@ void firm_opt_option_help(void)
                if (config->flags & OPT_FLAG_HIDE_OPTIONS)
                        continue;
 
-               snprintf(buf2, sizeof(buf2), "firm: enable %s", config->description);
-               print_option_help(config->name, buf2);
-               snprintf(buf, sizeof(buf), "no-%s", config->name);
-               snprintf(buf2, sizeof(buf2), "firm: disable %s", config->description);
+               snprintf(buf, sizeof(buf), "-f%s", config->name);
+               snprintf(buf2, sizeof(buf2), "enable %s", config->description);
+               print_option_help(buf, buf2);
+               snprintf(buf, sizeof(buf), "-fno-%s", config->name);
+               snprintf(buf2, sizeof(buf2), "disable %s", config->description);
+               print_option_help(buf, buf2);
+       }
+
+       size_t const n_options = sizeof(firm_options)/sizeof(firm_options[0]);
+       for (size_t k = 0; k < n_options; ++k) {
+               char buf[1024];
+               char buf2[1024];
+               snprintf(buf, sizeof(buf), "-f%s", firm_options[k].option);
+               snprintf(buf2, sizeof(buf2), "%s", firm_options[k].description);
                print_option_help(buf, buf2);
        }
 }
 
+int firm_option(const char *const opt)
+{
+       char const* val;
+       if ((val = strstart(opt, "dump-filter="))) {
+               ir_set_dump_filter(val);
+               return 1;
+       } else if ((val = strstart(opt, "clone-threshold="))) {
+               sscanf(val, "%d", &firm_opt.clone_threshold);
+               return 1;
+       } else if ((val = strstart(opt, "inline-max-size="))) {
+               sscanf(val, "%u", &firm_opt.inline_maxsize);
+               return 1;
+       } else if ((val = strstart(opt, "inline-threshold="))) {
+               sscanf(val, "%u", &firm_opt.inline_threshold);
+               return 1;
+       } else if (streq(opt, "no-opt")) {
+               disable_all_opts();
+               return 1;
+       }
+
+       size_t const len = strlen(opt);
+       size_t const n_options = sizeof(firm_options)/sizeof(firm_options[0]);
+       for (size_t i = n_options; i != 0;) {
+               struct params const* const o = &firm_options[--i];
+               if (len == o->opt_len && strncmp(opt, o->option, len) == 0) {
+                       /* statistic options do accumulate */
+                       if (o->flag == &firm_dump.statistic)
+                               *o->flag = (bool) (*o->flag | o->set);
+                       else
+                               *o->flag = o->set;
+
+                       return 1;
+               }
+       }
+
+       /* maybe this enables/disables optimisations */
+       if (firm_opt_option(opt))
+               return 1;
+
+       return 0;
+}
+
 static void set_be_option(const char *arg)
 {
        int res = be_parse_arg(arg);
index 4b5192b..9f3516f 100644 (file)
@@ -93,36 +93,24 @@ enum rts_names {
 
 extern ir_entity_ptr rts_entities[rts_max];
 
-/** Debug printf implementation. */
-extern void dbg_printf(const char *fmt, ...);
-
 /** Initialize for the Firm-generating back end. */
 void gen_firm_init(void);
 
-void disable_all_opts(void);
-
 /** called, after the Firm generation is completed. */
 void gen_firm_finish(FILE *out, const char *input_filename);
 
-void gen_Firm_assembler(const char *input_filename);
-
 /** early initialization. */
 void firm_early_init(void);
 
-/** process optimisation commandline option */
-int firm_opt_option(const char *opt);
+/** process optimization commandline option */
+int firm_option(const char *opt);
 
-/** print help about optimisations options */
-void firm_opt_option_help(void);
+typedef void (*print_option_help_func)(const char *name, const char *description);
+
+void firm_option_help(print_option_help_func func);
 
 /** Choose an optimization level. (Typically used to interpret the -O compiler
  * switches) */
 void choose_optimization_pack(int level);
 
-/**
- * Setup firm to generate code for a specific os.
- * The parameter should be the OS-part of a machine triple
- */
-void firm_init_os(const char *os);
-
 #endif
diff --git a/main.c b/main.c
index f30c8ca..741f3c9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -70,7 +70,6 @@
 #include "diagnostic.h"
 #include "lang_features.h"
 #include "driver/firm_opt.h"
-#include "driver/firm_cmdline.h"
 #include "driver/firm_timing.h"
 #include "driver/firm_machine.h"
 #include "adt/error.h"
@@ -563,6 +562,7 @@ static void print_help_basic(const char *argv0)
        put_help("--help-parser",            "Display information about parser options");
        put_help("--help-warnings",          "Display information about warning options");
        put_help("--help-codegen",           "Display information about code-generation options");
+       put_help("--help-optimization",      "Display information about optimization options");
        put_help("--help-linker",            "Display information about linker options");
        put_help("--help-language-tools",    "Display information about language tools options");
        put_help("--help-debug",             "Display information about compiler debugging options");
@@ -640,9 +640,10 @@ static void print_help_warnings(void)
        print_warning_opt_help();
 }
 
-static void print_help_optimisation(void)
+static void print_help_optimization(void)
 {
-       put_help("-O LEVEL",                 "select optimisation level (0-4)");
+       put_help("-O LEVEL",                 "select optimization level (0-4)");
+       firm_option_help(put_help);
        put_help("-fexpensive-optimizations","ignored (gcc compatibility)");
 }
 
@@ -729,7 +730,7 @@ typedef enum {
        HELP_PREPROCESSOR  = 1u << 1,
        HELP_PARSER        = 1u << 2,
        HELP_WARNINGS      = 1u << 3,
-       HELP_OPTIMISATION  = 1u << 4,
+       HELP_OPTIMIZATION  = 1u << 4,
        HELP_CODEGEN       = 1u << 5,
        HELP_LINKER        = 1u << 6,
        HELP_LANGUAGETOOLS = 1u << 7,
@@ -745,7 +746,7 @@ static void print_help(const char *argv0, help_sections_t sections)
        if (sections & HELP_PREPROCESSOR)  print_help_preprocessor();
        if (sections & HELP_PARSER)        print_help_parser();
        if (sections & HELP_WARNINGS)      print_help_warnings();
-       if (sections & HELP_OPTIMISATION)  print_help_optimisation();
+       if (sections & HELP_OPTIMIZATION)  print_help_optimization();
        if (sections & HELP_CODEGEN)       print_help_codegeneration();
        if (sections & HELP_LINKER)        print_help_linker();
        if (sections & HELP_LANGUAGETOOLS) print_help_language_tools();
@@ -898,7 +899,7 @@ int main(int argc, char **argv)
 
 #define SINGLE_OPTION(ch) (option[0] == (ch) && option[1] == '\0')
 
-       /* early options parsing (find out optimisation level and OS) */
+       /* early options parsing (find out optimization level and OS) */
        for (int i = 1; i < argc; ++i) {
                const char *arg = argv[i];
                if (arg[0] != '-')
@@ -1105,7 +1106,7 @@ int main(int argc, char **argv)
                                                fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt);
                                        } else if (streq(opt, "help")) {
                                                fprintf(stderr, "warning: -fhelp is deprecated\n");
-                                               help |= HELP_FIRM;
+                                               help |= HELP_OPTIMISATION;
                                        } else {
                                                int res = firm_option(orig_opt);
                                                if (res == 0) {
@@ -1335,6 +1336,8 @@ int main(int argc, char **argv)
                                        help |= HELP_CODEGEN;
                                } else if (streq(option, "help-linker")) {
                                        help |= HELP_LINKER;
+                               } else if (streq(option, "help-optimization")) {
+                                       help |= HELP_OPTIMIZATION;
                                } else if (streq(option, "help-language-tools")) {
                                        help |= HELP_LANGUAGETOOLS;
                                } else if (streq(option, "help-debug")) {