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

Arushi Aggarwal aggarwa4 at illinois.edu
Wed Jun 15 15:36:03 PDT 2011


Author: aggarwa4
Date: Wed Jun 15 17:36:02 2011
New Revision: 133098

URL: http://llvm.org/viewvc/llvm-project?rev=133098&view=rev
Log:
Optimization pass to not instrument loads of pointers
used solely in compares.

Added:
    poolalloc/trunk/include/assistDS/TypeChecksCmpOpt.h
    poolalloc/trunk/lib/AssistDS/TypeChecksCmpOpt.cpp

Added: poolalloc/trunk/include/assistDS/TypeChecksCmpOpt.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/assistDS/TypeChecksCmpOpt.h?rev=133098&view=auto
==============================================================================
--- poolalloc/trunk/include/assistDS/TypeChecksCmpOpt.h (added)
+++ poolalloc/trunk/include/assistDS/TypeChecksCmpOpt.h Wed Jun 15 17:36:02 2011
@@ -0,0 +1,46 @@
+//=== TypeChecksCmpOpt.h - Remove runtime type checks for ptrs used in cmp ===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass removes type checks that are on values used in compares
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TYPE_CHECKS_CMP_OPT_H
+#define TYPE_CHECKS_CMP_OPT_H
+
+#include "assistDS/TypeAnalysis.h"
+
+#include "llvm/Instructions.h"
+#include "llvm/Pass.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Support/CallSite.h"
+
+#include <set>
+
+namespace llvm {
+
+class Type;
+class Value;
+
+class TypeChecksCmpOpt : public ModulePass {
+
+private:
+
+  std::set<Instruction *> toDelete;
+
+public:
+  static char ID;
+  TypeChecksCmpOpt() : ModulePass(&ID) {}
+  virtual bool runOnModule(Module &M);
+
+};
+
+} // End llvm namespace
+
+#endif

Added: poolalloc/trunk/lib/AssistDS/TypeChecksCmpOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecksCmpOpt.cpp?rev=133098&view=auto
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecksCmpOpt.cpp (added)
+++ poolalloc/trunk/lib/AssistDS/TypeChecksCmpOpt.cpp Wed Jun 15 17:36:02 2011
@@ -0,0 +1,97 @@
+//===---------- TypeChecksOpt.h - Remove safe runtime type checks ---------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass removes type checks that are statically proven safe
+//
+//===----------------------------------------------------------------------===//
+
+#include "assistDS/TypeChecksCmpOpt.h"
+#include "llvm/Constants.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
+#include "llvm/Assembly/Writer.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/InstIterator.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Intrinsics.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/ADT/Statistic.h"
+
+#include <set>
+#include <vector>
+
+using namespace llvm;
+
+char TypeChecksCmpOpt::ID = 0;
+
+static RegisterPass<TypeChecksCmpOpt> 
+TC("typechecks-cmp-opt", "Remove runtime type checks", false, true);
+
+// Pass statistics
+STATISTIC(numSafe,  "Number of type checks on loads used in Cmp");
+
+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;
+static Constant *trackLoadInst;
+
+bool TypeChecksCmpOpt::runOnModule(Module &M) {
+
+  // Create the necessary prototypes
+  VoidTy = IntegerType::getVoidTy(M.getContext());
+  Int8Ty = IntegerType::getInt8Ty(M.getContext());
+  Int32Ty = IntegerType::getInt32Ty(M.getContext());
+  Int64Ty = IntegerType::getInt64Ty(M.getContext());
+  VoidPtrTy = PointerType::getUnqual(Int8Ty);
+
+  trackLoadInst = M.getOrInsertFunction("trackLoadInst",
+                                        VoidTy,
+                                        VoidPtrTy,/*ptr*/
+                                        Int8Ty,/*type*/
+                                        Int64Ty,/*size*/
+                                        Int32Ty,/*tag*/
+                                        NULL);
+  for(Value::use_iterator User = trackLoadInst->use_begin(); User != trackLoadInst->use_end(); ++User) {
+    CallInst *CI = dyn_cast<CallInst>(User);
+    assert(CI);
+    Value *LPtr = CI->getOperand(1)->stripPointerCasts();
+    for(Value::use_iterator II = LPtr->use_begin(); II != LPtr->use_end(); ++II) {
+      if(LoadInst *LI = dyn_cast<LoadInst>(II)) {
+        if(LI->getOperand(0) == LPtr) {
+          if(LI->getType()->isPointerTy()) {
+            bool allIcmpUse = true;
+            for(Value::use_iterator EE = LI->use_begin(); EE != LI->use_end(); ++EE) {
+              if(!isa<ICmpInst>(EE)) {
+                allIcmpUse = false;
+                break;
+              }
+            }
+            if(allIcmpUse) {
+              toDelete.insert(CI);
+              LI->dump();
+            }
+          }
+        }
+      }
+    }
+  }
+
+  numSafe += toDelete.size();
+
+  std::set<Instruction*>::iterator II = toDelete.begin();
+  for(; II != toDelete.end();) {
+    Instruction *I = *II++;
+    I->eraseFromParent();
+  }
+  return (numSafe > 0);
+}
+





More information about the llvm-commits mailing list