Commit Graph

2366 Commits

Author SHA1 Message Date
Alessandro Di Federico d83eca0902 Use ConstantExpr::isCast()
Simplify `getConstValue` in `IRHelpers.h` to use `ConstantExpr::isCast`.
2020-05-14 11:58:18 +02:00
Alessandro Di Federico 8deab9c7ea Whitespace and other minor changes
* Drop unused argument names from function prototypes
* Make `static` some methods
* Disable some copy constructors
* Fix casing of Doxygen `\file` directives
* Add some casts to make the compiler happy
* Initialize `hasRelocationAddend` for AArch64
* Use references in range-for where possible
* Drop default for `switch` statements covering all the entries of an `enum`
* Make some global variables `static`
* Drop dead functions
2020-05-14 11:58:18 +02:00
Pietro Fezzardi 2d7463f190 Fix C++ Standard includes in ReachabilityPass 2020-03-11 14:36:21 +01:00
Pietro Fezzardi 98c1c38b55 RegionCFGTree: drop old TransformIterators
They have been dropped from rev.ng, and substituted with
llvm::mapped_iterators which serve the sames goals.
2020-03-03 01:17:20 +01:00
Pietro Fezzardi 5d0f5fef71 Drop TransformIterator
LLVM already implements an analogous `mapped_iterator` type in
`STLExtras.h` header.  `llvm::mapped_iterator` has been used to
substitute `TransformIterator` in the project so that we don't need to
reinvent the wheel.
2020-02-27 12:28:28 +01:00
Alain Carlucci 469ef9cae8 Rename emit to flush in Debug.h
The `emit` keyword is used in Qt and, if the method is called `emit`,
rev.ng headers cannot be included in a Qt project.
2020-02-27 12:12:25 +01:00
Pietro Fezzardi 890be7d6a2 Uniform dumpToString interface
Before this commit, the `dumpToString()` function defined in
`include/revng/Support/IRHelpers.h` was only defined with arguments of
type `const llvm::Module *` and `const llvm::Value *`.
This is not very ergonomic, because lots of types in LLVM have a
`print()` method that dumps the representation on a
`llvm::raw_ostream``.

This commit introduces function templates to handle all possible types
in LLVM that have a method `void print(llvm::raw_ostream &)`.

The templates are defined so that they should work with every possible
combination of references and pointer types, along with const
qualifiers.

To achieve this, the code makes use of `std::enable_if`` to provide
different definitions of the `dumpToString()` template helper function,
which only participate in overload resolution for specific types:
1. for `llvm::Module` and `llvm::Function`, which share the same
prototype for the `print()` method
2. for `llvm::Value` which has yet another prototype for the `print()`
method
3. for all other types that provide a method with the signature
`void print(llvm::raw_ostream &)`.

The last implementation (3) also works for all non-LLVM types provide a
method with the signature `void print(llvm::raw_ostream &)`.
In this sense, if in the future we want our own type to be easily dumped
to string (handy for logging), we can just implement the method
`void print(llvm::raw_ostream &)` and the `dumpToString()` function
template added in this commit will work out ot the box.
2020-02-27 11:55:09 +01:00
Andrea Gussoni 0c05c0c75b AVI: handle ConstantPointerNull and UndefValue
Handle `ConstantPointerNull` explicitly in Advanced Value Info, instead
of trying to obtain the analysis result for its operand (which is by
design a `nullptr`).
2020-02-27 11:55:09 +01:00
Pietro Fezzardi 433ce5613b Drop old useless header MemoryAccess.h
This was a leftover from the OSRA era.
2020-02-27 10:48:17 +01:00
Pietro Fezzardi ae948500eb Move LLVM header where it's really needed
Before this commit, the header `revng/Support/DebugHelper.h` could only
be included after explicitly including
`llvm/IR/AssemblyAnnotationWriter.h`, since `DebugHelper.h` used the
LLVM class `AssemblyAnnotationWriter`, that is not defined in
`DebugHelper.h`.

This commit includes `llvm/IR/AssemblyAnnotationWriter.h` directly into
`revng/Support/DebugHelper.h`, which can now be included alone without
compilation errors.
2020-02-27 10:47:07 +01:00
Pietro Fezzardi 58428bdd4a IteratorWrapper: use implicit copy constructor 2020-01-27 11:29:01 +01:00
Pietro Fezzardi 67e762d668 Add breaks to switch to remove warnings 2020-01-27 11:29:01 +01:00
Pietro Fezzardi c3a6a09f11 Upgrade to llvm-9 2020-01-15 18:24:28 +01:00
Pietro Fezzardi 2feaa47737 Fix use of boost unit_test_framework
This commit does three things.
- Removes explicit dependency from boost version 1.63. This is no longer
  necessary since orchestra has moved to compiling boost test directly,
  and ships version 1.71 (as of now).
- Switches UnitTests.cmake to using modern cmake package for
  Boost::unit_test_framework
- Adds an header copied from revng, to define
    boost::throw_exception(std::exception const &E)
  This is necessary to compile with -fno-exception and boost
  unit_test_framework.
2020-01-15 18:23:41 +01:00
Andrea Gussoni 86f35b6d93 Various Untangle improvements
Introduced various untangle algorithm improvements:
- Improve untangle edge reorganization: improve the criterion used for
  reorganizing the edges between the old postdominator and the cloned
  one, after an inline procedure is attempted during the untangle.
- Untangle counter: introduce two new counters which take into account
  the number of times the untangle procedure is attempted and the actual
  times it is performed.
- Disable not dominated restriction: disable the criterion which
  restricts the untangle opportunities if we do not dominate entirely
  at least one of the two branches. This has likely broken the
  assumption that the postdominators of nodes do not changes after each
  untangle step has been carried out.
- Change dominance criterion: the dominance of the nodes belonging to
  the `then` and `else` nodes is now checked not with respect to the
  conditional node, but to the `then` and `else` edges of the conditional
  node.
- Untangle eager inlining: now, when the untangle procedure finds a
  suitable candidate for the inlining, proceed the complete inlining
  starting from the selected branch. By default new clones of all the
  nodes till the exit are created and attached to the branch, while the
  original nodes are detached. An additional pass which removes eventual
  dandling nodes (nodes which are not reachable from the entry node of
  the graph) is performed after the eager inlining. This means that if
  no other incoming edges to this group of nodes is present the original
  nodes will be purged.
  The post dominator now is updated during the inlining analysis, and
  the paths conducting to inlined exits are not taken into account for
  the post dominator computation.
- Enable untangle for mixed branches: perform the untangle even if the
  `then` and `else` branches share nodes. This was not feasible before
  because without the eager inlining we couldn't decide which edge to
  attach to the new postdominator clone. This problem is not present
  anymore, so we can handle any kind of topology in the untangle.
- Improved also the analysis information serialized by the decompiler.
2020-01-13 12:13:42 +01:00
Andrea Gussoni f0bedc973e Improve graph weight computation
Improve the duplication weight computation with the percentage increase.
2020-01-13 11:57:04 +01:00
Andrea Gussoni 30bc1d333e Decompile a single function
Add a flag to enable the decompilation of a single function.
In order to have a single flag shared between the `RestructureCFGPass`
and the `CDecompilerPass`, we added a new dedicated decompilation unit
called `TargetFunctionOption`.
2020-01-13 11:55:32 +01:00
Pietro Fezzardi 76404c8fd1 Prevent Logger::emit to clash with Qt emit keyword
This commits make the use of Loggers in revng-c more idiomatic, while
removing calls to the method, which clashes with the Qt emit keyword.

This is important, because this clash prevents integration of revng-c
into the GUI, which is written in Qt.
2020-01-09 17:44:04 +01:00
Alessandro Di Federico b6658df052 Fix various warnings 2019-11-24 22:52:23 +01:00
Alessandro Di Federico 72f9c633d4 Make ConstantRangeSet LLVM 9-compliant
A `ConstantRange` such as `[5,0)` was not handled correctly in
`ConstantRangeSet` due to a spurious 0 at the end of the range.

This commit also fixes the testing infrastructure that was not checking
the size of the range before making the comparison with the reference
vector.
2019-11-21 23:50:59 +01:00
Alessandro Di Federico 0eb1bb583f Remove TerminatorInst
LLVM 9 drops the `TerminatorInst` class. This commit replaces it with
`Instruction` where possible and asserts
`Instruction::isTerminator()`. It also switches from
`TerminatorInst::successors` to `successors(TerminatorInst *)`.
2019-11-21 20:50:55 +01:00
Alessandro Di Federico 3818a4fcc6 Drop ConstantRange::ConstantRange
LLVM 9 prevents us from using the `ConstantRange` constructor. This
commit switches to use factory methods.
2019-11-21 20:50:03 +01:00
Andrea Gussoni de70a09c7a Fix gcc warnings related to default switch case 2019-11-20 15:16:17 +01:00
Pietro Fezzardi c6c6f19535 Enforce check-conventions 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 429233f054 Fix more warnings left from -Weverything 2019-11-20 15:16:17 +01:00
Andrea Gussoni 3a830f532d Fix debug dots directory creation 2019-11-20 15:16:17 +01:00
Andrea Gussoni 335dc34ad1 Fix -Wshadow 2019-11-20 15:16:17 +01:00
Andrea Gussoni 46265f6eaf Fix -Wextra-semi 2019-11-20 15:16:17 +01:00
Andrea Gussoni 8255661b8b Fix BasicBlockNodeBB in ASTNode namespace 2019-11-20 15:16:17 +01:00
Pietro Fezzardi f95899c7ac Fix LLVM-style RTTI destruction for ASTNode 2019-11-20 15:16:17 +01:00
Pietro Fezzardi cb58b8a526 Fix destruction of ExprNodes class hierarchy
`ExprNode` and its child classes use LLVM-style RTTI.

Until now their destruction was not handled properly, causing the
constructor-destructor type mismatch warnings on ASAN.
Despite this all the code was working properly, but just for luck,
because of the fact that these classes are very shallow.

This commit fixes the issue, and allow `ExprNode` and its child classes
to be extended without worrying about wrong destructors being invoked.
2019-11-20 15:16:17 +01:00
Pietro Fezzardi 81a1c9c1e1 Remove Liveness again 2019-11-20 15:16:17 +01:00
Andrea Gussoni b0c191f188 Fix path for dot files for debug 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 5fe551a188 Fix destructors and warnings for ExprNodes 2019-11-20 15:16:17 +01:00
Andrea Gussoni b214dd1921 Enforce check-conventions.sh
Replicate this commit 72f836d30079c191d1c30e185114c4c0a0f914df made by
Pietro.
2019-11-20 15:16:17 +01:00
Andrea Gussoni 560a345a2c Enforce -Weverything extensively
Replicate the changes made by this commit
f2a0df309f78e1b5d7c5f81ada5110523644559e perfomed by Pietro on the
branch containing the development fixes for `revng-c`.
2019-11-20 15:16:17 +01:00
Andrea Gussoni 7cae83a3bb Template instance declaration for -Weverything
Add new headers files (terminating with `BB`, as `BasicBlockNodeBB.h`),
which will be used as the new header files by the users, and which
contain a declaration of the template instantiation, and a `using`
aliasing the instantiation.

This has been made to comply with the `-Wundefined-func-template` flag,
automatically enabled when using `-Weverything`
2019-11-20 15:16:17 +01:00
Pietro Fezzardi 812708de96 Remove virtual calls from ASTNodes 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 02ea1e5f94 Fix warnings emerged with -Wextra and -Weverything 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 569ec5658e Add and enforce -Wall and -Werror 2019-11-20 15:16:14 +01:00
Andrea Gussoni fdda9fdd70 Collect metrics about duplication
Collect the metrics regarding duplication during the combing pass, and
output them in `.csv` format.
2019-07-30 18:24:16 +02:00
Andrea Gussoni 8eb5abaaeb Fix emission computation for continue nodes
Added a new attribute for the `ContinueNode`, which tells if a
`ContinueNode` should be considered implicit. An implicit continue node
means that it can be dropped without it altering the semantics of the
code (e.g., when the `continue` is the last statement inside the body of
a cycle).

This attribute enables us to avoid directly dropping the continue node,
which would also cause the computation attached to this node to be
dropped, also in the output of the decompiler pass.
2019-07-30 18:20:06 +02:00
Alessandro Di Federico e445201b94 Restore getBasicBlockPC and fix FunctionIsolation
This commit restores the old implementation of `getBasicBlockPC` (which
was changed in an incompatible and wrong way) and fixes the bug the
original change tried to fix: in function isolation, jumping from a
function to a basic block that doesn't start with `newpc` now leads to a
basic block containing an `unreachable`.
2019-05-28 17:03:30 +02:00
Alessandro Di Federico b9ef70c8dc AdvancedValueInfo: handle pointer types 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 877ba895af Rewrite get{BasicBlockPC,PrevPCWrite}
This commit reimplements `getBasicBlockPC` and `getPrevPCWrite` using
`BackwardBFSVisitor`, making them much more effective.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico d0e5f61b20 CSAA: allow recursion in untainted paths 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 7815c551db Support for file names in Logger
`Logger` can now print the file name from which it was called
(`--debug-location-max-length`).
2019-05-27 19:36:12 +02:00
Andrea Gussoni dd772f5f5f Enhance findReachableNodes algorithm
Enhanced the `findReachableNodes` algorithm, with a new `StackSet`
parallel data structure which is used to quickly check if we are
encountering a node already on the visit stack.

Modified the `findReachableNodes` to include in the returned set of
nodes also nodes which are encountered on self loop paths and that
should consequently be included in this set.
2019-05-24 18:35:52 +02:00
Andrea Gussoni ac34e38b2f New merge criterion for SCS regions
The new SCS merging criterion, checks that there are no abnormal
retreating nodes between SCS, meaning retreatings which exit from the
current SCS and do not point to the head of another SCS.

This kind of situation, if ignored could cause the introduction of some
cycles between outlined nodes and existing nodes, inserting new cycles
during the restructuring, which is a behavior which we aim to avoid.
2019-05-24 18:35:45 +02:00
Andrea Gussoni ead83260d6 Outlined nodes inserted in parent metaregions
When outlining nodes, we now include them in eventual parent metaregions
that included the nodes collapsed.

This should lead to minor duplication (as in the `cp` benchmark), since
we avoid duplicating two times nodes if also the external region causes
the first iteration outlining.
2019-05-24 16:10:02 +02:00