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/ADT/GraphTraits.h"
22 //===----------------------------------------------------------------------===//
23 // Provide specializations of GraphTraits to be able to treat def-use/use-def
26 template <> struct GraphTraits<const Value*> {
27 typedef const Value NodeType;
28 typedef Value::use_const_iterator ChildIteratorType;
30 static NodeType *getEntryNode(const Value *G) {
34 static inline ChildIteratorType child_begin(NodeType *N) {
35 return N->use_begin();
38 static inline ChildIteratorType child_end(NodeType *N) {
43 template <> struct GraphTraits<Value*> {
44 typedef Value NodeType;
45 typedef Value::use_iterator ChildIteratorType;
47 static NodeType *getEntryNode(Value *G) {
51 static inline ChildIteratorType child_begin(NodeType *N) {
52 return N->use_begin();
55 static inline ChildIteratorType child_end(NodeType *N) {
60 template <> struct GraphTraits<Inverse<const User*> > {
61 typedef const Value NodeType;
62 typedef User::const_op_iterator ChildIteratorType;
64 static NodeType *getEntryNode(Inverse<const User*> G) {
68 static inline ChildIteratorType child_begin(NodeType *N) {
69 if (const User *U = dyn_cast<User>(N))
74 static inline ChildIteratorType child_end(NodeType *N) {
75 if(const User *U = dyn_cast<User>(N))
81 template <> struct GraphTraits<Inverse<User*> > {
82 typedef Value NodeType;
83 typedef User::op_iterator ChildIteratorType;
85 static NodeType *getEntryNode(Inverse<User*> G) {
89 static inline ChildIteratorType child_begin(NodeType *N) {
90 if (User *U = dyn_cast<User>(N))
95 static inline ChildIteratorType child_end(NodeType *N) {
96 if (User *U = dyn_cast<User>(N))