Skip to content

Commit

Permalink
Merge pull request rust-lang#104 from wasmerio/debug
Browse files Browse the repository at this point in the history
Move PassManager::{initialize,finalize} to PassManager<FunctionValue>.
  • Loading branch information
TheDan64 authored Jul 30, 2019
2 parents 4813026 + 26a9366 commit 8852db0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
28 changes: 15 additions & 13 deletions src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ pub struct PassManager<T> {
sub_type: PhantomData<T>,
}

impl PassManager<FunctionValue> {
// 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<T: PassManagerSubType> PassManager<T> {
pub(crate) fn new(pass_manager: LLVMPassManagerRef) -> Self {
assert!(!pass_manager.is_null());
Expand All @@ -227,19 +242,6 @@ impl<T: PassManagerSubType> PassManager<T> {
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 {
Expand Down
15 changes: 7 additions & 8 deletions tests/all/test_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8852db0

Please sign in to comment.