Skip to content

Commit

Permalink
Merge branch 'main' into make-block-api-trait
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l authored Jan 2, 2025
2 parents 549f042 + 5af479f commit 6c7bfc3
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "melior-macro"
description = "Internal macros for Melior"
version = "0.12.2"
version = "0.13.2"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/mlir-sys/melior"
documentation = "https://mlir-sys.github.io/melior/melior/"
repository = "https://github.com/mlir-rs/melior"
documentation = "https://mlir-rs.github.io/melior/melior/"
readme = "../README.md"
keywords = ["mlir", "llvm"]

[lib]
proc-macro = true

[dependencies]
comrak = { version = "0.31.0", default-features = false }
comrak = { version = "0.32.0", default-features = false }
convert_case = "0.6.0"
proc-macro2 = "1"
quote = "1"
Expand Down
8 changes: 4 additions & 4 deletions melior/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "melior"
description = "The rustic MLIR bindings in Rust"
version = "0.19.2"
version = "0.20.2"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/mlir-sys/melior"
documentation = "https://mlir-sys.github.io/melior/melior/"
repository = "https://github.com/mlir-rs/melior"
documentation = "https://mlir-rs.github.io/melior/melior/"
keywords = ["mlir", "llvm"]

[features]
Expand All @@ -14,7 +14,7 @@ ods-dialects = []
helpers = ["ods-dialects"]

[dependencies]
melior-macro = { version = "0.12.2", path = "../macro" }
melior-macro = { version = "0.13.2", path = "../macro" }
mlir-sys = "0.4.1"

[dev-dependencies]
Expand Down
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
21 changes: 18 additions & 3 deletions melior/src/utility.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Utility functions.
use crate::{
context::Context, dialect::DialectRegistry, logical_result::LogicalResult, pass,
context::Context, dialect::DialectRegistry, ir::Module, logical_result::LogicalResult, pass,
string_ref::StringRef, Error,
};
use mlir_sys::{
mlirParsePassPipeline, mlirRegisterAllDialects, mlirRegisterAllLLVMTranslations,
mlirRegisterAllPasses, MlirStringRef,
mlirLoadIRDLDialects, mlirParsePassPipeline, mlirRegisterAllDialects,
mlirRegisterAllLLVMTranslations, mlirRegisterAllPasses, MlirStringRef,
};
use std::{
ffi::c_void,
Expand Down Expand Up @@ -54,6 +54,11 @@ pub fn parse_pass_pipeline(manager: pass::OperationPassManager, source: &str) ->
}
}

/// Loads all IRDL dialects in the provided module, registering the dialects in the module's associated context.
pub fn load_irdl_dialects(module: &Module) -> bool {
unsafe { mlirLoadIRDLDialects(module.to_raw()).value == 1 }
}

unsafe extern "C" fn handle_parse_error(raw_string: MlirStringRef, data: *mut c_void) {
let string = StringRef::from_raw(raw_string);
let data = &mut *(data as *mut Option<String>);
Expand Down Expand Up @@ -99,6 +104,8 @@ pub(crate) unsafe extern "C" fn print_string_callback(string: MlirStringRef, dat

#[cfg(test)]
mod tests {
use crate::ir::Location;

use super::*;

#[test]
Expand Down Expand Up @@ -148,4 +155,12 @@ mod tests {
register_all_passes();
}
}

#[test]
fn test_load_irdl_dialects() {
let context = Context::new();
let module = Module::new(Location::unknown(&context));

assert!(load_irdl_dialects(&module));
}
}
15 changes: 15 additions & 0 deletions tools/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e

level=${1:-patch}

if [ $# -gt 0 ]; then
shift 1
fi

options="$@"

cd $(dirname $0)/..

cargo release version $level --execute --no-confirm --allow-branch '*' $options

0 comments on commit 6c7bfc3

Please sign in to comment.