Commit Graph

165 Commits

Author SHA1 Message Date
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
Alessandro Di Federico 40f1e06135 CFGAnalyzer, opaque_true: use inaccessiblememonly
This prevents EarlyCSE from deduplicating calls to this functions with
the same arguments, which has unintend effects and leads to loss of
code.
2022-09-01 11:32:42 +02:00
Alessandro Di Federico df34095721 Minor changes 2022-09-01 11:32:12 +02:00
Massimo Fioravanti 633f49c1ef Introduce dedicated namespace for kinds and ranks 2022-08-29 14:44:53 +02:00
Massimo Fioravanti 915c083661 Pipes: reorganize who defines pipes 2022-08-29 14:44:35 +02:00
Alessandro Di Federico 1d91ed9beb tuple_tree_generator: make C++ just a regular backend
The `tuple_tree_generator` component was still heavily treating C++ as a
special citizen.
This commit normalizes the situation.
2022-08-11 16:20:42 +02:00
Massimo Fioravanti 96bd5835d8 revng-pipeline: rework file-to-container syntax 2022-08-10 09:49:24 +02:00
Alessandro Di Federico 1cf9a06009 EnforceABI: use read-only model 2022-08-08 13:55:36 +02:00
Alessandro Di Federico 6a6cd939db Rework EarlyFunctionAnalysis 2022-08-08 13:55:34 +02:00
Alessandro Di Federico 562bb9959d Reimplement GCBI::getBlocksGeneratedByPC
GCBI::getBlocksGeneratedByPC has been reimplemented using recursive
coroutines.  Caching dominator trees was very error-prone.
2022-08-08 13:55:26 +02:00
Alessandro Di Federico 8e358d6609 Introduce additional assertions 2022-08-08 13:54:41 +02:00
Ivan Krysak 65d1a016d4 Standardize concept naming across the codebase 2022-08-05 17:27:56 +03:00
Alessandro Di Federico 6d3a35cf22 EFA: ignore dynamic functions, if static too 2022-06-21 14:17:57 +02:00
Ivan Krysak 7063bb528c Make CFG verification use GenericGraph exporter 2022-06-15 15:51:22 +03:00
Alessandro Di Federico 1764f6120c EFA: update Block.End when appropriate
This change handles the situation in which getLastPC returns an invalid
MetaAddress. This is a new behavior introduces to handle queries on
`llvm::BasicBlock`s whose last PC is ambiguous.
2022-05-06 16:04:22 +02:00
Alessandro Di Federico a4d7e78856 Stop registering Invalid model::Functions 2022-04-29 17:57:49 +02:00
Antonio Frighetto ab4bdf398d EFA: leverage ABI-specific layer
Architecture-agnostic results provided by EarlyFunctionAnalysis
are refined through an ABI-specific layer.
2022-04-15 18:25:11 +02:00
Antonio Frighetto 7235f69a99 EFA: add final results to ABIAnalysis::dump
Output `FinalReturnValuesRegisters` results for aiding debugging tasks.
2022-04-15 18:25:11 +02:00
Antonio Frighetto 276d168e32 Introduce LoadFunctionMetadataPass
LoadFunctionMetadataPass lazily loads a `std::map` from isolated
function MetaAddress to `efa::FunctionMetadata`, and caches it.
2022-04-05 20:50:20 +02:00
Antonio Frighetto 9980fc8c67 EFA: support dynamic function calls
EarlyFunctionAnalysis now can handle calls to
dynamically linked functions.
2022-04-05 15:37:57 +02:00
Antonio Frighetto 499a837aac EFA: take a const model in Analyzer constructor
EarlyFunctionAnalysis now takes a `const TupleTree<model::Binary> &`
as part of `Analyzer` constructor, `finalizeModel` method excepted,
since it needs to write into the model.
2022-04-05 15:37:57 +02:00
Antonio Frighetto d6a1611c0a EFA: full ABI analysis or CFG collection only
EarlyFunctionAnalysis now can be invoked to schedule a full
ABI analysis over the collected functions via `--detect-abi`
option, or it can limit itself to simply recover the CFG and
serialize it onto the LLVM IR via `--collect-cfg` option.
2022-04-05 15:37:57 +02:00
Antonio Frighetto 20cdfe668a EFA: take the control-flow graph out of the model
The control-flow graph and all its hierarchy components
have been moved from `model` to `efa`. The CFG is now
serialized onto the LLVM IR module as a metadata.
2022-04-05 15:37:57 +02:00
Antonio Frighetto 98b79766be EFA: initialize cache by loading from model
The results of the model are loaded into the EarlyFunctionAnalysis
cache, and only those functions which are not in the model have
an EarlyFunctionAnalysis scheduled. The model is updated appropriately.
2022-04-05 15:37:57 +02:00
Antonio Frighetto ddc7fede5a EFA: optimize cross-call site propagation
Take advantage of directly iterating over the call-sites of a
function and perform the cross-call site merge, instead of
iterating over all the functions for each function.
2022-04-05 15:37:57 +02:00
Antonio Frighetto 08b790329a EFA: fix end address of a jump target
EarlyFunctionAnalysis was considering jump targets as part of the
current basic block, thus computing the final address erroneously.
2022-04-05 15:37:57 +02:00
Antonio Frighetto 12d8b1f222 EFA: remove reference template parameter
Code simplification to lighten the syntax.
2022-04-05 15:37:57 +02:00
Antonio Frighetto 31926b7fe1 EFA: fix results on ABIAnalysis::dump method 2022-04-05 15:37:57 +02:00
Antonio Frighetto aae31a3a05 Introduce function entry-points collection passes
The collection of the function entry-points has now been separated
from EarlyFunctionAnalysis into two distinct passes: the first one,
which collects functions which are in call-sites of a direct call,
and the second one which collects code pointers in `.rodata` (e.g.,
function pointers, vtables; jump-tables are possibly skipped).
2022-04-05 15:37:57 +02:00