@@ -415,11 +415,12 @@ pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
415415
416416pub ( crate ) unsafe fn optimize_with_new_llvm_pass_manager (
417417 cgcx : & CodegenContext < LlvmCodegenBackend > ,
418+ diag_handler : & Handler ,
418419 module : & ModuleCodegen < ModuleLlvm > ,
419420 config : & ModuleConfig ,
420421 opt_level : config:: OptLevel ,
421422 opt_stage : llvm:: OptStage ,
422- ) {
423+ ) -> Result < ( ) , FatalError > {
423424 let unroll_loops =
424425 opt_level != config:: OptLevel :: Size && opt_level != config:: OptLevel :: SizeMin ;
425426 let using_thin_buffers = opt_stage == llvm:: OptStage :: PreLinkThinLTO || config. bitcode_needed ( ) ;
@@ -449,13 +450,12 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
449450 std:: ptr:: null_mut ( )
450451 } ;
451452
453+ let extra_passes = config. passes . join ( "," ) ;
454+
452455 // FIXME: NewPM doesn't provide a facility to pass custom InlineParams.
453456 // We would have to add upstream support for this first, before we can support
454457 // config.inline_threshold and our more aggressive default thresholds.
455- // FIXME: NewPM uses an different and more explicit way to textually represent
456- // pass pipelines. It would probably make sense to expose this, but it would
457- // require a different format than the current -C passes.
458- llvm:: LLVMRustOptimizeWithNewPassManager (
458+ let result = llvm:: LLVMRustOptimizeWithNewPassManager (
459459 module. module_llvm . llmod ( ) ,
460460 & * module. module_llvm . tm ,
461461 to_pass_builder_opt_level ( opt_level) ,
@@ -477,7 +477,10 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
477477 llvm_selfprofiler,
478478 selfprofile_before_pass_callback,
479479 selfprofile_after_pass_callback,
480+ extra_passes. as_ptr ( ) . cast ( ) ,
481+ extra_passes. len ( ) ,
480482 ) ;
483+ result. into_result ( ) . map_err ( |( ) | llvm_err ( diag_handler, "failed to run LLVM passes" ) )
481484}
482485
483486// Unsafe due to LLVM calls.
@@ -486,7 +489,7 @@ pub(crate) unsafe fn optimize(
486489 diag_handler : & Handler ,
487490 module : & ModuleCodegen < ModuleLlvm > ,
488491 config : & ModuleConfig ,
489- ) {
492+ ) -> Result < ( ) , FatalError > {
490493 let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_optimize" , & module. name [ ..] ) ;
491494
492495 let llmod = module. module_llvm . llmod ( ) ;
@@ -511,8 +514,14 @@ pub(crate) unsafe fn optimize(
511514 _ if cgcx. opts . cg . linker_plugin_lto . enabled ( ) => llvm:: OptStage :: PreLinkThinLTO ,
512515 _ => llvm:: OptStage :: PreLinkNoLTO ,
513516 } ;
514- optimize_with_new_llvm_pass_manager ( cgcx, module, config, opt_level, opt_stage) ;
515- return ;
517+ return optimize_with_new_llvm_pass_manager (
518+ cgcx,
519+ diag_handler,
520+ module,
521+ config,
522+ opt_level,
523+ opt_stage,
524+ ) ;
516525 }
517526
518527 if cgcx. prof . llvm_recording_enabled ( ) {
@@ -647,6 +656,7 @@ pub(crate) unsafe fn optimize(
647656 llvm:: LLVMDisposePassManager ( fpm) ;
648657 llvm:: LLVMDisposePassManager ( mpm) ;
649658 }
659+ Ok ( ( ) )
650660}
651661
652662unsafe fn add_sanitizer_passes ( config : & ModuleConfig , passes : & mut Vec < & ' static mut llvm:: Pass > ) {
0 commit comments