Make the Node member of SUnit private, and add accessors.
[oota-llvm.git] / include / llvm / Instructions.h
index 7372b995b1028b81af6649f0007eccca28c3e491..6ee18313a221969afe8cc1726eb16b55e0847df6 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "llvm/InstrTypes.h"
 #include "llvm/DerivedTypes.h"
-#include "llvm/ParameterAttributes.h"
+#include "llvm/Attributes.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/ADT/SmallVector.h"
 
@@ -408,9 +408,6 @@ class GetElementPtrInst : public Instruction {
   /// Null is returned if the indices are invalid for the specified
   /// pointer type.
   ///
-  static const Type *getIndexedType(const Type *Ptr,
-                                    Value* const *Idx, unsigned NumIdx);
-
   template<typename InputIterator>
   static const Type *getIndexedType(const Type *Ptr,
                                     InputIterator IdxBegin, 
@@ -423,7 +420,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);
   }
@@ -509,6 +506,13 @@ public:
                           typename std::iterator_traits<InputIterator>::
                           iterator_category());
   }  
+
+  static const Type *getIndexedType(const Type *Ptr,
+                                    Value* const *Idx, unsigned NumIdx);
+
+  static const Type *getIndexedType(const Type *Ptr,
+                                    uint64_t const *Idx, unsigned NumIdx);
+
   static const Type *getIndexedType(const Type *Ptr, Value *Idx);
 
   inline op_iterator       idx_begin()       { return op_begin()+1; }
@@ -617,7 +621,8 @@ public:
     Value *RHS,      ///< The right-hand-side of the expression
     const std::string &NameStr = "",  ///< Name of the instruction
     Instruction *InsertBefore = 0  ///< Where to insert
-  ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, NameStr,
+  ) : CmpInst(makeCmpResultType(LHS->getType()),
+              Instruction::ICmp, pred, LHS, RHS, NameStr,
               InsertBefore) {
     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
            pred <= CmpInst::LAST_ICMP_PREDICATE &&
@@ -625,7 +630,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()->isInteger() || 
+    assert((getOperand(0)->getType()->isIntOrIntVector() || 
             isa<PointerType>(getOperand(0)->getType())) &&
            "Invalid operand types for ICmp instruction");
   }
@@ -637,7 +642,8 @@ public:
     Value *RHS,     ///< The right-hand-side of the expression
     const std::string &NameStr,  ///< Name of the instruction
     BasicBlock *InsertAtEnd   ///< Block to insert into.
-  ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, NameStr,
+  ) : CmpInst(makeCmpResultType(LHS->getType()),
+              Instruction::ICmp, pred, LHS, RHS, NameStr,
               InsertAtEnd) {
     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
            pred <= CmpInst::LAST_ICMP_PREDICATE &&
@@ -645,7 +651,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()->isInteger() || 
+    assert((getOperand(0)->getType()->isIntOrIntVector() || 
             isa<PointerType>(getOperand(0)->getType())) &&
            "Invalid operand types for ICmp instruction");
   }
@@ -750,6 +756,7 @@ public:
   static inline bool classof(const Value *V) {
     return isa<Instruction>(V) && classof(cast<Instruction>(V));
   }
+
 };
 
 //===----------------------------------------------------------------------===//
@@ -769,14 +776,15 @@ public:
     Value *RHS,      ///< The right-hand-side of the expression
     const std::string &NameStr = "",  ///< Name of the instruction
     Instruction *InsertBefore = 0  ///< Where to insert
-  ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, NameStr,
+  ) : CmpInst(makeCmpResultType(LHS->getType()),
+              Instruction::FCmp, pred, LHS, RHS, NameStr,
               InsertBefore) {
     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
            "Invalid FCmp predicate value");
     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
            "Both operands to FCmp instruction are not of the same type!");
     // Check that the operands are the right type
-    assert(getOperand(0)->getType()->isFloatingPoint() &&
+    assert(getOperand(0)->getType()->isFPOrFPVector() &&
            "Invalid operand types for FCmp instruction");
   }
 
@@ -787,27 +795,34 @@ public:
     Value *RHS,     ///< The right-hand-side of the expression
     const std::string &NameStr,  ///< Name of the instruction
     BasicBlock *InsertAtEnd   ///< Block to insert into.
-  ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, NameStr,
+  ) : CmpInst(makeCmpResultType(LHS->getType()),
+              Instruction::FCmp, pred, LHS, RHS, NameStr,
               InsertAtEnd) {
     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
            "Invalid FCmp predicate value");
     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
            "Both operands to FCmp instruction are not of the same type!");
     // Check that the operands are the right type
-    assert(getOperand(0)->getType()->isFloatingPoint() &&
+    assert(getOperand(0)->getType()->isFPOrFPVector() &&
            "Invalid operand types for FCmp instruction");
   }
 
-  /// This also tests for commutativity. If isEquality() returns true then
-  /// the predicate is also commutative. Only the equality predicates are
-  /// commutative.
   /// @returns true if the predicate of this instruction is EQ or NE.
   /// @brief Determine if this is an equality predicate.
   bool isEquality() const {
     return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
            SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
   }
-  bool isCommutative() const { return isEquality(); }
+
+  /// @returns true if the predicate of this instruction is commutative.
+  /// @brief Determine if this is a commutative predicate.
+  bool isCommutative() const {
+    return isEquality() ||
+           SubclassData == FCMP_FALSE ||
+           SubclassData == FCMP_TRUE ||
+           SubclassData == FCMP_ORD ||
+           SubclassData == FCMP_UNO;
+  }
 
   /// @returns true if the predicate is relational (not EQ or NE). 
   /// @brief Determine if this a relational predicate.
@@ -833,6 +848,7 @@ public:
   static inline bool classof(const Value *V) {
     return isa<Instruction>(V) && classof(cast<Instruction>(V));
   }
+  
 };
 
 //===----------------------------------------------------------------------===//
@@ -957,7 +973,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);
@@ -1040,16 +1056,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; }
@@ -1057,78 +1073,79 @@ public:
     SubclassData = (SubclassData & 1) | (CC << 1);
   }
 
-  /// getParamAttrs - Return the parameter attributes for this call.
+  /// getAttributes - Return the parameter attributes for this call.
   ///
-  const PAListPtr &getParamAttrs() const { return ParamAttrs; }
+  const AttrListPtr &getAttributes() const { return AttributeList; }
 
-  /// setParamAttrs - Sets the parameter attributes for this call.
-  void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
+  /// setAttributes - Set the parameter attributes for this call.
+  ///
+  void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
   
-  /// addParamAttr - adds the attribute to the list of attributes.
-  void addParamAttr(unsigned i, ParameterAttributes 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, ParameterAttributes 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 
   /// 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));
   }
@@ -2337,7 +2354,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);
@@ -2415,69 +2432,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; }
 
-  /// @brief Determine whether the call or the callee has the given attribute.
-  bool paramHasAttr(unsigned i, ParameterAttributes attr) const;
-  
-  /// addParamAttr - adds the attribute to the list of attributes.
-  void addParamAttr(unsigned i, ParameterAttributes 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, ParameterAttributes 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;
+  
   /// @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 
   /// 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
@@ -2487,8 +2509,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 {