Static Value-Flow Analysis
WTO.h
Go to the documentation of this file.
1 //===- WTO.h -- Weakest Topological Order Analysis-------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * WTO.h
25  *
26  * The implementation is based on F. Bourdoncle's paper:
27  * "Efficient chaotic iteration strategies with widenings", Formal
28  * Methods in Programming and Their Applications, 1993, pages 128-141.
29  *
30  * Created on: Jan 22, 2024
31  * Author: Xiao Cheng, Jiawei Wang
32  *
33  */
34 #ifndef WTO_H_
35 #define WTO_H_
36 
37 #include "SVFIR/SVFType.h"
38 #include "SVFIR/SVFValue.h"
39 #include <functional>
40 
41 namespace SVF
42 {
43 
44 template <typename GraphT> class WTO;
45 
46 template <typename GraphT> class WTONode;
47 
48 template <typename GraphT> class WTOCycle;
49 
50 template <typename GraphT> class WTOComponentVisitor;
51 
52 // Helper to test for the existence of a sub type
53 template <typename T, typename = void> struct has_nodetype : std::false_type
54 {
55 };
56 
57 template <typename T>
58 struct has_nodetype<T, std::void_t<typename T::NodeType>> : std::true_type
59 {
60 };
61 
62 template <typename T, typename = void> struct has_edgetype : std::false_type
63 {
64 };
65 
66 template <typename T>
67 struct has_edgetype<T, std::void_t<typename T::EdgeType>> : std::true_type
68 {
69 };
70 
101 template <typename GraphT> class WTOCycleDepth
102 {
103 public:
104  static_assert(has_nodetype<GraphT>::value,
105  "GraphT must have a nested type named 'NodeType'");
106  typedef typename GraphT::NodeType NodeT;
107 
108 private:
109  typedef std::vector<const NodeT*> NodeRefList;
110 
111 public:
112  typedef typename NodeRefList::const_iterator Iterator;
113 
114 private:
116 
117 public:
119  WTOCycleDepth() = default;
120 
122  WTOCycleDepth(const WTOCycleDepth&) = default;
123 
126 
129 
132 
134  ~WTOCycleDepth() = default;
135 
137  void add(const NodeT* head)
138  {
139  _heads.push_back(head);
140  }
141 
143  Iterator begin() const
144  {
145  return _heads.cbegin();
146  }
147 
149  Iterator end() const
150  {
151  return _heads.cend();
152  }
153 
156  {
157  WTOCycleDepth res;
158  for (auto this_it = begin(), other_it = other.begin();
159  this_it != end() && other_it != other.end(); ++this_it, ++other_it)
160  {
161  if (*this_it == *other_it)
162  {
163  res.add(*this_it);
164  }
165  else
166  {
167  break;
168  }
169  }
170  return res;
171  }
172 
173 private:
175  int compare(const WTOCycleDepth& other) const
176  {
177  if (this == &other)
178  {
179  return 0; // equals
180  }
181 
182  auto this_it = begin();
183  auto other_it = other.begin();
184  while (this_it != end())
185  {
186  if (other_it == other.end())
187  {
188  return 1; // `this` is nested within `other`
189  }
190  else if (*this_it == *other_it)
191  {
192  ++this_it;
193  ++other_it;
194  }
195  else
196  {
197  return 2; // not comparable
198  }
199  }
200  if (other_it == other.end())
201  {
202  return 0; // equals
203  }
204  else
205  {
206  return -1; // `other` is nested within `this`
207  }
208  }
209 
210 public:
211  bool operator<(const WTOCycleDepth& other) const
212  {
213  return compare(other) == -1;
214  }
215 
216  bool operator<=(const WTOCycleDepth& other) const
217  {
218  return compare(other) <= 0;
219  }
220 
221  bool operator==(const WTOCycleDepth& other) const
222  {
223  return compare(other) == 0;
224  }
225 
226  bool operator>=(const WTOCycleDepth& other) const
227  {
228  return operator<=(other, *this);
229  }
230 
231  bool operator>(const WTOCycleDepth& other) const
232  {
233  return compare(other) == 1;
234  }
235 
237  [[nodiscard]] std::string toString() const
238  {
239  std::string str;
240  std::stringstream rawstr(str);
241  rawstr << "[";
242  for (auto it = begin(), et = end(); it != et;)
243  {
244  rawstr << (*it)->toString();
245  ++it;
246  if (it != et)
247  {
248  rawstr << ", ";
249  }
250  }
251  rawstr << "]";
252  return rawstr.str();
253  }
254 
256 
257  friend std::ostream& operator<<(std::ostream& o,
258  const WTOCycleDepth<GraphT>& wto)
259  {
260  o << wto.toString();
261  return o;
262  }
264 
265 }; // end class WTOCycleDepth
266 
272 template <typename GraphT> class WTOComponent
273 {
274 public:
275  enum WTOCT
276  {
278  Cycle
279  };
280 
282  explicit WTOComponent(WTOCT k) : _type(k) {};
283 
285  WTOComponent(const WTOComponent&) noexcept = default;
286 
288  WTOComponent(WTOComponent&&) noexcept = default;
289 
291  WTOComponent& operator=(const WTOComponent&) noexcept = default;
292 
294  WTOComponent& operator=(WTOComponent&&) noexcept = default;
295 
297  virtual void accept(WTOComponentVisitor<GraphT>&) const = 0;
298 
300  virtual ~WTOComponent() = default;
301 
302  inline WTOCT getKind() const
303  {
304  return _type;
305  }
306 
307  [[nodiscard]] virtual std::string toString() const = 0;
308 
310 
311  friend std::ostream& operator<<(std::ostream& o,
312  const WTOComponent<GraphT>& wto)
313  {
314  o << wto.toString();
315  return o;
316  }
318 
320 
321 }; // end class WTOComponent
322 
326 template <typename GraphT> class WTONode final : public WTOComponent<GraphT>
327 {
328 public:
329  static_assert(has_nodetype<GraphT>::value,
330  "GraphT must have a nested type named 'NodeType'");
331  typedef typename GraphT::NodeType NodeT;
332 
333 private:
334  const NodeT* _node;
335 
336 public:
338  explicit WTONode(const NodeT* node)
339  : WTOComponent<GraphT>(WTOComponent<GraphT>::Node), _node(node)
340  {
341  }
342 
344  const NodeT* getICFGNode() const
345  {
346  return _node;
347  }
348 
350  void accept(WTOComponentVisitor<GraphT>& v) const override
351  {
352  v.visit(*this);
353  }
354 
356  [[nodiscard]] std::string toString() const override
357  {
358  // return _node->toString();
359  return std::to_string(_node->getId());
360  }
361 
363 
364  static inline bool classof(const WTONode<GraphT>*)
365  {
366  return true;
367  }
368 
369  static inline bool classof(const WTOComponent<GraphT>* c)
370  {
371  return c->getKind() == WTOComponent<GraphT>::Node;
372  }
374 
375 }; // end class WTONode
376 
380 template <typename GraphT> class WTOCycle final : public WTOComponent<GraphT>
381 {
382 public:
383  static_assert(has_nodetype<GraphT>::value,
384  "GraphT must have a nested type named 'NodeType'");
385  typedef typename GraphT::NodeType NodeT;
387 
388 private:
390  typedef std::list<WTOComponentPtr> WTOComponentRefList;
391 
392 public:
394  typedef typename WTOComponentRefList::const_iterator Iterator;
395 
396 private:
399 
402 
403 public:
406  : WTOComponent<GraphT>(WTOComponent<GraphT>::Cycle), _head(head),
407  _components(std::move(components))
408  {
409  }
410 
412  const WTONode<GraphT>* head() const
413  {
414  return _head;
415  }
416 
419  {
420  return _components;
421  }
422 
424  Iterator begin() const
425  {
426  return _components.cbegin();
427  }
428 
430  Iterator end() const
431  {
432  return _components.cend();
433  }
434 
436  void accept(WTOComponentVisitor<GraphT>& v) const override
437  {
438  v.visit(*this);
439  }
440 
442 
443  static inline bool classof(const WTOCycle<GraphT>*)
444  {
445  return true;
446  }
447 
448  static inline bool classof(const WTOComponent<GraphT>* c)
449  {
450  return c->getKind() == WTOComponent<GraphT>::Cycle;
451  }
453 
455  [[nodiscard]] std::string toString() const override
456  {
457  std::string str;
458  std::stringstream rawstr(str);
459  rawstr << "(";
460  rawstr << _head->getICFGNode()->getId() << ", ";
461  for (auto it = begin(), et = end(); it != et;)
462  {
463  rawstr << (*it)->toString();
464  ++it;
465  if (it != et)
466  {
467  rawstr << ", ";
468  }
469  }
470  rawstr << ")";
471  return rawstr.str();
472  }
473 
474 }; // end class WTOCycle
475 
479 template <typename GraphT> class WTOComponentVisitor
480 {
481 public:
484 
485 public:
487  WTOComponentVisitor() = default;
488 
490  WTOComponentVisitor(const WTOComponentVisitor&) noexcept = default;
491 
494 
496  WTOComponentVisitor& operator=(const WTOComponentVisitor&) noexcept =
497  default;
498 
500  WTOComponentVisitor& operator=(WTOComponentVisitor&&) noexcept = default;
501 
503  virtual void visit(const WTONodeT&) = 0;
504 
506  virtual void visit(const WTOCycleT&) = 0;
507 
509  virtual ~WTOComponentVisitor() = default;
510 
511 }; // end class WTOComponentVisitor
512 
516 template <typename GraphT> class WTO
517 {
518 
519 public:
520  static_assert(has_nodetype<GraphT>::value,
521  "GraphT must have a nested type named 'NodeType'");
522  static_assert(has_edgetype<GraphT>::value,
523  "GraphT must have a nested type named 'EdgeType'");
524  typedef typename GraphT::NodeType NodeT;
525  typedef typename GraphT::EdgeType EdgeT;
531 
532 protected:
534  typedef std::list<WTOComponentPtr> WTOComponentRefList;
538 
541  typedef std::vector<const NodeT*> Stack;
542  typedef std::shared_ptr<GraphTWTOCycleDepth> WTOCycleDepthPtr;
544 
545 public:
547  typedef typename WTOComponentRefList::const_iterator Iterator;
548 
549 protected:
557  GraphT* _graph;
558  const NodeT* _entry;
559 
560 public:
561 
563  explicit WTO(GraphT* graph, const NodeT* entry) : _num(0), _graph(graph), _entry(entry)
564  {
565  }
566 
568  WTO(const WTO& other) = default;
569 
571  WTO(WTO&& other) = default;
572 
574  WTO& operator=(const WTO& other) = default;
575 
577  WTO& operator=(WTO&& other) = default;
578 
581  {
582  for (const auto& component : _allComponents)
583  {
584  delete component;
585  }
586  }
587 
590  {
591  return _components;
592  }
593 
595  Iterator begin() const
596  {
597  return _components.cbegin();
598  }
599 
601  Iterator end() const
602  {
603  return _components.cend();
604  }
605 
606  bool isHead(const NodeT* node) const
607  {
608  return headRefToCycle.find(node) != headRefToCycle.end();
609  }
610 
611  typename NodeRefToWTOCycleMap::const_iterator headBegin() const
612  {
613  return headRefToCycle.cbegin();
614  }
615 
617  typename NodeRefToWTOCycleMap::const_iterator headEnd() const
618  {
619  return headRefToCycle.cend();
620  }
621 
623  const GraphTWTOCycleDepth& cycleDepth(const NodeT* n) const
624  {
625  auto it = _nodeToDepth.find(n);
626  assert(it != _nodeToDepth.end() && "node not found");
627  return *(it->second);
628  }
629 
631  inline bool in_cycleDepth_table(const NodeT* n) const
632  {
633  auto it = _nodeToDepth.find(n);
634  return it != _nodeToDepth.end();
635  }
636 
639  {
640  for (const auto& c : _components)
641  {
642  c->accept(v);
643  }
644  }
645 
647  [[nodiscard]] std::string toString() const
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  }
664 
666 
667  friend std::ostream& operator<<(std::ostream& o, const WTO<GraphT>& wto)
668  {
669  o << wto.toString();
670  return o;
671  }
673 
674  void init()
675  {
676  visit(_entry, _components);
677  _nodeToCDN.clear();
678  _stack.clear();
679  buildNodeToDepth();
680  }
681 
682 protected:
683 
685  class WTOCycleDepthBuilder final : public WTOComponentVisitor<GraphT>
686  {
687  private:
690 
691  public:
693  NodeRefToWTOCycleDepthPtr& nodeToWTOCycleDepth)
694  : _wtoCycleDepth(std::make_shared<GraphTWTOCycleDepth>()),
695  _nodeToWTOCycleDepth(nodeToWTOCycleDepth)
696  {
697  }
698 
699  void visit(const WTOCycleT& cycle) override
700  {
701  const NodeT* head = cycle.head()->getICFGNode();
702  WTOCycleDepthPtr previous_cycleDepth = _wtoCycleDepth;
703  _nodeToWTOCycleDepth.insert(std::make_pair(head, _wtoCycleDepth));
704  _wtoCycleDepth =
705  std::make_shared<GraphTWTOCycleDepth>(*_wtoCycleDepth);
706  _wtoCycleDepth->add(head);
707  for (auto it = cycle.begin(), et = cycle.end(); it != et; ++it)
708  {
709  (*it)->accept(*this);
710  }
711  _wtoCycleDepth = previous_cycleDepth;
712  }
713 
714  void visit(const WTONodeT& node) override
715  {
716  _nodeToWTOCycleDepth.insert(
717  std::make_pair(node.getICFGNode(), _wtoCycleDepth));
718  }
719 
720  }; // end class WTOCycleDepthBuilder
721 
722 protected:
723 
724  inline virtual void forEachSuccessor(const NodeT* node, std::function<void(const NodeT*)> func) const
725  {
726  for (const auto& e : node->getOutEdges())
727  {
728  func(e->getDstNode());
729  }
730  }
731 
732 protected:
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  }
746 
748  void setCDN(const NodeT* n, const CycleDepthNumber& dfn)
749  {
750  auto res = _nodeToCDN.insert(std::make_pair(n, dfn));
751  if (!res.second)
752  {
753  (res.first)->second = dfn;
754  }
755  }
756 
758  const NodeT* pop()
759  {
760  assert(!_stack.empty() && "empty stack");
761  const NodeT* top = _stack.back();
762  _stack.pop_back();
763  return top;
764  }
765 
767  void push(const NodeT* n)
768  {
769  _stack.push_back(n);
770  }
771 
772  const WTONodeT* newNode(const NodeT* node)
773  {
774  const WTONodeT* ptr = new WTONodeT(node);
775  _allComponents.insert(ptr);
776  return ptr;
777  }
778 
779  const WTOCycleT* newCycle(const WTONodeT* node,
780  const WTOComponentRefList& partition)
781  {
782  const WTOCycleT* ptr = new WTOCycleT(node, std::move(partition));
783  _allComponents.insert(ptr);
784  return ptr;
785  }
786 
788  virtual const WTOCycleT* component(const NodeT* node)
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  }
803 
807  virtual CycleDepthNumber visit(const NodeT* node,
808  WTOComponentRefList& partition)
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  }
857 
860  {
861  WTOCycleDepthBuilder builder(_nodeToDepth);
862  for (auto it = begin(), et = end(); it != et; ++it)
863  {
864  (*it)->accept(builder);
865  }
866  }
867 
868 }; // end class WTO
869 
870 } // namespace SVF
871 
872 #endif /* WTO_H_ */
cJSON * n
Definition: cJSON.cpp:2558
const char *const string
Definition: cJSON.h:172
virtual void visit(const WTONodeT &)=0
Visit the given node.
WTOComponentVisitor(WTOComponentVisitor &&) noexcept=default
Move constructor.
WTOComponentVisitor(const WTOComponentVisitor &) noexcept=default
Copy constructor.
WTOComponentVisitor()=default
Default constructor.
WTONode< GraphT > WTONodeT
Definition: WTO.h:482
WTOCycle< GraphT > WTOCycleT
Definition: WTO.h:483
virtual std::string toString() const =0
WTOCT _type
Definition: WTO.h:319
virtual void accept(WTOComponentVisitor< GraphT > &) const =0
Accept the given visitor.
WTOComponent(WTOCT k)
Default constructor.
Definition: WTO.h:282
WTOComponent(const WTOComponent &) noexcept=default
Copy constructor.
friend std::ostream & operator<<(std::ostream &o, const WTOComponent< GraphT > &wto)
Overloading operator << for dumping ICFG node ID.
Definition: WTO.h:311
WTOCT getKind() const
Definition: WTO.h:302
WTOComponent(WTOComponent &&) noexcept=default
Move constructor.
Iterator begin() const
Begin iterator over the head of cycles.
Definition: WTO.h:143
bool operator>=(const WTOCycleDepth &other) const
Definition: WTO.h:226
~WTOCycleDepth()=default
Destructor.
Iterator end() const
End iterator over the head of cycles.
Definition: WTO.h:149
std::string toString() const
Dump the cycleDepth, for debugging purpose.
Definition: WTO.h:237
bool operator<=(const WTOCycleDepth &other) const
Definition: WTO.h:216
NodeRefList::const_iterator Iterator
Definition: WTO.h:112
bool operator<(const WTOCycleDepth &other) const
Definition: WTO.h:211
bool operator==(const WTOCycleDepth &other) const
Definition: WTO.h:221
WTOCycleDepth(WTOCycleDepth &&)=default
Move constructor.
friend std::ostream & operator<<(std::ostream &o, const WTOCycleDepth< GraphT > &wto)
Overloading operator << for dumping ICFG node ID.
Definition: WTO.h:257
WTOCycleDepth & operator=(WTOCycleDepth &&)=default
Move assignment operator.
NodeRefList _heads
Definition: WTO.h:115
WTOCycleDepth(const WTOCycleDepth &)=default
Copy constructor.
bool operator>(const WTOCycleDepth &other) const
Definition: WTO.h:231
void add(const NodeT *head)
Add a cycle head in the cycleDepth.
Definition: WTO.h:137
WTOCycleDepth()=default
Constructor.
GraphT::NodeType NodeT
Definition: WTO.h:105
WTOCycleDepth operator^(const WTOCycleDepth &other) const
Return the common prefix of the given cycle depths.
Definition: WTO.h:155
WTOCycleDepth & operator=(const WTOCycleDepth &)=default
Copy assignment operator.
std::vector< const NodeT * > NodeRefList
Definition: WTO.h:109
int compare(const WTOCycleDepth &other) const
Compare the given cycle depths.
Definition: WTO.h:175
static bool classof(const WTOComponent< GraphT > *c)
Definition: WTO.h:448
Iterator end() const
End iterator over the components.
Definition: WTO.h:430
std::list< WTOComponentPtr > WTOComponentRefList
Definition: WTO.h:390
GraphT::NodeType NodeT
Definition: WTO.h:384
const WTONode< GraphT > * head() const
Return the head of the cycle.
Definition: WTO.h:412
const WTOComponentT * WTOComponentPtr
Definition: WTO.h:389
const WTOComponentRefList & getWTOComponents() const
Get all wto components in WTO cycle.
Definition: WTO.h:418
std::string toString() const override
Dump the cycle, for debugging purpose.
Definition: WTO.h:455
const WTONode< GraphT > * _head
Head of the cycle.
Definition: WTO.h:398
Iterator begin() const
Begin iterator over the components.
Definition: WTO.h:424
WTOComponentRefList _components
List of components.
Definition: WTO.h:401
void accept(WTOComponentVisitor< GraphT > &v) const override
Accept the given visitor.
Definition: WTO.h:436
WTOComponentRefList::const_iterator Iterator
Iterator over the components.
Definition: WTO.h:394
WTOComponent< GraphT > WTOComponentT
Definition: WTO.h:386
static bool classof(const WTOCycle< GraphT > *)
ClassOf.
Definition: WTO.h:443
WTOCycle(const WTONode< GraphT > *head, WTOComponentRefList components)
Constructor.
Definition: WTO.h:405
void accept(WTOComponentVisitor< GraphT > &v) const override
Accept the given visitor.
Definition: WTO.h:350
static bool classof(const WTONode< GraphT > *)
ClassOf.
Definition: WTO.h:364
GraphT::NodeType NodeT
Definition: WTO.h:330
std::string toString() const override
Dump the node, for debugging purpose.
Definition: WTO.h:356
const NodeT * _node
Definition: WTO.h:334
const NodeT * getICFGNode() const
Return the graph node.
Definition: WTO.h:344
WTONode(const NodeT *node)
Constructor.
Definition: WTO.h:338
static bool classof(const WTOComponent< GraphT > *c)
Definition: WTO.h:369
Visitor to build the cycle depths of each node.
Definition: WTO.h:686
void visit(const WTONodeT &node) override
Visit the given node.
Definition: WTO.h:714
WTOCycleDepthBuilder(NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth)
Definition: WTO.h:692
NodeRefToWTOCycleDepthPtr & _nodeToWTOCycleDepth
Definition: WTO.h:689
void visit(const WTOCycleT &cycle) override
Visit the given cycle.
Definition: WTO.h:699
WTOCycleDepthPtr _wtoCycleDepth
Definition: WTO.h:688
Definition: WTO.h:517
WTO(WTO &&other)=default
Move constructor.
const WTOComponentRefList & getWTOComponents() const
Get all wto components in WTO.
Definition: WTO.h:589
void init()
Definition: WTO.h:674
Iterator begin() const
Begin iterator over the components.
Definition: WTO.h:595
const WTOCycleT * newCycle(const WTONodeT *node, const WTOComponentRefList &partition)
Definition: WTO.h:779
bool in_cycleDepth_table(const NodeT *n) const
Return the cycleDepth of the given node.
Definition: WTO.h:631
std::string toString() const
Dump the order, for debugging purpose.
Definition: WTO.h:647
Iterator end() const
End iterator over the components.
Definition: WTO.h:601
const WTONodeT * newNode(const NodeT *node)
Definition: WTO.h:772
Stack _stack
Definition: WTO.h:556
WTOComponent< GraphT > WTOComponentT
Definition: WTO.h:527
WTOComponentRefList::const_iterator Iterator
Iterator over the components.
Definition: WTO.h:547
Map< const NodeT *, WTOCycleDepthPtr > NodeRefToWTOCycleDepthPtr
Definition: WTO.h:543
u32_t CycleDepthNumber
Definition: WTO.h:539
NodeRefToCycleDepthNumber _nodeToCDN
Definition: WTO.h:554
virtual CycleDepthNumber visit(const NodeT *node, WTOComponentRefList &partition)
Definition: WTO.h:807
NodeRefToWTOCycleMap headRefToCycle
Definition: WTO.h:552
const NodeT * _entry
Definition: WTO.h:558
bool isHead(const NodeT *node) const
Definition: WTO.h:606
GraphT::EdgeType EdgeT
Definition: WTO.h:525
NodeRefToWTOCycleMap::const_iterator headBegin() const
Definition: WTO.h:611
WTOComponentRefSet _allComponents
Definition: WTO.h:551
virtual void forEachSuccessor(const NodeT *node, std::function< void(const NodeT *)> func) const
Definition: WTO.h:724
WTOCycle< GraphT > WTOCycleT
Definition: WTO.h:529
WTO(GraphT *graph, const NodeT *entry)
Compute the weak topological order of the given graph.
Definition: WTO.h:563
~WTO()
Destructor.
Definition: WTO.h:580
GraphT::NodeType NodeT
Definition: WTO.h:521
Set< const NodeT * > NodeRefList
Definition: WTO.h:530
void setCDN(const NodeT *n, const CycleDepthNumber &dfn)
Set the depth-first number of the given node.
Definition: WTO.h:748
std::shared_ptr< GraphTWTOCycleDepth > WTOCycleDepthPtr
Definition: WTO.h:542
WTO(const WTO &other)=default
No copy constructor.
virtual const WTOCycleT * component(const NodeT *node)
Create the cycle component for the given node.
Definition: WTO.h:788
Map< const NodeT *, const WTOCycleT * > NodeRefToWTOCycleMap
Definition: WTO.h:536
CycleDepthNumber getCDN(const NodeT *n) const
Return the depth-first number of the given node.
Definition: WTO.h:734
Set< WTOComponentPtr > WTOComponentRefSet
Definition: WTO.h:535
friend std::ostream & operator<<(std::ostream &o, const WTO< GraphT > &wto)
Overloading operator << for dumping ICFG node ID.
Definition: WTO.h:667
Map< const NodeT *, CycleDepthNumber > NodeRefToCycleDepthNumber
Definition: WTO.h:540
WTONode< GraphT > WTONodeT
Definition: WTO.h:528
void push(const NodeT *n)
Push a node on the stack.
Definition: WTO.h:767
const GraphTWTOCycleDepth & cycleDepth(const NodeT *n) const
Return the cycleDepth of the given node.
Definition: WTO.h:623
std::vector< const NodeT * > Stack
Definition: WTO.h:541
NodeRefToWTOCycleDepthPtr _nodeToDepth
Definition: WTO.h:553
const WTOComponentT * WTOComponentPtr
Definition: WTO.h:533
void buildNodeToDepth()
Build the node to WTO cycle depth table.
Definition: WTO.h:859
std::list< WTOComponentPtr > WTOComponentRefList
Definition: WTO.h:534
WTO & operator=(const WTO &other)=default
No copy assignment operator.
WTOComponentRefList _components
Definition: WTO.h:550
NodeRefToWTOCycleMap::const_iterator headEnd() const
End iterator over the components.
Definition: WTO.h:617
WTO & operator=(WTO &&other)=default
Move assignment operator.
WTOCycleDepth< GraphT > GraphTWTOCycleDepth
Definition: WTO.h:526
Map< const NodeT *, NodeRefList > NodeRefTONodeRefListMap
Definition: WTO.h:537
const NodeT * pop()
Pop a node from the stack.
Definition: WTO.h:758
GraphT * _graph
Definition: WTO.h:557
void accept(WTOComponentVisitor< GraphT > &v)
Accept the given visitor.
Definition: WTO.h:638
CycleDepthNumber _num
Definition: WTO.h:555
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
Definition: SVFUtil.h:447
typename make_void< Ts... >::type void_t
Definition: SVFUtil.h:457
for isBitcode
Definition: BasicTypes.h:68
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101
unsigned u32_t
Definition: GeneralType.h:46
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96