15 Commits

Author SHA1 Message Date
Alessandro Di Federico 903617e79e IRHelpers: turn some functions into IRBuilder::* 2026-06-19 09:18:16 +02:00
Alessandro Di Federico 5820908675 Remove and ban \file 2025-12-16 17:41:55 +01:00
Ivan Krysak 5b419540cc Disable IRBuilder checks in some additional places 2025-10-31 09:04:59 +01:00
Alessandro Di Federico f8bd4c3bac Move around some files in preparation for libtcg
* Make the following private headers public:
  * Lift/CPUStateAccessAnalysisPass.h
  * Lift/CSVOffsets.h
  * Lift/PTCDump.h
  * Lift/VariableManager.h
* Move from revngSupport to revngLift:
  * IRAnnotators.{h,cpp}
  * SelfReferencingDbgAnnotationWriter.{h,cpp}
* Move from revngSupport to revngModel:
  * FunctionTags.{h,cpp}
  * ProgramCounterHandler.{h,cpp}
* Move from revngSupport to revngRecompile:
  * OriginalAssemblyAnnotationWriter.{h,cpp}
2025-10-24 15:34:11 +02:00
Ivan Krysak 3561c2b907 Adopt IRBuilder wrapper 2025-10-21 19:17:01 +03:00
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00
Alessandro Di Federico 2e4f4d09b9 Remaining FunctionTags have been moved to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 0c212b66d9 Relicense to MIT 2024-02-29 17:03:36 +01:00
Andrea Gussoni 67a708c1e8 SimplifyHybridNot: improve BBExprsMap
The container used to store the associated `ExprNode`s that we need to
flip when performing a `HybridNot` simplification, is changed from a
`llvm::SmallVector` to `llvm:SmallSet`.
Indeed, during the collection of the `ExprNode`s pointing to a
`llvm::BasicBlock`, it should not be possible to find a single
`ExprNode` twice. We now assert this fact.
2023-11-03 11:44:09 +01:00
Andrea Gussoni 733f5008b3 BeautifyGHAST: implement DualSwitch simplify
We introduce a simplification step, which looks for `switch`es that can
be reduced to simpler `if` statements.

Specifically, the logic is the following:
1) When we identify a `switch` statement composed by a single `case` and
   a possible default, we transform it into an `if` with the `case` now
   corresponding to the `then`, and the `default` corresponding to the
   `else`, if present.
2) When we identify a `switch` statement composed by two `case`s, and no
   `default` is present, we can promote it to an `if` with `then` `else`
   branches.

Other key details:
- The promotion happens only if we can identify at least one of the
  `case`s that have a single element in the `case` label. If this is not
  the case, we do not promote one to RHS of the `if` condition.
- A new `CompareNode` class, inheriting from `ExprNode`, is created, in
  order to represent the equality or inequality condition of an `IfNode`
  instance that is the result of the promotion. This `CompareNode` can
  represent for the LHS both an `llvm::Value` or the `loop_state_var`,
  while it embeds the RHS constant which completes the comparison.
- We remove `SwitchBreak` AST nodes that may now appear as children of
  an `if` node promoted from a `switch`.
- We introduce in the `CompareNode` the `weaved` concept. Indeed, if a
  promotion of a weaved `switch` happens, we should avoid the
  serialization of the instructions leading to the computation of the
  condition of the original `switch`, because they have been already
  emitted by the main related dominating `switch`.

We also introduce an additional simplification step, which takes care
of:
- Promoting `!(==)` to `(!=)` and `!(!=)` to `(==)`, if the inner
  equal/not equal is represented via a `CompareNode`.
- Promoting `x == 0` to `!x` and `x != 0` to `x`.

To be able to correctly emit (or not) the instructions computing a
condition of an `IfNode`, we need to add the `EmittBB` flag, an
additional parameter to the `buildGHASTCondition` function, which
controls the emission of the statements of a basic block computing a
condition.

Consequently, the `IfNode` acquires a `IsWeaved` field, which is used to
mirror the property having the same name on `SwitchNode`. Being now
possible a promotion from a dual `SwitchNode` to an `IfNode`, we need to
represent this property on the `IfNode` too.
2023-10-23 18:16:20 +02:00
Andrea Gussoni f98e72d9a7 BeautifyGHAST: move SimplifyHybridNot header 2023-10-23 18:16:20 +02:00
Ivan Krysak 888e5371eb Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-05 06:06:07 +00:00
Ivan Krysak 3c584cfabc Formatting: set AllowShortEnumsOnASingleLine
The new value is `false`.
2023-07-05 06:05:04 +00:00
Andrea Gussoni 2162bd6f4a BeautifyGHAST: change Standard to WhileTrue
Rename the `LoopType` enum element `Standard` to `WhileTrue`, to better
convey the information that in that stage the loop as not been promoted.
2023-06-26 15:23:00 +02:00
Andrea Gussoni 3b07a6fba6 BeautifyGHAST: Introduce the hybrid not simplify
Introduce the hybrid beautifier aiming to simplify double `not`s (one on
the IR side (e.g., a `icmp ne`), and one on the `ExprNode` side on the
`GHAST` in the form of a `NotNode`.

To do this hybrid beautifier, we basically need to do the following:
- Implement a preliminary collection phase which computes which
  `ExprNode`s are affected by which `BasicBlock`.
- Compute the so-called consesus, i.e., verify that for all the
  `ExprNode`s affected by a certain `BasicBlock`, the transformation
  would be beneficial in terms of output. Basically:
    1) That the number of `!(!=)` transformed into `(==)` outscores the
       number of correlated `(!=)` which are transformed into `!(==)`.
    2) That the number of `!(==)` transformed into `(!=)` outscores the
       number of correlated `(==)` which are transformed into `!(!=)`.
- Actually perform the transformation for those situations where the
  consensus agrees.
2023-06-26 15:23:00 +02:00