Commit Graph

6113 Commits

Author SHA1 Message Date
Alessandro Di Federico 54ea92cfec Introduce GCBI::programCounterHandler 2020-12-31 14:37:53 +01:00
Alessandro Di Federico d3247870f0 Reorganize ProgramCounterHandler construction 2020-12-31 14:37:53 +01:00
Alessandro Di Federico a153dc3f7a ProgramCounterHandler.cpp: drop unnecessary llvm:: 2020-12-31 14:17:30 +01:00
Alessandro Di Federico 4c4e427a4a Make ProgramCounterHandler implementations private 2020-12-31 14:17:30 +01:00
Antonio Frighetto 02b3a24463 Jump to dispatcher when location is invalid
Replace a call to `abort` with a branch to `dispatcher` when the
callee is unknown or invalid (namely, it is always treated as an
indirect call).
2020-12-31 14:17:30 +01:00
Pietro Fezzardi e1b283b0b6 Add RecursiveCoroutine headers and tests
RecursiveCoroutines are a facility intended to be used as-drop in
replacement of recursive functions.

They provide the following features.
- They can be written almost as regular recursive functions,
  with 4 caveats.
  1. A recursive coroutine that returns a type `T`, needs to be declared
     to return a `RecursiveCoroutine<T>`.
  2. Inside the body of a recursive coroutine, when recursively calling
     another recursive coroutine, the recursive call needs to be
     prepended by the new keyword `rc_recur`.
  3. Inside the body of a recursive coroutine, the `return` statement
     needs to be substituted with `rc_return`.
  4. When launching a recursive coroutine `A` from a function that is
     not a recursive coroutine, `A` needs to be called with the provided
     dedicated template wrapper `rc_run`.
     The syntax is the following `rc_run(A, arg0, arg1, ...)`.
     This is necessary to enable swapping off recursive coroutine and
     fall back to regular recursion for debug.
     See below for how to do it.
- Unlike regular recursive functions, they don't use the system stack
  for recursion. They use a custom heap-allocated stack to manage
  recursion. This makes them more robust for implementing recursive
  functions that manipulate user-defined input, because they are much
  less likely to trigger stack overflow.
- They can be turned off compiling with
  `-DDISABLE_RECURSIVE_COROUTINES`, falling back to regular recursion,
  for debug purposes.
- They support both direct and indirect recursion, i.e. a recursive
  coroutine A can recursively call itself, or it can recursively call
  another recursive coroutine B, which in turns recursively calls A.
2020-12-29 16:15:31 +01:00
Alessandro Di Federico 6652eb660d Merge 'check-conventions-generate-style-file' 2020-12-29 16:15:09 +01:00
Alessandro Di Federico 3c58c7441b Whitespace changes 2020-12-29 16:14:49 +01:00
Pietro Fezzardi 9a3b514a80 CMakeLists.txt: generate and install .clang-format
This is intended to be used by all projects that adopt rev.ng coding
conventions for C++. Each project can create a symbolic link to the
installed .clang-format file, so that IDEs and other dev tools can pick
it up easily while keeping it up-to-date when updating revng.
2020-12-29 16:14:49 +01:00
Pietro Fezzardi 670801fad7 Tidy-up cmake commands for check-revng-conventions
This is a preliminary step before adding cmake commands to generate and
install a .clang-format file for easier use from other projects.
2020-12-29 16:14:49 +01:00
Pietro Fezzardi d37aed928e Run check-revng-conventions from outside git dirs
This enables running the check-revng-conventions script as part of the
build and install process, to generate the .clang-format file for
installation and use from other projects.
2020-12-29 16:14:45 +01:00
Pietro Fezzardi 86fcff5db4 check-revng-conventions: improve help 2020-12-29 15:43:34 +01:00
Pietro Fezzardi 13a893e91f check-revng-conventions prints errors on more opts
Options with only a single leading dash were previously recognized as
filenames.
Now they are recognized as options.
2020-12-29 15:43:34 +01:00
Pietro Fezzardi 01118920b0 Add check-revng-conventions option to print config
This option is enabled with --print-clang-format-config.
This is useful to work around the fact that clang-format configuration
is hard-coded in a file.
Using this option is easier to generate a .clang-format file that can be
dropped in single projects to be picked up by IDE.
2020-12-29 15:43:34 +01:00
Pietro Fezzardi 4b4e791afe Add missing option to check-revng-conventions help 2020-12-29 15:43:34 +01:00
Pietro Fezzardi cb2c3c610f Add --help flag to check-revng-conventions 2020-12-29 15:43:32 +01:00
Antonio Frighetto e6f0b26455 CodeGen: remove variadic args in calls to newpc
After the discovery of new code to be translated, the calls to `newpc`
can be stripped of their variadic arguments (reference to local vars)
in order to let SROA perform more optimization.
2020-12-29 15:25:42 +01:00
Antonio Frighetto 59b8c6ca4d Exception helper: add attribute noreturn
`raise_exception_helper` must not return to its caller. Should
`_Unwind_RaiseException` return, something will have gone wrong
with the personality routine; yet this should never happen.
This way we might also save a few bytes and hint the compiler to
avoid storing the callee-saved regs / allocating a new frame.
2020-12-29 14:53:09 +01:00
Pietro Fezzardi 7ff24ac761 GCBI: remove assertion on Dispatcher != nullptr
This assertion was executed in the `runOnModule` method of the GCBI
pass, but it is too strict.

Asserting that Dispatcher != nullptr during the execution of the pass
prevents the pass from successfully running on a Module without a
Dispatcher.
This is unfortunate, because some passes that depend on GCBI in revng-c
actually do that. They do so because they are not really interested in
the Dispatcher at all. They only use GCBI to access information on the
Stack Pointer.

In fact, the check for Dispatcher being != from nullptr is already
performed also in the `dispatcher()` method which is the sane thing to
do. This commit removes the assertion from the `runOnModule` method and
leaves it in the `dispatcher` method.
This allows to run the pass successfully even on a Module without the
Dispatcher, while not changing the contract of this pass (i.e. that when
you call the `dispatcher` method you get a nonnull pointer).
2020-12-29 14:51:38 +01:00
Pietro Fezzardi 5f90f7addb [TypeShrinking] Locally declare WorklistItem 2020-12-23 02:37:17 +01:00
Pietro Fezzardi 826033a63f [TypeShrinking] Fix comparisons of WorklistItem 2020-12-23 02:34:45 +01:00
Pietro Fezzardi 31a63a1416 [TypeShrinking] Apply check-revng-conventions 2020-12-23 02:27:04 +01:00
Qian Matteo Chen 0b2ba53560 [TypeShrinking] Add type shrinking to pipeline 2020-12-23 02:24:03 +01:00
Qian Matteo Chen 61c7f4cf0f [TypeShrinking] Fix use after destructor 2020-12-23 02:23:32 +01:00
Qian Matteo Chen 04085ecd99 [TypeShrinking] Fix styling issues 2020-12-23 02:23:00 +01:00
Qian Matteo Chen 750b326d24 [TypeShrinking] Ensure coherence of input liveness
with result size.
2020-12-23 02:22:28 +01:00
Qian Matteo Chen 007119af91 [TypeShrinking] Fix comment capitalization 2020-12-23 02:21:56 +01:00
Qian Matteo Chen 8d05cfc440 [TypeShrinking] Visit extremal labels first 2020-12-23 02:21:25 +01:00
Qian Matteo Chen 04a7ff86b2 [TypeShrinking] Don't shrink to booleans 2020-12-23 02:20:53 +01:00
Qian Matteo Chen 232c1596ce [TypeShrinking] Split passes in two 2020-12-23 02:20:21 +01:00
Qian Matteo Chen 0893cd824f [TypeShrinking] Handle rooted graphs 2020-12-23 02:19:49 +01:00
Qian Matteo Chen 568f13e48d [TypeShrinking] Document transfer functions 2020-12-23 02:19:18 +01:00
Qian Matteo Chen d085560674 [TypeShrinking] Sort nodes using RPOT for MFP 2020-12-23 02:16:07 +01:00
Qian Matteo Chen d6b4bcc185 [TypeShrinking] Allow personalized GraphTrait 2020-12-23 02:13:09 +01:00
Qian Matteo Chen bb8e98bfcb [TypeShrinking] Refactor using ranges .at() 2020-12-23 02:10:16 +01:00
Qian Matteo Chen ee7917faa1 [TypeShrinking] Iterate over instructions 2020-12-23 02:07:34 +01:00
Qian Matteo Chen a37ef2f2bd [TypeShrinking] Move small definitions in header 2020-12-23 02:03:46 +01:00
Qian Matteo Chen b0a3c4007c [TypeShrinking] Uppercase arguments 2020-12-23 02:00:51 +01:00
Qian Matteo Chen 5c02c41e12 [TypeShrinking] Use dyn_cast instead of isa + cast 2020-12-23 01:57:20 +01:00
Qian Matteo Chen b0542bbb64 [TypeShrinking] Use concepts in MFP implementation 2020-12-23 01:54:10 +01:00
Qian Matteo Chen 4a0b124464 [TypeShrinking] Remove java like constructor 2020-12-23 01:51:07 +01:00
Qian Matteo Chen 948c1c6bd6 [TypeShrinking] Reformat CMakeLists.txt 2020-12-23 01:48:04 +01:00
Qian Matteo Chen 923debe1a6 [TypeShrinking] Use std::min and std::max 2020-12-23 01:44:59 +01:00
Qian Matteo Chen b371c27089 [TypeShrinking] Remove unused header 2020-12-23 01:42:05 +01:00
Qian Matteo Chen 5ee2cdf004 [TypeShrinking] Refactor code
- Use uint32_t
- Define Top as uin32_t max
- Fix copyright notice
- Use using namespace llvm in cpp files
- Change hasSideEffects to isDataFlowSink
- Outline isAddLike
- Add option to ignore certain analysis results
2020-12-23 01:38:52 +01:00
Qian Matteo Chen 247d44d29b [TypeShrinking] Add forward declaration 2020-12-23 01:35:08 +01:00
Qian Matteo Chen bd613d5c7f [TypeShrinking] Remove unused files 2020-12-23 01:29:43 +01:00
Qian Matteo Chen 4565edc4fb [TypeShrinking] Move DataFlowGraph.h to local dir 2020-12-23 01:24:37 +01:00
Qian Matteo Chen a0e45760c5 [TypeShrinking] Add more transfer functions 2020-12-23 01:21:03 +01:00
Qian Matteo Chen 479298d60c [TypeShrinking] Implement type shrinking pass 2020-12-23 01:17:55 +01:00