fix Analysis/BasicAA/2004-12-08-BasicAACrash.ll by allowing opaque types.
[oota-llvm.git] / lib / VMCore / Instructions.cpp
index 473e9fac19c0b4243d224f720e2343355b106430..7f5d4615d187a4de8f8dc108354868d4a6c9cc4b 100644 (file)
@@ -12,7 +12,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/BasicBlock.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
@@ -26,72 +25,77 @@ using namespace llvm;
 //                            CallSite Class
 //===----------------------------------------------------------------------===//
 
+#define CALLSITE_DELEGATE_GETTER(METHOD) \
+  Instruction *II(getInstruction());     \
+  return isCall()                        \
+    ? cast<CallInst>(II)->METHOD         \
+    : cast<InvokeInst>(II)->METHOD
+
+#define CALLSITE_DELEGATE_SETTER(METHOD) \
+  Instruction *II(getInstruction());     \
+  if (isCall())                          \
+    cast<CallInst>(II)->METHOD;          \
+  else                                   \
+    cast<InvokeInst>(II)->METHOD
+
 CallSite::CallSite(Instruction *C) {
   assert((isa<CallInst>(C) || isa<InvokeInst>(C)) && "Not a call!");
-  I = C;
+  I.setPointer(C);
+  I.setInt(isa<CallInst>(C));
 }
 unsigned CallSite::getCallingConv() const {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    return CI->getCallingConv();
-  else
-    return cast<InvokeInst>(I)->getCallingConv();
+  CALLSITE_DELEGATE_GETTER(getCallingConv());
 }
 void CallSite::setCallingConv(unsigned CC) {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    CI->setCallingConv(CC);
-  else
-    cast<InvokeInst>(I)->setCallingConv(CC);
+  CALLSITE_DELEGATE_SETTER(setCallingConv(CC));
 }
-const PAListPtr &CallSite::getParamAttrs() const {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    return CI->getParamAttrs();
-  else
-    return cast<InvokeInst>(I)->getParamAttrs();
+const AttrListPtr &CallSite::getAttributes() const {
+  CALLSITE_DELEGATE_GETTER(getAttributes());
 }
-void CallSite::setParamAttrs(const PAListPtr &PAL) {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    CI->setParamAttrs(PAL);
-  else
-    cast<InvokeInst>(I)->setParamAttrs(PAL);
+void CallSite::setAttributes(const AttrListPtr &PAL) {
+  CALLSITE_DELEGATE_SETTER(setAttributes(PAL));
 }
-bool CallSite::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    return CI->paramHasAttr(i, attr);
-  else
-    return cast<InvokeInst>(I)->paramHasAttr(i, attr);
+bool CallSite::paramHasAttr(uint16_t i, Attributes attr) const {
+  CALLSITE_DELEGATE_GETTER(paramHasAttr(i, attr));
 }
 uint16_t CallSite::getParamAlignment(uint16_t i) const {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    return CI->getParamAlignment(i);
-  else
-    return cast<InvokeInst>(I)->getParamAlignment(i);
+  CALLSITE_DELEGATE_GETTER(getParamAlignment(i));
 }
-
 bool CallSite::doesNotAccessMemory() const {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    return CI->doesNotAccessMemory();
-  else
-    return cast<InvokeInst>(I)->doesNotAccessMemory();
+  CALLSITE_DELEGATE_GETTER(doesNotAccessMemory());
+}
+void CallSite::setDoesNotAccessMemory(bool doesNotAccessMemory) {
+  CALLSITE_DELEGATE_SETTER(setDoesNotAccessMemory(doesNotAccessMemory));
 }
 bool CallSite::onlyReadsMemory() const {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    return CI->onlyReadsMemory();
-  else
-    return cast<InvokeInst>(I)->onlyReadsMemory();
+  CALLSITE_DELEGATE_GETTER(onlyReadsMemory());
+}
+void CallSite::setOnlyReadsMemory(bool onlyReadsMemory) {
+  CALLSITE_DELEGATE_SETTER(setOnlyReadsMemory(onlyReadsMemory));
+}
+bool CallSite::doesNotReturn() const {
+ CALLSITE_DELEGATE_GETTER(doesNotReturn());
+}
+void CallSite::setDoesNotReturn(bool doesNotReturn) {
+  CALLSITE_DELEGATE_SETTER(setDoesNotReturn(doesNotReturn));
 }
 bool CallSite::doesNotThrow() const {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    return CI->doesNotThrow();
-  else
-    return cast<InvokeInst>(I)->doesNotThrow();
+  CALLSITE_DELEGATE_GETTER(doesNotThrow());
 }
 void CallSite::setDoesNotThrow(bool doesNotThrow) {
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    CI->setDoesNotThrow(doesNotThrow);
-  else
-    cast<InvokeInst>(I)->setDoesNotThrow(doesNotThrow);
+  CALLSITE_DELEGATE_SETTER(setDoesNotThrow(doesNotThrow));
+}
+
+bool CallSite::hasArgument(const Value *Arg) const {
+  for (arg_iterator AI = this->arg_begin(), E = this->arg_end(); AI != E; ++AI)
+    if (AI->get() == Arg)
+      return true;
+  return false;
 }
 
+#undef CALLSITE_DELEGATE_GETTER
+#undef CALLSITE_DELEGATE_SETTER
+
 //===----------------------------------------------------------------------===//
 //                            TerminatorInst Class
 //===----------------------------------------------------------------------===//
@@ -108,6 +112,33 @@ TerminatorInst::~TerminatorInst() {
 UnaryInstruction::~UnaryInstruction() {
 }
 
+//===----------------------------------------------------------------------===//
+//                              SelectInst Class
+//===----------------------------------------------------------------------===//
+
+/// areInvalidOperands - Return a string if the specified operands are invalid
+/// for a select operation, otherwise return null.
+const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) {
+  if (Op1->getType() != Op2->getType())
+    return "both values to select must have same type";
+  
+  if (const VectorType *VT = dyn_cast<VectorType>(Op0->getType())) {
+    // Vector select.
+    if (VT->getElementType() != Type::Int1Ty)
+      return "vector select condition element type must be i1";
+    const VectorType *ET = dyn_cast<VectorType>(Op1->getType());
+    if (ET == 0)
+      return "selected values for vector select must be vectors";
+    if (ET->getNumElements() != VT->getNumElements())
+      return "vector select requires selected vectors to have "
+                   "the same vector length as select condition";
+  } else if (Op0->getType() != Type::Int1Ty) {
+    return "select condition must be i1 or <n x i1>";
+  }
+  return 0;
+}
+
+
 //===----------------------------------------------------------------------===//
 //                               PHINode Class
 //===----------------------------------------------------------------------===//
@@ -118,13 +149,14 @@ PHINode::PHINode(const PHINode &PN)
     ReservedSpace(PN.getNumOperands()) {
   Use *OL = OperandList;
   for (unsigned i = 0, e = PN.getNumOperands(); i != e; i+=2) {
-    OL[i].init(PN.getOperand(i), this);
-    OL[i+1].init(PN.getOperand(i+1), this);
+    OL[i] = PN.getOperand(i);
+    OL[i+1] = PN.getOperand(i+1);
   }
 }
 
 PHINode::~PHINode() {
-  dropHungoffUses(OperandList);
+  if (OperandList)
+    dropHungoffUses(OperandList);
 }
 
 // removeIncomingValue - Remove an incoming value.  This is useful if a
@@ -183,9 +215,7 @@ void PHINode::resizeOperands(unsigned NumOps) {
   ReservedSpace = NumOps;
   Use *OldOps = OperandList;
   Use *NewOps = allocHungoffUses(NumOps);
-  for (unsigned i = 0; i != e; ++i) {
-      NewOps[i].init(OldOps[i], this);
-  }
+  std::copy(OldOps, OldOps + e, NewOps);
   OperandList = NewOps;
   if (OldOps) Use::zap(OldOps, OldOps + e, true);
 }
@@ -249,7 +279,7 @@ CallInst::~CallInst() {
 void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
   assert(NumOperands == NumParams+1 && "NumOperands not set up?");
   Use *OL = OperandList;
-  OL[0].init(Func, this);
+  OL[0] = Func;
 
   const FunctionType *FTy =
     cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@@ -262,16 +292,16 @@ void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
     assert((i >= FTy->getNumParams() || 
             FTy->getParamType(i) == Params[i]->getType()) &&
            "Calling a function with a bad signature!");
-    OL[i+1].init(Params[i], this);
+    OL[i+1] = Params[i];
   }
 }
 
 void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
   assert(NumOperands == 3 && "NumOperands not set up?");
   Use *OL = OperandList;
-  OL[0].init(Func, this);
-  OL[1].init(Actual1, this);
-  OL[2].init(Actual2, this);
+  OL[0] = Func;
+  OL[1] = Actual1;
+  OL[2] = Actual2;
 
   const FunctionType *FTy =
     cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@@ -291,8 +321,8 @@ void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
 void CallInst::init(Value *Func, Value *Actual) {
   assert(NumOperands == 2 && "NumOperands not set up?");
   Use *OL = OperandList;
-  OL[0].init(Func, this);
-  OL[1].init(Actual, this);
+  OL[0] = Func;
+  OL[1] = Actual;
 
   const FunctionType *FTy =
     cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@@ -309,7 +339,7 @@ void CallInst::init(Value *Func, Value *Actual) {
 void CallInst::init(Value *Func) {
   assert(NumOperands == 1 && "NumOperands not set up?");
   Use *OL = OperandList;
-  OL[0].init(Func, this);
+  OL[0] = Func;
 
   const FunctionType *FTy =
     cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@@ -365,31 +395,34 @@ CallInst::CallInst(const CallInst &CI)
   : Instruction(CI.getType(), Instruction::Call,
                 OperandTraits<CallInst>::op_end(this) - CI.getNumOperands(),
                 CI.getNumOperands()) {
-  setParamAttrs(CI.getParamAttrs());
+  setAttributes(CI.getAttributes());
   SubclassData = CI.SubclassData;
   Use *OL = OperandList;
   Use *InOL = CI.OperandList;
   for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i)
-    OL[i].init(InOL[i], this);
+    OL[i] = InOL[i];
+}
+
+void CallInst::addAttribute(unsigned i, Attributes attr) {
+  AttrListPtr PAL = getAttributes();
+  PAL = PAL.addAttr(i, attr);
+  setAttributes(PAL);
+}
+
+void CallInst::removeAttribute(unsigned i, Attributes attr) {
+  AttrListPtr PAL = getAttributes();
+  PAL = PAL.removeAttr(i, attr);
+  setAttributes(PAL);
 }
 
-bool CallInst::paramHasAttr(unsigned i, ParameterAttributes attr) const {
-  if (ParamAttrs.paramHasAttr(i, attr))
+bool CallInst::paramHasAttr(unsigned i, Attributes attr) const {
+  if (AttributeList.paramHasAttr(i, attr))
     return true;
   if (const Function *F = getCalledFunction())
     return F->paramHasAttr(i, attr);
   return false;
 }
 
-void CallInst::setDoesNotThrow(bool doesNotThrow) {
-  PAListPtr PAL = getParamAttrs();
-  if (doesNotThrow)
-    PAL = PAL.addAttr(0, ParamAttr::NoUnwind);
-  else
-    PAL = PAL.removeAttr(0, ParamAttr::NoUnwind);
-  setParamAttrs(PAL);
-}
-
 
 //===----------------------------------------------------------------------===//
 //                        InvokeInst Implementation
@@ -399,9 +432,9 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
                       Value* const *Args, unsigned NumArgs) {
   assert(NumOperands == 3+NumArgs && "NumOperands not set up?");
   Use *OL = OperandList;
-  OL[0].init(Fn, this);
-  OL[1].init(IfNormal, this);
-  OL[2].init(IfException, this);
+  OL[0] = Fn;
+  OL[1] = IfNormal;
+  OL[2] = IfException;
   const FunctionType *FTy =
     cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
   FTy = FTy;  // silence warning.
@@ -415,7 +448,7 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
             FTy->getParamType(i) == Args[i]->getType()) &&
            "Invoking a function with a bad signature!");
     
-    OL[i+3].init(Args[i], this);
+    OL[i+3] = Args[i];
   }
 }
 
@@ -424,11 +457,11 @@ InvokeInst::InvokeInst(const InvokeInst &II)
                    OperandTraits<InvokeInst>::op_end(this)
                    - II.getNumOperands(),
                    II.getNumOperands()) {
-  setParamAttrs(II.getParamAttrs());
+  setAttributes(II.getAttributes());
   SubclassData = II.SubclassData;
   Use *OL = OperandList, *InOL = II.OperandList;
   for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i)
-    OL[i].init(InOL[i], this);
+    OL[i] = InOL[i];
 }
 
 BasicBlock *InvokeInst::getSuccessorV(unsigned idx) const {
@@ -441,21 +474,24 @@ void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) {
   return setSuccessor(idx, B);
 }
 
-bool InvokeInst::paramHasAttr(unsigned i, ParameterAttributes attr) const {
-  if (ParamAttrs.paramHasAttr(i, attr))
+bool InvokeInst::paramHasAttr(unsigned i, Attributes attr) const {
+  if (AttributeList.paramHasAttr(i, attr))
     return true;
   if (const Function *F = getCalledFunction())
     return F->paramHasAttr(i, attr);
   return false;
 }
 
-void InvokeInst::setDoesNotThrow(bool doesNotThrow) {
-  PAListPtr PAL = getParamAttrs();
-  if (doesNotThrow)
-    PAL = PAL.addAttr(0, ParamAttr::NoUnwind);
-  else
-    PAL = PAL.removeAttr(0, ParamAttr::NoUnwind);
-  setParamAttrs(PAL);
+void InvokeInst::addAttribute(unsigned i, Attributes attr) {
+  AttrListPtr PAL = getAttributes();
+  PAL = PAL.addAttr(i, attr);
+  setAttributes(PAL);
+}
+
+void InvokeInst::removeAttribute(unsigned i, Attributes attr) {
+  AttrListPtr PAL = getAttributes();
+  PAL = PAL.removeAttr(i, attr);
+  setAttributes(PAL);
 }
 
 
@@ -465,75 +501,30 @@ void InvokeInst::setDoesNotThrow(bool doesNotThrow) {
 
 ReturnInst::ReturnInst(const ReturnInst &RI)
   : TerminatorInst(Type::VoidTy, Instruction::Ret,
-                   OperandTraits<ReturnInst>::op_end(this)
-                   - RI.getNumOperands(),
+                   OperandTraits<ReturnInst>::op_end(this) -
+                     RI.getNumOperands(),
                    RI.getNumOperands()) {
-  unsigned N = RI.getNumOperands();
-  if (N == 1)
-    Op<0>().init(RI.Op<0>(), this);
-  else if (N) {
-    Use *OL = OperandList;
-    for (unsigned i = 0; i < N; ++i)
-      OL[i].init(RI.getOperand(i), this);
-  }
+  if (RI.getNumOperands())
+    Op<0>() = RI.Op<0>();
 }
 
 ReturnInst::ReturnInst(Value *retVal, Instruction *InsertBefore)
   : TerminatorInst(Type::VoidTy, Instruction::Ret,
-                   OperandTraits<ReturnInst>::op_end(this) - (retVal != 0),
-                   retVal != 0, InsertBefore) {
+                   OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
+                   InsertBefore) {
   if (retVal)
-    init(&retVal, 1);
+    Op<0>() = retVal;
 }
 ReturnInst::ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
   : TerminatorInst(Type::VoidTy, Instruction::Ret,
-                   OperandTraits<ReturnInst>::op_end(this) - (retVal != 0),
-                   retVal != 0, InsertAtEnd) {
+                   OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
+                   InsertAtEnd) {
   if (retVal)
-    init(&retVal, 1);
+    Op<0>() = retVal;
 }
 ReturnInst::ReturnInst(BasicBlock *InsertAtEnd)
   : TerminatorInst(Type::VoidTy, Instruction::Ret,
-                   OperandTraits<ReturnInst>::op_end(this),
-                   0, InsertAtEnd) {
-}
-
-ReturnInst::ReturnInst(Value * const* retVals, unsigned N,
-                       Instruction *InsertBefore)
-  : TerminatorInst(Type::VoidTy, Instruction::Ret,
-                   OperandTraits<ReturnInst>::op_end(this) - N,
-                   N, InsertBefore) {
-  if (N != 0)
-    init(retVals, N);
-}
-ReturnInst::ReturnInst(Value * const* retVals, unsigned N,
-                       BasicBlock *InsertAtEnd)
-  : TerminatorInst(Type::VoidTy, Instruction::Ret,
-                   OperandTraits<ReturnInst>::op_end(this) - N,
-                   N, InsertAtEnd) {
-  if (N != 0)
-    init(retVals, N);
-}
-
-void ReturnInst::init(Value * const* retVals, unsigned N) {
-  assert (N > 0 && "Invalid operands numbers in ReturnInst init");
-
-  NumOperands = N;
-  if (NumOperands == 1) {
-    Value *V = *retVals;
-    if (V->getType() == Type::VoidTy)
-      return;
-    Op<0>().init(V, this);
-    return;
-  }
-
-  Use *OL = OperandList;
-  for (unsigned i = 0; i < NumOperands; ++i) {
-    Value *V = *retVals++;
-    assert(!isa<BasicBlock>(V) &&
-           "Cannot return basic block.  Probably using the incorrect ctor");
-    OL[i].init(V, this);
-  }
+                   OperandTraits<ReturnInst>::op_end(this), 0, InsertAtEnd) {
 }
 
 unsigned ReturnInst::getNumSuccessorsV() const {
@@ -621,16 +612,16 @@ BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
                    OperandTraits<BranchInst>::op_end(this) - 1,
                    1, InsertBefore) {
   assert(IfTrue != 0 && "Branch destination may not be null!");
-  Op<0>().init(reinterpret_cast<Value*>(IfTrue), this);
+  Op<0>() = IfTrue;
 }
 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
                        Instruction *InsertBefore)
   : TerminatorInst(Type::VoidTy, Instruction::Br,
                    OperandTraits<BranchInst>::op_end(this) - 3,
                    3, InsertBefore) {
-  Op<0>().init(reinterpret_cast<Value*>(IfTrue), this);
-  Op<1>().init(reinterpret_cast<Value*>(IfFalse), this);
-  Op<2>().init(Cond, this);
+  Op<0>() = IfTrue;
+  Op<1>() = IfFalse;
+  Op<2>() = Cond;
 #ifndef NDEBUG
   AssertOK();
 #endif
@@ -641,7 +632,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
                    OperandTraits<BranchInst>::op_end(this) - 1,
                    1, InsertAtEnd) {
   assert(IfTrue != 0 && "Branch destination may not be null!");
-  Op<0>().init(reinterpret_cast<Value*>(IfTrue), this);
+  Op<0>() = IfTrue;
 }
 
 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
@@ -649,9 +640,9 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
   : TerminatorInst(Type::VoidTy, Instruction::Br,
                    OperandTraits<BranchInst>::op_end(this) - 3,
                    3, InsertAtEnd) {
-  Op<0>().init(reinterpret_cast<Value*>(IfTrue), this);
-  Op<1>().init(reinterpret_cast<Value*>(IfFalse), this);
-  Op<2>().init(Cond, this);
+  Op<0>() = IfTrue;
+  Op<1>() = IfFalse;
+  Op<2>() = Cond;
 #ifndef NDEBUG
   AssertOK();
 #endif
@@ -662,11 +653,11 @@ BranchInst::BranchInst(const BranchInst &BI) :
   TerminatorInst(Type::VoidTy, Instruction::Br,
                  OperandTraits<BranchInst>::op_end(this) - BI.getNumOperands(),
                  BI.getNumOperands()) {
-  OperandList[0].init(BI.getOperand(0), this);
+  OperandList[0] = BI.getOperand(0);
   if (BI.getNumOperands() != 1) {
     assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!");
-    OperandList[1].init(BI.getOperand(1), this);
-    OperandList[2].init(BI.getOperand(2), this);
+    OperandList[1] = BI.getOperand(1);
+    OperandList[2] = BI.getOperand(2);
   }
 }
 
@@ -742,6 +733,18 @@ AllocaInst::AllocaInst(const AllocaInst &AI)
                    Instruction::Alloca, AI.getAlignment()) {
 }
 
+/// isStaticAlloca - Return true if this alloca is in the entry block of the
+/// function and is a constant size.  If so, the code generator will fold it
+/// into the prolog/epilog code, so it is basically free.
+bool AllocaInst::isStaticAlloca() const {
+  // Must be constant size.
+  if (!isa<ConstantInt>(getArraySize())) return false;
+  
+  // Must be in the entry block.
+  const BasicBlock *Parent = getParent();
+  return Parent == &Parent->getParent()->front();
+}
+
 MallocInst::MallocInst(const MallocInst &MI)
   : AllocationInst(MI.getType()->getElementType(), (Value*)MI.getOperand(0),
                    Instruction::Malloc, MI.getAlignment()) {
@@ -884,6 +887,7 @@ void LoadInst::setAlignment(unsigned Align) {
 //===----------------------------------------------------------------------===//
 
 void StoreInst::AssertOK() {
+  assert(getOperand(0) && getOperand(1) && "Both operands must be non-null!");
   assert(isa<PointerType>(getOperand(1)->getType()) &&
          "Ptr must have pointer type!");
   assert(getOperand(0)->getType() ==
@@ -897,8 +901,8 @@ StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore)
                 OperandTraits<StoreInst>::op_begin(this),
                 OperandTraits<StoreInst>::operands(this),
                 InsertBefore) {
-  Op<0>().init(val, this);
-  Op<1>().init(addr, this);
+  Op<0>() = val;
+  Op<1>() = addr;
   setVolatile(false);
   setAlignment(0);
   AssertOK();
@@ -909,8 +913,8 @@ StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)
                 OperandTraits<StoreInst>::op_begin(this),
                 OperandTraits<StoreInst>::operands(this),
                 InsertAtEnd) {
-  Op<0>().init(val, this);
-  Op<1>().init(addr, this);
+  Op<0>() = val;
+  Op<1>() = addr;
   setVolatile(false);
   setAlignment(0);
   AssertOK();
@@ -922,8 +926,8 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
                 OperandTraits<StoreInst>::op_begin(this),
                 OperandTraits<StoreInst>::operands(this),
                 InsertBefore) {
-  Op<0>().init(val, this);
-  Op<1>().init(addr, this);
+  Op<0>() = val;
+  Op<1>() = addr;
   setVolatile(isVolatile);
   setAlignment(0);
   AssertOK();
@@ -935,8 +939,8 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
                 OperandTraits<StoreInst>::op_begin(this),
                 OperandTraits<StoreInst>::operands(this),
                 InsertBefore) {
-  Op<0>().init(val, this);
-  Op<1>().init(addr, this);
+  Op<0>() = val;
+  Op<1>() = addr;
   setVolatile(isVolatile);
   setAlignment(Align);
   AssertOK();
@@ -948,8 +952,8 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
                 OperandTraits<StoreInst>::op_begin(this),
                 OperandTraits<StoreInst>::operands(this),
                 InsertAtEnd) {
-  Op<0>().init(val, this);
-  Op<1>().init(addr, this);
+  Op<0>() = val;
+  Op<1>() = addr;
   setVolatile(isVolatile);
   setAlignment(Align);
   AssertOK();
@@ -961,8 +965,8 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
                 OperandTraits<StoreInst>::op_begin(this),
                 OperandTraits<StoreInst>::operands(this),
                 InsertAtEnd) {
-  Op<0>().init(val, this);
-  Op<1>().init(addr, this);
+  Op<0>() = val;
+  Op<1>() = addr;
   setVolatile(isVolatile);
   setAlignment(0);
   AssertOK();
@@ -981,31 +985,36 @@ static unsigned retrieveAddrSpace(const Value *Val) {
   return cast<PointerType>(Val->getType())->getAddressSpace();
 }
 
-void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
+void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
+                             const std::string &Name) {
   assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
   Use *OL = OperandList;
-  OL[0].init(Ptr, this);
+  OL[0] = Ptr;
 
   for (unsigned i = 0; i != NumIdx; ++i)
-    OL[i+1].init(Idx[i], this);
+    OL[i+1] = Idx[i];
+
+  setName(Name);
 }
 
-void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
+void GetElementPtrInst::init(Value *Ptr, Value *Idx, const std::string &Name) {
   assert(NumOperands == 2 && "NumOperands not initialized?");
   Use *OL = OperandList;
-  OL[0].init(Ptr, this);
-  OL[1].init(Idx, this);
+  OL[0] = Ptr;
+  OL[1] = Idx;
+
+  setName(Name);
 }
 
 GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
-  : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
+  : Instruction(GEPI.getType(), GetElementPtr,
                 OperandTraits<GetElementPtrInst>::op_end(this)
                 - GEPI.getNumOperands(),
                 GEPI.getNumOperands()) {
   Use *OL = OperandList;
   Use *GEPIOL = GEPI.OperandList;
   for (unsigned i = 0, E = NumOperands; i != E; ++i)
-    OL[i].init(GEPIOL[i], this);
+    OL[i] = GEPIOL[i];
 }
 
 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
@@ -1015,8 +1024,7 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
                 GetElementPtr,
                 OperandTraits<GetElementPtrInst>::op_end(this) - 2,
                 2, InBe) {
-  init(Ptr, Idx);
-  setName(Name);
+  init(Ptr, Idx, Name);
 }
 
 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
@@ -1026,53 +1034,64 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
                 GetElementPtr,
                 OperandTraits<GetElementPtrInst>::op_end(this) - 2,
                 2, IAE) {
-  init(Ptr, Idx);
-  setName(Name);
+  init(Ptr, Idx, Name);
 }
 
-// getIndexedType - Returns the type of the element that would be loaded with
-// a load instruction with the specified parameters.
-//
-// A null type is returned if the indices are invalid for the specified
-// pointer type.
-//
-const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
-                                              Value* const *Idxs,
-                                              unsigned NumIdx,
-                                              bool AllowCompositeLeaf) {
-  if (!isa<PointerType>(Ptr)) return 0;   // Type isn't a pointer type!
-
-  // Handle the special case of the empty set index set...
-  if (NumIdx == 0) {
-    if (AllowCompositeLeaf ||
-        cast<PointerType>(Ptr)->getElementType()->isFirstClassType())
-      return cast<PointerType>(Ptr)->getElementType();
-    else
-      return 0;
-  }
-
-  unsigned CurIdx = 0;
-  while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
-    if (NumIdx == CurIdx) {
-      if (AllowCompositeLeaf || CT->isFirstClassType()) return Ptr;
-      return 0;   // Can't load a whole structure or array!?!?
-    }
+/// getIndexedType - Returns the type of the element that would be accessed with
+/// a gep instruction with the specified parameters.
+///
+/// The Idxs pointer should point to a continuous piece of memory containing the
+/// indices, either as Value* or uint64_t.
+///
+/// A null type is returned if the indices are invalid for the specified
+/// pointer type.
+///
+template <typename IndexTy>
+static const Type* getIndexedTypeInternal(const Type *Ptr, IndexTy const *Idxs,
+                                          unsigned NumIdx) {
+  const PointerType *PTy = dyn_cast<PointerType>(Ptr);
+  if (!PTy) return 0;   // Type isn't a pointer type!
+  const Type *Agg = PTy->getElementType();
 
-    Value *Index = Idxs[CurIdx++];
-    if (isa<PointerType>(CT) && CurIdx != 1)
-      return 0;  // Can only index into pointer types at the first index!
+  // Handle the special case of the empty set index set, which is always valid.
+  if (NumIdx == 0)
+    return Agg;
+  
+  // If there is at least one index, the top level type must be sized, otherwise
+  // it cannot be 'stepped over'.  We explicitly allow abstract types (those
+  // that contain opaque types) under the assumption that it will be resolved to
+  // a sane type later.
+  if (!Agg->isSized() && !Agg->isAbstract())
+    return 0;
+
+  unsigned CurIdx = 1;
+  for (; CurIdx != NumIdx; ++CurIdx) {
+    const CompositeType *CT = dyn_cast<CompositeType>(Agg);
+    if (!CT || isa<PointerType>(CT)) return 0;
+    IndexTy Index = Idxs[CurIdx];
     if (!CT->indexValid(Index)) return 0;
-    Ptr = CT->getTypeAtIndex(Index);
+    Agg = CT->getTypeAtIndex(Index);
 
     // If the new type forwards to another type, then it is in the middle
     // of being refined to another type (and hence, may have dropped all
     // references to what it was using before).  So, use the new forwarded
     // type.
-    if (const Type * Ty = Ptr->getForwardedType()) {
-      Ptr = Ty;
-    }
+    if (const Type *Ty = Agg->getForwardedType())
+      Agg = Ty;
   }
-  return CurIdx == NumIdx ? Ptr : 0;
+  return CurIdx == NumIdx ? Agg : 0;
+}
+
+const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
+                                              Value* const *Idxs,
+                                              unsigned NumIdx) {
+  return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
+}
+
+const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
+                                              uint64_t const *Idxs,
+                                              unsigned NumIdx) {
+  return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
 }
 
 const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
@@ -1125,8 +1144,8 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
                 2, InsertBef) {
   assert(isValidOperands(Val, Index) &&
          "Invalid extractelement instruction operands!");
-  Op<0>().init(Val, this);
-  Op<1>().init(Index, this);
+  Op<0>() = Val;
+  Op<1>() = Index;
   setName(Name);
 }
 
@@ -1140,8 +1159,8 @@ ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
   Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
   assert(isValidOperands(Val, Index) &&
          "Invalid extractelement instruction operands!");
-  Op<0>().init(Val, this);
-  Op<1>().init(Index, this);
+  Op<0>() = Val;
+  Op<1>() = Index;
   setName(Name);
 }
 
@@ -1156,8 +1175,8 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
   assert(isValidOperands(Val, Index) &&
          "Invalid extractelement instruction operands!");
 
-  Op<0>().init(Val, this);
-  Op<1>().init(Index, this);
+  Op<0>() = Val;
+  Op<1>() = Index;
   setName(Name);
 }
 
@@ -1172,8 +1191,8 @@ ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
   assert(isValidOperands(Val, Index) &&
          "Invalid extractelement instruction operands!");
   
-  Op<0>().init(Val, this);
-  Op<1>().init(Index, this);
+  Op<0>() = Val;
+  Op<1>() = Index;
   setName(Name);
 }
 
@@ -1192,9 +1211,9 @@ bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
 InsertElementInst::InsertElementInst(const InsertElementInst &IE)
     : Instruction(IE.getType(), InsertElement,
                   OperandTraits<InsertElementInst>::op_begin(this), 3) {
-  Op<0>().init(IE.Op<0>(), this);
-  Op<1>().init(IE.Op<1>(), this);
-  Op<2>().init(IE.Op<2>(), this);
+  Op<0>() = IE.Op<0>();
+  Op<1>() = IE.Op<1>();
+  Op<2>() = IE.Op<2>();
 }
 InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
                                      const std::string &Name,
@@ -1204,9 +1223,9 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
                 3, InsertBef) {
   assert(isValidOperands(Vec, Elt, Index) &&
          "Invalid insertelement instruction operands!");
-  Op<0>().init(Vec, this);
-  Op<1>().init(Elt, this);
-  Op<2>().init(Index, this);
+  Op<0>() = Vec;
+  Op<1>() = Elt;
+  Op<2>() = Index;
   setName(Name);
 }
 
@@ -1219,9 +1238,9 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
   Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
   assert(isValidOperands(Vec, Elt, Index) &&
          "Invalid insertelement instruction operands!");
-  Op<0>().init(Vec, this);
-  Op<1>().init(Elt, this);
-  Op<2>().init(Index, this);
+  Op<0>() = Vec;
+  Op<1>() = Elt;
+  Op<2>() = Index;
   setName(Name);
 }
 
@@ -1235,9 +1254,9 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
   assert(isValidOperands(Vec, Elt, Index) &&
          "Invalid insertelement instruction operands!");
 
-  Op<0>().init(Vec, this);
-  Op<1>().init(Elt, this);
-  Op<2>().init(Index, this);
+  Op<0>() = Vec;
+  Op<1>() = Elt;
+  Op<2>() = Index;
   setName(Name);
 }
 
@@ -1251,9 +1270,9 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
   assert(isValidOperands(Vec, Elt, Index) &&
          "Invalid insertelement instruction operands!");
   
-  Op<0>().init(Vec, this);
-  Op<1>().init(Elt, this);
-  Op<2>().init(Index, this);
+  Op<0>() = Vec;
+  Op<1>() = Elt;
+  Op<2>() = Index;
   setName(Name);
 }
 
@@ -1279,28 +1298,30 @@ ShuffleVectorInst::ShuffleVectorInst(const ShuffleVectorInst &SV)
   : Instruction(SV.getType(), ShuffleVector,
                 OperandTraits<ShuffleVectorInst>::op_begin(this),
                 OperandTraits<ShuffleVectorInst>::operands(this)) {
-  Op<0>().init(SV.Op<0>(), this);
-  Op<1>().init(SV.Op<1>(), this);
-  Op<2>().init(SV.Op<2>(), this);
+  Op<0>() = SV.Op<0>();
+  Op<1>() = SV.Op<1>();
+  Op<2>() = SV.Op<2>();
 }
 
 ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
                                      const std::string &Name,
                                      Instruction *InsertBefore)
-  : Instruction(V1->getType(), ShuffleVector,
-                OperandTraits<ShuffleVectorInst>::op_begin(this),
-                OperandTraits<ShuffleVectorInst>::operands(this),
-                InsertBefore) {
+: Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
+                cast<VectorType>(Mask->getType())->getNumElements()),
+              ShuffleVector,
+              OperandTraits<ShuffleVectorInst>::op_begin(this),
+              OperandTraits<ShuffleVectorInst>::operands(this),
+              InsertBefore) {
   assert(isValidOperands(V1, V2, Mask) &&
          "Invalid shuffle vector instruction operands!");
-  Op<0>().init(V1, this);
-  Op<1>().init(V2, this);
-  Op<2>().init(Mask, this);
+  Op<0>() = V1;
+  Op<1>() = V2;
+  Op<2>() = Mask;
   setName(Name);
 }
 
 ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
-                                     const std::string &Name, 
+                                     const std::string &Name,
                                      BasicBlock *InsertAtEnd)
   : Instruction(V1->getType(), ShuffleVector,
                 OperandTraits<ShuffleVectorInst>::op_begin(this),
@@ -1309,23 +1330,20 @@ ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
   assert(isValidOperands(V1, V2, Mask) &&
          "Invalid shuffle vector instruction operands!");
 
-  Op<0>().init(V1, this);
-  Op<1>().init(V2, this);
-  Op<2>().init(Mask, this);
+  Op<0>() = V1;
+  Op<1>() = V2;
+  Op<2>() = Mask;
   setName(Name);
 }
 
-bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2, 
+bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
                                         const Value *Mask) {
-  if (!isa<VectorType>(V1->getType()) || 
-      V1->getType() != V2->getType()) 
+  if (!isa<VectorType>(V1->getType()) || V1->getType() != V2->getType())
     return false;
   
   const VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType());
   if (!isa<Constant>(Mask) || MaskTy == 0 ||
-      MaskTy->getElementType() != Type::Int32Ty ||
-      MaskTy->getNumElements() != 
-      cast<VectorType>(V1->getType())->getNumElements())
+      MaskTy->getElementType() != Type::Int32Ty)
     return false;
   return true;
 }
@@ -1345,6 +1363,115 @@ int ShuffleVectorInst::getMaskValue(unsigned i) const {
   return cast<ConstantInt>(MaskCV->getOperand(i))->getZExtValue();
 }
 
+//===----------------------------------------------------------------------===//
+//                             InsertValueInst Class
+//===----------------------------------------------------------------------===//
+
+void InsertValueInst::init(Value *Agg, Value *Val, const unsigned *Idx, 
+                           unsigned NumIdx, const std::string &Name) {
+  assert(NumOperands == 2 && "NumOperands not initialized?");
+  Op<0>() = Agg;
+  Op<1>() = Val;
+
+  Indices.insert(Indices.end(), Idx, Idx + NumIdx);
+  setName(Name);
+}
+
+void InsertValueInst::init(Value *Agg, Value *Val, unsigned Idx, 
+                           const std::string &Name) {
+  assert(NumOperands == 2 && "NumOperands not initialized?");
+  Op<0>() = Agg;
+  Op<1>() = Val;
+
+  Indices.push_back(Idx);
+  setName(Name);
+}
+
+InsertValueInst::InsertValueInst(const InsertValueInst &IVI)
+  : Instruction(IVI.getType(), InsertValue,
+                OperandTraits<InsertValueInst>::op_begin(this), 2),
+    Indices(IVI.Indices) {
+  Op<0>() = IVI.getOperand(0);
+  Op<1>() = IVI.getOperand(1);
+}
+
+InsertValueInst::InsertValueInst(Value *Agg,
+                                 Value *Val,
+                                 unsigned Idx, 
+                                 const std::string &Name,
+                                 Instruction *InsertBefore)
+  : Instruction(Agg->getType(), InsertValue,
+                OperandTraits<InsertValueInst>::op_begin(this),
+                2, InsertBefore) {
+  init(Agg, Val, Idx, Name);
+}
+
+InsertValueInst::InsertValueInst(Value *Agg,
+                                 Value *Val,
+                                 unsigned Idx, 
+                                 const std::string &Name,
+                                 BasicBlock *InsertAtEnd)
+  : Instruction(Agg->getType(), InsertValue,
+                OperandTraits<InsertValueInst>::op_begin(this),
+                2, InsertAtEnd) {
+  init(Agg, Val, Idx, Name);
+}
+
+//===----------------------------------------------------------------------===//
+//                             ExtractValueInst Class
+//===----------------------------------------------------------------------===//
+
+void ExtractValueInst::init(const unsigned *Idx, unsigned NumIdx,
+                            const std::string &Name) {
+  assert(NumOperands == 1 && "NumOperands not initialized?");
+
+  Indices.insert(Indices.end(), Idx, Idx + NumIdx);
+  setName(Name);
+}
+
+void ExtractValueInst::init(unsigned Idx, const std::string &Name) {
+  assert(NumOperands == 1 && "NumOperands not initialized?");
+
+  Indices.push_back(Idx);
+  setName(Name);
+}
+
+ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
+  : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)),
+    Indices(EVI.Indices) {
+}
+
+// getIndexedType - Returns the type of the element that would be extracted
+// with an extractvalue instruction with the specified parameters.
+//
+// A null type is returned if the indices are invalid for the specified
+// pointer type.
+//
+const Type* ExtractValueInst::getIndexedType(const Type *Agg,
+                                             const unsigned *Idxs,
+                                             unsigned NumIdx) {
+  unsigned CurIdx = 0;
+  for (; CurIdx != NumIdx; ++CurIdx) {
+    const CompositeType *CT = dyn_cast<CompositeType>(Agg);
+    if (!CT || isa<PointerType>(CT) || isa<VectorType>(CT)) return 0;
+    unsigned Index = Idxs[CurIdx];
+    if (!CT->indexValid(Index)) return 0;
+    Agg = CT->getTypeAtIndex(Index);
+
+    // If the new type forwards to another type, then it is in the middle
+    // of being refined to another type (and hence, may have dropped all
+    // references to what it was using before).  So, use the new forwarded
+    // type.
+    if (const Type *Ty = Agg->getForwardedType())
+      Agg = Ty;
+  }
+  return CurIdx == NumIdx ? Agg : 0;
+}
+
+const Type* ExtractValueInst::getIndexedType(const Type *Agg,
+                                             unsigned Idx) {
+  return getIndexedType(Agg, &Idx, 1);
+}
 
 //===----------------------------------------------------------------------===//
 //                             BinaryOperator Class
@@ -1357,8 +1484,8 @@ BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
                 OperandTraits<BinaryOperator>::op_begin(this),
                 OperandTraits<BinaryOperator>::operands(this),
                 InsertBefore) {
-  Op<0>().init(S1, this);
-  Op<1>().init(S2, this);
+  Op<0>() = S1;
+  Op<1>() = S2;
   init(iType);
   setName(Name);
 }
@@ -1370,8 +1497,8 @@ BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
                 OperandTraits<BinaryOperator>::op_begin(this),
                 OperandTraits<BinaryOperator>::operands(this),
                 InsertAtEnd) {
-  Op<0>().init(S1, this);
-  Op<1>().init(S2, this);
+  Op<0>() = S1;
+  Op<1>() = S2;
   init(iType);
   setName(Name);
 }
@@ -1427,8 +1554,10 @@ void BinaryOperator::init(BinaryOps iType) {
   case AShr:
     assert(getType() == LHS->getType() &&
            "Shift operation should return same type as operands!");
-    assert(getType()->isInteger() && 
-           "Shift operation requires integer operands");
+    assert((getType()->isInteger() ||
+            (isa<VectorType>(getType()) && 
+             cast<VectorType>(getType())->getElementType()->isInteger())) &&
+           "Tried to create a shift operation on a non-integral type!");
     break;
   case And: case Or:
   case Xor:
@@ -1445,7 +1574,7 @@ void BinaryOperator::init(BinaryOps iType) {
 #endif
 }
 
-BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
+BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
                                        const std::string &Name,
                                        Instruction *InsertBefore) {
   assert(S1->getType() == S2->getType() &&
@@ -1453,15 +1582,15 @@ BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
   return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
 }
 
-BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
+BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
                                        const std::string &Name,
                                        BasicBlock *InsertAtEnd) {
-  BinaryOperator *Res = create(Op, S1, S2, Name);
+  BinaryOperator *Res = Create(Op, S1, S2, Name);
   InsertAtEnd->getInstList().push_back(Res);
   return Res;
 }
 
-BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const std::string &Name,
                                           Instruction *InsertBefore) {
   Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType());
   return new BinaryOperator(Instruction::Sub,
@@ -1469,7 +1598,7 @@ BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
                             Op->getType(), Name, InsertBefore);
 }
 
-BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const std::string &Name,
                                           BasicBlock *InsertAtEnd) {
   Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType());
   return new BinaryOperator(Instruction::Sub,
@@ -1477,7 +1606,7 @@ BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
                             Op->getType(), Name, InsertAtEnd);
 }
 
-BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNot(Value *Op, const std::string &Name,
                                           Instruction *InsertBefore) {
   Constant *C;
   if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
@@ -1491,7 +1620,7 @@ BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
                             Op->getType(), Name, InsertBefore);
 }
 
-BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNot(Value *Op, const std::string &Name,
                                           BasicBlock *InsertAtEnd) {
   Constant *AllOnes;
   if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
@@ -1796,7 +1925,7 @@ unsigned CastInst::isEliminableCastPair(
   return 0;
 }
 
-CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty, 
+CastInst *CastInst::Create(Instruction::CastOps op, Value *S, const Type *Ty, 
   const std::string &Name, Instruction *InsertBefore) {
   // Construct and return the appropriate CastInst subclass
   switch (op) {
@@ -1818,7 +1947,7 @@ CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty,
   return 0;
 }
 
-CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty,
+CastInst *CastInst::Create(Instruction::CastOps op, Value *S, const Type *Ty,
   const std::string &Name, BasicBlock *InsertAtEnd) {
   // Construct and return the appropriate CastInst subclass
   switch (op) {
@@ -1840,55 +1969,55 @@ CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty,
   return 0;
 }
 
-CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty, 
+CastInst *CastInst::CreateZExtOrBitCast(Value *S, const Type *Ty, 
                                         const std::string &Name,
                                         Instruction *InsertBefore) {
   if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
-    return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
-  return create(Instruction::ZExt, S, Ty, Name, InsertBefore);
+    return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+  return Create(Instruction::ZExt, S, Ty, Name, InsertBefore);
 }
 
-CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty, 
+CastInst *CastInst::CreateZExtOrBitCast(Value *S, const Type *Ty, 
                                         const std::string &Name,
                                         BasicBlock *InsertAtEnd) {
   if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
-    return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
-  return create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
+    return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+  return Create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
 }
 
-CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty, 
+CastInst *CastInst::CreateSExtOrBitCast(Value *S, const Type *Ty, 
                                         const std::string &Name,
                                         Instruction *InsertBefore) {
   if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
-    return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
-  return create(Instruction::SExt, S, Ty, Name, InsertBefore);
+    return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+  return Create(Instruction::SExt, S, Ty, Name, InsertBefore);
 }
 
-CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty, 
+CastInst *CastInst::CreateSExtOrBitCast(Value *S, const Type *Ty, 
                                         const std::string &Name,
                                         BasicBlock *InsertAtEnd) {
   if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
-    return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
-  return create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
+    return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+  return Create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
 }
 
-CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreateTruncOrBitCast(Value *S, const Type *Ty,
                                          const std::string &Name,
                                          Instruction *InsertBefore) {
   if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
-    return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
-  return create(Instruction::Trunc, S, Ty, Name, InsertBefore);
+    return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+  return Create(Instruction::Trunc, S, Ty, Name, InsertBefore);
 }
 
-CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreateTruncOrBitCast(Value *S, const Type *Ty,
                                          const std::string &Name, 
                                          BasicBlock *InsertAtEnd) {
   if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
-    return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
-  return create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
+    return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+  return Create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
 }
 
-CastInst *CastInst::createPointerCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreatePointerCast(Value *S, const Type *Ty,
                                       const std::string &Name,
                                       BasicBlock *InsertAtEnd) {
   assert(isa<PointerType>(S->getType()) && "Invalid cast");
@@ -1896,12 +2025,12 @@ CastInst *CastInst::createPointerCast(Value *S, const Type *Ty,
          "Invalid cast");
 
   if (Ty->isInteger())
-    return create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
-  return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+    return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
+  return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
 }
 
 /// @brief Create a BitCast or a PtrToInt cast instruction
-CastInst *CastInst::createPointerCast(Value *S, const Type *Ty, 
+CastInst *CastInst::CreatePointerCast(Value *S, const Type *Ty, 
                                       const std::string &Name, 
                                       Instruction *InsertBefore) {
   assert(isa<PointerType>(S->getType()) && "Invalid cast");
@@ -1909,11 +2038,11 @@ CastInst *CastInst::createPointerCast(Value *S, const Type *Ty,
          "Invalid cast");
 
   if (Ty->isInteger())
-    return create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
-  return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+    return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
+  return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
 }
 
-CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty, 
+CastInst *CastInst::CreateIntegerCast(Value *C, const Type *Ty, 
                                       bool isSigned, const std::string &Name,
                                       Instruction *InsertBefore) {
   assert(C->getType()->isInteger() && Ty->isInteger() && "Invalid cast");
@@ -1923,10 +2052,10 @@ CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty,
     (SrcBits == DstBits ? Instruction::BitCast :
      (SrcBits > DstBits ? Instruction::Trunc :
       (isSigned ? Instruction::SExt : Instruction::ZExt)));
-  return create(opcode, C, Ty, Name, InsertBefore);
+  return Create(opcode, C, Ty, Name, InsertBefore);
 }
 
-CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty, 
+CastInst *CastInst::CreateIntegerCast(Value *C, const Type *Ty, 
                                       bool isSigned, const std::string &Name,
                                       BasicBlock *InsertAtEnd) {
   assert(C->getType()->isInteger() && Ty->isInteger() && "Invalid cast");
@@ -1936,10 +2065,10 @@ CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty,
     (SrcBits == DstBits ? Instruction::BitCast :
      (SrcBits > DstBits ? Instruction::Trunc :
       (isSigned ? Instruction::SExt : Instruction::ZExt)));
-  return create(opcode, C, Ty, Name, InsertAtEnd);
+  return Create(opcode, C, Ty, Name, InsertAtEnd);
 }
 
-CastInst *CastInst::createFPCast(Value *C, const Type *Ty, 
+CastInst *CastInst::CreateFPCast(Value *C, const Type *Ty, 
                                  const std::string &Name, 
                                  Instruction *InsertBefore) {
   assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() && 
@@ -1949,10 +2078,10 @@ CastInst *CastInst::createFPCast(Value *C, const Type *Ty,
   Instruction::CastOps opcode =
     (SrcBits == DstBits ? Instruction::BitCast :
      (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
-  return create(opcode, C, Ty, Name, InsertBefore);
+  return Create(opcode, C, Ty, Name, InsertBefore);
 }
 
-CastInst *CastInst::createFPCast(Value *C, const Type *Ty, 
+CastInst *CastInst::CreateFPCast(Value *C, const Type *Ty, 
                                  const std::string &Name, 
                                  BasicBlock *InsertAtEnd) {
   assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() && 
@@ -1962,7 +2091,7 @@ CastInst *CastInst::createFPCast(Value *C, const Type *Ty,
   Instruction::CastOps opcode =
     (SrcBits == DstBits ? Instruction::BitCast :
      (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
-  return create(opcode, C, Ty, Name, InsertAtEnd);
+  return Create(opcode, C, Ty, Name, InsertAtEnd);
 }
 
 // Check whether it is valid to call getCastOpcode for these types.
@@ -2061,6 +2190,7 @@ CastInst::getCastOpcode(
     } else if (const VectorType *PTy = dyn_cast<VectorType>(SrcTy)) {
       assert(DestBits == PTy->getBitWidth() &&
                "Casting vector to integer of different width");
+      PTy = NULL;
       return BitCast;                             // Same size, no-op cast
     } else {
       assert(isa<PointerType>(SrcTy) &&
@@ -2084,7 +2214,8 @@ CastInst::getCastOpcode(
     } else if (const VectorType *PTy = dyn_cast<VectorType>(SrcTy)) {
       assert(DestBits == PTy->getBitWidth() &&
              "Casting vector to floating point of different width");
-        return BitCast;                             // same size, no-op cast
+      PTy = NULL;
+      return BitCast;                             // same size, no-op cast
     } else {
       assert(0 && "Casting pointer or non-first class to float");
     }
@@ -2092,6 +2223,7 @@ CastInst::getCastOpcode(
     if (const VectorType *SrcPTy = dyn_cast<VectorType>(SrcTy)) {
       assert(DestPTy->getBitWidth() == SrcPTy->getBitWidth() &&
              "Casting vector to vector of different widths");
+      SrcPTy = NULL;
       return BitCast;                             // vector -> vector
     } else if (DestPTy->getBitWidth() == SrcBits) {
       return BitCast;                               // float/int -> vector
@@ -2140,37 +2272,42 @@ CastInst::castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy) {
   switch (op) {
   default: return false; // This is an input error
   case Instruction::Trunc:
-    return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize > DstBitSize;
+    return SrcTy->isIntOrIntVector() &&
+           DstTy->isIntOrIntVector()&& SrcBitSize > DstBitSize;
   case Instruction::ZExt:
-    return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize < DstBitSize;
+    return SrcTy->isIntOrIntVector() &&
+           DstTy->isIntOrIntVector()&& SrcBitSize < DstBitSize;
   case Instruction::SExt: 
-    return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize < DstBitSize;
+    return SrcTy->isIntOrIntVector() &&
+           DstTy->isIntOrIntVector()&& SrcBitSize < DstBitSize;
   case Instruction::FPTrunc:
-    return SrcTy->isFloatingPoint() && DstTy->isFloatingPoint() && 
-      SrcBitSize > DstBitSize;
+    return SrcTy->isFPOrFPVector() &&
+           DstTy->isFPOrFPVector() && 
+           SrcBitSize > DstBitSize;
   case Instruction::FPExt:
-    return SrcTy->isFloatingPoint() && DstTy->isFloatingPoint() && 
-      SrcBitSize < DstBitSize;
+    return SrcTy->isFPOrFPVector() &&
+           DstTy->isFPOrFPVector() && 
+           SrcBitSize < DstBitSize;
   case Instruction::UIToFP:
   case Instruction::SIToFP:
     if (const VectorType *SVTy = dyn_cast<VectorType>(SrcTy)) {
       if (const VectorType *DVTy = dyn_cast<VectorType>(DstTy)) {
-        return SVTy->getElementType()->isInteger() &&
-               DVTy->getElementType()->isFloatingPoint() &&
+        return SVTy->getElementType()->isIntOrIntVector() &&
+               DVTy->getElementType()->isFPOrFPVector() &&
                SVTy->getNumElements() == DVTy->getNumElements();
       }
     }
-    return SrcTy->isInteger() && DstTy->isFloatingPoint();
+    return SrcTy->isIntOrIntVector() && DstTy->isFPOrFPVector();
   case Instruction::FPToUI:
   case Instruction::FPToSI:
     if (const VectorType *SVTy = dyn_cast<VectorType>(SrcTy)) {
       if (const VectorType *DVTy = dyn_cast<VectorType>(DstTy)) {
-        return SVTy->getElementType()->isFloatingPoint() &&
-               DVTy->getElementType()->isInteger() &&
+        return SVTy->getElementType()->isFPOrFPVector() &&
+               DVTy->getElementType()->isIntOrIntVector() &&
                SVTy->getNumElements() == DVTy->getNumElements();
       }
     }
-    return SrcTy->isFloatingPoint() && DstTy->isInteger();
+    return SrcTy->isFPOrFPVector() && DstTy->isIntOrIntVector();
   case Instruction::PtrToInt:
     return isa<PointerType>(SrcTy) && DstTy->isInteger();
   case Instruction::IntToPtr:
@@ -2342,8 +2479,8 @@ CmpInst::CmpInst(const Type *ty, OtherOps op, unsigned short predicate,
                 OperandTraits<CmpInst>::op_begin(this),
                 OperandTraits<CmpInst>::operands(this),
                 InsertBefore) {
-    Op<0>().init(LHS, this);
-    Op<1>().init(RHS, this);
+    Op<0>() = LHS;
+    Op<1>() = RHS;
   SubclassData = predicate;
   setName(Name);
 }
@@ -2355,14 +2492,14 @@ CmpInst::CmpInst(const Type *ty, OtherOps op, unsigned short predicate,
                 OperandTraits<CmpInst>::op_begin(this),
                 OperandTraits<CmpInst>::operands(this),
                 InsertAtEnd) {
-  Op<0>().init(LHS, this);
-  Op<1>().init(RHS, this);
+  Op<0>() = LHS;
+  Op<1>() = RHS;
   SubclassData = predicate;
   setName(Name);
 }
 
 CmpInst *
-CmpInst::create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, 
+CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, 
                 const std::string &Name, Instruction *InsertBefore) {
   if (Op == Instruction::ICmp) {
     return new ICmpInst(CmpInst::Predicate(predicate), S1, S2, Name, 
@@ -2381,7 +2518,7 @@ CmpInst::create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
 }
 
 CmpInst *
-CmpInst::create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, 
+CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, 
                 const std::string &Name, BasicBlock *InsertAtEnd) {
   if (Op == Instruction::ICmp) {
     return new ICmpInst(CmpInst::Predicate(predicate), S1, S2, Name, 
@@ -2419,10 +2556,9 @@ bool CmpInst::isEquality() {
 }
 
 
-ICmpInst::Predicate ICmpInst::getInversePredicate(Predicate pred) {
+CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
   switch (pred) {
-    default:
-      assert(!"Unknown icmp predicate!");
+    default: assert(!"Unknown cmp predicate!");
     case ICMP_EQ: return ICMP_NE;
     case ICMP_NE: return ICMP_EQ;
     case ICMP_UGT: return ICMP_ULE;
@@ -2433,22 +2569,23 @@ ICmpInst::Predicate ICmpInst::getInversePredicate(Predicate pred) {
     case ICMP_SLT: return ICMP_SGE;
     case ICMP_SGE: return ICMP_SLT;
     case ICMP_SLE: return ICMP_SGT;
-  }
-}
 
-ICmpInst::Predicate ICmpInst::getSwappedPredicate(Predicate pred) {
-  switch (pred) {
-    default: assert(! "Unknown icmp predicate!");
-    case ICMP_EQ: case ICMP_NE:
-      return pred;
-    case ICMP_SGT: return ICMP_SLT;
-    case ICMP_SLT: return ICMP_SGT;
-    case ICMP_SGE: return ICMP_SLE;
-    case ICMP_SLE: return ICMP_SGE;
-    case ICMP_UGT: return ICMP_ULT;
-    case ICMP_ULT: return ICMP_UGT;
-    case ICMP_UGE: return ICMP_ULE;
-    case ICMP_ULE: return ICMP_UGE;
+    case FCMP_OEQ: return FCMP_UNE;
+    case FCMP_ONE: return FCMP_UEQ;
+    case FCMP_OGT: return FCMP_ULE;
+    case FCMP_OLT: return FCMP_UGE;
+    case FCMP_OGE: return FCMP_ULT;
+    case FCMP_OLE: return FCMP_UGT;
+    case FCMP_UEQ: return FCMP_ONE;
+    case FCMP_UNE: return FCMP_OEQ;
+    case FCMP_UGT: return FCMP_OLE;
+    case FCMP_ULT: return FCMP_OGE;
+    case FCMP_UGE: return FCMP_OLT;
+    case FCMP_ULE: return FCMP_OGT;
+    case FCMP_ORD: return FCMP_UNO;
+    case FCMP_UNO: return FCMP_ORD;
+    case FCMP_TRUE: return FCMP_FALSE;
+    case FCMP_FALSE: return FCMP_TRUE;
   }
 }
 
@@ -2524,32 +2661,20 @@ ICmpInst::makeConstantRange(Predicate pred, const APInt &C) {
   return ConstantRange(Lower, Upper);
 }
 
-FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) {
-  switch (pred) {
-    default:
-      assert(!"Unknown icmp predicate!");
-    case FCMP_OEQ: return FCMP_UNE;
-    case FCMP_ONE: return FCMP_UEQ;
-    case FCMP_OGT: return FCMP_ULE;
-    case FCMP_OLT: return FCMP_UGE;
-    case FCMP_OGE: return FCMP_ULT;
-    case FCMP_OLE: return FCMP_UGT;
-    case FCMP_UEQ: return FCMP_ONE;
-    case FCMP_UNE: return FCMP_OEQ;
-    case FCMP_UGT: return FCMP_OLE;
-    case FCMP_ULT: return FCMP_OGE;
-    case FCMP_UGE: return FCMP_OLT;
-    case FCMP_ULE: return FCMP_OGT;
-    case FCMP_ORD: return FCMP_UNO;
-    case FCMP_UNO: return FCMP_ORD;
-    case FCMP_TRUE: return FCMP_FALSE;
-    case FCMP_FALSE: return FCMP_TRUE;
-  }
-}
-
-FCmpInst::Predicate FCmpInst::getSwappedPredicate(Predicate pred) {
+CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
   switch (pred) {
-    default: assert(!"Unknown fcmp predicate!");
+    default: assert(!"Unknown cmp predicate!");
+    case ICMP_EQ: case ICMP_NE:
+      return pred;
+    case ICMP_SGT: return ICMP_SLT;
+    case ICMP_SLT: return ICMP_SGT;
+    case ICMP_SGE: return ICMP_SLE;
+    case ICMP_SLE: return ICMP_SGE;
+    case ICMP_UGT: return ICMP_ULT;
+    case ICMP_ULT: return ICMP_UGT;
+    case ICMP_UGE: return ICMP_ULE;
+    case ICMP_ULE: return ICMP_UGE;
+  
     case FCMP_FALSE: case FCMP_TRUE:
     case FCMP_OEQ: case FCMP_ONE:
     case FCMP_UEQ: case FCMP_UNE:
@@ -2610,8 +2735,8 @@ void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumCases) {
   NumOperands = 2;
   OperandList = allocHungoffUses(ReservedSpace);
 
-  OperandList[0].init(Value, this);
-  OperandList[1].init(Default, this);
+  OperandList[0] = Value;
+  OperandList[1] = Default;
 }
 
 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
@@ -2639,8 +2764,8 @@ SwitchInst::SwitchInst(const SwitchInst &SI)
                    allocHungoffUses(SI.getNumOperands()), SI.getNumOperands()) {
   Use *OL = OperandList, *InOL = SI.OperandList;
   for (unsigned i = 0, E = SI.getNumOperands(); i != E; i+=2) {
-    OL[i].init(InOL[i], this);
-    OL[i+1].init(InOL[i+1], this);
+    OL[i] = InOL[i];
+    OL[i+1] = InOL[i+1];
   }
 }
 
@@ -2658,8 +2783,8 @@ void SwitchInst::addCase(ConstantInt *OnVal, BasicBlock *Dest) {
   // Initialize some new operands.
   assert(OpNo+1 < ReservedSpace && "Growing didn't work!");
   NumOperands = OpNo+2;
-  OperandList[OpNo].init(OnVal, this);
-  OperandList[OpNo+1].init(Dest, this);
+  OperandList[OpNo] = OnVal;
+  OperandList[OpNo+1] = Dest;
 }
 
 /// removeCase - This method removes the specified successor from the switch
@@ -2713,7 +2838,7 @@ void SwitchInst::resizeOperands(unsigned NumOps) {
   Use *NewOps = allocHungoffUses(NumOps);
   Use *OldOps = OperandList;
   for (unsigned i = 0; i != e; ++i) {
-      NewOps[i].init(OldOps[i], this);
+      NewOps[i] = OldOps[i];
   }
   OperandList = NewOps;
   if (OldOps) Use::zap(OldOps, OldOps + e, true);
@@ -2730,43 +2855,6 @@ void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
   setSuccessor(idx, B);
 }
 
-//===----------------------------------------------------------------------===//
-//                           GetResultInst Implementation
-//===----------------------------------------------------------------------===//
-
-GetResultInst::GetResultInst(Value *Aggregate, unsigned Index,
-                             const std::string &Name,
-                             Instruction *InsertBef)
-  : UnaryInstruction(cast<StructType>(Aggregate->getType())
-                       ->getElementType(Index),
-                     GetResult, Aggregate, InsertBef),
-    Idx(Index) {
-  assert(isValidOperands(Aggregate, Index)
-         && "Invalid GetResultInst operands!");
-  setName(Name);
-}
-
-bool GetResultInst::isValidOperands(const Value *Aggregate, unsigned Index) {
-  if (!Aggregate)
-    return false;
-
-  if (const StructType *STy = dyn_cast<StructType>(Aggregate->getType())) {
-    unsigned NumElements = STy->getNumElements();
-    if (Index >= NumElements || NumElements == 0)
-      return false;
-
-    // getresult aggregate value's element types are restricted to
-    // avoid nested aggregates.
-    for (unsigned i = 0; i < NumElements; ++i)
-      if (!STy->getElementType(i)->isFirstClassType())
-        return false;
-
-    // Otherwise, Aggregate is valid.
-    return true;
-  }
-  return false;
-}
-
 // Define these methods here so vtables don't get emitted into every translation
 // unit that uses these classes.
 
@@ -2775,7 +2863,7 @@ GetElementPtrInst *GetElementPtrInst::clone() const {
 }
 
 BinaryOperator *BinaryOperator::clone() const {
-  return create(getOpcode(), Op<0>(), Op<1>());
+  return Create(getOpcode(), Op<0>(), Op<1>());
 }
 
 FCmpInst* FCmpInst::clone() const {
@@ -2792,6 +2880,14 @@ VICmpInst* VICmpInst::clone() const {
   return new VICmpInst(getPredicate(), Op<0>(), Op<1>());
 }
 
+ExtractValueInst *ExtractValueInst::clone() const {
+  return new ExtractValueInst(*this);
+}
+InsertValueInst *InsertValueInst::clone() const {
+  return new InsertValueInst(*this);
+}
+
+
 MallocInst *MallocInst::clone()   const { return new MallocInst(*this); }
 AllocaInst *AllocaInst::clone()   const { return new AllocaInst(*this); }
 FreeInst   *FreeInst::clone()     const { return new FreeInst(getOperand(0)); }
@@ -2839,4 +2935,3 @@ InvokeInst *InvokeInst::clone() const {
 }
 UnwindInst *UnwindInst::clone() const { return new UnwindInst(); }
 UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();}
-GetResultInst *GetResultInst::clone() const { return new GetResultInst(*this); }