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 516 of file WTO.h.

Member Typedef Documentation

◆ CycleDepthNumber

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

Definition at line 539 of file WTO.h.

◆ EdgeT

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

Definition at line 525 of file WTO.h.

◆ GraphTWTOCycleDepth

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

Definition at line 526 of file WTO.h.

◆ Iterator

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

Iterator over the components.

Definition at line 547 of file WTO.h.

◆ NodeRefList

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

Definition at line 530 of file WTO.h.

◆ NodeRefToCycleDepthNumber

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

Definition at line 540 of file WTO.h.

◆ NodeRefTONodeRefListMap

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

Definition at line 537 of file WTO.h.

◆ NodeRefToWTOCycleDepthPtr

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

Definition at line 543 of file WTO.h.

◆ NodeRefToWTOCycleMap

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

Definition at line 536 of file WTO.h.

◆ NodeT

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

Definition at line 524 of file WTO.h.

◆ Stack

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

Definition at line 541 of file WTO.h.

◆ WTOComponentPtr

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

Definition at line 533 of file WTO.h.

◆ WTOComponentRefList

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

Definition at line 534 of file WTO.h.

◆ WTOComponentRefSet

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

Definition at line 535 of file WTO.h.

◆ WTOComponentT

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

Definition at line 527 of file WTO.h.

◆ WTOCycleDepthPtr

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

Definition at line 542 of file WTO.h.

◆ WTOCycleT

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

Definition at line 529 of file WTO.h.

◆ WTONodeT

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

Definition at line 528 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 562 of file WTO.h.

562 : _num(0), _entry(entry)
563 {
564 }
const NodeT * _entry
Definition WTO.h:557
CycleDepthNumber _num
Definition WTO.h:555

◆ 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 579 of file WTO.h.

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

Member Function Documentation

◆ accept()

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

Accept the given visitor.

Definition at line 637 of file WTO.h.

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

◆ begin()

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

Begin iterator over the components.

Definition at line 594 of file WTO.h.

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

◆ buildNodeToDepth()

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

Build the node to WTO cycle depth table.

Definition at line 862 of file WTO.h.

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

◆ 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 789 of file WTO.h.

790 {
792
793 for (auto succ: getSuccessors(node))
794 {
795 if (getCDN(succ) == 0)
796 {
798 }
799 }
800 const WTONodeT* head = newNode(node);
801 const WTOCycleT* ptr = newCycle(head, partition);
802 headRefToCycle.emplace(node, ptr);
803 return ptr;
804 }
virtual CycleDepthNumber visit(const NodeT *node, WTOComponentRefList &partition)
Definition WTO.h:809
NodeRefToWTOCycleMap headRefToCycle
Definition WTO.h:552
const WTOCycleT * newCycle(const WTONodeT *node, const WTOComponentRefList &partition)
Definition WTO.h:780
WTOCycle< GraphT > WTOCycleT
Definition WTO.h:529
CycleDepthNumber getCDN(const NodeT *n) const
Return the depth-first number of the given node.
Definition WTO.h:735
virtual std::vector< const NodeT * > getSuccessors(const NodeT *node)
Return the successors of node.
Definition WTO.h:723
WTONode< GraphT > WTONodeT
Definition WTO.h:528
std::list< WTOComponentPtr > WTOComponentRefList
Definition WTO.h:534
const WTONodeT * newNode(const NodeT *node)
Definition WTO.h:773

◆ 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 622 of file WTO.h.

623 {
624 auto it = _nodeToDepth.find(n);
625 assert(it != _nodeToDepth.end() && "node not found");
626 return *(it->second);
627 }
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 600 of file WTO.h.

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

◆ 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 735 of file WTO.h.

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

◆ 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 723 of file WTO.h.

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

◆ getWTOComponents()

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

Get all wto components in WTO.

Definition at line 588 of file WTO.h.

589 {
590 return _components;
591 }

◆ headBegin()

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

Definition at line 610 of file WTO.h.

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

◆ headEnd()

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

End iterator over the components.

Definition at line 616 of file WTO.h.

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

◆ 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 630 of file WTO.h.

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

◆ init()

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

Definition at line 673 of file WTO.h.

674 {
676 _nodeToCDN.clear();
677 _stack.clear();
679 }
Stack _stack
Definition WTO.h:556
void buildNodeToDepth()
Build the node to WTO cycle depth table.
Definition WTO.h:862

◆ isHead()

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

Definition at line 605 of file WTO.h.

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

◆ newCycle()

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

Definition at line 780 of file WTO.h.

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

◆ newNode()

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

Definition at line 773 of file WTO.h.

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

◆ 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 759 of file WTO.h.

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

◆ push()

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

Push a node on the stack.

Definition at line 768 of file WTO.h.

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

◆ 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 749 of file WTO.h.

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

◆ toString()

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

Dump the order, for debugging purpose.

Definition at line 646 of file WTO.h.

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

◆ 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 809 of file WTO.h.

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

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 666 of file WTO.h.

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

Member Data Documentation

◆ _allComponents

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

Definition at line 551 of file WTO.h.

◆ _components

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

Definition at line 550 of file WTO.h.

◆ _entry

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

Definition at line 557 of file WTO.h.

◆ _nodeToCDN

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

Definition at line 554 of file WTO.h.

◆ _nodeToDepth

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

Definition at line 553 of file WTO.h.

◆ _num

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

Definition at line 555 of file WTO.h.

◆ _stack

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

Definition at line 556 of file WTO.h.

◆ headRefToCycle

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

Definition at line 552 of file WTO.h.


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