A brief survey of priority_queue usage in the tree turned this up
[oota-llvm.git] / lib / VMCore / Instruction.cpp
index fdee5e8b4603628f24ff1d6883577bcb201e260a..e8738d2ba72bd755ab7427f8987834bac0781558 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     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 is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -13,7 +13,6 @@
 
 #include "llvm/Type.h"
 #include "llvm/Instructions.h"
-#include "llvm/IntrinsicInst.h" // FIXME: remove
 #include "llvm/Function.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/LeakDetector.h"
@@ -46,8 +45,8 @@ Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
 
 
 // Out of line virtual method, so the vtable, etc has a home.
-void Instruction::destroyThis(Instruction*v) {
-  assert(v->Parent == 0 && "Instruction still linked in the program!");
+Instruction::~Instruction() {
+  assert(Parent == 0 && "Instruction still linked in the program!");
 }
 
 
@@ -69,6 +68,12 @@ void Instruction::eraseFromParent() {
   getParent()->getInstList().erase(this);
 }
 
+/// insertBefore - Insert an unlinked instructions into a basic block
+/// immediately before the specified instruction.
+void Instruction::insertBefore(Instruction *InsertPos) {
+  InsertPos->getParent()->getInstList().insert(InsertPos, this);
+}
+
 /// moveBefore - Unlink this instruction from its current basic block and
 /// insert it into the basic block that MovePos lives in, right before
 /// MovePos.
@@ -129,6 +134,8 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
   // Other instructions...
   case ICmp:           return "icmp";
   case FCmp:           return "fcmp";
+  case VICmp:          return "vicmp";
+  case VFCmp:          return "vfcmp";
   case PHI:            return "phi";
   case Select:         return "select";
   case Call:           return "call";
@@ -139,6 +146,9 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
   case ExtractElement: return "extractelement";
   case InsertElement:  return "insertelement";
   case ShuffleVector:  return "shufflevector";
+  case GetResult:      return "getresult";
+  case ExtractValue:   return "extractvalue";
+  case InsertValue:    return "insertvalue";
 
   default: return "<Invalid operator> ";
   }
@@ -198,20 +208,58 @@ bool Instruction::isSameOperationAs(Instruction *I) const {
   return true;
 }
 
+/// isUsedOutsideOfBlock - Return true if there are any uses of I outside of the
+/// specified block.  Note that PHI nodes are considered to evaluate their
+/// operands in the corresponding predecessor block.
+bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const {
+  for (use_const_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) {
+    // PHI nodes uses values in the corresponding predecessor block.  For other
+    // instructions, just check to see whether the parent of the use matches up.
+    const PHINode *PN = dyn_cast<PHINode>(*UI);
+    if (PN == 0) {
+      if (cast<Instruction>(*UI)->getParent() != BB)
+        return true;
+      continue;
+    }
+    
+    unsigned UseOperand = UI.getOperandNo();
+    if (PN->getIncomingBlock(UseOperand/2) != BB)
+      return true;
+  }
+  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::VAArg:
+  case Instruction::Load:
+    return true;
+  case Instruction::Call:
+    return !cast<CallInst>(this)->doesNotAccessMemory();
+  case Instruction::Invoke:
+    return !cast<InvokeInst>(this)->doesNotAccessMemory();
+  case Instruction::Store:
+    return cast<StoreInst>(this)->isVolatile();
+  }
+}
+
 /// mayWriteToMemory - Return true if this instruction may modify memory.
 ///
 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:
-    if (!isa<IntrinsicInst>(this))
-      return true; // FIXME: workaround gcc bootstrap breakage
     return !cast<CallInst>(this)->onlyReadsMemory();
+  case Instruction::Invoke:
+    return !cast<InvokeInst>(this)->onlyReadsMemory();
   case Instruction::Load:
     return cast<LoadInst>(this)->isVolatile();
   }
@@ -268,6 +316,7 @@ bool Instruction::isTrapping(unsigned op) {
   case Store:
   case Call:
   case Invoke:
+  case VAArg:
     return true;
   default:
     return false;