optimize.scm 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ;;; Optimization flags
  2. ;; Copyright (C) 2018,2020-2022,2024 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. (#:demux-lambda? 2)
  31. (#:seal-private-bindings? 3)
  32. (#:partial-eval? 1)
  33. (#:eta-expand? 2)
  34. (#:inlinable-exports? 2)
  35. (#:cross-module-inlining? 2)))
  36. ('cps
  37. '( ;; (#:split-rec? #t)
  38. (#:simplify? 2)
  39. (#:eliminate-dead-code? 2)
  40. (#:prune-top-level-scopes? 2)
  41. (#:contify? 2)
  42. (#:specialize-primcalls? 2)
  43. (#:peel-loops? 2)
  44. (#:cse? 2)
  45. (#:type-fold? 2)
  46. (#:elide-arity-checks? 2)
  47. (#:optimize-known-return-types? 2)
  48. (#:resolve-self-references? 2)
  49. (#:devirtualize-integers? 2)
  50. (#:specialize-numbers? 2)
  51. (#:optimize-branch-chains? 2)
  52. (#:licm? 2)
  53. (#:rotate-loops? 2)
  54. ;; This one is used by the slot allocator.
  55. (#:precolor-calls? 2)))
  56. (#f
  57. (append (available-optimizations 'tree-il)
  58. (available-optimizations 'cps)))))
  59. (define (pass-optimization-level kw)
  60. (match (assq kw (available-optimizations))
  61. ((kw level) level)
  62. (_ (error "unknown optimization" kw))))
  63. ;; Turn on all optimizations unless -O0.
  64. (define (optimizations-for-level level)
  65. (let lp ((options (available-optimizations)))
  66. (match options
  67. (() '())
  68. (((kw at-level) . options)
  69. (cons* kw (<= at-level level) (lp options))))))