43#define DEBUG_TYPE "dag-delta"
47class DAGDeltaAlgorithmImpl {
48 friend class DeltaActiveSetHelper;
57 typedef std::vector<change_ty>::iterator pred_iterator_ty;
58 typedef std::vector<change_ty>::iterator succ_iterator_ty;
59 typedef std::set<change_ty>::iterator pred_closure_iterator_ty;
60 typedef std::set<change_ty>::iterator succ_closure_iterator_ty;
64 std::vector<change_ty> Roots;
70 mutable std::set<changeset_ty> FailedTestsCache;
73 std::map<change_ty, std::vector<change_ty> > Predecessors;
74 std::map<change_ty, std::vector<change_ty> > Successors;
76 std::map<change_ty, std::set<change_ty> > PredClosure;
77 std::map<change_ty, std::set<change_ty> > SuccClosure;
81 assert(Predecessors.count(
Node) &&
"Invalid node!");
82 return Predecessors[
Node].begin();
85 assert(Predecessors.count(
Node) &&
"Invalid node!");
86 return Predecessors[
Node].end();
89 pred_closure_iterator_ty pred_closure_begin(change_ty
Node) {
90 assert(PredClosure.count(
Node) &&
"Invalid node!");
91 return PredClosure[
Node].begin();
93 pred_closure_iterator_ty pred_closure_end(change_ty
Node) {
94 assert(PredClosure.count(
Node) &&
"Invalid node!");
95 return PredClosure[
Node].end();
99 assert(Successors.count(
Node) &&
"Invalid node!");
100 return Successors[
Node].begin();
103 assert(Successors.count(
Node) &&
"Invalid node!");
104 return Successors[
Node].end();
107 succ_closure_iterator_ty succ_closure_begin(change_ty
Node) {
108 assert(SuccClosure.count(
Node) &&
"Invalid node!");
109 return SuccClosure[
Node].begin();
111 succ_closure_iterator_ty succ_closure_end(change_ty
Node) {
112 assert(SuccClosure.count(
Node) &&
"Invalid node!");
113 return SuccClosure[
Node].end();
116 void UpdatedSearchState(
const changeset_ty &Changes,
117 const changesetlist_ty &Sets,
118 const changeset_ty &Required) {
123 bool ExecuteOneTest(
const changeset_ty &S) {
126 for (changeset_ty::const_iterator it = S.begin(), ie = S.end(); it != ie;
130 assert(S.count(*it2) &&
"Attempt to run invalid changeset!");
138 const std::vector<edge_ty> &Dependencies);
150 bool GetTestResult(
const changeset_ty &Changes,
const changeset_ty &Required);
155 DAGDeltaAlgorithmImpl &DDAI;
157 const changeset_ty &Required;
162 const changesetlist_ty &Sets)
override {
163 DDAI.UpdatedSearchState(Changes, Sets, Required);
167 return DDAI.GetTestResult(S, Required);
171 DeltaActiveSetHelper(DAGDeltaAlgorithmImpl &DDAI,
172 const changeset_ty &Required)
173 : DDAI(DDAI), Required(Required) {}
178DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(
180 const std::vector<edge_ty> &Dependencies)
182 for (change_ty Change : Changes) {
183 Predecessors.insert(std::make_pair(Change, std::vector<change_ty>()));
184 Successors.insert(std::make_pair(Change, std::vector<change_ty>()));
186 for (
const edge_ty &Dep : Dependencies) {
187 Predecessors[Dep.second].push_back(Dep.first);
188 Successors[Dep.first].push_back(Dep.second);
192 for (change_ty Change : Changes)
194 Roots.push_back(Change);
197 std::vector<change_ty> Worklist(Roots.begin(), Roots.end());
198 while (!Worklist.empty()) {
199 change_ty Change = Worklist.back();
202 std::set<change_ty> &ChangeSuccs = SuccClosure[Change];
203 for (pred_iterator_ty it =
pred_begin(Change),
204 ie =
pred_end(Change); it != ie; ++it) {
205 SuccClosure[*it].insert(Change);
206 SuccClosure[*it].insert(ChangeSuccs.begin(), ChangeSuccs.end());
207 Worklist.push_back(*it);
212 for (change_ty Change : Changes)
213 PredClosure.insert(std::make_pair(Change, std::set<change_ty>()));
214 for (change_ty Change : Changes)
215 for (succ_closure_iterator_ty it2 = succ_closure_begin(Change),
216 ie2 = succ_closure_end(Change);
218 PredClosure[*it2].insert(Change);
222 llvm::errs() <<
"-- DAGDeltaAlgorithmImpl --\n";
224 for (changeset_ty::const_iterator it = Changes.begin(), ie = Changes.end();
226 if (it != Changes.begin())
244 for (std::vector<change_ty>::const_iterator it = Roots.begin(),
247 if (it != Roots.begin())
254 for (change_ty Change : Changes) {
256 for (pred_closure_iterator_ty it2 = pred_closure_begin(Change),
257 ie2 = pred_closure_end(Change);
259 if (it2 != pred_closure_begin(Change))
267 for (change_ty Change : Changes) {
269 for (succ_closure_iterator_ty it2 = succ_closure_begin(Change),
270 ie2 = succ_closure_end(Change);
272 if (it2 != succ_closure_begin(Change))
283bool DAGDeltaAlgorithmImpl::GetTestResult(
const changeset_ty &Changes,
284 const changeset_ty &Required) {
286 Extended.insert(Changes.begin(), Changes.end());
287 for (change_ty Change : Changes)
288 Extended.insert(pred_closure_begin(Change), pred_closure_end(Change));
290 if (FailedTestsCache.count(Extended))
293 bool Result = ExecuteOneTest(Extended);
295 FailedTestsCache.insert(Extended);
301DAGDeltaAlgorithmImpl::Run() {
303 changeset_ty CurrentSet(Roots.begin(), Roots.end());
313 while (!CurrentSet.empty()) {
315 llvm::errs() <<
"DAG_DD - " << CurrentSet.size() <<
" active changes, "
316 <<
Required.size() <<
" required changes\n";
320 DeltaActiveSetHelper Helper(*
this, Required);
321 changeset_ty CurrentMinSet = Helper.Run(CurrentSet);
330 Required.insert(CurrentMinSet.begin(), CurrentMinSet.end());
335 for (change_ty CT : CurrentMinSet)
345void DAGDeltaAlgorithm::anchor() {
350 const std::vector<edge_ty> &Dependencies) {
351 return DAGDeltaAlgorithmImpl(*
this, Changes, Dependencies).Run();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DAGDeltaAlgorithm - Implements a "delta debugging" algorithm for minimizing directed acyclic graphs u...
virtual bool ExecuteOneTest(const changeset_ty &S)=0
ExecuteOneTest - Execute a single test predicate on the change set S.
std::vector< changeset_ty > changesetlist_ty
std::set< change_ty > changeset_ty
std::pair< change_ty, change_ty > edge_ty
virtual void UpdatedSearchState(const changeset_ty &Changes, const changesetlist_ty &Sets, const changeset_ty &Required)
UpdatedSearchState - Callback used when the search state changes.
changeset_ty Run(const changeset_ty &Changes, const std::vector< edge_ty > &Dependencies)
Run - Minimize the DAG formed by the Changes vertices and the Dependencies edges by executing.
DeltaAlgorithm - Implements the delta debugging algorithm (A.
virtual bool ExecuteOneTest(const changeset_ty &S)=0
ExecuteOneTest - Execute a single test predicate on the change set S.
virtual void UpdatedSearchState(const changeset_ty &Changes, const changesetlist_ty &Sets)
UpdatedSearchState - Callback used when the search state changes.
This is an optimization pass for GlobalISel generic memory operations.
pred_iterator pred_end(BasicBlock *BB)
pred_iterator pred_begin(BasicBlock *BB)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)