Commit Graph

50 Commits

Author SHA1 Message Date
Alessandro Di Federico 47c3dd8f0f Drop model::Segment::Sections 2024-05-22 10:25:25 +02:00
Alessandro Di Federico e64eee9402 CodeGenerator: handle partially valid instructions
Sometimes we have instructions that are, say, two bytes long but only
one of the two bytes are invalid (because they end up out of the
segment).
2024-05-15 13:19:42 +02:00
Andrea Gussoni 8125a19379 JumpTargetManager: improve rebuildDispatcher
Improve the way in which we connect the non reachable `JumpTargets` when
rebuilding the dispatcher for non `SemanticsPreserving` `CFGForm`s.

When connecting group of jump targets that are not currently reachable
from the entry dispatcher, we elect the jump target with the lowest
program counter value, as the one to be connected to the dispatcher.
We also mark the jump targets now transitively reachables from the
elected one, as reachable, so to avoid adding other unnecessary edges
from the dispatcher.
2024-01-18 11:06:17 +01:00
Massimo Fioravanti c276a439b5 Add pipeline invalidation
Replace the stub implementation of invalidation with the proper
implementation. A ReadPathCache is added to each global so that it can
keep tracks of what target are associated to which read paths.
2024-01-02 11:14:56 +01:00
Alessandro Di Federico 0e7d3a9a71 Pass PlainMetaAddress by pointer 2023-12-12 10:20:51 +01:00
Alessandro Di Federico 14525d91f5 Adopt llvm::Task 2023-08-01 10:51:16 +02:00
Alessandro Di Federico a24f3479ca JumpTargetManager::readFromPointer: fix unmapped
This commit introduces a fix to correctly handle trying to read from an
unmapped region.
2023-07-26 10:16:25 +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 d0b235c1f4 JTM::findCodePointers: ignore non-aligned data 2023-05-17 11:17:41 +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 da25162d74 JumpTargetManager: drop assertNoUnreachable
The assertion cannot really hold under certain CFG forms.
2023-04-28 14:34:58 +02:00
Alessandro Di Federico 50f396c43d Drop revng.csv in favor of a Tag 2023-04-28 14:04:32 +02:00
Alessandro Di Federico 170749b0aa Introduce revng::verify 2023-04-28 14:04:31 +02:00
Djordje Todorovic c9b2ffaf72 JumpTargetManager: improve data structures
This commit adopts `llvm::DenseSet`, `llvm::DenseMap` and
`std::unordered_set` where needed.
It also tweaks some `llvm::SmallVector` sizes.

It brings an additional ~3% improvement during lifting.
2023-04-27 19:22:03 +02:00
Djordje Todorovic e43fe18021 harvestWithAVI: split up in multiple functions 2023-04-27 19:22:00 +02:00
Djordje Todorovic 3f495d2bc3 harvestWithAVI: run InstCombine only once 2023-04-27 19:16:07 +02:00
Djordje Todorovic 07cd786ec4 Preliminary harvesting: disable InstCombine
Saves up to ~50% of time.
2023-04-27 19:16:07 +02:00
Djordje Todorovic 0604bc4d19 harvestWithAVI: limit InstCombine iterations to 1 2023-04-27 19:16:07 +02:00
Djordje Todorovic 872f14fad4 harvestWithAVI: disable GVN
This commit disables GVN in order to improve lifting performance.

It also increases `EarlyCSEMssaOptCap` so we keep catching all the jump
target we used to.

Lifting /bin/bash goes from ~29mins to ~5mins
2023-04-27 19:16:07 +02:00
Djordje Todorovic 37ab350102 Minor changes 2023-04-27 19:16:07 +02:00
Alessandro Di Federico 40135aad97 Drop CSVAliasAnalysisPass 2023-04-13 18:11:48 +02:00
Alessandro Di Federico 624cf2f160 AVI: add GVN
We should be able to drop this soon.
2023-04-13 18:11:48 +02:00
Alessandro Di Federico 0c991af685 AVI: after function_call, jump to anypc
We used to jump to the dispatcher, however we only sink to an
unreachable `anypc`. We were threfore significantly complicating the CFG
in case of indirect function calls.
2023-04-08 08:42:24 +02:00
Alessandro Di Federico 6564fc0568 Minor changes 2023-04-08 08:42:24 +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 e131817334 Drop usage of Type::getPointerElementType 2023-04-08 08:42:24 +02:00
Alessandro Di Federico 26765f3d84 Drop usages of getBasicBlockList 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
Alessandro Di Federico dbcdad0a4d Switch from llvm::Optional to std::optional 2023-04-08 08:42:24 +02:00
Ivan Krysak 11c0d7f02e Stop using \brief doxygen command 2023-03-15 10:19:01 +01:00
Alessandro Di Federico 09541be398 getUniqueString: do not rely on named metadata
`getUniqueString` returns a dedup'd char array `GlobalVariable` given a
string. We used to rely on named metadata to dedup them. However, this
lead to issues with `LLVMContainer` cloning and linking.

The new implementation uses the name of the variable as the
de-decuplication key, circumventing the problem entirely and improving
performance.
2023-03-13 22:53:44 +01:00
Alessandro Di Federico 54e8393cb8 Minor changes 2023-03-13 22:53:44 +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
Alessandro Di Federico a4f4906ba7 Lift: re-enable InstCombine upon harvesting
InstCombine was disabled in favor of some more basic constant
propagation, but it turns that under certain circumstances this leads to
direct branches appearing as indirect branches until we run InstCombine
during finalization, which triggers an assertion, since we do not expect
any direct jump there.

If this, affects translation performance, we can think to run it less
often.
2023-01-03 13:41:40 +01:00
Massimo Fioravanti 742e1a0c56 TupleTree: switch from public fields to accessors 2022-12-12 18:36:57 +01:00
Alessandro Di Federico 8cf981fbf8 JTM: no assert on indirect jump to invalid address 2022-09-22 17:43:56 +02:00
Alessandro Di Federico 6a6cd939db Rework EarlyFunctionAnalysis 2022-08-08 13:55:34 +02:00
Alessandro Di Federico 4eb70b0e35 Reimplement exitTBCleanup 2022-08-08 13:55:25 +02:00
Alessandro Di Federico b07d134b73 Introduce CanonicalRegisterValues in the model
These canonical values ease certain analysis that can assume their value
at function entry.
2022-08-08 13:55:25 +02:00
Antonio Frighetto dad721941e JTM: set symbol name to OriginalName in newpc 2022-04-05 15:37:57 +02:00
Alessandro Di Federico 0793e4afcb Turn lifting into a pass 2022-03-11 15:37:12 +01:00
Alessandro Di Federico ee0b8f44c1 Introduce BinaryImporter
This is a big step to split revng-lift in two parts: one that only
writes the model and one that actually lifts to LLVM IR.

* Introduce `revng import binary`
* Split off `BinaryFile.h`
* Drop `revng.h`
* `GeneratedCodeBasicInfo`: use model
* Reduce role of `GeneratedCodeBasicInfo` in favor of
  `model::Architecture` and `model::Register` methods
* `CodeGenerator`: adopt `RawBinaryView` and model
* `JumpTargetManager`: adopt `RawBinaryView` and model
* `ExternalJumpsHandler`: adopt model
* `InstructionTranslator`: discard `Architecture` in favor of
  `EndianessMismatch`
* Many other changes
2022-03-08 15:15:24 +01:00
Alessandro Di Federico 0a5d2c04a7 Rework LoadModelPass 2022-03-08 15:04:34 +01:00
Alessandro Di Federico 1cd17a13e8 readFromPointer: use bool IsLittleEndian 2022-03-08 12:25:47 +01:00
Alessandro Di Federico 7c515ff997 Use std::string for MaterializedValue::SymbolName 2022-03-08 12:25:35 +01:00
Alessandro Di Federico cfb47157b9 clang-tidy: readability-identifier-naming
This commit fixes all the non-compliance with our preliminary clang-tidy
configuration, which will be merged soon.
2022-01-07 09:18:05 +01:00
Massimo Fioravanti 9e477d0ada Make a library out of revng-lift 2021-12-22 13:47:21 +01:00