retdec
Public Member Functions | Private Types | Private Attributes | List of all members
retdec::llvmir2hll::StructureConverter Class Referencefinal

A converter of the LLVM function structure. More...

#include <structure_converter.h>

Inheritance diagram for retdec::llvmir2hll::StructureConverter:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::StructureConverter:
Collaboration graph
[legend]

Public Member Functions

 StructureConverter (llvm::Pass *basePass, ShPtr< LLVMValueConverter > conv, ShPtr< Module > module)
 Constructs a new structure converter. More...
 
ShPtr< StatementconvertFuncBody (llvm::Function &func)
 Converts body of the given LLVM function func into a sequence of statements in BIR which include conditional statements and loops. More...
 

Private Types

enum class  DFSNodeState { Opened , Closed }
 Information about state of node during DFS traversal. More...
 
using SwitchClause = std::pair< ExprVector, ShPtr< CFGNode > >
 
using BBSet = std::unordered_set< llvm::BasicBlock * >
 
using CFGNodeQueue = std::queue< ShPtr< CFGNode > >
 
using CFGNodeStack = std::stack< ShPtr< CFGNode > >
 
using CFGNodeVector = std::vector< ShPtr< CFGNode > >
 
using LoopSet = std::unordered_set< llvm::Loop * >
 
using SwitchClauseVector = std::vector< ShPtr< SwitchClause > >
 
using MapBBToBBSet = std::unordered_map< llvm::BasicBlock *, BBSet >
 
using MapBBToCFGNode = std::unordered_map< llvm::BasicBlock *, ShPtr< CFGNode > >
 
using MapCFGNodeToSwitchClause = std::unordered_map< ShPtr< CFGNode >, ShPtr< SwitchClause > >
 
using MapCFGNodeToDFSNodeState = std::unordered_map< ShPtr< CFGNode >, DFSNodeState >
 
using MapLoopToCFGNode = std::unordered_map< llvm::Loop *, ShPtr< CFGNode > >
 
using MapStmtToTargetNode = std::unordered_map< ShPtr< Statement >, ShPtr< CFGNode > >
 
using MapTargetToGoto = std::unordered_map< ShPtr< CFGNode >, std::vector< ShPtr< GotoStmt > >>
 
using MapStmtToClones = std::unordered_map< ShPtr< Statement >, std::vector< ShPtr< Statement > >>
 

Private Member Functions

Construction and traversal through control-flow graph
ShPtr< CFGNodecreateCFG (llvm::BasicBlock &root)
 Creates control-flow graph of the function from the given root basic block root. More...
 
void detectBackEdges (ShPtr< CFGNode > cfg) const
 Traverses the given control-flow graph cfg and detects all back edges. More...
 
bool reduceCFG (ShPtr< CFGNode > cfg)
 Traverses the given control-flow graph cfg and tries to reduce some nodes to control-flow statements. More...
 
bool inspectCFGNode (ShPtr< CFGNode > node)
 Inspects the given CFG node node and tries to reduce this and neighboring nodes to any control-flow statement. More...
 
ShPtr< CFGNodepopFromQueue (CFGNodeQueue &queue) const
 Pop and return node from the given queue queue. More...
 
void addUnvisitedSuccessorsToQueue (const ShPtr< CFGNode > &node, CFGNodeQueue &toBeVisited, CFGNode::CFGNodeSet &visited) const
 Adds all unvisited successors of the given node node to the queue toBeVisited and also to the set of visited nodes visited. More...
 
void addUnvisitedSuccessorsToQueueInLoop (const ShPtr< CFGNode > &node, CFGNodeQueue &toBeVisited, CFGNode::CFGNodeSet &visited, llvm::Loop *loop) const
 Adds all unvisited successors inside loop loop of the given node node to the queue toBeVisited and also to the set of visited nodes visited. More...
 
bool BFSTraverse (ShPtr< CFGNode > cfg, std::function< bool(ShPtr< CFGNode >)> inspectFunc) const
 Traverses the given control-flow graph cfg using breadth-first search and inspect every node by function inspectFunc. More...
 
bool BFSTraverseLoop (ShPtr< CFGNode > cfg, std::function< bool(ShPtr< CFGNode >)> inspectFunc) const
 Traverses the given control-flow graph cfg of a loop using breadth-first search and inspect every node by function inspectFunc. More...
 
ShPtr< CFGNodeBFSFindFirst (ShPtr< CFGNode > cfg, std::function< bool(ShPtr< CFGNode >)> pred) const
 Traverses the given control-flow graph cfg using breadth-first search and returns first node which satisfies the predicate pred. More...
 
bool existsPathWithoutLoopsBetween (const ShPtr< CFGNode > &node1, const ShPtr< CFGNode > &node2) const
 Determines whether exists direct path (without loops) between two given nodes node1 and node2. More...
 
Detection of constructions
bool isSequence (const ShPtr< CFGNode > &node) const
 Determines whether the given node node can be reduced with following node as a sequence. More...
 
bool isSequenceWithTerminatingBranchToClone (const ShPtr< CFGNode > &node) const
 Determines whether the given node node can be reduced with following node as a sequence, where is cloned the terminating successor. More...
 
bool isIfElseStatement (const ShPtr< CFGNode > &node) const
 Determines whether the given the given node node is an if statement with else clause. More...
 
bool isIfStatement (const ShPtr< CFGNode > &node, std::size_t succ) const
 Determines whether the given node node is an if statement without else clause and if body is in the successor on index succ. More...
 
bool isIfStatementWithTerminatingBranch (const ShPtr< CFGNode > &node, std::size_t succ) const
 Determines whether the given node node is an if statement and successor on the index succ is terminated (e.g. by return). More...
 
bool isIfStatementWithTerminatingBranchToClone (const ShPtr< CFGNode > &node, std::size_t succ) const
 Determines whether the given node node is an if statement and successor on the index succ is terminated (e.g. by return). More...
 
bool isIfStatementWithBreakInLoop (const ShPtr< CFGNode > &node, std::size_t succ) const
 Determines whether the given node node is an if statement without else clause and in its successor on the index succ schould be break. More...
 
bool isIfStatementWithBreakByGotoInLoop (const ShPtr< CFGNode > &node, std::size_t succ) const
 Determines whether the given node node is an if statement without else clause and in its successor on the index succ is outside loop. More...
 
bool isIfElseStatementWithContinue (const ShPtr< CFGNode > &node, std::size_t succ) const
 Determines whether the given node node is an if statement without else clause and in its successor on the index succ schould be continue. More...
 
bool isContinueStatement (const ShPtr< CFGNode > &node) const
 Determines whether the given node node is terminated by continue statement. More...
 
bool isForLoop (const ShPtr< CFGNode > &node) const
 Determines whether the given node node is a reducible for loop. More...
 
bool isWhileTrueLoop (const ShPtr< CFGNode > &node) const
 Determines whether the given node node is a while(true) loop. More...
 
bool isNestedWhileTrueLoopWithContinueInHeader (const ShPtr< CFGNode > &node, std::size_t succ) const
 Determines whether the given node node is a while(true) statement, when on the index succ is the body of the loop and on the other index is continue statement to the parent loop. More...
 
bool isSwitchStatement (const ShPtr< CFGNode > &node) const
 Determines whether the given node node is a switch statement. More...
 
bool canBeCloned (const ShPtr< CFGNode > &node) const
 Determines whether the given node node can be cloned. More...
 
Reduction of nodes
void reduceToSequence (ShPtr< CFGNode > node)
 Reduces node node and its only successor into a single node which contains merged bodies of both nodes. More...
 
void reduceToSequenceClone (ShPtr< CFGNode > node)
 Reduces node node and its only successor into a single node which contains merged bodies of both nodes, where is cloned the terminating successor. More...
 
void reduceToIfElseStatement (ShPtr< CFGNode > node)
 Reduces node node and both its successors into a single node with if statement with else clause. More...
 
void reduceToIfStatement (ShPtr< CFGNode > node, std::size_t succ)
 Reduces node node and its successor on index succ into a single node with if statement without else clause. More...
 
void reduceToIfStatementClone (ShPtr< CFGNode > node, std::size_t succ)
 Reduces node node and its successor on index succ into a single node with if statement without else clause. The body of the node on index succ is cloned. More...
 
void reduceToIfElseStatementWithBreakInLoop (ShPtr< CFGNode > node, std::size_t succ)
 Reduces node node and its successor on index succ into a single node with if statement with break statement inside. More...
 
void reduceToIfElseStatementWithBreakByGotoInLoop (ShPtr< CFGNode > node, std::size_t succ)
 Reduces node node and its successor on index succ into a single node with if statement with goto statement inside. More...
 
void reduceToIfElseStatementWithContinue (ShPtr< CFGNode > node, std::size_t succ)
 Reduces node node and its successor on index succ into a single node with if statement with continue statement inside. More...
 
void reduceToContinueStatement (ShPtr< CFGNode > node)
 Reduces node node into a node which is terminated by switch statement. More...
 
void reduceToForLoop (ShPtr< CFGNode > node)
 Reduces node node into a node with for loop. More...
 
void reduceToWhileTrueLoop (ShPtr< CFGNode > node)
 Reduces node node into a node with while(true) loop. More...
 
void reduceToNestedWhileTrueLoopWithContinueInHeader (ShPtr< CFGNode > node, std::size_t succ)
 Reduces the given node node is into a while(true) statement, when on the index succ is the body of the loop and on the other index is continue statement to the parent loop. More...
 
void structureByGotos (ShPtr< CFGNode > cfg)
 Completely structures given CFG cfg using goto statements. More...
 
Condition refinement
ShPtr< StatementgetIfClauseBody (const ShPtr< CFGNode > &node, const ShPtr< CFGNode > &clause, const ShPtr< CFGNode > &ifSuccessor)
 Creates a new body of the given if clause clause. More...
 
ShPtr< StatementgetIfClauseBodyClone (const ShPtr< CFGNode > &node, const ShPtr< CFGNode > &clause, const ShPtr< CFGNode > &ifSuccessor)
 Creates a new body of the given if clause clause. The body of the clause is cloned. More...
 
ShPtr< IfStmtgetIfStmt (const ShPtr< Expression > &cond, const ShPtr< Statement > &trueBody, const ShPtr< Statement > &falseBody=nullptr) const
 Returns new if statement with the given condition cond and true body trueBody and false body (else clause) falseBody. More...
 
Loop refinement
ShPtr< CFGNodegetLoopSuccessor (const ShPtr< CFGNode > &loopNode) const
 Returns successor of the given loop node loopNode. More...
 
void completelyReduceLoop (ShPtr< CFGNode > loopNode)
 Completely reduces the given loop node loopNode. More...
 
Switch refinement
void reduceSwitchStatement (ShPtr< CFGNode > node)
 Reduces node node into a node with the switch statement. More...
 
ShPtr< CFGNodegetSwitchSuccessor (const ShPtr< CFGNode > &switchNode) const
 Returns successor of the given switch node switchNode. More...
 
bool isNodeAfterAllSwitchClauses (const ShPtr< CFGNode > &node, const ShPtr< CFGNode > &switchNode) const
 Determines whether the given node node is after all clauses of the given switch switchNode. More...
 
bool isNodeAfterSwitchClause (const ShPtr< CFGNode > &node, const ShPtr< CFGNode > &clauseNode) const
 Determines whether the given node node is after the given switch clause clauseNode. More...
 
bool hasDefaultClause (const ShPtr< CFGNode > &switchNode, const ShPtr< CFGNode > &switchSuccessor) const
 Determines whether the given switch node switchNode has a default clause. More...
 
bool isReducibleClause (const ShPtr< CFGNode > &clauseNode, const ShPtr< CFGNode > &switchNode, const ShPtr< CFGNode > &switchSuccessor, bool hasDefault=true) const
 Determines whether the given switch clause clauseNode is a clause ready to be reduced. More...
 
bool hasOnlySwitchOrClausesInPreds (const ShPtr< CFGNode > &clauseNode, const ShPtr< CFGNode > &switchNode, bool hasDefault) const
 Determines whether the given switch clause clauseNode has only switch node or other clauses in predecessors. More...
 
bool fallsThroughToAnotherCase (const ShPtr< CFGNode > &clauseNode, const ShPtr< CFGNode > &switchNode, bool hasDefault) const
 Determines whether the given switch clause clauseNode falls through to the another case clause or to the default clause. More...
 
ShPtr< SwitchStmtgetSwitchStmt (const ShPtr< CFGNode > &switchNode, const ShPtr< CFGNode > &switchSuccessor, bool hasDefault)
 Returns new switch statement which is created from the given switch node switchNode. More...
 
SwitchClauseVector getSwitchClauses (const ShPtr< CFGNode > &switchNode, bool hasDefault) const
 Returns a vector of clauses of the given switch node switchNode. More...
 
SwitchClauseVector sortSwitchClauses (const SwitchClauseVector &clauses, const ShPtr< CFGNode > &switchSuccessor) const
 Returns sorted vector of switch clauses clauses. More...
 
ShPtr< SwitchClausefindFirstClauseWithSinglePred (const SwitchClauseVector &clauses) const
 Returns first switch clause from the vector of clauses clauses which has only single predecessor. More...
 
ShPtr< StatementgetClauseBody (const ShPtr< CFGNode > &clauseNode, const ShPtr< CFGNode > &switchNode, const ShPtr< CFGNode > &switchSuccessor, const CFGNode::CFGNodeSet &generated)
 Returns new case clause of the switch statement which is created from the given switch node clauseNode. More...
 
bool isClauseTerminatedByBreak (const ShPtr< CFGNode > &clauseNode, const ShPtr< CFGNode > &switchSuccessor) const
 Determines whether the given switch clause clauseNode is terminated by a break statement. More...
 
void addClausesWithTheSameCond (ShPtr< SwitchStmt > switchStmt, const ExprVector &conds, const ShPtr< Statement > &clauseBody) const
 Adds case clauses with different conditions, but with the same clause body to the given switch statement switchStmt. More...
 
void removeReducedSuccsOfSwitch (const ShPtr< CFGNode > &switchNode, bool hasDefault) const
 Removes reduced successors of the given switch node switchNode. More...
 
Successor getters
ShPtr< StatementgetSuccessorsBody (const ShPtr< CFGNode > &node, const ShPtr< CFGNode > &succ)
 Creates a new body of the given node node successor succ. More...
 
ShPtr< StatementgetSuccessorsBodyClone (const ShPtr< CFGNode > &node, const ShPtr< CFGNode > &succ)
 Creates a new body of the given node node successor succ. The body of the successor is cloned. More...
 
ShPtr< StatementgetGotoForSuccessor (const ShPtr< CFGNode > &node, const ShPtr< CFGNode > &target)
 Creates a goto statement which jumps from the given node node to the given target node target. More...
 
ShPtr< StatementgetAssignsToPHINodes (const ShPtr< CFGNode > &from, const ShPtr< CFGNode > &to)
 Returns assignments to the PHI nodes from the given node from and to the given node to. More...
 
ShPtr< StatementgetPHICopiesForSuccessor (llvm::BasicBlock *currBB, llvm::BasicBlock *succ)
 Returns PHI copies for the given basic block currBB and its successor succ. More...
 
Work with LLVM analyses
void initialiazeLLVMAnalyses (llvm::Function &func)
 Initializes required LLVM analyses for converted function func. More...
 
llvm::Loop * getLoopFor (const ShPtr< CFGNode > &node) const
 Returns the innermost loop for the given node node. If node is not inside loop, returns nulptr. More...
 
bool isLoopHeader (const ShPtr< CFGNode > &node) const
 Determines whether the given node node is a loop header. More...
 
bool isLoopHeader (const ShPtr< CFGNode > &node, llvm::Loop *loop) const
 Determines whether the given node node is a header of the given loop loop. More...
 
bool isNodeOutsideLoop (const ShPtr< CFGNode > &node, llvm::Loop *loop) const
 Determines whether the given node node is outside of the given loop loop. More...
 
bool isInParentLoopOf (const ShPtr< CFGNode > &node, llvm::Loop *loop) const
 Determines whether the given node node is in the parent loop of the given loop loop. More...
 
unsigned getTripCount (llvm::Loop *loop) const
 Returns number of iterations for the given for loop loop. If loop is not a for loop, it returns zero. More...
 
bool canBeForLoop (llvm::Loop *loop) const
 Determines whether the given loop loop can be a for loop. More...
 
Postprocessing methods
ShPtr< StatementreplaceBreakOrContinueOutsideLoop (ShPtr< Statement > statement, SwitchParent sp)
 Replaces break/continue statements that are outside of loop with goto statements. More...
 
void replaceGoto (CFGNodeVector &targets)
 Replaces goto with code if there is only one reference to it. More...
 
void correctUndefinedLabels ()
 If goto target label is not used in code, it is replaced with its clone (that is used) More...
 
std::vector< ShPtr< Statement > > findContinueOrBreakStatements (ShPtr< Statement > parent, SwitchParent sp)
 Finds break and continue statements in cloned statements. More...
 
unsigned getStatementCount (ShPtr< Statement > statement)
 Returns number of statements in parent statement (body of if/while etc.) More...
 
void insertClonedLoopTargets (ShPtr< Statement > origParent, ShPtr< Statement > newParent)
 Inserts cloned break/continue stmts in case they need replacing. More...
 
void fixClonedGotos (ShPtr< Statement > statement)
 
Helper methods
void addGotoTargetIfNotExists (const ShPtr< CFGNode > &node)
 Adds node node to the vector of the goto targets if it isn't already there. More...
 
void addBranchMetadataToEndOfBodyIfNeeded (ShPtr< Statement > &body, const ShPtr< CFGNode > &clause, const ShPtr< CFGNode > &ifSuccessor) const
 Adds metadata of the form "branch -> xxx" to the body of the given if statement (if needed). More...
 
std::string getLabel (const ShPtr< CFGNode > &node) const
 Returns a label of the given node node. More...
 
void cleanUp ()
 Cleans up the helper containers. More...
 
- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Private Attributes

llvm::Pass * basePass
 Pass that have instantiated the converter. More...
 
llvm::LoopInfo * loopInfo
 Information about loops. More...
 
llvm::ScalarEvolution * scalarEvolution
 
ShPtr< LabelsHandlerlabelsHandler
 A handler of labels. More...
 
BasicBlockConverter bbConverter
 A converter of the LLVM basic block. More...
 
ShPtr< LLVMValueConverterconverter
 A converter from LLVM values to values in BIR. More...
 
MapLoopToCFGNode loopHeaders
 
MapBBToBBSet generatedPHINodes
 A map of already generated phi nodes from specific basic blocks. More...
 
MapStmtToTargetNode loopTargets
 A map of targets for break and continue statements. More...
 
MapStmtToTargetNode gotoTargetsToCfgNodes
 A map of goto target statements to cfg nodes. More...
 
MapTargetToGoto targetReferences
 A map of references for goto targets. More...
 
MapStmtToClones stmtClones
 A map of clones of statement. More...
 
LoopSet reducedLoops
 
BBSet reducedSwitches
 
CFGNodeStack statementsStack
 
CFGNode::CFGNodeSet statementsOnStack
 
CFGNodeVector gotoTargets
 
CFGNode::CFGNodeSet gotoTargetsSet
 
CFGNode::CFGNodeSet generatedNodes
 
ShPtr< ModuleresModule
 The resulting module in BIR. More...
 

Detailed Description

A converter of the LLVM function structure.

Member Typedef Documentation

◆ BBSet

using retdec::llvmir2hll::StructureConverter::BBSet = std::unordered_set<llvm::BasicBlock *>
private

◆ CFGNodeQueue

◆ CFGNodeStack

◆ CFGNodeVector

◆ LoopSet

using retdec::llvmir2hll::StructureConverter::LoopSet = std::unordered_set<llvm::Loop *>
private

◆ MapBBToBBSet

using retdec::llvmir2hll::StructureConverter::MapBBToBBSet = std::unordered_map<llvm::BasicBlock *, BBSet>
private

◆ MapBBToCFGNode

using retdec::llvmir2hll::StructureConverter::MapBBToCFGNode = std::unordered_map<llvm::BasicBlock *, ShPtr<CFGNode> >
private

◆ MapCFGNodeToDFSNodeState

◆ MapCFGNodeToSwitchClause

◆ MapLoopToCFGNode

using retdec::llvmir2hll::StructureConverter::MapLoopToCFGNode = std::unordered_map<llvm::Loop *, ShPtr<CFGNode> >
private

◆ MapStmtToClones

using retdec::llvmir2hll::StructureConverter::MapStmtToClones = std::unordered_map<ShPtr<Statement>, std::vector<ShPtr<Statement> >>
private

◆ MapStmtToTargetNode

◆ MapTargetToGoto

using retdec::llvmir2hll::StructureConverter::MapTargetToGoto = std::unordered_map<ShPtr<CFGNode>, std::vector<ShPtr<GotoStmt> >>
private

◆ SwitchClause

◆ SwitchClauseVector

Member Enumeration Documentation

◆ DFSNodeState

Information about state of node during DFS traversal.

Enumerator
Opened 
Closed 

Visited, but not closed node.

Visited and closed node.

Constructor & Destructor Documentation

◆ StructureConverter()

retdec::llvmir2hll::StructureConverter::StructureConverter ( llvm::Pass *  basePass,
ShPtr< LLVMValueConverter conv,
ShPtr< Module module 
)

Constructs a new structure converter.

Parameters
[in]basePassPass that have instantiated the converter.
[in]convA converter from LLVM values to values in BIR.
[in]moduleA module this converter works on. Needed only for debugging purposes.

Member Function Documentation

◆ addBranchMetadataToEndOfBodyIfNeeded()

void retdec::llvmir2hll::StructureConverter::addBranchMetadataToEndOfBodyIfNeeded ( ShPtr< Statement > &  body,
const ShPtr< CFGNode > &  clause,
const ShPtr< CFGNode > &  ifSuccessor 
) const
private

Adds metadata of the form "branch -> xxx" to the body of the given if statement (if needed).

◆ addClausesWithTheSameCond()

void retdec::llvmir2hll::StructureConverter::addClausesWithTheSameCond ( ShPtr< SwitchStmt switchStmt,
const ExprVector conds,
const ShPtr< Statement > &  clauseBody 
) const
private

Adds case clauses with different conditions, but with the same clause body to the given switch statement switchStmt.

Parameters
[out]switchStmtGiven switch statement.
[in]condsGiven vector of conditions with the same clause body.
[in]clauseBodyGiven clause clauseBody.
Preconditions
  • both switchStmt and clauseBody are non-null

◆ addGotoTargetIfNotExists()

void retdec::llvmir2hll::StructureConverter::addGotoTargetIfNotExists ( const ShPtr< CFGNode > &  node)
private

Adds node node to the vector of the goto targets if it isn't already there.

Preconditions
  • node is non-null

◆ addUnvisitedSuccessorsToQueue()

void retdec::llvmir2hll::StructureConverter::addUnvisitedSuccessorsToQueue ( const ShPtr< CFGNode > &  node,
CFGNodeQueue toBeVisited,
CFGNode::CFGNodeSet visited 
) const
private

Adds all unvisited successors of the given node node to the queue toBeVisited and also to the set of visited nodes visited.

Preconditions
  • node is non-null

◆ addUnvisitedSuccessorsToQueueInLoop()

void retdec::llvmir2hll::StructureConverter::addUnvisitedSuccessorsToQueueInLoop ( const ShPtr< CFGNode > &  node,
CFGNodeQueue toBeVisited,
CFGNode::CFGNodeSet visited,
llvm::Loop *  loop 
) const
private

Adds all unvisited successors inside loop loop of the given node node to the queue toBeVisited and also to the set of visited nodes visited.

Preconditions
  • node is non-null
  • loop is non-null

◆ BFSFindFirst()

ShPtr< CFGNode > retdec::llvmir2hll::StructureConverter::BFSFindFirst ( ShPtr< CFGNode cfg,
std::function< bool(ShPtr< CFGNode >)>  pred 
) const
private

Traverses the given control-flow graph cfg using breadth-first search and returns first node which satisfies the predicate pred.

Preconditions
  • cfg is non-null

◆ BFSTraverse()

bool retdec::llvmir2hll::StructureConverter::BFSTraverse ( ShPtr< CFGNode cfg,
std::function< bool(ShPtr< CFGNode >)>  inspectFunc 
) const
private

Traverses the given control-flow graph cfg using breadth-first search and inspect every node by function inspectFunc.

Returns
Returns true if inspection of any node return true.
Preconditions
  • cfg is non-null

◆ BFSTraverseLoop()

bool retdec::llvmir2hll::StructureConverter::BFSTraverseLoop ( ShPtr< CFGNode cfg,
std::function< bool(ShPtr< CFGNode >)>  inspectFunc 
) const
private

Traverses the given control-flow graph cfg of a loop using breadth-first search and inspect every node by function inspectFunc.

Returns
Returns true if inspection of any node return true.
Preconditions
  • cfg is non-null

◆ canBeCloned()

bool retdec::llvmir2hll::StructureConverter::canBeCloned ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given node node can be cloned.

Preconditions
  • node is non-null

◆ canBeForLoop()

bool retdec::llvmir2hll::StructureConverter::canBeForLoop ( llvm::Loop *  loop) const
private

Determines whether the given loop loop can be a for loop.

Loop can be a for loop when it has the induction variable and non-zero number of iterations.

Preconditions
  • loop is non-null

◆ cleanUp()

void retdec::llvmir2hll::StructureConverter::cleanUp ( )
private

Cleans up the helper containers.

◆ completelyReduceLoop()

void retdec::llvmir2hll::StructureConverter::completelyReduceLoop ( ShPtr< CFGNode loopNode)
private

Completely reduces the given loop node loopNode.

If loop cannot be reduced normally, it will be reduced by goto statements.

Preconditions
  • loopNode is non-null

◆ convertFuncBody()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::convertFuncBody ( llvm::Function &  func)

Converts body of the given LLVM function func into a sequence of statements in BIR which include conditional statements and loops.

Preconditions
  • func is not a function declaration

◆ correctUndefinedLabels()

void retdec::llvmir2hll::StructureConverter::correctUndefinedLabels ( )
private

If goto target label is not used in code, it is replaced with its clone (that is used)

◆ createCFG()

ShPtr< CFGNode > retdec::llvmir2hll::StructureConverter::createCFG ( llvm::BasicBlock &  root)
private

Creates control-flow graph of the function from the given root basic block root.

◆ detectBackEdges()

void retdec::llvmir2hll::StructureConverter::detectBackEdges ( ShPtr< CFGNode cfg) const
private

Traverses the given control-flow graph cfg and detects all back edges.

Preconditions
  • cfg is non-null

◆ existsPathWithoutLoopsBetween()

bool retdec::llvmir2hll::StructureConverter::existsPathWithoutLoopsBetween ( const ShPtr< CFGNode > &  node1,
const ShPtr< CFGNode > &  node2 
) const
private

Determines whether exists direct path (without loops) between two given nodes node1 and node2.

Preconditions
  • both node1 and node2 are non-null

◆ fallsThroughToAnotherCase()

bool retdec::llvmir2hll::StructureConverter::fallsThroughToAnotherCase ( const ShPtr< CFGNode > &  clauseNode,
const ShPtr< CFGNode > &  switchNode,
bool  hasDefault 
) const
private

Determines whether the given switch clause clauseNode falls through to the another case clause or to the default clause.

Parameters
[in]clauseNodeGiven switch clause node.
[in]switchNodeGiven switch node.
[in]hasDefaultHas switch default clause?
Preconditions
  • both clauseNode and switchNode are non-null

◆ findContinueOrBreakStatements()

std::vector< ShPtr< Statement > > retdec::llvmir2hll::StructureConverter::findContinueOrBreakStatements ( ShPtr< Statement parent,
SwitchParent  sp 
)
private

Finds break and continue statements in cloned statements.

◆ findFirstClauseWithSinglePred()

ShPtr< StructureConverter::SwitchClause > retdec::llvmir2hll::StructureConverter::findFirstClauseWithSinglePred ( const SwitchClauseVector clauses) const
private

Returns first switch clause from the vector of clauses clauses which has only single predecessor.

◆ fixClonedGotos()

void retdec::llvmir2hll::StructureConverter::fixClonedGotos ( ShPtr< Statement statement)
private

Add goto statements created by cloning to targetReferences container.

◆ getAssignsToPHINodes()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::getAssignsToPHINodes ( const ShPtr< CFGNode > &  from,
const ShPtr< CFGNode > &  to 
)
private

Returns assignments to the PHI nodes from the given node from and to the given node to.

Preconditions
  • both from and to are non-null

◆ getClauseBody()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::getClauseBody ( const ShPtr< CFGNode > &  clauseNode,
const ShPtr< CFGNode > &  switchNode,
const ShPtr< CFGNode > &  switchSuccessor,
const CFGNode::CFGNodeSet generated 
)
private

Returns new case clause of the switch statement which is created from the given switch node clauseNode.

Parameters
[in]clauseNodeGiven switch clause node.
[in]switchNodeGiven switch node.
[in]switchSuccessorSuccessor of the switch.
[in]generatedAlready generated switch clauses.
Preconditions
  • both clauseNode and switchNode are non-null

◆ getGotoForSuccessor()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::getGotoForSuccessor ( const ShPtr< CFGNode > &  node,
const ShPtr< CFGNode > &  target 
)
private

Creates a goto statement which jumps from the given node node to the given target node target.

Preconditions
  • both node and target are non-null

◆ getIfClauseBody()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::getIfClauseBody ( const ShPtr< CFGNode > &  node,
const ShPtr< CFGNode > &  clause,
const ShPtr< CFGNode > &  ifSuccessor 
)
private

Creates a new body of the given if clause clause.

Parameters
[in]nodeGiven if statement node.
[in]clauseGiven if clause node.
[in]ifSuccessorSuccessor of the if statement.
Preconditions
  • all of node, clause and ifSuccessor are non-null

◆ getIfClauseBodyClone()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::getIfClauseBodyClone ( const ShPtr< CFGNode > &  node,
const ShPtr< CFGNode > &  clause,
const ShPtr< CFGNode > &  ifSuccessor 
)
private

Creates a new body of the given if clause clause. The body of the clause is cloned.

Parameters
[in]nodeGiven if statement node.
[in]clauseGiven if clause node.
[in]ifSuccessorSuccessor of the if statement.
Preconditions
  • all of node, clause and ifSuccessor are non-null

◆ getIfStmt()

ShPtr< IfStmt > retdec::llvmir2hll::StructureConverter::getIfStmt ( const ShPtr< Expression > &  cond,
const ShPtr< Statement > &  trueBody,
const ShPtr< Statement > &  falseBody = nullptr 
) const
private

Returns new if statement with the given condition cond and true body trueBody and false body (else clause) falseBody.

If the given trueBody contains only empty statements, the condition will be negated to produce non-empty body of the if statement.

If the given falseBody ir nullptr or contains only empty statements, the else clause will be omitted.

If both trueBody and falseBody contain only empty statements, nullptr will be returned.

Preconditions
  • both cond and falseBody are non-null

◆ getLabel()

std::string retdec::llvmir2hll::StructureConverter::getLabel ( const ShPtr< CFGNode > &  node) const
private

Returns a label of the given node node.

Preconditions
  • node is non-null

◆ getLoopFor()

llvm::Loop * retdec::llvmir2hll::StructureConverter::getLoopFor ( const ShPtr< CFGNode > &  node) const
private

Returns the innermost loop for the given node node. If node is not inside loop, returns nulptr.

Preconditions
  • node is non-null

◆ getLoopSuccessor()

ShPtr< CFGNode > retdec::llvmir2hll::StructureConverter::getLoopSuccessor ( const ShPtr< CFGNode > &  loopNode) const
private

Returns successor of the given loop node loopNode.

Loop also could have no successor. In that case, nullptr is returned.

Preconditions
  • loopNode is non-null

◆ getPHICopiesForSuccessor()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::getPHICopiesForSuccessor ( llvm::BasicBlock *  currBB,
llvm::BasicBlock *  succ 
)
private

Returns PHI copies for the given basic block currBB and its successor succ.

Preconditions
  • both currBB and succ are non-null

◆ getStatementCount()

unsigned retdec::llvmir2hll::StructureConverter::getStatementCount ( ShPtr< Statement statement)
private

Returns number of statements in parent statement (body of if/while etc.)

◆ getSuccessorsBody()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::getSuccessorsBody ( const ShPtr< CFGNode > &  node,
const ShPtr< CFGNode > &  succ 
)
private

Creates a new body of the given node node successor succ.

Preconditions
  • both node and succ are non-null

◆ getSuccessorsBodyClone()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::getSuccessorsBodyClone ( const ShPtr< CFGNode > &  node,
const ShPtr< CFGNode > &  succ 
)
private

Creates a new body of the given node node successor succ. The body of the successor is cloned.

Preconditions
  • both node and succ are non-null

◆ getSwitchClauses()

StructureConverter::SwitchClauseVector retdec::llvmir2hll::StructureConverter::getSwitchClauses ( const ShPtr< CFGNode > &  switchNode,
bool  hasDefault 
) const
private

Returns a vector of clauses of the given switch node switchNode.

Parameters
[in]switchNodeGiven switch node.
[in]hasDefaultHas switch default clause?
Preconditions
  • switchNode is non-null

◆ getSwitchStmt()

ShPtr< SwitchStmt > retdec::llvmir2hll::StructureConverter::getSwitchStmt ( const ShPtr< CFGNode > &  switchNode,
const ShPtr< CFGNode > &  switchSuccessor,
bool  hasDefault 
)
private

Returns new switch statement which is created from the given switch node switchNode.

Parameters
[in]switchNodeGiven switch node.
[in]switchSuccessorSuccessor of the switch.
[in]hasDefaultHas switch default clause?
Preconditions
  • switchNode is non-null

◆ getSwitchSuccessor()

ShPtr< CFGNode > retdec::llvmir2hll::StructureConverter::getSwitchSuccessor ( const ShPtr< CFGNode > &  switchNode) const
private

Returns successor of the given switch node switchNode.

Switch also could have no successor. In that case, nullptr is returned.

Preconditions
  • switchNode is non-null

◆ getTripCount()

unsigned retdec::llvmir2hll::StructureConverter::getTripCount ( llvm::Loop *  loop) const
private

Returns number of iterations for the given for loop loop. If loop is not a for loop, it returns zero.

Preconditions
  • loop is non-null

◆ hasDefaultClause()

bool retdec::llvmir2hll::StructureConverter::hasDefaultClause ( const ShPtr< CFGNode > &  switchNode,
const ShPtr< CFGNode > &  switchSuccessor 
) const
private

Determines whether the given switch node switchNode has a default clause.

Parameters
[in]switchNodeGiven switch node.
[in]switchSuccessorSuccessor of the switch.
Preconditions
  • switchNode is non-null

◆ hasOnlySwitchOrClausesInPreds()

bool retdec::llvmir2hll::StructureConverter::hasOnlySwitchOrClausesInPreds ( const ShPtr< CFGNode > &  clauseNode,
const ShPtr< CFGNode > &  switchNode,
bool  hasDefault 
) const
private

Determines whether the given switch clause clauseNode has only switch node or other clauses in predecessors.

Parameters
[in]clauseNodeGiven switch clause node.
[in]switchNodeGiven switch node.
[in]hasDefaultHas switch default clause?
Preconditions
  • both clauseNode and switchNode are non-null

◆ initialiazeLLVMAnalyses()

void retdec::llvmir2hll::StructureConverter::initialiazeLLVMAnalyses ( llvm::Function &  func)
private

Initializes required LLVM analyses for converted function func.

◆ insertClonedLoopTargets()

void retdec::llvmir2hll::StructureConverter::insertClonedLoopTargets ( ShPtr< Statement origParent,
ShPtr< Statement newParent 
)
private

Inserts cloned break/continue stmts in case they need replacing.

◆ inspectCFGNode()

bool retdec::llvmir2hll::StructureConverter::inspectCFGNode ( ShPtr< CFGNode node)
private

Inspects the given CFG node node and tries to reduce this and neighboring nodes to any control-flow statement.

Returns
Returns true if the node have been reduced.
Preconditions
  • node is non-null

◆ isClauseTerminatedByBreak()

bool retdec::llvmir2hll::StructureConverter::isClauseTerminatedByBreak ( const ShPtr< CFGNode > &  clauseNode,
const ShPtr< CFGNode > &  switchSuccessor 
) const
private

Determines whether the given switch clause clauseNode is terminated by a break statement.

Parameters
[in]clauseNodeGiven switch clause node.
[in]switchSuccessorSuccessor of the switch.
Preconditions
  • clauseNode is non-null

◆ isContinueStatement()

bool retdec::llvmir2hll::StructureConverter::isContinueStatement ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given node node is terminated by continue statement.

Preconditions
  • node is non-null

◆ isForLoop()

bool retdec::llvmir2hll::StructureConverter::isForLoop ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given node node is a reducible for loop.

Preconditions
  • node is non-null

◆ isIfElseStatement()

bool retdec::llvmir2hll::StructureConverter::isIfElseStatement ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given the given node node is an if statement with else clause.

Preconditions
  • node is non-null

◆ isIfElseStatementWithContinue()

bool retdec::llvmir2hll::StructureConverter::isIfElseStatementWithContinue ( const ShPtr< CFGNode > &  node,
std::size_t  succ 
) const
private

Determines whether the given node node is an if statement without else clause and in its successor on the index succ schould be continue.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ isIfStatement()

bool retdec::llvmir2hll::StructureConverter::isIfStatement ( const ShPtr< CFGNode > &  node,
std::size_t  succ 
) const
private

Determines whether the given node node is an if statement without else clause and if body is in the successor on index succ.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ isIfStatementWithBreakByGotoInLoop()

bool retdec::llvmir2hll::StructureConverter::isIfStatementWithBreakByGotoInLoop ( const ShPtr< CFGNode > &  node,
std::size_t  succ 
) const
private

Determines whether the given node node is an if statement without else clause and in its successor on the index succ is outside loop.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ isIfStatementWithBreakInLoop()

bool retdec::llvmir2hll::StructureConverter::isIfStatementWithBreakInLoop ( const ShPtr< CFGNode > &  node,
std::size_t  succ 
) const
private

Determines whether the given node node is an if statement without else clause and in its successor on the index succ schould be break.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ isIfStatementWithTerminatingBranch()

bool retdec::llvmir2hll::StructureConverter::isIfStatementWithTerminatingBranch ( const ShPtr< CFGNode > &  node,
std::size_t  succ 
) const
private

Determines whether the given node node is an if statement and successor on the index succ is terminated (e.g. by return).

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ isIfStatementWithTerminatingBranchToClone()

bool retdec::llvmir2hll::StructureConverter::isIfStatementWithTerminatingBranchToClone ( const ShPtr< CFGNode > &  node,
std::size_t  succ 
) const
private

Determines whether the given node node is an if statement and successor on the index succ is terminated (e.g. by return).

In comparation to method isIfStatementWithTerminatingBranch(), in this case cannot body of the terminating node be already reduced and in usage, body must be cloned.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ isInParentLoopOf()

bool retdec::llvmir2hll::StructureConverter::isInParentLoopOf ( const ShPtr< CFGNode > &  node,
llvm::Loop *  loop 
) const
private

Determines whether the given node node is in the parent loop of the given loop loop.

This method returns true also if loop does not have a parent and node is outside loop.

Preconditions
  • both node and loop are non-null

◆ isLoopHeader() [1/2]

bool retdec::llvmir2hll::StructureConverter::isLoopHeader ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given node node is a loop header.

Preconditions
  • node is non-null

◆ isLoopHeader() [2/2]

bool retdec::llvmir2hll::StructureConverter::isLoopHeader ( const ShPtr< CFGNode > &  node,
llvm::Loop *  loop 
) const
private

Determines whether the given node node is a header of the given loop loop.

Preconditions
  • both node and loop are non-null

◆ isNestedWhileTrueLoopWithContinueInHeader()

bool retdec::llvmir2hll::StructureConverter::isNestedWhileTrueLoopWithContinueInHeader ( const ShPtr< CFGNode > &  node,
std::size_t  succ 
) const
private

Determines whether the given node node is a while(true) statement, when on the index succ is the body of the loop and on the other index is continue statement to the parent loop.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ isNodeAfterAllSwitchClauses()

bool retdec::llvmir2hll::StructureConverter::isNodeAfterAllSwitchClauses ( const ShPtr< CFGNode > &  node,
const ShPtr< CFGNode > &  switchNode 
) const
private

Determines whether the given node node is after all clauses of the given switch switchNode.

Preconditions
  • both node and switchNode are non-null

◆ isNodeAfterSwitchClause()

bool retdec::llvmir2hll::StructureConverter::isNodeAfterSwitchClause ( const ShPtr< CFGNode > &  node,
const ShPtr< CFGNode > &  clauseNode 
) const
private

Determines whether the given node node is after the given switch clause clauseNode.

Preconditions
  • both node and clauseNode are non-null

◆ isNodeOutsideLoop()

bool retdec::llvmir2hll::StructureConverter::isNodeOutsideLoop ( const ShPtr< CFGNode > &  node,
llvm::Loop *  loop 
) const
private

Determines whether the given node node is outside of the given loop loop.

Preconditions
  • both node and loop are non-null

◆ isReducibleClause()

bool retdec::llvmir2hll::StructureConverter::isReducibleClause ( const ShPtr< CFGNode > &  clauseNode,
const ShPtr< CFGNode > &  switchNode,
const ShPtr< CFGNode > &  switchSuccessor,
bool  hasDefault = true 
) const
private

Determines whether the given switch clause clauseNode is a clause ready to be reduced.

Clause is ready to be reduced, when it is in one of these states:

  • it terminates
  • it falls through to the another clause
  • it has only one successor which is the successor of the whole switch
Parameters
[in]clauseNodeGiven switch clause node.
[in]switchNodeGiven switch node.
[in]switchSuccessorSuccessor of the switch.
[in]hasDefaultHas switch default clause?
Preconditions
  • both clauseNode and switchNode are non-null

◆ isSequence()

bool retdec::llvmir2hll::StructureConverter::isSequence ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given node node can be reduced with following node as a sequence.

Preconditions
  • node is non-null

◆ isSequenceWithTerminatingBranchToClone()

bool retdec::llvmir2hll::StructureConverter::isSequenceWithTerminatingBranchToClone ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given node node can be reduced with following node as a sequence, where is cloned the terminating successor.

Preconditions
  • node is non-null

◆ isSwitchStatement()

bool retdec::llvmir2hll::StructureConverter::isSwitchStatement ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given node node is a switch statement.

Preconditions
  • node is non-null

◆ isWhileTrueLoop()

bool retdec::llvmir2hll::StructureConverter::isWhileTrueLoop ( const ShPtr< CFGNode > &  node) const
private

Determines whether the given node node is a while(true) loop.

Preconditions
  • node is non-null

◆ popFromQueue()

ShPtr< CFGNode > retdec::llvmir2hll::StructureConverter::popFromQueue ( CFGNodeQueue queue) const
private

Pop and return node from the given queue queue.

◆ reduceCFG()

bool retdec::llvmir2hll::StructureConverter::reduceCFG ( ShPtr< CFGNode cfg)
private

Traverses the given control-flow graph cfg and tries to reduce some nodes to control-flow statements.

Returns
Returns true if any node have been reduced.
Preconditions
  • cfg is non-null

◆ reduceSwitchStatement()

void retdec::llvmir2hll::StructureConverter::reduceSwitchStatement ( ShPtr< CFGNode node)
private

Reduces node node into a node with the switch statement.

Preconditions
  • node is non-null

◆ reduceToContinueStatement()

void retdec::llvmir2hll::StructureConverter::reduceToContinueStatement ( ShPtr< CFGNode node)
private

Reduces node node into a node which is terminated by switch statement.

Preconditions
  • node is non-null

◆ reduceToForLoop()

void retdec::llvmir2hll::StructureConverter::reduceToForLoop ( ShPtr< CFGNode node)
private

Reduces node node into a node with for loop.

Preconditions
  • node is non-null

◆ reduceToIfElseStatement()

void retdec::llvmir2hll::StructureConverter::reduceToIfElseStatement ( ShPtr< CFGNode node)
private

Reduces node node and both its successors into a single node with if statement with else clause.

Preconditions
  • node is non-null

◆ reduceToIfElseStatementWithBreakByGotoInLoop()

void retdec::llvmir2hll::StructureConverter::reduceToIfElseStatementWithBreakByGotoInLoop ( ShPtr< CFGNode node,
std::size_t  succ 
)
private

Reduces node node and its successor on index succ into a single node with if statement with goto statement inside.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ reduceToIfElseStatementWithBreakInLoop()

void retdec::llvmir2hll::StructureConverter::reduceToIfElseStatementWithBreakInLoop ( ShPtr< CFGNode node,
std::size_t  succ 
)
private

Reduces node node and its successor on index succ into a single node with if statement with break statement inside.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ reduceToIfElseStatementWithContinue()

void retdec::llvmir2hll::StructureConverter::reduceToIfElseStatementWithContinue ( ShPtr< CFGNode node,
std::size_t  succ 
)
private

Reduces node node and its successor on index succ into a single node with if statement with continue statement inside.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ reduceToIfStatement()

void retdec::llvmir2hll::StructureConverter::reduceToIfStatement ( ShPtr< CFGNode node,
std::size_t  succ 
)
private

Reduces node node and its successor on index succ into a single node with if statement without else clause.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ reduceToIfStatementClone()

void retdec::llvmir2hll::StructureConverter::reduceToIfStatementClone ( ShPtr< CFGNode node,
std::size_t  succ 
)
private

Reduces node node and its successor on index succ into a single node with if statement without else clause. The body of the node on index succ is cloned.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ reduceToNestedWhileTrueLoopWithContinueInHeader()

void retdec::llvmir2hll::StructureConverter::reduceToNestedWhileTrueLoopWithContinueInHeader ( ShPtr< CFGNode node,
std::size_t  succ 
)
private

Reduces the given node node is into a while(true) statement, when on the index succ is the body of the loop and on the other index is continue statement to the parent loop.

Preconditions
  • node is non-null
  • succ has value 0 or 1

◆ reduceToSequence()

void retdec::llvmir2hll::StructureConverter::reduceToSequence ( ShPtr< CFGNode node)
private

Reduces node node and its only successor into a single node which contains merged bodies of both nodes.

Preconditions
  • node is non-null

◆ reduceToSequenceClone()

void retdec::llvmir2hll::StructureConverter::reduceToSequenceClone ( ShPtr< CFGNode node)
private

Reduces node node and its only successor into a single node which contains merged bodies of both nodes, where is cloned the terminating successor.

Preconditions
  • node is non-null

◆ reduceToWhileTrueLoop()

void retdec::llvmir2hll::StructureConverter::reduceToWhileTrueLoop ( ShPtr< CFGNode node)
private

Reduces node node into a node with while(true) loop.

Preconditions
  • node is non-null

◆ removeReducedSuccsOfSwitch()

void retdec::llvmir2hll::StructureConverter::removeReducedSuccsOfSwitch ( const ShPtr< CFGNode > &  switchNode,
bool  hasDefault 
) const
private

Removes reduced successors of the given switch node switchNode.

Parameters
[in]switchNodeGiven switch node.
[in]hasDefaultHas switch default clause?
Preconditions
  • switchNode is non-null

◆ replaceBreakOrContinueOutsideLoop()

ShPtr< Statement > retdec::llvmir2hll::StructureConverter::replaceBreakOrContinueOutsideLoop ( ShPtr< Statement statement,
SwitchParent  sp 
)
private

Replaces break/continue statements that are outside of loop with goto statements.

◆ replaceGoto()

void retdec::llvmir2hll::StructureConverter::replaceGoto ( CFGNodeVector targets)
private

Replaces goto with code if there is only one reference to it.

◆ sortSwitchClauses()

StructureConverter::SwitchClauseVector retdec::llvmir2hll::StructureConverter::sortSwitchClauses ( const SwitchClauseVector clauses,
const ShPtr< CFGNode > &  switchSuccessor 
) const
private

Returns sorted vector of switch clauses clauses.

Parameters
[in]clausesSwitch clauses to be sorted.
[in]switchSuccessorSuccessor of the switch.

◆ structureByGotos()

void retdec::llvmir2hll::StructureConverter::structureByGotos ( ShPtr< CFGNode cfg)
private

Completely structures given CFG cfg using goto statements.

Preconditions
  • cfg is non-null

Member Data Documentation

◆ basePass

llvm::Pass* retdec::llvmir2hll::StructureConverter::basePass
private

Pass that have instantiated the converter.

◆ bbConverter

BasicBlockConverter retdec::llvmir2hll::StructureConverter::bbConverter
private

A converter of the LLVM basic block.

◆ converter

ShPtr<LLVMValueConverter> retdec::llvmir2hll::StructureConverter::converter
private

A converter from LLVM values to values in BIR.

◆ generatedNodes

CFGNode::CFGNodeSet retdec::llvmir2hll::StructureConverter::generatedNodes
private

◆ generatedPHINodes

MapBBToBBSet retdec::llvmir2hll::StructureConverter::generatedPHINodes
private

A map of already generated phi nodes from specific basic blocks.

◆ gotoTargets

CFGNodeVector retdec::llvmir2hll::StructureConverter::gotoTargets
private

◆ gotoTargetsSet

CFGNode::CFGNodeSet retdec::llvmir2hll::StructureConverter::gotoTargetsSet
private

◆ gotoTargetsToCfgNodes

MapStmtToTargetNode retdec::llvmir2hll::StructureConverter::gotoTargetsToCfgNodes
private

A map of goto target statements to cfg nodes.

◆ labelsHandler

ShPtr<LabelsHandler> retdec::llvmir2hll::StructureConverter::labelsHandler
private

A handler of labels.

◆ loopHeaders

MapLoopToCFGNode retdec::llvmir2hll::StructureConverter::loopHeaders
private

A map of the corresponding loops and loop headers represented by CFG nodes.

◆ loopInfo

llvm::LoopInfo* retdec::llvmir2hll::StructureConverter::loopInfo
private

Information about loops.

◆ loopTargets

MapStmtToTargetNode retdec::llvmir2hll::StructureConverter::loopTargets
private

A map of targets for break and continue statements.

◆ reducedLoops

LoopSet retdec::llvmir2hll::StructureConverter::reducedLoops
private

◆ reducedSwitches

BBSet retdec::llvmir2hll::StructureConverter::reducedSwitches
private

◆ resModule

ShPtr<Module> retdec::llvmir2hll::StructureConverter::resModule
private

The resulting module in BIR.

◆ scalarEvolution

llvm::ScalarEvolution* retdec::llvmir2hll::StructureConverter::scalarEvolution
private

◆ statementsOnStack

CFGNode::CFGNodeSet retdec::llvmir2hll::StructureConverter::statementsOnStack
private

◆ statementsStack

CFGNodeStack retdec::llvmir2hll::StructureConverter::statementsStack
private

◆ stmtClones

MapStmtToClones retdec::llvmir2hll::StructureConverter::stmtClones
private

A map of clones of statement.

◆ targetReferences

MapTargetToGoto retdec::llvmir2hll::StructureConverter::targetReferences
private

A map of references for goto targets.


The documentation for this class was generated from the following files: