From 3fcdd364c58d2433f674ade045575237cf7a0dec Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Thu, 25 Jul 2019 21:16:08 -0700 Subject: [PATCH 1/2] Move PassManager::{initialize,finalize} to PassManager only. --- src/passes.rs | 28 +++++++++++++++------------- tests/all/test_passes.rs | 11 +++-------- 2 files changed, 18 insertions(+), 21 deletions(-) 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..76d5c3e251aa8 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] @@ -125,6 +117,9 @@ fn test_pass_manager_builder() { #[cfg(not(feature = "llvm4-0"))] assert!(!fn_pass_manager.run_on(&fn_value)); + assert!(!fn_pass_manager.initialize()); + assert!(!fn_pass_manager.finalize()); + let module_pass_manager = PassManager::create(()); pass_manager_builder.populate_module_pass_manager(&module_pass_manager); From 26a9366bb357a078d04ee512c06b11a38581b8f4 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 29 Jul 2019 11:41:03 -0700 Subject: [PATCH 2/2] In LLVM 3.7 BasicAA always returns true from doInitialization even though it never modifies the IR. --- tests/all/test_passes.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/all/test_passes.rs b/tests/all/test_passes.rs index 76d5c3e251aa8..22566ff495b64 100644 --- a/tests/all/test_passes.rs +++ b/tests/all/test_passes.rs @@ -112,12 +112,16 @@ 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.initialize()); assert!(!fn_pass_manager.finalize()); let module_pass_manager = PassManager::create(());