Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opaque pointers in merge and remove wrappers.cpp #126

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions crates/concrete_codegen_mlir/build.rs

This file was deleted.

8 changes: 4 additions & 4 deletions crates/concrete_codegen_mlir/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand All @@ -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)?
Expand Down Expand Up @@ -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)?
Expand All @@ -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)?
Expand Down
15 changes: 3 additions & 12 deletions crates/concrete_codegen_mlir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use llvm_sys::{
LLVMPrintModuleToFile,
},
error::LLVMGetErrorMessage,
prelude::{LLVMContextRef, LLVMModuleRef},
target::{
LLVM_InitializeAllAsmPrinters, LLVM_InitializeAllTargetInfos, LLVM_InitializeAllTargetMCs,
LLVM_InitializeAllTargets,
Expand All @@ -34,6 +33,7 @@ use llvm_sys::{
LLVMCreatePassBuilderOptions, LLVMDisposePassBuilderOptions, LLVMRunPasses,
},
};
use mlir_sys::mlirTranslateModuleToLLVMIR;
use module::MLIRModule;

mod codegen;
Expand Down Expand Up @@ -68,15 +68,6 @@ pub fn compile(session: &Session, program: &ProgramBody) -> Result<PathBuf, Code
Ok(object_path)
}

extern "C" {
/// Translate operation that satisfies LLVM dialect module requirements into an LLVM IR module living in the given context.
/// This translates operations from any dilalect that has a registered implementation of LLVMTranslationDialectInterface.
fn mlirTranslateModuleToLLVMIR(
module_operation_ptr: mlir_sys::MlirOperation,
llvm_context: LLVMContextRef,
) -> LLVMModuleRef;
}

pub fn get_target_triple(_session: &Session) -> String {
// TODO: use session to get the specified target triple
let target_triple = unsafe {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -219,7 +210,7 @@ pub fn compile_to_object(
OptLevel::Aggressive => 3,
};
let passes = CString::new(format!("default<O{opt}>")).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);
Expand Down
23 changes: 0 additions & 23 deletions crates/concrete_codegen_mlir/src/wrappers.cpp

This file was deleted.

Loading