Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:03

0001 //===- DAGDeltaAlgorithm.h - A DAG Minimization Algorithm ------*- C++ -*--===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //===----------------------------------------------------------------------===//
0007 
0008 #ifndef LLVM_ADT_DAGDELTAALGORITHM_H
0009 #define LLVM_ADT_DAGDELTAALGORITHM_H
0010 
0011 #include <set>
0012 #include <utility>
0013 #include <vector>
0014 
0015 namespace llvm {
0016 
0017 /// DAGDeltaAlgorithm - Implements a "delta debugging" algorithm for minimizing
0018 /// directed acyclic graphs using a predicate function.
0019 ///
0020 /// The result of the algorithm is a subset of the input change set which is
0021 /// guaranteed to satisfy the predicate, assuming that the input set did. For
0022 /// well formed predicates, the result set is guaranteed to be such that
0023 /// removing any single element not required by the dependencies on the other
0024 /// elements would falsify the predicate.
0025 ///
0026 /// The DAG should be used to represent dependencies in the changes which are
0027 /// likely to hold across the predicate function. That is, for a particular
0028 /// changeset S and predicate P:
0029 ///
0030 ///   P(S) => P(S union pred(S))
0031 ///
0032 /// The minimization algorithm uses this dependency information to attempt to
0033 /// eagerly prune large subsets of changes. As with \see DeltaAlgorithm, the DAG
0034 /// is not required to satisfy this property, but the algorithm will run
0035 /// substantially fewer tests with appropriate dependencies. \see DeltaAlgorithm
0036 /// for more information on the properties which the predicate function itself
0037 /// should satisfy.
0038 class DAGDeltaAlgorithm {
0039   virtual void anchor();
0040 
0041 public:
0042   using change_ty = unsigned;
0043   using edge_ty = std::pair<change_ty, change_ty>;
0044 
0045   // FIXME: Use a decent data structure.
0046   using changeset_ty = std::set<change_ty>;
0047   using changesetlist_ty = std::vector<changeset_ty>;
0048 
0049 public:
0050   virtual ~DAGDeltaAlgorithm() = default;
0051 
0052   /// Run - Minimize the DAG formed by the \p Changes vertices and the
0053   /// \p Dependencies edges by executing \see ExecuteOneTest() on subsets of
0054   /// changes and returning the smallest set which still satisfies the test
0055   /// predicate and the input \p Dependencies.
0056   ///
0057   /// \param Changes The list of changes.
0058   ///
0059   /// \param Dependencies The list of dependencies amongst changes. For each
0060   /// (x,y) in \p Dependencies, both x and y must be in \p Changes. The
0061   /// minimization algorithm guarantees that for each tested changed set S,
0062   /// \f$ x \in S \f$ implies \f$ y \in S \f$. It is an error to have cyclic
0063   /// dependencies.
0064   changeset_ty Run(const changeset_ty &Changes,
0065                    const std::vector<edge_ty> &Dependencies);
0066 
0067   /// UpdatedSearchState - Callback used when the search state changes.
0068   virtual void UpdatedSearchState(const changeset_ty &Changes,
0069                                   const changesetlist_ty &Sets,
0070                                   const changeset_ty &Required) {}
0071 
0072   /// ExecuteOneTest - Execute a single test predicate on the change set \p S.
0073   virtual bool ExecuteOneTest(const changeset_ty &S) = 0;
0074 };
0075 
0076 } // end namespace llvm
0077 
0078 #endif // LLVM_ADT_DAGDELTAALGORITHM_H