Skip to content

Commit

Permalink
Use O0 for LLVM15
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Sep 23, 2023
1 parent 5570486 commit 53d2241
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/lisp/kernel/cmp/cmpexports.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lisp/kernel/cmp/compile-file-parallel.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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*)
Expand Down
2 changes: 1 addition & 1 deletion src/lisp/kernel/cmp/compile-file.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
43 changes: 0 additions & 43 deletions src/lisp/kernel/cmp/jit-setup.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -628,49 +628,6 @@ No DIBuilder is defined for the default module")

(export 'code-model)

(defvar *size-level* 1)

(defvar *optimization-pipelines*
'(0 "default<O0>"
1 "default<O1>"
2 "default<O2>"
3 "default<O3>"))

(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)
Expand Down
22 changes: 19 additions & 3 deletions src/llvmo/llvmoExpose.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 53d2241

Please sign in to comment.