[llvm-commits] [see] CVS: llvm-poolalloc/lib/DSA/DataStructure.cpp Local.cpp
Andrew Lenharth
alenhar2 at cs.uiuc.edu
Fri Mar 9 09:28:29 PST 2007
Changes in directory llvm-poolalloc/lib/DSA:
DataStructure.cpp updated: 1.248.2.4.2.3 -> 1.248.2.4.2.4
Local.cpp updated: 1.158.2.4.2.3 -> 1.158.2.4.2.4
---
Log message:
use nifty new, simpler, smaller, easy to understand metapool inference (yea yea, theres a memory leak in it
---
Diffs of the changes: (+49 -553)
DataStructure.cpp | 243 ++++--------------------------------
Local.cpp | 359 ++----------------------------------------------------
2 files changed, 49 insertions(+), 553 deletions(-)
Index: llvm-poolalloc/lib/DSA/DataStructure.cpp
diff -u llvm-poolalloc/lib/DSA/DataStructure.cpp:1.248.2.4.2.3 llvm-poolalloc/lib/DSA/DataStructure.cpp:1.248.2.4.2.4
--- llvm-poolalloc/lib/DSA/DataStructure.cpp:1.248.2.4.2.3 Wed Mar 7 16:49:43 2007
+++ llvm-poolalloc/lib/DSA/DataStructure.cpp Fri Mar 9 11:27:51 2007
@@ -98,6 +98,7 @@
DSNodeHandle &DSScalarMap::AddGlobal(GlobalValue *GV) {
assert(ValueMap.count(GV) == 0 && "GV already exists!");
+ assert(isa<GlobalValue>((Value*)GV) && "not a global");
// If the node doesn't exist, check to see if it's a global that is
// equated to another global in the program.
@@ -125,7 +126,11 @@
//===----------------------------------------------------------------------===//
DSNode::DSNode(const Type *T, DSGraph *G)
- : NumReferrers(0), Size(0), ParentGraph(G), Ty(Type::VoidTy), NodeType(0) {
+ : NumReferrers(0), Size(0), ParentGraph(G), Ty(Type::VoidTy), NodeType(0)
+#ifdef LLVA_KERNEL
+ , MP(0)
+#endif
+ {
// Add the type entry if it is specified...
if (T) mergeTypeInfo(T, 0);
if (G) G->addNode(this);
@@ -138,7 +143,11 @@
// DSNode copy constructor... do not copy over the referrers list!
DSNode::DSNode(const DSNode &N, DSGraph *G, bool NullLinks)
: NumReferrers(0), Size(N.Size), ParentGraph(G),
- Ty(N.Ty), Globals(N.Globals), NodeType(N.NodeType) {
+ Ty(N.Ty), Globals(N.Globals), NodeType(N.NodeType)
+#ifdef LLVA_KERNEL
+ , MP(N.MP.getPool())
+#endif
+ {
if (!NullLinks) {
Links = N.Links;
} else
@@ -153,19 +162,6 @@
DSNode::~DSNode() {
dropAllReferences();
assert(hasNoReferrers() && "Referrers to dead node exist!");
-
-#ifdef LLVA_KERNEL
- //
- // Remove all references to this node from the Pool Descriptor Map.
- //
-#if JTC
- std::cerr << "LLVA: Removing " << this << "\n";
-#endif
- if (ParentGraph) {
- hash_map<const DSNode *, MetaPoolHandle*> &pdm=ParentGraph->getPoolDescriptorsMap();
- pdm.erase (this);
- }
-#endif
}
/// getTargetData - Get the target data object used to construct this node.
@@ -201,6 +197,13 @@
NodeType = DEAD;
Size = 0;
Ty = Type::VoidTy;
+#ifdef LLVA_KERNEL
+ MetaPool* MP = new MetaPool();
+ MP->merge(getMP());
+ MP->merge(To->getMP());
+ setMP(MP);
+ To->setMP(MP);
+#endif
// Remove this node from the parent graph's Nodes list.
ParentGraph->unlinkNode(this);
@@ -261,21 +264,13 @@
DestNode->Ty = Type::VoidTy;
DestNode->Size = 1;
DestNode->Globals.swap(Globals);
+#ifdef LLVA_KERNEL
+ DestNode->setMP(getMP());
+#endif
#if JTC
std::cerr << "LLVA: foldNode: " << this << " becomes " << DestNode << "\n";
#endif
-#ifdef LLVA_KERNEL
- //Again we have created a new DSNode, we need to fill in the
- // pool desc map appropriately
- assert(ParentGraph && "parent graph is not null \n");
- hash_map<const DSNode *, MetaPoolHandle*> &pdm = ParentGraph->getPoolDescriptorsMap();
- if (pdm.count(this) > 0) {
- pdm[DestNode] = pdm[this];
- } else {
- //do nothing
- }
-#endif
// Start forwarding to the destination node...
forwardNode(DestNode, 0);
@@ -871,60 +866,11 @@
#endif
}
#ifdef LLVA_KERNEL
- DSNode *currNode = CurNodeH.getNode();
- DSNode *NNode = NH.getNode();
- DSGraph *pGraph = currNode->getParentGraph();
- assert((pGraph == NNode->getParentGraph()) && "LLVA_KERNEL : merging nodes in two different graphs?");
- //get the pooldescriptor map
- hash_map<const DSNode *, MetaPoolHandle*> &pdm = pGraph->getPoolDescriptorsMap();
- if (pdm.count(currNode) == 0) {
- if (pdm.count(NNode) == 0) {
- //do nothing (common case)
- } else {
- if (pdm[NNode]) {
-#if JTC
- std::cerr << "LLVA: 1: currNode (" << currNode << ") becomes " << pdm[NNode]->getName() << "(" << NNode << ")\n";
-#endif
- pdm[currNode] = pdm[NNode];
- }
- }
- } else {
- if (pdm.count(NNode) == 0) {
-#if 1
- //
- // FIXME:
- // Verify that this is correct. I believe it is; it seems to make sense
- // since either node can be used after the merge.
- //
-#if JTC
-std::cerr << "LLVA: MergeNodes: currnode has something, newnode has nothing\n";
- std::cerr << "LLVA: 2: currNode (" << currNode << ") becomes <no name>" << "(" << NNode << ")\n";
-#endif
- pdm[NNode] = pdm[currNode];
-#endif
- //do nothing
- } else {
- if (pdm[currNode] != pdm[NNode]) {
- //The following is commented because pdm[..] could be null!
- //std::cerr << "LLVA: OldPool: " << pdm[currNode]->getName() << "("
- // << pdm[currNode] << ") "
- // << " NewPool: " << pdm[NNode]->getName() << "("
- // << pdm[NNode] << ")" << std::endl;
- pdm[NNode]->merge(pdm[currNode]);
- /*
- Value *currN = pdm[currNode]->getMetaPoolValue();
- Value *NN = pdm[NNode]->getMetaPoolValue();
- if (currN != NN) {
- std::cerr << "LLVA: Two Pools for one DSNode\n";
- currN->replaceAllUsesWith(NN);
- pdm[currNode]->merge(pdm[NNode]);
- } else {
- //The nodes are same
- }
- */
- }
- }
- }
+ MetaPool* MP = new MetaPool();
+ MP->merge(CurNodeH.getNode()->getMP());
+ MP->merge(NH.getNode()->getMP());
+ CurNodeH.getNode()->setMP(MP);
+ NH.getNode()->setMP(MP);
#endif
// Merge the type entries of the two nodes together...
if (NH.getNode()->Ty != Type::VoidTy)
@@ -1087,21 +1033,6 @@
DSNode *DN = new DSNode(*SN, &Dest, true /* Null out all links */);
DN->maskNodeTypes(BitsToKeep);
NH = DN;
-#if JTC
-std::cerr << "LLVA: getClonedNH: " << SN << " becomes " << DN << "\n";
-#endif
-#if 1
-#ifdef LLVA_KERNEL
- //Again we have created a new DSNode, we need to fill in the
- // pool desc map appropriately
- hash_map<const DSNode *, MetaPoolHandle*> &pdm = Dest.getPoolDescriptorsMap();
- if (pdm.count(SN) > 0) {
- pdm[DN] = pdm[SN];
- } else {
- //do nothing
- }
-#endif
-#endif
// Next, recursively clone all outgoing links as necessary. Note that
// adding these links can cause the node to collapse itself at any time, and
@@ -1260,58 +1191,15 @@
}
}
-#if JTC
-std::cerr << "LLVA: mergeWith: " << SN << " becomes " << DN << "\n";
-#endif
#ifdef LLVA_KERNEL
- //Here some merge is going on just like in DSNode::merge
- //I think because of the inplace merging we don't update the pool desc maps
- //This is modification from DSNode::MergeNodes
- //Here DN and SN may belong to different graphs
- DN = NH.getNode();
-#if 0
- DSGraph *destGraph = DN->getParentGraph();
- DSGraph *srcGraph = SN->getParentGraph();
-#else
- DSGraph *destGraph = NH.getNode()->getParentGraph();
- DSGraph *srcGraph = SN->getParentGraph();
-#endif
- if (destGraph && srcGraph) {
- //get the pooldescriptor map
- hash_map<const DSNode *, MetaPoolHandle*> &destpdm = destGraph->getPoolDescriptorsMap();
- hash_map<const DSNode *, MetaPoolHandle*> &srcpdm = srcGraph->getPoolDescriptorsMap();
- if (destpdm.count(DN) == 0) {
- if (srcpdm.count(SN) == 0) {
- //do nothing (common case)
- } else {
- if (srcpdm[SN]) {
-#if JTC
- std::cerr << "LLVA: DN becomes " << srcpdm[SN]->getName() << std::endl;
-#endif
- destpdm[DN] = srcpdm[SN];
- }
- }
- } else {
- if (srcpdm.count(SN) == 0) {
- srcpdm[SN] = destpdm[DN];
- } else {
- if (destpdm[DN] != srcpdm[SN]) {
- srcpdm[SN]->merge(destpdm[DN]);
- /*
- Value *dnv = destpdm[DN]->getMetaPoolValue();
- Value *snv = srcpdm[SN]->getMetaPoolValue();
- if (dnv != snv) {
- DEBUG(std::cerr << "LLVA: Two Pools for one DSNode\n");
- dnv->replaceAllUsesWith(snv);
- destpdm[DN]->setMetaPoolValue(snv);
- }
- */
- }
- }
- }
- }
+ MetaPool* MP = new MetaPool();
+ MP->merge(NH.getNode()->getMP());
+ MP->merge(SrcNH.getNode()->getMP());
+ NH.getNode()->setMP(MP);
+ SrcNH.getNode()->setMP(MP);
#endif
+
// Next, recursively merge all outgoing links as necessary. Note that
// adding these links can cause the destination node to collapse itself at
// any time, and the current node may be merged with arbitrary other nodes.
@@ -1380,55 +1268,6 @@
NH = RC.getClonedNH(Src);
}
-#ifdef LLVA_KERNEL
-// MetaPoolHandle Implementation
- //The following should go in a cpp file later
- MetaPoolHandle::MetaPoolHandle(MetaPool *mp, Instruction * Maker) {
- Rep = mp;
- Rep->insert(this);
- Creator = Maker;
- }
- const std::string& MetaPoolHandle::getName() {
- assert(Rep != 0 && "Null meta pool ??\n");
- return Rep->getName();
- }
- Value *MetaPoolHandle::getMetaPoolValue() {
- assert(Rep != 0 && "Null meta pool ??\n");
- return Rep->getMetaPoolValue();
- }
- void MetaPoolHandle::merge(MetaPoolHandle *other) {
- //after this operation other points to what this points to .
- //first replace all uses
- Value *dest = getMetaPoolValue();
- Value *curr = other->getMetaPoolValue();
- if (dest != curr) {
-#if 0
- std::cerr << "LLVA: Merging metapools: " << this->Creator->getParent()->getParent()->getName() << " : " << other->Creator->getParent()->getParent()->getName() << "\n"
- << "LLVA: " << *(this->Creator) << "\n"
- << "LLVA: " << *(other->Creator) << "\n";
- curr->replaceAllUsesWith(dest);
-#endif
- }
-
- //merge the hash sets in to other
- hash_set<MetaPoolHandle *> &otherHandleSet = other->getMetaPool()->getHandleSet();
- hash_set<MetaPoolHandle *>::iterator ohsI = otherHandleSet.begin(), ohsE = otherHandleSet.end();
- for (; ohsI != ohsE; ++ohsI) {
- MetaPoolHandle *omph = *ohsI;
- //now make sure that this omph points to what we point to
- omph->setMetaPool(Rep);
- Rep->insert(omph);
- }
-
- //now delete others MetaPool
- //gd delete other->getMetaPool();
-
- //Assign our metapool to other
- other->setMetaPool(Rep);
-}
-
-#endif
-
//===----------------------------------------------------------------------===//
// DSGraph Implementation
//===----------------------------------------------------------------------===//
@@ -1462,9 +1301,6 @@
AuxFunctionCalls.clear();
ScalarMap.clear();
ReturnNodes.clear();
-#ifdef LLVA_KERNEL
- PoolDescriptors.clear();
-#endif
// Drop all intra-node references, so that assertions don't fail...
for (node_iterator NI = node_begin(), E = node_end(); NI != E; ++NI)
NI->dropAllReferences();
@@ -1540,10 +1376,6 @@
DSNode *New = new DSNode(*I, this);
New->maskNodeTypes(~BitsToClear);
OldNodeMap[I] = New;
-#ifdef LLVA_KERNEL
- if (G.getPoolForNode(&*I))
- PoolDescriptors[New] = G.getPoolForNode(&*I);
-#endif
}
#ifndef NDEBUG
@@ -1621,17 +1453,6 @@
// Merge the scalar map in.
ScalarMap.spliceFrom(RHS.ScalarMap);
-
-#ifdef LLVA_KERNEL
- //Take all from the pooldescriptor map
-#if 0
- PoolDescriptors.swap(RHS.getPoolDescriptorsMap());
-#else
- hash_map<const DSNode *, MetaPoolHandle*>& rhsmap = RHS.getPoolDescriptorsMap();
- PoolDescriptors.insert(rhsmap.begin(), rhsmap.end());
-#endif
- RHS.getPoolDescriptorsMap().clear();
-#endif
}
/// spliceFrom - Copy all entries from RHS, then clear RHS.
Index: llvm-poolalloc/lib/DSA/Local.cpp
diff -u llvm-poolalloc/lib/DSA/Local.cpp:1.158.2.4.2.3 llvm-poolalloc/lib/DSA/Local.cpp:1.158.2.4.2.4
--- llvm-poolalloc/lib/DSA/Local.cpp:1.158.2.4.2.3 Wed Mar 7 17:42:43 2007
+++ llvm-poolalloc/lib/DSA/Local.cpp Fri Mar 9 11:27:51 2007
@@ -593,9 +593,8 @@
{
if (SI.getParent()->getParent()->getName() == "alloc_vfsmnt") {
DSNode * N = getValueDest(*SI.getOperand(1)).getNode();
- if (G.getPoolDescriptorsMap().count(N) != 0)
- if (G.getPoolDescriptorsMap()[N])
- std::cerr << "LLVA: Store: Pool for " << SI.getName() << " is " << G.getPoolDescriptorsMap()[N]->getName() << "\n";
+ if (N->getMP())
+ std::cerr << "LLVA: Store: Pool for " << SI.getName() << " is " << N->getMP() << "\n";
}
}
#endif
@@ -1098,135 +1097,6 @@
if (DSNode *N = getValueDest(**(CS.arg_begin() + 1)).getNode())
N->setReadMarker();
return true;
-#ifdef LLVA_KERNEL_0
- } else if (F->getName() == "kmem_cache_alloc") {
- DEBUG(std::cerr << "LLVA: kmem_cache_alloc" << std::endl);
- // Update the statistics count
- ++CacheAllocs;
-
- // Create a new DSNode for this memory allocation
- DSNode *N = createNode();
- N->setHeapNodeMarker();
- setDestTo(*CS.getInstruction(), N);
-
- // Get the pool handle
- if (CS.arg_begin() == CS.arg_end()) {
- abort(); //Hanlde this later
- // Treat it as a kmalloc
- N->foldNodeCompletely();
- //This becomes a kmalloc pool
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(KMallocPool));
- G.getPoolDescriptorsMap()[N] = tmpvh;
- } else {
- Value *actualPD = *(CS.arg_begin());
- if (!isa<GlobalValue>(actualPD)) {
-#if 0
- std::cerr << "WARNING: Pool is not global. Function = " << CS.getCaller()->getName() << "\n";
-#endif
- } else {
- ++GlobalPools;
- }
- Value *TheMetaPool = actualPD;
- if (G.getPoolDescriptorsMap().count(N)== 0) {
- //Here we insert a global meta pool
- //Get the Module first
- Module * M = F->getParent();
- //Now create a meta pool for this value, DSN Node
- const Type * VoidPtrType = PointerType::get(Type::SByteTy);
- TheMetaPool = new GlobalVariable(
- /*type=*/ VoidPtrType,
- /*isConstant=*/ false,
- /*Linkage=*/ GlobalValue::InternalLinkage,
- /*initializer=*/ Constant::getNullValue(VoidPtrType),
- /*name=*/ "_metaPool_",
- /*parent=*/ M );
- //Inserted a global meta pool
- }
- //Now insert a function call that takes care of adding this pool to the global pool
-
- //First get the Insert point
- Instruction *InsertPoint = CS.getInstruction();
-
- //Assumes AddPoolDescToMetaPool is in the module
- CastInst *CastMetaPool =
- new CastInst(TheMetaPool,
- PointerType::get(Type::SByteTy), "metapool.casted", InsertPoint);
- CastInst *CastActualPD =
- new CastInst(actualPD,
- PointerType::get(Type::SByteTy), "poolhandle.lscasted", InsertPoint);
-
- // Create the call to AddPoolDescToMetaPool
- std::vector<Value *> args(1,CastMetaPool);
- args.push_back(CastActualPD);
- new CallInst(AddPoolDescToMetaPool,args,"", InsertPoint);
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(TheMetaPool));
- G.getPoolDescriptorsMap()[N] = tmpvh;
- }
- } else if (F->getName() == "poolalloc") {
- if (CS.getCaller()->getName() == "kmem_cache_alloc")
- return;
- // Update the statistics
- ++KMallocs;
-
- // Create a DSNode for the memory allocated by this function call
- DSNode *N = createNode();
- N->setHeapNodeMarker();
- setDestTo(*CS.getInstruction(), N);
-
- // Get the pool handle, if possible
- if (CS.arg_begin() == CS.arg_end()) {
- abort(); //handle later
- // Treat it as kmalloc
- N->foldNodeCompletely();
- //This becomes a kmalloc pool
- //So get the kmalloc pool
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(KMallocPool));
- G.getPoolDescriptorsMap()[N] = tmpvh;
- } else {
- Value *actualPD = *(CS.arg_begin());
- if (!isa<GlobalValue>(actualPD)) {
-#if 0
- std::cerr << "WARNING: Pool is not global. Function = " << CS.getCaller()->getName() << "\n";
-#endif
- } else {
- ++GlobalPools;
- }
- Value *TheMetaPool = actualPD;
- if (G.getPoolDescriptorsMap().count(N)== 0) {
- //Here we insert a global meta pool
- //Get the Module first
- Module * M = F->getParent();
- //Now create a meta pool for this value, DSN Node
- const Type * VoidPtrType = PointerType::get(Type::SByteTy);
- TheMetaPool = new GlobalVariable(
- /*type=*/ VoidPtrType,
- /*isConstant=*/ false,
- /*Linkage=*/ GlobalValue::InternalLinkage,
- /*initializer=*/ Constant::getNullValue(VoidPtrType),
- /*name=*/ "_metaPool_",
- /*parent=*/ M );
- //Inserted a global meta pool
- }
- //Now insert a function call that takes care of adding this pool to the global pool
- //First get the Insert point
- Instruction *InsertPoint = CS.getInstruction();
-
- //Assumes AddPoolDescToMetaPool is in the module
- CastInst *CastMetaPool =
- new CastInst(TheMetaPool,
- PointerType::get(Type::SByteTy), "metapool.casted", InsertPoint);
- CastInst *CastActualPD =
- new CastInst(actualPD,
- PointerType::get(Type::SByteTy), "poolhandle.lscasted", InsertPoint);
-
- // Create the call to AddPoolDescToMetaPool
- std::vector<Value *> args(1,CastMetaPool);
- args.push_back(CastActualPD);
- new CallInst(AddPoolDescToMetaPool,args,"", InsertPoint);
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(TheMetaPool));
- G.getPoolDescriptorsMap()[N] = tmpvh;
- }
-#endif
#ifdef LLVA_KERNEL
} else if (F->getName() == "llva_memcpy") {
if (CS.getCaller()->getName() == "kmem_cache_alloc")
@@ -1274,172 +1144,7 @@
void GraphBuilder::visitCallSite(CallSite CS) {
Value *Callee = CS.getCalledValue();
- // Special case handling of certain libc allocation functions here.
if (Function *F = dyn_cast<Function>(Callee)) {
-#ifdef LLVA_KERNEL
- if (F->getName() == "kmem_cache_alloc") {
- DEBUG(std::cerr << "LLVA: kmem_cache_alloc" << std::endl);
- // Update the statistics count
- ++CacheAllocs;
-
- // Create a new DSNode for this memory allocation
- DSNode *N = createNode();
- N->setHeapNodeMarker();
- setDestTo(*CS.getInstruction(), N);
-
- // Get the pool handle
- if (CS.arg_begin() == CS.arg_end()) {
- abort(); //Handle this later
- // Treat it as a kmalloc
- N->foldNodeCompletely();
- //This becomes a kmalloc pool
- MetaPoolHandle* mpvh = new MetaPoolHandle(new MetaPool(KMallocPool));
- G.getPoolDescriptorsMap()[N] = mpvh;
- } else {
- Value *actualPD = *(CS.arg_begin());
- if (!isa<GlobalValue>(actualPD)) {
-#if 0
- std::cerr << "WARNING: Pool is not global. Function = " << CS.getCaller()->getName() << "\n";
-#endif
- } else {
- ++GlobalPools;
- }
- Value *TheMetaPool = actualPD;
- //Get the Module first
- Module * M = F->getParent();
- if (G.getPoolDescriptorsMap().count(N)== 0) {
- //Here we insert a global meta pool
- //Now create a meta pool for this value, DSN Node
- const Type * VoidPtrType = PointerType::get(Type::SByteTy);
- TheMetaPool = new GlobalVariable(
- /*type=*/ VoidPtrType,
- /*isConstant=*/ false,
- /*Linkage=*/ GlobalValue::InternalLinkage,
- /*initializer=*/ Constant::getNullValue(VoidPtrType),
- /*name=*/ "_metaPool_",
- /*parent=*/ M );
- //Inserted a global meta pool
- }
-#if 1
- else {
- // Lookup the meta pool
- TheMetaPool = G.getPoolForNode(N)->getMetaPoolValue();
- }
-#endif
- //Now insert a function call that takes care of adding this pool to the global pool
-
- //First get the Insert point
- Instruction *InsertPoint = CS.getInstruction();
-
- //Assumes AddPoolDescToMetaPool is in the module
- const Type * VoidPtrType = PointerType::get(Type::SByteTy);
- const Type * VoidPtrPtrType = PointerType::get(VoidPtrType);
- CastInst *CastMetaPool =
- new CastInst(TheMetaPool,
- VoidPtrPtrType, "metapool.casted", InsertPoint);
- CastInst *CastActualPD =
- new CastInst(actualPD,
- PointerType::get(Type::SByteTy), "poolhandle.lscasted", InsertPoint);
-
- // Create the call to AddPoolDescToMetaPool
- std::vector<Value *> args(1,CastMetaPool);
- args.push_back(CastActualPD);
-
- //Get the AddPoolDescToMetaPool function from the module
- //FIXME optimize it by getting it once per module
- std::vector<const Type *> Arg(1, VoidPtrPtrType);
- Arg.push_back(VoidPtrType);
- FunctionType *AddPoolDescToMetaPoolTy =
- FunctionType::get(Type::VoidTy,Arg, false);
- Function *AddPoolDescToMetaPool = M->getOrInsertFunction("AddPoolDescToMetaPool", AddPoolDescToMetaPoolTy);
-
-
- new CallInst(AddPoolDescToMetaPool,args,"", InsertPoint);
-#if 0
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(TheMetaPool));
-#else
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(TheMetaPool), CS.getInstruction());
-#endif
- G.getPoolDescriptorsMap()[N] = tmpvh;
- }
- return;
- } else if (F->getName() == "poolalloc") {
- if (CS.getCaller()->getName() == "kmem_cache_alloc")
- return;
- // Update the statistics
- ++KMallocs;
-
- // Create a DSNode for the memory allocated by this function call
- DSNode *N = createNode();
- N->setHeapNodeMarker();
- setDestTo(*CS.getInstruction(), N);
-
- // Get the pool handle, if possible
- if (CS.arg_begin() == CS.arg_end()) {
- abort() ; //Handle this later
- // Treat it as kmalloc
- N->foldNodeCompletely();
- //This becomes a kmalloc pool
- //So get the kmalloc pool
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(KMallocPool));
- G.getPoolDescriptorsMap()[N] = tmpvh;
- } else {
- Value *actualPD = *(CS.arg_begin());
- if (!isa<GlobalValue>(actualPD)) {
-#if 0
- std::cerr << "WARNING: Pool is not global. Function = " << CS.getCaller()->getName() << "\n";
-#endif
- } else {
- ++GlobalPools;
- }
- Value *TheMetaPool = actualPD;
- Module * M = F->getParent();
- if (G.getPoolDescriptorsMap().count(N)== 0) {
- //Here we insert a global meta pool
- //Get the Module first
- //Now create a meta pool for this value, DSN Node
- const Type * VoidPtrType = PointerType::get(Type::SByteTy);
- TheMetaPool = new GlobalVariable(
- /*type=*/ VoidPtrType,
- /*isConstant=*/ false,
- /*Linkage=*/ GlobalValue::InternalLinkage,
- /*initializer=*/ Constant::getNullValue(VoidPtrType),
- /*name=*/ "_metaPool_",
- /*parent=*/ M );
- //Inserted a global meta pool
- }
- //Now insert a function call that takes care of adding this pool to the global pool
- //First get the Insert point
- Instruction *InsertPoint = CS.getInstruction();
-
- //Assumes AddPoolDescToMetaPool is in the module
- const Type * VoidPtrType = PointerType::get(Type::SByteTy);
- const Type * VoidPtrPtrType = PointerType::get(VoidPtrType);
- CastInst *CastMetaPool =
- new CastInst(TheMetaPool,
- VoidPtrPtrType, "metapool.casted", InsertPoint);
- CastInst *CastActualPD =
- new CastInst(actualPD,
- PointerType::get(Type::SByteTy), "poolhandle.lscasted", InsertPoint);
-
- // Create the call to AddPoolDescToMetaPool
- std::vector<Value *> args(1,CastMetaPool);
- args.push_back(CastActualPD);
-
- //FIXME optimize it by getting it once per module
- std::vector<const Type *> Arg(1, VoidPtrPtrType);
- Arg.push_back(VoidPtrType);
- FunctionType *AddPoolDescToMetaPoolTy =
- FunctionType::get(Type::VoidTy,Arg, false);
- Function *AddPoolDescToMetaPool = M->getOrInsertFunction("AddPoolDescToMetaPool", AddPoolDescToMetaPoolTy);
-
- new CallInst(AddPoolDescToMetaPool,args,"", InsertPoint);
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(TheMetaPool));
- G.getPoolDescriptorsMap()[N] = tmpvh;
- }
- return;
- }
-#endif
if (F->isExternal())
if (F->isIntrinsic() && visitIntrinsic(CS, F))
return;
@@ -1447,8 +1152,10 @@
// 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()->setHeapNodeMarker()->setModifiedMarker());
+ DSNode* N = createNode()->setHeapNodeMarker()->setModifiedMarker();
+ setDestTo(*CS.getInstruction(), N);
+ MetaPool* MP = new MetaPool(CS);
+ N->setMP(MP);
return;
}
@@ -1606,6 +1313,10 @@
// Get a node handle to the global node and merge the initializer into it.
DSNodeHandle NH = getValueDest(*GV);
MergeConstantInitIntoNode(NH, GV->getInitializer());
+ MetaPool* MP = new MetaPool(GV);
+ if (NH.getNode()->getMP())
+ MP->merge(NH.getNode()->getMP());
+ NH.getNode()->setMP(MP);
}
@@ -1692,6 +1403,13 @@
}
bool LocalDataStructures::runOnModule(Module &M) {
+
+#ifdef LLVA_KERNEL
+ AllocList.push_back("kmalloc");
+ AllocList.push_back("__vmalloc");
+ AllocList.push_back("kmem_cache_alloc");
+#endif
+
const TargetData &TD = getAnalysis<TargetData>();
// First step, build the globals graph.
@@ -1713,49 +1431,6 @@
DEBUG(std::cerr << "Eliminating " << ECGlobals.size() << " EC Globals!\n");
ECGlobals.clear();
-#ifdef LLVA_KERNEL
- //
- // Scan through all the globals; if they have a DSNode but no MetaPool, give
- // them a MetaPool.
- //
- const Type * VoidPtrType = PointerType::get(Type::SByteTy);
- for (Module::global_iterator I = M.global_begin(), E = M.global_end();
- I != E; ++I) {
- // Skip functions and externally declared variables
- if (!isa<GlobalVariable>(I)) continue;
- if (I->isExternal()) continue;
-
- GlobalValue * GV = I;
- GlobalValue * GVL = GlobalsGraph->getScalarMap().getLeaderForGlobal(I);
- DSNode *Node = GlobalsGraph->getNodeForValue(GVL).getNode();
-
- // If this global happens to be a MetaPool, it will have no DSNode.
- // In that case, do not assign a MetaPool.
- if (!Node) continue;
-
- //
- // Add the MetaPool for the DSNode if it does not already have one.
- //
- if (GlobalsGraph->getPoolDescriptorsMap().count(Node) == 0) {
- Value * TheMetaPool = 0;
- TheMetaPool = new GlobalVariable(
- /*type=*/ VoidPtrType,
- /*isConstant=*/ false,
- /*Linkage=*/ GlobalValue::InternalLinkage,
- /*initializer=*/ Constant::getNullValue(VoidPtrType),
- /*name=*/ "_metaPool_",
- /*parent=*/ &M );
-
- //
- // Create the internal data structure for the MetaPool and associate the
- // DSNode with it.
- //
- MetaPoolHandle* tmpvh = new MetaPoolHandle(new MetaPool(TheMetaPool), NULL);
- GlobalsGraph->getPoolDescriptorsMap()[Node] = tmpvh;
- }
- }
-#endif
-
// Calculate all of the graphs...
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isExternal())
More information about the llvm-commits
mailing list