Commit Graph

326 Commits

Author SHA1 Message Date
Alvise de Faveri 2ffa537605 IRCanonicalization: Add Copy()
Use the `Copy` opcode to substitute load instructiobs.
2022-06-28 10:28:38 +02:00
Alvise de Faveri 6b258c83a1 IRCanonicalization: Fold ModelGEP(AddressOf())
- `FoldModelGEP` folds `ModelGEP(AddressOf())` into `ModelGEPRef`
- `RemoveRefDeref` remove `ModelGEPRef`s with no arguments
2022-06-28 10:26:50 +02:00
Alvise de Faveri 123a1777cd IRCanonicalization: Add RemoveLoadStore pass 2022-06-28 10:25:49 +02:00
Alvise de Faveri f7866ddd85 IRCanonicalization: Add MakeLocalVariables pass 2022-06-28 10:24:48 +02:00
Alvise de Faveri ad524a4d4d ModelGEP: Return the size of the gepped field
ModelGEP calls in LLVM IR now return an integer that has the same
size of the field being addressed by the ModelGEP.

AddressOf calls, instead, can accept any integer size as argument but
always return a pointer-sized integer.
2022-06-28 10:14:10 +02:00
Alvise de Faveri fa68b56573 Add ReadsMemory and WritesMemory Tags
Add `ReadsMemory` and `WritesMemory` Tags and restructure the
logic that decides whether two instructions are interfering
as follows:

1. Consider `Store`s and anything with a `WritesMemory` tag as
   having side effects
2. Consider all the `TaintSet` of an instruction when deciding
   if two instructions interfere
3. Consider both `ReadsMemory` and `WritesMemory` Tags when
   deciding interference
2022-06-28 10:11:06 +02:00
Alvise de Faveri e05972bd88 Make ref opcodes ReadOnly and InaccessibleMem
Add `ReadOnly` and `InaccessibleMemOnly` attributes to the following
functions:

- `revng_stack_frame`
- `revng_call_stack_arguments`
- `ModelGEP`
- `AddressOf`

This prevents `CSE` from grouping together any of these calls, while
still enabling `DCE` to remove calls that are not used.
2022-06-23 11:23:34 +02:00
Antonio Frighetto cd65fd1554 Introduce OperatorPrecedenceResolutionPass
A simple pass that maps LLVM IR instructions to C operators,
taking into account their precedence and associativity to
emit nice-looking parenthesized expressions.
2022-06-15 10:28:50 +02:00
Antonio Frighetto 4a045cce53 Introduce MakeModelCastPass
A pass that strips the casts off from some instructions, including
`ModelGEP`s, general function calls, return and store ones, and
embeds the cast into new dedicated `ModelCast` function calls.
2022-06-15 10:28:50 +02:00
Pietro Fezzardi ad81bc7020 Enable addtional compilation warnings
These warnings are not enabled by default with -Wall nor with -Wextra.
2022-06-14 12:48:54 +02:00
Alvise de Faveri 66e077fdcb Support: Fix dropPointer() 2022-06-13 15:21:49 +02:00
Alvise de Faveri 7f37a22b5d Support: Improve peelConstAndTypedefs constness 2022-06-01 11:21:02 +02:00
Alvise de Faveri e9fcdc3f2a Support: Convert LLVM types as generic types 2022-06-01 11:09:15 +02:00
Alvise de Faveri c7264badae Support: Add serializeToLLVMString(QualifiedT) 2022-06-01 11:08:29 +02:00
Alvise de Faveri 189fbe4651 Support: Fix the key for OpaqueExtractValue pool
Calls to `OpaqueExtractValue()` are meant to replace `extractvalue`s
found in the LLVM IR. Since the type of an `OpaqueExtractValue` is
identified by both the return type (extracted value) and the first
argument's type (aggregate operand of the `extractvalue` instruction),
we need to consider both when building the associated FunctionPool.

Previously, we were identifying each `OpaqueExtractValue` variant using
only the returned value, which was wrong. In fact, if we have two
`extractvalue` instructions that extract a value of the same type
(e.g. i32) from two different aggregate types (e.g. structA and
structB), we have to define two different `OpaqueExtractValue`: one
that returns an i32 and has a parameter of type structA, and one that
returns an i32 and has a parameter of structB. If we use only the
return type, we are not able to distinguish the two.
2022-06-01 11:05:31 +02:00
Pietro Fezzardi 4ed636cbba Support emission in C of null pointers 2022-05-31 12:40:52 +02:00
Pietro Fezzardi 97f0f8c521 IRHelpers: add deleteOnlyBody helper 2022-05-11 15:19:34 +02:00
Pietro Fezzardi 238b98c3da Switch all revng-c to revng-pipeline 2022-05-11 12:42:38 +02:00
Alessandro Di Federico 9fcdc3393a getLastNewPC: return nullptr when ambiguous 2022-05-06 16:04:22 +02:00
Alessandro Di Federico 0f3c29fa1b Split moveToNewFunctionType off changeFunctionType 2022-04-29 17:57:49 +02:00
Giacomo Vercesi 168eab6cc5 Use /proc/self/maps to determine root
Use the path of the mapped librevngSupport.so to determine the root
directory.
2022-04-28 22:18:08 +02:00
Giacomo Vercesi 91067a8886 getCurrentExecutableFullPath: assert on error
`getCurrentExecutableFullPath` now aborts if it cannot determine the
real path instead of returning an empty string.
2022-04-28 22:10:14 +02:00
Giacomo Vercesi d109a68bc4 Remove BUILD_PATH
It has not been relevant for a long time.
2022-04-28 22:10:02 +02:00
Pietro Fezzardi b909bb6629 New MarkAssignments library in IRCanonicalization
This library replaces the old AddIRSerializationMarkers, cleaning up a
lot of historcal baggage, merging Liveness and MarkAnalysis, and
adopting a more accurate naming across all the codebase.
2022-04-21 18:13:51 +02:00
Alvise de Faveri 96074c7938 ModelHelpers: Make dropPointer recursive 2022-04-20 17:35:05 +02:00
Alvise de Faveri 827d5605f4 llvmIntToModelType: Handle nested pointer types 2022-04-20 17:35:05 +02:00
Giacomo Vercesi ab125b35b0 Fix License headers
Change company name to "rev.ng Labs Srl" in all license headers
to reflect changed company name and legal status
Add missing license headers to files that didn't have one
2022-04-19 12:17:59 +02:00
Alessandro Di Federico f6c9b04c81 Adopt clang-tidy: readability-identifier-naming 2022-04-04 21:15:52 +02:00
Alessandro Di Federico 1a2a729e92 Rework FunctionTags::Tag 2022-03-31 12:51:24 +02:00
Alvise de Faveri 8230d91da7 Add RemoveExtractValues and RestoreExtractValues
* RemoveExtractValues transforms every `extractvalue` instruction
  into an opaque call. This prevents the optimization pipeline from
  moving around and optimizing `extractvalue`s, since they have a
  particular meaning in our IR
* RestoreExtractValues transforms such opaque calls back to regular
  `extractvalue`s at the end of the pipeline
2022-03-31 10:49:13 +02:00
Pietro Fezzardi ddf6c23be6 Migrate AddressOf to OpaqueFunctionsPool 2022-03-31 10:36:57 +02:00
Massimo Fioravanti b2dfd2bc64 TupleTreeGenerator.cmake: single call generation 2022-03-28 12:17:05 +02:00
Alvise de Faveri 4d7e41e62a Add model type helpers to ModelHelpers 2022-03-22 10:55:11 +01:00
Alvise de Faveri 68a4665ea1 Handle markers in getExtractedValuesFromInst() 2022-03-22 10:50:45 +01:00
Alessandro Di Federico 1dcce82dfc Adopt cmake-format 2022-03-18 12:32:44 +01:00
Alessandro Di Federico 2b55d1df22 Adopt cmake-format 2022-03-17 18:52:18 +01:00
Giacomo Vercesi e237ee75b0 Add custom traceback support 2022-03-17 18:33:59 +01:00
Pietro Fezzardi c41ca3a451 New revng helpers for Qualifier and QualifiedType 2022-03-17 17:15:50 +01:00
Alessandro Di Federico 00ce580362 Introduce EnforceABI and PromoteCSV pipes 2022-03-17 14:10:50 +01:00
Alessandro Di Federico fa3206b26d Rename Lifted tag to Isolated 2022-03-17 14:10:50 +01:00
Alessandro Di Federico da7701bd4e Move all executables except revng to libexec/revng
We used to collect all binaries into the `bin/` directory. However this
led to confusions since certain commands where available both as
`revng-command` and `revng command`.

This commit moves all the executables except `revng` into
`libexec/revng`, which, according to FHS, is dedicated to "internal
binaries that are not intended to be executed directly by users or shell
scripts".
2022-03-17 14:10:50 +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
Alvise de Faveri 4e5026c368 Add ReadNone attribute to revng intrinsics
In order to enable the optimizer to strip dead calls, ModelGEP,
 SerializationMarker and AddressOf functions are marked as
 `ReadNone` instead of `InaccessibleMemOnly`.
2022-03-02 11:46:42 +01:00
Pietro Fezzardi cd240e1bdb lib/Support link with revngModel 2022-02-28 18:04:43 +01:00
Pietro Fezzardi 5cdc63cda6 Apply new revng coding conventions 2022-02-28 18:02:25 +01:00
Alvise de Faveri 73c743597b Pull out DepGraph and naming from ModelToHeader
Separate `ModelToHeader.cpp` into 3 different files:

1. DependencyGraph, used to calculate the precedence between
   type declarations
2. ModelTypeNames, that holds all the naming logic, whose
   primitives are accessible from other modules through a
   public header
3. ModelToHeader, that now contains only the logic to print
   out declarations and definitions

Also add a compilation test for the headers generated by this pass.
2022-02-10 17:12:56 +01:00
Massimo Fioravanti afbebaf531 ProgramRunner: fix misuse of executable path
ProgramRunner was using garbage data instead of correctly using the path
to the current executable directory.
2022-01-17 18:17:54 +01:00
Massimo Fioravanti 6421aeed3e Support: depend on generated model headers
renvg.h should not use model headers, however, currently it does. This,
combined with the fact that the revngSupport library did not depend on
revngModel or the header generation led to non-deterministic build
failures.

Before this commit the bug can be found by:

    orc clean revng
    orc uninstall revng
    orc configure revng
    orc shell -c revng ninja renvgSupport

The error should manifest itself as some generated headers missing.

The proper fix would be to rewrite revng.h so that it does not uses the
model.
2022-01-17 18:17:45 +01:00
Pietro Fezzardi 9e498f8b02 MakeModelGEP: switch to reference semantics 2022-01-14 14:29:57 +01:00
Pietro Fezzardi 9a27131303 Add argument to SerializationMarker functions
This commit adds a second argument to functions in the family of
SerializationMarker. The second argument is a boolean.
If it's true, it represents the information that the marked
llvm::Instruction was marked because it had side effects.
This information is necessary for various beautification tasks on the
GHAST, and we want it on the IR in order to be able to switch away from
the old MarkForSerializationPass.
2022-01-14 14:29:35 +01:00