aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTorok Edwin <edwintorok@gmail.com>2008-04-02 14:57:52 +0000
committerTorok Edwin <edwintorok@gmail.com>2008-04-02 14:57:52 +0000
commit56c2f99f00567ebd0969bbf12050f9ce2c8105ef (patch)
tree017b97cbe159720106feece94a714ff411e284a7 /include
parent67073f1cbd95f61a8db01ac479f5e60c0a048ac0 (diff)
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
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Support/DataFlow.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/include/llvm/Support/DataFlow.h b/include/llvm/Support/DataFlow.h
new file mode 100644
index 0000000000..8d0ae0c70c
--- /dev/null
+++ b/include/llvm/Support/DataFlow.h
@@ -0,0 +1,104 @@
+//===-- 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/User.h"
+#include "llvm/Value.h"
+#include "llvm/ADT/GraphTraits.h"
+
+namespace llvm {
+
+//===----------------------------------------------------------------------===//
+// Provide specializations of GraphTraits to be able to treat def-use/use-def
+// chains as graphs
+
+template <> struct GraphTraits<const User*> {
+ typedef const Value NodeType;
+ typedef Value::use_const_iterator ChildIteratorType;
+
+ static NodeType *getEntryNode(const User *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<User*> {
+ typedef Value NodeType;
+ typedef Value::use_iterator ChildIteratorType;
+
+ static NodeType *getEntryNode(User *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