Skip to content

Commit

Permalink
Fix opaque pointers in merge and remove wrappers.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed May 7, 2024
1 parent 848181b commit 907fd28
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 55 deletions.
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.

0 comments on commit 907fd28

Please sign in to comment.