diff --git a/crates/concrete_codegen_mlir/build.rs b/crates/concrete_codegen_mlir/build.rs deleted file mode 100644 index e94c06f..0000000 --- a/crates/concrete_codegen_mlir/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::env::var; - -fn main() { - let mlir_path = var("MLIR_SYS_180_PREFIX").expect("MLIR path should be set."); - - cc::Build::new() - .cpp(true) - .flag("-std=c++17") - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-comment") - .include(&format!("{mlir_path}/include")) - .file("src/wrappers.cpp") - .compile("ffi"); - - println!("cargo:rerun-if-changed=src/wrappers.cpp"); -} diff --git a/crates/concrete_codegen_mlir/src/codegen.rs b/crates/concrete_codegen_mlir/src/codegen.rs index 3ee279a..1aa5e5d 100644 --- a/crates/concrete_codegen_mlir/src/codegen.rs +++ b/crates/concrete_codegen_mlir/src/codegen.rs @@ -1031,7 +1031,7 @@ fn compile_store_place<'c: 'b, 'b>( ptr, &[index], compile_type(ctx.module_ctx, &local_ty), - opaque_pointer(ctx.context()), + pointer(ctx.context(), 0), Location::unknown(ctx.context()), )) .result(0)? @@ -1049,7 +1049,7 @@ fn compile_store_place<'c: 'b, 'b>( ptr, DenseI32ArrayAttribute::new(ctx.context(), &[(*index).try_into().unwrap()]), compile_type(ctx.module_ctx, &local_ty), - opaque_pointer(ctx.context()), + pointer(ctx.context(), 0), Location::unknown(ctx.context()), )) .result(0)? @@ -1144,7 +1144,7 @@ fn compile_load_place<'c: 'b, 'b>( ptr, &[index], compile_type(ctx.module_ctx, &local_ty), - opaque_pointer(ctx.context()), + pointer(ctx.context(), 0), Location::unknown(ctx.context()), )) .result(0)? @@ -1161,7 +1161,7 @@ fn compile_load_place<'c: 'b, 'b>( ptr, DenseI32ArrayAttribute::new(ctx.context(), &[(*index).try_into().unwrap()]), compile_type(ctx.module_ctx, &local_ty), - opaque_pointer(ctx.context()), + pointer(ctx.context(), 0), Location::unknown(ctx.context()), )) .result(0)? diff --git a/crates/concrete_codegen_mlir/src/lib.rs b/crates/concrete_codegen_mlir/src/lib.rs index a8e30aa..70a05cc 100644 --- a/crates/concrete_codegen_mlir/src/lib.rs +++ b/crates/concrete_codegen_mlir/src/lib.rs @@ -19,7 +19,6 @@ use llvm_sys::{ LLVMPrintModuleToFile, }, error::LLVMGetErrorMessage, - prelude::{LLVMContextRef, LLVMModuleRef}, target::{ LLVM_InitializeAllAsmPrinters, LLVM_InitializeAllTargetInfos, LLVM_InitializeAllTargetMCs, LLVM_InitializeAllTargets, @@ -34,6 +33,7 @@ use llvm_sys::{ LLVMCreatePassBuilderOptions, LLVMDisposePassBuilderOptions, LLVMRunPasses, }, }; +use mlir_sys::mlirTranslateModuleToLLVMIR; use module::MLIRModule; mod codegen; @@ -68,15 +68,6 @@ pub fn compile(session: &Session, program: &ProgramBody) -> Result LLVMModuleRef; -} - pub fn get_target_triple(_session: &Session) -> String { // TODO: use session to get the specified target triple let target_triple = unsafe { @@ -160,7 +151,7 @@ pub fn compile_to_object( let op = module.melior_module.as_operation().to_raw(); - let llvm_module = mlirTranslateModuleToLLVMIR(op, llvm_context); + let llvm_module = mlirTranslateModuleToLLVMIR(op, llvm_context as *mut _) as *mut _; let mut null = null_mut(); let mut error_buffer = addr_of_mut!(null); @@ -219,7 +210,7 @@ pub fn compile_to_object( OptLevel::Aggressive => 3, }; let passes = CString::new(format!("default")).unwrap(); - let error = LLVMRunPasses(llvm_module, passes.as_ptr(), machine, opts); + let error = LLVMRunPasses(llvm_module as *mut _, passes.as_ptr(), machine, opts); if !error.is_null() { let msg = LLVMGetErrorMessage(error); let msg = CStr::from_ptr(msg); diff --git a/crates/concrete_codegen_mlir/src/wrappers.cpp b/crates/concrete_codegen_mlir/src/wrappers.cpp deleted file mode 100644 index 004136f..0000000 --- a/crates/concrete_codegen_mlir/src/wrappers.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" LLVMModuleRef mlirTranslateModuleToLLVMIR(MlirOperation module, - LLVMContextRef context) { - mlir::Operation *moduleOp = unwrap(module); - - llvm::LLVMContext *ctx = llvm::unwrap(context); - - std::unique_ptr llvmModule = mlir::translateModuleToLLVMIR( - moduleOp, *ctx); - - LLVMModuleRef moduleRef = llvm::wrap(llvmModule.release()); - - return moduleRef; -}