[runtime] Fix parse_optimizations () so the optimization names don't … (#4300)
authorZoltan Varga <vargaz@gmail.com>
Wed, 1 Feb 2017 12:42:14 +0000 (07:42 -0500)
committerGitHub <noreply@github.com>
Wed, 1 Feb 2017 12:42:14 +0000 (07:42 -0500)
* [runtime] Fix parse_optimizations () so the optimization names don't need to be in a particular order.

* [jit] Avoid unused bits in optflags.

mono/mini/driver.c
mono/mini/optflags-def.h

index 018657b181a0cd0faaba08bc628aa1cc843c5d0f..357c1cd5057c99b612ccafba0c94f32a031ad6e9 100644 (file)
@@ -120,11 +120,6 @@ opt_names [] = {
 
 #endif
 
-static const OptFunc
-opt_funcs [sizeof (int) * 8] = {
-       NULL
-};
-
 #ifdef __native_client__
 extern char *nacl_mono_path;
 #endif
@@ -154,7 +149,8 @@ parse_optimizations (guint32 opt, const char* p, gboolean cpu_opts)
 {
        guint32 exclude = 0;
        const char *n;
-       int i, invert, len;
+       int i, invert;
+       char **parts, **ptr;
 
        /* Initialize the hwcap module if necessary. */
        mono_hwcap_init ();
@@ -167,7 +163,11 @@ parse_optimizations (guint32 opt, const char* p, gboolean cpu_opts)
        if (!p)
                return opt;
 
-       while (*p) {
+       parts = g_strsplit (p, ",", -1);
+       for (ptr = parts; ptr && *ptr; ptr ++) {
+               char *arg = *ptr;
+               char *p = arg;
+
                if (*p == '-') {
                        p++;
                        invert = TRUE;
@@ -176,24 +176,11 @@ parse_optimizations (guint32 opt, const char* p, gboolean cpu_opts)
                }
                for (i = 0; i < G_N_ELEMENTS (opt_names) && optflag_get_name (i); ++i) {
                        n = optflag_get_name (i);
-                       len = strlen (n);
-                       if (strncmp (p, n, len) == 0) {
+                       if (!strcmp (p, n)) {
                                if (invert)
                                        opt &= ~ (1 << i);
                                else
                                        opt |= 1 << i;
-                               p += len;
-                               if (*p == ',') {
-                                       p++;
-                                       break;
-                               } else if (*p == '=') {
-                                       p++;
-                                       if (opt_funcs [i])
-                                               opt_funcs [i] (p);
-                                       while (*p && *p++ != ',');
-                                       break;
-                               }
-                               /* error out */
                                break;
                        }
                }
@@ -203,15 +190,16 @@ parse_optimizations (guint32 opt, const char* p, gboolean cpu_opts)
                                        opt = 0;
                                else
                                        opt = ~(EXCLUDED_FROM_ALL | exclude);
-                               p += 3;
-                               if (*p == ',')
-                                       p++;
                        } else {
                                fprintf (stderr, "Invalid optimization name `%s'\n", p);
                                exit (1);
                        }
                }
+
+               g_free (arg);
        }
+       g_free (parts);
+
        return opt;
 }
 
index b72ab7a227d2d0d24b4ae195ddd4e4ea538f397f..c9eb600d46c527e85ffdc68b399506792823e978 100644 (file)
@@ -20,12 +20,10 @@ OPTFLAG(ABCREM   ,18, "abcrem",     "Array bound checks removal")
 OPTFLAG(SSAPRE   ,19, "ssapre",     "SSA based Partial Redundancy Elimination (obsolete)")
 OPTFLAG(EXCEPTION,20, "exception",  "Optimize exception catch blocks")
 OPTFLAG(SSA      ,21, "ssa",        "Use plain SSA form")
+OPTFLAG(FLOAT32  ,22, "float32",    "Use 32 bit float arithmetic if possible")
 OPTFLAG(SSE2     ,23, "sse2",       "SSE2 instructions on x86")
-/* The id has to be smaller than gshared's, the parser code depends on this */
 OPTFLAG(GSHAREDVT,24, "gsharedvt",     "Generic sharing for valuetypes")
-OPTFLAG (GSHARED, 25, "gshared", "Generic Sharing")
+OPTFLAG (GSHARED, 25, "gshared",     "Generic Sharing")
 OPTFLAG(SIMD    ,26, "simd",       "Simd intrinsics")
 OPTFLAG(UNSAFE  ,27, "unsafe",     "Remove bound checks and perform other dangerous changes")
 OPTFLAG(ALIAS_ANALYSIS  ,28, "alias-analysis",      "Alias analysis of locals")
-OPTFLAG(FLOAT32  ,29, "float32",    "Use 32 bit float arithmetic if possible")
-