[llvm-commits] [poolalloc] r132075 - in /poolalloc/trunk: include/assistDS/TypeChecks.h lib/AssistDS/TypeChecks.cpp

Arushi Aggarwal aggarwa4 at illinois.edu
Wed May 25 13:05:07 PDT 2011


Author: aggarwa4
Date: Wed May 25 15:05:07 2011
New Revision: 132075

URL: http://llvm.org/viewvc/llvm-project?rev=132075&view=rev
Log:
The map for metadata was getting initialized with
default values 0. Every time a new type is 
encountered, give it the next type tag.

Modified:
    poolalloc/trunk/include/assistDS/TypeChecks.h
    poolalloc/trunk/lib/AssistDS/TypeChecks.cpp

Modified: poolalloc/trunk/include/assistDS/TypeChecks.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/assistDS/TypeChecks.h?rev=132075&r1=132074&r2=132075&view=diff
==============================================================================
--- poolalloc/trunk/include/assistDS/TypeChecks.h (original)
+++ poolalloc/trunk/include/assistDS/TypeChecks.h Wed May 25 15:05:07 2011
@@ -70,6 +70,7 @@
   bool visitCopyingStoreInst(Module &M, StoreInst &SI, Value *SS);
   bool visitInputFunctionValue(Module &M, Value *V, Instruction *CI);
 
+  unsigned int getTypeMarker(const llvm::Type*);
   // Return the map containing all of the types used in the module.
   const std::map<const Type *, unsigned int> &getTypes() const {
     return UsedTypes;

Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=132075&r1=132074&r2=132075&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Wed May 25 15:05:07 2011
@@ -53,6 +53,14 @@
 static const Type *Int64Ty = 0;
 static const PointerType *VoidPtrTy = 0;
 
+unsigned int 
+TypeChecks::getTypeMarker(const Type * Ty) {
+  if(UsedTypes.find(Ty) == UsedTypes.end())
+    UsedTypes[Ty] = UsedTypes.size();
+
+  return UsedTypes[Ty];
+}
+
 bool TypeChecks::runOnModule(Module &M) {
   bool modified = false; // Flags whether we modified the module.
 
@@ -144,27 +152,27 @@
 // Transform Variable Argument functions, by also passing
 // the relavant metadata info
 bool
-TypeChecks::visitVarArgFunction(Module &M, Function &F) {
-  if(!F.isVarArg())
-    return false;
+  TypeChecks::visitVarArgFunction(Module &M, Function &F) {
+    if(!F.isVarArg())
+      return false;
 
-  if(F.hasInternalLinkage()) {
-    visitInternalVarArgFunction(M, F);
-  } else {
-    // create internal clone
-    Function *F_clone = CloneFunction(&F);
-    F_clone->setName(F.getNameStr() + "internal");
-    F.setLinkage(GlobalValue::InternalLinkage);
-    F.getParent()->getFunctionList().push_back(F_clone);
-    F.replaceAllUsesWith(F_clone);
-    visitInternalVarArgFunction(M, *F_clone);
+    if(F.hasInternalLinkage()) {
+      visitInternalVarArgFunction(M, F);
+    } else {
+      // create internal clone
+      Function *F_clone = CloneFunction(&F);
+      F_clone->setName(F.getNameStr() + "internal");
+      F.setLinkage(GlobalValue::InternalLinkage);
+      F.getParent()->getFunctionList().push_back(F_clone);
+      F.replaceAllUsesWith(F_clone);
+      visitInternalVarArgFunction(M, *F_clone);
+    }
+    return true;
   }
-  return true;
-}
 
 bool 
 TypeChecks::visitInternalVarArgFunction(Module &M, Function &F) {
-  
+
   inst_iterator InsPt = inst_begin(F);
 
   AllocaInst *VASizeLoc = new AllocaInst(Int64Ty, "", &*InsPt);
@@ -199,14 +207,14 @@
       Instruction *VAMetaData = new LoadInst(VAMDLoc, "", VI);
       Args.push_back(VASize);
       Args.push_back(OldValue);
-      Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[VI->getType()]));
+      Args.push_back(ConstantInt::get(Int8Ty, getTypeMarker(VI->getType())));
       Args.push_back(VAMetaData);
       Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
       Constant *Func = M.getOrInsertFunction("compareTypeAndNumber", VoidTy, Int64Ty, Int64Ty, Int8Ty, VoidPtrTy, Int32Ty, NULL);
       CallInst::Create(Func, Args.begin(), Args.end(), "", VI);
     }
   }
-  
+
   CallInst *VAStart = NULL;
   for (Function::iterator B = F.begin(), FE = F.end(); B != FE; ++B) {
     for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE;) {
@@ -262,7 +270,7 @@
       Idx[0] = ConstantInt::get(Int32Ty, j++);
       // For each vararg argument, also add its type information before it
       GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(AI, Idx, Idx + 1, "", CI);
-      new StoreInst(ConstantInt::get(Int8Ty, UsedTypes[CI->getOperand(i)->getType()]), GEP, CI);
+      new StoreInst(ConstantInt::get(Int8Ty, getTypeMarker(CI->getOperand(i)->getType())), GEP, CI);
     }
 
     for(i = 1 ;i < CI->getNumOperands(); i++) {
@@ -718,7 +726,7 @@
 
       std::vector<Value *> Args;
       Args.push_back(GEP);
-      Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[CAZ->getType()]));
+      Args.push_back(ConstantInt::get(Int8Ty, getTypeMarker(CAZ->getType())));
       Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(CAZ->getType())));
       Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
       Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int64Ty, Int32Ty, NULL);
@@ -735,7 +743,7 @@
 
     std::vector<Value *> Args;
     Args.push_back(GEP);
-    Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[C->getType()]));
+    Args.push_back(ConstantInt::get(Int8Ty, getTypeMarker(C->getType())));
     Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(C->getType())));
     Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
     Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int64Ty, Int32Ty, NULL);
@@ -1026,7 +1034,7 @@
 
   std::vector<Value *> Args;
   Args.push_back(BCI);
-  Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[PTy->getElementType()])); // SI.getValueOperand()
+  Args.push_back(ConstantInt::get(Int8Ty, getTypeMarker(PTy->getElementType())));
   Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(PTy->getElementType())));
   Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
 
@@ -1049,7 +1057,7 @@
 
   std::vector<Value *> Args;
   Args.push_back(BCI);
-  Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[LI.getType()]));
+  Args.push_back(ConstantInt::get(Int8Ty, getTypeMarker(LI.getType())));
   Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(LI.getType())));
   Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
 
@@ -1072,7 +1080,8 @@
 
   std::vector<Value *> Args;
   Args.push_back(BCI);
-  Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[SI.getOperand(0)->getType()])); // SI.getValueOperand()
+  Args.push_back(ConstantInt::get(Int8Ty, 
+                                  getTypeMarker(SI.getOperand(0)->getType()))); // SI.getValueOperand()
   Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(SI.getOperand(0)->getType())));
   Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
 





More information about the llvm-commits mailing list