diff --git a/src/passes.rs b/src/passes.rs index be311bbaaf74f..13eed358c86b4 100644 --- a/src/passes.rs +++ b/src/passes.rs @@ -209,6 +209,21 @@ pub struct PassManager { sub_type: PhantomData, } +impl PassManager { + // return true means some pass modified the module, not an error occurred + pub fn initialize(&self) -> bool { + unsafe { + LLVMInitializeFunctionPassManager(self.pass_manager) == 1 + } + } + + pub fn finalize(&self) -> bool { + unsafe { + LLVMFinalizeFunctionPassManager(self.pass_manager) == 1 + } + } +} + impl PassManager { pub(crate) fn new(pass_manager: LLVMPassManagerRef) -> Self { assert!(!pass_manager.is_null()); @@ -227,19 +242,6 @@ impl PassManager { PassManager::new(pass_manager) } - // return true means some pass modified the module, not an error occurred - pub fn initialize(&self) -> bool { - unsafe { - LLVMInitializeFunctionPassManager(self.pass_manager) == 1 - } - } - - pub fn finalize(&self) -> bool { - unsafe { - LLVMFinalizeFunctionPassManager(self.pass_manager) == 1 - } - } - /// This method returns true if any of the passes modified the function or module /// and false otherwise. pub fn run_on(&self, input: &T) -> bool { diff --git a/tests/all/test_passes.rs b/tests/all/test_passes.rs index b598b06d742c8..22566ff495b64 100644 --- a/tests/all/test_passes.rs +++ b/tests/all/test_passes.rs @@ -82,15 +82,7 @@ fn test_init_all_passes_for_module() { pass_manager.add_loop_unroll_and_jam_pass(); } - assert!(!pass_manager.initialize()); - assert!(!pass_manager.finalize()); - pass_manager.run_on(&module); - - assert!(!pass_manager.initialize()); - assert!(!pass_manager.finalize()); - - // TODO: Test when initialize and finalize are true } #[test] @@ -120,11 +112,18 @@ fn test_pass_manager_builder() { builder.position_at_end(&entry); builder.build_return(None); + #[cfg(not(feature = "llvm3-7"))] + assert!(!fn_pass_manager.initialize()); + #[cfg(feature = "llvm3-7")] + fn_pass_manager.initialize(); + // TODO: Test with actual changes? Would be true in that case // REVIEW: Segfaults in 4.0 #[cfg(not(feature = "llvm4-0"))] assert!(!fn_pass_manager.run_on(&fn_value)); + assert!(!fn_pass_manager.finalize()); + let module_pass_manager = PassManager::create(()); pass_manager_builder.populate_module_pass_manager(&module_pass_manager);