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

Brice Lin Brice.Lin at gmail.com
Tue Apr 5 22:39:55 PDT 2011


Author: bglin2
Date: Wed Apr  6 00:39:55 2011
New Revision: 128989

URL: http://llvm.org/viewvc/llvm-project?rev=128989&view=rev
Log:
Modified dynamic type checking pass to insert the shadow initialization function at the entry to main.

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=128989&r1=128988&r2=128989&view=diff
==============================================================================
--- poolalloc/trunk/include/assistDS/TypeChecks.h (original)
+++ poolalloc/trunk/include/assistDS/TypeChecks.h Wed Apr  6 00:39:55 2011
@@ -45,8 +45,7 @@
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
   }
 
-  bool initShadow(Module &M, StoreInst &SI);
-  bool initShadowLI(Module &M, LoadInst &LI);
+  bool initShadow(Module &M, Instruction &I);
   bool unmapShadow(Module &M, Instruction &I);
   bool visitLoadInst(Module &M, LoadInst &LI);
   bool visitStoreInst(Module &M, StoreInst &SI);

Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=128989&r1=128988&r2=128989&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Wed Apr  6 00:39:55 2011
@@ -62,7 +62,6 @@
 
 bool TypeChecks::runOnModule(Module &M) {
   bool modified = false; // Flags whether we modified the module.
-  bool firstSI = true;
 
   VoidTy = IntegerType::getVoidTy(M.getContext());
   Int8Ty = IntegerType::getInt8Ty(M.getContext());
@@ -80,6 +79,14 @@
     }
   }
 
+  // Insert the shadow initialization function at the entry to main.
+  Function *MainF = M.getFunction("main");
+  if (MainF == 0 || MainF->isDeclaration())
+    return false;
+
+  inst_iterator MainI = inst_begin(MainF);
+  modified |= initShadow(M, *MainI);
+
   for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI) {
     IncorporateType(MI->getType());
     Function &F = *MI;
@@ -94,19 +101,8 @@
       }
 
       if (StoreInst *SI = dyn_cast<StoreInst>(&I)) {
-        if (firstSI) {
-          modified |= initShadow(M, *SI);
-          firstSI = false;
-        }
-
         modified |= visitStoreInst(M, *SI);
       } else if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
-        // Unlikely, but just in case
-        if (firstSI) {
-          modified |= initShadowLI(M, *LI);
-          firstSI = false;
-        }
-
         modified |= visitLoadInst(M, *LI);
       }
     }
@@ -137,19 +133,10 @@
 }
 
 // Initialize the shadow memory which contains the 1:1 mapping.
-bool TypeChecks::initShadow(Module &M, StoreInst &SI) {
+bool TypeChecks::initShadow(Module &M, Instruction &I) {
   // Create the call to the runtime initialization function and place it before the store instruction.
   Constant *F = M.getOrInsertFunction("shadowInit", VoidTy, NULL);
-  CallInst::Create(F, "", &SI);
-
-  return true;
-}
-
-// Initialize the shadow memory which contains the 1:1 mapping.
-bool TypeChecks::initShadowLI(Module &M, LoadInst &LI) {
-  // Create the call to the runtime initialization function and place it before the load instruction.
-  Constant *F = M.getOrInsertFunction("shadowInit", VoidTy, NULL);
-  CallInst::Create(F, "", &LI);
+  CallInst::Create(F, "", &I);
 
   return true;
 }





More information about the llvm-commits mailing list