Commit Graph

7544 Commits

Author SHA1 Message Date
Alessandro Di Federico bf5f5e6a7a BitLiveness: fix BitLivenessAnnotatedWriter typo 2026-06-09 13:50:50 +02:00
Alessandro Di Federico 74608011a9 MFP: rename namespace MFP into mfp 2026-06-09 13:50:50 +02:00
Alessandro Di Federico dc05030dd6 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-09 13:50:50 +02:00
Alessandro Di Federico 5670527190 tests/unit: add MFP tests 2026-06-09 13:50:50 +02:00
Alessandro Di Federico 79dfbc6b7d 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-09 13:50:50 +02:00
Alessandro Di Federico 3940c89e57 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-09 13:50:49 +02:00
Alessandro Di Federico 95a216c574 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-09 13:50:49 +02:00
Alessandro Di Federico 45e8df2b44 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-09 13:50:49 +02:00
Alessandro Di Federico d346713845 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-09 13:50:49 +02:00
Alessandro Di Federico d113b571a3 DwarfToModelConverter: skip wide float primitives 2026-06-09 13:50:49 +02:00
Alessandro Di Federico 38b6bebb40 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-09 13:50:49 +02:00
Alessandro Di Federico 57a0d1170f FunctionTags: drop MemoryEffects on AddressOf pool 2026-06-09 13:50:49 +02:00
Alessandro Di Federico 3ef80ee406 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-09 13:50:49 +02:00
Alessandro Di Federico fb1ad3b6d5 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-09 13:50:48 +02:00
Alessandro Di Federico 2c02954410 CliftEmitC: drop assert in emitUndefExpression 2026-06-09 13:50:48 +02:00
Alessandro Di Federico 2628216bc3 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-09 13:50:48 +02:00
Alessandro Di Federico b847229da1 Minor changes
Comment refresh, formatting and small no-op tweaks across unrelated
files.
2026-06-09 13:50:48 +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
Andrea Gussoni 660f5551ee cmake: fix helper-annotation pipeline dependency
Add the `revngHelperArgumentsAnalysis` library to the dependencies of
the helpers building pipeline, so they are rebuilt whenever there is a
change in the library.
2026-05-29 17:12:35 +02:00
Andrea Gussoni 9b5eb460e0 docs: tested docs for QEMU helper functions
Walks through the full helper evolution pipeline (QEMU C ->
original IR -> full -> to-inline -> declarations-only), covering
env-to-CSV rewriting by fix-helpers, REVNG_INLINE/REVNG_EXCEPTIONAL
semantics, CSV access metadata, and per-artifact usage (lift,
enforce-abi, recompile).

All code snippets are tested via revng test-docs.
2026-05-29 17:12:35 +02:00
Andrea Gussoni 76fedfb249 Clifter: remove abbreviation and use alignTo
Remove an abbreviation and use `llvm::alignTo` to compute the
alignment.
2026-05-29 17:12:35 +02:00
Andrea Gussoni ada6ef50f2 HelpersToHeader: remove _PACKED handling
Uniform the `struct` emission to use the `_PACKED` version, and use
`llvm::alignTo` to compute the alignment.
2026-05-29 17:12:35 +02:00
Andrea Gussoni 530ce317c1 ABI: use llvm::alignToPowerOf2
`llvm::alignToPowerOf2` covers the same semantics of the dropped
`alignedOffset` method, including the power of 2 assertion.
2026-05-29 17:12:35 +02:00
Alessandro Di Federico ebad6c458e IsolateFunction: keep all register CSVs 2026-05-29 15:20:26 +02:00
Pietro Fezzardi 599c282e94 Merge 'feature/clift-hoist-variable-initializers' 2026-05-25 10:12:10 +02:00
Lauri Vasama b078f2c809 Fix C label output around hidden statements 2026-05-25 09:00:41 +02:00
Lauri Vasama 5c9a7b4207 Fix C output around hidden casts
```
// before
(var_0.x)[1];

// after
var_0.x[1];
```
2026-05-25 09:00:41 +02:00
Lauri Vasama 039f533a9f Add ternary inversion rewrite pattern
```
// before
!x ? y ? z

// after
x ? z ? y
```
2026-05-25 09:00:41 +02:00
Lauri Vasama 5a5703ec10 Add expression rewrite descriptions 2026-05-25 09:00:41 +02:00