Commit Graph

3168 Commits

Author SHA1 Message Date
Andrea Gussoni 6b5b2ee5f5 InlineDispatcherSwitch: do not inline non local CF
Do not inline loop related `break` and `continue` statements.
Indeed, inlining them would mean moving from the scope of a cycle, to an
inner one, non-local control flow statements, and this would break the
semantics.
2024-05-07 14:16:45 +02:00
Andrea Gussoni e926a80e1c InlineDispatcherSwitch: remove non-exercised code 2024-05-07 14:01:56 +02:00
Andrea Gussoni 67e7b54eda BeautifyGHAST: reorder SwitchBreaksFixer pass
Delay the `SwitchBreaksFixer` beautify pass run.
Specifically, we run it last, as this pass computes information used
only by the backend, and the information it depends upon may be
invalidated by some passes that transform `switch`es (as the
`simplifyDualSwitch` pass).
2024-05-07 09:18:20 +02:00
Andrea Gussoni 0fb60b5c0c BeautifyGHAST: remove unused using 2024-05-07 09:18:20 +02:00
Alessandro Di Federico 31344a3270 Add missing includes 2024-05-03 21:55:33 +02:00
Alessandro Di Federico bf6cefc05a Externalize functions to improve build times 2024-05-03 21:52:40 +02:00
Alessandro Di Federico fe1dffcffd Add some missing includes
This is in preparation of reducing headers in Debug.h.
2024-05-03 21:52:40 +02:00
Andrea Gussoni 1590d96381 SimplifyDualSwitch: Fix two case switch
Fix the promotion logic to not promote standard `switch`es with two
`case`s and no `default` (or the semantics will be corrupted).
2024-05-03 07:40:38 +02:00
Alessandro Di Federico 452036edf1 Purge instructions to save return address 2024-04-30 15:25:53 +02:00
Alessandro Di Federico 0459b9d084 Introduce RegisterUsageAnalyses 2024-04-19 18:33:00 +02:00
Alessandro Di Federico 9d12cd35e3 DwarfImporter: improve logging 2024-04-19 18:33:00 +02:00
Alessandro Di Federico 58d965f977 DwarfImporter::getName: consider abstract_origin 2024-04-19 18:33:00 +02:00
Alessandro Di Federico fcd04c163b DwarfImporter: hack to handle transparent unions 2024-04-19 18:33:00 +02:00
Alessandro Di Federico 2267b51090 Mark findPrototype as inline 2024-04-19 18:33:00 +02:00
Alessandro Di Federico ba65443293 DetectABI call graph: no multiple identical edges 2024-04-18 17:55:22 +02:00
Alessandro Di Federico dcfb4621a7 Improve GenericGraph::verify 2024-04-18 17:50:33 +02:00
Alessandro Di Federico a1f3624b21 TraceProgressListener: flush upon signal 2024-04-18 17:50:33 +02:00
Alessandro Di Federico dae9f33544 Minor changes 2024-04-18 17:50:31 +02:00
Alessandro Di Federico 9bbf1cc144 DwarfImporter: renumber UnionFields after cleanup 2024-04-11 15:29:39 +02:00
Alessandro Di Federico 53f0c71d3b FunctionMetadata::dumpCFG: dump to file 2024-04-05 13:29:15 +02:00
Alessandro Di Federico dda484d642 FunctionMetadata::simplify: use .nextBlock()
Before we were using `.End()` which lead to lose the inlining index.
2024-04-05 13:28:31 +02:00
Andrea Gussoni f05723707f BeautifyGHAST: delay loop promotion passes
Delay as much as possible the loop promotion passes, in order to catch
more opportunities.

Specifically, we now perform the loop promotion after the dual case
`switch` promotion pass.
2024-03-26 17:08:20 +01:00
Pietro Fezzardi 8b0f4e035c RestructureCFG: update deduplicated dummy nodes
Before this commit, it could happen that some duplicated dummy node
(used to mark backedges) could be left lingering in wrong regions when
collapsing a regions, if they were first iteration outlined.

This commit fixes the problem, by collecting them and letting
`updateNodes` take care of them, removing them from the containing
region and all its parents.
2024-03-25 18:08:35 +01:00
Pietro Fezzardi 454e38e4ff RestructureCFG: handle retreating from SetNodes 2024-03-25 18:08:35 +01:00
Pietro Fezzardi 4baff26fca SwitchToStatements: handle self-assignments 2024-03-25 18:08:35 +01:00
Pietro Fezzardi b50aca6a15 MergePointeesOfPointerUnion: improve Model types
Before this commit, the DLAStep MergePointeesOfPointerUnion wasn't
really equipped for dealing with LayoutTypeSystemNodes representing
types imported from Model.
There was some code that tried to deal with them but it was mostly an
afterthought and it wasn't robust.

This commit fixes that, and is able to handle a strict superset of the
scenarios envisioned before, while preserving the property that nodes
representing types imported from Model should be preserved (in
particular their size).
2024-03-21 11:51:10 +01:00
Pietro Fezzardi d84f099af7 RestructureCFG: fix iterator invalidation 2024-03-19 17:46:32 +01:00
Pietro Fezzardi e58531b88d RestructureCFG: flush logger 2024-03-19 17:46:32 +01:00
Pietro Fezzardi f0619b08eb MakeModelGEP: simplify ModelGEPs LLVM Types
Now ModelGEPs emitted by MakeModelGEP always forward the LLVM Type of
the operand representing the base address.

Before this commit they were occasionally using an integer type with the
size of the underlying `model::QualifiedType`, but that is not necessary
and may end up requiring `llvm::IntegerType`s that are very large, to
the point of not being supported by LLVM, for no additional advantage.
2024-03-19 17:46:32 +01:00
Pietro Fezzardi d9b0a118ef SegregateStackAccessesPass: drop unused AssignPool 2024-03-19 17:46:32 +01:00
Pietro Fezzardi 4531b9ff5d InitModelTypes: fix IntToPtr
Before this commit, initModelTypes could return integers of the wrong
size for IntToPtrInst, whenever the integer being casted to pointer did
not have the exact same size of the pointer on the model.

This commit fixes the problem. Now initModelTypes, even if it might be
forced to return an integer type for IntToPtr, it makes sure that the
size of that integer matches the size of the pointer on the model.
2024-03-19 09:44:00 +01:00
Pietro Fezzardi 132adeecd5 Add PeepholeOptimization pass
This pass is dedicated to applying a bunch of peephole optimizations
that are useful for decompilation and haven't been implemented in LLVM
for whatever reason.

At the moment it only runs an optimization that tries to reduce the uses
of incoming values of PHINodes, under very specific condidtions, which
enables emitting less LocalVariables.
2024-03-19 09:44:00 +01:00
Pietro Fezzardi 37340a91a7 Don't skip non-isolated Function in FunctionPass
Before this commit, many passes in revng-c were skipping over
non-isolated functions.

Now revng-pipeline takes care of removing non-isolated functions so that
check can be omitted everywhere.
2024-03-19 09:44:00 +01:00
Pietro Fezzardi 70c8ae48ff Retire MarkAssignment for SwitchToStatements 2024-03-19 09:44:00 +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
Pietro Fezzardi ed88c6b459 Use LLVM MemoryEffects in hasSideEffects 2024-03-19 09:44:00 +01:00
Pietro Fezzardi 206936f1c0 Drop redunant ReadsMemory and WritesMemory Tags
Over time, these tags have shifted to basically coincide with the Copy
and Assign tags. There's no need for them anymore they just make the
code more verbose and less straightforward.
2024-03-19 09:44:00 +01:00
Pietro Fezzardi 83d56fb40b Update hasSideEffects helper function
Before this commit the `hasSideEffects` helper function was only a stub,
that was never updated to be aware of recent FunctionTags representing
custom opcodes without side-effects.

This commit updates it, so that now it is less aggressive in marking
harmless stuff as side-effectful.
2024-03-19 09:44:00 +01:00
Pietro Fezzardi 76739c2811 ExitSSA: better placement for StoreInst
This commits changes the ExitSSAPass to ensure that StoreInst are placed
ASAP, close to the computation of the incoming Values of the replaced
PHINode.
This generates IR that typically yields less local variables in
SwitchToStatements.
2024-03-19 09:44:00 +01:00
Pietro Fezzardi 6b022c9d30 Make ExitSSA deterministic 2024-03-19 09:44:00 +01:00
Pietro Fezzardi 847cad3422 MakeSegmentRef: fix checks on pointer size 2024-03-19 09:44:00 +01:00
Pietro Fezzardi df3bd470a1 Enforce determinism on CSV handling
Various parts of revng replace `llvm::GlobalVariable`s representing CSVs
with Allocal/Load/Store. In particular, these are PromoteCSV,
RootAnalyzer and PromoteGlobalToLocalVars.

Before this commit, those places were sloppy when replacing CSVs with
Alloca/Load/Store, and did that iterating on a container sorted by
pointers. This caused Alloca/Load/Store to be emitted in different order
accross runs, which in turn caused more non-determinism down the
pipeline.

This commit fixes the non-deterministic behavior, sorting CSVs based on
their names, which should always be present and deterministic.
2024-03-19 09:43:59 +01:00
Pietro Fezzardi 1baec8ff7b Drop old MonotoneFramework 2024-03-19 09:43:59 +01:00
Ivan Krysak 89b454a224 EFA: improve robustness against non-existent FSO 2024-03-18 19:32:35 +01:00
Ivan Krysak 0692ef0828 Doxygen: be extra explicit about layout usage 2024-03-18 19:32:34 +01:00
Ivan Krysak d1d97fe47e PTML: fix doxygen stack indication 2024-03-18 19:32:34 +01:00
Ivan Krysak 6b7650276e EFA: split importModel into multiple methods 2024-03-18 19:32:34 +01:00
Ivan Krysak 5afba1382c EFA: update clobbered register list computation 2024-03-18 19:32:34 +01:00
Ivan Krysak 7e08c341e9 EFA: update preserved register diffing 2024-03-18 19:32:34 +01:00
Ivan Krysak 2aad45f452 EFA: reorder prototype-based summary importer
This lets up cleanly "bail out" after only some of the computation
is done. This way we avoid reading information we don't really use
from the model based on who is the specific user of the oracle.
2024-03-18 19:32:34 +01:00