Write constexpr casts using the cast X to Y notation, not using the implicit
[oota-llvm.git] / lib / VMCore / InstrTypes.cpp
index 29b293f1aa29b190c5ee72f3b8fa0457208b0e23..954719aa95070aae6b73a402213c899122b10670 100644 (file)
@@ -5,31 +5,23 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/iOther.h"
-#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/iPHINode.h"
+#include "llvm/Function.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Type.h"
-#include <algorithm>
+#include <algorithm>  // find
 
 //===----------------------------------------------------------------------===//
 //                            TerminatorInst Class
 //===----------------------------------------------------------------------===//
 
-TerminatorInst::TerminatorInst(unsigned iType) 
+TerminatorInst::TerminatorInst(Instruction::TermOps iType) 
   : Instruction(Type::VoidTy, iType, "") {
 }
 
-
-//===----------------------------------------------------------------------===//
-//                            MethodArgument Class
-//===----------------------------------------------------------------------===//
-
-// Specialize setName to take care of symbol table majik
-void MethodArgument::setName(const string &name) {
-  Method *P;
-  if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
-  Value::setName(name);
-  if (P && hasName()) P->getSymbolTable()->insert(this);
+TerminatorInst::TerminatorInst(const Type *Ty, Instruction::TermOps iType,
+                              const std::string &Name)
+  : Instruction(Ty, iType, Name) {
 }
 
 
@@ -37,30 +29,33 @@ void MethodArgument::setName(const string &name) {
 //                               PHINode Class
 //===----------------------------------------------------------------------===//
 
-PHINode::PHINode(const Type *Ty, const string &name) 
+PHINode::PHINode(const Type *Ty, const std::string &name) 
   : Instruction(Ty, Instruction::PHINode, name) {
 }
 
 PHINode::PHINode(const PHINode &PN) 
   : Instruction(PN.getType(), Instruction::PHINode) {
-  
-  for (unsigned i = 0; i < PN.IncomingValues.size(); i++)
-    IncomingValues.push_back(Use(PN.IncomingValues[i], this));
+  Operands.reserve(PN.Operands.size());
+  for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
+    Operands.push_back(Use(PN.Operands[i], this));
+    Operands.push_back(Use(PN.Operands[i+1], this));
+  }
 }
 
-void PHINode::dropAllReferences() {
-  IncomingValues.clear();
+void PHINode::addIncoming(Value *D, BasicBlock *BB) {
+  assert(getType() == D->getType() &&
+         "All operands to PHI node must be the same type as the PHI node!");
+  Operands.push_back(Use(D, this));
+  Operands.push_back(Use(BB, this));
 }
 
-bool PHINode::setOperand(unsigned i, Value *Val) {
-  assert(Val && "PHI node must only reference nonnull definitions!");
-  if (i >= IncomingValues.size()) return false;
-
-  IncomingValues[i] = Val;
-  return true;
-}
-
-void PHINode::addIncoming(Value *D) {
-  IncomingValues.push_back(Use(D, this));
+// removeIncomingValue - Remove an incoming value.  This is useful if a
+// predecessor basic block is deleted.
+Value *PHINode::removeIncomingValue(const BasicBlock *BB) {
+  op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB);
+  assert(Idx != Operands.end() && "BB not in PHI node!");
+  --Idx;  // Back up to value prior to Basic block
+  Value *Removed = *Idx;
+  Operands.erase(Idx, Idx+2);  // Erase Value and BasicBlock
+  return Removed;
 }
-