Add method
authorChris Lattner <sabre@nondot.org>
Tue, 30 Nov 2004 02:51:53 +0000 (02:51 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 30 Nov 2004 02:51:53 +0000 (02:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18368 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8d49870e4d32398e49175e73d3cdfa51ac592ba7..a7359731db7d513f77bd136acbb5efda4452c6d6 100644 (file)
@@ -67,6 +67,12 @@ public:
   ///   * The instruction has no name
   ///
   virtual Instruction *clone() const = 0;
+
+  /// isIdenticalTo - Return true if the specified instruction is exactly
+  /// identical to the current one.  This means that all operands match and any
+  /// extra information (e.g. load is volatile) agree.
+  bool isIdenticalTo(Instruction *I) const;
+
   
   // Accessor methods...
   //
index 17970ac9ba9ad84ea22d6542ed6be3e907195c56..696b12e27b1341b2322dab8d46f2acbbea2ce944 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Instructions.h"
 #include "llvm/Function.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Type.h"
 #include "llvm/Support/LeakDetector.h"
 using namespace llvm;
 
-void Instruction::init()
-{
+void Instruction::init() {
   // Make sure that we get added to a basicblock
   LeakDetector::addGarbageObject(this);
 }
@@ -134,6 +134,31 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
   return 0;
 }
 
+/// isIdenticalTo - Return true if the specified instruction is exactly
+/// identical to the current one.  This means that all operands match and any
+/// extra information (e.g. load is volatile) agree.
+bool Instruction::isIdenticalTo(Instruction *I) const {
+  if (getOpcode() != I->getOpcode() ||
+      getNumOperands() != I->getNumOperands() ||
+      getType() != I->getType())
+    return false;
+
+  // We have two instructions of identical opcode and #operands.  Check to see
+  // if all operands are the same.
+  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
+    if (getOperand(i) != I->getOperand(i))
+      return false;
+
+  // Check special state that is a part of some instructions.
+  if (const LoadInst *LI = dyn_cast<LoadInst>(this))
+    return LI->isVolatile() == cast<LoadInst>(I)->isVolatile();
+  if (const StoreInst *SI = dyn_cast<StoreInst>(this))
+    return SI->isVolatile() == cast<StoreInst>(I)->isVolatile();
+  if (const VANextInst *VAN = dyn_cast<VANextInst>(this))
+    return VAN->getArgType() == cast<VANextInst>(I)->getArgType();
+  return true;
+}
+
 
 /// isAssociative - Return true if the instruction is associative:
 ///