optimize.scm 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ;;; Optimization flags
  2. ;; Copyright (C) 2018, 2020-2022 Free Software Foundation, Inc.
  3. ;;;; This library is free software; you can redistribute it and/or
  4. ;;;; modify it under the terms of the GNU Lesser General Public
  5. ;;;; License as published by the Free Software Foundation; either
  6. ;;;; version 3 of the License, or (at your option) any later version.
  7. ;;;;
  8. ;;;; This library is distributed in the hope that it will be useful,
  9. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. ;;;; Lesser General Public License for more details.
  12. ;;;;
  13. ;;;; You should have received a copy of the GNU Lesser General Public
  14. ;;;; License along with this library; if not, write to the Free Software
  15. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. ;;; Code:
  17. (define-module (system base optimize)
  18. #:use-module (ice-9 match)
  19. #:export (available-optimizations
  20. pass-optimization-level
  21. optimizations-for-level))
  22. (define* (available-optimizations #:optional lang-name)
  23. (match lang-name
  24. ('tree-il
  25. '((#:cps? 2)
  26. (#:resolve-free-vars? 2)
  27. (#:resolve-primitives? 1)
  28. (#:expand-primitives? 1)
  29. (#:letrectify? 2)
  30. (#:seal-private-bindings? 3)
  31. (#:partial-eval? 1)
  32. (#:eta-expand? 2)
  33. (#:inlinable-exports? 2)
  34. (#:cross-module-inlining? 2)))
  35. ('cps
  36. '( ;; (#:split-rec? #t)
  37. (#:simplify? 2)
  38. (#:eliminate-dead-code? 2)
  39. (#:prune-top-level-scopes? 2)
  40. (#:contify? 2)
  41. (#:specialize-primcalls? 2)
  42. (#:peel-loops? 2)
  43. (#:cse? 2)
  44. (#:type-fold? 2)
  45. (#:elide-arity-checks? 2)
  46. (#:optimize-known-return-types? 2)
  47. (#:resolve-self-references? 2)
  48. (#:devirtualize-integers? 2)
  49. (#:specialize-numbers? 2)
  50. (#:optimize-branch-chains? 2)
  51. (#:licm? 2)
  52. (#:rotate-loops? 2)
  53. ;; This one is used by the slot allocator.
  54. (#:precolor-calls? 2)))
  55. (#f
  56. (append (available-optimizations 'tree-il)
  57. (available-optimizations 'cps)))))
  58. (define (pass-optimization-level kw)
  59. (match (assq kw (available-optimizations))
  60. ((kw level) level)
  61. (_ (error "unknown optimization" kw))))
  62. ;; Turn on all optimizations unless -O0.
  63. (define (optimizations-for-level level)
  64. (let lp ((options (available-optimizations)))
  65. (match options
  66. (() '())
  67. (((kw at-level) . options)
  68. (cons* kw (<= at-level level) (lp options))))))