178 Commits

Author SHA1 Message Date
Alessandro Di Federico 903617e79e IRHelpers: turn some functions into IRBuilder::* 2026-06-19 09:18:16 +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 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 2a2ef04ec0 Minor changes
Comment refresh, formatting and small no-op tweaks across unrelated
files.
2026-06-11 17:39:52 +02:00
Pietro Fezzardi 8ee6edfd15 Restructure LocalVariableBuilder
Reorganise LocalVariableBuilder so that the legacy and non-legacy
code paths are separated into two specialisations, and so that the
non-legacy specialisation does not need a model::Binary to operate.

This is a prerequisite for using LocalVariableBuilder from passes
that do not know about the model, e.g. unit tests for the new-PM
SwitchToStatements and the upcoming non-legacy decompilation
pipeline.
2026-05-08 11:37:09 +02:00
Pietro Fezzardi f71200ae00 Segregate: emit "revng.pointers" metadata
Extend SegregateStackAccessesPass to attach the "revng.pointers"
metadata on every llvm::Function it rewrites, and on every CallInst
it produces.

The metadata represents, in a model-agnostic way, which arguments
and return values of a call or function (both formal and actual)
are pointer-typed in the model. Later passes consume this so that
they can stay model-agnostic.
2026-05-08 11:37:09 +02:00
Alessandro Di Federico 7049f61baa Minor changes 2026-04-23 13:40:41 +02:00
Alessandro Di Federico c2fe99337d DetectStackSize: sign-exted LowerBound
This led to misdetect the stack size on 32-bit architectures.
2026-03-18 15:19:18 +01:00
Ivan Krysak ad822abc53 Fix static IR helper object names 2026-02-25 14:10:44 +01:00
Ivan Krysak f0e00d66ab Do not use doxygen for TODOs 2026-02-25 12:47:27 +01:00
Giacomo Vercesi 27f419c8cd Fix and ban namespace clobbering
Fix an instance where the `std` namespace got clobbered into the global
namespace by accident.
2026-02-16 10:34:38 +01:00
Lauri Vasama aa2597d13b model::Function: add stack frame name and comment
* StackFrameType() is removed.
* StackFrame() is introduced in its place.
* Use StackFrame().Type() to acess the stack frame type.
2026-02-13 08:41:39 +02: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 69e3d4bd9b revng_undefined_local_sp: mark as read-only
`revng_undefined_local_sp` was previously initially marked as using
inaccessible memory and, later on, marked as reading only memory.

Doing the latter right away is fine.

This commit also does not assume that function is always available.
2025-12-22 11:34:47 +01:00
Alessandro Di Federico 4d5183a0ac Make layoutToLLVMFunctionType self-contained
`layoutToLLVMFunctionType` no longer needs to know the old return type.
2025-12-22 11:34:47 +01:00
Alessandro Di Federico 0bf97a9e68 getPointerSizedInteger: use model::Architecture
No need to get model::Binary.
2025-12-22 11:34:47 +01:00
Giacomo Vercesi 397df408be RemoveStackAlignment: allow missing InitFunction 2025-12-19 10:28:29 +01:00
Giacomo Vercesi 1632aeac73 Comment run* function with inlinable content
Add `TODO` comments to piperuns' `run*` functions that will have content
inlined once the old pipeline is removed.
2025-12-10 16:16:14 +01:00
Giacomo Vercesi ee1fdebc4e Add SegregateStackAccesses to pypeline 2025-12-10 16:16:14 +01:00
Giacomo Vercesi 5a6efb0fa2 Add DetectStackSize analysis to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 3e37058899 Add LegacySegregateStackAccesses to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi c0e8c8fa09 Add PromoteStackPointer to pypeline 2025-12-10 15:05:53 +01:00
Giacomo Vercesi 10cc709098 Add InjectStackSizeProbesAtCallSites to pypeline 2025-12-10 15:05:53 +01:00
Alessandro Di Federico 896bb8d523 Drop SegregateStackAccessesPass.h 2025-12-03 17:59:18 +01:00
Alessandro Di Federico c883bed765 Drop Logger's StaticEnabled feature 2025-10-31 17:25:03 +01:00
Lauri Vasama 086dc9fbc9 Remove RecursiveCoroutine operator*
* Add rc_eval to force evaluation.
2025-10-31 17:23:52 +01:00
Alessandro Di Federico 4fb6b5f4e1 Minor changes 2025-10-24 18:20:48 +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 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
Ivan Krysak a285ad2785 IRHelperRegister: get a comment from Description 2025-07-23 11:38:53 +02:00
Ivan Krysak 76ed261375 Use revng_undefined_ instead of init_
Current `init_` prefix used to set the default values of SCVs
is very common in typical code, hence it would cause a lot of
collisions.
2025-04-17 11:19:17 +03:00
Ivan Krysak 8a8e0ce4ae PromoteStackPointer: adopt helper registry 2025-04-17 11:19:17 +03:00
Ivan Krysak aa15d8ca21 Standardize abort-like function usage 2025-04-17 11:19:17 +03:00
Ivan Krysak 154287b5d5 init_local_sp: drop leading _ 2025-04-17 11:19:17 +03:00
Ivan Krysak 57b5eb7f98 NameBuilder: allow different name checkers 2025-04-17 11:19:17 +03:00
Ivan Krysak 645cf7fc2e NameBuilder: sunset deduplication
This reworks NameBuilder to ease the transition to the system where
the model will be guaranteed to never contain any name collisions, both
between user-specified names and the automatic ones.
2025-04-15 16:35:42 +03:00
Ivan Krysak 3edb6cbb9b Minor improvements 2025-04-15 16:35:42 +03:00
Alessandro Di Federico c5b9728289 LocalVariableBuilder: add pointer size assumption
This commit further centralizes the creation of allocas + ptrtoint.  The
creation of these pair of instructions is problematic when the size of a
pointer in the input and target architecture differ.

In fact, in such cases, LLVM turns trunc into masking the integer to
suppresse the high bits. This results in problematic code.

This commit introduces an assumption that ensures LLVM does not do that.
2025-03-17 08:51:29 +01:00
Alessandro Di Federico 25239cdf34 Improve RemoveStackAlignmentPass
This commit adopts `PatternMatch.h` and adds support discarding
alignment operations even if they are performed after manipulating the
stack pointer.

For instance, glibc's `_start` does the following:

    xor    ebp,ebp
    mov    r9,rdx
    pop    rsi
    mov    rdx,rsp
    and    rsp,0xfffffffffffffff0
2025-03-05 09:57:51 +01:00
Alessandro Di Federico 22ab0ae718 ComputeStackAccessesBounds: fix mismatch in types 2025-02-21 14:26:59 +01:00
Ivan Krysak 705e4a5955 auto [...] -> auto &&[...] 2025-02-13 13:10:51 +02:00
Pietro Fezzardi 0f2466e84b SegregateStack: drop old unused LocalVarPool 2025-01-29 15:17:15 +01:00
Pietro Fezzardi 1676ecdd8f SegregateStack: emit AddressOf only in legacy mode 2025-01-29 15:17:15 +01:00
Pietro Fezzardi 290f3a557c SegregateStack: emit ModelGEPs in only legacy mode 2025-01-29 15:17:15 +01:00
Pietro Fezzardi fd46acc72b SegregateStack: LocalVariableBuilder for stack arg 2025-01-29 15:17:15 +01:00
Pietro Fezzardi a6883064fd SegregateStack: refactor creation of AddressOf 2025-01-29 15:17:15 +01:00
Pietro Fezzardi 8fff02b45c SegregateStack: LocalVariableBuilder for stack 2025-01-29 15:17:15 +01:00
Pietro Fezzardi fcab2e0c19 SegregateStack: LocalVariableBuilder for locals 2025-01-29 15:17:15 +01:00