Commit Graph

61 Commits

Author SHA1 Message Date
Giacomo Vercesi d578bc6cd2 isolate: clone root module conservatively
In the new pipeline the root module is split off in its individual
isolated modules at the end of `isolate`. Before splitting, there are a
lot of global variables in the root module and only a small part is
going to be needed after splitting for each module. To avoid excessive
memory usage employ `ConservativeModuleCloner` in `Isolate` so that
only the needed global variables are actually cloned when splitting off.
2026-02-05 10:20:45 +01:00
Alessandro Di Federico d79c66cb1b Introduce getOrCreateGlobal 2025-12-22 11:34:47 +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
Alessandro Di Federico 5820908675 Remove and ban \file 2025-12-16 17:41:55 +01:00
Giacomo Vercesi 6d58434868 linkFunctionModule: improve linking of globals
When linking globals that are later going to be uniqued by their id,
change their name to a temporary unique value and then restore it
post-linking, this avoids situations where function declarations shared
a common name but not metadata and were merged together by the linker.
2025-12-10 16:16:14 +01:00
Giacomo Vercesi cff658dd1c makeGlobalObjectsArray: use opaque pointers
Switch from using an array of integers with `ptrtoint` to using an array
of opaque pointers to store globals in an array to prevent their
deletion. This avoids spurious `ptrtoint`s when looking at uses of
globals.
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 b4f9147646 Introduce LLVMFunctionsContainer
Add another container for LLVM modules. This one stores one
`llvm::Module` per function (all modules share the same
`llvm::LLVMContext` for performance reasons).
2025-11-18 17:47:54 +01:00
Giacomo Vercesi a39906ca85 Factor out cloneFiltered from LLVMContainer
Move the body of `cloneFiltered` from `LLVMContainer` into a free
function in `IRHelpers.h`.
2025-11-17 10:04:13 +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 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 e56f543b1a Split module.bc.zstd 2025-10-13 10:26:41 +03:00
Ivan Krysak 79d2719347 dumpModule: set IsForDebug to true
This is purely for consistency sake. All the other module dumping
wrappers set this argument, except for this one.
2025-09-10 17:44:00 +02:00
Ivan Krysak 98a3b00535 Minor Improvements 2025-09-10 17:44:00 +02:00
Ivan Krysak 1bce76f511 Bring name mangling out into a support helper 2025-04-24 13:22:14 +02:00
Ivan Krysak aa15d8ca21 Standardize abort-like function usage 2025-04-17 11:19:17 +03:00
Ivan Krysak a3c8ced826 getUniqueString: use hash for empty strings 2025-04-17 11:19:17 +03:00
Alessandro Di Federico c5c657d11b Lift: increase determinism 2025-04-15 15:31:10 +02:00
Ivan Krysak 705e4a5955 auto [...] -> auto &&[...] 2025-02-13 13:10:51 +02:00
Alessandro Di Federico 2128a80cc8 Preserve metadata after Function::deleteBody
Also, introduce and adopt a simple helper class to get this right.
2025-01-28 12:19:16 +01:00
Alessandro Di Federico 16e01f43d6 Import revng-c's FunctionTags.h 2024-10-31 17:19:51 +01:00
Alessandro Di Federico d72f6413f0 Import revng-c's Support/IRHelpers.h 2024-10-31 17:19:51 +01:00
Alessandro Di Federico c1cbb4e9a0 Initialize pointers to nullptr 2024-09-27 12:07:17 +02:00
Alessandro Di Federico baa1bd612e Introduce recreateWithoutBody
Similar to moveToNewFunctionType, but doesn't move the BasicBlocks.
2024-09-27 12:07:16 +02:00
Alessandro Di Federico bce1d6c0f3 Adopt invalidation along the core pipeline 2024-06-20 10:24:50 +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 7d235f4fd0 Enforce licence header consistency
Also do some basic cleanup: capitalize first letters, add `.`
at the end of the sentences, and so on.
2023-07-03 15:23:10 +00:00
Ivan Krysak 9f1d9fd5d0 Use Container::contains() where appropriate 2023-07-02 15:06:11 +00:00
Alessandro Di Federico 942cc1323a revng::verify: dump module upon failure 2023-06-23 17:54:55 +02:00
Alessandro Di Federico 4b2e067574 rcc: ban functions we wrap 2023-04-28 14:34:52 +02:00
Alessandro Di Federico 628aa42cc2 Introduce collectTypes 2023-04-28 14:04:31 +02:00
Alessandro Di Federico 170749b0aa Introduce revng::verify 2023-04-28 14:04:31 +02:00
Alessandro Di Federico 8fd34ff0f7 pruneDICompileUnits: delegate to DIFinder 2023-04-14 08:36:05 +02:00
Alessandro Di Federico 92b9ba5571 Import findPhiTreeLeaves 2023-04-08 08:42:24 +02:00
Alessandro Di Federico a0c0cd9468 extractFromConstantStringPtr: no stripPointerCasts 2023-04-08 08:42:24 +02:00
Alessandro Di Federico 26765f3d84 Drop usages of getBasicBlockList 2023-04-08 08:42:24 +02:00
Kacper Kołodziej bbebdd44b4 Prefer String.empty() case first 2023-04-04 09:30:09 +02:00
Kacper Kołodziej 17b0ecd78a Compare to nullptr instead of implicit cast
Prefer explicit comparing to nullptr instead of implicit casting pointer
to bool.
2023-04-04 09:30:09 +02:00
Pietro Fezzardi 8801fc3b33 Support empty strings in getUniqueString
This commit works around a quirk of
`llvm::ConstantDataArray::getString`, which returns a
`llvm::ConstantAggregateZero` for empty strings.

This quirk caused assertions in the previous implementation when passing
an empty `String` to `getUniqueString`.
2023-04-04 09:30:09 +02:00
Pietro Fezzardi 91af14007f Assert non-empty namespace in getUniqueString
Using an empty namespace causes the creation of a named metadata with an
empty string as name.
`llvm::verifyModule` does not check for that, so the `Module` still
verifies, but the on-disk serialization generated by `AsmPrinter.cpp`
prints `"empty name"` instead of the metadata name, and if the
serialized `Module` is then reparsed it parses succesfully but it does
not verify anymore.
2023-04-04 09:30:09 +02:00
Alessandro Di Federico 09541be398 getUniqueString: do not rely on named metadata
`getUniqueString` returns a dedup'd char array `GlobalVariable` given a
string. We used to rely on named metadata to dedup them. However, this
lead to issues with `LLVMContainer` cloning and linking.

The new implementation uses the name of the variable as the
de-decuplication key, circumventing the problem entirely and improving
performance.
2023-03-13 22:53:44 +01:00
Alessandro Di Federico 6f47231695 LLVMContainer: pruneDICompileUnits pre linking 2023-03-13 22:53:44 +01:00
Alessandro Di Federico 927f5b38be PromoteCSVs/EnforceABI: handle declarations
PromoteCSVs and EnforceABI were not handling declarated functions
properly, leading to issues downstream.
2023-03-13 22:53:44 +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
Alessandro Di Federico 4d69437548 Split moveBlocksInto off moveToNewFunctionType 2022-08-08 13:55:25 +02:00
Alessandro Di Federico 9fcdc3393a getLastNewPC: return nullptr when ambiguous 2022-05-06 16:04:22 +02:00
Alessandro Di Federico 0f3c29fa1b Split moveToNewFunctionType off changeFunctionType 2022-04-29 17:57:49 +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 88dbc39f29 Reorganize LLVM IR debug annotations emission 2021-12-22 17:47:54 +01:00