summaryrefslogtreecommitdiff
path: root/include/llvm/Support/DataFlow.h
blob: a09ccaac27893326ba1642347a67e3771e472b17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//===-- llvm/Support/DataFlow.h - dataflow as graphs ------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines specializations of GraphTraits that allows Use-Def and
// Def-Use relations to be treated as proper graphs for generic algorithms.
//===----------------------------------------------------------------------===//

#ifndef LLVM_SUPPORT_DATAFLOW_H
#define LLVM_SUPPORT_DATAFLOW_H

#include "llvm/ADT/GraphTraits.h"
#include "llvm/IR/User.h"

namespace llvm {

//===----------------------------------------------------------------------===//
// Provide specializations of GraphTraits to be able to treat def-use/use-def
// chains as graphs

template <> struct GraphTraits<const Value*> {
  typedef const Value NodeType;
  typedef Value::const_use_iterator ChildIteratorType;

  static NodeType *getEntryNode(const Value *G) {
    return G;
  }

  static inline ChildIteratorType child_begin(NodeType *N) {
    return N->use_begin();
  }

  static inline ChildIteratorType child_end(NodeType *N) {
    return N->use_end();
  }
};

template <> struct GraphTraits<Value*> {
  typedef Value NodeType;
  typedef Value::use_iterator ChildIteratorType;

  static NodeType *getEntryNode(Value *G) {
    return G;
  }

  static inline ChildIteratorType child_begin(NodeType *N) {
    return N->use_begin();
  }

  static inline ChildIteratorType child_end(NodeType *N) {
    return N->use_end();
  }
};

template <> struct GraphTraits<Inverse<const User*> > {
  typedef const Value NodeType;
  typedef User::const_op_iterator ChildIteratorType;

  static NodeType *getEntryNode(Inverse<const User*> G) {
    return G.Graph;
  }

  static inline ChildIteratorType child_begin(NodeType *N) {
    if (const User *U = dyn_cast<User>(N))
      return U->op_begin();
    return NULL;
  }

  static inline ChildIteratorType child_end(NodeType *N) {
    if(const User *U = dyn_cast<User>(N))
      return U->op_end();
    return NULL;
  }
};

template <> struct GraphTraits<Inverse<User*> > {
  typedef Value NodeType;
  typedef User::op_iterator ChildIteratorType;

  static NodeType *getEntryNode(Inverse<User*> G) {
    return G.Graph;
  }

  static inline ChildIteratorType child_begin(NodeType *N) {
    if (User *U = dyn_cast<User>(N))
      return U->op_begin();
    return NULL;
  }

  static inline ChildIteratorType child_end(NodeType *N) {
    if (User *U = dyn_cast<User>(N))
      return U->op_end();
    return NULL;
  }
};

}
#endif