Commit Graph

947 Commits

Author SHA1 Message Date
Giacomo Vercesi dbc734f23a CMake: force use of Python3
Switch from using `find_package(Python ...)` to `find_package(Python3
...)` as it excludes that CMake picks a Python 2 version by accident.
2026-05-14 11:26:41 +02:00
Roberto Bertolini 5dcd6334b3 Add Clift local variable scope tightening 2026-05-13 15:32:34 +02:00
Pietro Fezzardi 986ec7a3b8 STS: add unit tests with the store before the call
Add three more unit tests that mirror the previous "with_alloca"
variants but where the store of the extra argument %val into the
pre-existing alloca happens BEFORE the call instead of after it. The
expected number of NEW allocas after the pass is the same as in the
corresponding store-after-call variant: the position of the store
relative to the call does not change the picker's decision.
2026-05-08 17:16:57 +02:00
Pietro Fezzardi 325af4f696 STS: add unit tests with a pre-existing alloca
Add three more unit tests, one for each of the three call patterns
introduced in the previous commit. Each test takes an extra i64
argument %val, has an alloca pre-existing in the entry block, stores
%val into the alloca right after the call, and at least one branch
returns by loading from the alloca.

The pre-existing alloca/store/load pattern does not write to memory
the call could read (the alloca is local and the call's pointer
argument is unrelated) and the call cannot write to the alloca, so
the picker should reach the same conclusion as in the simpler
counterpart tests: the variant of @call_rw_one_use generates no new
alloca, @call_rw_two_uses generates one new alloca alongside the
pre-existing one, and @call_ro_two_uses generates none.
2026-05-08 17:14:10 +02:00
Pietro Fezzardi 133b29a474 STS: add unit tests for calls and serialization
Cover three representative cases for how the picker should treat
function calls in non-legacy mode:

- A call to a read+write function with a single use (an icmp that
  feeds a conditional branch). The call has only one use, so the
  picker does not pick it and no new alloca is created.
- The same shape, but with two uses of the call (the icmp and a
  return). Because the function may read+write memory and the call
  has more than one use, the picker picks the call: a new alloca is
  created at the top of entry, the result of the call is stored into
  it, and every user of the call uses a load from the alloca.
- The same shape as the second case but with a function that only
  reads memory (and is also nounwind willreturn so that
  Instruction::mayHaveSideEffects returns false). The picker does
  not pick the call and no new alloca is created.
2026-05-08 17:11:00 +02:00
Pietro Fezzardi e41e243d68 ArithmeticToGEP: see through Add subtrees
Make cannotBePointer recurse through an Add when both of its
operands cannot be pointers. This lets canDisambiguatePointerOperand
identify the only viable base pointer of an outer Add even when the
offset side is itself an Add (or a deeper tree of Adds) whose leaves
are all clearly-non-pointer values, e.g.

    %offset = add i64 (%a*%b), (%c*%d)
    %result = add i64 %arg, %offset

Two unit tests cover the simple two-mul case and a deeper
four-mul binary-tree variant.
2026-05-08 11:37:11 +02:00
Pietro Fezzardi 9dd0770290 ArithmeticToGEP: add deep ambiguous-add tests
Cover several scenarios where a single base pointer is reachable
only after the discovery walk in ArithmeticToGEPPass propagates
through many layers of Add instructions, each of which has
ambiguous pointer operands and must be disambiguated separately:

- A chain of 8 chained adds with a varied set of clearly-non-pointer
  offset opcodes (mul, ashr, shl, and, or, xor, sdiv, srem), with
  discovery seeded from the !revng.pointers metadata on the return.
- A chain seeded from a pointer argument (forward propagation).
- A chain feeding the integer argument of a call whose argument is
  a pointer (backwards discovery from the call site).
- A chain where the pointer side alternates between operand 0 and
  operand 1 of each add.
- A chain whose offset side is hidden behind freeze instructions,
  so the cannotBePointer recursion through transparent casts is
  exercised.
- A chain where every add reuses the same multiplication as offset,
  exercising independent disambiguation per-add over a shared
  sub-expression.
- A chain interrupted by ptrtoint/inttoptr round-trips between adds.
2026-05-08 11:37:11 +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
Pietro Fezzardi cb5702dc04 Add ArithmeticToGEP pass
Introduce the ArithmeticToGEP canonicalisation pass. It detects
pointers (LLVM-typed pointer values, model pointers flagged by the
"revng.pointers" metadata, and pointer-tagged extract values) and
rewrites integer arithmetic computed on top of them as i8 GEPs,
followed by a ptrtoint when the original use needs an integer.

For each obvious pointer the pass also walks backwards through Add
chains and disambiguates the pointer operand of each Add when the
other operand cannot be a pointer, so the rewrite extends to integer
arithmetic that only later flows into a pointer use.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 9111f127dd STS: add unit tests
Add an llvm-lit test suite for the new-PassManager
SwitchToStatements pass, exercised via
`revng opt -passes=switch-to-statements-test` (registered by the
pass's registerCallbacks hook). The tests cover load/store
serialisation, side-effecting calls and a few representative
patterns where an instruction must be picked for serialisation
because its memory read is no longer available at one of its uses.
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 0ab9f769dd Add CDataModel in ABI definition 2026-05-02 17:21:47 +03:00
Lauri Vasama 5a538c0f84 Add (*x).m -> x->m expression rewrite 2026-04-30 15:09:16 +03:00
Lauri Vasama 90e5dfd4c9 Pass MLIRContext by address
Passing by address is more conventional. This is what MLIR does most of
the time, and it avoids dereferences and addressofs everywhere.
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
Lauri Vasama a338194eb7 Move namespace mlir::clift out of namespace mlir 2026-04-27 12:48:24 +03:00
Alessandro Di Federico c1b3f23cf5 Uniform Binary::get{Definition,Binary}Reference 2026-04-24 17:54:09 +02:00
Alessandro Di Federico 0742699a81 s/OutputFilename/OutputPath/g 2026-04-23 13:40:42 +02: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
Ivan Krysak 6f1c8edd16 Avoid relative paths in LLVM lit tests 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
Ivan Krysak 141bddb241 CDoxygenEmitter: pull factories in as methods 2026-04-22 06:33:56 +00:00
Ivan Krysak 2f8557a418 Doxygen unit test: improve the error message 2026-04-22 06:33:56 +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
Giacomo Vercesi 18e3501731 pypeline: implement proper config parsing
Overhaul the pipeline configuration logic by collapsing all dynamic
configuration options, both for analyses and pipes into a single
dictionary. Change all the interfaces so that there is no longer
distinction between the configuration of an analysis and of pipes.
Expose these options to the command line via `--{name}-configuration`
options for each pipe/analysis that is applicable to the command-line
invocation.
2026-04-10 11:45:12 +02:00
Lauri Vasama 79a4fbc808 Fix DoxygenEmitter line prefix emission 2026-04-09 18:37:46 +03: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
Lauri Vasama 00e9ed8c5d Remove unnecessary Clift unit test 2026-04-08 11:12:41 +03:00
Giacomo Vercesi 2e6193e77f test_pypeline_daemon: fix flaky SIGSEGV
Avoid triggering a flaky SIGSEGV caused by running the asyncio event
loop in a thread. Switch to using `Process` which avoids the issue
altogether.
2026-03-31 17:00:49 +02:00