llvm.org GIT mirror llvm / 56c2f99
Add new file Support/DataFlow.h. It allows Use-Def and Def-Use relations to be treated as graphs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49088 91177308-0d34-0410-b5e6-96231b3b80d8 Torok Edwin 12 years ago
1 changed file(s) with 104 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===-- llvm/Support/DataFlow.h - dataflow as graphs ------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines specializations of GraphTraits that allows Use-Def and
10 // Def-Use relations to be treated as proper graphs for generic algorithms.
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SUPPORT_DATAFLOW_H
14 #define LLVM_SUPPORT_DATAFLOW_H
15
16 #include "llvm/User.h"
17 #include "llvm/Value.h"
18 #include "llvm/ADT/GraphTraits.h"
19
20 namespace llvm {
21
22 //===----------------------------------------------------------------------===//
23 // Provide specializations of GraphTraits to be able to treat def-use/use-def
24 // chains as graphs
25
26 template <> struct GraphTraits {
27 typedef const Value NodeType;
28 typedef Value::use_const_iterator ChildIteratorType;
29
30 static NodeType *getEntryNode(const User *G) {
31 return G;
32 }
33
34 static inline ChildIteratorType child_begin(NodeType *N) {
35 return N->use_begin();
36 }
37
38 static inline ChildIteratorType child_end(NodeType *N) {
39 return N->use_end();
40 }
41 };
42
43 template <> struct GraphTraits {
44 typedef Value NodeType;
45 typedef Value::use_iterator ChildIteratorType;
46
47 static NodeType *getEntryNode(User *G) {
48 return G;
49 }
50
51 static inline ChildIteratorType child_begin(NodeType *N) {
52 return N->use_begin();
53 }
54
55 static inline ChildIteratorType child_end(NodeType *N) {
56 return N->use_end();
57 }
58 };
59
60 template <> struct GraphTraits > {
61 typedef const Value NodeType;
62 typedef User::const_op_iterator ChildIteratorType;
63
64 static NodeType *getEntryNode(Inverse G) {
65 return G.Graph;
66 }
67
68 static inline ChildIteratorType child_begin(NodeType *N) {
69 if (const User *U = dyn_cast(N))
70 return U->op_begin();
71 return NULL;
72 }
73
74 static inline ChildIteratorType child_end(NodeType *N) {
75 if(const User *U = dyn_cast(N))
76 return U->op_end();
77 return NULL;
78 }
79 };
80
81 template <> struct GraphTraits > {
82 typedef Value NodeType;
83 typedef User::op_iterator ChildIteratorType;
84
85 static NodeType *getEntryNode(Inverse G) {
86 return G.Graph;
87 }
88
89 static inline ChildIteratorType child_begin(NodeType *N) {
90 if (User *U = dyn_cast(N))
91 return U->op_begin();
92 return NULL;
93 }
94
95 static inline ChildIteratorType child_end(NodeType *N) {
96 if (User *U = dyn_cast(N))
97 return U->op_end();
98 return NULL;
99 }
100 };
101
102 }
103 #endif