1210006Srdivacky//===--- DAGDeltaAlgorithm.h - A DAG Minimization Algorithm ----*- C++ -*--===// 2210006Srdivacky// 3210006Srdivacky// The LLVM Compiler Infrastructure 4210006Srdivacky// 5210006Srdivacky// This file is distributed under the University of Illinois Open Source 6210006Srdivacky// License. See LICENSE.TXT for details. 7210006Srdivacky//===----------------------------------------------------------------------===// 8210006Srdivacky 9210006Srdivacky#ifndef LLVM_ADT_DAGDELTAALGORITHM_H 10210006Srdivacky#define LLVM_ADT_DAGDELTAALGORITHM_H 11210006Srdivacky 12249423Sdim#include <set> 13210006Srdivacky#include <vector> 14210006Srdivacky 15210006Srdivackynamespace llvm { 16210006Srdivacky 17210006Srdivacky/// DAGDeltaAlgorithm - Implements a "delta debugging" algorithm for minimizing 18210006Srdivacky/// directed acyclic graphs using a predicate function. 19210006Srdivacky/// 20210006Srdivacky/// The result of the algorithm is a subset of the input change set which is 21210006Srdivacky/// guaranteed to satisfy the predicate, assuming that the input set did. For 22210006Srdivacky/// well formed predicates, the result set is guaranteed to be such that 23210006Srdivacky/// removing any single element not required by the dependencies on the other 24210006Srdivacky/// elements would falsify the predicate. 25210006Srdivacky/// 26210006Srdivacky/// The DAG should be used to represent dependencies in the changes which are 27210006Srdivacky/// likely to hold across the predicate function. That is, for a particular 28210006Srdivacky/// changeset S and predicate P: 29210006Srdivacky/// 30210006Srdivacky/// P(S) => P(S union pred(S)) 31210006Srdivacky/// 32210006Srdivacky/// The minization algorithm uses this dependency information to attempt to 33210006Srdivacky/// eagerly prune large subsets of changes. As with \see DeltaAlgorithm, the DAG 34210006Srdivacky/// is not required to satisfy this property, but the algorithm will run 35210006Srdivacky/// substantially fewer tests with appropriate dependencies. \see DeltaAlgorithm 36210006Srdivacky/// for more information on the properties which the predicate function itself 37210006Srdivacky/// should satisfy. 38210006Srdivackyclass DAGDeltaAlgorithm { 39234353Sdim virtual void anchor(); 40210006Srdivackypublic: 41210006Srdivacky typedef unsigned change_ty; 42210006Srdivacky typedef std::pair<change_ty, change_ty> edge_ty; 43210006Srdivacky 44210006Srdivacky // FIXME: Use a decent data structure. 45210006Srdivacky typedef std::set<change_ty> changeset_ty; 46210006Srdivacky typedef std::vector<changeset_ty> changesetlist_ty; 47210006Srdivacky 48210006Srdivackypublic: 49210006Srdivacky virtual ~DAGDeltaAlgorithm() {} 50210006Srdivacky 51243830Sdim /// Run - Minimize the DAG formed by the \p Changes vertices and the 52243830Sdim /// \p Dependencies edges by executing \see ExecuteOneTest() on subsets of 53210006Srdivacky /// changes and returning the smallest set which still satisfies the test 54243830Sdim /// predicate and the input \p Dependencies. 55210006Srdivacky /// 56210006Srdivacky /// \param Changes The list of changes. 57210006Srdivacky /// 58210006Srdivacky /// \param Dependencies The list of dependencies amongst changes. For each 59243830Sdim /// (x,y) in \p Dependencies, both x and y must be in \p Changes. The 60243830Sdim /// minimization algorithm guarantees that for each tested changed set S, 61243830Sdim /// \f$ x \in S \f$ implies \f$ y \in S \f$. It is an error to have cyclic 62243830Sdim /// dependencies. 63210006Srdivacky changeset_ty Run(const changeset_ty &Changes, 64210006Srdivacky const std::vector<edge_ty> &Dependencies); 65210006Srdivacky 66210006Srdivacky /// UpdatedSearchState - Callback used when the search state changes. 67210006Srdivacky virtual void UpdatedSearchState(const changeset_ty &Changes, 68210006Srdivacky const changesetlist_ty &Sets, 69210006Srdivacky const changeset_ty &Required) {} 70210006Srdivacky 71243830Sdim /// ExecuteOneTest - Execute a single test predicate on the change set \p S. 72210006Srdivacky virtual bool ExecuteOneTest(const changeset_ty &S) = 0; 73210006Srdivacky}; 74210006Srdivacky 75210006Srdivacky} // end namespace llvm 76210006Srdivacky 77210006Srdivacky#endif 78