Commit Graph

8 Commits

Author SHA1 Message Date
Lauri Vasama a338194eb7 Move namespace mlir::clift out of namespace mlir 2026-04-27 12:48:24 +03:00
Lauri Vasama 29c935ac90 Replace Clift type category helpers with casts 2026-04-08 12:25:04 +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 89fd0ee909 Use getObjectSize in EmitFieldAccesses 2026-04-08 11:13:44 +03:00
Andrea Gussoni 82945de055 EmitFieldAccesses: support pointer as array
Introduce the support to decouple the `BaseType` from `BasePointer`
pointee type.

This enable us to wrap pointee typees into an implicit array. This
enables pointer arithmetic rewriting of `*(p + i)` as `p[i]`.
2026-03-30 16:03:37 +02:00
Andrea Gussoni 5d023b32a4 EmitFieldAccesses: no assumption on composePtrAdd
We now don't assume that the `PointerOperand` of a `ptr_add` leads to a
`Address` PA, nor that the `OffsetOperand` leads to a `Numeric` PA.

We now behave as a simple `composeAdd`, keeping the special `Offset`
scaling by the `PointeeSize` of the `PointerOperand`.
2026-03-19 17:31:42 +01:00
Andrea Gussoni 6eaa1c39ad EmitFieldAccesses: no leaf on intermediate bitcast
Remove the special casing for `composeBitcast`, where we created a
`leaf` PA in case the traversal of the upward tree did only provide a
`Numeric` PA.

This was introduced as a workaround for handling `composePtrAdd` when
the `PointerOperand` was a `Numeric` PA.
2026-03-19 16:49:37 +01: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