diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8f451425f3..b306bde263 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,7 +41,7 @@ jobs: run: | brew update brew upgrade - brew install boost fmt gmp llvm@15 ninja pkg-config sbcl ecl netcdf expat + brew install boost fmt gmp llvm@17 ninja pkg-config sbcl ecl netcdf expat - name: Checkout repository uses: actions/checkout@v4 diff --git a/src/lisp/kernel/cmp/cmpexports.lisp b/src/lisp/kernel/cmp/cmpexports.lisp index 65222629dd..feb1ccd997 100644 --- a/src/lisp/kernel/cmp/cmpexports.lisp +++ b/src/lisp/kernel/cmp/cmpexports.lisp @@ -151,8 +151,6 @@ irc-create-call-wft irc-calculate-entry compile-file-to-module - optimize-module-for-compile - optimize-module-for-compile-file codegen compile-error-if-not-enough-arguments compile-in-env diff --git a/src/lisp/kernel/cmp/compile-file-parallel.lisp b/src/lisp/kernel/cmp/compile-file-parallel.lisp index 7e18fc3482..f2065aa87a 100644 --- a/src/lisp/kernel/cmp/compile-file-parallel.lisp +++ b/src/lisp/kernel/cmp/compile-file-parallel.lisp @@ -185,7 +185,7 @@ (let ((module (llvm-create-module (format nil "module~a" (ast-job-form-index job)))) (core:*current-source-pos-info* (ast-job-source-pos-info job))) (with-module (:module module - :optimize (when optimize #'optimize-module-for-compile-file) + :optimize (when optimize #'llvm-sys:optimize-module) :optimize-level optimize-level) (with-debug-info-generator (:module module :pathname *compile-file-source-debug-pathname*) diff --git a/src/lisp/kernel/cmp/compile-file.lisp b/src/lisp/kernel/cmp/compile-file.lisp index 292be5428a..9374f8272d 100644 --- a/src/lisp/kernel/cmp/compile-file.lisp +++ b/src/lisp/kernel/cmp/compile-file.lisp @@ -197,7 +197,7 @@ Compile a Lisp source stream and return a corresponding LLVM module." (unless module (error "module is NIL")) (cmp-log "About to with-module%N") (with-module (:module module - :optimize (when optimize #'optimize-module-for-compile-file) + :optimize (when optimize #'llvm-sys:optimize-module) :optimize-level optimize-level) ;; (1) Generate the code (cmp-log "About to with-debug-info-generator%N") diff --git a/src/lisp/kernel/cmp/jit-setup.lisp b/src/lisp/kernel/cmp/jit-setup.lisp index 271d137010..69442bc22a 100644 --- a/src/lisp/kernel/cmp/jit-setup.lisp +++ b/src/lisp/kernel/cmp/jit-setup.lisp @@ -628,49 +628,6 @@ No DIBuilder is defined for the default module") (export 'code-model) -(defvar *size-level* 1) - -(defvar *optimization-pipelines* - '(0 "default" - 1 "default" - 2 "default" - 3 "default")) - -(defun optimize-module-for-compile-file (module &optional (optimize-level *optimization-level*)) - (declare (type (or null llvm-sys:module) module)) - (let ((pipeline (getf *optimization-pipelines* optimize-level))) - (when pipeline - (llvm-sys:optimize-module module pipeline)) - module)) - -(defun optimize-module-for-compile (module) - module) - -#+(or) -(defun optimize-module-for-compile (module &optional (optimize-level *optimization-level*) (size-level *size-level*)) - (declare (type (or null llvm-sys:module) module)) - (when (> *optimization-level* 0) - #++(let ((call-sites (call-sites-to-always-inline module))) - (core:fmt t "Call-sites -> {}%N" call-sites)) - (let* ((pass-manager-builder (llvm-sys:make-pass-manager-builder)) - (mpm (llvm-sys:make-pass-manager)) - (fpm (llvm-sys:make-function-pass-manager module)) - (olevel optimize-level)) - (llvm-sys:pass-manager-builder-setf-opt-level pass-manager-builder olevel) - (llvm-sys:pass-manager-builder-setf-size-level pass-manager-builder size-level) - (llvm-sys:pass-manager-builder-setf-inliner pass-manager-builder (llvm-sys:create-always-inliner-legacy-pass)) - (llvm-sys:populate-function-pass-manager pass-manager-builder fpm) - (llvm-sys:populate-module-pass-manager pass-manager-builder mpm) - (llvm-sys:do-initialization fpm) - (let ((funcs (llvm-sys:module-get-function-list module))) - (dolist (func funcs) - (llvm-sys:function-pass-manager-run fpm func))) - (llvm-sys:do-finalization fpm) - (llvm-sys:pass-manager-run mpm module))) - module) - - - (defun remove-always-inline-from-functions (module) (let ((functions (llvm-sys:module-get-function-list module)) inline-functions) diff --git a/src/llvmo/llvmoExpose.cc b/src/llvmo/llvmoExpose.cc index 1e373afcc1..d6a854754f 100644 --- a/src/llvmo/llvmoExpose.cc +++ b/src/llvmo/llvmoExpose.cc @@ -4237,14 +4237,16 @@ CL_DEFUN void llvm_sys__removeAlwaysInlineFunctions(llvm::Module* module) } DOCGROUP(clasp); -CL_DEFUN void llvm_sys__optimizeModule(llvm::Module *module, const string &pipelineText) { +CL_DEFUN void llvm_sys__optimizeModule(llvm::Module *module, int level) { llvm::LoopAnalysisManager LAM; llvm::FunctionAnalysisManager FAM; llvm::CGSCCAnalysisManager CGAM; llvm::ModuleAnalysisManager MAM; llvm::PipelineTuningOptions pipeline_opts; +#if LLVM_VERSION_MAJOR > 15 pipeline_opts.InlinerThreshold = 0; +#endif llvm::PassBuilder PB(NULL, pipeline_opts); llvm::ModulePassManager MPM; @@ -4255,9 +4257,23 @@ CL_DEFUN void llvm_sys__optimizeModule(llvm::Module *module, const string &pipel PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); - if (PB.parsePassPipeline(MPM, pipelineText)) { - SIMPLE_ERROR("Unable to parse optimization pipeline: {}", pipelineText); + llvm::OptimizationLevel opt_level = OptimizationLevel::O0; + +#if LLVM_VERSION_MAJOR > 15 + switch (level) { + case 1: + opt_level = OptimizationLevel::O1; + break; + case 2: + opt_level = OptimizationLevel::O2; + break; + case 3: + opt_level = OptimizationLevel::O3; + break; } +#endif + + PB.buildPerModuleDefaultPipeline(opt_level); MPM.run(*module, MAM); }