Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.6 KiB

  1. //===-- llvm/Support/DataFlow.h - dataflow as graphs ------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  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. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_DATAFLOW_H
  14. #define LLVM_SUPPORT_DATAFLOW_H
  15. #include "llvm/ADT/GraphTraits.h"
  16. #include "llvm/IR/User.h"
  17. namespace llvm {
  18. //===----------------------------------------------------------------------===//
  19. // Provide specializations of GraphTraits to be able to treat def-use/use-def
  20. // chains as graphs
  21. template <> struct GraphTraits<const Value*> {
  22. typedef const Value NodeType;
  23. typedef Value::const_use_iterator ChildIteratorType;
  24. static NodeType *getEntryNode(const Value *G) {
  25. return G;
  26. }
  27. static inline ChildIteratorType child_begin(NodeType *N) {
  28. return N->use_begin();
  29. }
  30. static inline ChildIteratorType child_end(NodeType *N) {
  31. return N->use_end();
  32. }
  33. };
  34. template <> struct GraphTraits<Value*> {
  35. typedef Value NodeType;
  36. typedef Value::use_iterator ChildIteratorType;
  37. static NodeType *getEntryNode(Value *G) {
  38. return G;
  39. }
  40. static inline ChildIteratorType child_begin(NodeType *N) {
  41. return N->use_begin();
  42. }
  43. static inline ChildIteratorType child_end(NodeType *N) {
  44. return N->use_end();
  45. }
  46. };
  47. template <> struct GraphTraits<Inverse<const User*> > {
  48. typedef const Value NodeType;
  49. typedef User::const_op_iterator ChildIteratorType;
  50. static NodeType *getEntryNode(Inverse<const User*> G) {
  51. return G.Graph;
  52. }
  53. static inline ChildIteratorType child_begin(NodeType *N) {
  54. if (const User *U = dyn_cast<User>(N))
  55. return U->op_begin();
  56. return NULL;
  57. }
  58. static inline ChildIteratorType child_end(NodeType *N) {
  59. if(const User *U = dyn_cast<User>(N))
  60. return U->op_end();
  61. return NULL;
  62. }
  63. };
  64. template <> struct GraphTraits<Inverse<User*> > {
  65. typedef Value NodeType;
  66. typedef User::op_iterator ChildIteratorType;
  67. static NodeType *getEntryNode(Inverse<User*> G) {
  68. return G.Graph;
  69. }
  70. static inline ChildIteratorType child_begin(NodeType *N) {
  71. if (User *U = dyn_cast<User>(N))
  72. return U->op_begin();
  73. return NULL;
  74. }
  75. static inline ChildIteratorType child_end(NodeType *N) {
  76. if (User *U = dyn_cast<User>(N))
  77. return U->op_end();
  78. return NULL;
  79. }
  80. };
  81. }
  82. #endif