Commit Graph

35 Commits

Author SHA1 Message Date
Lauri Vasama 039f533a9f Add ternary inversion rewrite pattern
```
// before
!x ? y ? z

// after
x ? z ? y
```
2026-05-25 09:00:41 +02:00
Lauri Vasama 5a5703ec10 Add expression rewrite descriptions 2026-05-25 09:00:41 +02:00
Lauri Vasama e30a09644e Introduce hoist-variable-initializers pass 2026-05-25 09:00:41 +02:00
Roberto Bertolini 5dcd6334b3 Add Clift local variable scope tightening 2026-05-13 15:32:34 +02:00
Pietro Fezzardi abc3f45298 Drop duplicated BitCastOfBitCastPattern
This is now subsumed into CastCollapsingPattern.
2026-05-11 09:32:20 +02:00
Pietro Fezzardi a28e6b8b87 CliftTransforms: add BitCastOfBitCastPattern
Add a Clift expression-rewrite pattern that collapses
`(T2)(T1)x` into `(T2)x` when both casts are BitCastOps. A
matching mlir-lit test is added.
2026-05-08 11:37:10 +02:00
Lauri Vasama c7e3a12657 Add implicit cast elision pass 2026-05-04 10:49:07 +03:00
Lauri Vasama 04fe27b8e9 Migrate Clift users to CDataModel 2026-05-04 10:49:03 +03:00
Lauri Vasama 7f2bf61d10 Move cast collapsing rewrite to a separate set 2026-04-30 15:09:16 +03:00
Lauri Vasama 5a538c0f84 Add (*x).m -> x->m expression rewrite 2026-04-30 15:09:16 +03:00
Lauri Vasama e5fb446430 Rename BooleanNegations.h to Expressions.h 2026-04-30 15:09:16 +03:00
Lauri Vasama 31c80b0625 Fix (&x)->m -> x.m expression rewrite 2026-04-30 15:09:16 +03:00
Lauri Vasama a338194eb7 Move namespace mlir::clift out of namespace mlir 2026-04-27 12:48:24 +03:00
Ivan Krysak 3de5b009e7 Clift: introduce simple passes for header tests 2026-04-22 08:19:29 +00:00
Ivan Krysak c5130ce689 Clift: factor common ptml pass options out 2026-04-22 08:19:28 +00:00
Andrea Gussoni 4e3af009fe Expressions: fold x[0] into *x
Implement a DDR rewriting for folding the `x[0]` into `*x`, in order
to avoid a useless verbose syntax. Due to concatenation of rewrites, we
will get `&(x[0])` transformed into `x`, which is the rewriting we are
aiming to.
2026-04-14 09:52:07 +02:00
Lauri Vasama 80731d1a10 Migrate users to new Clift type casts 2026-04-08 12:27:32 +03:00
Lauri Vasama f9a4cb6384 Split up clift::dealias
* `unwrapTypedefs` matches `dealias(T, /*IgnoreQualifiers=*/true)`.
* `collapseTypedefs` matches `dealias(T)`.
2026-04-08 12:18:42 +03:00
Lauri Vasama be8351a17d Split up Clift PrimitiveType
* PrimitiveType is now an interface.
* VoidKind is now VoidType.
* FloatKind is now FloatType.
* The integer kinds are now IntegerType with IntegerKind.
2026-04-08 12:18:10 +03:00
Lauri Vasama a2be1b476a Split up Clift CastOp
* DecayOp - array or function to pointer decay. Not shown in C.
* BitCastOp - bit-preserving conversion. Emitted as bit_cast if
  necessary.
* ExtendOp - zero- or sign-extending conversion from any integer type to
  any wider integer type.
* TruncateOp - truncating conversion from any integer type to any
  narrower integer type.
* PtrResizeOp - resizes a pointer without changing its pointee type.
2026-04-08 12:11:54 +03:00
Lauri Vasama 007ae24bb0 Simplify Clift expression pattern definitions 2026-04-08 11:12:41 +03:00
Lauri Vasama 3b731330b9 Fix getPointeeType expression rewrite helper 2026-04-08 11:12:41 +03:00
Andrea Gussoni 02cc6923d0 EmitFieldAccesses: implement pass
The `EmitFieldAccesses` pass transforms `clift` by taking pointer-typed
expressions computed via integerr arithmetic with type-safe field
accesses and array accesses.

The transformation is split in three main phases:
1) `PointerArithmetic` computation.
2) `BestTraversal` computation.
3) `FieldAccess` `clift` rewrite.

The high level driver is implemented in the `EmitFieldAccesses` header
and cpp, while the nested 3 phases are implemented respectively in
`PointerArithmetic`, `BestTraversal` and `FieldAccessReplacement`.

The `computerPointerArithmetic` phase is concerned with taking a
pointer-typed `ExpressionOp`, called `PointerToReplace`, and expressing
it in a `BasePointer+Offset` form.

The `computeBestTraversal` phase is concerned with computing the best
traversal of the type pointed to by `BasePointer`, that can be used to
rewrite the pointer arithmetic in `clift` with just field accesses and
array subscripts.

The `replaceFieldAccess` phase takes the `Traversal` computed at the
previous step, and actually rewrites in `clift` the `PointerToReplace`
in terms of field accesses and array accesses w.r.t. the `BasePointer`.
2026-03-18 17:25:13 +01:00
Lauri Vasama 21a51af54f Add immediate radix deduction pass 2025-12-05 19:53:41 +02:00
Lauri Vasama 33450e9306 Add terminal-branch-complement-hoisting pass 2025-12-05 19:53:41 +02:00
Lauri Vasama 73d7a77442 Add expression rewrite pass 2025-12-05 19:53:41 +02:00
Lauri Vasama 0f04483517 Add statement rewrite pass 2025-12-05 19:53:41 +02:00
Lauri Vasama 448276915e Add label-merging pass 2025-12-05 19:53:41 +02:00
Lauri Vasama f2911da190 Add trivial-return-elimination pass 2025-12-05 19:53:41 +02:00
Lauri Vasama 58216deafd Add RewriteHelpers.h
Contains helpers for statement rewriting.
2025-12-05 19:53:41 +02:00
Lauri Vasama c835baf65a Add PatternRewriter.h
Contains APIs from upstream LLVM that are not yet present in the current
version, as well as helpers not present in upstream.

See upstream commit 42c31d8302ff8f716601df9c276a5cd9ace6b158.
2025-12-05 19:53:41 +02:00
Lauri Vasama fbc1563b43 Add loop detection pass 2025-11-12 15:28:54 +02:00
Lauri Vasama 7980e57fb5 Add Clift C legalization pass 2025-10-21 09:15:40 +02:00
Lauri Vasama 26e6b9086c Simplify Clift pass declarations 2025-10-21 09:15:40 +02:00
Lauri Vasama 22d6f70ee2 Clift directory structure overhaul 2025-10-13 15:08:20 +02:00