Commit Graph

193 Commits

Author SHA1 Message Date
Alessandro Di Federico 7dff660b36 propagatePrototypesInFunction: propagate names 2023-10-05 10:19:44 +02:00
Alessandro Di Federico e919fff6e7 DetectABI: posticipate propagatePrototypes
This change avoids making changes to the model that `finalizeModel` does
not expect.
2023-10-05 10:19:44 +02:00
Alessandro Di Federico 52dc3faf2c CFGAnalyzer: noreturn tail calls do not return 2023-10-05 10:19:44 +02:00
Alessandro Di Federico bf66ecc389 {,Dynamic}Function::Prototype: support typedefs 2023-10-05 10:19:44 +02:00
Alessandro Di Federico 7ba01f513b ABIAnalyses: fix collection points
The collection points of several ABI analyses where incorrect. Several
analyses that should have collected data only from entry points were
collecting data from any node in the graph.
2023-10-04 17:47:50 +02:00
Alessandro Di Federico 676654ea7b ABIAnalysis: improve logging 2023-10-04 17:47:50 +02:00
Alessandro Di Federico 111b3a819d CFGAnalyzer::milkInfo: add logging 2023-10-04 17:47:50 +02:00
Djordje Todorovic fc88a52fae AttachDebugInfo: Fix for MLIR
Up until now, we did not need different !dbg/DISubprogram
attached to each isolated llvm::Function, but for the
purpose of MLIR lowering, we need it.

On the LLVM IR level, we used to reuse root's DISubpgram,
and we have not being attaching !dbg/DISubprogram to the
isolated functions at all (just to llvm::Instructions),
but that was an hack in order to avoid some LLVM verify
checks, since LLVM IR expects !dbg attachments to calls of
functions that could be inlined, but by avoid !dbg on the
Function itself, it won't verify !dbg attachments on the
instructions, since it will assume it has no debug info in
it. When it comes to MLIR, it expects different !dbg
attached to each function, in order to process debug info
in it, so that is the reason we cannot rely on the root
DISubprogram only anymore.
2023-09-21 08:05:49 +02:00
Alessandro Di Federico f51af94e8f TupleTreeReference::isValid is for assertions only 2023-08-23 16:14:05 +02:00
Kacper Kołodziej c0f226fa70 Add const qualifiers to some functions
getJumpTargetBlock takes llvm::BasicBlock * as argument, but doesn't
need to modify it, so const it adds const to it and other functions that
are used by getJumpTargetBlock: findJumpTarget, isTranslated, getType,
isJumpTarget.
2023-07-31 11:29:40 +02:00
Kacper Kołodziej 2c470ec036 Add propagating prototypes in DetectABI pass
The goal of this update is to propagate prototypes of functions called
in wrappers to this wrappers.

When some function hasn't it's own prototype, but the only thing it does
is calling another function, DetectABI pass sets callee prototype as
caller prototype also.

This behaviour is limited to callers that:
 1. have only one basic block
 2. end with call
 3. don't write arguments of callee
 4. don't modify stack pointer
 5. don't write to memory.
2023-07-20 18:09:48 +02:00
Kacper Kołodziej 75ed8f7788 Add WrittenRegisters set to FunctionSummary
WrittenRegisters will be used in propagating prototypes to wrappers
functionality to check if function writes to arguments or stack pointer.
2023-07-20 18:09:48 +02:00
Ivan Krysak 7d235f4fd0 Enforce licence header consistency
Also do some basic cleanup: capitalize first letters, add `.`
at the end of the sentences, and so on.
2023-07-03 15:23:10 +00:00
Ivan Krysak 9f1d9fd5d0 Use Container::contains() where appropriate 2023-07-02 15:06:11 +00:00
Ivan Krysak bc98e0079f Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-02 13:20:49 +02:00
Alessandro Di Federico a65ccc3413 Introduce ValueMaterializer
`ValueMaterializer` is a rewrite of what was called `AdvancedValueInfo`
which follows the same principles.

The main benefits over the old version is:

* We materialize the data-flow graph and the CFG of the relevant part of
  root. This makes debugging significantly easier.
* We drop the old MonotoneFramework infrastructure in favor of
  getMaximalFixedPoint.
* We significantly reduce the amount of queries we make to
  AdvancedValueInfo.
2023-06-30 13:39:22 +02:00
Alessandro Di Federico 466871e866 Introduce RegisterClobberer 2023-06-30 13:28:36 +02:00
Ivan Krysak 5b2af637de Minor Changes 2023-05-25 06:25:07 +00:00
Ivan Krysak 641fb61f7b EFA: upgrade buildControlFlowGraph
It now assumes that the nodes of the graph it constructs also require
the function entry point on top of the basic block ID.
2023-05-17 14:08:05 +02:00
Ivan Krysak d99b0241e8 Minor improvements 2023-05-17 14:08:04 +02:00
Alessandro Di Federico 14b40ebe45 CFEP: ignore if already part of another block
We used to ignore CFEPs that matched the starting address of a basic
block of a previously detect function.
We now also exclude such CFEPs even if the candidate is *part* of an
existing block.
2023-05-17 11:19:32 +02:00
Alessandro Di Federico 739bed3c1d DetectABI: serialize CFG in root
This is done mainly so that downstream passes do not need to run
`CollectCFG` to store information that has already been computed but not
serialized.

This come at the cost of computing the CFG also of functions we don't
want to analyze in `DetectABI`.
2023-05-17 11:17:44 +02:00
Giacomo Vercesi 31cd2b53f9 rcc: add codespell
Add codespell to the list of checks performed by
revng-check-conventions. This should reduce the amount of typos present
in the revng codebase.
2023-05-11 10:05:32 +02:00
Alessandro Di Federico 680c706771 DetectABI: introduce extra assertions 2023-05-10 09:15:04 +02:00
Ivan Krysak 7ca012dbc3 Minor improvements 2023-04-27 17:28:22 +02:00
Massimo Fioravanti 254dc99fcb TupleTreeGenerator: emit tracking machinery 2023-04-21 17:50:16 +02:00
Alessandro Di Federico 401f731eda AttachDebugInfo: color instructions with a visit
We used to only color instructions in the same BasicBlock as the call to
`newpc`.  However, an instruction in the original binary can span
multiple BasicBlocks.
2023-04-13 18:11:48 +02:00
Alessandro Di Federico bc4833078c Fix InstCombine constructor invocation
In LLVM 12 the `InstCombine` constructor used to take a `bool`, in LLVM
16 it takes an integer. Implicit promotion was hiding this fact.
2023-04-08 08:42:24 +02:00
Alessandro Di Federico 6c115da619 Update pass names 2023-04-08 08:42:24 +02:00
Alessandro Di Federico ae871f5062 Adopt setOnlyReadsMemory 2023-04-08 08:42:24 +02:00
Alessandro Di Federico 43fd690ea8 InaccessibleMemOnly: adopt MemoryEffects 2023-04-08 08:42:24 +02:00
Alessandro Di Federico e131817334 Drop usage of Type::getPointerElementType 2023-04-08 08:42:24 +02:00
Alessandro Di Federico a0fa150576 Drop usages of LoadInst::getPointerOperandType 2023-04-08 08:42:24 +02:00
Alessandro Di Federico 7a08d51816 Drop usages of PointerType::getElementType 2023-04-08 08:42:24 +02:00
Alessandro Di Federico a99d54457b Drop usages of getInstList 2023-04-08 08:42:24 +02:00
Alessandro Di Federico aa6a60c5b8 Adopt new InlineFunction prototype 2023-04-08 08:42:24 +02:00
Alessandro Di Federico 449e95021a Replace CallBase::getNumArgOperands with arg_size 2023-04-08 08:42:24 +02:00
Alessandro Di Federico d2caa1fad0 Make CreateLoad usages opaque pointers-compatible 2023-04-08 08:42:24 +02:00
Ivan Krysak ea6148e616 DetectABI: leave a todo on droping RS deductions 2023-03-15 10:19:03 +01:00
Ivan Krysak 9e393578c9 ABI: move state deduction onto the runtime trait 2023-03-15 10:19:02 +01:00
Ivan Krysak 01a05e2037 ABI: separate convertions based on the direction 2023-03-15 10:19:02 +01:00
Alessandro Di Federico f68b7866b3 Introduce BasicBlockID
This commit introduces `BasicBlockID` as the unique identifier for a
`efa::BasicBlock` into the CFG. A `BasicBlockID` is defined by a
`MetaAddress` plus an incremental integer. This enables us to have
multiple instances of the same block in a single function, which is
particularly useful when inlining multiple times the same function.

Apart from this, the commit also does the following:

* It drops representing `MetaAddress`es a `structs` in the IR. This created
  several issues related to ABI. We now represent them as strings.

* It defines more functions in `support.h`, instead of defining prototypes
  by hand in `CodeGenerator.cpp` and the like. Specifically, `unknownPC`
  and `raise_exception_helper`. We also introduce a C "constructor" for
  `PlainMetaAddress`.

* It significantly reduces the API of `GeneratedCodeBasicInfo`, which
  was supposed to be put on a diet since a long time.  Specifically,
  many jump target related methods have been moved to free functions in
  `IRHelpers.h`.  Also `GCBI::getSuccessors` has been pushed into its
  only user, `PruneRetSuccessors`, to prevent further usage of a
  deprecated API. In the future, it would be nice to drop it entirely.

* It introduces `efa::BasicBlock::InlinedFrom`.

* Introduce an enum to represent named argument indices for `newpc`.
  This enables us to more effectively manipulate its argument list.

* It improves the verification and error reporting for
  `efa::FunctionMetadata`.

* Update tests.

This commit is preliminary to another piece of work to improve the
generality of inlining beyond the simple "fake function" scenario, for
which the feature was originally conceived.
2023-02-23 14:51:10 +01:00
Djordje Todorovic a48e518467 Introduce AttachDebugInfo pass 2023-02-02 15:26:44 +01:00
Massimo Fioravanti 742e1a0c56 TupleTree: switch from public fields to accessors 2022-12-12 18:36:57 +01:00
Alessandro Di Federico 63e3330bab efa::FunctionMetadata: use ROOT_TYPE 2022-12-09 09:12:28 +01:00
Ivan Krysak 855999f5f0 Layout: add support for multiple return values 2022-11-30 15:06:54 +01:00
Alessandro Di Federico 85b7cf2b85 DetectABI: do not analyze functions with prototype 2022-11-30 15:06:54 +01:00
Massimo Fioravanti 0bfb73fe95 FunctionMetadata: introduce cache
FunctionMetadata was being deserialized every time they were
inspected. This commit introduces a cache structure to prevent this
excessive deserializations.
2022-11-22 14:15:00 +01:00
Massimo Fioravanti fa30486ce0 Outliner: create extractor cache once 2022-11-10 19:41:42 +01:00
Alessandro Di Federico b0bfa5db4a CollectCFG: nop if root is absent 2022-09-01 14:58:50 +02:00