Files
revng-revng/lib/RestructureCFG/FallThroughScopeAnalysis.h
T
Andrea Gussoni ca422bafd2 PromoteCallNoReturn: introduce beautify pass
We introduce the PromoteCallNoReturn beautification pass. Its goal is to
restructure sequence of statements, in order to have `call`s to
`noreturn` functions as _inlined_ in the middle of the statement
sequence, and leave _non local control flow statements_ at the end of
that scope. E.g., we prefer:
```
if (cond)
  call noreturnfunc();
return;
```
to
```
if (!cond)
  return;
call noreturnfunc();
```

In order to do this, contextually, we restructure the routine computing
the `fallthrough` property, in order to be able to differentiate between
the _non local control flow statements_, a call to a `noreturn`
function, or a generic mix of the two (useful when combining results
from the two situations above).

The new analysis is also used in the `promoteNoFallThrough` promotion
pass.
2023-11-28 16:19:08 +01:00

33 lines
706 B
C++

#pragma once
//
// Copyright rev.ng Labs Srl. See LICENSE.md for details.
//
#include "revng/Model/IRHelpers.h"
// Forward declarations
class ASTNode;
class ASTTree;
// This `enum class` is used to represent the fallthrough type
enum class FallThroughScopeType {
FallThrough,
// This is a placeholder state to represent the combination of two no
// fallthrough states
MixedNoFallThrough,
CallNoReturn,
Return,
Continue,
LoopBreak,
SwitchBreak,
};
using FallThroughScopeTypeMap = std::map<const ASTNode *, FallThroughScopeType>;
bool fallsThrough(FallThroughScopeType Element);
extern FallThroughScopeTypeMap
computeFallThroughScope(const model::Binary &Model, ASTNode *RootNode);