[llvm-commits] [poolalloc] r130061 - in /poolalloc/trunk: include/assistDS/TypeChecks.h lib/AssistDS/TypeChecks.cpp runtime/DynamicTypeChecks/TypeRuntime.c

Arushi Aggarwal aggarwa4 at illinois.edu
Sat Apr 23 10:02:23 PDT 2011


Author: aggarwa4
Date: Sat Apr 23 12:02:23 2011
New Revision: 130061

URL: http://llvm.org/viewvc/llvm-project?rev=130061&view=rev
Log:
Add support for memcpy.

Modified:
    poolalloc/trunk/include/assistDS/TypeChecks.h
    poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
    poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c

Modified: poolalloc/trunk/include/assistDS/TypeChecks.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/assistDS/TypeChecks.h?rev=130061&r1=130060&r2=130061&view=diff
==============================================================================
--- poolalloc/trunk/include/assistDS/TypeChecks.h (original)
+++ poolalloc/trunk/include/assistDS/TypeChecks.h Sat Apr 23 12:02:23 2011
@@ -19,6 +19,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Pass.h"
 #include "llvm/Target/TargetData.h"
+#include "llvm/Support/CallSite.h"
 
 #include <map>
 
@@ -55,6 +56,8 @@
 
   bool initShadow(Module &M, Instruction &I);
   bool unmapShadow(Module &M, Instruction &I);
+  bool visitCallInst(Module &M, CallInst &CI);
+  bool visitCallSite(Module &M, CallSite CS);
   bool visitLoadInst(Module &M, LoadInst &LI);
   bool visitGlobal(Module &M, GlobalVariable &GV, 
                    Constant *C, Instruction &I, unsigned offset);

Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=130061&r1=130060&r2=130061&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Sat Apr 23 12:02:23 2011
@@ -19,6 +19,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/InstIterator.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Intrinsics.h"
 
 using namespace llvm;
 
@@ -29,6 +30,7 @@
 static const Type *VoidTy = 0;
 static const Type *Int8Ty = 0;
 static const Type *Int32Ty = 0;
+static const Type *Int64Ty = 0;
 static const PointerType *VoidPtrTy = 0;
 
 // Incorporate one type and all of its subtypes into the collection of used types.
@@ -71,6 +73,7 @@
   VoidTy = IntegerType::getVoidTy(M.getContext());
   Int8Ty = IntegerType::getInt8Ty(M.getContext());
   Int32Ty = IntegerType::getInt32Ty(M.getContext());
+  Int64Ty = IntegerType::getInt64Ty(M.getContext());
   VoidPtrTy = PointerType::getUnqual(Int8Ty);
 
   UsedTypes.clear(); // Reset if run multiple times.
@@ -128,6 +131,8 @@
         if (!TA.isCopyingLoad(LI)) {
           modified |= visitLoadInst(M, *LI);
         }
+      } else if (CallInst *CI = dyn_cast<CallInst>(&I)) {
+        modified |= visitCallInst(M, *CI);
       }
     }
   }
@@ -266,6 +271,45 @@
 
   return true;
 }
+// Insert runtime checks for certain call instructions
+bool TypeChecks::visitCallInst(Module &M, CallInst &CI) {
+  return visitCallSite(M, &CI);
+}
+
+bool TypeChecks::visitCallSite(Module &M, CallSite CS) {
+  //
+  // Get the called value.  Strip off any casts which are lossless.
+  //
+  Value *Callee = CS.getCalledValue()->stripPointerCasts();
+  Instruction *I = CS.getInstruction();
+
+  // Special case handling of certain libc allocation functions here.
+  if (Function *F = dyn_cast<Function>(Callee))
+    if (F->isIntrinsic()) {
+      CS.getInstruction()->dump();
+      switch(F->getIntrinsicID()) {
+      case Intrinsic::memcpy: 
+        {
+          CastInst *BCI_Src = BitCastInst::CreatePointerCast(I->getOperand(2), VoidPtrTy, "", I);
+          CastInst *BCI_Dest = BitCastInst::CreatePointerCast(I->getOperand(1), VoidPtrTy, "", I);
+          std::vector<Value *> Args;
+          Args.push_back(BCI_Dest);
+          Args.push_back(BCI_Src);
+          Args.push_back(I->getOperand(3));
+          Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
+          Constant *F = M.getOrInsertFunction("copyTypeInfo", VoidTy, VoidPtrTy, VoidPtrTy, I->getOperand(3)->getType(), Int32Ty, NULL);
+          CallInst::Create(F, Args.begin(), Args.end(), "", I);
+          break;
+        }
+
+      case Intrinsic::memmove: 
+      case Intrinsic::memset:
+        break;
+      }
+    }
+
+  return true;
+}
 
 // Insert runtime checks before all load instructions.
 bool TypeChecks::visitLoadInst(Module &M, LoadInst &LI) {
@@ -277,7 +321,7 @@
   Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[LI.getType()]));
   Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(LI.getType())));
   Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
-  
+
 
   // Create the call to the runtime check and place it before the load instruction.
   Constant *F = M.getOrInsertFunction("trackLoadInst", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
@@ -313,11 +357,11 @@
   std::vector<Value *> Args;
   Args.push_back(BCI_Dest);
   Args.push_back(BCI_Src);
-  Args.push_back(ConstantInt::get(Int32Ty, TD->getTypeStoreSize(SI.getOperand(0)->getType())));
+  Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(SI.getOperand(0)->getType())));
   Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
 
   // Create the call to the runtime check and place it before the copying store instruction.
-  Constant *F = M.getOrInsertFunction("copyTypeInfo", VoidTy, VoidPtrTy, VoidPtrTy, Int32Ty, Int32Ty, NULL);
+  Constant *F = M.getOrInsertFunction("copyTypeInfo", VoidTy, VoidPtrTy, VoidPtrTy, Int64Ty, Int32Ty, NULL);
   CallInst::Create(F, Args.begin(), Args.end(), "", &SI);
 
   return true;

Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c?rev=130061&r1=130060&r2=130061&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c Sat Apr 23 12:02:23 2011
@@ -104,7 +104,7 @@
 /**
  * Copy size bits of metadata from src ptr to dest ptr.
  */
-void copyTypeInfo(void *dstptr, void *srcptr, uint8_t size, uint32_t tag) {
+void copyTypeInfo(void *dstptr, void *srcptr, uint64_t size, uint32_t tag) {
 	uintptr_t d = (uintptr_t)dstptr;
 	uintptr_t s = (uintptr_t)srcptr;
 	d &= 0xFFFFFFFF;





More information about the llvm-commits mailing list