make mayWriteToMemory a non-virtual function


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34334 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index 7f7bcc8..239e878 100644
--- a/include/llvm/Instruction.h
+++ b/include/llvm/Instruction.h
@@ -54,7 +54,7 @@
   
   /// mayWriteToMemory - Return true if this instruction may modify memory.
   ///
-  virtual bool mayWriteToMemory() const { return false; }
+  bool mayWriteToMemory() const;
 
   /// clone() - Create a copy of 'this' instruction that is identical in all
   /// ways except the following:
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h
index 9fc7601..259b5aa 100644
--- a/include/llvm/Instructions.h
+++ b/include/llvm/Instructions.h
@@ -189,8 +189,6 @@
 
   virtual FreeInst *clone() const;
 
-  virtual bool mayWriteToMemory() const { return true; }
-
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const FreeInst *) { return true; }
   static inline bool classof(const Instruction *I) {
@@ -245,8 +243,6 @@
 
   virtual LoadInst *clone() const;
 
-  virtual bool mayWriteToMemory() const { return isVolatile(); }
-
   Value *getPointerOperand() { return getOperand(0); }
   const Value *getPointerOperand() const { return getOperand(0); }
   static unsigned getPointerOperandIndex() { return 0U; }
@@ -310,8 +306,6 @@
 
   virtual StoreInst *clone() const;
 
-  virtual bool mayWriteToMemory() const { return true; }
-
   Value *getPointerOperand() { return getOperand(1); }
   const Value *getPointerOperand() const { return getOperand(1); }
   static unsigned getPointerOperandIndex() { return 1U; }
@@ -722,8 +716,7 @@
   ~CallInst();
 
   virtual CallInst *clone() const;
-  bool mayWriteToMemory() const { return true; }
-
+  
   bool isTailCall() const           { return SubclassData & 1; }
   void setTailCall(bool isTailCall = true) {
     SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
@@ -845,7 +838,6 @@
   }
 
   virtual VAArgInst *clone() const;
-  bool mayWriteToMemory() const { return true; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const VAArgInst *) { return true; }
@@ -888,8 +880,6 @@
 
   virtual ExtractElementInst *clone() const;
 
-  virtual bool mayWriteToMemory() const { return false; }
-
   /// Transparently provide more efficient getOperand methods.
   Value *getOperand(unsigned i) const {
     assert(i < 2 && "getOperand() out of range!");
@@ -938,8 +928,6 @@
 
   virtual InsertElementInst *clone() const;
 
-  virtual bool mayWriteToMemory() const { return false; }
-
   /// getType - Overload to return most specific vector type.
   ///
   inline const VectorType *getType() const {
@@ -990,8 +978,6 @@
 
   virtual ShuffleVectorInst *clone() const;
 
-  virtual bool mayWriteToMemory() const { return false; }
-
   /// getType - Overload to return most specific vector type.
   ///
   inline const VectorType *getType() const {
@@ -1499,8 +1485,6 @@
 
   virtual InvokeInst *clone() const;
 
-  bool mayWriteToMemory() const { return true; }
-
   /// getCallingConv/setCallingConv - Get or set the calling convention of this
   /// function call.
   unsigned getCallingConv() const { return SubclassData; }
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp
index 39a89551..e02af07 100644
--- a/lib/VMCore/Instruction.cpp
+++ b/lib/VMCore/Instruction.cpp
@@ -225,6 +225,25 @@
   return true;
 }
 
+/// mayWriteToMemory - Return true if this instruction may modify memory.
+///
+bool Instruction::mayWriteToMemory() const {
+  switch (getOpcode()) {
+  default: return false;
+  case Instruction::Free:
+  case Instruction::Store:
+  case Instruction::Invoke:
+  case Instruction::VAArg:
+    return true;
+  case Instruction::Call:
+    if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(this)) {
+      // If the intrinsic doesn't write memory, it is safe.
+    }
+    return true;
+  case Instruction::Load:
+    return cast<LoadInst>(this)->isVolatile();
+  }
+}
 
 /// isAssociative - Return true if the instruction is associative:
 ///