Remove the vicmp and vfcmp instructions. Because we never had a release with
[oota-llvm.git] / include / llvm / Instructions.h
index b897a39fad732e054af3218631571a5322db4deb..aef77f0a93d81fd71f8520eb912fc90259a720de 100644 (file)
 #ifndef LLVM_INSTRUCTIONS_H
 #define LLVM_INSTRUCTIONS_H
 
-#include <iterator>
-
 #include "llvm/InstrTypes.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Attributes.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/ADT/SmallVector.h"
+#include <iterator>
 
 namespace llvm {
 
 class ConstantInt;
-class PointerType;
-class VectorType;
 class ConstantRange;
 class APInt;
 
@@ -54,7 +51,7 @@ public:
   ///
   bool isArrayAllocation() const;
 
-  /// getArraySize - Get the number of element allocated, for a simple
+  /// getArraySize - Get the number of elements allocated. For a simple
   /// allocation of a single element, this will return a constant 1 value.
   ///
   const Value *getArraySize() const { return getOperand(0); }
@@ -111,7 +108,8 @@ public:
   MallocInst(const Type *Ty, const std::string &NameStr,
              Instruction *InsertBefore = 0)
     : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertBefore) {}
-  MallocInst(const Type *Ty, const std::string &NameStr, BasicBlock *InsertAtEnd)
+  MallocInst(const Type *Ty, const std::string &NameStr,
+             BasicBlock *InsertAtEnd)
     : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {}
 
   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
@@ -168,6 +166,11 @@ public:
 
   virtual AllocaInst *clone() const;
 
+  /// 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 isStaticAlloca() const;
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const AllocaInst *) { return true; }
   static inline bool classof(const Instruction *I) {
@@ -192,7 +195,7 @@ public:
   FreeInst(Value *Ptr, BasicBlock *InsertAfter);
 
   virtual FreeInst *clone() const;
-  
+
   // Accessor methods for consistency with other memory operations
   Value *getPointerOperand() { return getOperand(0); }
   const Value *getPointerOperand() const { return getOperand(0); }
@@ -230,7 +233,7 @@ class LoadInst : public UnaryInstruction {
 public:
   LoadInst(Value *Ptr, const std::string &NameStr, Instruction *InsertBefore);
   LoadInst(Value *Ptr, const std::string &NameStr, BasicBlock *InsertAtEnd);
-  LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile = false, 
+  LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile = false,
            Instruction *InsertBefore = 0);
   LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile,
            unsigned Align, Instruction *InsertBefore = 0);
@@ -245,7 +248,7 @@ public:
                     bool isVolatile = false,  Instruction *InsertBefore = 0);
   LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
            BasicBlock *InsertAtEnd);
-  
+
   /// isVolatile - Return true if this is a load from a volatile memory
   /// location.
   ///
@@ -253,8 +256,8 @@ public:
 
   /// setVolatile - Specify whether this is a volatile load or not.
   ///
-  void setVolatile(bool V) { 
-    SubclassData = (SubclassData & ~1) | (V ? 1 : 0); 
+  void setVolatile(bool V) {
+    SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
   }
 
   virtual LoadInst *clone() const;
@@ -264,7 +267,7 @@ public:
   unsigned getAlignment() const {
     return (1 << (SubclassData>>1)) >> 1;
   }
-  
+
   void setAlignment(unsigned Align);
 
   Value *getPointerOperand() { return getOperand(0); }
@@ -290,14 +293,14 @@ public:
 ///
 class StoreInst : public Instruction {
   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
-  
+
   StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store,
                                                &Op<0>(), 2) {
     Op<0>() = SI.Op<0>();
     Op<1>() = SI.Op<1>();
     setVolatile(SI.isVolatile());
     setAlignment(SI.getAlignment());
-    
+
 #ifndef NDEBUG
     AssertOK();
 #endif
@@ -326,8 +329,8 @@ public:
 
   /// setVolatile - Specify whether this is a volatile load or not.
   ///
-  void setVolatile(bool V) { 
-    SubclassData = (SubclassData & ~1) | (V ? 1 : 0); 
+  void setVolatile(bool V) {
+    SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
   }
 
   /// Transparently provide more efficient getOperand methods.
@@ -338,9 +341,9 @@ public:
   unsigned getAlignment() const {
     return (1 << (SubclassData>>1)) >> 1;
   }
-  
+
   void setAlignment(unsigned Align);
-  
+
   virtual StoreInst *clone() const;
 
   Value *getPointerOperand() { return getOperand(1); }
@@ -391,7 +394,7 @@ class GetElementPtrInst : public Instruction {
             // do arithmetic on in constant time
             std::random_access_iterator_tag) {
     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
-    
+
     if (NumIdx > 0) {
       // This requires that the iterator points to contiguous memory.
       init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
@@ -410,7 +413,7 @@ class GetElementPtrInst : public Instruction {
   ///
   template<typename InputIterator>
   static const Type *getIndexedType(const Type *Ptr,
-                                    InputIterator IdxBegin, 
+                                    InputIterator IdxBegin,
                                     InputIterator IdxEnd,
                                     // This argument ensures that we
                                     // have an iterator we can do
@@ -420,7 +423,7 @@ class GetElementPtrInst : public Instruction {
 
     if (NumIdx > 0)
       // This requires that the iterator points to contiguous memory.
-      return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx);
+      return getIndexedType(Ptr, &*IdxBegin, NumIdx);
     else
       return getIndexedType(Ptr, (Value *const*)0, NumIdx);
   }
@@ -430,7 +433,7 @@ class GetElementPtrInst : public Instruction {
   /// instruction, the second appends the new instruction to the specified
   /// BasicBlock.
   template<typename InputIterator>
-  inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, 
+  inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
                            InputIterator IdxEnd,
                            unsigned Values,
                            const std::string &NameStr,
@@ -449,11 +452,11 @@ class GetElementPtrInst : public Instruction {
                     const std::string &NameStr, BasicBlock *InsertAtEnd);
 public:
   template<typename InputIterator>
-  static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, 
+  static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
                                    InputIterator IdxEnd,
                                    const std::string &NameStr = "",
                                    Instruction *InsertBefore = 0) {
-    typename std::iterator_traits<InputIterator>::difference_type Values = 
+    typename std::iterator_traits<InputIterator>::difference_type Values =
       1 + std::distance(IdxBegin, IdxEnd);
     return new(Values)
       GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
@@ -463,7 +466,7 @@ public:
                                    InputIterator IdxBegin, InputIterator IdxEnd,
                                    const std::string &NameStr,
                                    BasicBlock *InsertAtEnd) {
-    typename std::iterator_traits<InputIterator>::difference_type Values = 
+    typename std::iterator_traits<InputIterator>::difference_type Values =
       1 + std::distance(IdxBegin, IdxEnd);
     return new(Values)
       GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
@@ -505,7 +508,7 @@ public:
     return getIndexedType(Ptr, IdxBegin, IdxEnd,
                           typename std::iterator_traits<InputIterator>::
                           iterator_category());
-  }  
+  }
 
   static const Type *getIndexedType(const Type *Ptr,
                                     Value* const *Idx, unsigned NumIdx);
@@ -530,6 +533,13 @@ public:
     return 0U;                      // get index for modifying correct operand
   }
 
+  /// getPointerOperandType - Method to return the pointer operand as a
+  /// PointerType.
+  const PointerType *getPointerOperandType() const {
+    return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
+  }
+
+
   unsigned getNumIndices() const {  // Note: always non-negative
     return getNumOperands() - 1;
   }
@@ -537,17 +547,17 @@ public:
   bool hasIndices() const {
     return getNumOperands() > 1;
   }
-  
+
   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
   /// zeros.  If so, the result pointer and the first operand have the same
   /// value, just potentially different types.
   bool hasAllZeroIndices() const;
-  
+
   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
   /// constant integers.  If so, the result pointer and the first operand have
   /// a constant offset between them.
   bool hasAllConstantIndices() const;
-  
+
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const GetElementPtrInst *) { return true; }
@@ -565,7 +575,7 @@ struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
 
 template<typename InputIterator>
 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
-                                     InputIterator IdxBegin, 
+                                     InputIterator IdxBegin,
                                      InputIterator IdxEnd,
                                      unsigned Values,
                                      const std::string &NameStr,
@@ -630,7 +640,7 @@ public:
     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
           "Both operands to ICmp instruction are not of the same type!");
     // Check that the operands are the right type
-    assert((getOperand(0)->getType()->isIntOrIntVector() || 
+    assert((getOperand(0)->getType()->isIntOrIntVector() ||
             isa<PointerType>(getOperand(0)->getType())) &&
            "Invalid operand types for ICmp instruction");
   }
@@ -651,7 +661,7 @@ public:
     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
           "Both operands to ICmp instruction are not of the same type!");
     // Check that the operands are the right type
-    assert((getOperand(0)->getType()->isIntOrIntVector() || 
+    assert((getOperand(0)->getType()->isIntOrIntVector() ||
             isa<PointerType>(getOperand(0)->getType())) &&
            "Invalid operand types for ICmp instruction");
   }
@@ -685,7 +695,7 @@ public:
   static bool isEquality(Predicate P) {
     return P == ICMP_EQ || P == ICMP_NE;
   }
-  
+
   /// isEquality - Return true if this predicate is either EQ or NE.  This also
   /// tests for commutativity.
   bool isEquality() const {
@@ -696,18 +706,18 @@ public:
   /// @brief Determine if this relation is commutative.
   bool isCommutative() const { return isEquality(); }
 
-  /// isRelational - Return true if the predicate is relational (not EQ or NE). 
+  /// isRelational - Return true if the predicate is relational (not EQ or NE).
   ///
   bool isRelational() const {
     return !isEquality();
   }
 
-  /// isRelational - Return true if the predicate is relational (not EQ or NE). 
+  /// isRelational - Return true if the predicate is relational (not EQ or NE).
   ///
   static bool isRelational(Predicate P) {
     return !isEquality(P);
   }
-  
+
   /// @returns true if the predicate of this ICmpInst is signed, false otherwise
   /// @brief Determine if this instruction's predicate is signed.
   bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
@@ -732,14 +742,14 @@ public:
     return isTrueWhenEqual(getPredicate());
   }
 
-  /// Initialize a set of values that all satisfy the predicate with C. 
+  /// Initialize a set of values that all satisfy the predicate with C.
   /// @brief Make a ConstantRange for a relation with a constant value.
   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
 
   /// Exchange the two operands to this instruction in such a way that it does
   /// not modify the semantics of the instruction. The predicate value may be
   /// changed to retain the same result if the predicate is order dependent
-  /// (e.g. ult). 
+  /// (e.g. ult).
   /// @brief Swap operands and adjust predicate.
   void swapOperands() {
     SubclassData = getSwappedPredicate();
@@ -764,7 +774,7 @@ public:
 //===----------------------------------------------------------------------===//
 
 /// This instruction compares its operands according to the predicate given
-/// to the constructor. It only operates on floating point values or packed     
+/// to the constructor. It only operates on floating point values or packed
 /// vectors of floating point values. The operands must be identical types.
 /// @brief Represents a floating point comparison operator.
 class FCmpInst: public CmpInst {
@@ -824,14 +834,14 @@ public:
            SubclassData == FCMP_UNO;
   }
 
-  /// @returns true if the predicate is relational (not EQ or NE). 
+  /// @returns true if the predicate is relational (not EQ or NE).
   /// @brief Determine if this a relational predicate.
   bool isRelational() const { return !isEquality(); }
 
   /// Exchange the two operands to this instruction in such a way that it does
   /// not modify the semantics of the instruction. The predicate value may be
   /// changed to retain the same result if the predicate is order dependent
-  /// (e.g. ult). 
+  /// (e.g. ult).
   /// @brief Swap operands and adjust predicate.
   void swapOperands() {
     SubclassData = getSwappedPredicate();
@@ -848,119 +858,7 @@ public:
   static inline bool classof(const Value *V) {
     return isa<Instruction>(V) && classof(cast<Instruction>(V));
   }
-  
-};
-
-//===----------------------------------------------------------------------===//
-//                               VICmpInst Class
-//===----------------------------------------------------------------------===//
-
-/// This instruction compares its operands according to the predicate given
-/// to the constructor. It only operates on vectors of integers.
-/// The operands must be identical types.
-/// @brief Represents a vector integer comparison operator.
-class VICmpInst: public CmpInst {
-public:
-  /// @brief Constructor with insert-before-instruction semantics.
-  VICmpInst(
-    Predicate pred,  ///< The predicate to use for the comparison
-    Value *LHS,      ///< The left-hand-side of the expression
-    Value *RHS,      ///< The right-hand-side of the expression
-    const std::string &NameStr = "",  ///< Name of the instruction
-    Instruction *InsertBefore = 0  ///< Where to insert
-  ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, NameStr,
-              InsertBefore) {
-    assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
-           pred <= CmpInst::LAST_ICMP_PREDICATE &&
-           "Invalid VICmp predicate value");
-    assert(getOperand(0)->getType() == getOperand(1)->getType() &&
-          "Both operands to VICmp instruction are not of the same type!");
-  }
-
-  /// @brief Constructor with insert-at-block-end semantics.
-  VICmpInst(
-    Predicate pred, ///< The predicate to use for the comparison
-    Value *LHS,     ///< The left-hand-side of the expression
-    Value *RHS,     ///< The right-hand-side of the expression
-    const std::string &NameStr,  ///< Name of the instruction
-    BasicBlock *InsertAtEnd   ///< Block to insert into.
-  ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, NameStr,
-              InsertAtEnd) {
-    assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
-           pred <= CmpInst::LAST_ICMP_PREDICATE &&
-           "Invalid VICmp predicate value");
-    assert(getOperand(0)->getType() == getOperand(1)->getType() &&
-          "Both operands to VICmp instruction are not of the same type!");
-  }
-  
-  /// @brief Return the predicate for this instruction.
-  Predicate getPredicate() const { return Predicate(SubclassData); }
-
-  virtual VICmpInst *clone() const;
 
-  // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool classof(const VICmpInst *) { return true; }
-  static inline bool classof(const Instruction *I) {
-    return I->getOpcode() == Instruction::VICmp;
-  }
-  static inline bool classof(const Value *V) {
-    return isa<Instruction>(V) && classof(cast<Instruction>(V));
-  }
-};
-
-//===----------------------------------------------------------------------===//
-//                               VFCmpInst Class
-//===----------------------------------------------------------------------===//
-
-/// This instruction compares its operands according to the predicate given
-/// to the constructor. It only operates on vectors of floating point values.
-/// The operands must be identical types.
-/// @brief Represents a vector floating point comparison operator.
-class VFCmpInst: public CmpInst {
-public:
-  /// @brief Constructor with insert-before-instruction semantics.
-  VFCmpInst(
-    Predicate pred,  ///< The predicate to use for the comparison
-    Value *LHS,      ///< The left-hand-side of the expression
-    Value *RHS,      ///< The right-hand-side of the expression
-    const std::string &NameStr = "",  ///< Name of the instruction
-    Instruction *InsertBefore = 0  ///< Where to insert
-  ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
-              Instruction::VFCmp, pred, LHS, RHS, NameStr, InsertBefore) {
-    assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
-           "Invalid VFCmp predicate value");
-    assert(getOperand(0)->getType() == getOperand(1)->getType() &&
-           "Both operands to VFCmp instruction are not of the same type!");
-  }
-
-  /// @brief Constructor with insert-at-block-end semantics.
-  VFCmpInst(
-    Predicate pred, ///< The predicate to use for the comparison
-    Value *LHS,     ///< The left-hand-side of the expression
-    Value *RHS,     ///< The right-hand-side of the expression
-    const std::string &NameStr,  ///< Name of the instruction
-    BasicBlock *InsertAtEnd   ///< Block to insert into.
-  ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
-              Instruction::VFCmp, pred, LHS, RHS, NameStr, InsertAtEnd) {
-    assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
-           "Invalid VFCmp predicate value");
-    assert(getOperand(0)->getType() == getOperand(1)->getType() &&
-           "Both operands to VFCmp instruction are not of the same type!");
-  }
-
-  /// @brief Return the predicate for this instruction.
-  Predicate getPredicate() const { return Predicate(SubclassData); }
-
-  virtual VFCmpInst *clone() const;
-
-  /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool classof(const VFCmpInst *) { return true; }
-  static inline bool classof(const Instruction *I) {
-    return I->getOpcode() == Instruction::VFCmp;
-  }
-  static inline bool classof(const Value *V) {
-    return isa<Instruction>(V) && classof(cast<Instruction>(V));
-  }
 };
 
 //===----------------------------------------------------------------------===//
@@ -973,7 +871,7 @@ public:
 ///
 
 class CallInst : public Instruction {
-  PAListPtr ParamAttrs; ///< parameter attributes for call
+  AttrListPtr AttributeList; ///< parameter attributes for call
   CallInst(const CallInst &CI);
   void init(Value *Func, Value* const *Params, unsigned NumParams);
   void init(Value *Func, Value *Actual1, Value *Actual2);
@@ -987,7 +885,7 @@ class CallInst : public Instruction {
             // do arithmetic on in constant time
             std::random_access_iterator_tag) {
     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
-    
+
     // This requires that the iterator points to contiguous memory.
     init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
     setName(NameStr);
@@ -1056,16 +954,16 @@ public:
 
   ~CallInst();
 
-  virtual CallInst *clone() const;
-
-  /// Provide fast operand accessors
-  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-  
   bool isTailCall() const           { return SubclassData & 1; }
   void setTailCall(bool isTC = true) {
     SubclassData = (SubclassData & ~1) | unsigned(isTC);
   }
 
+  virtual CallInst *clone() const;
+
+  /// Provide fast operand accessors
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
   /// getCallingConv/setCallingConv - Get or set the calling convention of this
   /// function call.
   unsigned getCallingConv() const { return SubclassData >> 1; }
@@ -1073,86 +971,87 @@ public:
     SubclassData = (SubclassData & 1) | (CC << 1);
   }
 
-  /// getParamAttrs - Return the parameter attributes for this call.
+  /// getAttributes - Return the parameter attributes for this call.
+  ///
+  const AttrListPtr &getAttributes() const { return AttributeList; }
+
+  /// setAttributes - Set the parameter attributes for this call.
   ///
-  const PAListPtr &getParamAttrs() const { return ParamAttrs; }
+  void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
 
-  /// setParamAttrs - Sets the parameter attributes for this call.
-  void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
-  
-  /// addParamAttr - adds the attribute to the list of attributes.
-  void addParamAttr(unsigned i, Attributes attr);
+  /// addAttribute - adds the attribute to the list of attributes.
+  void addAttribute(unsigned i, Attributes attr);
 
-  /// removeParamAttr - removes the attribute from the list of attributes.
-  void removeParamAttr(unsigned i, Attributes attr);
+  /// removeAttribute - removes the attribute from the list of attributes.
+  void removeAttribute(unsigned i, Attributes attr);
 
   /// @brief Determine whether the call or the callee has the given attribute.
-  bool paramHasAttr(unsigned i, unsigned attr) const;
+  bool paramHasAttr(unsigned i, Attributes attr) const;
 
   /// @brief Extract the alignment for a call or parameter (0=unknown).
   unsigned getParamAlignment(unsigned i) const {
-    return ParamAttrs.getParamAlignment(i);
+    return AttributeList.getParamAlignment(i);
   }
 
   /// @brief Determine if the call does not access memory.
   bool doesNotAccessMemory() const {
-    return paramHasAttr(0, ParamAttr::ReadNone);
+    return paramHasAttr(~0, Attribute::ReadNone);
   }
   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
-    if (NotAccessMemory) addParamAttr(0, ParamAttr::ReadNone);
-    else removeParamAttr(0, ParamAttr::ReadNone);
+    if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
+    else removeAttribute(~0, Attribute::ReadNone);
   }
 
   /// @brief Determine if the call does not access or only reads memory.
   bool onlyReadsMemory() const {
-    return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
+    return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
   }
   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
-    if (OnlyReadsMemory) addParamAttr(0, ParamAttr::ReadOnly);
-    else removeParamAttr(0, ParamAttr::ReadOnly | ParamAttr::ReadNone);
+    if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
+    else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
   }
 
   /// @brief Determine if the call cannot return.
   bool doesNotReturn() const {
-    return paramHasAttr(0, ParamAttr::NoReturn);
+    return paramHasAttr(~0, Attribute::NoReturn);
   }
   void setDoesNotReturn(bool DoesNotReturn = true) {
-    if (DoesNotReturn) addParamAttr(0, ParamAttr::NoReturn);
-    else removeParamAttr(0, ParamAttr::NoReturn);
+    if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
+    else removeAttribute(~0, Attribute::NoReturn);
   }
 
   /// @brief Determine if the call cannot unwind.
   bool doesNotThrow() const {
-    return paramHasAttr(0, ParamAttr::NoUnwind);
+    return paramHasAttr(~0, Attribute::NoUnwind);
   }
   void setDoesNotThrow(bool DoesNotThrow = true) {
-    if (DoesNotThrow) addParamAttr(0, ParamAttr::NoUnwind);
-    else removeParamAttr(0, ParamAttr::NoUnwind);
+    if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
+    else removeAttribute(~0, Attribute::NoUnwind);
   }
 
-  /// @brief Determine if the call returns a structure through first 
+  /// @brief Determine if the call returns a structure through first
   /// pointer argument.
   bool hasStructRetAttr() const {
     // Be friendly and also check the callee.
-    return paramHasAttr(1, ParamAttr::StructRet);
+    return paramHasAttr(1, Attribute::StructRet);
   }
 
   /// @brief Determine if any call argument is an aggregate passed by value.
   bool hasByValArgument() const {
-    return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal);
+    return AttributeList.hasAttrSomewhere(Attribute::ByVal);
   }
 
-  /// getCalledFunction - Return the function being called by this instruction
-  /// if it is a direct call.  If it is a call through a function pointer,
-  /// return null.
+  /// getCalledFunction - Return the function called, or null if this is an
+  /// indirect function invocation.
+  ///
   Function *getCalledFunction() const {
-    return dyn_cast<Function>(getOperand(0));
+    return dyn_cast<Function>(Op<0>());
   }
 
-  /// getCalledValue - Get a pointer to the function that is invoked by this 
+  /// getCalledValue - Get a pointer to the function that is invoked by this
   /// instruction
-  const Value *getCalledValue() const { return getOperand(0); }
-        Value *getCalledValue()       { return getOperand(0); }
+  const Value *getCalledValue() const { return Op<0>(); }
+        Value *getCalledValue()       { return Op<0>(); }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const CallInst *) { return true; }
@@ -1188,7 +1087,7 @@ CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
                 Instruction::Call,
                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
                 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
-  init(Func, ArgBegin, ArgEnd, NameStr, 
+  init(Func, ArgBegin, ArgEnd, NameStr,
        typename std::iterator_traits<InputIterator>::iterator_category());
 }
 
@@ -1202,6 +1101,7 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
 ///
 class SelectInst : public Instruction {
   void init(Value *C, Value *S1, Value *S2) {
+    assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
     Op<0>() = C;
     Op<1>() = S1;
     Op<2>() = S2;
@@ -1241,6 +1141,10 @@ public:
   Value *getTrueValue() const { return Op<1>(); }
   Value *getFalseValue() const { return Op<2>(); }
 
+  /// areInvalidOperands - Return a string if the specified operands are invalid
+  /// for a select operation, otherwise return null.
+  static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
+
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
 
@@ -1363,9 +1267,11 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
 class InsertElementInst : public Instruction {
   InsertElementInst(const InsertElementInst &IE);
   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
-                    const std::string &NameStr = "",Instruction *InsertBefore = 0);
+                    const std::string &NameStr = "",
+                    Instruction *InsertBefore = 0);
   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
-                    const std::string &NameStr = "",Instruction *InsertBefore = 0);
+                    const std::string &NameStr = "",
+                    Instruction *InsertBefore = 0);
   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
                     const std::string &NameStr, BasicBlock *InsertAtEnd);
   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
@@ -1462,7 +1368,7 @@ public:
 
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-  
+
   /// getMaskValue - Return the index from the shuffle mask for the specified
   /// output result.  This is either -1 if the element is undef or a number less
   /// than 2*numelements.
@@ -1506,7 +1412,7 @@ class ExtractValueInst : public UnaryInstruction {
             // do arithmetic on in constant time
             std::random_access_iterator_tag) {
     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
-    
+
     // There's no fundamental reason why we require at least one index
     // (other than weirdness with &*IdxBegin being invalid; see
     // getelementptr's init routine for example). But there's no
@@ -1529,7 +1435,7 @@ class ExtractValueInst : public UnaryInstruction {
 
   template<typename InputIterator>
   static const Type *getIndexedType(const Type *Ptr,
-                                    InputIterator IdxBegin, 
+                                    InputIterator IdxBegin,
                                     InputIterator IdxEnd,
                                     // This argument ensures that we
                                     // have an iterator we can do
@@ -1549,7 +1455,7 @@ class ExtractValueInst : public UnaryInstruction {
   /// an existing instruction, the second appends the new instruction to the
   /// specified BasicBlock.
   template<typename InputIterator>
-  inline ExtractValueInst(Value *Agg, InputIterator IdxBegin, 
+  inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
                           InputIterator IdxEnd,
                           const std::string &NameStr,
                           Instruction *InsertBefore);
@@ -1565,7 +1471,7 @@ class ExtractValueInst : public UnaryInstruction {
 
 public:
   template<typename InputIterator>
-  static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, 
+  static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
                                   InputIterator IdxEnd,
                                   const std::string &NameStr = "",
                                   Instruction *InsertBefore = 0) {
@@ -1598,11 +1504,6 @@ public:
 
   virtual ExtractValueInst *clone() const;
 
-  // getType - Overload to return most specific pointer type...
-  const PointerType *getType() const {
-    return reinterpret_cast<const PointerType*>(Instruction::getType());
-  }
-
   /// getIndexedType - Returns the type of the element that would be extracted
   /// with an extractvalue instruction with the specified parameters.
   ///
@@ -1616,7 +1517,7 @@ public:
     return getIndexedType(Ptr, IdxBegin, IdxEnd,
                           typename std::iterator_traits<InputIterator>::
                           iterator_category());
-  }  
+  }
   static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
 
   typedef const unsigned* idx_iterator;
@@ -1640,7 +1541,7 @@ public:
   bool hasIndices() const {
     return true;
   }
-  
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ExtractValueInst *) { return true; }
   static inline bool classof(const Instruction *I) {
@@ -1653,7 +1554,7 @@ public:
 
 template<typename InputIterator>
 ExtractValueInst::ExtractValueInst(Value *Agg,
-                                   InputIterator IdxBegin, 
+                                   InputIterator IdxBegin,
                                    InputIterator IdxEnd,
                                    const std::string &NameStr,
                                    Instruction *InsertBefore)
@@ -1701,7 +1602,7 @@ class InsertValueInst : public Instruction {
             // do arithmetic on in constant time
             std::random_access_iterator_tag) {
     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
-    
+
     // There's no fundamental reason why we require at least one index
     // (other than weirdness with &*IdxBegin being invalid; see
     // getelementptr's init routine for example). But there's no
@@ -1718,7 +1619,7 @@ class InsertValueInst : public Instruction {
   /// optionally insert before an existing instruction, the second appends
   /// the new instruction to the specified BasicBlock.
   template<typename InputIterator>
-  inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin, 
+  inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
                          InputIterator IdxEnd,
                          const std::string &NameStr,
                          Instruction *InsertBefore);
@@ -1776,11 +1677,6 @@ public:
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
 
-  // getType - Overload to return most specific pointer type...
-  const PointerType *getType() const {
-    return reinterpret_cast<const PointerType*>(Instruction::getType());
-  }
-
   typedef const unsigned* idx_iterator;
   inline idx_iterator idx_begin() const { return Indices.begin(); }
   inline idx_iterator idx_end()   const { return Indices.end(); }
@@ -1812,7 +1708,7 @@ public:
   bool hasIndices() const {
     return true;
   }
-  
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const InsertValueInst *) { return true; }
   static inline bool classof(const Instruction *I) {
@@ -1830,7 +1726,7 @@ struct OperandTraits<InsertValueInst> : FixedNumOperandTraits<2> {
 template<typename InputIterator>
 InsertValueInst::InsertValueInst(Value *Agg,
                                  Value *Val,
-                                 InputIterator IdxBegin, 
+                                 InputIterator IdxBegin,
                                  InputIterator IdxEnd,
                                  const std::string &NameStr,
                                  Instruction *InsertBefore)
@@ -1924,10 +1820,22 @@ public:
     assert(i*2 < getNumOperands() && "Invalid value number!");
     setOperand(i*2, V);
   }
-  unsigned getOperandNumForIncomingValue(unsigned i) {
+  static unsigned getOperandNumForIncomingValue(unsigned i) {
     return i*2;
   }
+  static unsigned getIncomingValueNumForOperand(unsigned i) {
+    assert(i % 2 == 0 && "Invalid incoming-value operand index!");
+    return i/2;
+  }
 
+  /// getIncomingBlock - Return incoming basic block corresponding
+  /// to value use iterator
+  ///
+  template <typename U>
+  BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
+    assert(this == *I && "Iterator doesn't point to PHI's Uses?");
+    return static_cast<BasicBlock*>((&I.getUse() + 1)->get());
+  }
   /// getIncomingBlock - Return incoming basic block number x
   ///
   BasicBlock *getIncomingBlock(unsigned i) const {
@@ -1936,9 +1844,13 @@ public:
   void setIncomingBlock(unsigned i, BasicBlock *BB) {
     setOperand(i*2+1, BB);
   }
-  unsigned getOperandNumForIncomingBlock(unsigned i) {
+  static unsigned getOperandNumForIncomingBlock(unsigned i) {
     return i*2+1;
   }
+  static unsigned getIncomingBlockNumForOperand(unsigned i) {
+    assert(i % 2 == 1 && "Invalid incoming-block operand index!");
+    return i/2;
+  }
 
   /// addIncoming - Add an incoming value to the end of the PHI list
   ///
@@ -2007,7 +1919,7 @@ template <>
 struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
 };
 
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)  
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
 
 
 //===----------------------------------------------------------------------===//
@@ -2091,8 +2003,9 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
 ///
 class BranchInst : public TerminatorInst {
   /// Ops list - Branches are strange.  The operands are ordered:
-  ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
-  /// they don't have to check for cond/uncond branchness.
+  ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
+  /// they don't have to check for cond/uncond branchness. These are mostly
+  /// accessed relative from op_end().
   BranchInst(const BranchInst &BI);
   void AssertOK();
   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
@@ -2110,24 +2023,21 @@ class BranchInst : public TerminatorInst {
              BasicBlock *InsertAtEnd);
 public:
   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
-    return new(1) BranchInst(IfTrue, InsertBefore);
+    return new(1, true) BranchInst(IfTrue, InsertBefore);
   }
   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
                             Value *Cond, Instruction *InsertBefore = 0) {
     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
   }
   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
-    return new(1) BranchInst(IfTrue, InsertAtEnd);
+    return new(1, true) BranchInst(IfTrue, InsertAtEnd);
   }
   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
                             Value *Cond, BasicBlock *InsertAtEnd) {
     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
   }
 
-  ~BranchInst() {
-    if (NumOperands == 1)
-      NumOperands = (unsigned)((Use*)this - OperandList);
-  }
+  ~BranchInst();
 
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -2139,23 +2049,24 @@ public:
 
   Value *getCondition() const {
     assert(isConditional() && "Cannot get condition of an uncond branch!");
-    return getOperand(2);
+    return Op<-3>();
   }
 
   void setCondition(Value *V) {
     assert(isConditional() && "Cannot set condition of unconditional branch!");
-    setOperand(2, V);
+    Op<-3>() = V;
   }
 
   // setUnconditionalDest - Change the current branch to an unconditional branch
   // targeting the specified block.
   // FIXME: Eliminate this ugly method.
   void setUnconditionalDest(BasicBlock *Dest) {
-    Op<0>() = Dest;
+    Op<-1>() = Dest;
     if (isConditional()) {  // Convert this to an uncond branch.
-      Op<1>().set(0);
-      Op<2>().set(0);
+      Op<-2>() = 0;
+      Op<-3>() = 0;
       NumOperands = 1;
+      OperandList = op_begin();
     }
   }
 
@@ -2163,12 +2074,12 @@ public:
 
   BasicBlock *getSuccessor(unsigned i) const {
     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
-    return cast<BasicBlock>(getOperand(i));
+    return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
   }
 
   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
-    setOperand(idx, NewSucc);
+    *(&Op<-1>() - idx) = NewSucc;
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -2186,11 +2097,7 @@ private:
 };
 
 template <>
-struct OperandTraits<BranchInst> : HungoffOperandTraits<> {
-  // we need to access operands via OperandList, since
-  // the NumOperands may change from 3 to 1
-  static inline void *allocate(unsigned); // FIXME
-};
+struct OperandTraits<BranchInst> : VariadicOperandTraits<1> {};
 
 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
 
@@ -2221,7 +2128,7 @@ class SwitchInst : public TerminatorInst {
   /// constructor can also autoinsert before another instruction.
   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
              Instruction *InsertBefore = 0);
-  
+
   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
   /// switch on and a default destination.  The number of additional cases can
   /// be specified here to make memory allocation more efficient.  This
@@ -2342,7 +2249,7 @@ template <>
 struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
 };
 
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)  
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
 
 
 //===----------------------------------------------------------------------===//
@@ -2353,7 +2260,7 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
 /// calling convention of the call.
 ///
 class InvokeInst : public TerminatorInst {
-  PAListPtr ParamAttrs;
+  AttrListPtr AttributeList;
   InvokeInst(const InvokeInst &BI);
   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
             Value* const *Args, unsigned NumArgs);
@@ -2366,7 +2273,7 @@ class InvokeInst : public TerminatorInst {
             // do arithmetic on in constant time
             std::random_access_iterator_tag) {
     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
-    
+
     // This requires that the iterator points to contiguous memory.
     init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
     setName(NameStr);
@@ -2423,7 +2330,7 @@ public:
 
   /// Provide fast operand accessors
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-  
+
   /// getCallingConv/setCallingConv - Get or set the calling convention of this
   /// function call.
   unsigned getCallingConv() const { return SubclassData; }
@@ -2431,69 +2338,74 @@ public:
     SubclassData = CC;
   }
 
-  /// getParamAttrs - Return the parameter attributes for this invoke.
+  /// getAttributes - Return the parameter attributes for this invoke.
   ///
-  const PAListPtr &getParamAttrs() const { return ParamAttrs; }
+  const AttrListPtr &getAttributes() const { return AttributeList; }
 
-  /// setParamAttrs - Set the parameter attributes for this invoke.
+  /// setAttributes - Set the parameter attributes for this invoke.
   ///
-  void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
+  void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
+
+  /// addAttribute - adds the attribute to the list of attributes.
+  void addAttribute(unsigned i, Attributes attr);
+
+  /// removeAttribute - removes the attribute from the list of attributes.
+  void removeAttribute(unsigned i, Attributes attr);
 
   /// @brief Determine whether the call or the callee has the given attribute.
   bool paramHasAttr(unsigned i, Attributes attr) const;
-  
-  /// addParamAttr - adds the attribute to the list of attributes.
-  void addParamAttr(unsigned i, Attributes attr);
-
-  /// removeParamAttr - removes the attribute from the list of attributes.
-  void removeParamAttr(unsigned i, Attributes attr);
 
   /// @brief Extract the alignment for a call or parameter (0=unknown).
   unsigned getParamAlignment(unsigned i) const {
-    return ParamAttrs.getParamAlignment(i);
+    return AttributeList.getParamAlignment(i);
   }
 
   /// @brief Determine if the call does not access memory.
   bool doesNotAccessMemory() const {
-    return paramHasAttr(0, ParamAttr::ReadNone);
+    return paramHasAttr(0, Attribute::ReadNone);
   }
   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
-    if (NotAccessMemory) addParamAttr(0, ParamAttr::ReadNone);
-    else removeParamAttr(0, ParamAttr::ReadNone);
+    if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
+    else removeAttribute(~0, Attribute::ReadNone);
   }
 
   /// @brief Determine if the call does not access or only reads memory.
   bool onlyReadsMemory() const {
-    return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
+    return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
   }
   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
-    if (OnlyReadsMemory) addParamAttr(0, ParamAttr::ReadOnly);
-    else removeParamAttr(0, ParamAttr::ReadOnly | ParamAttr::ReadNone);
+    if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
+    else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
   }
 
   /// @brief Determine if the call cannot return.
   bool doesNotReturn() const {
-    return paramHasAttr(0, ParamAttr::NoReturn);
+    return paramHasAttr(~0, Attribute::NoReturn);
   }
   void setDoesNotReturn(bool DoesNotReturn = true) {
-    if (DoesNotReturn) addParamAttr(0, ParamAttr::NoReturn);
-    else removeParamAttr(0, ParamAttr::NoReturn);
+    if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
+    else removeAttribute(~0, Attribute::NoReturn);
   }
 
   /// @brief Determine if the call cannot unwind.
   bool doesNotThrow() const {
-    return paramHasAttr(0, ParamAttr::NoUnwind);
+    return paramHasAttr(~0, Attribute::NoUnwind);
   }
   void setDoesNotThrow(bool DoesNotThrow = true) {
-    if (DoesNotThrow) addParamAttr(0, ParamAttr::NoUnwind);
-    else removeParamAttr(0, ParamAttr::NoUnwind);
+    if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
+    else removeAttribute(~0, Attribute::NoUnwind);
   }
 
-  /// @brief Determine if the call returns a structure through first 
+  /// @brief Determine if the call returns a structure through first
   /// pointer argument.
   bool hasStructRetAttr() const {
     // Be friendly and also check the callee.
-    return paramHasAttr(1, ParamAttr::StructRet);
+    return paramHasAttr(1, Attribute::StructRet);
+  }
+
+  /// @brief Determine if any call argument is an aggregate passed by value.
+  bool hasByValArgument() const {
+    return AttributeList.hasAttrSomewhere(Attribute::ByVal);
   }
 
   /// getCalledFunction - Return the function called, or null if this is an
@@ -2503,8 +2415,10 @@ public:
     return dyn_cast<Function>(getOperand(0));
   }
 
-  // getCalledValue - Get a pointer to a function that is invoked by this inst.
-  Value *getCalledValue() const { return getOperand(0); }
+  /// getCalledValue - Get a pointer to the function that is invoked by this
+  /// instruction
+  const Value *getCalledValue() const { return getOperand(0); }
+        Value *getCalledValue()       { return getOperand(0); }
 
   // get*Dest - Return the destination basic blocks...
   BasicBlock *getNormalDest() const {