Static Value-Flow Analysis
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< GraphT > GraphTWTOCycleDepth
 
typedef WTOComponent< GraphT > WTOComponentT
 
typedef WTONode< GraphT > WTONodeT
 
typedef WTOCycle< GraphT > WTOCycleT
 
typedef Set< const NodeT * > NodeRefList
 
typedef WTOComponentRefList::const_iterator Iterator
 Iterator over the components. More...
 

Public Member Functions

 WTO (GraphT *graph, const NodeT *entry)
 Compute the weak topological order of the given graph. More...
 
 WTO (const WTO &other)=default
 No copy constructor. More...
 
 WTO (WTO &&other)=default
 Move constructor. More...
 
WTOoperator= (const WTO &other)=default
 No copy assignment operator. More...
 
WTOoperator= (WTO &&other)=default
 Move assignment operator. More...
 
 ~WTO ()
 Destructor. More...
 
const WTOComponentRefListgetWTOComponents () const
 Get all wto components in WTO. More...
 
Iterator begin () const
 Begin iterator over the components. More...
 
Iterator end () const
 End iterator over the components. More...
 
bool isHead (const NodeT *node) const
 
NodeRefToWTOCycleMap::const_iterator headBegin () const
 
NodeRefToWTOCycleMap::const_iterator headEnd () const
 End iterator over the components. More...
 
const GraphTWTOCycleDepthcycleDepth (const NodeT *n) const
 Return the cycleDepth of the given node. More...
 
bool in_cycleDepth_table (const NodeT *n) const
 Return the cycleDepth of the given node. More...
 
void accept (WTOComponentVisitor< GraphT > &v)
 Accept the given visitor. More...
 
std::string toString () const
 Dump the order, for debugging purpose. More...
 
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 void forEachSuccessor (const NodeT *node, std::function< void(const NodeT *)> func) const
 
CycleDepthNumber getCDN (const NodeT *n) const
 Return the depth-first number of the given node. More...
 
void setCDN (const NodeT *n, const CycleDepthNumber &dfn)
 Set the depth-first number of the given node. More...
 
const NodeTpop ()
 Pop a node from the stack. More...
 
void push (const NodeT *n)
 Push a node on the stack. More...
 
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. More...
 
virtual CycleDepthNumber visit (const NodeT *node, WTOComponentRefList &partition)
 
void buildNodeToDepth ()
 Build the node to WTO cycle depth table. More...
 

Protected Attributes

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

Friends

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

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 ( GraphT *  graph,
const NodeT entry 
)
inlineexplicit

Compute the weak topological order of the given graph.

Definition at line 563 of file WTO.h.

563  : _num(0), _graph(graph), _entry(entry)
564  {
565  }
const NodeT * _entry
Definition: WTO.h:558
GraphT * _graph
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 580 of file WTO.h.

581  {
582  for (const auto& component : _allComponents)
583  {
584  delete component;
585  }
586  }
WTOComponentRefSet _allComponents
Definition: WTO.h:551
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 638 of file WTO.h.

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

◆ begin()

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

Begin iterator over the components.

Definition at line 595 of file WTO.h.

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

◆ buildNodeToDepth()

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

Build the node to WTO cycle depth table.

Definition at line 859 of file WTO.h.

860  {
861  WTOCycleDepthBuilder builder(_nodeToDepth);
862  for (auto it = begin(), et = end(); it != et; ++it)
863  {
864  (*it)->accept(builder);
865  }
866  }
Iterator begin() const
Begin iterator over the components.
Definition: WTO.h:595
Iterator end() const
End iterator over the components.
Definition: WTO.h:601
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 788 of file WTO.h.

789  {
790  WTOComponentRefList partition;
791  forEachSuccessor(node, [&](const NodeT* succ)
792  {
793  if (getCDN(succ) == 0)
794  {
795  visit(succ, partition);
796  }
797  });
798  const WTONodeT* head = newNode(node);
799  const WTOCycleT* ptr = newCycle(head, partition);
800  headRefToCycle.emplace(node, ptr);
801  return ptr;
802  }
const WTOCycleT * newCycle(const WTONodeT *node, const WTOComponentRefList &partition)
Definition: WTO.h:779
const WTONodeT * newNode(const NodeT *node)
Definition: WTO.h:772
virtual CycleDepthNumber visit(const NodeT *node, WTOComponentRefList &partition)
Definition: WTO.h:807
NodeRefToWTOCycleMap headRefToCycle
Definition: WTO.h:552
virtual void forEachSuccessor(const NodeT *node, std::function< void(const NodeT *)> func) const
Definition: WTO.h:724
WTOCycle< GraphT > WTOCycleT
Definition: WTO.h:529
GraphT::NodeType NodeT
Definition: WTO.h:521
CycleDepthNumber getCDN(const NodeT *n) const
Return the depth-first number of the given node.
Definition: WTO.h:734
WTONode< GraphT > WTONodeT
Definition: WTO.h:528
std::list< WTOComponentPtr > WTOComponentRefList
Definition: WTO.h:534

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

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

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

◆ forEachSuccessor()

template<typename GraphT >
virtual void SVF::WTO< GraphT >::forEachSuccessor ( const NodeT node,
std::function< void(const NodeT *)>  func 
) const
inlineprotectedvirtual

Definition at line 724 of file WTO.h.

725  {
726  for (const auto& e : node->getOutEdges())
727  {
728  func(e->getDstNode());
729  }
730  }

◆ 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:554

◆ getWTOComponents()

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

Get all wto components in WTO.

Definition at line 589 of file WTO.h.

590  {
591  return _components;
592  }

◆ headBegin()

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

Definition at line 611 of file WTO.h.

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

◆ headEnd()

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

End iterator over the components.

Definition at line 617 of file WTO.h.

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

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

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

◆ init()

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

Definition at line 674 of file WTO.h.

675  {
677  _nodeToCDN.clear();
678  _stack.clear();
680  }
Stack _stack
Definition: WTO.h:556
void buildNodeToDepth()
Build the node to WTO cycle depth table.
Definition: WTO.h:859

◆ isHead()

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

Definition at line 606 of file WTO.h.

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

◆ 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  }
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
Definition: SVFUtil.h:447

◆ 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  }

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

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

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

809  {
810  CycleDepthNumber head(0);
811  CycleDepthNumber min(0);
812  bool loop;
813 
814  push(node);
815  _num += CycleDepthNumber(1);
816  head = _num;
817  setCDN(node, head);
818  loop = false;
819  forEachSuccessor(node, [&](const NodeT* succ)
820  {
821  CycleDepthNumber succ_dfn = getCDN(succ);
822  if (succ_dfn == CycleDepthNumber(0))
823  {
824  min = visit(succ, partition);
825  }
826  else
827  {
828  min = succ_dfn;
829  }
830  if (min <= head)
831  {
832  head = min;
833  loop = true;
834  }
835  });
836 
837  if (head == getCDN(node))
838  {
839  setCDN(node, UINT_MAX);
840  const NodeT* element = pop();
841  if (loop)
842  {
843  while (element != node)
844  {
845  setCDN(element, 0);
846  element = pop();
847  }
848  partition.push_front(component(node));
849  }
850  else
851  {
852  partition.push_front(newNode(node));
853  }
854  }
855  return head;
856  }
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:748
void push(const NodeT *n)
Push a node on the stack.
Definition: WTO.h:767
const NodeT * pop()
Pop a node from the stack.
Definition: WTO.h:758

Friends And Related Function 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 667 of file WTO.h.

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

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

◆ _graph

template<typename GraphT >
GraphT* SVF::WTO< GraphT >::_graph
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: