10#include "staticSingleAssignment.h"
11#include <boost/foreach.hpp>
22 template<
class CfgNodeT,
class CfgEdgeT>
23 std::multimap< CfgNodeT, std::pair<CfgNodeT, CfgEdgeT> > calculateControlDependence(
SgFunctionDefinition* function,
const std::map<CfgNodeT, CfgNodeT>& iPostDominatorMap);
25 using namespace boost;
32 template<
class CfgNodeT,
class CfgEdgeT>
33 multimap< CfgNodeT, pair<CfgNodeT, CfgEdgeT> >
34 calculateControlDependence(
SgFunctionDefinition* function,
const map<CfgNodeT, CfgNodeT>& iPostDominatorMap)
37 multimap< CfgNodeT, pair<CfgNodeT, CfgEdgeT> > controlDepdendences;
40 set<CfgNodeT> visited;
41 set<CfgNodeT> worklist;
44 worklist.insert(sourceNode);
46 while (!worklist.empty())
49 sourceNode = *worklist.begin();
50 worklist.erase(worklist.begin());
51 visited.insert(sourceNode);
55 BOOST_FOREACH(
const CfgEdgeT& edge, sourceNode.outEdges())
57 CfgNodeT targetNode = edge.target();
60 if (visited.count(targetNode) == 0)
62 worklist.insert(targetNode);
66 if (edge.condition() == VirtualCFG::eckUnconditional)
71 typename map<CfgNodeT, CfgNodeT>::const_iterator parentIter = iPostDominatorMap.find(sourceNode);
73 ROSE_ASSERT(parentIter != iPostDominatorMap.end());
75 parent = parentIter->second;
78 CfgNodeT currNode = targetNode;
83 if (currNode == parent)
89 controlDepdendences.insert(make_pair(currNode, make_pair(sourceNode, edge)));
91 if (StaticSingleAssignment::getDebugExtra())
93 printf(
"%s is control-dependent on %s - %s \n", currNode.toStringForDebugging().c_str(),
94 sourceNode.toStringForDebugging().c_str(), edge.condition() == VirtualCFG::eckTrue ?
"true" :
"false");
98 parentIter = iPostDominatorMap.find(currNode);
99 ROSE_ASSERT(parentIter != iPostDominatorMap.end());
100 currNode = parentIter->second;
105 return controlDepdendences;
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
VirtualCFG::CFGNode cfgForBeginning()
Returns the CFG node for just before this AST node.