DAGDeltaAlgorithm.h 3.3 KB

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