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.

77 lines
3.0 KiB

  1. //===--- DAGDeltaAlgorithm.h - A DAG Minimization Algorithm ----*- 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. #ifndef LLVM_ADT_DAGDELTAALGORITHM_H
  9. #define LLVM_ADT_DAGDELTAALGORITHM_H
  10. #include <set>
  11. #include <vector>
  12. namespace llvm {
  13. /// DAGDeltaAlgorithm - Implements a "delta debugging" algorithm for minimizing
  14. /// directed acyclic graphs using a predicate function.
  15. ///
  16. /// The result of the algorithm is a subset of the input change set which is
  17. /// guaranteed to satisfy the predicate, assuming that the input set did. For
  18. /// well formed predicates, the result set is guaranteed to be such that
  19. /// removing any single element not required by the dependencies on the other
  20. /// elements would falsify the predicate.
  21. ///
  22. /// The DAG should be used to represent dependencies in the changes which are
  23. /// likely to hold across the predicate function. That is, for a particular
  24. /// changeset S and predicate P:
  25. ///
  26. /// P(S) => P(S union pred(S))
  27. ///
  28. /// The minization algorithm uses this dependency information to attempt to
  29. /// eagerly prune large subsets of changes. As with \see DeltaAlgorithm, the DAG
  30. /// is not required to satisfy this property, but the algorithm will run
  31. /// substantially fewer tests with appropriate dependencies. \see DeltaAlgorithm
  32. /// for more information on the properties which the predicate function itself
  33. /// should satisfy.
  34. class DAGDeltaAlgorithm {
  35. virtual void anchor();
  36. public:
  37. typedef unsigned change_ty;
  38. typedef std::pair<change_ty, change_ty> edge_ty;
  39. // FIXME: Use a decent data structure.
  40. typedef std::set<change_ty> changeset_ty;
  41. typedef std::vector<changeset_ty> changesetlist_ty;
  42. public:
  43. virtual ~DAGDeltaAlgorithm() {}
  44. /// Run - Minimize the DAG formed by the \p Changes vertices and the
  45. /// \p Dependencies edges by executing \see ExecuteOneTest() on subsets of
  46. /// changes and returning the smallest set which still satisfies the test
  47. /// predicate and the input \p Dependencies.
  48. ///
  49. /// \param Changes The list of changes.
  50. ///
  51. /// \param Dependencies The list of dependencies amongst changes. For each
  52. /// (x,y) in \p Dependencies, both x and y must be in \p Changes. The
  53. /// minimization algorithm guarantees that for each tested changed set S,
  54. /// \f$ x \in S \f$ implies \f$ y \in S \f$. It is an error to have cyclic
  55. /// dependencies.
  56. changeset_ty Run(const changeset_ty &Changes,
  57. const std::vector<edge_ty> &Dependencies);
  58. /// UpdatedSearchState - Callback used when the search state changes.
  59. virtual void UpdatedSearchState(const changeset_ty &Changes,
  60. const changesetlist_ty &Sets,
  61. const changeset_ty &Required) {}
  62. /// ExecuteOneTest - Execute a single test predicate on the change set \p S.
  63. virtual bool ExecuteOneTest(const changeset_ty &S) = 0;
  64. };
  65. } // end namespace llvm
  66. #endif