LLVM API Documentation
00001 //===--- DAGDeltaAlgorithm.h - A DAG Minimization Algorithm ----*- C++ -*--===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 //===----------------------------------------------------------------------===// 00008 00009 #ifndef LLVM_ADT_DAGDELTAALGORITHM_H 00010 #define LLVM_ADT_DAGDELTAALGORITHM_H 00011 00012 #include <set> 00013 #include <vector> 00014 00015 namespace llvm { 00016 00017 /// DAGDeltaAlgorithm - Implements a "delta debugging" algorithm for minimizing 00018 /// directed acyclic graphs using a predicate function. 00019 /// 00020 /// The result of the algorithm is a subset of the input change set which is 00021 /// guaranteed to satisfy the predicate, assuming that the input set did. For 00022 /// well formed predicates, the result set is guaranteed to be such that 00023 /// removing any single element not required by the dependencies on the other 00024 /// elements would falsify the predicate. 00025 /// 00026 /// The DAG should be used to represent dependencies in the changes which are 00027 /// likely to hold across the predicate function. That is, for a particular 00028 /// changeset S and predicate P: 00029 /// 00030 /// P(S) => P(S union pred(S)) 00031 /// 00032 /// The minization algorithm uses this dependency information to attempt to 00033 /// eagerly prune large subsets of changes. As with \see DeltaAlgorithm, the DAG 00034 /// is not required to satisfy this property, but the algorithm will run 00035 /// substantially fewer tests with appropriate dependencies. \see DeltaAlgorithm 00036 /// for more information on the properties which the predicate function itself 00037 /// should satisfy. 00038 class DAGDeltaAlgorithm { 00039 virtual void anchor(); 00040 public: 00041 typedef unsigned change_ty; 00042 typedef std::pair<change_ty, change_ty> edge_ty; 00043 00044 // FIXME: Use a decent data structure. 00045 typedef std::set<change_ty> changeset_ty; 00046 typedef std::vector<changeset_ty> changesetlist_ty; 00047 00048 public: 00049 virtual ~DAGDeltaAlgorithm() {} 00050 00051 /// Run - Minimize the DAG formed by the \p Changes vertices and the 00052 /// \p Dependencies edges by executing \see ExecuteOneTest() on subsets of 00053 /// changes and returning the smallest set which still satisfies the test 00054 /// predicate and the input \p Dependencies. 00055 /// 00056 /// \param Changes The list of changes. 00057 /// 00058 /// \param Dependencies The list of dependencies amongst changes. For each 00059 /// (x,y) in \p Dependencies, both x and y must be in \p Changes. The 00060 /// minimization algorithm guarantees that for each tested changed set S, 00061 /// \f$ x \in S \f$ implies \f$ y \in S \f$. It is an error to have cyclic 00062 /// dependencies. 00063 changeset_ty Run(const changeset_ty &Changes, 00064 const std::vector<edge_ty> &Dependencies); 00065 00066 /// UpdatedSearchState - Callback used when the search state changes. 00067 virtual void UpdatedSearchState(const changeset_ty &Changes, 00068 const changesetlist_ty &Sets, 00069 const changeset_ty &Required) {} 00070 00071 /// ExecuteOneTest - Execute a single test predicate on the change set \p S. 00072 virtual bool ExecuteOneTest(const changeset_ty &S) = 0; 00073 }; 00074 00075 } // end namespace llvm 00076 00077 #endif