374 Commits

Author SHA1 Message Date
Alessandro Di Federico 64fa538051 Introduce DropRedundantPtrIntCasts 2026-06-19 09:18:15 +02:00
Andrea Gussoni 8443f06170 DetectUninlinableHelpers: introduce pass
Introduce a pass which statically demotes some helpers from candidates
for inlining:
1) Helpers which are part of SCC on the callgraph.
2) Helpers which contains an `insertvalue`.
3) Helpers which _fail_ the `CriticalArguments` criterion.

A critical argument is defined starting from the critical operand
definition.
A critical operand is either the condition of a `switch` instruction or
the indices of a `getelementptr` instruction.
If the dataflow computing the the operand trace back to a formal
parameter of the function, that parameter will be considered critical
when attempting the inlining of the helper.

In case each condition is satisfied, the `revng.inline.policy` metadata
is attached to the function, so that it can be used at _inline_ time to
take the decision based on the critical arguments constantness.

The metadata is encoded as an `iN` integer with N = `arg_size() + 1`:
the extra most-significant bit is always zero so LLVM's signed-decimal
`iN` printer renders the value positively (avoiding e.g. `!{i2 -2}`).

The (de)serialisation primitives live in `revng/Support/IRHelpers.h`
as `serializeInliningPolicy` / `deserializeInliningPolicy` so the
runtime `revngFunctionIsolation` doesn't need to link the build-time
`revngHelperInliningAnalyses` to read the metadata back.
2026-05-29 17:12:35 +02:00
Alessandro Di Federico 8a28920773 Move *LDDTree* to Model/Importer/Binary 2026-05-15 11:27:33 +02:00
Lauri Vasama ad0c466d6d Remove revng/Support/CTarget.h 2026-05-04 10:49:06 +03:00
Lauri Vasama 27fb305c5a Add revng/Support/CDataModel
This structure describes the data model used by a C ABI.
2026-04-30 15:09:16 +03:00
Alessandro Di Federico 6894862ef2 Implement platform roots support
Refactor the binary import and dependency resolution infrastructure to
support multiple platforms (Linux, Windows, macOS) via a
configuration-driven root system.

Major changes:

* Overhaul PDB and DWARF importers for platform-aware debug info
  loading.
* Refactor LDDTree into a template-based architecture with
  platform-specific implementations (ELF, PE/COFF).
* Mostly rewrite the PDB importer, which had significant limitations.
2026-04-24 17:54:09 +02:00
Alessandro Di Federico eb9e82477a Introduce WindowsApiSetSchemaParser 2026-04-23 13:40:43 +02:00
Alessandro Di Federico f1ab2f7544 Introduce getConfigDirectory 2026-04-23 13:40:43 +02:00
Alessandro Di Federico 0385e4c652 Introduce revng::Configuration 2026-04-23 13:40:43 +02:00
Alessandro Di Federico 80657806da Introduce findPathCaseInsensitive 2026-04-23 13:40:42 +02:00
Alessandro Di Federico 58ab09b107 findFileInPaths: do not abort on missing file 2026-04-23 13:40:42 +02:00
Alessandro Di Federico 6a3a0489a7 Logger::unindent: fix assertion 2026-04-23 13:40:41 +02:00
Alessandro Di Federico 7049f61baa Minor changes 2026-04-23 13:40:41 +02: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
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
Giacomo Vercesi 93a998ce93 TraceProgressListener: also record memory usage
Add the additional optional functionality to `TraceProgressListener` to
periodically poll the memory usage of the current process to plot as a
separate counter as part of the trace.
2026-01-20 12:29:12 +01:00
Alessandro Di Federico d79c66cb1b Introduce getOrCreateGlobal 2025-12-22 11:34:47 +01:00
Alessandro Di Federico b94e21a06e Handle inexistent --debug-log gracefully 2025-12-22 11:34:47 +01:00
Alessandro Di Federico 7d6c007d71 Progress: check ioctl(TIOCGWINSZ) result 2025-12-22 11:34:46 +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 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
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
Giacomo Vercesi 153fcf2773 InitRevng: initialize LLVM components
In the constructor of `InitRevng` also call all the `llvm::initialize*`
functions. This is done to be less implementation-specific and having
these functions be called in
`LLVMPipelineRegistry.libraryInitialization`.
2025-11-17 10:04:13 +01:00
Alessandro Di Federico c883bed765 Drop Logger's StaticEnabled feature 2025-10-31 17:25:03 +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 246e0d9b59 Logger: handle nameless loggers 2025-10-29 10:57:19 +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 2ba5ca3e3d Suppress selected IRBuilder checks 2025-10-21 19:17:37 +03:00
Ivan Krysak 3561c2b907 Adopt IRBuilder wrapper 2025-10-21 19:17:01 +03:00
Giacomo Vercesi e57442fafe Introduce Tar.h
Split off the `GzipTarReader` into `Tar.h`, include a normal
`TarWriter` class which leverages libarchive to generate the tar file.
2025-10-16 16:08:05 +02:00
Giacomo Vercesi 2f83d8f5c9 Introduce CUniquePtr
Add a helper using of `std::unique_ptr` that allows easier wrapping of
C pointer with destructors.
2025-10-16 16:08:05 +02:00
Ivan Krysak e56f543b1a Split module.bc.zstd 2025-10-13 10:26:41 +03:00
Ivan Krysak 5717d835f8 Add missing llvm::Error checks 2025-10-13 10:26:37 +03:00
Ivan Krysak dadd836035 MetaAddress: assert validity 2025-10-08 12:22:34 +03:00
Ivan Krysak a88747cf99 Drop unused includes 2025-10-08 12:22:34 +03:00
Lauri Vasama 375d40fc59 Move CTarget.h under revng/Support 2025-09-29 18:05:54 +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 a285ad2785 IRHelperRegister: get a comment from Description 2025-07-23 11:38:53 +02:00
Ivan Krysak b5337d78da Minor Improvements 2025-07-23 11:38:50 +02:00
Andrea Gussoni 1faa781e6a CommandLine: drop pathToStream
Remove `pathToStream` in favour of `llvm::ToolOutputFile`.
2025-07-23 11:34:13 +02:00
Giacomo Vercesi f4a1d5bba6 OnQuit: clean up
Split the handlers in `OnQuit` between the repeatable and non-repeatable
ones. Trigger the non-repeatable ones only on program exit.
2025-05-07 16:42:20 +02:00
Giacomo Vercesi fede2f2090 ProgramRunner: allow redirection of streams
Change ProgramRunner's API to allow to optionally provide stdin and
capture stdout/stderr.
2025-05-05 17:28:48 +02:00
Ivan Krysak 1bce76f511 Bring name mangling out into a support helper 2025-04-24 13:22:14 +02:00