add a new Instruction::mayReadFromMemory predicate, make
authorChris Lattner <sabre@nondot.org>
Thu, 8 May 2008 17:16:51 +0000 (17:16 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 8 May 2008 17:16:51 +0000 (17:16 +0000)
Instruction::mayWriteToMemory stronger for invokes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50858 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instruction.h
lib/VMCore/Instruction.cpp

index 7933a4d3c2c545684cdbafcc095fcebaa64ab9fb..29ae5c3cfbf5aa853482a1388e35ff5707b3ff0b 100644 (file)
@@ -50,6 +50,10 @@ public:
   ///
   bool mayWriteToMemory() const;
 
+  /// mayReadFromMemory - Return true if this instruction may read memory.
+  ///
+  bool mayReadFromMemory() const;
+  
   /// clone() - Create a copy of 'this' instruction that is identical in all
   /// ways except the following:
   ///   * The instruction has no parent
index 5344cf7bfe58e101a1da105b31f0e0f7f07506d4..345fd1dd94e9fab52a5776d8022389ca1b64e892 100644 (file)
@@ -219,7 +219,23 @@ bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const {
   return false;    
 }
 
-
+/// mayReadFromMemory - Return true if this instruction may read memory.
+///
+bool Instruction::mayReadFromMemory() const {
+  switch (getOpcode()) {
+  default: return false;
+  case Instruction::Free:
+  case Instruction::Store:
+  case Instruction::VAArg:
+    return true;
+  case Instruction::Call:
+    return !cast<CallInst>(this)->doesNotAccessMemory();
+  case Instruction::Invoke:
+    return !cast<InvokeInst>(this)->doesNotAccessMemory();
+  case Instruction::Load:
+    return true;
+  }
+}
 
 /// mayWriteToMemory - Return true if this instruction may modify memory.
 ///
@@ -227,12 +243,13 @@ bool Instruction::mayWriteToMemory() const {
   switch (getOpcode()) {
   default: return false;
   case Instruction::Free:
-  case Instruction::Invoke:
   case Instruction::Store:
   case Instruction::VAArg:
     return true;
   case Instruction::Call:
     return !cast<CallInst>(this)->onlyReadsMemory();
+  case Instruction::Invoke:
+    return !cast<InvokeInst>(this)->onlyReadsMemory();
   case Instruction::Load:
     return cast<LoadInst>(this)->isVolatile();
   }