2002-11-06 17:02:03 +00:00
|
|
|
//===- IPModRef.cpp - Compute IP Mod/Ref information ------------*- C++ -*-===//
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-11-06 17:02:03 +00:00
|
|
|
//
|
2004-07-07 06:32:21 +00:00
|
|
|
// See high-level comments in IPModRef.h
|
2002-11-06 17:02:03 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-06-28 00:41:23 +00:00
|
|
|
#include "IPModRef.h"
|
2004-07-07 06:32:21 +00:00
|
|
|
#include "llvm/Analysis/DataStructure/DataStructure.h"
|
|
|
|
#include "llvm/Analysis/DataStructure/DSGraph.h"
|
2002-11-06 17:02:03 +00:00
|
|
|
#include "llvm/Module.h"
|
2002-11-27 17:37:46 +00:00
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/iMemory.h"
|
2002-11-06 17:02:03 +00:00
|
|
|
#include "llvm/iOther.h"
|
|
|
|
#include "Support/Statistic.h"
|
|
|
|
#include "Support/STLExtras.h"
|
|
|
|
#include "Support/StringExtras.h"
|
2002-11-27 17:37:46 +00:00
|
|
|
#include <vector>
|
2002-11-06 17:02:03 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-11-06 17:02:03 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Private constants and data
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static RegisterAnalysis<IPModRef>
|
|
|
|
Z("ipmodref", "Interprocedural mod/ref analysis");
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// class ModRefInfo
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2002-11-27 17:37:46 +00:00
|
|
|
void ModRefInfo::print(std::ostream &O,
|
|
|
|
const std::string& sprefix) const
|
2002-11-06 17:02:03 +00:00
|
|
|
{
|
2002-11-27 17:37:46 +00:00
|
|
|
O << sprefix << "Modified nodes = " << modNodeSet;
|
|
|
|
O << sprefix << "Referenced nodes = " << refNodeSet;
|
2002-11-06 17:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModRefInfo::dump() const
|
|
|
|
{
|
|
|
|
print(std::cerr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// class FunctionModRefInfo
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// This constructor computes a node numbering for the TD graph.
|
|
|
|
//
|
|
|
|
FunctionModRefInfo::FunctionModRefInfo(const Function& func,
|
2002-11-06 19:07:13 +00:00
|
|
|
IPModRef& ipmro,
|
2002-11-27 17:37:46 +00:00
|
|
|
DSGraph* tdgClone)
|
2002-11-06 19:07:13 +00:00
|
|
|
: F(func), IPModRefObj(ipmro),
|
2002-11-27 17:37:46 +00:00
|
|
|
funcTDGraph(tdgClone),
|
|
|
|
funcModRefInfo(tdgClone->getGraphSize())
|
2002-11-06 17:02:03 +00:00
|
|
|
{
|
2004-02-07 23:57:26 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
for (DSGraph::node_iterator NI = funcTDGraph->node_begin(),
|
|
|
|
E = funcTDGraph->node_end(); NI != E; ++NI)
|
|
|
|
NodeIds[*NI] = i++;
|
2002-11-06 17:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FunctionModRefInfo::~FunctionModRefInfo()
|
|
|
|
{
|
2003-09-20 16:34:13 +00:00
|
|
|
for(std::map<const Instruction*, ModRefInfo*>::iterator
|
2002-11-06 17:02:03 +00:00
|
|
|
I=callSiteModRefInfo.begin(), E=callSiteModRefInfo.end(); I != E; ++I)
|
|
|
|
delete(I->second);
|
|
|
|
|
|
|
|
// Empty map just to make problems easier to track down
|
|
|
|
callSiteModRefInfo.clear();
|
2002-11-27 17:37:46 +00:00
|
|
|
|
|
|
|
delete funcTDGraph;
|
2002-11-06 17:02:03 +00:00
|
|
|
}
|
|
|
|
|
2002-11-06 18:38:18 +00:00
|
|
|
unsigned FunctionModRefInfo::getNodeId(const Value* value) const {
|
2002-11-27 17:37:46 +00:00
|
|
|
return getNodeId(funcTDGraph->getNodeForValue(const_cast<Value*>(value))
|
2002-11-06 18:38:18 +00:00
|
|
|
.getNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-06 17:02:03 +00:00
|
|
|
|
|
|
|
// Compute Mod/Ref bit vectors for the entire function.
|
|
|
|
// These are simply copies of the Read/Write flags from the nodes of
|
|
|
|
// the top-down DS graph.
|
|
|
|
//
|
|
|
|
void FunctionModRefInfo::computeModRef(const Function &func)
|
|
|
|
{
|
|
|
|
// Mark all nodes in the graph that are marked MOD as being mod
|
|
|
|
// and all those marked REF as being ref.
|
2004-02-07 23:57:26 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
for (DSGraph::node_iterator NI = funcTDGraph->node_begin(),
|
|
|
|
E = funcTDGraph->node_end(); NI != E; ++NI, ++i) {
|
|
|
|
if ((*NI)->isModified()) funcModRefInfo.setNodeIsMod(i);
|
|
|
|
if ((*NI)->isRead()) funcModRefInfo.setNodeIsRef(i);
|
|
|
|
}
|
2002-11-06 17:02:03 +00:00
|
|
|
|
2002-11-27 17:37:46 +00:00
|
|
|
// Compute the Mod/Ref info for all call sites within the function.
|
|
|
|
// The call sites are recorded in the TD graph.
|
|
|
|
const std::vector<DSCallSite>& callSites = funcTDGraph->getFunctionCalls();
|
2002-11-06 17:02:03 +00:00
|
|
|
for (unsigned i = 0, N = callSites.size(); i < N; ++i)
|
2003-09-20 16:34:13 +00:00
|
|
|
computeModRef(callSites[i].getCallSite());
|
2002-11-06 17:02:03 +00:00
|
|
|
}
|
|
|
|
|
2002-11-27 17:37:46 +00:00
|
|
|
|
2002-11-06 19:38:43 +00:00
|
|
|
// ResolveCallSiteModRefInfo - This method performs the following actions:
|
|
|
|
//
|
|
|
|
// 1. It clones the top-down graph for the current function
|
|
|
|
// 2. It clears all of the mod/ref bits in the cloned graph
|
|
|
|
// 3. It then merges the bottom-up graph(s) for the specified call-site into
|
|
|
|
// the clone (bringing new mod/ref bits).
|
2002-11-06 19:59:33 +00:00
|
|
|
// 4. It returns the clone, and a mapping of nodes from the original TDGraph to
|
|
|
|
// the cloned graph with Mod/Ref info for the callsite.
|
2002-11-06 19:38:43 +00:00
|
|
|
//
|
|
|
|
// NOTE: Because this clones a dsgraph and returns it, the caller is responsible
|
|
|
|
// for deleting the returned graph!
|
2002-11-07 07:12:23 +00:00
|
|
|
// NOTE: This method may return a null pointer if it is unable to determine the
|
|
|
|
// requested information (because the call site calls an external
|
|
|
|
// function or we cannot determine the complete set of functions invoked).
|
2002-11-06 19:38:43 +00:00
|
|
|
//
|
2003-09-20 16:34:13 +00:00
|
|
|
DSGraph* FunctionModRefInfo::ResolveCallSiteModRefInfo(CallSite CS,
|
2003-02-01 04:52:08 +00:00
|
|
|
hash_map<const DSNode*, DSNodeHandle> &NodeMap)
|
2002-11-27 17:37:46 +00:00
|
|
|
{
|
|
|
|
// Step #0: Quick check if we are going to fail anyway: avoid
|
|
|
|
// all the graph cloning and map copying in steps #1 and #2.
|
|
|
|
//
|
2003-09-20 16:34:13 +00:00
|
|
|
if (const Function *F = CS.getCalledFunction()) {
|
|
|
|
if (F->isExternal())
|
2002-11-27 17:37:46 +00:00
|
|
|
return 0; // We cannot compute Mod/Ref info for this callsite...
|
2003-09-20 16:34:13 +00:00
|
|
|
} else {
|
|
|
|
// Eventually, should check here if any callee is external.
|
|
|
|
// For now we are not handling this case anyway.
|
|
|
|
std::cerr << "IP Mod/Ref indirect call not implemented yet: "
|
|
|
|
<< "Being conservative\n";
|
|
|
|
return 0; // We cannot compute Mod/Ref info for this callsite...
|
|
|
|
}
|
2002-11-06 19:59:33 +00:00
|
|
|
|
2002-11-06 19:38:43 +00:00
|
|
|
// Step #1: Clone the top-down graph...
|
2002-11-27 17:37:46 +00:00
|
|
|
DSGraph *Result = new DSGraph(*funcTDGraph, NodeMap);
|
2002-11-06 19:59:33 +00:00
|
|
|
|
|
|
|
// Step #2: Clear Mod/Ref information...
|
|
|
|
Result->maskNodeTypes(~(DSNode::Modified | DSNode::Read));
|
2002-11-06 19:38:43 +00:00
|
|
|
|
2002-11-07 07:12:23 +00:00
|
|
|
// Step #3: clone the bottom up graphs for the callees into the caller graph
|
2003-09-20 16:34:13 +00:00
|
|
|
if (Function *F = CS.getCalledFunction())
|
2002-11-27 17:37:46 +00:00
|
|
|
{
|
|
|
|
assert(!F->isExternal());
|
|
|
|
|
|
|
|
// Build up a DSCallSite for our invocation point here...
|
|
|
|
|
|
|
|
// If the call returns a value, make sure to merge the nodes...
|
|
|
|
DSNodeHandle RetVal;
|
2003-09-20 16:34:13 +00:00
|
|
|
if (DS::isPointerType(CS.getInstruction()->getType()))
|
|
|
|
RetVal = Result->getNodeForValue(CS.getInstruction());
|
2002-11-27 17:37:46 +00:00
|
|
|
|
|
|
|
// Populate the arguments list...
|
|
|
|
std::vector<DSNodeHandle> Args;
|
2003-09-20 16:34:13 +00:00
|
|
|
for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end();
|
|
|
|
I != E; ++I)
|
|
|
|
if (DS::isPointerType((*I)->getType()))
|
|
|
|
Args.push_back(Result->getNodeForValue(*I));
|
2002-11-27 17:37:46 +00:00
|
|
|
|
|
|
|
// Build the call site...
|
2003-11-05 05:55:45 +00:00
|
|
|
DSCallSite NCS(CS, RetVal, F, Args);
|
2002-11-27 17:37:46 +00:00
|
|
|
|
|
|
|
// Perform the merging now of the graph for the callee, which will
|
|
|
|
// come with mod/ref bits set...
|
2003-11-05 05:55:45 +00:00
|
|
|
Result->mergeInGraph(NCS, *F, IPModRefObj.getBUDSGraph(*F),
|
2002-11-27 17:37:46 +00:00
|
|
|
DSGraph::StripAllocaBit
|
|
|
|
| DSGraph::DontCloneCallNodes
|
|
|
|
| DSGraph::DontCloneAuxCallNodes);
|
2002-11-07 07:12:23 +00:00
|
|
|
}
|
2002-11-27 17:37:46 +00:00
|
|
|
else
|
|
|
|
assert(0 && "See error message");
|
2002-11-06 19:38:43 +00:00
|
|
|
|
2002-11-27 17:37:46 +00:00
|
|
|
// Remove dead nodes aggressively to match the caller's original graph.
|
2003-01-23 22:06:33 +00:00
|
|
|
Result->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
|
2002-11-07 07:12:23 +00:00
|
|
|
|
|
|
|
// Step #4: Return the clone + the mapping (by ref)
|
2002-11-06 19:38:43 +00:00
|
|
|
return Result;
|
|
|
|
}
|
2002-11-06 17:02:03 +00:00
|
|
|
|
|
|
|
// Compute Mod/Ref bit vectors for a single call site.
|
|
|
|
// These are copies of the Read/Write flags from the nodes of
|
2003-09-11 18:14:24 +00:00
|
|
|
// the graph produced by clearing all flags in the caller's TD graph
|
2002-11-06 17:02:03 +00:00
|
|
|
// and then inlining the callee's BU graph into the caller's TD graph.
|
|
|
|
//
|
|
|
|
void
|
2003-09-20 16:34:13 +00:00
|
|
|
FunctionModRefInfo::computeModRef(CallSite CS)
|
2002-11-06 17:02:03 +00:00
|
|
|
{
|
|
|
|
// Allocate the mod/ref info for the call site. Bits automatically cleared.
|
2002-11-27 17:37:46 +00:00
|
|
|
ModRefInfo* callModRefInfo = new ModRefInfo(funcTDGraph->getGraphSize());
|
2003-09-20 16:34:13 +00:00
|
|
|
callSiteModRefInfo[CS.getInstruction()] = callModRefInfo;
|
2002-11-06 17:02:03 +00:00
|
|
|
|
|
|
|
// Get a copy of the graph for the callee with the callee inlined
|
2003-02-01 04:52:08 +00:00
|
|
|
hash_map<const DSNode*, DSNodeHandle> NodeMap;
|
2003-09-20 16:34:13 +00:00
|
|
|
DSGraph* csgp = ResolveCallSiteModRefInfo(CS, NodeMap);
|
2002-11-27 17:37:46 +00:00
|
|
|
if (!csgp)
|
|
|
|
{ // Callee's side effects are unknown: mark all nodes Mod and Ref.
|
|
|
|
// Eventually this should only mark nodes visible to the callee, i.e.,
|
|
|
|
// exclude stack variables not reachable from any outgoing argument
|
|
|
|
// or any global.
|
|
|
|
callModRefInfo->getModSet().set();
|
|
|
|
callModRefInfo->getRefSet().set();
|
|
|
|
return;
|
|
|
|
}
|
2002-11-06 17:02:03 +00:00
|
|
|
|
|
|
|
// For all nodes in the graph, extract the mod/ref information
|
2004-02-07 23:57:26 +00:00
|
|
|
for (DSGraph::node_iterator NI = funcTDGraph->node_begin(),
|
|
|
|
E = funcTDGraph->node_end(); NI != E; ++NI) {
|
|
|
|
DSNode* csgNode = NodeMap[*NI].getNode();
|
|
|
|
assert(csgNode && "Inlined and original graphs do not correspond!");
|
|
|
|
if (csgNode->isModified())
|
|
|
|
callModRefInfo->setNodeIsMod(getNodeId(*NI));
|
|
|
|
if (csgNode->isRead())
|
|
|
|
callModRefInfo->setNodeIsRef(getNodeId(*NI));
|
|
|
|
}
|
2002-11-07 05:00:35 +00:00
|
|
|
|
|
|
|
// Drop nodemap before we delete the graph...
|
|
|
|
NodeMap.clear();
|
2002-11-06 19:38:43 +00:00
|
|
|
delete csgp;
|
2002-11-06 17:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-27 17:37:46 +00:00
|
|
|
class DSGraphPrintHelper {
|
|
|
|
const DSGraph& tdGraph;
|
|
|
|
std::vector<std::vector<const Value*> > knownValues; // identifiable objects
|
|
|
|
|
|
|
|
public:
|
|
|
|
/*ctor*/ DSGraphPrintHelper(const FunctionModRefInfo& fmrInfo)
|
|
|
|
: tdGraph(fmrInfo.getFuncGraph())
|
|
|
|
{
|
|
|
|
knownValues.resize(tdGraph.getGraphSize());
|
|
|
|
|
|
|
|
// For every identifiable value, save Value pointer in knownValues[i]
|
2003-02-01 04:52:08 +00:00
|
|
|
for (hash_map<Value*, DSNodeHandle>::const_iterator
|
2002-11-27 17:37:46 +00:00
|
|
|
I = tdGraph.getScalarMap().begin(),
|
|
|
|
E = tdGraph.getScalarMap().end(); I != E; ++I)
|
|
|
|
if (isa<GlobalValue>(I->first) ||
|
|
|
|
isa<Argument>(I->first) ||
|
|
|
|
isa<LoadInst>(I->first) ||
|
|
|
|
isa<AllocaInst>(I->first) ||
|
|
|
|
isa<MallocInst>(I->first))
|
|
|
|
{
|
|
|
|
unsigned nodeId = fmrInfo.getNodeId(I->second.getNode());
|
|
|
|
knownValues[nodeId].push_back(I->first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void printValuesInBitVec(std::ostream &O, const BitSetVector& bv) const
|
|
|
|
{
|
|
|
|
assert(bv.size() == knownValues.size());
|
|
|
|
|
|
|
|
if (bv.none())
|
|
|
|
{ // No bits are set: just say so and return
|
|
|
|
O << "\tNONE.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bv.all())
|
|
|
|
{ // All bits are set: just say so and return
|
|
|
|
O << "\tALL GRAPH NODES.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i=0, N=bv.size(); i < N; ++i)
|
|
|
|
if (bv.test(i))
|
|
|
|
{
|
|
|
|
O << "\tNode# " << i << " : ";
|
|
|
|
if (! knownValues[i].empty())
|
|
|
|
for (unsigned j=0, NV=knownValues[i].size(); j < NV; j++)
|
|
|
|
{
|
|
|
|
const Value* V = knownValues[i][j];
|
|
|
|
|
|
|
|
if (isa<GlobalValue>(V)) O << "(Global) ";
|
|
|
|
else if (isa<Argument>(V)) O << "(Target of FormalParm) ";
|
|
|
|
else if (isa<LoadInst>(V)) O << "(Target of LoadInst ) ";
|
|
|
|
else if (isa<AllocaInst>(V)) O << "(Target of AllocaInst) ";
|
|
|
|
else if (isa<MallocInst>(V)) O << "(Target of MallocInst) ";
|
|
|
|
|
|
|
|
if (V->hasName()) O << V->getName();
|
|
|
|
else if (isa<Instruction>(V)) O << *V;
|
|
|
|
else O << "(Value*) 0x" << (void*) V;
|
|
|
|
|
|
|
|
O << std::string((j < NV-1)? "; " : "\n");
|
|
|
|
}
|
2004-02-07 23:57:26 +00:00
|
|
|
#if 0
|
2002-11-27 17:37:46 +00:00
|
|
|
else
|
|
|
|
tdGraph.getNodes()[i]->print(O, /*graph*/ NULL);
|
2004-02-07 23:57:26 +00:00
|
|
|
#endif
|
2002-11-27 17:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-11-06 17:02:03 +00:00
|
|
|
// Print the results of the pass.
|
|
|
|
// Currently this just prints bit-vectors and is not very readable.
|
|
|
|
//
|
|
|
|
void FunctionModRefInfo::print(std::ostream &O) const
|
|
|
|
{
|
2002-11-27 17:37:46 +00:00
|
|
|
DSGraphPrintHelper DPH(*this);
|
|
|
|
|
|
|
|
O << "========== Mod/ref information for function "
|
|
|
|
<< F.getName() << "========== \n\n";
|
2002-11-06 17:02:03 +00:00
|
|
|
|
2002-11-27 17:37:46 +00:00
|
|
|
// First: Print Globals and Locals modified anywhere in the function.
|
|
|
|
//
|
|
|
|
O << " -----Mod/Ref in the body of function " << F.getName()<< ":\n";
|
2002-11-06 17:02:03 +00:00
|
|
|
|
2002-11-27 17:37:46 +00:00
|
|
|
O << " --Objects modified in the function body:\n";
|
|
|
|
DPH.printValuesInBitVec(O, funcModRefInfo.getModSet());
|
|
|
|
|
|
|
|
O << " --Objects referenced in the function body:\n";
|
|
|
|
DPH.printValuesInBitVec(O, funcModRefInfo.getRefSet());
|
|
|
|
|
|
|
|
O << " --Mod and Ref vectors for the nodes listed above:\n";
|
|
|
|
funcModRefInfo.print(O, "\t");
|
|
|
|
|
|
|
|
O << "\n";
|
|
|
|
|
|
|
|
// Second: Print Globals and Locals modified at each call site in function
|
|
|
|
//
|
2003-09-20 16:34:13 +00:00
|
|
|
for (std::map<const Instruction *, ModRefInfo*>::const_iterator
|
2002-11-06 17:02:03 +00:00
|
|
|
CI = callSiteModRefInfo.begin(), CE = callSiteModRefInfo.end();
|
|
|
|
CI != CE; ++CI)
|
|
|
|
{
|
2002-11-27 17:37:46 +00:00
|
|
|
O << " ----Mod/Ref information for call site\n" << CI->first;
|
|
|
|
|
|
|
|
O << " --Objects modified at call site:\n";
|
|
|
|
DPH.printValuesInBitVec(O, CI->second->getModSet());
|
|
|
|
|
|
|
|
O << " --Objects referenced at call site:\n";
|
|
|
|
DPH.printValuesInBitVec(O, CI->second->getRefSet());
|
|
|
|
|
|
|
|
O << " --Mod and Ref vectors for the nodes listed above:\n";
|
|
|
|
CI->second->print(O, "\t");
|
|
|
|
|
|
|
|
O << "\n";
|
2002-11-06 17:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
O << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionModRefInfo::dump() const
|
|
|
|
{
|
|
|
|
print(std::cerr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// class IPModRef: An interprocedural pass that computes IP Mod/Ref info.
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Free the FunctionModRefInfo objects cached in funcToModRefInfoMap.
|
|
|
|
//
|
|
|
|
void IPModRef::releaseMemory()
|
|
|
|
{
|
|
|
|
for(std::map<const Function*, FunctionModRefInfo*>::iterator
|
|
|
|
I=funcToModRefInfoMap.begin(), E=funcToModRefInfoMap.end(); I != E; ++I)
|
|
|
|
delete(I->second);
|
|
|
|
|
|
|
|
// Clear map so memory is not re-released if we are called again
|
|
|
|
funcToModRefInfoMap.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run the "interprocedural" pass on each function. This needs to do
|
|
|
|
// NO real interprocedural work because all that has been done the
|
|
|
|
// data structure analysis.
|
|
|
|
//
|
|
|
|
bool IPModRef::run(Module &theModule)
|
|
|
|
{
|
|
|
|
M = &theModule;
|
2002-11-07 05:00:35 +00:00
|
|
|
|
2002-11-06 17:02:03 +00:00
|
|
|
for (Module::const_iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
|
|
|
|
if (! FI->isExternal())
|
|
|
|
getFuncInfo(*FI, /*computeIfMissing*/ true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-06 18:38:18 +00:00
|
|
|
FunctionModRefInfo& IPModRef::getFuncInfo(const Function& func,
|
|
|
|
bool computeIfMissing)
|
|
|
|
{
|
|
|
|
FunctionModRefInfo*& funcInfo = funcToModRefInfoMap[&func];
|
|
|
|
assert (funcInfo != NULL || computeIfMissing);
|
2002-11-06 19:07:13 +00:00
|
|
|
if (funcInfo == NULL)
|
2002-11-27 17:37:46 +00:00
|
|
|
{ // Create a new FunctionModRefInfo object.
|
|
|
|
// Clone the top-down graph and remove any dead nodes first, because
|
|
|
|
// otherwise original and merged graphs will not match.
|
|
|
|
// The memory for this graph clone will be freed by FunctionModRefInfo.
|
|
|
|
DSGraph* funcTDGraph =
|
|
|
|
new DSGraph(getAnalysis<TDDataStructures>().getDSGraph(func));
|
2003-01-23 22:06:33 +00:00
|
|
|
funcTDGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
|
2002-11-27 17:37:46 +00:00
|
|
|
|
|
|
|
funcInfo = new FunctionModRefInfo(func, *this, funcTDGraph); //auto-insert
|
|
|
|
funcInfo->computeModRef(func); // computes the mod/ref info
|
2002-11-06 18:38:18 +00:00
|
|
|
}
|
|
|
|
return *funcInfo;
|
|
|
|
}
|
|
|
|
|
2002-11-07 07:12:23 +00:00
|
|
|
/// getBUDSGraph - This method returns the BU data structure graph for F through
|
|
|
|
/// the use of the BUDataStructures object.
|
|
|
|
///
|
|
|
|
const DSGraph &IPModRef::getBUDSGraph(const Function &F) {
|
|
|
|
return getAnalysis<BUDataStructures>().getDSGraph(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-06 18:38:18 +00:00
|
|
|
// getAnalysisUsage - This pass requires top-down data structure graphs.
|
|
|
|
// It modifies nothing.
|
|
|
|
//
|
|
|
|
void IPModRef::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<LocalDataStructures>();
|
2002-11-06 19:07:13 +00:00
|
|
|
AU.addRequired<BUDataStructures>();
|
2002-11-06 18:38:18 +00:00
|
|
|
AU.addRequired<TDDataStructures>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-06 17:02:03 +00:00
|
|
|
void IPModRef::print(std::ostream &O) const
|
|
|
|
{
|
2002-11-27 17:37:46 +00:00
|
|
|
O << "\nRESULTS OF INTERPROCEDURAL MOD/REF ANALYSIS:\n\n";
|
2002-11-06 17:02:03 +00:00
|
|
|
|
|
|
|
for (std::map<const Function*, FunctionModRefInfo*>::const_iterator
|
|
|
|
mapI = funcToModRefInfoMap.begin(), mapE = funcToModRefInfoMap.end();
|
|
|
|
mapI != mapE; ++mapI)
|
|
|
|
mapI->second->print(O);
|
|
|
|
|
|
|
|
O << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IPModRef::dump() const
|
|
|
|
{
|
|
|
|
print(std::cerr);
|
|
|
|
}
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
} // End llvm namespace
|