summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2017-02-17 06:29:56 +0100
committerMatthias Braun <matze@braunis.de>2017-02-17 06:32:56 +0100
commit90bf15b1f015560fd4f07a71c40560c6237c2a9e (patch)
tree54050f1f54a3edda04e11275b23273391d7d2727 /src
parent1013360c9a435d444ee0eaa338110e6e0c8a8b8c (diff)
Improve optimization level parsing
- Use an enum for the different optimization levels. - Set them slightly later in the initialization process (so we do not need to re-set them) - Deduce preprocessor defines from level instead of setting flags.
Diffstat (limited to 'src')
-rw-r--r--src/driver/options.c31
-rw-r--r--src/driver/predefs.c7
-rw-r--r--src/driver/predefs.h3
-rw-r--r--src/driver/target.h14
-rw-r--r--src/firm/firm_opt.c23
-rw-r--r--src/firm/firm_opt.h13
-rw-r--r--src/main.c1
7 files changed, 52 insertions, 40 deletions
diff --git a/src/driver/options.c b/src/driver/options.c
index 540ee5c..0daab06 100644
--- a/src/driver/options.c
+++ b/src/driver/options.c
@@ -27,10 +27,11 @@
#include "target.h"
#include "wrappergen/write_jna.h"
-codegen_option_t *codegen_options = NULL;
-codegen_option_t **codegen_options_anchor = &codegen_options;
-bool profile_generate;
-bool profile_use;
+codegen_option_t *codegen_options = NULL;
+codegen_option_t **codegen_options_anchor = &codegen_options;
+optimization_level_t opt_level = OPT_1;
+bool profile_generate;
+bool profile_use;
static compilation_unit_type_t forced_unittype = COMPILATION_UNIT_AUTODETECT;
@@ -725,28 +726,28 @@ bool options_parse_early_codegen(options_state_t *s)
const char *arg;
if (accept_prefix(s, "-O", false, &arg)) {
- unsigned opt_level;
if (arg[0] == '\0') {
- opt_level = 1; /* '-O' is equivalent to '-O1'. */
+ opt_level = OPT_1; /* '-O' is equivalent to '-O1'. */
} else if (is_digit(arg[0])) {
- opt_level = arg[0] - '0';
+ switch (arg[0] - '0') {
+ case 0: opt_level = OPT_0; break;
+ case 1: opt_level = OPT_1; break;
+ case 2: opt_level = OPT_2; break;
+ default: opt_level = OPT_3; break;
+ }
} else if (streq(arg, "fast")) {
- opt_level = 3; /* TODO stub. */
+ opt_level = OPT_fast;
} else if (streq(arg, "g")) {
- opt_level = 0; /* TODO stub. */
+ opt_level = OPT_g;
} else if (streq(arg, "s")) {
- opt_level = 2; /* TODO For now, until we have a real '-Os'. */
- predef_optimize_size = true;
+ opt_level = OPT_s;
} else if (streq(arg, "z")) {
- opt_level = 2; /* TODO For now until we have a real '-Oz'. */
- predef_optimize_size = true;
+ opt_level = OPT_z;
} else {
errorf(NULL, "invalid optimization option '%s'", full_option);
s->argument_errors = true;
return true;
}
- choose_optimization_pack(opt_level);
- predef_optimize = opt_level > 0;
} else
return false;
/* Remove argument so we do not parse it again in later phases */
diff --git a/src/driver/predefs.c b/src/driver/predefs.c
index b70a8e8..a217ad9 100644
--- a/src/driver/predefs.c
+++ b/src/driver/predefs.c
@@ -20,9 +20,6 @@
#include "target.h"
#include "version.h"
-bool predef_optimize;
-bool predef_optimize_size;
-
static void add_define_prop_fmt(const char *name_template, const char *name,
const char *value_fmt, ...)
{
@@ -302,9 +299,9 @@ void add_predefined_macros(void)
* of x87 inline assembly in the glibc/linux headers which we don't support
* yet */
#if 0
- if (predef_optimize)
+ if (opt_level != OPT_O0 && opt_level != OPT_Og)
add_define("__OPTIMIZE__", "1", false);
- if (predef_optimize_size)
+ if (opt_level == OPT_Os || opt_level == OPT_Oz)
add_define("__OPTIMIZE_SIZE__", "1", false);
#endif
diff --git a/src/driver/predefs.h b/src/driver/predefs.h
index 67bbdb5..d3ee5c8 100644
--- a/src/driver/predefs.h
+++ b/src/driver/predefs.h
@@ -7,9 +7,6 @@
#include <stdbool.h>
-extern bool predef_optimize;
-extern bool predef_optimize_size;
-
void add_predefined_macros(void);
#endif
diff --git a/src/driver/target.h b/src/driver/target.h
index 989a206..1d9035d 100644
--- a/src/driver/target.h
+++ b/src/driver/target.h
@@ -10,6 +10,7 @@
#include "adt/util.h"
#include "machine_triple.h"
+#include "firm/firm_opt.h"
#include "options.h"
typedef enum object_format_t {
@@ -72,11 +73,12 @@ struct codegen_option_t {
char option[];
};
-extern codegen_option_t *codegen_options;
-extern codegen_option_t **codegen_options_anchor;
-extern bool profile_generate;
-extern bool profile_use;
-extern const char *multilib_directory_target_triple;
-extern unsigned target_size_override;
+extern optimization_level_t opt_level;
+extern codegen_option_t *codegen_options;
+extern codegen_option_t **codegen_options_anchor;
+extern bool profile_generate;
+extern bool profile_use;
+extern const char *multilib_directory_target_triple;
+extern unsigned target_size_override;
#endif
diff --git a/src/firm/firm_opt.c b/src/firm/firm_opt.c
index ed893e7..f5a5ee9 100644
--- a/src/firm/firm_opt.c
+++ b/src/firm/firm_opt.c
@@ -892,32 +892,35 @@ bool firm_is_inlining_enabled(void)
return config->flags & OPT_FLAG_ENABLED;
}
-void choose_optimization_pack(int level)
+void set_optimization_level(optimization_level_t level)
{
- /* apply optimization level */
switch (level) {
- default:
- case 3:
+ case OPT_fast:
+ case OPT_3:
set_option("bool");
set_option("thread-jumps");
set_option("if-conversion");
/* FALLTHROUGH */
- case 2:
+ case OPT_2:
set_option("inline");
set_option("occults");
set_option("deconv");
set_option("memcombine");
set_be_option("omitfp");
- break;
+ return;
- case 1:
+ case OPT_s:
+ case OPT_z:
+ case OPT_1:
set_option("no-inline");
- break;
+ return;
- case 0:
+ case OPT_g:
+ case OPT_0:
set_option("no-opt");
- break;
+ return;
}
+ panic("Invalid optimization level");
}
void init_implicit_optimizations(void)
diff --git a/src/firm/firm_opt.h b/src/firm/firm_opt.h
index b9b0415..af3073e 100644
--- a/src/firm/firm_opt.h
+++ b/src/firm/firm_opt.h
@@ -96,6 +96,17 @@ enum rts_names {
rts_max
};
+typedef enum optimization_level_t {
+ OPT_0,
+ OPT_1,
+ OPT_2,
+ OPT_3,
+ OPT_fast,
+ OPT_s,
+ OPT_z,
+ OPT_g,
+} optimization_level_t;
+
extern ir_entity *rts_entities[rts_max];
/** Initialize for the Firm-generating back end. */
@@ -125,7 +136,7 @@ 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);
+void set_optimization_level(optimization_level_t opt_level);
/**
* Initialize implicit optimization settings in firm. Frontends should call this
diff --git a/src/main.c b/src/main.c
index 139b1dc..711efa8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -333,6 +333,7 @@ int main(int argc, char **argv)
/* Setup target so later options can override the target defaults */
target_set_defaults();
+ set_optimization_level(opt_level);
/* parse rest of options */
for (state.i = 1; state.i < argc; ++state.i) {