retdec
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
retdec::llvmir2hll::CFGNode Class Reference

A representation of a control-flow graph node. More...

#include <cfg_node.h>

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

Classes

class  CFGEdge
 A representation of a control-flow graph edge. More...
 

Public Types

using CFGEdgeVector = std::vector< ShPtr< CFGEdge > >
 
using CFGNodeSet = std::unordered_set< ShPtr< CFGNode > >
 
using CFGNodeVector = std::vector< ShPtr< CFGNode > >
 

Public Member Functions

 CFGNode (llvm::BasicBlock *bb, ShPtr< Statement > body)
 Constructs a new control-flow graph node. More...
 
Operations with stored basic blocks
llvm::BasicBlock * getFirstBB () const
 Returns the first LLVM basic block in sequence which is represented by this node. More...
 
llvm::BasicBlock * getLastBB () const
 Returns the last LLVM basic block in sequence which is represented by this node. More...
 
void setLastBB (llvm::BasicBlock *bb)
 Sets bb as the last LLVM basic block in sequence which is represented by this node. More...
 
Operations with terminator instruction of the last basic block
llvm::Instruction * getTerm () const
 Returns the terminator instruction of stored basic block in this node. More...
 
llvm::Value * getCond () const
 Returns a condition of this node if this is conditional branch. Otherwise, returns nullptr. More...
 
Operations with node's body
ShPtr< StatementgetBody () const
 Returns the body in BIR of this node. More...
 
void setBody (ShPtr< Statement > body)
 Sets a new body body to this node. More...
 
void appendToBody (ShPtr< Statement > statement)
 Appends the given statement statement to this node's body. More...
 
Addition and deletion of the node's successors
void addSuccessor (ShPtr< CFGNode > succ)
 Adds a new successor succ to this node. More...
 
void moveSuccessorsFrom (const ShPtr< CFGNode > &node)
 Moves all successors from the given node node to this node. More...
 
void removeSucc (std::size_t i)
 Removes a successor of this node on the index i. More...
 
void deleteSucc (std::size_t i)
 Deletes a successor of this node on the index i. More...
 
void deleteSuccessors ()
 Deletes all successors of this node. More...
 
Getters for number of predecessors and successors
std::size_t getPredsNum () const
 Returns a number of this node successors. More...
 
std::size_t getSuccNum () const
 Returns a number of this node successors. More...
 
Node's successors getters and querying
CFGNodeSet getPredecessors ()
 Returns a set of predecessors of this node. More...
 
CFGNodeVector getSuccessors ()
 Returns a vector of successors of this node. More...
 
ShPtr< CFGNodegetSucc (std::size_t i) const
 Returns a successor of this node on the index i. More...
 
ShPtr< CFGNodegetSuccOrNull (std::size_t i) const
 Returns a successor of this node on the index i. If this node does not have a successor on the index i, it returns nullptr. More...
 
bool hasSuccessor (const ShPtr< CFGNode > &node) const
 Determines whether the given node node is this node's successor. More...
 
Operations with back-edges
void markAsBackEdge (const ShPtr< CFGNode > &node)
 Sets flag that this node's succ node is a back-edge. More...
 
bool isBackEdge (const ShPtr< CFGNode > &node) const
 Returns true if this node's succ node is a back-edge. More...
 
Operations with statement successor
bool hasStatementSuccessor () const
 Determines whether this node has a statement successor. More...
 
ShPtr< CFGNodegetStatementSuccessor () const
 Returns the statement successor. More...
 
void setStatementSuccessor (ShPtr< CFGNode > succ)
 Sets succ as a new statement successor. More...
 
void removeStatementSuccessor ()
 Removes statement successor if exists. More...
 
Debugging methods
std::string getName () const
 Returns the label of first basic block in this node. More...
 
void debugPrint () const
 Emits this node's name and its successors and predecessors to the standard error output. More...
 

Private Attributes

llvm::BasicBlock * firstBasicBlock
 A first LLVM basic block in sequence which is represented by this node. More...
 
llvm::BasicBlock * lastBasicBlock
 A last LLVM basic block in sequence which is represented by this node. More...
 
ShPtr< Statementbody
 A body of this tree node. More...
 
CFGNodeSet predecessors
 A set of node predecessors. More...
 
CFGEdgeVector successors
 An ordered vector of node successors. More...
 
ShPtr< CFGNodestatementSuccessor
 A successor of the high-level statement represented by this node. More...
 

Additional Inherited Members

- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Detailed Description

A representation of a control-flow graph node.

Member Typedef Documentation

◆ CFGEdgeVector

◆ CFGNodeSet

using retdec::llvmir2hll::CFGNode::CFGNodeSet = std::unordered_set<ShPtr<CFGNode> >

◆ CFGNodeVector

Constructor & Destructor Documentation

◆ CFGNode()

retdec::llvmir2hll::CFGNode::CFGNode ( llvm::BasicBlock *  bb,
ShPtr< Statement body 
)

Constructs a new control-flow graph node.

Parameters
[in]bbAn LLVM basic block to store to this tree node.
[in]bodyA converted body of this tree node.

Member Function Documentation

◆ addSuccessor()

void retdec::llvmir2hll::CFGNode::addSuccessor ( ShPtr< CFGNode succ)

Adds a new successor succ to this node.

This method also adds self as predecessor to currently added successor.

Preconditions
  • succ is non-null

◆ appendToBody()

void retdec::llvmir2hll::CFGNode::appendToBody ( ShPtr< Statement statement)

Appends the given statement statement to this node's body.

Appended statement statement could be also nullptr.

◆ debugPrint()

void retdec::llvmir2hll::CFGNode::debugPrint ( ) const

Emits this node's name and its successors and predecessors to the standard error output.

Only for debugging purposes.

◆ deleteSucc()

void retdec::llvmir2hll::CFGNode::deleteSucc ( std::size_t  i)

Deletes a successor of this node on the index i.

Delete means that deleted node will be removed from the tree and all edges to this node will be removed.

Preconditions
  • i < NUM_NODE_SUCC, where NUM_NODE_SUCC is the number of node's successors

◆ deleteSuccessors()

void retdec::llvmir2hll::CFGNode::deleteSuccessors ( )

Deletes all successors of this node.

◆ getBody()

ShPtr< Statement > retdec::llvmir2hll::CFGNode::getBody ( ) const

Returns the body in BIR of this node.

◆ getCond()

llvm::Value * retdec::llvmir2hll::CFGNode::getCond ( ) const

Returns a condition of this node if this is conditional branch. Otherwise, returns nullptr.

◆ getFirstBB()

llvm::BasicBlock * retdec::llvmir2hll::CFGNode::getFirstBB ( ) const

Returns the first LLVM basic block in sequence which is represented by this node.

◆ getLastBB()

llvm::BasicBlock * retdec::llvmir2hll::CFGNode::getLastBB ( ) const

Returns the last LLVM basic block in sequence which is represented by this node.

◆ getName()

std::string retdec::llvmir2hll::CFGNode::getName ( ) const

Returns the label of first basic block in this node.

◆ getPredecessors()

CFGNode::CFGNodeSet retdec::llvmir2hll::CFGNode::getPredecessors ( )

Returns a set of predecessors of this node.

◆ getPredsNum()

std::size_t retdec::llvmir2hll::CFGNode::getPredsNum ( ) const

Returns a number of this node successors.

◆ getStatementSuccessor()

ShPtr< CFGNode > retdec::llvmir2hll::CFGNode::getStatementSuccessor ( ) const

Returns the statement successor.

◆ getSucc()

ShPtr< CFGNode > retdec::llvmir2hll::CFGNode::getSucc ( std::size_t  i) const

Returns a successor of this node on the index i.

Preconditions
  • i < NUM_NODE_SUCC, where NUM_NODE_SUCC is the number of node's successors

◆ getSuccessors()

CFGNode::CFGNodeVector retdec::llvmir2hll::CFGNode::getSuccessors ( )

Returns a vector of successors of this node.

◆ getSuccNum()

std::size_t retdec::llvmir2hll::CFGNode::getSuccNum ( ) const

Returns a number of this node successors.

◆ getSuccOrNull()

ShPtr< CFGNode > retdec::llvmir2hll::CFGNode::getSuccOrNull ( std::size_t  i) const

Returns a successor of this node on the index i. If this node does not have a successor on the index i, it returns nullptr.

◆ getTerm()

llvm::Instruction * retdec::llvmir2hll::CFGNode::getTerm ( ) const

Returns the terminator instruction of stored basic block in this node.

◆ hasStatementSuccessor()

bool retdec::llvmir2hll::CFGNode::hasStatementSuccessor ( ) const

Determines whether this node has a statement successor.

◆ hasSuccessor()

bool retdec::llvmir2hll::CFGNode::hasSuccessor ( const ShPtr< CFGNode > &  node) const

Determines whether the given node node is this node's successor.

Preconditions
  • node is non-null

◆ isBackEdge()

bool retdec::llvmir2hll::CFGNode::isBackEdge ( const ShPtr< CFGNode > &  node) const

Returns true if this node's succ node is a back-edge.

◆ markAsBackEdge()

void retdec::llvmir2hll::CFGNode::markAsBackEdge ( const ShPtr< CFGNode > &  node)

Sets flag that this node's succ node is a back-edge.

◆ moveSuccessorsFrom()

void retdec::llvmir2hll::CFGNode::moveSuccessorsFrom ( const ShPtr< CFGNode > &  node)

Moves all successors from the given node node to this node.

Preconditions
  • node is non-null

◆ removeStatementSuccessor()

void retdec::llvmir2hll::CFGNode::removeStatementSuccessor ( )

Removes statement successor if exists.

◆ removeSucc()

void retdec::llvmir2hll::CFGNode::removeSucc ( std::size_t  i)

Removes a successor of this node on the index i.

Remove means that node will be removed from successors and also back edge from successor to current node will be removed.

Preconditions
  • i < NUM_NODE_SUCC, where NUM_NODE_SUCC is the number of node's successors

◆ setBody()

void retdec::llvmir2hll::CFGNode::setBody ( ShPtr< Statement body)

Sets a new body body to this node.

Preconditions
  • body is non-null

◆ setLastBB()

void retdec::llvmir2hll::CFGNode::setLastBB ( llvm::BasicBlock *  bb)

Sets bb as the last LLVM basic block in sequence which is represented by this node.

◆ setStatementSuccessor()

void retdec::llvmir2hll::CFGNode::setStatementSuccessor ( ShPtr< CFGNode succ)

Sets succ as a new statement successor.

Member Data Documentation

◆ body

ShPtr<Statement> retdec::llvmir2hll::CFGNode::body
private

A body of this tree node.

◆ firstBasicBlock

llvm::BasicBlock* retdec::llvmir2hll::CFGNode::firstBasicBlock
private

A first LLVM basic block in sequence which is represented by this node.

◆ lastBasicBlock

llvm::BasicBlock* retdec::llvmir2hll::CFGNode::lastBasicBlock
private

A last LLVM basic block in sequence which is represented by this node.

◆ predecessors

CFGNodeSet retdec::llvmir2hll::CFGNode::predecessors
private

A set of node predecessors.

◆ statementSuccessor

ShPtr<CFGNode> retdec::llvmir2hll::CFGNode::statementSuccessor
private

A successor of the high-level statement represented by this node.

◆ successors

CFGEdgeVector retdec::llvmir2hll::CFGNode::successors
private

An ordered vector of node successors.


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