Skip to content

Commit

Permalink
Add PassManager from/to raw methods
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Dec 10, 2024
1 parent a1a203d commit 9373418
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion melior/src/pass/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mlir_sys::{
mlirPassManagerGetAsOpPassManager, mlirPassManagerGetNestedUnder, mlirPassManagerRunOnOp,
MlirPassManager,
};
use std::marker::PhantomData;
use std::{marker::PhantomData, mem::forget};

/// A pass manager.
pub struct PassManager<'c> {
Expand Down Expand Up @@ -68,6 +68,29 @@ impl PassManager<'_> {
pub fn as_operation_pass_manager(&self) -> OperationPassManager {
unsafe { OperationPassManager::from_raw(mlirPassManagerGetAsOpPassManager(self.raw)) }
}

/// Creates a PassManager from the given raw pointer.
///
/// # Safety
/// Caller must ensure this is a valid PassManager pointer.
pub unsafe fn from_raw(raw: MlirPassManager) -> Self {
Self {
raw,
_context: Default::default(),
}
}

/// Gets the raw object of this pass manager.
pub const fn to_raw(&self) -> MlirPassManager {
self.raw
}

/// Converts a PassManager into an owned raw object.
pub const fn into_raw(self) -> MlirPassManager {
let raw = self.raw;
forget(self);
raw
}
}

impl Drop for PassManager<'_> {
Expand Down

0 comments on commit 9373418

Please sign in to comment.