Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Feb 12, 2024
1 parent b5315fb commit ef0b72d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
45 changes: 44 additions & 1 deletion crates/concrete_codegen_mlir/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, error::Error};

use bumpalo::Bump;
use concrete_check::ast_helper::{AstHelper, ModuleInfo};
use concrete_ir::{DefId, FnBody, LocalKind, ModuleBody, ProgramBody, Ty, TyKind};
use concrete_ir::{DefId, FnBody, LocalKind, ModuleBody, ProgramBody, Statement, Ty, TyKind};
use concrete_session::Session;
use melior::{
dialect::{
Expand Down Expand Up @@ -121,6 +121,7 @@ pub fn compile_function(ctx: FunctionCodegenCtx) -> Result<(), Box<dyn std::erro
let entry_block = region.append_block(Block::new(&params_ty));

let mut locals = HashMap::new();
let mut ret_local = None;

let mut arg_counter = 0;

Expand Down Expand Up @@ -168,6 +169,7 @@ pub fn compile_function(ctx: FunctionCodegenCtx) -> Result<(), Box<dyn std::erro
LocalKind::ReturnPointer => {
if let TyKind::Unit = local.ty.kind {
} else {
ret_local = Some(index);
let ptr: Value = entry_block
.append_operation(memref::alloca(
ctx.context(),
Expand All @@ -185,6 +187,47 @@ pub fn compile_function(ctx: FunctionCodegenCtx) -> Result<(), Box<dyn std::erro
}
}

let mut blocks = Vec::with_capacity(body.basic_blocks.len());

for _ in body.basic_blocks.iter() {
let mlir_block = region.append_block(Block::new(&[]));
blocks.push(mlir_block);
}

entry_block.append_operation(cf::br(&blocks[0], &[], Location::unknown(ctx.context())));

for (block, mlir_block) in body.basic_blocks.iter().zip(blocks.iter()) {
for statement in &block.statements {
match &statement.kind {
concrete_ir::StatementKind::Assign(_, _) => todo!(),
concrete_ir::StatementKind::StorageLive(_) => todo!(),
concrete_ir::StatementKind::StorageDead(_) => todo!(),
}
}

match &block.terminator.kind {
concrete_ir::TerminatorKind::Goto { target } => {
mlir_block.append_operation(cf::br(
&blocks[*target],
&[],
Location::unknown(ctx.context()),
));
}
concrete_ir::TerminatorKind::Return => {}
concrete_ir::TerminatorKind::Unreachable => todo!(),
concrete_ir::TerminatorKind::Call {
func,
args,
destination,
target,
} => todo!(),
concrete_ir::TerminatorKind::SwitchInt {
discriminator,
targets,
} => todo!(),
}
}

Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions crates/concrete_ir/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ fn lower_if_statement(builder: &mut FnBodyBuilder, info: &IfExpr) {
});

let targets = SwitchTargets {
values: vec![ValueTree::Leaf(ConstValue::Bool(true))],
targets: vec![first_then_block_idx, first_else_block_idx],
values: vec![ValueTree::Leaf(ConstValue::Bool(false))],
targets: vec![first_else_block_idx, first_then_block_idx],
};

let kind = TerminatorKind::SwitchInt {
Expand Down

0 comments on commit ef0b72d

Please sign in to comment.