[llvm-commits] [poolalloc] r50042 - /poolalloc/trunk/lib/PoolAllocate/PASimple.cpp

John Criswell criswell at uiuc.edu
Mon Apr 21 07:53:58 PDT 2008


Author: criswell
Date: Mon Apr 21 09:53:58 2008
New Revision: 50042

URL: http://llvm.org/viewvc/llvm-project?rev=50042&view=rev
Log:
Added support for strdup().

Modified:
    poolalloc/trunk/lib/PoolAllocate/PASimple.cpp

Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=50042&r1=50041&r2=50042&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Mon Apr 21 09:53:58 2008
@@ -259,6 +259,39 @@
 
           // Update def-use info
           CI->replaceAllUsesWith(Casted);
+        } else if (CF && (CF->isDeclaration()) && (CF->getName() == "strdup")) {
+          // Associate the global pool decriptor with the DSNode
+          DSNode * Node = ECG.getNodeForValue(CI).getNode();
+          FInfo.PoolDescriptors.insert(make_pair(Node,TheGlobalPool));
+
+          // Mark the realloc as an instruction to delete
+          toDelete.push_back(ii);
+
+          // Insertion point - Instruction before which all our instructions go
+          Instruction *InsertPt = CI;
+          Value *OldPtr = CS.getArgument(0);
+
+          // Ensure the size and pointer arguments are of the correct type
+          static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+          if (OldPtr->getType() != VoidPtrTy)
+            OldPtr = CastInst::createPointerCast (OldPtr,
+                                                  VoidPtrTy,
+                                                  OldPtr->getName(),
+                                                  InsertPt);
+
+          std::string Name = CI->getName(); CI->setName("");
+          Value* Opts[2] = {TheGlobalPool, OldPtr};
+          Instruction *V = CallInst::Create (PoolStrdup,
+                                         Opts,
+                                         Opts + 3,
+                                         Name,
+                                         InsertPt);
+          Instruction *Casted = V;
+          if (V->getType() != CI->getType())
+            Casted = CastInst::createPointerCast (V, CI->getType(), V->getName(), InsertPt);
+
+          // Update def-use info
+          CI->replaceAllUsesWith(Casted);
         }
       } else if (FreeInst * FI = dyn_cast<FreeInst>(ii)) {
         Type * VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);





More information about the llvm-commits mailing list