From 9da524619e25bf91e36cd8db4c890e465fd61811 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Tue, 10 Dec 2024 10:50:11 -0300 Subject: [PATCH 1/4] Add load_irdl_dialects --- melior/src/utility.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/melior/src/utility.rs b/melior/src/utility.rs index ed450bf673..986a099781 100644 --- a/melior/src/utility.rs +++ b/melior/src/utility.rs @@ -1,12 +1,10 @@ //! Utility functions. use crate::{ - context::Context, dialect::DialectRegistry, logical_result::LogicalResult, pass, - string_ref::StringRef, Error, + 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, @@ -54,6 +52,13 @@ 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); @@ -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] @@ -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)); + } } From 7f5109a342b554cbecff8f279098e8ed7a990564 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Tue, 10 Dec 2024 11:51:54 -0300 Subject: [PATCH 2/4] Fix ods include paths --- macro/src/dialect.rs | 16 +++++++++++++++- melior/src/dialect/ods.rs | 2 +- melior/src/utility.rs | 10 +++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/macro/src/dialect.rs b/macro/src/dialect.rs index f9e4662f88..cd9aae7c2d 100644 --- a/macro/src/dialect.rs +++ b/macro/src/dialect.rs @@ -16,13 +16,27 @@ use operation::Operation; use proc_macro::TokenStream; use proc_macro2::Span; use quote::quote; -use std::{env, fmt::Display, str}; +use std::{env, fmt::Display, path::Path, str}; use tblgen::{record::Record, record_keeper::RecordKeeper, TableGenParser}; pub fn generate_dialect(input: DialectInput) -> Result> { let mut parser = TableGenParser::new(); if let Some(source) = input.table_gen() { + let base = Path::new(env!("LLVM_INCLUDE_DIRECTORY")); + + // Here source looks like " include "somepathto.td" include "somepathto2.td" " + for (i, p) in source.split_ascii_whitespace().enumerate() { + if i % 2 == 0 { + continue; // skip "include" + } + + let x = &p[1..(p.len() - 1)]; // remove "" + let path = Path::new(x).parent().unwrap(); + let path = base.join(path); + parser = parser.add_include_path(&path.to_string_lossy()); + } + parser = parser.add_source(source).map_err(create_syn_error)?; } diff --git a/melior/src/dialect/ods.rs b/melior/src/dialect/ods.rs index 6c9ab91cbe..2ba5beee87 100644 --- a/melior/src/dialect/ods.rs +++ b/melior/src/dialect/ods.rs @@ -65,7 +65,7 @@ melior_macro::dialect! { } melior_macro::dialect! { name: "irdl", - table_gen: r#"include "mlir/Dialect/IRDL/IR/IRDL.td""# + table_gen: r#"include "mlir/Dialect/IRDL/IR/IRDLOps.td""# } melior_macro::dialect! { name: "llvm", diff --git a/melior/src/utility.rs b/melior/src/utility.rs index 986a099781..ac8fa9d0c3 100644 --- a/melior/src/utility.rs +++ b/melior/src/utility.rs @@ -1,10 +1,12 @@ //! Utility functions. use crate::{ - context::Context, dialect::DialectRegistry, ir::Module, logical_result::LogicalResult, pass, string_ref::StringRef, Error + context::Context, dialect::DialectRegistry, ir::Module, logical_result::LogicalResult, pass, + string_ref::StringRef, Error, }; use mlir_sys::{ - mlirLoadIRDLDialects, mlirParsePassPipeline, mlirRegisterAllDialects, mlirRegisterAllLLVMTranslations, mlirRegisterAllPasses, MlirStringRef + mlirLoadIRDLDialects, mlirParsePassPipeline, mlirRegisterAllDialects, + mlirRegisterAllLLVMTranslations, mlirRegisterAllPasses, MlirStringRef, }; use std::{ ffi::c_void, @@ -54,9 +56,7 @@ 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 { mlirLoadIRDLDialects(module.to_raw()).value == 1 } } unsafe extern "C" fn handle_parse_error(raw_string: MlirStringRef, data: *mut c_void) { From 6e50a9ab31dce96fe64598735049444b7c9d0dc4 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Tue, 10 Dec 2024 12:14:17 -0300 Subject: [PATCH 3/4] more dialects --- melior/src/dialect/ods.rs | 44 ++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/melior/src/dialect/ods.rs b/melior/src/dialect/ods.rs index 2ba5beee87..370048c7ed 100644 --- a/melior/src/dialect/ods.rs +++ b/melior/src/dialect/ods.rs @@ -9,11 +9,14 @@ pub mod __private { melior_macro::dialect! { name: "affine", - table_gen: r#"include "mlir/Dialect/Affine/IR/AffineOps.td""# + table_gen: r#"include "mlir/Dialect/Affine/IR/AffineOps.td" + include "mlir/Dialect/Affine/TransformOps/AffineTransformOps.td" + include "mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td""# } melior_macro::dialect! { name: "amdgpu", - table_gen: r#"include "mlir/Dialect/AMDGPU/IR/AMDGPU.td""# + table_gen: r#"include "mlir/Dialect/AMDGPU/IR/AMDGPU.td" + include "mlir/Dialect/AMDGPU/Transforms/Passes.td""# } melior_macro::dialect! { name: "arith", @@ -27,9 +30,17 @@ melior_macro::dialect! { name: "arm_sve", table_gen: r#"include "mlir/Dialect/ArmSVE/IR/ArmSVE.td""# } +melior_macro::dialect! { + name: "arm_sme", + table_gen: r#"include "mlir/Dialect/ArmSME/IR/ArmSME.td" + include "mlir/Dialect/ArmSME/IR/ArmSMEOps.td" + include "mlir/Dialect/ArmSME/IR/ArmSMEIntrinsicOps.td""# +} melior_macro::dialect! { name: "async", - table_gen: r#"include "mlir/Dialect/Async/IR/AsyncOps.td""# + table_gen: r#"include "mlir/Dialect/Async/IR/AsyncDialect.td" + include "mlir/Dialect/Async/IR/AsyncOps.td" + include "mlir/Dialect/Async/IR/AsyncTypes.td""# } melior_macro::dialect! { name: "amx", @@ -41,7 +52,13 @@ melior_macro::dialect! { } melior_macro::dialect! { name: "bufferization", - table_gen: r#"include "mlir/Dialect/Bufferization/IR/BufferizationOps.td""# + table_gen: r#"include "mlir/Dialect/Bufferization/IR/BufferizationOps.td" + include "mlir/Dialect/Bufferization/IR/AllocationOpInterface.td" + include "mlir/Dialect/Bufferization/IR/BufferizationEnums.td" + include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.td" + include "mlir/Dialect/Bufferization/TransformOps/BufferizationTransformOps.td" + include "mlir/Dialect/Bufferization/Transforms/Passes.td" + "# } melior_macro::dialect! { name: "complex", @@ -53,11 +70,15 @@ melior_macro::dialect! { } melior_macro::dialect! { name: "dlti", - table_gen: r#"include "mlir/Dialect/DLTI/DLTI.td""# + table_gen: r#"include "mlir/Dialect/DLTI/DLTI.td" + include "mlir/Dialect/DLTI/DLTIAttrs.td" + include "mlir/Dialect/DLTI/DLTIBase.td""# } melior_macro::dialect! { name: "func", - table_gen: r#"include "mlir/Dialect/Func/IR/FuncOps.td""# + table_gen: r#"include "mlir/Dialect/Func/IR/FuncOps.td" + include "mlir/Dialect/Func/TransformOps/FuncTransformOps.td" + include "mlir/Dialect/Func/Transforms/Passes.td""# } melior_macro::dialect! { name: "index", @@ -65,12 +86,19 @@ melior_macro::dialect! { } melior_macro::dialect! { name: "irdl", - table_gen: r#"include "mlir/Dialect/IRDL/IR/IRDLOps.td""# + table_gen: r#"include "mlir/Dialect/IRDL/IR/IRDL.td" include "mlir/Dialect/IRDL/IR/IRDLOps.td""# } melior_macro::dialect! { name: "llvm", // spell-checker: disable-next-line - table_gen: r#"include "mlir/Dialect/LLVMIR/LLVMOps.td" include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td""# + table_gen: r#"include "mlir/Dialect/LLVMIR/LLVMOps.td" + include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td" + include "mlir/Dialect/LLVMIR/LLVMDialect.td" + include "mlir/Dialect/LLVMIR/LLVMInterfaces.td" + include "mlir/Dialect/LLVMIR/LLVMTypes.td" + include "mlir/Dialect/LLVMIR/LLVMOpBase.td" + include "mlir/Dialect/LLVMIR/LLVMAttrDefs.td" + include "mlir/Dialect/LLVMIR/BasicPtxBuilderInterface.td""# } melior_macro::dialect! { name: "memref", From f796a31aa633d4b028a2fa0c5eafc375356887dc Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Tue, 10 Dec 2024 12:16:42 -0300 Subject: [PATCH 4/4] spell --- cspell.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cspell.json b/cspell.json index 3caaaf4be4..85dadc0710 100644 --- a/cspell.json +++ b/cspell.json @@ -66,6 +66,9 @@ "trunci", "unranked", "vulkan", - "xori" + "xori", + "LLVMIR", + "somepathto", + "Bufferizable" ] }