Change the type of FnAllocState.
[oota-llvm.git] / lib / Analysis / LoadValueNumbering.cpp
index c47010c38317e73990db2950e90e91becf3861cf..cbcdd0f178a467784cce4d9467d957cf117380cb 100644 (file)
@@ -1,4 +1,11 @@
 //===- LoadValueNumbering.cpp - Load Value #'ing Implementation -*- C++ -*-===//
+// 
+//                     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 file implements a value numbering pass that value #'s load instructions.
 // To do this, it finds lexically identical load instructions, and uses alias
@@ -85,11 +92,15 @@ void LoadVN::getAnalysisUsage(AnalysisUsage &AU) const {
 void LoadVN::getEqualNumberNodes(Value *V,
                                  std::vector<Value*> &RetVals) const {
   // If the alias analysis has any must alias information to share with us, we
-  // can definately use it.
+  // can definitely use it.
   if (isa<PointerType>(V->getType()))
     getAnalysis<AliasAnalysis>().getMustAliases(V, RetVals);
 
   if (LoadInst *LI = dyn_cast<LoadInst>(V)) {
+    // Volatile loads cannot be replaced with the value of other loads.
+    if (LI->isVolatile())
+      return getAnalysis<ValueNumbering>().getEqualNumberNodes(V, RetVals);
+
     // If we have a load instruction, find all of the load and store
     // instructions that use the same source operand.  We implement this
     // recursively, because there could be a load of a load of a load that are
@@ -105,7 +116,7 @@ void LoadVN::getEqualNumberNodes(Value *V,
     Function *F = LI->getParent()->getParent();
 
     // Now that we know the set of equivalent source pointers for the load
-    // instruction, look to see if there are any load or store candiates that
+    // instruction, look to see if there are any load or store candidates that
     // are identical.
     //
     std::vector<LoadInst*> CandidateLoads;
@@ -119,10 +130,10 @@ void LoadVN::getEqualNumberNodes(Value *V,
            UI != UE; ++UI)
         if (LoadInst *Cand = dyn_cast<LoadInst>(*UI)) {// Is a load of source?
           if (Cand->getParent()->getParent() == F &&   // In the same function?
-              Cand != LI)                              // Not LI itself?
+              Cand != LI && !Cand->isVolatile())       // Not LI itself?
             CandidateLoads.push_back(Cand);     // Got one...
         } else if (StoreInst *Cand = dyn_cast<StoreInst>(*UI)) {
-          if (Cand->getParent()->getParent() == F &&
+          if (Cand->getParent()->getParent() == F && !Cand->isVolatile() &&
               Cand->getOperand(1) == Source)  // It's a store THROUGH the ptr...
             CandidateStores.push_back(Cand);
         }
@@ -144,7 +155,7 @@ void LoadVN::getEqualNumberNodes(Value *V,
     AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
     DominatorSet &DomSetInfo = getAnalysis<DominatorSet>();
     
-    // Loop over all of the candindate loads.  If they are not invalidated by
+    // Loop over all of the candidate loads.  If they are not invalidated by
     // stores or calls between execution of them and LI, then add them to
     // RetVals.
     for (unsigned i = 0, e = CandidateLoads.size(); i != e; ++i)