Commit Graph

158 Commits

Author SHA1 Message Date
Roberto Bertolini 5dcd6334b3 Add Clift local variable scope tightening 2026-05-13 15:32:34 +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 f6d2eaea4b Add Clift DataModelAttr 2026-05-04 10:48:03 +03:00
Lauri Vasama 5a538c0f84 Add (*x).m -> x->m expression rewrite 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 3f89cdcbd8 Disable MLIR output in Clift backend tests 2026-04-27 12:48:24 +03:00
Ivan Krysak 490504604c mlir-lit-tests: test forbidden attributes 2026-04-22 08:19:35 +00:00
Ivan Krysak f83465eadb mlir-lit-tests: test unknown attributes 2026-04-22 08:19:34 +00:00
Ivan Krysak e1c4ad760f mlir-lit-tests: test function type attributes 2026-04-22 08:19:34 +00:00
Ivan Krysak 41c4dcd6ee mlir-lit-tests: add missing _ABI attributes 2026-04-22 08:19:33 +00:00
Ivan Krysak 935208dc43 mlir-lit-tests: test struct attributes 2026-04-22 08:19:33 +00:00
Ivan Krysak 61c8a44870 mlir-lit-tests: test function attributes 2026-04-22 08:19:32 +00:00
Ivan Krysak 1b6c4c8f45 mlir-lit-tests: test raw function attributes 2026-04-22 08:19:32 +00:00
Ivan Krysak 0a23d51da8 model-verify tests: separate a handles subset 2026-04-22 08:19:31 +00:00
Lauri Vasama cd45c8a831 Avoid relative paths in MLIR lit tests 2026-04-22 08:19:31 +00:00
Ivan Krysak e693cdbd53 model-verify-clift -> verify-against-model 2026-04-22 08:19:30 +00:00
Ivan Krysak ce7e5a3917 CliftModelVerify: improve error message wording 2026-04-22 08:19:30 +00:00
Ivan Krysak 5cc5bf77ed mlir_lit_tests: add header-level comment tests 2026-04-22 08:19:29 +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
Andrea Gussoni 8359b4da26 EmitFieldAccesses: indirection propagation test 2026-04-14 09:50:48 +02:00
Andrea Gussoni f6b1772bbd EmitFieldAccesses: add const-qualified test 2026-04-14 09:50:48 +02:00
Lauri Vasama 8085a1e8e9 Improve integer literal emission 2026-04-08 12:31:45 +03:00
Lauri Vasama 4cadcafa2c Move operand constraints from C++ to tablegen 2026-04-08 12:30:31 +03:00
Lauri Vasama 0e7703e312 CBackend null pointer constant 2026-04-08 12:29:58 +03:00
Lauri Vasama d35e54627c Add Clift ValueType interface
Value types is the set of non-array object types. These types are
assignable, can be used as function parameters, and as return types
(along with void), and in other scenarios where the type must have usual
value-like behaviour with no weirdness (such as array decay).
2026-04-08 12:28:45 +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 90658bbbed Change default C target size of long
Currently there is only a single default target used for all C emission.
However, the emitted code is actually compiled using multiple
implementations (32-bit and 64-bit targets), some of which use a 32-bit
wide long. This causes integer literals to be emitted with wrong sizes
on those targets. This change forces all 64-bit literals to be emitted
using long long, which is 64 bits wide in all relevant implementations.
2026-04-08 11:12:41 +03:00
Andrea Gussoni 30a1396a64 EmitFieldAccesses: typedef pointer as array tests 2026-03-30 16:03:37 +02:00
Andrea Gussoni 4c27971ed8 EmitFieldAccesses: pointer as array tests 2026-03-30 16:03:37 +02:00
Ivan Krysak 979a384763 mlir_lit_tests: test unit attribute emission 2026-03-27 08:28:21 +00:00
Ivan Krysak 82e86cf167 Emit prototype attributes *before* the prototype 2026-03-27 08:27:52 +00:00
Ivan Krysak 69a6508ea7 mlir_lit_tests: introduce comment-specific tests 2026-03-27 08:21:58 +00:00
Ivan Krysak 8f747e7ff3 Name-import tests: be explicit about the ABI 2026-03-27 08:15:56 +00:00
Ivan Krysak 9524312ed4 C-Attributes: test typed arguments 2026-03-27 08:07:41 +00:00
Ivan Krysak 58257d5520 ImportModel: import _ABI 2026-03-27 08:04:10 +00:00
Ivan Krysak 105f15266b ImportModel: import _CAN_CONTAIN_CODE 2026-03-27 07:19:27 +00:00
Ivan Krysak f4e7d50361 Allow C-Attributes to accept integers and types 2026-03-27 07:18:49 +00:00
Ivan Krysak 73ddff7126 import-clift-types -> import-types 2026-03-26 16:28:48 +00:00
Ivan Krysak addfc543c8 import-model-names -> import-descriptive-info 2026-03-26 16:28:48 +00:00
Ivan Krysak 1310b6ab62 Clift: append C to attribute classes we emit 2026-03-25 15:42:13 +00:00
Andrea Gussoni d54b8a5767 EmitFieldAccesses: array access argument and shl
Add two unit tests having a `struct` -> `array` -> `struct` access,
where the offset is computed through a `shl` operation, applied to a
dynamic index obtained through the argument.
2026-03-23 17:34:50 +01:00
Andrea Gussoni 732c880cd8 EmitFieldAccesses: array access argument and mul
Add a unit test having a `struct` -> `array` -> `struct` access, where
the offset is computed through a `mul` operation, applied to a dynamic
index obtained through an argument.
2026-03-23 17:34:50 +01:00
Andrea Gussoni cd3a30d346 EmitFieldAccesses: nested array access
Add a unit test for nested `array`s access, and a unit test for nested
`array`s access with a `struct` indirection level in the middle.
2026-03-23 17:34:50 +01:00
Andrea Gussoni 5a4a281677 EmitFieldAccesses: array with dynamic index test
Add a `EmitFieldAccess` unit test where we perform am `array` access,
using a dynamic index contained in another field of the `struct`
containing the `array` itself.
2026-03-23 17:34:50 +01:00
Andrea Gussoni 9e2528faec EmitFieldAccesses: ptr_add LinearCombination test
Add a test exercising the `LinearCombination` propagation through
`composePtrAdd`.
2026-03-23 17:34:50 +01:00
Andrea Gussoni b70c9aed66 EmitFieldAccess: ptr_add.offset as BasePointer
Additional test in to struct-ptradd-access.mlir that exercises the case
where the base pointer information comes from the offset operand (RHS)
of ptr_add rather than the pointer operand (LHS).

This tests the relaxed assumptions introduced in the previous commit
where `composePtrAdd` no longer requires the `PointerOperand` to be an
`Address` `PA`.
2026-03-19 17:31:42 +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