1 //===-- llvm/Support/DataFlow.h - dataflow as graphs ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines specializations of GraphTraits that allows Use-Def and
11 // Def-Use relations to be treated as proper graphs for generic algorithms.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_DATAFLOW_H
15 #define LLVM_SUPPORT_DATAFLOW_H
17 #include "llvm/User.h"
18 #include "llvm/Value.h"
19 #include "llvm/ADT/GraphTraits.h"
23 //===----------------------------------------------------------------------===//
24 // Provide specializations of GraphTraits to be able to treat def-use/use-def
27 template <> struct GraphTraits<const User*> {
28 typedef const Value NodeType;
29 typedef Value::use_const_iterator ChildIteratorType;
31 static NodeType *getEntryNode(const User *G) {
35 static inline ChildIteratorType child_begin(NodeType *N) {
36 return N->use_begin();
39 static inline ChildIteratorType child_end(NodeType *N) {
44 template <> struct GraphTraits<User*> {
45 typedef Value NodeType;
46 typedef Value::use_iterator ChildIteratorType;
48 static NodeType *getEntryNode(User *G) {
52 static inline ChildIteratorType child_begin(NodeType *N) {
53 return N->use_begin();
56 static inline ChildIteratorType child_end(NodeType *N) {
61 template <> struct GraphTraits<Inverse<const User*> > {
62 typedef const Value NodeType;
63 typedef User::const_op_iterator ChildIteratorType;
65 static NodeType *getEntryNode(Inverse<const User*> G) {
69 static inline ChildIteratorType child_begin(NodeType *N) {
70 if (const User *U = dyn_cast<User>(N))
75 static inline ChildIteratorType child_end(NodeType *N) {
76 if(const User *U = dyn_cast<User>(N))
82 template <> struct GraphTraits<Inverse<User*> > {
83 typedef Value NodeType;
84 typedef User::op_iterator ChildIteratorType;
86 static NodeType *getEntryNode(Inverse<User*> G) {
90 static inline ChildIteratorType child_begin(NodeType *N) {
91 if (User *U = dyn_cast<User>(N))
96 static inline ChildIteratorType child_end(NodeType *N) {
97 if (User *U = dyn_cast<User>(N))