1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 // This class is used to perform data flow optimizations.
7 // An example usage would be:
9 // DataFlow flow(m_pCompiler);
10 // flow.ForwardAnalysis(callback);
12 // The "callback" object needs to implement the necessary callback
13 // functions that the "flow" object will call as the data flow
14 // analysis progresses.
27 // The callback interface that needs to be implemented by anyone
28 // needing updates by the dataflow object.
32 Callback(Compiler* pCompiler);
34 void StartMerge(BasicBlock* block);
35 void Merge(BasicBlock* block, BasicBlock* pred, flowList* preds);
36 bool EndMerge(BasicBlock* block);
39 Compiler* m_pCompiler;
42 DataFlow(Compiler* pCompiler);
44 template <typename TCallback>
45 void ForwardAnalysis(TCallback& callback);
48 Compiler* m_pCompiler;
51 template <typename TCallback>
52 void DataFlow::ForwardAnalysis(TCallback& callback)
54 jitstd::list<BasicBlock*> worklist(jitstd::allocator<void>(m_pCompiler->getAllocator()));
56 worklist.insert(worklist.begin(), m_pCompiler->fgFirstBB);
57 while (!worklist.empty())
59 BasicBlock* block = *(worklist.begin());
60 worklist.erase(worklist.begin());
62 callback.StartMerge(block);
64 flowList* preds = m_pCompiler->BlockPredsWithEH(block);
65 for (flowList* pred = preds; pred; pred = pred->flNext)
67 callback.Merge(block, pred->flBlock, preds);
71 if (callback.EndMerge(block))
73 for (BasicBlock* succ : block->GetAllSuccs(m_pCompiler))
75 worklist.insert(worklist.end(), succ);