Static Value-Flow Analysis
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
SVF::WTO< GraphT > Class Template Reference

#include <WTO.h>

Classes

class  WTOCycleDepthBuilder
 Visitor to build the cycle depths of each node. More...
 

Public Types

typedef GraphT::NodeType NodeT
 
typedef GraphT::EdgeType EdgeT
 
typedef WTOCycleDepth< GraphTGraphTWTOCycleDepth
 
typedef WTOComponent< GraphTWTOComponentT
 
typedef WTONode< GraphTWTONodeT
 
typedef WTOCycle< GraphTWTOCycleT
 
typedef Set< const NodeT * > NodeRefList
 
typedef WTOComponentRefList::const_iterator Iterator
 Iterator over the components.
 

Public Member Functions

 WTO (const NodeT *entry)
 Compute the weak topological order of the given graph.
 
 WTO (const WTO &other)=default
 No copy constructor.
 
 WTO (WTO &&other)=default
 Move constructor.
 
WTOoperator= (const WTO &other)=default
 No copy assignment operator.
 
WTOoperator= (WTO &&other)=default
 Move assignment operator.
 
 ~WTO ()
 Destructor.
 
const WTOComponentRefListgetWTOComponents () const
 Get all wto components in WTO.
 
Iterator begin () const
 Begin iterator over the components.
 
Iterator end () const
 End iterator over the components.
 
bool isHead (const NodeT *node) const
 
NodeRefToWTOCycleMap::const_iterator headBegin () const
 
NodeRefToWTOCycleMap::const_iterator headEnd () const
 End iterator over the components.
 
const GraphTWTOCycleDepthcycleDepth (const NodeT *n) const
 Return the cycleDepth of the given node.
 
bool in_cycleDepth_table (const NodeT *n) const
 Return the cycleDepth of the given node.
 
void accept (WTOComponentVisitor< GraphT > &v)
 Accept the given visitor.
 
std::string toString () const
 Dump the order, for debugging purpose.
 
void init ()
 

Protected Types

typedef const WTOComponentTWTOComponentPtr
 
typedef std::list< WTOComponentPtrWTOComponentRefList
 
typedef Set< WTOComponentPtrWTOComponentRefSet
 
typedef Map< const NodeT *, const WTOCycleT * > NodeRefToWTOCycleMap
 
typedef Map< const NodeT *, NodeRefListNodeRefTONodeRefListMap
 
typedef u32_t CycleDepthNumber
 
typedef Map< const NodeT *, CycleDepthNumberNodeRefToCycleDepthNumber
 
typedef std::vector< const NodeT * > Stack
 
typedef std::shared_ptr< GraphTWTOCycleDepthWTOCycleDepthPtr
 
typedef Map< const NodeT *, WTOCycleDepthPtrNodeRefToWTOCycleDepthPtr
 

Protected Member Functions

virtual std::vector< const NodeT * > getSuccessors (const NodeT *node)
 Return the successors of node.
 
CycleDepthNumber getCDN (const NodeT *n) const
 Return the depth-first number of the given node.
 
void setCDN (const NodeT *n, const CycleDepthNumber &dfn)
 Set the depth-first number of the given node.
 
const NodeTpop ()
 Pop a node from the stack.
 
void push (const NodeT *n)
 Push a node on the stack.
 
const WTONodeTnewNode (const NodeT *node)
 
const WTOCycleTnewCycle (const WTONodeT *node, const WTOComponentRefList &partition)
 
virtual const WTOCycleTcomponent (const NodeT *node)
 Create the cycle component for the given node.
 
virtual CycleDepthNumber visit (const NodeT *node, WTOComponentRefList &partition)
 
void buildNodeToDepth ()
 Build the node to WTO cycle depth table.
 

Protected Attributes

WTOComponentRefList _components
 
WTOComponentRefSet _allComponents
 
NodeRefToWTOCycleMap headRefToCycle
 
NodeRefToWTOCycleDepthPtr _nodeToDepth
 
NodeRefToCycleDepthNumber _nodeToCDN
 
CycleDepthNumber _num
 
Stack _stack
 
const NodeT_entry
 

Friends

std::ostream & operator<< (std::ostream &o, const WTO< GraphT > &wto)
 Overloading operator << for dumping ICFG node ID.
 

Detailed Description

template<typename GraphT>
class SVF::WTO< GraphT >

Weak topological order for GraphT

Definition at line 515 of file WTO.h.

Member Typedef Documentation

◆ CycleDepthNumber

template<typename GraphT >
typedef u32_t SVF::WTO< GraphT >::CycleDepthNumber
protected

Definition at line 538 of file WTO.h.

◆ EdgeT

template<typename GraphT >
typedef GraphT::EdgeType SVF::WTO< GraphT >::EdgeT

Definition at line 524 of file WTO.h.

◆ GraphTWTOCycleDepth

template<typename GraphT >
typedef WTOCycleDepth<GraphT> SVF::WTO< GraphT >::GraphTWTOCycleDepth

Definition at line 525 of file WTO.h.

◆ Iterator

template<typename GraphT >
typedef WTOComponentRefList::const_iterator SVF::WTO< GraphT >::Iterator

Iterator over the components.

Definition at line 546 of file WTO.h.

◆ NodeRefList

template<typename GraphT >
typedef Set<const NodeT*> SVF::WTO< GraphT >::NodeRefList

Definition at line 529 of file WTO.h.

◆ NodeRefToCycleDepthNumber

template<typename GraphT >
typedef Map<const NodeT*, CycleDepthNumber> SVF::WTO< GraphT >::NodeRefToCycleDepthNumber
protected

Definition at line 539 of file WTO.h.

◆ NodeRefTONodeRefListMap

template<typename GraphT >
typedef Map<const NodeT*, NodeRefList> SVF::WTO< GraphT >::NodeRefTONodeRefListMap
protected

Definition at line 536 of file WTO.h.

◆ NodeRefToWTOCycleDepthPtr

template<typename GraphT >
typedef Map<const NodeT*, WTOCycleDepthPtr> SVF::WTO< GraphT >::NodeRefToWTOCycleDepthPtr
protected

Definition at line 542 of file WTO.h.

◆ NodeRefToWTOCycleMap

template<typename GraphT >
typedef Map<const NodeT*, const WTOCycleT*> SVF::WTO< GraphT >::NodeRefToWTOCycleMap
protected

Definition at line 535 of file WTO.h.

◆ NodeT

template<typename GraphT >
typedef GraphT::NodeType SVF::WTO< GraphT >::NodeT

Definition at line 523 of file WTO.h.

◆ Stack

template<typename GraphT >
typedef std::vector<const NodeT*> SVF::WTO< GraphT >::Stack
protected

Definition at line 540 of file WTO.h.

◆ WTOComponentPtr

template<typename GraphT >
typedef const WTOComponentT* SVF::WTO< GraphT >::WTOComponentPtr
protected

Definition at line 532 of file WTO.h.

◆ WTOComponentRefList

template<typename GraphT >
typedef std::list<WTOComponentPtr> SVF::WTO< GraphT >::WTOComponentRefList
protected

Definition at line 533 of file WTO.h.

◆ WTOComponentRefSet

template<typename GraphT >
typedef Set<WTOComponentPtr> SVF::WTO< GraphT >::WTOComponentRefSet
protected

Definition at line 534 of file WTO.h.

◆ WTOComponentT

template<typename GraphT >
typedef WTOComponent<GraphT> SVF::WTO< GraphT >::WTOComponentT

Definition at line 526 of file WTO.h.

◆ WTOCycleDepthPtr

template<typename GraphT >
typedef std::shared_ptr<GraphTWTOCycleDepth> SVF::WTO< GraphT >::WTOCycleDepthPtr
protected

Definition at line 541 of file WTO.h.

◆ WTOCycleT

template<typename GraphT >
typedef WTOCycle<GraphT> SVF::WTO< GraphT >::WTOCycleT

Definition at line 528 of file WTO.h.

◆ WTONodeT

template<typename GraphT >
typedef WTONode<GraphT> SVF::WTO< GraphT >::WTONodeT

Definition at line 527 of file WTO.h.

Constructor & Destructor Documentation

◆ WTO() [1/3]

template<typename GraphT >
SVF::WTO< GraphT >::WTO ( const NodeT entry)
inlineexplicit

Compute the weak topological order of the given graph.

Definition at line 561 of file WTO.h.

561 : _num(0), _entry(entry)
562 {
563 }
const NodeT * _entry
Definition WTO.h:556
CycleDepthNumber _num
Definition WTO.h:554

◆ WTO() [2/3]

template<typename GraphT >
SVF::WTO< GraphT >::WTO ( const WTO< GraphT > &  other)
default

No copy constructor.

◆ WTO() [3/3]

template<typename GraphT >
SVF::WTO< GraphT >::WTO ( WTO< GraphT > &&  other)
default

Move constructor.

◆ ~WTO()

template<typename GraphT >
SVF::WTO< GraphT >::~WTO ( )
inline

Destructor.

Definition at line 578 of file WTO.h.

579 {
580 for (const auto& component : _allComponents)
581 {
582 delete component;
583 }
584 }
WTOComponentRefSet _allComponents
Definition WTO.h:550
virtual const WTOCycleT * component(const NodeT *node)
Create the cycle component for the given node.
Definition WTO.h:788

Member Function Documentation

◆ accept()

template<typename GraphT >
void SVF::WTO< GraphT >::accept ( WTOComponentVisitor< GraphT > &  v)
inline

Accept the given visitor.

Definition at line 636 of file WTO.h.

637 {
638 for (const auto& c : _components)
639 {
640 c->accept(v);
641 }
642 }
WTOComponentRefList _components
Definition WTO.h:549
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ begin()

template<typename GraphT >
Iterator SVF::WTO< GraphT >::begin ( ) const
inline

Begin iterator over the components.

Definition at line 593 of file WTO.h.

594 {
595 return _components.cbegin();
596 }

◆ buildNodeToDepth()

template<typename GraphT >
void SVF::WTO< GraphT >::buildNodeToDepth ( )
inlineprotected

Build the node to WTO cycle depth table.

Definition at line 861 of file WTO.h.

862 {
863 WTOCycleDepthBuilder builder(_nodeToDepth);
864 for (auto it = begin(), et = end(); it != et; ++it)
865 {
866 (*it)->accept(builder);
867 }
868 }
Iterator begin() const
Begin iterator over the components.
Definition WTO.h:593
Iterator end() const
End iterator over the components.
Definition WTO.h:599
NodeRefToWTOCycleDepthPtr _nodeToDepth
Definition WTO.h:552

◆ component()

template<typename GraphT >
virtual const WTOCycleT * SVF::WTO< GraphT >::component ( const NodeT node)
inlineprotectedvirtual

Create the cycle component for the given node.

Definition at line 788 of file WTO.h.

789 {
791
792 for (auto succ: getSuccessors(node))
793 {
794 if (getCDN(succ) == 0)
795 {
797 }
798 }
799 const WTONodeT* head = newNode(node);
800 const WTOCycleT* ptr = newCycle(head, partition);
801 headRefToCycle.emplace(node, ptr);
802 return ptr;
803 }
virtual CycleDepthNumber visit(const NodeT *node, WTOComponentRefList &partition)
Definition WTO.h:808
NodeRefToWTOCycleMap headRefToCycle
Definition WTO.h:551
const WTOCycleT * newCycle(const WTONodeT *node, const WTOComponentRefList &partition)
Definition WTO.h:779
WTOCycle< GraphT > WTOCycleT
Definition WTO.h:528
CycleDepthNumber getCDN(const NodeT *n) const
Return the depth-first number of the given node.
Definition WTO.h:734
virtual std::vector< const NodeT * > getSuccessors(const NodeT *node)
Return the successors of node.
Definition WTO.h:722
WTONode< GraphT > WTONodeT
Definition WTO.h:527
std::list< WTOComponentPtr > WTOComponentRefList
Definition WTO.h:533
const WTONodeT * newNode(const NodeT *node)
Definition WTO.h:772

◆ cycleDepth()

template<typename GraphT >
const GraphTWTOCycleDepth & SVF::WTO< GraphT >::cycleDepth ( const NodeT n) const
inline

Return the cycleDepth of the given node.

Definition at line 621 of file WTO.h.

622 {
623 auto it = _nodeToDepth.find(n);
624 assert(it != _nodeToDepth.end() && "node not found");
625 return *(it->second);
626 }
cJSON * n
Definition cJSON.cpp:2558

◆ end()

template<typename GraphT >
Iterator SVF::WTO< GraphT >::end ( ) const
inline

End iterator over the components.

Definition at line 599 of file WTO.h.

600 {
601 return _components.cend();
602 }

◆ getCDN()

template<typename GraphT >
CycleDepthNumber SVF::WTO< GraphT >::getCDN ( const NodeT n) const
inlineprotected

Return the depth-first number of the given node.

Definition at line 734 of file WTO.h.

735 {
736 auto it = _nodeToCDN.find(n);
737 if (it != _nodeToCDN.end())
738 {
739 return it->second;
740 }
741 else
742 {
743 return 0;
744 }
745 }
NodeRefToCycleDepthNumber _nodeToCDN
Definition WTO.h:553

◆ getSuccessors()

template<typename GraphT >
virtual std::vector< const NodeT * > SVF::WTO< GraphT >::getSuccessors ( const NodeT node)
inlineprotectedvirtual

Return the successors of node.

Definition at line 722 of file WTO.h.

723 {
724 std::vector<const NodeT *> succssors;
725 for (const auto& e : node->getOutEdges())
726 {
727 succssors.push_back(e->getDstNode());
728 }
729 return succssors;
730 }

◆ getWTOComponents()

template<typename GraphT >
const WTOComponentRefList & SVF::WTO< GraphT >::getWTOComponents ( ) const
inline

Get all wto components in WTO.

Definition at line 587 of file WTO.h.

588 {
589 return _components;
590 }

◆ headBegin()

template<typename GraphT >
NodeRefToWTOCycleMap::const_iterator SVF::WTO< GraphT >::headBegin ( ) const
inline

Definition at line 609 of file WTO.h.

610 {
611 return headRefToCycle.cbegin();
612 }

◆ headEnd()

template<typename GraphT >
NodeRefToWTOCycleMap::const_iterator SVF::WTO< GraphT >::headEnd ( ) const
inline

End iterator over the components.

Definition at line 615 of file WTO.h.

616 {
617 return headRefToCycle.cend();
618 }

◆ in_cycleDepth_table()

template<typename GraphT >
bool SVF::WTO< GraphT >::in_cycleDepth_table ( const NodeT n) const
inline

Return the cycleDepth of the given node.

Definition at line 629 of file WTO.h.

630 {
631 auto it = _nodeToDepth.find(n);
632 return it != _nodeToDepth.end();
633 }

◆ init()

template<typename GraphT >
void SVF::WTO< GraphT >::init ( )
inline

Definition at line 672 of file WTO.h.

673 {
675 _nodeToCDN.clear();
676 _stack.clear();
678 }
Stack _stack
Definition WTO.h:555
void buildNodeToDepth()
Build the node to WTO cycle depth table.
Definition WTO.h:861

◆ isHead()

template<typename GraphT >
bool SVF::WTO< GraphT >::isHead ( const NodeT node) const
inline

Definition at line 604 of file WTO.h.

605 {
606 return headRefToCycle.find(node) != headRefToCycle.end();
607 }

◆ newCycle()

template<typename GraphT >
const WTOCycleT * SVF::WTO< GraphT >::newCycle ( const WTONodeT node,
const WTOComponentRefList partition 
)
inlineprotected

Definition at line 779 of file WTO.h.

781 {
782 const WTOCycleT* ptr = new WTOCycleT(node, std::move(partition));
783 _allComponents.insert(ptr);
784 return ptr;
785 }

◆ newNode()

template<typename GraphT >
const WTONodeT * SVF::WTO< GraphT >::newNode ( const NodeT node)
inlineprotected

Definition at line 772 of file WTO.h.

773 {
774 const WTONodeT* ptr = new WTONodeT(node);
775 _allComponents.insert(ptr);
776 return ptr;
777 }

◆ operator=() [1/2]

template<typename GraphT >
WTO & SVF::WTO< GraphT >::operator= ( const WTO< GraphT > &  other)
default

No copy assignment operator.

◆ operator=() [2/2]

template<typename GraphT >
WTO & SVF::WTO< GraphT >::operator= ( WTO< GraphT > &&  other)
default

Move assignment operator.

◆ pop()

template<typename GraphT >
const NodeT * SVF::WTO< GraphT >::pop ( )
inlineprotected

Pop a node from the stack.

Definition at line 758 of file WTO.h.

759 {
760 assert(!_stack.empty() && "empty stack");
761 const NodeT* top = _stack.back();
762 _stack.pop_back();
763 return top;
764 }
GraphT::NodeType NodeT
Definition WTO.h:523

◆ push()

template<typename GraphT >
void SVF::WTO< GraphT >::push ( const NodeT n)
inlineprotected

Push a node on the stack.

Definition at line 767 of file WTO.h.

768 {
769 _stack.push_back(n);
770 }

◆ setCDN()

template<typename GraphT >
void SVF::WTO< GraphT >::setCDN ( const NodeT n,
const CycleDepthNumber dfn 
)
inlineprotected

Set the depth-first number of the given node.

Definition at line 748 of file WTO.h.

749 {
750 auto res = _nodeToCDN.insert(std::make_pair(n, dfn));
751 if (!res.second)
752 {
753 (res.first)->second = dfn;
754 }
755 }

◆ toString()

template<typename GraphT >
std::string SVF::WTO< GraphT >::toString ( ) const
inline

Dump the order, for debugging purpose.

Definition at line 645 of file WTO.h.

646 {
647 std::string str;
648 std::stringstream rawstr(str);
649 rawstr << "[";
650 for (auto it = begin(), et = end(); it != et;)
651 {
652 rawstr << (*it)->toString();
653 ++it;
654 if (it != et)
655 {
656 rawstr << ", ";
657 }
658 }
659 rawstr << "]";
660 return rawstr.str();
661 }

◆ visit()

template<typename GraphT >
virtual CycleDepthNumber SVF::WTO< GraphT >::visit ( const NodeT node,
WTOComponentRefList partition 
)
inlineprotectedvirtual

Visit the given node

Algorithm to build a weak topological order of a graph

Definition at line 808 of file WTO.h.

810 {
811 CycleDepthNumber head(0);
812 CycleDepthNumber min(0);
813 bool loop;
814
815 push(node);
817 head = _num;
818 setCDN(node, head);
819 loop = false;
820
821 for (auto succ: getSuccessors(node))
822 {
824 if (succ_dfn == CycleDepthNumber(0))
825 {
826 min = visit(succ, partition);
827 }
828 else
829 {
830 min = succ_dfn;
831 }
832 if (min <= head)
833 {
834 head = min;
835 loop = true;
836 }
837 }
838
839 if (head == getCDN(node))
840 {
841 setCDN(node, UINT_MAX);
842 const NodeT* element = pop();
843 if (loop)
844 {
845 while (element != node)
846 {
847 setCDN(element, 0);
848 element = pop();
849 }
850 partition.push_front(component(node));
851 }
852 else
853 {
854 partition.push_front(newNode(node));
855 }
856 }
857 return head;
858 }
const NodeT * pop()
Pop a node from the stack.
Definition WTO.h:758
u32_t CycleDepthNumber
Definition WTO.h:538
void setCDN(const NodeT *n, const CycleDepthNumber &dfn)
Set the depth-first number of the given node.
Definition WTO.h:748
void push(const NodeT *n)
Push a node on the stack.
Definition WTO.h:767

Friends And Related Symbol Documentation

◆ operator<<

template<typename GraphT >
std::ostream & operator<< ( std::ostream &  o,
const WTO< GraphT > &  wto 
)
friend

Overloading operator << for dumping ICFG node ID.

Definition at line 665 of file WTO.h.

666 {
667 o << wto.toString();
668 return o;
669 }

Member Data Documentation

◆ _allComponents

template<typename GraphT >
WTOComponentRefSet SVF::WTO< GraphT >::_allComponents
protected

Definition at line 550 of file WTO.h.

◆ _components

template<typename GraphT >
WTOComponentRefList SVF::WTO< GraphT >::_components
protected

Definition at line 549 of file WTO.h.

◆ _entry

template<typename GraphT >
const NodeT* SVF::WTO< GraphT >::_entry
protected

Definition at line 556 of file WTO.h.

◆ _nodeToCDN

template<typename GraphT >
NodeRefToCycleDepthNumber SVF::WTO< GraphT >::_nodeToCDN
protected

Definition at line 553 of file WTO.h.

◆ _nodeToDepth

template<typename GraphT >
NodeRefToWTOCycleDepthPtr SVF::WTO< GraphT >::_nodeToDepth
protected

Definition at line 552 of file WTO.h.

◆ _num

template<typename GraphT >
CycleDepthNumber SVF::WTO< GraphT >::_num
protected

Definition at line 554 of file WTO.h.

◆ _stack

template<typename GraphT >
Stack SVF::WTO< GraphT >::_stack
protected

Definition at line 555 of file WTO.h.

◆ headRefToCycle

template<typename GraphT >
NodeRefToWTOCycleMap SVF::WTO< GraphT >::headRefToCycle
protected

Definition at line 551 of file WTO.h.


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