108 Commits

Author SHA1 Message Date
Alessandro Di Federico 903617e79e IRHelpers: turn some functions into IRBuilder::* 2026-06-19 09:18:16 +02:00
Giacomo Vercesi 0ba82ce4f9 GCBI: explicitly store module reference
When calling `programCounterHandler`, instead of relying on the presence
of the `root` function, which might be absent, use a guaranteed
reference to the module.
2026-02-05 09:25:42 +01:00
Giacomo Vercesi 723ae8d801 GCBI: rework members and constructor
Move member declaration to the top of the class definition of
`GeneratedCodeBasicInfo` and initialize primitive members.
Merge the `run` method into the constructor since all uses have them
happening close to each other.
2026-02-05 09:25:42 +01:00
Alessandro Di Federico c18aa628e7 Minor changes 2025-12-19 14:38:19 +01:00
Alessandro Di Federico 1429b526ab Introduce libtcg
This commit drops libptc in favor of its new form libtcg.

It brings several improvements, among which:

* The QEMU version we work on has been upgraded.
* CPUStateAccessAnalysis has been reimplemented in a way that makes it
  easier to debug and solves some limitations (e.g., tracking leaking
  pointers).
* Identification of pieces of the CPU state that are read by each helper
  and fixing access to the CPU state is now performed at build-time.
* We no longer mmap the code we need to translate, dropping all the
  issues related to code that needed to be mapped where something is
  already present.
* We now have two distinct flavors of helper modules: the full one and
  the "slim" one. The latter contains the definition only of functions
  we intend to inline. It is used in most of the pipeline, a good thing
  since we spend less time optimizing code we don't really care about.
  The full module is only used on the re-compilation branch of the
  pipeline.
* We no longer split the `cpu_loop` function.
* We change MetaAddress to rely on architectures from `model::` as
  opposed to the LLVM ones.
* We no longer attach debug info to LLVM IR containing the original
  assembly.
* We now verify that the lifted code only contains code we expect.
2025-10-31 17:25:03 +01:00
Alessandro Di Federico fb80f4b8bd FunctionCallIdentification: handle delay slot 2025-10-24 18:21:07 +02:00
Alessandro Di Federico ed3fc26166 MaterializedValue: handle loading mutable data 2025-10-24 18:20:54 +02:00
Alessandro Di Federico f8bd4c3bac Move around some files in preparation for libtcg
* Make the following private headers public:
  * Lift/CPUStateAccessAnalysisPass.h
  * Lift/CSVOffsets.h
  * Lift/PTCDump.h
  * Lift/VariableManager.h
* Move from revngSupport to revngLift:
  * IRAnnotators.{h,cpp}
  * SelfReferencingDbgAnnotationWriter.{h,cpp}
* Move from revngSupport to revngModel:
  * FunctionTags.{h,cpp}
  * ProgramCounterHandler.{h,cpp}
* Move from revngSupport to revngRecompile:
  * OriginalAssemblyAnnotationWriter.{h,cpp}
2025-10-24 15:34:11 +02:00
Ivan Krysak 3561c2b907 Adopt IRBuilder wrapper 2025-10-21 19:17:01 +03:00
Ivan Krysak 7b02ab0e44 getJTReasons: Work on const instructions 2025-04-17 11:19:17 +03:00
Alessandro Di Federico 16e01f43d6 Import revng-c's FunctionTags.h 2024-10-31 17:19:51 +01:00
Alessandro Di Federico e44fe36539 Make GCBI::getJTReasons static 2024-06-20 10:24:49 +02:00
Kacper Kołodziej c0f226fa70 Add const qualifiers to some functions
getJumpTargetBlock takes llvm::BasicBlock * as argument, but doesn't
need to modify it, so const it adds const to it and other functions that
are used by getJumpTargetBlock: findJumpTarget, isTranslated, getType,
isJumpTarget.
2023-07-31 11:29:40 +02:00
Ivan Krysak 9f1d9fd5d0 Use Container::contains() where appropriate 2023-07-02 15:06:11 +00:00
Ivan Krysak bc98e0079f Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-02 13:20:49 +02:00
Alessandro Di Federico a65ccc3413 Introduce ValueMaterializer
`ValueMaterializer` is a rewrite of what was called `AdvancedValueInfo`
which follows the same principles.

The main benefits over the old version is:

* We materialize the data-flow graph and the CFG of the relevant part of
  root. This makes debugging significantly easier.
* We drop the old MonotoneFramework infrastructure in favor of
  getMaximalFixedPoint.
* We significantly reduce the amount of queries we make to
  AdvancedValueInfo.
2023-06-30 13:39:22 +02:00
Giacomo Vercesi 31cd2b53f9 rcc: add codespell
Add codespell to the list of checks performed by
revng-check-conventions. This should reduce the amount of typos present
in the revng codebase.
2023-05-11 10:05:32 +02:00
Alessandro Di Federico 40135aad97 Drop CSVAliasAnalysisPass 2023-04-13 18:11:48 +02:00
Alessandro Di Federico daafc6a1e7 AVI: handle SCEV's scSequentialUMinExpr 2023-04-08 08:42:24 +02:00
Alessandro Di Federico bcd374038c s/zextOrSelf/zext/g 2023-04-08 08:42:24 +02:00
Alessandro Di Federico e131817334 Drop usage of Type::getPointerElementType 2023-04-08 08:42:24 +02:00
Alessandro Di Federico dbcdad0a4d Switch from llvm::Optional to std::optional 2023-04-08 08:42:24 +02:00
Ivan Krysak 11c0d7f02e Stop using \brief doxygen command 2023-03-15 10:19:01 +01:00
Alessandro Di Federico f68b7866b3 Introduce BasicBlockID
This commit introduces `BasicBlockID` as the unique identifier for a
`efa::BasicBlock` into the CFG. A `BasicBlockID` is defined by a
`MetaAddress` plus an incremental integer. This enables us to have
multiple instances of the same block in a single function, which is
particularly useful when inlining multiple times the same function.

Apart from this, the commit also does the following:

* It drops representing `MetaAddress`es a `structs` in the IR. This created
  several issues related to ABI. We now represent them as strings.

* It defines more functions in `support.h`, instead of defining prototypes
  by hand in `CodeGenerator.cpp` and the like. Specifically, `unknownPC`
  and `raise_exception_helper`. We also introduce a C "constructor" for
  `PlainMetaAddress`.

* It significantly reduces the API of `GeneratedCodeBasicInfo`, which
  was supposed to be put on a diet since a long time.  Specifically,
  many jump target related methods have been moved to free functions in
  `IRHelpers.h`.  Also `GCBI::getSuccessors` has been pushed into its
  only user, `PruneRetSuccessors`, to prevent further usage of a
  deprecated API. In the future, it would be nice to drop it entirely.

* It introduces `efa::BasicBlock::InlinedFrom`.

* Introduce an enum to represent named argument indices for `newpc`.
  This enables us to more effectively manipulate its argument list.

* It improves the verification and error reporting for
  `efa::FunctionMetadata`.

* Update tests.

This commit is preliminary to another piece of work to improve the
generality of inlining beyond the simple "fake function" scenario, for
which the feature was originally conceived.
2023-02-23 14:51:10 +01:00
Massimo Fioravanti 742e1a0c56 TupleTree: switch from public fields to accessors 2022-12-12 18:36:57 +01:00
Massimo Fioravanti 0d3133cfc9 Fix missing includes
This ensures headers make sense on their own, without implicit
assumption about includers to also include other headers before them.
2022-12-09 18:09:39 +01:00
Massimo Fioravanti ad0f1163b2 AVI: increase performance by caching successors 2022-11-10 19:40:11 +01:00
Ivan Krysak 909042a13d AVI: rename ::Edge to avoids name collision 2022-09-26 10:33:43 +02:00
Alessandro Di Federico 6a6cd939db Rework EarlyFunctionAnalysis 2022-08-08 13:55:34 +02:00
Alessandro Di Federico 562bb9959d Reimplement GCBI::getBlocksGeneratedByPC
GCBI::getBlocksGeneratedByPC has been reimplemented using recursive
coroutines.  Caching dominator trees was very error-prone.
2022-08-08 13:55:26 +02:00
Alessandro Di Federico ff8ca0aaff AVI: relax allowed operations on symbol
It is now legal to `and` and `bswap` the address of a symbol.
2022-08-08 13:55:26 +02:00
Alessandro Di Federico 2088a65fa0 Implement SuccessorsList::operator== 2022-08-08 13:54:41 +02:00
Pietro Fezzardi b4c733ab57 Move Concepts.h into include/ADT for better reuse 2022-03-30 17:09:24 +02:00
Alessandro Di Federico ee0b8f44c1 Introduce BinaryImporter
This is a big step to split revng-lift in two parts: one that only
writes the model and one that actually lifts to LLVM IR.

* Introduce `revng import binary`
* Split off `BinaryFile.h`
* Drop `revng.h`
* `GeneratedCodeBasicInfo`: use model
* Reduce role of `GeneratedCodeBasicInfo` in favor of
  `model::Architecture` and `model::Register` methods
* `CodeGenerator`: adopt `RawBinaryView` and model
* `JumpTargetManager`: adopt `RawBinaryView` and model
* `ExternalJumpsHandler`: adopt model
* `InstructionTranslator`: discard `Architecture` in favor of
  `EndianessMismatch`
* Many other changes
2022-03-08 15:15:24 +01:00
Alessandro Di Federico 7c515ff997 Use std::string for MaterializedValue::SymbolName 2022-03-08 12:25:35 +01:00
Massimo Fioravanti 79d5ca1e27 Introduce FunctionTags::IsolatedRoot
This will be used by the revng-pipeline to tell apart a `root` calling
isolated functions from a regular one.
2022-01-05 14:45:01 +01:00
Alessandro Di Federico 3e1e69e08f Introduce eraseFromParent 2021-12-17 18:50:08 +01:00
Alessandro Di Federico a2364bc6a0 GeneratedCodeBasicInfo: parse root lazily
This commit makes sure that GeneratedCodeBasicInfo can be used even in
absence of the `root`.

This also ensure that no time is wasted on brief/focused pipelines that
do not care about analyzing each basic block in the `root` function.
2021-12-17 18:49:42 +01:00
Antonio Frighetto 215dab9dd2 Introduce CSVAliasAnalysisPass
A pass that decorates memory accesses with
information about CSV aliasing.
2021-12-15 18:03:30 +01:00
Antonio Frighetto e9439a15e5 Introduce RemoveHelperCallsPass
A simple pass that removes the calls to the helpers and replaces them
with stores of an opaque value onto the CSVs clobbered by the helper.
2021-12-15 18:03:30 +01:00
Antonio Frighetto ba49937a69 Introduce RemoveNewPCCallsPass
A simple pass that removes the calls to `newpc` marker.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 1d8a3281a8 GeneratedCodeBasicInfo: add purgeDomTree method
Erase element from the DominatorTree map when needed.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 5b4e4d8e84 GeneratedCodeBasicInfo: add invalidate method 2021-12-15 18:03:30 +01:00
Antonio Frighetto 34580789eb BinaryFile: add architecture-dependent fields
Add return address register and minimal final stack offset in Arch.
2021-12-15 18:03:30 +01:00
Alessandro Di Federico 6dd346ab04 Move GCBI.getMetaAddressMetadata to IRHelpers.h 2021-12-15 18:03:30 +01:00
Alessandro Di Federico eb2c3df925 Tag with MetaAddress functions and call sites 2021-10-21 15:02:00 +02:00
Pietro Fezzardi 71c79461d8 MaterializedValue: fix comparison between APInt
Comparing APInt requires them to have the same BitWidth.
2021-06-14 23:04:02 +02:00
Pietro Fezzardi 2448fec4a5 AVI: use new LVI API 2021-06-14 23:04:02 +02:00
Pietro Fezzardi 1e5cce6654 AVI: handle new SCEVType in switch 2021-06-14 23:04:02 +02:00
Alessandro Di Federico 10eb8e498a AVI: handle Undef
Also, be more verbose on an unexpected instruction.
2021-05-12 18:31:23 +02:00