3016 Commits

Author SHA1 Message Date
Alessandro Di Federico a1f9bd2d16 Minor changes 2025-12-22 11:34:46 +01:00
Alessandro Di Federico b80d68364c ProgramCounterHandler: make Alignment an uint64_t
`Alignment` was `unsigned`. However we were doing bit operations,
bitwise negation in particular, which was supposed to happen on
64-bits, to initialize a `ConstantInt` mask.
2025-12-19 14:44:09 +01:00
Alessandro Di Federico d9123fcd49 PECOFFImporter: fix handling of relocations
This commit ensures relocations imported from PE/COFF binaries have
generic `Address`. The fact that this was not the case lead to not
detecting dynamic calls.

The commit also improves logging and fixes the handling of maximum depth
visit of the PDB importer.
2025-12-19 14:44:07 +01:00
Alessandro Di Federico c18aa628e7 Minor changes 2025-12-19 14:38:19 +01:00
Giacomo Vercesi e8b55583e6 isolate: outline function splitting in function
Outline the code responsible for splitting an isolated function into its
own `llvm::Module` in a separate function.
2025-12-19 10:29:28 +01:00
Giacomo Vercesi 664eb497c1 isolate: selectively clone helpers
When performing `cloneFiltered`, instead of cloning all the helper
functions only clone those that are transitively called from the isolated
function.
2025-12-19 10:29:28 +01:00
Giacomo Vercesi 7f7f9571a8 pypeline: implement container discarding
Add infrastructure to pypeline that allows containers to be notified
when they are being used last, this allows two things:
* `Pipe`s eagerly clearing those containers once they are done reading
  their contents
* `ScheduledTask`s clearing those out at the end of their execution in
  case the pipe did not do it
This overall should improve memory usage as container no longer take up
memory if they are no longer used as part of a `Schedule`.
2025-12-19 10:29:28 +01:00
Giacomo Vercesi 3d2015a233 isolate: implement trivial memory optimizations
Implement trivial memory optimizations on the `isolate` pipe:
* Clone the `root` module right away to the correct context before
  performing isolation
* Delete the `root` function's body right after isolation
* Delete the isolated function body from the cloned module after it has
  been `cloneFiltered`-ed into the output container
2025-12-19 10:28:29 +01:00
Giacomo Vercesi 265af3768f Binary importers: fix debug info detection
Fix the behavior of binary importers by propagating the path of the
input binary from revng2 downwards, allowing finding `.debug` files in
the correct paths.
2025-12-19 10:28:29 +01:00
Giacomo Vercesi e8f293271b BinariesContainer: page files to disk
Store the contents of the files deserialized by `BinariesContainer` to
disk via `TemporaryFile`. This also allows some pipes to avoid shuffling
data around since they needed a file on disk anyways.
2025-12-19 10:28:29 +01:00
Alessandro Di Federico 6175c43b0c Lift: zero initialize temporaries
Sometimes QEMU will emit code that reads a local temporary *before* it
is assigned in the `TranslationBlock`. This usually happens when lifting
non-code, but it's still a problem since it leads to phis around the
dispatcher, which we don't want.

For example, consider the following x86-64 code:

```
0000000140002000 <.text>:
140002000: f0    lock
140002001: 38 00 cmpb    %al, (%rax)
```

It leads to:

```
[libtcg] Translation starting from 0x140002000:Generic64
[libtcg]   ---- 0000000040002000
[libtcg]     mov_i64 loc2,rax
[libtcg]     mov_i64 loc1,rax
[libtcg]     mov_i64 cc_src,loc1
[libtcg]     mov_i64 loc8,loc0
[libtcg]     sub_i64 cc_dst,loc0,loc1
[libtcg]     discard cc_src2
[libtcg]     discard cc_op
```

Note how `loc0` is read before being initialized.

Currently we zero-initialize all the temporaries. It would be in
princple possible to detect those that need the initialization, which
would also enable us to emit a warning.
2025-12-16 17:42:07 +01:00
Giacomo Vercesi 6e7efc835b InitRevng: fix memory leak due to stack trace
When initializing `revng::InitRevng` it is assumed by its parent,
`InitLLVM`, that the lifetime of `Argv` and be equivalent to
static, because it might be later retrieved to print it in case of a
crash. This works with the traditional `main`, however in the pipebox
the string passed are not guaranteed to have that lifetime. This commits
moves ownership of the strings to a class that stores them to avoid this
problem.
2025-12-12 15:46:49 +01:00
Giacomo Vercesi f7231a29da Add yield-cfg to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 255748228a Add yield-call-graph-slice to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 4385f28c17 Add YieldCallGraph to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 9a202822f1 Add ProcessCallGraph to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi a8ed75fdb1 Add CleanupIR to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi d80c0a73f6 Add MergeLLVMModules to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 05dc279ef2 Add emit-c-as-single-file to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi e260d05082 Add EmitC to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 9b527c8b69 Add ImportModelNames to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi cfe476c701 Add ModelVerifyClift to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 75455a339e Add PureMLIRPassesPipe to pypeline
In the same vein as `PureLLVMPassesPipe`, add a pipe to pypeline that
allows running arbitrarily-specified MLIR passes that do not depend on
the model.
2025-12-10 16:16:14 +01:00
Giacomo Vercesi 97fe9203e1 Add LLVMToClift to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 08154335e3 Add SwitchToStatements to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi ee1fdebc4e Add SegregateStackAccesses to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 3cd011c146 Introduce CliftFunctionMixin
In equivalence with `LLVMFunctionMixin`, add a mixin that allows
writing a pipe that instead of defining the `runOnFunction` method it
defines the `runOnCliftFunction` which receives both the
`module::Function` and the `FunctionOp`.
2025-12-10 16:16:14 +01:00
Giacomo Vercesi 16e89416c5 Add CliftFunctionContainer
Add a container that owns one `mlir::ModuleOp` per function, to be used
in conjunction with the new clift backend.
2025-12-10 16:16:14 +01:00
Giacomo Vercesi e35f5750de Add ConvertFunctionsToCABI analysis to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 9e8e4cdf85 Add AnalyzeDataLayout analysis to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 56ab47bfd2 Outline mergeBackImpl in IRHelpers
Move the body of `LLVMContainer::mergeBackImpl` in
`Support/IRHelpers.cpp` under the name `linkFunctionModules`.
2025-12-10 16:16:14 +01:00
Giacomo Vercesi 5a6efb0fa2 Add DetectStackSize analysis to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi c1217dcfc3 Add DetectABI analysis to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 405733369b Add ImportWellKnownModelsAnalysis to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 47038d46ec Add ParseBinaryAnalysis to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi e4e259df3c Add MakeSegmentRef to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 3e37058899 Add LegacySegregateStackAccesses to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 3a08f8713b Add SimplifySwitch to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi c0e8c8fa09 Add PromoteStackPointer to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 10cc709098 Add InjectStackSizeProbesAtCallSites to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 0bc74e0234 Add PromoteInitCSVToUndef to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi e13e5add06 Add RemoveLiftingArtifacts to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 19f67c8223 Introduce LLVMFunctionMixin
Add a mixin class for piperuns that work on an LLVM module and need
both the model function and the `llvm::Function`. Pipe that inherit this
mixin will receive both the model and LLVM function in the
`runOnLLVMFunction` method.
2025-12-10 15:05:53 +01:00
Giacomo Vercesi db94859401 Registrars: add Run suffix for piperuns
Change the `Register.*Pipe` functions to end in `Run` if the template
argument should be a pipe run. Also change the concepts `Is.*Pipe` to
also have the `Run` suffix if applicable.
2025-12-10 15:05:53 +01:00
Giacomo Vercesi 296eb9a76f Make SingleOutputPipe uniform to other piperuns
Make the interface required by `SingleOutputPipe` similar to other
piperuns by requiring a constructor, the use of `PipeRunArgument`s and
the implementation of a non-static `run` function.
2025-12-10 15:05:53 +01:00
Giacomo Vercesi 532a4a19f6 Drop LLVMFunctionPassPipe
Drop the `LLVMFunctionPassPipe` as it will not be used in the pipeline
by any pipe and its infrastructure is not needed.
2025-12-10 15:05:53 +01:00
Giacomo Vercesi 1da6e49b36 ObjectDependenciesTracker: also stop tracking
Call `revng::Tracking::stop` in the destructor of
`ObjectDependenciesTracker` to avoid tracking happening after the object
is destroyed.
2025-12-10 15:05:53 +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