LLVM API Documentation
00001 //===-- llvm/Support/DataFlow.h - dataflow as graphs ------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines specializations of GraphTraits that allows Use-Def and 00011 // Def-Use relations to be treated as proper graphs for generic algorithms. 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_SUPPORT_DATAFLOW_H 00015 #define LLVM_SUPPORT_DATAFLOW_H 00016 00017 #include "llvm/User.h" 00018 #include "llvm/ADT/GraphTraits.h" 00019 00020 namespace llvm { 00021 00022 //===----------------------------------------------------------------------===// 00023 // Provide specializations of GraphTraits to be able to treat def-use/use-def 00024 // chains as graphs 00025 00026 template <> struct GraphTraits<const User*> { 00027 typedef const Value NodeType; 00028 typedef Value::use_const_iterator ChildIteratorType; 00029 00030 static NodeType *getEntryNode(const User *G) { 00031 return G; 00032 } 00033 00034 static inline ChildIteratorType child_begin(NodeType *N) { 00035 return N->use_begin(); 00036 } 00037 00038 static inline ChildIteratorType child_end(NodeType *N) { 00039 return N->use_end(); 00040 } 00041 }; 00042 00043 template <> struct GraphTraits<User*> { 00044 typedef Value NodeType; 00045 typedef Value::use_iterator ChildIteratorType; 00046 00047 static NodeType *getEntryNode(User *G) { 00048 return G; 00049 } 00050 00051 static inline ChildIteratorType child_begin(NodeType *N) { 00052 return N->use_begin(); 00053 } 00054 00055 static inline ChildIteratorType child_end(NodeType *N) { 00056 return N->use_end(); 00057 } 00058 }; 00059 00060 template <> struct GraphTraits<Inverse<const User*> > { 00061 typedef const Value NodeType; 00062 typedef User::const_op_iterator ChildIteratorType; 00063 00064 static NodeType *getEntryNode(Inverse<const User*> G) { 00065 return G.Graph; 00066 } 00067 00068 static inline ChildIteratorType child_begin(NodeType *N) { 00069 if (const User *U = dyn_cast<User>(N)) 00070 return U->op_begin(); 00071 return NULL; 00072 } 00073 00074 static inline ChildIteratorType child_end(NodeType *N) { 00075 if(const User *U = dyn_cast<User>(N)) 00076 return U->op_end(); 00077 return NULL; 00078 } 00079 }; 00080 00081 template <> struct GraphTraits<Inverse<User*> > { 00082 typedef Value NodeType; 00083 typedef User::op_iterator ChildIteratorType; 00084 00085 static NodeType *getEntryNode(Inverse<User*> G) { 00086 return G.Graph; 00087 } 00088 00089 static inline ChildIteratorType child_begin(NodeType *N) { 00090 if (User *U = dyn_cast<User>(N)) 00091 return U->op_begin(); 00092 return NULL; 00093 } 00094 00095 static inline ChildIteratorType child_end(NodeType *N) { 00096 if (User *U = dyn_cast<User>(N)) 00097 return U->op_end(); 00098 return NULL; 00099 } 00100 }; 00101 00102 } 00103 #endif
This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.