Skip to content

Commit 8852db0

Browse files
authored
Merge pull request rust-lang#104 from wasmerio/debug
Move PassManager::{initialize,finalize} to PassManager<FunctionValue>.
2 parents 4813026 + 26a9366 commit 8852db0

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/passes.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,21 @@ pub struct PassManager<T> {
209209
sub_type: PhantomData<T>,
210210
}
211211

212+
impl PassManager<FunctionValue> {
213+
// return true means some pass modified the module, not an error occurred
214+
pub fn initialize(&self) -> bool {
215+
unsafe {
216+
LLVMInitializeFunctionPassManager(self.pass_manager) == 1
217+
}
218+
}
219+
220+
pub fn finalize(&self) -> bool {
221+
unsafe {
222+
LLVMFinalizeFunctionPassManager(self.pass_manager) == 1
223+
}
224+
}
225+
}
226+
212227
impl<T: PassManagerSubType> PassManager<T> {
213228
pub(crate) fn new(pass_manager: LLVMPassManagerRef) -> Self {
214229
assert!(!pass_manager.is_null());
@@ -227,19 +242,6 @@ impl<T: PassManagerSubType> PassManager<T> {
227242
PassManager::new(pass_manager)
228243
}
229244

230-
// return true means some pass modified the module, not an error occurred
231-
pub fn initialize(&self) -> bool {
232-
unsafe {
233-
LLVMInitializeFunctionPassManager(self.pass_manager) == 1
234-
}
235-
}
236-
237-
pub fn finalize(&self) -> bool {
238-
unsafe {
239-
LLVMFinalizeFunctionPassManager(self.pass_manager) == 1
240-
}
241-
}
242-
243245
/// This method returns true if any of the passes modified the function or module
244246
/// and false otherwise.
245247
pub fn run_on(&self, input: &T) -> bool {

tests/all/test_passes.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,7 @@ fn test_init_all_passes_for_module() {
8282
pass_manager.add_loop_unroll_and_jam_pass();
8383
}
8484

85-
assert!(!pass_manager.initialize());
86-
assert!(!pass_manager.finalize());
87-
8885
pass_manager.run_on(&module);
89-
90-
assert!(!pass_manager.initialize());
91-
assert!(!pass_manager.finalize());
92-
93-
// TODO: Test when initialize and finalize are true
9486
}
9587

9688
#[test]
@@ -120,11 +112,18 @@ fn test_pass_manager_builder() {
120112
builder.position_at_end(&entry);
121113
builder.build_return(None);
122114

115+
#[cfg(not(feature = "llvm3-7"))]
116+
assert!(!fn_pass_manager.initialize());
117+
#[cfg(feature = "llvm3-7")]
118+
fn_pass_manager.initialize();
119+
123120
// TODO: Test with actual changes? Would be true in that case
124121
// REVIEW: Segfaults in 4.0
125122
#[cfg(not(feature = "llvm4-0"))]
126123
assert!(!fn_pass_manager.run_on(&fn_value));
127124

125+
assert!(!fn_pass_manager.finalize());
126+
128127
let module_pass_manager = PassManager::create(());
129128

130129
pass_manager_builder.populate_module_pass_manager(&module_pass_manager);

0 commit comments

Comments
 (0)