本文整理汇总了C++中DSGraph::retnodes_begin方法的典型用法代码示例。如果您正苦于以下问题:C++ DSGraph::retnodes_begin方法的具体用法?C++ DSGraph::retnodes_begin怎么用?C++ DSGraph::retnodes_begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DSGraph
的用法示例。
在下文中一共展示了DSGraph::retnodes_begin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateGraphs
//.........这里部分代码省略.........
//
if (Min != MyID)
return Min;
//
// If this is a new SCC, process it now.
//
if (Stack.back() == F) { // Special case the single "SCC" case here.
DEBUG(errs() << "Visiting single node SCC #: " << MyID << " fn: "
<< F->getName() << "\n");
Stack.pop_back();
DEBUG(errs() << " [BU] Calculating graph for: " << F->getName()<< "\n");
DSGraph* G = getOrCreateGraph(F);
calculateGraph(G);
DEBUG(errs() << " [BU] Done inlining: " << F->getName() << " ["
<< G->getGraphSize() << "+" << G->getAuxFunctionCalls().size()
<< "]\n");
if (MaxSCC < 1) MaxSCC = 1;
//
// Should we revisit the graph? Only do it if there are now new resolvable
// callees.
FuncSet NewCallees;
getAllAuxCallees(G, NewCallees);
if (!NewCallees.empty()) {
if (hasNewCallees(NewCallees, CalleeFunctions)) {
DEBUG(errs() << "Recalculating " << F->getName() << " due to new knowledge\n");
ValMap.erase(F);
++NumRecalculations;
return calculateGraphs(F, Stack, NextID, ValMap);
}
++NumRecalculationsSkipped;
}
ValMap[F] = ~0U;
return MyID;
} else {
unsigned SCCSize = 1;
const Function *NF = Stack.back();
if(NF != F)
ValMap[NF] = ~0U;
DSGraph* SCCGraph = getDSGraph(*NF);
//
// First thing first: collapse all of the DSGraphs into a single graph for
// the entire SCC. Splice all of the graphs into one and discard all of
// the old graphs.
//
while (NF != F) {
Stack.pop_back();
NF = Stack.back();
if(NF != F)
ValMap[NF] = ~0U;
DSGraph* NFG = getDSGraph(*NF);
if (NFG != SCCGraph) {
// Update the Function -> DSG map.
for (DSGraph::retnodes_iterator I = NFG->retnodes_begin(),
E = NFG->retnodes_end(); I != E; ++I)
setDSGraph(*I->first, SCCGraph);
SCCGraph->spliceFrom(NFG);
delete NFG;
++SCCSize;
}
}
Stack.pop_back();
DEBUG(errs() << "Calculating graph for SCC #: " << MyID << " of size: "
<< SCCSize << "\n");
// Compute the Max SCC Size.
if (MaxSCC < SCCSize)
MaxSCC = SCCSize;
// Clean up the graph before we start inlining a bunch again...
SCCGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
// Now that we have one big happy family, resolve all of the call sites in
// the graph...
calculateGraph(SCCGraph);
DEBUG(errs() << " [BU] Done inlining SCC [" << SCCGraph->getGraphSize()
<< "+" << SCCGraph->getAuxFunctionCalls().size() << "]\n"
<< "DONE with SCC #: " << MyID << "\n");
FuncSet NewCallees;
getAllAuxCallees(SCCGraph, NewCallees);
if (!NewCallees.empty()) {
if (hasNewCallees(NewCallees, CalleeFunctions)) {
DEBUG(errs() << "Recalculating SCC Graph " << F->getName() << " due to new knowledge\n");
ValMap.erase(F);
++NumRecalculations;
return calculateGraphs(F, Stack, NextID, ValMap);
}
++NumRecalculationsSkipped;
}
ValMap[F] = ~0U;
return MyID;
}
}
示例2: printCollection
static void printCollection(const Collection &C, llvm::raw_ostream &O,
const Module *M, const std::string &Prefix) {
if (M == 0) {
O << "Null Module pointer, cannot continue!\n";
return;
}
unsigned TotalNumNodes = 0, TotalCallNodes = 0;
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
if (C.hasDSGraph(*I)) {
DSGraph* Gr = C.getDSGraph((const Function&)*I);
unsigned NumCalls = Gr->shouldUseAuxCalls() ?
Gr->getAuxFunctionCalls().size() : Gr->getFunctionCalls().size();
bool IsDuplicateGraph = false;
//if no only print options, print everything
bool doPrint = OnlyPrint.begin() == OnlyPrint.end();
//otherwise check the name
if (!doPrint)
doPrint = OnlyPrint.end() !=
std::find(OnlyPrint.begin(), OnlyPrint.end(), I->getName().str());
if (doPrint) {
const Function *SCCFn = Gr->retnodes_begin()->first;
if (&*I == SCCFn) {
Gr->writeGraphToFile(O, Prefix+I->getName().str());
} else {
IsDuplicateGraph = true; // Don't double count node/call nodes.
O << "Didn't write '" << Prefix+I->getName().str()
<< ".dot' - Graph already emitted to '" << Prefix+SCCFn->getName().str()
<< "\n";
}
} else {
const Function *SCCFn = Gr->retnodes_begin()->first;
if (&*I == SCCFn) {
//O << "Skipped Writing '" << Prefix+I->getName().str() << ".dot'... ["
// << Gr->getGraphSize() << "+" << NumCalls << "]\n";
} else {
IsDuplicateGraph = true; // Don't double count node/call nodes.
}
}
if (!IsDuplicateGraph) {
unsigned GraphSize = Gr->getGraphSize();
if (MaxGraphSize < GraphSize) MaxGraphSize = GraphSize;
TotalNumNodes += Gr->getGraphSize();
TotalCallNodes += NumCalls;
for (DSGraph::node_iterator NI = Gr->node_begin(), E = Gr->node_end();
NI != E; ++NI)
if (NI->isNodeCompletelyFolded())
++NumFoldedNodes;
}
}
DSGraph* GG = C.getGlobalsGraph();
TotalNumNodes += GG->getGraphSize();
TotalCallNodes += GG->getFunctionCalls().size();
GG->writeGraphToFile(O, Prefix + "GlobalsGraph");
O << "\nGraphs contain [" << TotalNumNodes << "+" << TotalCallNodes
<< "] nodes total\n";
}
示例3: IV
/// visitGraph - Visit the functions in the specified graph, updating the
/// specified lattice values for all of their uses.
///
void StructureFieldVisitorBase::
visitGraph(DSGraph &DSG, std::multimap<DSNode*, LatticeValue*> &NodeLVs) {
assert(!NodeLVs.empty() && "No lattice values to compute!");
// To visit a graph, first step, we visit the instruction making up each
// function in the graph, but ignore calls when processing them. We handle
// call nodes explicitly by looking at call nodes in the graph if needed. We
// handle instructions before calls to avoid interprocedural analysis if we
// can drive lattice values to bottom early.
//
SFVInstVisitor IV(DSG, Callbacks, NodeLVs);
for (DSGraph::retnodes_iterator FI = DSG.retnodes_begin(),
E = DSG.retnodes_end(); FI != E; ++FI)
for (Function::iterator BB = FI->first->begin(), E = FI->first->end();
BB != E; ++BB)
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
if (IV.visit(*I) && NodeLVs.empty())
return; // Nothing left to analyze.
// Keep track of which actual direct callees are handled.
std::set<Function*> CalleesHandled;
// Once we have visited all of the instructions in the function bodies, if
// there are lattice values that have not been driven to bottom, see if any of
// the nodes involved are passed into function calls. If so, we potentially
// have to recursively traverse the call graph.
for (DSGraph::fc_iterator CS = DSG.fc_begin(), E = DSG.fc_end();
CS != E; ++CS) {
// Figure out the mapping from a node in the caller (potentially several)
// nodes in the callee.
DSGraph::NodeMapTy CallNodeMap;
Instruction *TheCall = CS->getCallSite().getInstruction();
// If this is an indirect function call, assume nothing gets passed through
// it. FIXME: THIS IS BROKEN! Just get the ECG for the fn ptr if it's not
// direct.
if (CS->isIndirectCall())
continue;
// If this is an external function call, it cannot be involved with this
// node, because otherwise the node would be marked incomplete!
if (CS->getCalleeFunc()->isExternal())
continue;
// If we can handle this function call, remove it from the set of direct
// calls found by the visitor.
CalleesHandled.insert(CS->getCalleeFunc());
std::vector<DSNodeHandle> Args;
DSGraph *CG = &ECG.getDSGraph(*CS->getCalleeFunc());
CG->getFunctionArgumentsForCall(CS->getCalleeFunc(), Args);
if (!CS->getRetVal().isNull())
DSGraph::computeNodeMapping(Args[0], CS->getRetVal(), CallNodeMap);
for (unsigned i = 0, e = CS->getNumPtrArgs(); i != e; ++i) {
if (i == Args.size()-1) break;
DSGraph::computeNodeMapping(Args[i+1], CS->getPtrArg(i), CallNodeMap);
}
Args.clear();
// The mapping we just computed maps from nodes in the callee to nodes in
// the caller, so we can't query it efficiently. Instead of going through
// the trouble of inverting the map to do this (linear time with the size of
// the mapping), we just do a linear search to see if any affected nodes are
// passed into this call.
bool CallCanModifyDataFlow = false;
for (DSGraph::NodeMapTy::iterator MI = CallNodeMap.begin(),
E = CallNodeMap.end(); MI != E; ++MI)
if (NodeLVs.count(MI->second.getNode()))
// Okay, the node is passed in, check to see if the call might do
// something interesting to it (i.e. if analyzing the call can produce
// anything other than "top").
if ((CallCanModifyDataFlow = NodeCanPossiblyBeInteresting(MI->first,
Callbacks)))
break;
// If this function call cannot impact the analysis (either because the
// nodes we are tracking are not passed into the call, or the DSGraph for
// the callee tells us that analysis of the callee can't provide interesting
// information), ignore it.
if (!CallCanModifyDataFlow)
continue;
// Okay, either compute analysis results for the callee function, or reuse
// results previously computed.
std::multimap<DSNode*, LatticeValue*> &CalleeFacts = getCalleeFacts(*CG);
// Merge all of the facts for the callee into the facts for the caller. If
// this reduces anything in the caller to 'bottom', remove them.
for (DSGraph::NodeMapTy::iterator MI = CallNodeMap.begin(),
E = CallNodeMap.end(); MI != E; ++MI) {
// If we have Lattice facts in the caller for this node in the callee,
// merge any information from the callee into the caller.
//.........这里部分代码省略.........
示例4: calculateGraphs
unsigned BUDataStructures::calculateGraphs(const Function *F,
std::vector<const Function*> &Stack,
unsigned &NextID,
hash_map<const Function*, unsigned> &ValMap) {
assert(!ValMap.count(F) && "Shouldn't revisit functions!");
unsigned Min = NextID++, MyID = Min;
ValMap[F] = Min;
Stack.push_back(F);
// FIXME! This test should be generalized to be any function that we have
// already processed, in the case when there isn't a main or there are
// unreachable functions!
if (F->isDeclaration()) { // sprintf, fprintf, sscanf, etc...
// No callees!
Stack.pop_back();
ValMap[F] = ~0;
return Min;
}
DSGraph* Graph = getOrFetchDSGraph(F);
// Find all callee functions.
std::vector<const Function*> CalleeFunctions;
GetAllAuxCallees(Graph, CalleeFunctions);
std::sort(CalleeFunctions.begin(), CalleeFunctions.end());
std::vector<const Function*>::iterator uid = std::unique(CalleeFunctions.begin(), CalleeFunctions.end());
CalleeFunctions.resize(uid - CalleeFunctions.begin());
// The edges out of the current node are the call site targets...
for (unsigned i = 0, e = CalleeFunctions.size(); i != e; ++i) {
const Function *Callee = CalleeFunctions[i];
unsigned M;
// Have we visited the destination function yet?
hash_map<const Function*, unsigned>::iterator It = ValMap.find(Callee);
if (It == ValMap.end()) // No, visit it now.
M = calculateGraphs(Callee, Stack, NextID, ValMap);
else // Yes, get it's number.
M = It->second;
if (M < Min) Min = M;
}
assert(ValMap[F] == MyID && "SCC construction assumption wrong!");
if (Min != MyID)
return Min; // This is part of a larger SCC!
// If this is a new SCC, process it now.
if (Stack.back() == F) { // Special case the single "SCC" case here.
DEBUG(errs() << "Visiting single node SCC #: " << MyID << " fn: "
<< F->getName() << "\n");
Stack.pop_back();
DEBUG(errs() << " [BU] Calculating graph for: " << F->getName()<< "\n");
calculateGraph(Graph);
DEBUG(errs() << " [BU] Done inlining: " << F->getName() << " ["
<< Graph->getGraphSize() << "+" << Graph->getAuxFunctionCalls().size()
<< "]\n");
if (MaxSCC < 1) MaxSCC = 1;
// Should we revisit the graph? Only do it if there are now new resolvable
// callees or new callees
GetAllAuxCallees(Graph, CalleeFunctions);
if (CalleeFunctions.size()) {
DEBUG(errs() << "Recalculating " << F->getName() << " due to new knowledge\n");
ValMap.erase(F);
return calculateGraphs(F, Stack, NextID, ValMap);
} else {
ValMap[F] = ~0U;
return MyID;
}
} else {
// SCCFunctions - Keep track of the functions in the current SCC
//
std::vector<DSGraph*> SCCGraphs;
unsigned SCCSize = 1;
const Function *NF = Stack.back();
ValMap[NF] = ~0U;
DSGraph* SCCGraph = getDSGraph(NF);
// First thing first, collapse all of the DSGraphs into a single graph for
// the entire SCC. Splice all of the graphs into one and discard all of the
// old graphs.
//
while (NF != F) {
Stack.pop_back();
NF = Stack.back();
ValMap[NF] = ~0U;
DSGraph* NFG = getDSGraph(NF);
if (NFG != SCCGraph) {
// Update the Function -> DSG map.
for (DSGraph::retnodes_iterator I = NFG->retnodes_begin(),
E = NFG->retnodes_end(); I != E; ++I)
setDSGraph(I->first, SCCGraph);
SCCGraph->spliceFrom(NFG);
delete NFG;
++SCCSize;
}
//.........这里部分代码省略.........