[llvm-commits] [poolalloc] r57451 - in /poolalloc/trunk: include/dsa/DataStructure.h lib/DSA/BottomUpClosure.cpp lib/DSA/CompleteBottomUp.cpp lib/DSA/DataStructure.cpp lib/DSA/Local.cpp lib/DSA/Printer.cpp lib/DSA/StdLibPass.cpp lib/DSA/TopDownClosure.cpp lib/PoolAllocate/PoolAllocate.cpp lib/PoolAllocate/TransformFunctionBody.cpp
Andrew Lenharth
alenhar2 at cs.uiuc.edu
Mon Oct 13 10:47:38 PDT 2008
Author: alenhar2
Date: Mon Oct 13 12:47:38 2008
New Revision: 57451
URL: http://llvm.org/viewvc/llvm-project?rev=57451&view=rev
Log:
Fix a number of bugs, much more of multisource passes now
Modified:
poolalloc/trunk/include/dsa/DataStructure.h
poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp
poolalloc/trunk/lib/DSA/DataStructure.cpp
poolalloc/trunk/lib/DSA/Local.cpp
poolalloc/trunk/lib/DSA/Printer.cpp
poolalloc/trunk/lib/DSA/StdLibPass.cpp
poolalloc/trunk/lib/DSA/TopDownClosure.cpp
poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
Modified: poolalloc/trunk/include/dsa/DataStructure.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Mon Oct 13 12:47:38 2008
@@ -37,10 +37,10 @@
FunctionPass *createDataStructureGraphCheckerPass();
class DataStructures : public ModulePass {
- typedef std::map<const Instruction*, std::set<const Function*> > ActualCalleesTy;
+ typedef hash_map<const Instruction*, hash_set<const Function*> > ActualCalleesTy;
typedef hash_map<const Function*, DSGraph*> DSInfoTy;
public:
- typedef std::set<const Function*>::const_iterator callee_iterator;
+ typedef hash_set<const Function*>::const_iterator callee_iterator;
private:
/// TargetData, comes in handy
@@ -52,6 +52,10 @@
/// Do we clone Graphs or steal them?
bool Clone;
+
+ /// do we reset the aux list to the func list?
+ bool resetAuxCalls;
+
void buildGlobalECs(std::set<const GlobalValue*>& ECGlobals);
void eliminateUsesOfECGlobals(DSGraph& G, const std::set<const GlobalValue*> &ECGlobals);
@@ -62,6 +66,9 @@
// Callgraph, as computed so far
ActualCalleesTy ActualCallees;
+ // Name for printing
+ const char* printname;
+
protected:
/// The Globals Graph contains all information on the globals
@@ -72,7 +79,7 @@
EquivalenceClasses<const GlobalValue*> GlobalECs;
- void init(DataStructures* D, bool clone, bool printAuxCalls, bool copyGlobalAuxCalls);
+ void init(DataStructures* D, bool clone, bool printAuxCalls, bool copyGlobalAuxCalls, bool resetAux);
void init(TargetData* T);
void formGlobalECs();
@@ -82,13 +89,18 @@
ActualCallees[I].insert(F);
}
- DataStructures(intptr_t id)
- :ModulePass(id), TD(0), GraphSource(0), GlobalsGraph(0) {
+ DataStructures(intptr_t id, const char* name)
+ :ModulePass(id), TD(0), GraphSource(0), printname(name), GlobalsGraph(0) {
//a dummy node for empty call sites
ActualCallees[0];
}
public:
+ /// print - Print out the analysis results...
+ ///
+ void print(std::ostream &O, const Module *M) const;
+ void dumpCallGraph() const;
+
callee_iterator callee_begin(const Instruction *I) const {
ActualCalleesTy::const_iterator ii = ActualCallees.find(I);
if (ii == ActualCallees.end())
@@ -103,6 +115,10 @@
return ii->second.end();
}
+ void callee_site(const Instruction* I) {
+ ActualCallees[I];
+ }
+
unsigned callee_size() const {
unsigned sum = 0;
for (ActualCalleesTy::const_iterator ii = ActualCallees.begin(),
@@ -159,15 +175,11 @@
class LocalDataStructures : public DataStructures {
public:
static char ID;
- LocalDataStructures() : DataStructures((intptr_t)&ID) {}
+ LocalDataStructures() : DataStructures((intptr_t)&ID, "local.") {}
~LocalDataStructures() { releaseMemory(); }
virtual bool runOnModule(Module &M);
- /// print - Print out the analysis results...
- ///
- void print(std::ostream &O, const Module *M) const;
-
/// getAnalysisUsage - This obviously provides a data structure graph.
///
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -181,15 +193,11 @@
void eraseCallsTo(Function* F);
public:
static char ID;
- StdLibDataStructures() : DataStructures((intptr_t)&ID) {}
+ StdLibDataStructures() : DataStructures((intptr_t)&ID, "stdlib.") {}
~StdLibDataStructures() { releaseMemory(); }
virtual bool runOnModule(Module &M);
- /// print - Print out the analysis results...
- ///
- void print(std::ostream &O, const Module *M) const;
-
/// getAnalysisUsage - This obviously provides a data structure graph.
///
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -209,15 +217,17 @@
std::pair<DSGraph*, std::vector<DSNodeHandle> > > IndCallGraphMap;
const char* debugname;
+ bool useCallGraph;
public:
static char ID;
//Child constructor
- BUDataStructures(intptr_t CID, const char* name)
- : DataStructures(CID), debugname(name) {}
+ BUDataStructures(intptr_t CID, const char* name, const char* printname)
+ : DataStructures(CID, printname), debugname(name), useCallGraph(true) {}
//main constructor
BUDataStructures()
- : DataStructures((intptr_t)&ID), debugname("dsa-bu") {}
+ : DataStructures((intptr_t)&ID, "bu."), debugname("dsa-bu"),
+ useCallGraph(false) {}
~BUDataStructures() { releaseMemory(); }
virtual bool runOnModule(Module &M);
@@ -227,10 +237,6 @@
void deleteValue(Value *V);
void copyValue(Value *From, Value *To);
- /// print - Print out the analysis results...
- ///
- void print(std::ostream &O, const Module *M) const;
-
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<StdLibDataStructures>();
}
@@ -289,15 +295,11 @@
public:
static char ID;
- TDDataStructures() : DataStructures((intptr_t)&ID) {}
+ TDDataStructures() : DataStructures((intptr_t)&ID, "td.") {}
~TDDataStructures() { releaseMemory(); }
virtual bool runOnModule(Module &M);
- /// print - Print out the analysis results...
- ///
- void print(std::ostream &O, const Module *M) const;
-
/// getAnalysisUsage - This obviously provides a data structure graph.
///
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -324,7 +326,7 @@
public:
static char ID;
CompleteBUDataStructures()
- : BUDataStructures((intptr_t)&ID, "dsa-cbu") {}
+ : BUDataStructures((intptr_t)&ID, "dsa-cbu", "cbu.") {}
~CompleteBUDataStructures() { releaseMemory(); }
virtual bool runOnModule(Module &M);
@@ -333,9 +335,6 @@
AU.addRequired<BUDataStructures>();
}
- /// print - Print out the analysis results...
- ///
- void print(std::ostream &O, const Module *M) const;
};
} // End llvm namespace
Modified: poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/BottomUpClosure.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/BottomUpClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/BottomUpClosure.cpp Mon Oct 13 12:47:38 2008
@@ -37,7 +37,7 @@
// program.
//
bool BUDataStructures::runOnModule(Module &M) {
- init(&getAnalysis<StdLibDataStructures>(), false, true, false);
+ init(&getAnalysis<StdLibDataStructures>(), false, true, false, false );
return runOnModuleInternal(M);
}
@@ -165,11 +165,11 @@
CS.getCalleeNode()->addFullFunctionList(Callees);
// If any of the callees are unresolvable, remove the whole batch!
- for (unsigned i = OldSize; i != Callees.size(); )
+ for (unsigned i = OldSize, e = Callees.size(); i != e; ++i)
if (Callees[i]->isDeclaration()) {
- Callees.erase(Callees.begin()+i);
- } else
- ++i;
+ Callees.erase(Callees.begin()+OldSize, Callees.end());
+ return;
+ }
}
}
@@ -183,12 +183,12 @@
unsigned OldSize = Callees.size();
CS.getCalleeNode()->addFullFunctionList(Callees);
- // If any of the callees are unresolvable, remove the whole batch!
- for (unsigned i = OldSize, e = Callees.size(); i != e; ++i)
+ // If any of the callees are unresolvable, remove them
+ for (unsigned i = OldSize; i != Callees.size(); )
if (Callees[i]->isDeclaration()) {
- Callees.erase(Callees.begin()+OldSize, Callees.end());
- return;
- }
+ Callees.erase(Callees.begin()+i);
+ } else
+ ++i;
}
}
@@ -352,6 +352,7 @@
for(DSGraph::afc_iterator ii = G.afc_begin(), ee = G.afc_end();
ii != ee; ++ii) {
+ //cerr << "Pushing " << ii->getCallSite().getInstruction()->getOperand(0) << "\n";
//If we can, merge with an existing call site for this instruction
if (GG.hasNodeForValue(ii->getCallSite().getInstruction()->getOperand(0))) {
DSGraph::afc_iterator GGii;
@@ -407,35 +408,36 @@
std::vector<const Function*> CalledFuncs;
while (!TempFCs.empty()) {
DSCallSite &CS = *TempFCs.begin();
+ Instruction *TheCall = CS.getCallSite().getInstruction();
CalledFuncs.clear();
- // Fast path for noop calls. Note that we don't care about merging globals
- // in the callee with nodes in the caller here.
- if (CS.getRetVal().isNull() && CS.getNumPtrArgs() == 0) {
- TempFCs.erase(TempFCs.begin());
- continue;
- }
-
GetAllCallees(CS, CalledFuncs);
bool isComplete = true;
if (CalledFuncs.empty()) {
// Remember that we could not resolve this yet!
- AuxCallsList.splice(AuxCallsList.end(), TempFCs, TempFCs.begin());
isComplete = false;
GetAnyCallees(CS, CalledFuncs);
+ if (useCallGraph)
+ for (callee_iterator ii = callee_begin(CS.getCallSite().getInstruction()),
+ ee = callee_end(CS.getCallSite().getInstruction()); ii != ee; ++ii)
+ CalledFuncs.push_back(*ii);
+ std::sort(CalledFuncs.begin(), CalledFuncs.end());
+ std::vector<const Function*>::iterator uid = std::unique(CalledFuncs.begin(), CalledFuncs.end());
+ CalledFuncs.resize(uid - CalledFuncs.begin());
}
-
- if (CalledFuncs.empty())
- continue;
+
+ //cerr << "at " << TheCall << " with " << CalledFuncs.size() << "\n";
DSGraph *GI;
- Instruction *TheCall = CS.getCallSite().getInstruction();
+ for (std::vector<const Function*>::iterator ii = CalledFuncs.begin(), ee = CalledFuncs.end();
+ ii != ee; ++ii)
+ callee_add(TheCall, *ii);
+
if (CalledFuncs.size() == 1 && (isComplete || hasDSGraph(*CalledFuncs[0]))) {
const Function *Callee = CalledFuncs[0];
- callee_add(TheCall, Callee);
// Get the data structure graph for the called function.
GI = &getDSGraph(*Callee); // Graph to inline
@@ -448,7 +450,7 @@
DSGraph::StripAllocaBit|DSGraph::DontCloneCallNodes|
(isComplete?0:DSGraph::DontCloneAuxCallNodes));
++NumInlines;
- } else {
+ } else if (CalledFuncs.size() > 1) {
DEBUG(std::cerr << "In Fns: " << Graph.getFunctionNames() << "\n");
DEBUG(std::cerr << " calls " << CalledFuncs.size()
<< " fns from site: " << CS.getCallSite().getInstruction()
@@ -457,12 +459,8 @@
unsigned NumPrinted = 0;
for (std::vector<const Function*>::iterator I = CalledFuncs.begin(),
- E = CalledFuncs.end(); I != E; ++I) {
+ E = CalledFuncs.end(); I != E; ++I)
if (NumPrinted++ < 8) DOUT << " " << (*I)->getName();
-
- // Add the call edges to the call graph.
- callee_add(TheCall, *I);
- }
DOUT << "\n";
if (!isComplete) {
@@ -534,8 +532,9 @@
(isComplete?0:DSGraph::DontCloneAuxCallNodes));
++NumInlines;
}
- if (isComplete)
- TempFCs.erase(TempFCs.begin());
+ if (!isComplete)
+ AuxCallsList.push_front(CS);
+ TempFCs.erase(TempFCs.begin());
}
// Recompute the Incomplete markers
@@ -561,24 +560,23 @@
}
void BUDataStructures::inlineUnresolved(DSGraph &Graph) {
- std::list<DSCallSite> TempFCs;
- std::list<DSCallSite> &AuxCallsList = Graph.getAuxFunctionCalls();
- TempFCs.insert(TempFCs.begin(), AuxCallsList.begin(), AuxCallsList.end());
-
- std::vector<const Function*> CalledFuncs;
- while (!TempFCs.empty()) {
- DSCallSite CS = *TempFCs.begin();
- TempFCs.erase(TempFCs.begin());
- CalledFuncs.clear();
+ for (DSGraph::afc_iterator aii = Graph.afc_begin(), aee = Graph.afc_end();
+ aii != aee; ++aii) {
+ std::vector<const Function*> CalledFuncs;
+ DSCallSite CS = *aii;
GetAnyCallees(CS, CalledFuncs);
if (CalledFuncs.empty())
continue;
DSGraph *GI;
Instruction *TheCall = CS.getCallSite().getInstruction();
+
+ for (std::vector<const Function*>::iterator ii = CalledFuncs.begin(), ee = CalledFuncs.end();
+ ii != ee; ++ii)
+ callee_add(TheCall, *ii);
+
if (CalledFuncs.size() == 1 && hasDSGraph(*CalledFuncs[0])) {
const Function *Callee = CalledFuncs[0];
- callee_add(TheCall, Callee);
// Get the data structure graph for the called function.
GI = &getDSGraph(*Callee); // Graph to inline
@@ -600,12 +598,8 @@
unsigned NumPrinted = 0;
for (std::vector<const Function*>::iterator I = CalledFuncs.begin(),
- E = CalledFuncs.end(); I != E; ++I) {
+ E = CalledFuncs.end(); I != E; ++I)
if (NumPrinted++ < 8) DOUT << " " << (*I)->getName();
-
- // Add the call edges to the call graph.
- callee_add(TheCall, *I);
- }
DOUT << "\n";
for (unsigned x = 0; x < CalledFuncs.size(); )
Modified: poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp (original)
+++ poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp Mon Oct 13 12:47:38 2008
@@ -32,7 +32,7 @@
// program.
//
bool CompleteBUDataStructures::runOnModule(Module &M) {
- init(&getAnalysis<BUDataStructures>(), false, true, false);
+ init(&getAnalysis<BUDataStructures>(), false, true, false, true);
buildIndirectFunctionSets(M);
@@ -49,11 +49,14 @@
//mege nodes in the global graph for these functions
for (std::vector<const Instruction*>::iterator ii = keys.begin(), ee = keys.end();
ii != ee; ++ii) {
- callee_iterator base = callee_begin(*ii);
- for (callee_iterator csi = callee_begin(*ii), cse = callee_end(*ii);
- csi != cse; ++csi) {
- GlobalECs.unionSets(*base, *csi);
- GlobalsGraph->getNodeForValue(*base).mergeWith(GlobalsGraph->getNodeForValue(*csi));
+ if (*ii) {
+ callee_iterator base = callee_begin(*ii);
+
+ for (callee_iterator csi = callee_begin(*ii), cse = callee_end(*ii);
+ csi != cse; ++csi) {
+ GlobalECs.unionSets(*base, *csi);
+ GlobalsGraph->getNodeForValue(*base).mergeWith(GlobalsGraph->getNodeForValue(*csi));
+ }
}
}
}
Modified: poolalloc/trunk/lib/DSA/DataStructure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DataStructure.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/DataStructure.cpp (original)
+++ poolalloc/trunk/lib/DSA/DataStructure.cpp Mon Oct 13 12:47:38 2008
@@ -146,7 +146,7 @@
if (T) mergeTypeInfo(T, 0);
if (G) G->addNode(this);
++NumNodeAllocated;
- DOUT << "LLVA: Creating (1) DSNode " << this << "\n";
+ // DOUT << "LLVA: Creating (1) DSNode " << this << "\n";
}
// DSNode copy constructor... do not copy over the referrers list!
@@ -159,7 +159,7 @@
Links.resize(N.Links.size()); // Create the appropriate number of null links
G->addNode(this);
++NumNodeAllocated;
- DOUT << "LLVA: Creating (2) DSNode " << this << "\n";
+ // DOUT << "LLVA: Creating (2) DSNode " << this << "\n";
}
DSNode::~DSNode() {
@@ -272,7 +272,7 @@
DestNode->Size = 1;
DestNode->Globals.swap(Globals);
- DOUT << "LLVA: foldNode: " << this << " becomes " << DestNode << "\n";
+ // DOUT << "LLVA: foldNode: " << this << " becomes " << DestNode << "\n";
#ifdef LLVA_KERNEL
//Again we have created a new DSNode, we need to fill in the
// pool desc map appropriately
@@ -480,7 +480,7 @@
///
bool DSNode::mergeTypeInfo(const Type *NewTy, unsigned Offset,
bool FoldIfIncompatible) {
- DOUT << "merging " << *NewTy << " at " << Offset << " with " << *Ty << "\n";
+ //DOUT << "merging " << *NewTy << " at " << Offset << " with " << *Ty << "\n";
const TargetData &TD = getTargetData();
// Check to make sure the Size member is up-to-date. Size can be one of the
// following:
@@ -978,7 +978,7 @@
/// point to this node).
///
void DSNode::mergeWith(const DSNodeHandle &NH, unsigned Offset) {
- DOUT << "mergeWith: " << this << " becomes " << NH.getNode() << "\n";
+ //DOUT << "mergeWith: " << this << " becomes " << NH.getNode() << "\n";
DSNode *N = NH.getNode();
if (N == this && NH.getOffset() == Offset)
return; // Noop
@@ -1229,7 +1229,7 @@
}
}
- DOUT << "LLVA: mergeWith: " << SN << " becomes " << DN << "\n";
+ // DOUT << "LLVA: mergeWith: " << SN << " becomes " << DN << "\n";
#ifdef LLVA_KERNEL
//Here some merge is going on just like in DSNode::merge
@@ -1671,6 +1671,8 @@
bool PathExistsToClonedNode(const DSCallSite &CS) {
if (PathExistsToClonedNode(CS.getRetVal().getNode()))
return true;
+ if (CS.isDirectCall() || PathExistsToClonedNode(CS.getCalleeNode()))
+ return true;
for (unsigned i = 0, e = CS.getNumPtrArgs(); i != e; ++i)
if (PathExistsToClonedNode(CS.getPtrArg(i).getNode()))
return true;
@@ -2134,6 +2136,7 @@
// If this call site is now the same as the previous one, we can delete it
// as a duplicate.
if (*OldIt == *CI) {
+ cerr << "Deleteing " << CI->getCallSite().getInstruction() << "\n";
Calls.erase(CI);
CI = OldIt;
++NumDeleted;
@@ -2732,7 +2735,8 @@
} else {
G = new DSGraph(GlobalECs, GraphSource->getTargetData());
G->spliceFrom(BaseGraph);
- G->getAuxFunctionCalls() = G->getFunctionCalls();
+ if (resetAuxCalls)
+ G->getAuxFunctionCalls() = G->getFunctionCalls();
}
G->setPrintAuxCalls();
G->setGlobalsGraph(GlobalsGraph);
@@ -2841,10 +2845,11 @@
}
void DataStructures::init(DataStructures* D, bool clone, bool printAuxCalls,
- bool copyGlobalAuxCalls) {
+ bool copyGlobalAuxCalls, bool resetAux) {
assert (!GraphSource && "Already init");
GraphSource = D;
Clone = clone;
+ resetAuxCalls = resetAux;
TD = D->TD;
ActualCallees = D->ActualCallees;
GlobalECs = D->getGlobalECs();
Modified: poolalloc/trunk/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Local.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Local.cpp (original)
+++ poolalloc/trunk/lib/DSA/Local.cpp Mon Oct 13 12:47:38 2008
@@ -37,18 +37,6 @@
static RegisterPass<LocalDataStructures>
X("dsa-local", "Local Data Structure Analysis");
-static cl::list<std::string>
-AllocList("dsa-alloc-list",
- cl::value_desc("list"),
- cl::desc("List of functions that allocate memory from the heap"),
- cl::CommaSeparated, cl::Hidden);
-
-static cl::list<std::string>
-FreeList("dsa-free-list",
- cl::value_desc("list"),
- cl::desc("List of functions that free memory from the heap"),
- cl::CommaSeparated, cl::Hidden);
-
namespace {
//===--------------------------------------------------------------------===//
// GraphBuilder Class
@@ -60,6 +48,7 @@
class GraphBuilder : InstVisitor<GraphBuilder> {
DSGraph &G;
Function* FB;
+ DataStructures* DS;
////////////////////////////////////////////////////////////////////////////
// Helper functions used to implement the visitation functions...
@@ -129,8 +118,8 @@
void visitCallSite(CallSite CS);
public:
- GraphBuilder(Function &f, DSGraph &g)
- : G(g), FB(&f) {
+ GraphBuilder(Function &f, DSGraph &g, DataStructures& DSi)
+ : G(g), FB(&f), DS(&DSi) {
// Create scalar nodes for all pointer arguments...
for (Function::arg_iterator I = f.arg_begin(), E = f.arg_end();
I != E; ++I) {
@@ -172,6 +161,7 @@
{}
void mergeInGlobalInitializer(GlobalVariable *GV);
+ void mergeFunction(Function& F) { getValueDest(F); }
};
}
@@ -194,10 +184,14 @@
// Check first for constant expressions that must be traversed to
// extract the actual value.
DSNode* N;
- if (GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
+ if (GlobalVariable* GV = dyn_cast<GlobalVariable>(V)) {
// Create a new global node for this global variable.
N = createNode(GV->getType()->getElementType());
N->addGlobal(GV);
+ } else if (Function* GV = dyn_cast<Function>(V)) {
+ // Create a new global node for this global variable.
+ N = createNode();
+ N->addGlobal(GV);
} else if (Constant *C = dyn_cast<Constant>(V)) {
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
if (CE->isCast()) {
@@ -637,29 +631,9 @@
// Special case handling of certain libc allocation functions here.
if (Function *F = dyn_cast<Function>(Callee))
- if (F->isDeclaration()) {
+ if (F->isDeclaration())
if (F->isIntrinsic() && visitIntrinsic(CS, F))
return;
- else {
- // Determine if the called function is one of the specified heap
- // allocation functions
- if (AllocList.end() != std::find(AllocList.begin(), AllocList.end(), F->getName())) {
- setDestTo(*CS.getInstruction(),
- createNode()->setHeapMarker()->setModifiedMarker());
- return;
- }
-
- // Determine if the called function is one of the specified heap
- // free functions
- if (FreeList.end() != std::find(FreeList.begin(), FreeList.end(),
- F->getName())) {
- // Mark that the node is written to...
- if (DSNode *N = getValueDest(*(CS.getArgument(0))).getNode())
- N->setModifiedMarker()->setHeapMarker();
- return;
- }
- }
- }
// Set up the return value...
DSNodeHandle RetVal;
@@ -685,9 +659,10 @@
Args.push_back(getValueDest(**I));
// Add a new function call entry...
- if (CalleeNode)
+ if (CalleeNode) {
G.getFunctionCalls().push_back(DSCallSite(CS, RetVal, CalleeNode, Args));
- else
+ DS->callee_site(CS.getInstruction());
+ }else
G.getFunctionCalls().push_back(DSCallSite(CS, RetVal, cast<Function>(Callee),
Args));
}
@@ -776,6 +751,10 @@
I != E; ++I)
if (!I->isDeclaration())
GGB.mergeInGlobalInitializer(I);
+ // Add Functions to the globals graph.
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ if (!I->isDeclaration())
+ GGB.mergeFunction(*I);
}
// Next step, iterate through the nodes in the globals graph, unioning
@@ -786,7 +765,8 @@
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isDeclaration()) {
DSGraph* G = new DSGraph(GlobalECs, getTargetData(), GlobalsGraph);
- GraphBuilder GGB(*I, *G);
+ GraphBuilder GGB(*I, *G, *this);
+ G->getAuxFunctionCalls() = G->getFunctionCalls();
setDSGraph(*I, G);
}
Modified: poolalloc/trunk/lib/DSA/Printer.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Printer.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Printer.cpp (original)
+++ poolalloc/trunk/lib/DSA/Printer.cpp Mon Oct 13 12:47:38 2008
@@ -35,6 +35,7 @@
namespace {
cl::opt<bool> OnlyPrintMain("only-print-main-ds", cl::ReallyHidden);
cl::opt<bool> DontPrintAnything("dont-print-ds", cl::ReallyHidden);
+ cl::opt<bool> LimitPrint("dsa-limit-print", cl::Hidden);
STATISTIC (MaxGraphSize , "Maximum graph size");
STATISTIC (NumFoldedNodes , "Number of folded nodes (in final graph)");
}
@@ -158,21 +159,23 @@
}
- // Add scalar nodes to the graph...
- const DSGraph::ScalarMapTy &VM = G->getScalarMap();
- for (DSGraph::ScalarMapTy::const_iterator I = VM.begin(); I != VM.end();++I)
- if (!isa<GlobalValue>(I->first)) {
- std::stringstream OS;
- WriteAsOperand(OS, I->first, false, CurMod);
- GW.emitSimpleNode(I->first, "", OS.str());
-
- // Add edge from return node to real destination
- DSNode *DestNode = I->second.getNode();
- int EdgeDest = I->second.getOffset() >> DS::PointerShift;
- if (EdgeDest == 0) EdgeDest = -1;
- GW.emitEdge(I->first, -1, DestNode,
- EdgeDest, "arrowtail=tee,color=gray63");
- }
+ if (!LimitPrint) {
+ // Add scalar nodes to the graph...
+ const DSGraph::ScalarMapTy &VM = G->getScalarMap();
+ for (DSGraph::ScalarMapTy::const_iterator I = VM.begin(); I != VM.end();++I)
+ if (!isa<GlobalValue>(I->first)) {
+ std::stringstream OS;
+ WriteAsOperand(OS, I->first, false, CurMod);
+ GW.emitSimpleNode(I->first, "", OS.str());
+
+ // Add edge from return node to real destination
+ DSNode *DestNode = I->second.getNode();
+ int EdgeDest = I->second.getOffset() >> DS::PointerShift;
+ if (EdgeDest == 0) EdgeDest = -1;
+ GW.emitEdge(I->first, -1, DestNode,
+ EdgeDest, "arrowtail=tee,color=gray63");
+ }
+ }
// Output the returned value pointer...
@@ -333,28 +336,23 @@
}
-// print - Print out the analysis results...
-void LocalDataStructures::print(std::ostream &O, const Module *M) const {
- if (DontPrintAnything) return;
- printCollection(*this, O, M, "ds.");
-}
-
-void StdLibDataStructures::print(std::ostream &O, const Module *M) const {
- if (DontPrintAnything) return;
- printCollection(*this, O, M, "ds.");
-}
-
-void BUDataStructures::print(std::ostream &O, const Module *M) const {
- if (DontPrintAnything) return;
- printCollection(*this, O, M, "bu.");
-}
-
-void TDDataStructures::print(std::ostream &O, const Module *M) const {
- if (DontPrintAnything) return;
- printCollection(*this, O, M, "td.");
+void DataStructures::dumpCallGraph() const {
+ for( ActualCalleesTy::const_iterator ii = ActualCallees.begin(), ee = ActualCallees.end();
+ ii != ee; ++ii) {
+ if (ii->first) cerr << ii->first->getParent()->getParent()->getName() << " ";
+ cerr << ii->first << ": [";
+ for (callee_iterator cbi = ii->second.begin(), cbe = ii->second.end();
+ cbi != cbe; ++cbi) {
+ cerr << (*cbi)->getName() << " ";
+ }
+ cerr << "]\n";
+ if (ii->first) ii->first->dump();
+ }
}
-void CompleteBUDataStructures::print(std::ostream &O, const Module *M) const {
+// print - Print out the analysis results...
+void DataStructures::print(std::ostream &O, const Module *M) const {
if (DontPrintAnything) return;
- printCollection(*this, O, M, "cbu.");
+ printCollection(*this, O, M, printname);
+ dumpCallGraph();
}
Modified: poolalloc/trunk/lib/DSA/StdLibPass.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/StdLibPass.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/StdLibPass.cpp (original)
+++ poolalloc/trunk/lib/DSA/StdLibPass.cpp Mon Oct 13 12:47:38 2008
@@ -65,6 +65,7 @@
{"fprintf", {NRET_YARGS, NRET_YNARGS, NRET_NARGS, false, false, false}},
{"sprintf", {NRET_YARGS, NRET_YNARGS, NRET_NARGS, false, false, false}},
{"snprintf", {NRET_YARGS, NRET_YNARGS, NRET_NARGS, false, false, false}},
+ {"puts", {NRET_NARGS, NRET_NARGS, NRET_NARGS, false, false, false}},
{"calloc", {NRET_NARGS, YRET_NARGS, YRET_NARGS, false, false, false}},
{"malloc", {NRET_NARGS, YRET_NARGS, YRET_NARGS, false, false, false}},
@@ -164,7 +165,7 @@
}
bool StdLibDataStructures::runOnModule(Module &M) {
- init(&getAnalysis<LocalDataStructures>(), false, true, false);
+ init(&getAnalysis<LocalDataStructures>(), false, true, false, false);
//Clone Module
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
Modified: poolalloc/trunk/lib/DSA/TopDownClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/TopDownClosure.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/TopDownClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/TopDownClosure.cpp Mon Oct 13 12:47:38 2008
@@ -61,7 +61,7 @@
// program.
//
bool TDDataStructures::runOnModule(Module &M) {
- init(&getAnalysis<BUDataStructures>(), true, true, true);
+ init(&getAnalysis<BUDataStructures>(), true, true, true, false);
// Figure out which functions must not mark their arguments complete because
// they are accessible outside this compilation unit. Currently, these
Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Mon Oct 13 12:47:38 2008
@@ -16,7 +16,6 @@
#include "dsa/DataStructure.h"
#include "dsa/DSGraph.h"
-#include "dsa/CallTargets.h"
#include "poolalloc/PoolAllocate.h"
#include "Heuristic.h"
#include "llvm/Constants.h"
Modified: poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp?rev=57451&r1=57450&r2=57451&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp Mon Oct 13 12:47:38 2008
@@ -36,7 +36,6 @@
PoolAllocate &PAInfo;
DSGraph &G; // The Bottom-up DS Graph
FuncInfo &FI;
- CallTargetFinder* CTF;
// PoolUses - For each pool (identified by the pool descriptor) keep track
// of which blocks require the memory in the pool to not be freed. This
@@ -50,9 +49,8 @@
FuncTransform(PoolAllocate &P, DSGraph &g, FuncInfo &fi,
std::multimap<AllocaInst*, Instruction*> &poolUses,
- std::multimap<AllocaInst*, CallInst*> &poolFrees,
- CallTargetFinder* ctf)
- : PAInfo(P), G(g), FI(fi), CTF(ctf),
+ std::multimap<AllocaInst*, CallInst*> &poolFrees)
+ : PAInfo(P), G(g), FI(fi),
PoolUses(poolUses), PoolFrees(poolFrees) {
}
@@ -126,7 +124,7 @@
std::multimap<AllocaInst*,Instruction*> &poolUses,
std::multimap<AllocaInst*, CallInst*> &poolFrees,
Function &F) {
- FuncTransform(*this, g, fi, poolUses, poolFrees, CTF).visit(F);
+ FuncTransform(*this, g, fi, poolUses, poolFrees).visit(F);
}
@@ -616,57 +614,16 @@
Instruction *OrigInst =
cast<Instruction>(getOldValueIfAvailable(CS.getInstruction()));
- for (DataStructures::callee_iterator I = Graphs.callee_begin(OrigInst),
- E = Graphs.callee_end(OrigInst); I != E; ++I) {
- CF = *I;
- break;
- }
-
- // If we didn't find the callee in the constructed call graph, try
- // checking in the DSNode itself.
- // This isn't ideal as it means that this call site didn't have inlining
- // happen.
- if (!CF) {
- DSGraph* dg = &Graphs.getDSGraph(*OrigInst->getParent()->getParent());
- DSNode* d = dg->getNodeForValue(OrigInst->getOperand(0)).getNode();
- const std::vector<const GlobalValue*> &g = d->getGlobalsList();
- for(std::vector<const GlobalValue*>::const_iterator ii = g.begin(), ee = g.end();
- !CF && ii != ee; ++ii) {
- EquivalenceClasses< const GlobalValue *> & EC = Graphs.getGlobalECs();
- for (EquivalenceClasses<const GlobalValue *>::member_iterator MI = EC.findLeader(*ii);
- MI != EC.member_end(); ++MI) // Loop over members in this set.
- if ((CF = dyn_cast<Function>(*MI))) {
- std::cerr << "\n***\nPA: *** WARNING (FuncTransform::visitCallSite): "
- << "Using DSNode for callees for call-site in function "
- << CS.getCaller()->getName() << "\n***\n";
- break;
- }
- }
- }
-
- if (!CF && CTF) {
- std::cerr << "\nPA: Last Resort TD Indirect Resolve in " << CS.getCaller()->getName() << "\n";
- CF = *CTF->begin(isa<CallInst>(OrigInst)?CallSite(cast<CallInst>(OrigInst))
- :CallSite(cast<InvokeInst>(OrigInst)));
- if (CF) std::cerr << "TD resolved to " << CF->getName() << "\n";
- }
-
- if (!CF) {
- // FIXME: Unknown callees for a call-site. Warn and ignore.
- std::cerr << "\n***\nPA: *** WARNING (FuncTransform::visitCallSite): "
- << "Unknown callees for call-site in function "
- << CS.getCaller()->getName() << "\n***\n";
- abort();
- return;
- }
+ DataStructures::callee_iterator I = Graphs.callee_begin(OrigInst);
+ assert (I != Graphs.callee_end(OrigInst) && "No call graph info");
+ CF = *I;
// Get the common graph for the set of functions this call may invoke.
CalleeGraph = &Graphs.getDSGraph(*CF);
#ifndef NDEBUG
// Verify that all potential callees at call site have the same DS graph.
- DataStructures::callee_iterator I =
- Graphs.callee_begin(OrigInst), E = Graphs.callee_end(OrigInst);
+ DataStructures::callee_iterator E = Graphs.callee_end(OrigInst);
for (; I != E; ++I)
if (!(*I)->isDeclaration())
assert(CalleeGraph == &Graphs.getDSGraph(**I) &&
More information about the llvm-commits
mailing list