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

Arushi Aggarwal aggarwa4 at illinois.edu
Thu Apr 21 07:46:18 PDT 2011


Author: aggarwa4
Date: Thu Apr 21 09:46:17 2011
New Revision: 129911

URL: http://llvm.org/viewvc/llvm-project?rev=129911&view=rev
Log:
Adding tags to each runtime type tracking function.

Also in global array function, use memcpy, to copy all
the bytes we need, from the 0th object of the array, to all 
the other objects in the array.

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=129911&r1=129910&r2=129911&view=diff
==============================================================================
--- poolalloc/trunk/include/assistDS/TypeChecks.h (original)
+++ poolalloc/trunk/include/assistDS/TypeChecks.h Thu Apr 21 09:46:17 2011
@@ -56,9 +56,11 @@
   bool initShadow(Module &M, Instruction &I);
   bool unmapShadow(Module &M, Instruction &I);
   bool visitLoadInst(Module &M, LoadInst &LI);
-  bool visitGlobal(Module &M, GlobalVariable &GV, Constant *C, Instruction &I, unsigned offset);
+  bool visitGlobal(Module &M, GlobalVariable &GV, 
+                   Constant *C, Instruction &I, unsigned offset);
   bool visitStoreInst(Module &M, StoreInst &SI);
   bool visitCopyingStoreInst(Module &M, StoreInst &SI, Value *SS);
+  bool visitInputFunctionValue(Module &M, Value *V, CallInst *CI);
 
   // Return the map containing all of the types used in the module.
   const std::map<const Type *, unsigned int> &getTypes() const {

Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=129911&r1=129910&r2=129911&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Thu Apr 21 09:46:17 2011
@@ -25,6 +25,7 @@
 char TypeChecks::ID = 0;
 static RegisterPass<TypeChecks> TC("typechecks", "Insert runtime type checks", false, true);
 
+static int tagCounter = 0;
 static const Type *VoidTy = 0;
 static const Type *Int8Ty = 0;
 static const Type *Int32Ty = 0;
@@ -175,7 +176,6 @@
 
 bool TypeChecks::visitGlobal(Module &M, GlobalVariable &GV, 
                              Constant *C, Instruction &I, unsigned offset) {
-//void trackStoreArray(void *ptr, uint8_t size, uint32_t count) {
   if(ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
     const Type * ElementType = CA->getType()->getElementType();
     unsigned int t = TD->getTypeStoreSize(ElementType);
@@ -185,7 +185,8 @@
     Args.push_back(BCI);
     Args.push_back(ConstantInt::get(Int32Ty, t));
     Args.push_back(ConstantInt::get(Int32Ty, CA->getNumOperands()));
-    Constant *F = M.getOrInsertFunction("trackGlobalArray", VoidTy, VoidPtrTy, Int32Ty, Int32Ty, NULL);
+    Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
+    Constant *F = M.getOrInsertFunction("trackGlobalArray", VoidTy, VoidPtrTy, Int32Ty, Int32Ty, Int32Ty, NULL);
     CallInst::Create(F, Args.begin(), Args.end(), "", &I);
 
     //for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) {
@@ -212,7 +213,8 @@
       Args.push_back(BCI);
       Args.push_back(ConstantInt::get(Int32Ty, t));
       Args.push_back(ConstantInt::get(Int32Ty, ATy->getNumElements()));
-      Constant *F = M.getOrInsertFunction("trackGlobalArray", VoidTy, VoidPtrTy, Int32Ty, Int32Ty, NULL);
+      Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
+      Constant *F = M.getOrInsertFunction("trackGlobalArray", VoidTy, VoidPtrTy, Int32Ty, Int32Ty, Int32Ty, NULL);
       CallInst::Create(F, Args.begin(), Args.end(), "", &I);
       //for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
         //offset += t;
@@ -236,7 +238,8 @@
       Args.push_back(GEP);
       Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[CAZ->getType()]));
       Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(CAZ->getType())));
-      Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, NULL);
+      Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
+      Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
       CallInst::Create(F, Args.begin(), Args.end(), "", &I);
     }
   }
@@ -251,7 +254,8 @@
     Args.push_back(GEP);
     Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[C->getType()]));
     Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(C->getType())));
-    Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, NULL);
+    Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
+    Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
     CallInst::Create(F, Args.begin(), Args.end(), "", &I);
   }
 
@@ -267,9 +271,11 @@
   Args.push_back(BCI);
   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, NULL);
+  Constant *F = M.getOrInsertFunction("trackLoadInst", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
   CallInst::Create(F, Args.begin(), Args.end(), "", &LI);
 
   return true;
@@ -284,9 +290,10 @@
   Args.push_back(BCI);
   Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[SI.getOperand(0)->getType()])); // SI.getValueOperand()
   Args.push_back(ConstantInt::get(Int8Ty, 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 store instruction.
-  Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, NULL);
+  Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
   CallInst::Create(F, Args.begin(), Args.end(), "", &SI);
 
   return true;
@@ -302,9 +309,10 @@
   Args.push_back(BCI);
   Args.push_back(BCI_Src);
   Args.push_back(ConstantInt::get(Int32Ty, 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, NULL);
+  Constant *F = M.getOrInsertFunction("copyTypeInfo", VoidTy, VoidPtrTy, VoidPtrTy, Int32Ty, 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=129911&r1=129910&r2=129911&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c Thu Apr 21 09:46:17 2011
@@ -41,12 +41,11 @@
 /**
  * Record the global type and address in the shadow memory.
  */
-void trackGlobal(void *ptr, uint8_t typeNumber, uint8_t size) {
+void trackGlobal(void *ptr, uint8_t typeNumber, uint8_t size, uint32_t tag) {
 	uintptr_t p = (uintptr_t)ptr;
 	p &= 0xFFFFFFFF;
 	shadow_begin[p] = typeNumber;
 	memset(&shadow_begin[p + 1], 0, size - 1);
-
 #if DEBUG
 	printf("Global: %p, %p = %u | %u bytes\n", ptr, (void *)p, typeNumber, size);
 #endif
@@ -54,26 +53,26 @@
 /**
  * Record the type stored at ptr(of size size) and replicate it
  */
-void trackGlobalArray(void *ptr, uint32_t size, uint32_t count) {
+void trackGlobalArray(void *ptr, uint32_t size, uint32_t count, uint32_t tag) {
   unsigned i;
   uintptr_t p = (uintptr_t)ptr;
-  uint8_t typeNumber = shadow_begin[p & 0xFFFFFFFF];
+  uintptr_t p1 = (uintptr_t)ptr;
   for(i =1; i<count;i++) {
     p += size;
-    shadow_begin[p & 0xFFFFFFFF] = typeNumber;
+    memcpy(&shadow_begin[p & 0xFFFFFFFF], &shadow_begin[p1 & 0xFFFFFFFF] , size);
   }
 }
 
 /**
  * Check the loaded type against the type recorded in the shadow memory.
  */
-void trackLoadInst(void *ptr, uint8_t typeNumber, uint8_t size) {
+void trackLoadInst(void *ptr, uint8_t typeNumber, uint8_t size, uint32_t tag) {
 	uint8_t i = 1;
 	uintptr_t p = (uintptr_t)ptr;
 	p &= 0xFFFFFFFF;
 
 	if (typeNumber != shadow_begin[p]) {
-		printf("Type mismatch: detecting %u, expecting %u!\n", typeNumber, shadow_begin[p]);
+		printf("Type mismatch: detecting %p %u, expecting %u! %u \n", ptr, typeNumber, shadow_begin[p], tag);
 		i = size;
 	}
 
@@ -92,24 +91,26 @@
 /**
  * Record the stored type and address in the shadow memory.
  */
-void trackStoreInst(void *ptr, uint8_t typeNumber, uint8_t size) {
+void trackStoreInst(void *ptr, uint8_t typeNumber, uint8_t size, uint32_t tag) {
 	uintptr_t p = (uintptr_t)ptr;
 	p &= 0xFFFFFFFF;
 	shadow_begin[p] = typeNumber;
 	memset(&shadow_begin[p + 1], 0, size - 1);
-
 #if DEBUG
-	printf("Store: %p, %p = %u | %u bytes\n", ptr, (void *)p, typeNumber, size);
+	printf("Store: %p, %p = %u | %u %d bytes\n", ptr, (void *)p, typeNumber, size, tag);
 #endif
 }
 
 /**
  * Copy size bits of metadata from src ptr to dest ptr.
  */
-void copyTypeInfo(void *dstptr, void *srcptr, uint8_t size) {
+void copyTypeInfo(void *dstptr, void *srcptr, uint8_t size, uint32_t tag) {
 	uintptr_t d = (uintptr_t)dstptr;
 	uintptr_t s = (uintptr_t)srcptr;
 	d &= 0xFFFFFFFF;
 	s &= 0xFFFFFFFF;
 	memcpy(&shadow_begin[d], &shadow_begin[s], size);
+#if DEBUG
+	printf("Copy: %p, %p = %u | %u %d bytes\n", dstptr, (void *)d, shadow_begin[s], size, tag);
+#endif
 }





More information about the llvm-commits mailing list