1. Victor Stinner
  2. astoptimizer

Commits

Victor Stinner  committed 4bd5358

Config: add enable_all_optimizations() method

  • Participants
  • Parent commits d6ac309
  • Branches default

Comments (0)

Files changed (3)

File README

View file
  • Ignore whitespace
    the CPython test suite. Only use it for tests.
 
 Use ``Config("builtin_funcs", "pythonbin")`` to enable most optimizations.  You
-may also enable ``"pythonenv"`` to enable all optimizations, but then the
+may also enable ``"pythonenv"`` to enable more optimizations, but then the
 optimized code will depends on environment variables and Python command line
 options.
 
+Use config.enable_all_optimizations() to enable all optimizations, which may
+generate invalid code.
+
 
 Advices
 =======
 
 Changes:
 
+ * Add Config.enable_all_optimizations() method
  * Unroll loops (no support for break/continue yet)
  * Remove useless instructions. Example:
    "x=1; 'abc'; print(x)" => "x=1; print(x)"

File astoptimizer/config.py

View file
  • Ignore whitespace
         mod = getattr(mod, modname)
         mod.setup_config(self)
 
+    def enable_all_optimizations(self):
+        for feature in (
+            'builtin_funcs',
+            'builtin_types',
+            'math',
+            'platform',
+            'pythonbin',
+            'pythonenv',
+            'string',
+            'struct',
+        ):
+            self.enable(feature)
+        self.remove_dead_code = True
+        #self.use_experimental_vars = True
+
     def _add_module(self, name):
         if '.' not in name:
             return

File demo.py

View file
  • Ignore whitespace
         code_str = '\n'.join(args)
 
     config = Config()
+    if options.all:
+        config.enable_all_optimizations()
     if not options.n:
         for feature in options.enable.split(','):
             config.enable(feature) #'builtin_funcs', 'pythonenv')