Skip to content

Commit

Permalink
[doc] update some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu committed Nov 19, 2024
1 parent f97a797 commit 85a2a30
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
> "There is one who could unite them, one who could reclaim the throne of Gondor." (Gandalf)

<img src="https://github.com/Lancern/mlir-gccjit/raw/main/logo.png" width="232px" height="273px" align="right" />



# mlir-gccjit

MLIR dialect for [`libgccjit`](https://gcc.gnu.org/onlinedocs/jit/).
Expand Down Expand Up @@ -62,4 +67,4 @@ cmake --build .

## License

This project is licensed under [Apache License 2.0](./LICENSE).
Please refer to [COPYING](COPYING) for more information.
43 changes: 43 additions & 0 deletions include/mlir-gccjit/IR/GCCJITOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,58 @@ def ExprOp : GCCJIT_Op<"expr"> {
let summary = "Expression";
let description = [{
The "expr" operation represents an expression.

```mlir
%res = gccjit.expr {
%0 = gccjit.const #gccjit.int<32> : !gccjit.int<32>
%1 = gccjit.const #gccjit.int<32> : !gccjit.int<32>
%2 = gccjit.binary plus %0, %1 : !gccjit.int<32>, !gccjit.int<32>
gccjit.return %2 : !gccjit.int<32>
} : !gccjit.int<32>
```

The expr operation can be marked with a lazy attribute. If such an attribute
exists, the expr will not be materialized until it is used.

The above, for example, will be translated into the following gimple:

```c
%res = 32 + 32
```

Without the expr block, the above would be translated into:
```c
%0 = 32
%1 = 32
%2 = %0 + %1
%3 = %2
```

The lazy evaluation attribute is used to compose expression block with other operations
that may have side effects.
For example,

```mlir
%x = gccjit.expr lazy {
%0 = gccjit.const #gccjit.int<32> : !gccjit.int<32>
%1 = gccjit.as_rvalue %arg0 : !gccjit.lvalue<!i32> -> !gccjit.int<32>
%2 = gccjit.compare lt (%0 : !gccjit.int<32>, %1 : !gccjit.int<32>) : !gccjit.bool
gccjit.return %2 : !gccjit.bool
} : !gccjit.int<32>
gccjit.conditional %x, ^true, ^false
```

will be translated into:

```c
if ((int)32 < %arg0) goto ^true; else goto ^false;
```

Without the lazy attribute, the above would be translated into:

```c
%x = (int)32 < %arg0
if (%x) goto ^true; else goto ^false;
```
}];
let arguments = (ins UnitAttr:$lazy);
Expand Down

0 comments on commit 85a2a30

Please sign in to comment.