lambdaclass / concrete

Concrete is a simple programming language specifically crafted for creating highly scalable systems that are reliable, efficient, and easy to maintain.
Apache License 2.0
123 stars 11 forks source link

Basic mlir codegen #67

Closed edg-l closed 8 months ago

edg-l commented 8 months ago
mod Simple {
    fn main() -> i32 {
        let x: i32 = 2;
        let y: i32 = 4;
        return add_plus_two(x, y);
    }

    fn add_plus_two(x: i32, y: i32) -> i32 {
        let mut z: i32 = 1;
        z = z + 1;
        return x + y + z;
    }
}

Compiles to mlir

}
2024-01-09T17:06:16.830026Z DEBUG concrete_codegen_mlir::context: MLIR Code before passes:

module {
  func.func @main() -> i32 {
    %c2_i32 = arith.constant 2 : i32
    %c4_i32 = arith.constant 4 : i32
    %0 = call @add_plus_two(%c2_i32, %c4_i32) : (i32, i32) -> i32
    return %0 : i32
  }
  func.func @add_plus_two(%arg0: i32, %arg1: i32) -> i32 {
    %c1_i32 = arith.constant 1 : i32
    %c1_i32_0 = arith.constant 1 : i32
    %0 = arith.addi %c1_i32, %c1_i32_0 : i32
    %1 = arith.addi %arg0, %arg1 : i32
    %2 = arith.addi %1, %0 : i32
    return %2 : i32
  }
}

2024-01-09T17:06:16.835336Z DEBUG concrete_codegen_mlir::context: MLIR Code after passes:

module attributes {llvm.data_layout = ""} {
  llvm.func @main() -> i32 {
    %0 = llvm.mlir.constant(2 : i32) : i32
    %1 = llvm.mlir.constant(4 : i32) : i32
    %2 = llvm.call @add_plus_two(%0, %1) : (i32, i32) -> i32
    llvm.return %2 : i32
  }
  llvm.func @add_plus_two(%arg0: i32, %arg1: i32) -> i32 {
    %0 = llvm.mlir.constant(2 : i32) : i32
    %1 = llvm.add %arg0, %arg1  : i32
    %2 = llvm.add %1, %0  : i32
    llvm.return %2 : i32
  }
}

Checking the return code with bash we can see it returns the result:

concrete on  basic_codegen [!] via 🦀 v1.75.0 
❯ ./build_artifacts/simple

concrete on  basic_codegen [!] via 🦀 v1.75.0 
❯ echo $?
8
codecov-commenter commented 8 months ago

Codecov Report

Attention: 381 lines in your changes are missing coverage. Please review.

:exclamation: No coverage uploaded for pull request base (main@c9507f5). Click here to learn what that means. Report is 1 commits behind head on main.

Files Patch % Lines
crates/concrete_codegen_mlir/src/codegen.rs 0.00% 361 Missing :warning:
crates/concrete_codegen_mlir/src/context.rs 0.00% 10 Missing :warning:
crates/concrete_codegen_mlir/src/lib.rs 0.00% 8 Missing :warning:
crates/concrete_ast/src/common.rs 33.33% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #67 +/- ## ======================================= Coverage ? 17.26% ======================================= Files ? 24 Lines ? 834 Branches ? 0 ======================================= Hits ? 144 Misses ? 690 Partials ? 0 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.