7705 Commits

Author SHA1 Message Date
Ivan Krysak 6ff6b8d699 CliftImportModel: ensure DataModel is set 2026-06-15 11:47:41 +02:00
Ivan Krysak 4c6fe97059 abi::getDataModel: introduce 2026-06-15 11:47:41 +02:00
Ivan Krysak 659951620e Drop unnecessary includes 2026-06-15 11:47:41 +02:00
Ivan Krysak d22bd1cc58 CliftImportModel: introduce more bulk importers 2026-06-15 11:47:41 +02:00
Ivan Krysak 602a4fe138 Model: improve naming configuration verification 2026-06-15 11:47:41 +02:00
Ivan Krysak f9d18cfb9b TTG: remove unnecessary const 2026-06-15 11:47:41 +02:00
Ivan Krysak ea785998ec Minor improvements 2026-06-15 11:47:41 +02:00
Pietro Fezzardi b4aaf5814f ExitSSAPass.cpp: drop unused #include 2026-06-15 11:46:44 +02:00
Alessandro Di Federico bea71a46e2 Merge branch 'feature/segretate-aggregates' 2026-06-12 09:40:02 +02:00
Alessandro Di Federico 9217752883 model override-by-name: skip nameless base functions
`base_function["Name"]` crashes with `KeyError` when the model has
a function without an explicit `Name` (e.g. the binary entry stub).
Skip those entries silently; only named functions can be matched
by name anyway.
2026-06-11 17:39:53 +02:00
Alessandro Di Federico 58c5d942a0 BitLiveness: fix BitLivenessAnnotatedWriter typo 2026-06-11 17:39:53 +02:00
Alessandro Di Federico 6a594a9133 MFP: rename namespace MFP into mfp 2026-06-11 17:39:53 +02:00
Alessandro Di Federico 841b5dab71 SegregateStackAccesses: rewrite around ExtraState
Move all per-function state and logic into a new SegregateFunctionStack
worker, so the pass class itself only holds module-wide state and the
runOnFunction body is just upgrade() + segregate(). The discovery loop
now uses the MFP ExtraState surface to capture the analysis value
before each interesting program point, replacing the splitBasicBlock
trick that introduced fake nodes only to read the lattice value at
them.

Other changes that ride along:
- StackOffsetCache memoizes getStackOffset per function.
- findAllWriters does a single sorted sweep instead of a quadratic
  scan over Ranges.
- The pipeline gains a stack-accesses-segregated artifact entry.
- Test fixtures (filecheck.ll, override.yml, segregate-stack-accesses
  configuration) are updated to match the new IR shape.
2026-06-11 17:39:53 +02:00
Alessandro Di Federico 4f52d444c6 tests/unit: add MFP tests 2026-06-11 17:39:53 +02:00
Alessandro Di Federico d03e62c250 MFP: add ExtraState, MFPConfiguration, variant
Three closely-coupled changes that have to land together to keep
every caller compiling:

- Introduce a per-instance ExtraState recording surface (with a
  NoExtraState default) and thread it through applyTransferFunction.
- Replace getMaximalFixedPoint's positional arg list with a single
  MFPConfiguration struct, so callers spell out only the fields they
  need.
- Replace the EntryLabels pointer with an Entry/All/vector* variant
  so callers can ask for the graph entry, every node, or a custom
  list without juggling extra arguments.

Update every existing caller for the new signatures and switch
Liveness::GraphType to a plain Function* (with the inverse
GraphTraits selected at call sites).
2026-06-11 17:39:53 +02:00
Alessandro Di Federico c306157596 SplitStructPhis: replace HoistStructPhis
Replace the hoist-struct-phis pass with a split-struct-phis pass that
breaks struct PHI nodes into per-field PHIs instead of moving them
out, and update both pipelines to use the new name.
2026-06-11 17:39:53 +02:00
Alessandro Di Federico 4150afc33f StructInitializers: add createCall; EmitBody flag
Split createReturn into a reusable createCall that emits the
struct-initializer call without wrapping it in a return. An EmitBody
flag lets callers create the declaration but skip the body, useful
when the body would later be stripped.
2026-06-11 17:39:53 +02:00
Alessandro Di Federico 51526e9777 ABI/Layout: move YAML traits to header
The YAML traits for Layout (and friends) move into Layout.h so callers
can serialize a Layout directly without pulling in Layout.cpp's
internals. As a result StackSpan gains default-initialized fields and
its operator+ is hoisted to a free function (with the symmetric
uint64+StackSpan overload) so it works with the YAML mapping.
2026-06-11 17:39:53 +02:00
Alessandro Di Federico fbe825d66a ABI/Clifter: drop SPTAR special case in returns
Drop the SPTAR-specific special case in layoutToLLVMFunctionType: all
ModelAggregate-returning functions now use the same array-of-i8 return
type. Clifter is updated accordingly to treat any aggregate return the
same way, removing the SPTAR-specific branches that were just dead
code after the type unification.
2026-06-11 17:39:53 +02:00
Alessandro Di Federico 4daa276c45 DwarfToModelConverter: skip wide float primitives 2026-06-11 17:39:52 +02:00
Alessandro Di Federico f0e44e5fe8 primitive-types: emit undef_value as typed pointer
Return a pointer to a buffer of the requested size and let the macro
dereference it as the target type, instead of casting a uintmax_t. This
makes the macro usable for types wider than uintmax_t.
2026-06-11 17:39:52 +02:00
Alessandro Di Federico ce6eda6836 FunctionTags: drop MemoryEffects on AddressOf pool 2026-06-11 17:39:52 +02:00
Alessandro Di Federico 726f2ea618 IRHelpers: getConstantArg honors signedness of T
Use getSExtValue/getZExtValue depending on whether T is signed, so
callers asking for a signed type get the sign-extended value.
2026-06-11 17:39:52 +02:00
Alessandro Di Federico 1ca8239b65 ImplicitCastElision: elide casts only on integrals
For comparison operators (==, !=, <, >, <=, >=) the elision is only
sound when both operands are of integral type; otherwise we'd be
changing the kind of comparison being performed.
2026-06-11 17:39:52 +02:00
Alessandro Di Federico 8973f6e55c CliftEmitC: drop assert in emitUndefExpression 2026-06-11 17:39:52 +02:00
Alessandro Di Federico f28ca69921 Lift: drop redundant TranslateTask.complete()
The TranslateTask is immediately advanced to a new step right after,
which marks the previous step as complete automatically.
2026-06-11 17:39:52 +02:00
Alessandro Di Federico 2a2ef04ec0 Minor changes
Comment refresh, formatting and small no-op tweaks across unrelated
files.
2026-06-11 17:39:52 +02:00
Pietro Fezzardi 2bc640a5c2 import-from-c tests: make failures actually fail
These tests could pass even when the analysis crashed. The harness
joins the test command into a single shell line, and the diagnostic
block of the error-comparison branch was missing its statement
terminators: it collapsed into a single echo that swallowed `exit 1`,
so the comparison could never fail the test. Moreover, the exit code
of revng2 was only consumed as a boolean, mistaking crashes for
graceful failures, and tests without an expected-error.txt compared
the empty string against the empty RuntimeError payload extracted
from a crash trace, silently passing.

Now the diagnostics are properly terminated, the content of the error
file is printed on mismatch, and the expected-error path requires
exit code 1, an existing expected-error.txt and a non-empty
RuntimeError payload; any other failing outcome dumps stderr and
makes the test fail.
2026-06-10 13:21:17 +02:00
Pietro Fezzardi 73cbd99f0a Re-enable comment tests that check for no comments 2026-06-03 22:23:42 +02:00
Pietro Fezzardi 34ec07bd7f pipeline: add hoist-variable-initializers 2026-06-03 16:33:15 +02:00
Pietro Fezzardi ad18e6695c ExitSSA: make edge-splitting deterministic
Replace the stable_sort that ordered (block, value) entries by raw
BasicBlock* address in getIncomingUsesOfValuesFromBlocks with a
MapVector that groups entries by block in first-encountered
insertion order, and add a per-block stable_sort by use count
(descending). Same-block contiguity is now structural rather than
enforced by a sort, and the order in which the split basic blocks
are created and appended to the function no longer depends on
pointer values that vary across runs. The within-block ordering,
the use-count tie-breaking, and the rest of the edge-splitting
algorithm are preserved.
2026-06-03 16:33:15 +02:00
Pietro Fezzardi 1c0c28081d STS: reduce unnecessary use of llvm namespace 2026-06-03 16:33:15 +02:00
Pietro Fezzardi 197219673f STS: drop dependency from LVB in non-legacy mode
After we drop legacy mode, the only user of LocalVariableBuilder will be
SegregateStackAccesses. This is possible thanks to the fact that
dropping the legacy mode will demistify local variables and turn them
into plain allocas accessed via loads/stores. This will end the need for
a centralized place to deal with local variable creation, that is caused
by the various ad-hoc manipulations we've been doing for a long time in
legacy mode.
2026-06-03 16:33:15 +02:00
Pietro Fezzardi bbb713f548 LegacyStackAllocators: only depend on input intptr 2026-06-03 16:33:15 +02:00
Pietro Fezzardi 76b10703b1 TypeDependencyGraph: rename Mode to ModelMode 2026-06-03 16:33:15 +02:00
Pietro Fezzardi 18054eeee2 DLACollapseSingleChild: fix pointer loops
This commit fixes a situation where CollapseSingleChild could introduce
infinite loops composed entirely of pointer edges, which would end up in
making the DLA backend go out-of-memory.

This happened when collapsing a Child at offset 0 into a Parent node,
when Child had a pointer edge going to Parent.
The pointer edge needed not to be at step one, but it could possibly be
a pointer-to-pointer to Parent, at any depth.

After merging Child into Parent this would lead to a node pointing to
itself, which is a forbidden pointer loop in the graph.

This commit catches the pattern and prevents it to merge Child into
Parent.
2026-06-03 16:33:15 +02:00
Alessandro Di Federico 730e6f2bed Merge branch 'feature/improve-drop-types' 2026-06-03 14:31:30 +02:00
Alessandro Di Federico bc4872f2f4 DwarfImporter: handle STT_GNU_IFUNC symbols
In DWARF, `STT_GNU_IFUNC` symbols are associated to a function prototype
returning the actual prototype.
2026-06-03 13:59:53 +02:00
Alessandro Di Federico 9e9451247b Drop --import-debug-info command-line option
The --import-debug-info CLI flag and the ImporterOptions::
AdditionalDebugInfoPaths field it populated were a side-channel that
loaded extra DWARF files outside the normal ELF dependency-resolution
path. It bypassed the symbol-aware machinery and is no longer needed.
2026-06-03 13:59:53 +02:00
Alessandro Di Federico 03e02771ac Add model drop-types tool 2026-06-03 13:59:53 +02:00
Alessandro Di Federico 5fa47e8d37 Reorganize lit tests under tests/filecheck 2026-06-03 13:59:53 +02:00
Alessandro Di Federico 9596cf1151 Rework dropTypesDependingOnDefinitions 2026-06-03 13:58:33 +02:00
Alessandro Di Federico 1af2a5aed5 Merge branch 'feature/floating-point-frontend' 2026-06-03 11:26:07 +02:00
Andrea Gussoni d4f1a717e2 tests: add floating-point end-to-end tests 2026-05-29 17:12:38 +02:00
Andrea Gussoni 35b0da291a InlineHelpers: add post-inlining no-GEP verifier
Add `PostInlineHelpersVerifyPass`, a `ModulePass` derived class that
aborts on any `getelementptr` instruction found in any Isolated
function. `inline-helpers` is the only pass in the post-isolate chain
that could import a GEP into an Isolated function by inlining a helper
body that contains one, so the verifier is invoked at the end of
`InlineHelpersPass::runOnModule`. In this way, we early catch this
invariant on the IR.
2026-05-29 17:12:35 +02:00
Andrea Gussoni 9c8808fd9e InlineHelpers: Use revng.inline.policy metadata
Use the helper's `!revng.inline.policy` and inline at each call site
only when every critical argument is constant.
2026-05-29 17:12:35 +02:00
Andrea Gussoni f2f63dd73c PromoteCSVs: compute revng.inline.policy
When PromoteCSVs synthesizes a CSV-promoted wrapper for a helper,
compute the `!revng.inline.policy` metadata  so `InlineHelpers` sees the
static policy at the wrapper's call site.
2026-05-29 17:12:35 +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
Andrea Gussoni 8103e2046c MarkInlineHelpersUpTo: introduce pass
Introduce a build-time pass that tags every QEMU helper transitively
reaching a function defined under one of the configured runtime-library
directories (currently `fpu/` only) as `revng_inline`. The intent is to
make the lift pipeline surface "leaf-level" runtime-library calls (e.g.
softfloat ops) directly in the lifted IR by inlining away every wrapper
helper that sits between QEMU's `helper_*` boundary and the leaf.

We also gate the tagging by a per-function body-size budget.

The pass is run in the pipeline building the `libtcg-helpers-full-*.bc`
artifacts.
2026-05-29 17:12:35 +02:00
Andrea Gussoni 04a275d91b FixHelpers: switch on env-relative offsets
Fix the `switch` emitted by `fix-helpers` so that we express the address
as a `env`-relative offset.
2026-05-29 17:12:35 +02:00