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

Brice Lin Brice.Lin at gmail.com
Sat Apr 16 13:43:09 PDT 2011


Author: bglin2
Date: Sat Apr 16 15:43:09 2011
New Revision: 129645

URL: http://llvm.org/viewvc/llvm-project?rev=129645&view=rev
Log:
Interface the TypeChecks pass with the TargetData and TypeAnalysis passes.

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=129645&r1=129644&r2=129645&view=diff
==============================================================================
--- poolalloc/trunk/include/assistDS/TypeChecks.h (original)
+++ poolalloc/trunk/include/assistDS/TypeChecks.h Sat Apr 16 15:43:09 2011
@@ -14,8 +14,11 @@
 #ifndef TYPE_CHECKS_H
 #define TYPE_CHECKS_H
 
+#include "assistDS/TypeAnalysis.h"
+
 #include "llvm/Instructions.h"
 #include "llvm/Pass.h"
+#include "llvm/Target/TargetData.h"
 
 #include <map>
 
@@ -30,6 +33,9 @@
   std::map<const Type *, unsigned int> UsedTypes;
   std::map<const Value *, const Type *> UsedValues;
 
+  // Analysis from other passes.
+  TargetData *TD;
+
   // Incorporate one type and all of its subtypes into the collection of used types.
   void IncorporateType(const Type *Ty);
 
@@ -43,6 +49,8 @@
   virtual void print(raw_ostream &OS, const Module *M) const;
 
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+    AU.addRequired<TargetData>();
+    AU.addRequired<TypeAnalysis>();
   }
 
   bool initShadow(Module &M, Instruction &I);
@@ -50,6 +58,7 @@
   bool visitLoadInst(Module &M, LoadInst &LI);
   bool visitGlobal(Module &M, GlobalVariable &GV, Instruction &I);
   bool visitStoreInst(Module &M, StoreInst &SI);
+  bool visitCopyingStoreInst(Module &M, StoreInst &SI, Value *SS);
 
   // 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=129645&r1=129644&r2=129645&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Sat Apr 16 15:43:09 2011
@@ -63,6 +63,9 @@
 bool TypeChecks::runOnModule(Module &M) {
   bool modified = false; // Flags whether we modified the module.
 
+  TD = &getAnalysis<TargetData>();
+  TypeAnalysis &TA = getAnalysis<TypeAnalysis>();
+
   VoidTy = IntegerType::getVoidTy(M.getContext());
   Int8Ty = IntegerType::getInt8Ty(M.getContext());
   Int32Ty = IntegerType::getInt32Ty(M.getContext());
@@ -109,10 +112,20 @@
       for (User::op_iterator OI = I.op_begin(), OE = I.op_end(); OI != OE; ++OI) {
         IncorporateValue(*OI); // Insert instruction operand types.
       }
+
       if (StoreInst *SI = dyn_cast<StoreInst>(&I)) {
-        modified |= visitStoreInst(M, *SI);
+        if (TA.isCopyingStore(SI)) {
+          Value *SS = TA.getStoreSource(SI);
+          if (SS != NULL) {
+            modified |= visitCopyingStoreInst(M, *SI, SS);
+          }
+        } else {
+          modified |= visitStoreInst(M, *SI);
+        }
       } else if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
-        modified |= visitLoadInst(M, *LI);
+        if (!TA.isCopyingLoad(LI)) {
+          modified |= visitLoadInst(M, *LI);
+        }
       }
     }
   }
@@ -202,3 +215,19 @@
 
   return true;
 }
+
+// Insert runtime checks before copying store instructions.
+bool TypeChecks::visitCopyingStoreInst(Module &M, StoreInst &SI, Value *SS) {
+  // Cast the pointer operand to i8* for the runtime function.
+  CastInst *BCI = BitCastInst::CreatePointerCast(SI.getPointerOperand(), VoidPtrTy, "", &SI);
+
+  std::vector<Value *> Args;
+  Args.push_back(BCI);
+  Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[SS->getType()]));
+
+  // Create the call to the runtime check and place it before the store instruction.
+  Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, NULL);
+  CallInst::Create(F, Args.begin(), Args.end(), "", &SI);
+
+  return true;
+}





More information about the llvm-commits mailing list