Commit Graph

139 Commits

Author SHA1 Message Date
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
Pietro Fezzardi 59a1434fab Segregate: add template for legacy local variables
Introduce LegacySegregateStackAccessesPipe

This commit restructures the SegregateStackAccesses pass and
SegregateStackAccessesPipe so that they can have 2 modes of operations:
1. Legacy, with the same behavior as the old version, injecting local
   variables as custom llvm::Functions representing opcodes, such as
   LocalVariable, AddressOf, StackFrameAllocator, and CallStackArguments
   allocator.
2. Non-legacy, that is meant to operate with the new LocalVariableHelper
   to inject local variables as regular alloca instructions, with
   additional metadata to discriminate among them.

This commit renames the old SegregateStackAccessesPipe to
LegacySegregateStackAccessesPipe.
It then re-uses the old SegregateStackAccessesPipe name for a new pipe,
meant to work in non-legacy mode.

The pipeline definition YAML file is updated to keep using the legacy
version for now.

For now the implementation is still the same.
2025-01-29 15:17:15 +01:00
Pietro Fezzardi b0a071d2af Segregate: simplify ReturnMethod::ModelAggregate
This is preliminary to unifying the creation and handling of local
variable declarations, to simplify switching over to local variables
represented by plain allocas.
2025-01-29 15:17:15 +01:00
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00
Ivan Krysak 64446d0453 Adopt name builder across the model users 2024-11-06 19:18:53 +02:00
Ivan Krysak efbc5cdd5c Introduce an error creation helper 2024-11-06 19:18:53 +02:00
Alessandro Di Federico 8cd4ee3b59 Move Kinds.h to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 4e670ac8e6 Either link revngcSupport or revngSupport 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 2e4f4d09b9 Remaining FunctionTags have been moved to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico e239e18b0c Adopt FunctionPoolTag 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 800340d6e8 IRHelpers.cpp has been moved to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 5d0d4005c5 s/Ctxt?/Context/g 2024-09-27 10:35:10 +02:00
Alessandro Di Federico 8a5ae5f9c1 s/ExecutionContext &Ctx/ExecutionContext &EC/g 2024-09-27 10:35:10 +02:00
Alessandro Di Federico 9c99ac33ac s/serializeToLLVMString/toLLVMString/ 2024-09-27 10:35:10 +02:00
Alessandro Di Federico e1f46264f8 Ensure every pipe commits what it should 2024-09-26 17:51:07 +02:00
Alessandro Di Federico 14734eb3f0 ComputeStackAccessesBounds: add logging 2024-08-23 18:02:10 +02:00
Alessandro Di Federico d28af50f84 DetectStackSize: handle counted loops 2024-08-23 18:01:47 +02:00
Alessandro Di Federico 0cb3eedd37 Do not use CallBase::getCalledFunction
Use our wrapper, which does not return nullptr if the `FunctionType`s do
not match.
2024-08-07 15:40:56 +02:00
Ivan Krysak 94a0ad6b93 Adopt reworked model::Type 2024-06-27 11:07:01 +02:00
Ivan Krysak c2b4fb70bb Model: rename TypePath to DefinitionReference 2024-06-27 11:07:01 +02:00
Ivan Krysak 3705906074 Model: rename Type into TypeDefinition 2024-06-27 11:07:01 +02:00
Alessandro Di Federico 988af25a7d Adopt UniquedBy* FunctionTags for deduplication 2024-06-26 12:21:58 +02:00
Alessandro Di Federico 5186a58053 s/FunctionMetadata/ControlFlowGraph/ 2024-06-18 17:56:24 +02:00
Pietro Fezzardi d9b0a118ef SegregateStackAccessesPass: drop unused AssignPool 2024-03-19 17:46:32 +01:00
Pietro Fezzardi 05cc20cb6e Rename MallocLike Tag to ReturnsPolymorphic
Also add this Tag to the LocalVariable opcode who was missing it.
2024-03-19 09:44:00 +01:00
Ivan Krysak cb113db124 PromoteSP: stop using Layout 2024-03-18 17:24:01 +01:00
Alessandro Di Federico 0c212b66d9 Relicense to MIT 2024-02-29 17:03:36 +01:00
Alessandro Di Federico 36457a24b2 SegregateStack: support PointerToCopy arguments 2024-02-09 15:07:03 +00:00
Pietro Fezzardi 000b4bc481 Segregate: fix iteration on OpaqueExtractValues
Before this commit, the code was making a couple of broken assumptions on
OpaqueExtractValues
- that OpaqueExtractValues were always ordered in the same way as struct
  fields (e.g. the OpaqueExtractValue extracting field 0 was always the
  first use of the struct-typed value it was extracting from)
- that there was always one and exactly one OpaqueExtractValue for each
  field index in the struct

This commit fixes the issue, while reusing available facilities for
dealing with OpaqueExtractValues.
2024-01-09 09:32:25 +01:00
Massimo Fioravanti 86e45461a0 Introduce pipeline execution context 2024-01-02 11:05:50 +01:00
Pietro Fezzardi 8475e73fb5 Segregate: drop unnecessary variable 2023-12-19 01:57:06 +01:00
Pietro Fezzardi 72fc2be260 Add missing NoMerge function attributes 2023-12-19 01:27:12 +01:00
Alessandro Di Federico 2de10213d4 Segregate: improve returning aggregates support
This commit heavily reworks how we handle returned values, making things
a bit more elegant.

Apart from this, it fixes how were handling types that on the model are
aggregates but were being returned via registers on the IR.
2023-12-12 12:04:21 +01:00
Alessandro Di Federico 02d6f75d4b Segregate: add missing assignment 2023-12-12 12:04:17 +01:00
Alessandro Di Federico 75cfb52fce DetectStackSize: handle CABIFunctionType
DetectStackSize only updates RawFunctionTypes. However it must also
handle CABIFunctionTypes, when met in a call site.  This commit employs
abi::FunctionType::Layout to fix the situation.
2023-12-12 12:04:16 +01:00
Alessandro Di Federico 3709deebc8 SegregateStack: use alloca for stack arguments
This commit:

1. Introduces an alloca for stack arguments of a function. This enables
   us to "write" to stack argument. In order to do so, we simply map the
   relevant stack portion to the alloca that, since it's a memory
   object, can be `load`'d from and `store`'d to.

   Note that `llvm::Argument`s are always scalar since if the original
   argument was an aggregate, it would have been passed as a pointer,
   which is a scalar.

   Note also that previously we were using scalar arguments as if they
   were *pointers* to the stack arguments. This commit fixes that too
   (and updates the tests accordingly).

2. Introduces an alloca for *scalar* stack arguments of a call site.
   The alloca is then mapped to the corresponding part of the stack.
   Previously, there was no redirection and negative offsets from
   `_stack_frame` would pop up.
2023-12-12 12:04:15 +01:00
Alessandro Di Federico 95327c313d SegregateStackAccesses: delay handleMemoryAccess
This commit splits in two stages handleCallSite and
handleMemoryAccess. Running the latter after all the call sites have
been handled, is necessary in order to properly replace certain memory
accesses targeting stack arguments of a call site.
2023-12-12 12:04:15 +01:00
Alessandro Di Federico d267c49a58 Minor changes 2023-12-12 12:04:13 +01:00
Pietro Fezzardi 24cb43ce9c Make RawFunctionType::StackArgumentsType a TTR
This is homogeneous with all other nullable references to types in the
model, such as the StackFrameType in model::Function, and others.
2023-12-05 16:56:52 +01:00
Massimo Fioravanti fdf5cf0325 Fix incorrect usage of TaggedFunctionKinds
A bug in revng allowed to use any TaggedFunctionKinds in place of any
other one. That bug has been fixed and the wrong usages in revng-c have
been updated.
2023-11-06 14:35:06 +01:00