Commit Graph

85 Commits

Author SHA1 Message Date
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
Alessandro Di Federico 8cd4ee3b59 Move Kinds.h to revng 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 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 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 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
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
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 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
Alessandro Di Federico 489dddd0e7 TupleTreeReference::isValid is for assertions only 2023-08-23 16:37:39 +02:00
Alessandro Di Federico 330d2b6cc7 Model: rework how we name things
This commit:

* Introduces `_` as a prefix for all non-user entities we emit in
  decompiled code.
  Also, some names have been changed to be more concise.
  Specifically, the following entities have changed:
  `_ENUM_UNDERLYING`, `_ABI`, `_REG`, `_padding_at_`,
  `_artificial_struct_`, `_artificial_wrapper_`, `_stack`,
  `_break_from_loop_`, `_var_`, `_stack_arguments`,
  `_artificial_struct_returned_`, `_enum_max_value_`.
* Introduce _PACKED for `__attribute__((packed))`.
* `EnumEntry` name: drop the `EnumType` name prefix.
2023-08-23 16:37:39 +02:00
Pietro Fezzardi e423676da3 Segregate: copy attributes on function calls
Before this commit, we were only copying the metadata attached to the
CallInst, but we need to copy also the attributes, otherwise we might
lose important information, such as `nomerge`.
2023-07-20 17:24:54 +02:00
Ivan Krysak fe0531868c Use Container::contains() where appropriate 2023-07-05 06:07:09 +00:00
Ivan Krysak 888e5371eb Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-05 06:06:07 +00:00
Alessandro Di Federico a660c83b49 Segregate: fix handling of return values
We were not properly handling functions with a `CABIFunctionType` whose
return value covered multiple registers (e.g., a `uint64_t` being
returned through two registers in i386).

Also, we were not correctly handling `CABIFunctionType` returning a
integer type that is smaller than the register containing it (e.g., a
`uint32_t` being returned through `rax` in x86-64).

This commit fixes both situations.
2023-06-30 10:48:59 +02:00
Alessandro Di Federico 2a322dcfeb Segregate: handle small return types
If a function was returning a scalar, we used to forward the return type
from before Segregate. However, this was not OK in case a return value
was in a 64-bit register, but was actually using only the lower 32-bits.

This commit improves handling of such situation.
2023-06-21 15:17:28 +02:00
Pietro Fezzardi 3016c2ad41 MakeModelGEPPass: enable operator [] on pointers
This commit enables to emit accesses with the square bracket array
access operator on pointers.

This is accomplished by adding an additional mandatory argument to
ModelGEP (AND NOT to ModelGEPRef) to represent this case.

MakeModelGEPPass is updated to take this into account, together with all
the other passes that handle ModelGEPs.
2023-06-20 18:15:24 +02:00
Giacomo Vercesi a4ad571e61 rcc: Fix typos
Fix the typos detected by `codespell`
2023-05-11 10:04:32 +02:00
Alessandro Di Federico f7a3fa8f07 SegregateStackAccesses: fix returning structs
In SegregateStackAccesses sometimes we have to replace a call whose call
type does not match the callee type. Specifically when the return type
is a `StructType`, sometimes the call returns an identical `StructType`,
but with a different identity.

This commit adapts the return type of new calls on the fly.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 35d2323fa0 SegregateStackAccesses: assert(findAssociatedCall) 2023-04-14 14:54:14 +02:00
Alessandro Di Federico be79842827 Enable DCE of revng_init_local_sp 2023-04-14 14:54:14 +02:00
Alessandro Di Federico ccb660646e Introduce SimplifyCFGWithHoistAndSinkPass
This is a simple pass that enables running simplify-cfg with the legacy
pass manager enabling instruction hoisting and sinking.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 859a9ec2cf SegregateStackAccesses: do not iterate and modify
SegregateStackAccesses creates new functions. Iterating over existing
functions while creating new ones is problematic, so we now first
collect all the functions we want to inspect and then process them.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 82512ef81f CreateIntToPtr: adopt opaque pointer type 2023-04-14 14:54:14 +02:00
Alessandro Di Federico d33f339ec9 Adapt to revng.callerblock.start dismission
We no longer attach non-dbg metadata to instructions, it's not robust.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 7291314505 Stop using getPointer
After introduction of opaque pointers, it's not very effective.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico ead746ba68 Adopt MemoryEffects
Switch from function attributes to MemoryEffects.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 887009a14b InaccessibleMemOnly: adopt MemoryEffects 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 21bbd8b414 Drop usages of Type::getPointerElementType 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 0e5863e2e4 Make CreateLoad usages opaque pointers-compatible 2023-04-14 14:54:14 +02:00
Alessandro Di Federico b0024a302f Fixes for SPTAR passed on the stack 2023-03-15 10:28:24 +01:00
Alessandro Di Federico d325e3b64a SSA: support shadow arguments on stack 2023-03-15 10:28:24 +01:00
Ivan Krysak c2f0fc19e5 ABI: FunctionType.h -> FunctionType/Layout.h 2023-03-15 10:28:24 +01:00
Alessandro Di Federico e73bd95493 Improve handling of declarations
SegregateStackAccesses and PromoteStackPointer were not handling
functions declarated (but not defined) properly.

This commit fixes this, in part by adopting `TaggedFunctionPass`.
2023-03-13 13:42:33 +01:00