From d96288a2ff188bb1fb1b86fb89b1ac82f6310a5c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 8 May 2008 17:16:51 +0000 Subject: [PATCH] add a new Instruction::mayReadFromMemory predicate, make 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 | 4 ++++ lib/VMCore/Instruction.cpp | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 7933a4d3c2c..29ae5c3cfbf 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -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 diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 5344cf7bfe5..345fd1dd94e 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -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(this)->doesNotAccessMemory(); + case Instruction::Invoke: + return !cast(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(this)->onlyReadsMemory(); + case Instruction::Invoke: + return !cast(this)->onlyReadsMemory(); case Instruction::Load: return cast(this)->isVolatile(); }