[llvm-commits] [llvm] r40961 - in /llvm/trunk: include/llvm/Analysis/MemoryDependenceAnalysis.h lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/DeadStoreElimination.cpp lib/Transforms/Scalar/GVN.cpp lib/Transforms/Scalar/RedundantLoadElimination.cpp

Owen Anderson resistor at mac.com
Wed Aug 8 21:42:44 PDT 2007


Author: resistor
Date: Wed Aug  8 23:42:44 2007
New Revision: 40961

URL: http://llvm.org/viewvc/llvm-project?rev=40961&view=rev
Log:
Make NonLocal and None const in the right way. :-)

Modified:
    llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
    llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
    llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp
    llvm/trunk/lib/Transforms/Scalar/RedundantLoadElimination.cpp

Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h?rev=40961&r1=40960&r2=40961&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Wed Aug  8 23:42:44 2007
@@ -33,23 +33,23 @@
   private:
     // A map from instructions to their dependency, with a boolean
     // flags for whether this mapping is confirmed or not
-    typedef DenseMap<Instruction*, std::pair<const Instruction*, bool> > 
+    typedef DenseMap<Instruction*, std::pair<Instruction*, bool> > 
             depMapType;
     depMapType depGraphLocal;
 
     // A reverse mapping form dependencies to the dependees.  This is
     // used when removing instructions to keep the cache coherent.
-    typedef DenseMap<const Instruction*, SmallPtrSet<Instruction*, 4> >
+    typedef DenseMap<Instruction*, SmallPtrSet<Instruction*, 4> >
             reverseDepMapType;
     reverseDepMapType reverseDep;
     
   public:
     // Special marker indicating that the query has no dependency
     // in the specified block.
-    static const Instruction* NonLocal;
+    static Instruction* const NonLocal;
     
     // Special marker indicating that the query has no dependency at all
-    static const Instruction* None;
+    static Instruction* const None;
     
     static char ID; // Class identification, replacement for typeinfo
     MemoryDependenceAnalysis() : FunctionPass((intptr_t)&ID) {}
@@ -71,7 +71,7 @@
     
     /// getDependency - Return the instruction on which a memory operation
     /// depends, starting with start.
-    const Instruction* getDependency(Instruction* query, Instruction* start = 0,
+    Instruction* getDependency(Instruction* query, Instruction* start = 0,
                                BasicBlock* block = 0);
     
     /// getNonLocalDependency - Fills the passed-in map with the non-local 
@@ -85,7 +85,7 @@
     void removeInstruction(Instruction* rem);
     
   private:
-    const Instruction* getCallSiteDependency(CallSite C, Instruction* start,
+    Instruction* getCallSiteDependency(CallSite C, Instruction* start,
                                        BasicBlock* block);
     void nonLocalHelper(Instruction* query, BasicBlock* block,
                         DenseMap<BasicBlock*, Value*>& resp);

Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=40961&r1=40960&r2=40961&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Wed Aug  8 23:42:44 2007
@@ -26,8 +26,8 @@
 
 char MemoryDependenceAnalysis::ID = 0;
   
-const Instruction* MemoryDependenceAnalysis::NonLocal = (Instruction*)-3;
-const Instruction* MemoryDependenceAnalysis::None = (Instruction*)-4;
+Instruction* const MemoryDependenceAnalysis::NonLocal = (Instruction*)-3;
+Instruction* const MemoryDependenceAnalysis::None = (Instruction*)-4;
   
 // Register this pass...
 static RegisterPass<MemoryDependenceAnalysis> X("memdep",
@@ -43,7 +43,7 @@
 
 /// getCallSiteDependency - Private helper for finding the local dependencies
 /// of a call site.
-const Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C,
+Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C,
                                                            Instruction* start,
                                                             BasicBlock* block) {
   
@@ -147,9 +147,9 @@
     if (BB != block) {
       visited.insert(BB);
       
-      const Instruction* localDep = getDependency(query, 0, BB);
+      Instruction* localDep = getDependency(query, 0, BB);
       if (localDep != NonLocal) {
-        resp.insert(std::make_pair(BB, const_cast<Instruction*>(localDep)));
+        resp.insert(std::make_pair(BB, localDep));
         stack.pop_back();
         
         continue;
@@ -160,9 +160,9 @@
     } else if (BB == block && stack.size() > 1) {
       visited.insert(BB);
       
-      const Instruction* localDep = getDependency(query, 0, BB);
+      Instruction* localDep = getDependency(query, 0, BB);
       if (localDep != query)
-        resp.insert(std::make_pair(BB, const_cast<Instruction*>(localDep)));
+        resp.insert(std::make_pair(BB, localDep));
       
       stack.pop_back();
       
@@ -186,12 +186,12 @@
     // If we didn't insert because we have no predecessors, then this
     // query has no dependency at all.
     else if (!inserted && !predOnStack) {
-      resp.insert(std::make_pair(BB, const_cast<Instruction*>(None)));
+      resp.insert(std::make_pair(BB, None));
     // If we didn't insert because our predecessors are already on the stack,
     // then we might still have a dependency, but it will be discovered during
     // backtracking.
     } else if (!inserted && predOnStack){
-      resp.insert(std::make_pair(BB, const_cast<Instruction*>(NonLocal)));
+      resp.insert(std::make_pair(BB, NonLocal));
     }
     
     stack.pop_back();
@@ -204,10 +204,9 @@
 void MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query,
                                          DenseMap<BasicBlock*, Value*>& resp) {
   // First check that we don't actually have a local dependency.
-  const Instruction* localDep = getDependency(query);
+  Instruction* localDep = getDependency(query);
   if (localDep != NonLocal) {
-    resp.insert(std::make_pair(query->getParent(),
-                               const_cast<Instruction*>(localDep)));
+    resp.insert(std::make_pair(query->getParent(),localDep));
     return;
   }
   
@@ -218,20 +217,20 @@
 /// getDependency - Return the instruction on which a memory operation
 /// depends.  The local paramter indicates if the query should only
 /// evaluate dependencies within the same basic block.
-const Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
+Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
                                                      Instruction* start,
                                                      BasicBlock* block) {
   // Start looking for dependencies with the queried inst
   BasicBlock::iterator QI = query;
   
   // Check for a cached result
-  std::pair<const Instruction*, bool> cachedResult = depGraphLocal[query];
+  std::pair<Instruction*, bool> cachedResult = depGraphLocal[query];
   // If we have a _confirmed_ cached entry, return it
   if (cachedResult.second)
     return cachedResult.first;
   else if (cachedResult.first && cachedResult.first != NonLocal)
   // If we have an unconfirmed cached entry, we can start our search from there
-    QI = const_cast<Instruction*>(cachedResult.first);
+    QI = cachedResult.first;
   
   if (start)
     QI = start;
@@ -378,7 +377,7 @@
 /// This method attempts to keep the cache coherent using the reverse map.
 void MemoryDependenceAnalysis::removeInstruction(Instruction* rem) {
   // Figure out the new dep for things that currently depend on rem
-  const Instruction* newDep = NonLocal;
+  Instruction* newDep = NonLocal;
 
   depMapType::iterator depGraphEntry = depGraphLocal.find(rem);
   // We assume here that it's not in the reverse map if it's not in
@@ -388,8 +387,7 @@
     if (depGraphEntry->second.first != NonLocal &&
         depGraphEntry->second.second) {
       // If we have dep info for rem, set them to it
-      BasicBlock::iterator RI =
-                         const_cast<Instruction*>(depGraphEntry->second.first);
+      BasicBlock::iterator RI = depGraphEntry->second.first;
       RI++;
       newDep = RI;
     } else if (depGraphEntry->second.first == NonLocal &&

Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=40961&r1=40960&r2=40961&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Wed Aug  8 23:42:44 2007
@@ -121,14 +121,14 @@
       
     // ... to a pointer that has been stored to before...
     if (last) {
-      Instruction* dep = const_cast<Instruction*>(MD.getDependency(BBI));
+      Instruction* dep = MD.getDependency(BBI);
         
       // ... and no other memory dependencies are between them....
       while (dep != MemoryDependenceAnalysis::None &&
              dep != MemoryDependenceAnalysis::NonLocal &&
              isa<StoreInst>(dep)) {
         if (dep != last) {
-          dep = const_cast<Instruction*>(MD.getDependency(BBI, dep));
+          dep = MD.getDependency(BBI, dep);
           continue;
         }
         
@@ -154,7 +154,7 @@
     if (FreeInst* F = dyn_cast<FreeInst>(BBI)) {
       if (!deletedStore)
         MadeChange |= handleFreeWithNonTrivialDependency(F,
-                        const_cast<Instruction*>(MD.getDependency(F)),
+                                                         MD.getDependency(F),
                                                          possiblyDead);
       // No known stores after the free
       last = 0;

Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=40961&r1=40960&r2=40961&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Wed Aug  8 23:42:44 2007
@@ -803,7 +803,7 @@
       return false;
     } else if (I->second == MemoryDependenceAnalysis::NonLocal) {
       continue;
-    } else if (StoreInst* S = dyn_cast<StoreInst>(I->second)) {
+    }else if (StoreInst* S = dyn_cast<StoreInst>(I->second)) {
       if (S->getPointerOperand() == L->getPointerOperand())
         repl[I->first] = S->getOperand(0);
       else
@@ -856,7 +856,7 @@
   
   // ... to a pointer that has been loaded from before...
   MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
-  Instruction* dep = const_cast<Instruction*>(MD.getDependency(L));
+  Instruction* dep = MD.getDependency(L);
   if (dep == MemoryDependenceAnalysis::NonLocal &&
       L->getParent() != &L->getParent()->getParent()->getEntryBlock())
     processNonLocalLoad(L, toErase);
@@ -895,7 +895,7 @@
         
       break;
     } else {
-      dep = const_cast<Instruction*>(MD.getDependency(L, dep));
+      dep = MD.getDependency(L, dep);
     }
   }
   

Modified: llvm/trunk/lib/Transforms/Scalar/RedundantLoadElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RedundantLoadElimination.cpp?rev=40961&r1=40960&r2=40961&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/RedundantLoadElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/RedundantLoadElimination.cpp Wed Aug  8 23:42:44 2007
@@ -80,7 +80,7 @@
       LoadInst*& last = lastLoad[pointer];
       
       // ... to a pointer that has been loaded from before...
-      Instruction* dep = const_cast<Instruction*>(MD.getDependency(BBI));
+      Instruction* dep = MD.getDependency(BBI);
       bool deletedLoad = false;
       
       while (dep != MemoryDependenceAnalysis::None &&
@@ -120,7 +120,7 @@
             
           break;
         } else {
-          dep = const_cast<Instruction*>(MD.getDependency(BBI, dep));
+          dep = MD.getDependency(BBI, dep);
         }
       }
       





More information about the llvm-commits mailing list