X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm%2FIR%2FInstructions.h;h=99c5b67e9db6db12e71f3a3ba37cfe8ab79a0bd1;hp=91775499388338efc97af665b700af770dc0c3c2;hb=af1023588ed0de9c64f7e96922eb147995fad6d5;hpb=66981fe20809820e30dc19ea37ff7487eb67a96f diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index 91775499388..99c5b67e9db 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -180,7 +180,12 @@ public: unsigned Align, Instruction *InsertBefore = nullptr); LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, BasicBlock *InsertAtEnd); - LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, + LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, + AtomicOrdering Order, SynchronizationScope SynchScope = CrossThread, + Instruction *InsertBefore = nullptr) + : LoadInst(cast(Ptr->getType())->getElementType(), Ptr, + NameStr, isVolatile, Align, Order, SynchScope, InsertBefore) {} + LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, AtomicOrdering Order, SynchronizationScope SynchScope = CrossThread, Instruction *InsertBefore = nullptr); @@ -794,28 +799,31 @@ class GetElementPtrInst : public Instruction { /// list of indices. The first ctor can optionally insert before an existing /// instruction, the second appends the new instruction to the specified /// BasicBlock. - inline GetElementPtrInst(Value *Ptr, ArrayRef IdxList, - unsigned Values, const Twine &NameStr, - Instruction *InsertBefore); - inline GetElementPtrInst(Value *Ptr, ArrayRef IdxList, - unsigned Values, const Twine &NameStr, - BasicBlock *InsertAtEnd); + inline GetElementPtrInst(Type *PointeeType, Value *Ptr, + ArrayRef IdxList, unsigned Values, + const Twine &NameStr, Instruction *InsertBefore); + inline GetElementPtrInst(Type *PointeeType, Value *Ptr, + ArrayRef IdxList, unsigned Values, + const Twine &NameStr, BasicBlock *InsertAtEnd); + protected: GetElementPtrInst *clone_impl() const override; public: - static GetElementPtrInst *Create(Value *Ptr, ArrayRef IdxList, + static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr, + ArrayRef IdxList, const Twine &NameStr = "", Instruction *InsertBefore = nullptr) { unsigned Values = 1 + unsigned(IdxList.size()); - return new(Values) - GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore); + return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values, + NameStr, InsertBefore); } - static GetElementPtrInst *Create(Value *Ptr, ArrayRef IdxList, + static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr, + ArrayRef IdxList, const Twine &NameStr, BasicBlock *InsertAtEnd) { unsigned Values = 1 + unsigned(IdxList.size()); - return new(Values) - GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd); + return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values, + NameStr, InsertAtEnd); } /// Create an "inbounds" getelementptr. See the documentation for the @@ -824,7 +832,14 @@ public: ArrayRef IdxList, const Twine &NameStr = "", Instruction *InsertBefore = nullptr){ - GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore); + return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore); + } + static GetElementPtrInst * + CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef IdxList, + const Twine &NameStr = "", + Instruction *InsertBefore = nullptr) { + GetElementPtrInst *GEP = + Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore); GEP->setIsInBounds(true); return GEP; } @@ -832,7 +847,14 @@ public: ArrayRef IdxList, const Twine &NameStr, BasicBlock *InsertAtEnd) { - GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd); + return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd); + } + static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr, + ArrayRef IdxList, + const Twine &NameStr, + BasicBlock *InsertAtEnd) { + GetElementPtrInst *GEP = + Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd); GEP->setIsInBounds(true); return GEP; } @@ -845,6 +867,13 @@ public: return cast(Instruction::getType()); } + Type *getSourceElementType() const { + return cast(getPointerOperandType()->getScalarType()) + ->getElementType(); + } + + Type *getResultElementType() const { return getType()->getElementType(); } + /// \brief Returns the address space of this instruction's pointer type. unsigned getAddressSpace() const { // Note that this is always the same as the pointer operand's address space @@ -858,9 +887,9 @@ public: /// Null is returned if the indices are invalid for the specified /// pointer type. /// - static Type *getIndexedType(Type *Ptr, ArrayRef IdxList); - static Type *getIndexedType(Type *Ptr, ArrayRef IdxList); - static Type *getIndexedType(Type *Ptr, ArrayRef IdxList); + static Type *getIndexedType(Type *Ty, ArrayRef IdxList); + static Type *getIndexedType(Type *Ty, ArrayRef IdxList); + static Type *getIndexedType(Type *Ty, ArrayRef IdxList); inline op_iterator idx_begin() { return op_begin()+1; } inline const_op_iterator idx_begin() const { return op_begin()+1; } @@ -891,9 +920,12 @@ public: /// GetGEPReturnType - Returns the pointer type returned by the GEP /// instruction, which may be a vector of pointers. static Type *getGEPReturnType(Value *Ptr, ArrayRef IdxList) { - Type *PtrTy = PointerType::get(checkGEPType( - getIndexedType(Ptr->getType(), IdxList)), - Ptr->getType()->getPointerAddressSpace()); + Type *PtrTy = + PointerType::get(checkGEPType(getIndexedType( + cast(Ptr->getType()->getScalarType()) + ->getElementType(), + IdxList)), + Ptr->getType()->getPointerAddressSpace()); // Vector GEP if (Ptr->getType()->isVectorTy()) { unsigned NumElem = cast(Ptr->getType())->getNumElements(); @@ -953,27 +985,25 @@ struct OperandTraits : public VariadicOperandTraits { }; -GetElementPtrInst::GetElementPtrInst(Value *Ptr, - ArrayRef IdxList, - unsigned Values, +GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, + ArrayRef IdxList, unsigned Values, const Twine &NameStr, Instruction *InsertBefore) - : Instruction(getGEPReturnType(Ptr, IdxList), - GetElementPtr, - OperandTraits::op_end(this) - Values, - Values, InsertBefore) { + : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr, + OperandTraits::op_end(this) - Values, + Values, InsertBefore) { init(Ptr, IdxList, NameStr); + assert(!PointeeType || PointeeType == getSourceElementType()); } -GetElementPtrInst::GetElementPtrInst(Value *Ptr, - ArrayRef IdxList, - unsigned Values, +GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, + ArrayRef IdxList, unsigned Values, const Twine &NameStr, BasicBlock *InsertAtEnd) - : Instruction(getGEPReturnType(Ptr, IdxList), - GetElementPtr, - OperandTraits::op_end(this) - Values, - Values, InsertAtEnd) { + : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr, + OperandTraits::op_end(this) - Values, + Values, InsertAtEnd) { init(Ptr, IdxList, NameStr); + assert(!PointeeType || PointeeType == getSourceElementType()); } @@ -1194,11 +1224,15 @@ public: /// @returns true if the predicate of this instruction is EQ or NE. /// \brief Determine if this is an equality predicate. - bool isEquality() const { - return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE || - getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE; + static bool isEquality(Predicate Pred) { + return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ || + Pred == FCMP_UNE; } + /// @returns true if the predicate of this instruction is EQ or NE. + /// \brief Determine if this is an equality predicate. + bool isEquality() const { return isEquality(getPredicate()); } + /// @returns true if the predicate of this instruction is commutative. /// \brief Determine if this is a commutative predicate. bool isCommutative() const { @@ -1901,6 +1935,9 @@ public: typedef const unsigned* idx_iterator; inline idx_iterator idx_begin() const { return Indices.begin(); } inline idx_iterator idx_end() const { return Indices.end(); } + inline iterator_range indices() const { + return iterator_range(idx_begin(), idx_end()); + } Value *getAggregateOperand() { return getOperand(0); @@ -2012,6 +2049,9 @@ public: typedef const unsigned* idx_iterator; inline idx_iterator idx_begin() const { return Indices.begin(); } inline idx_iterator idx_end() const { return Indices.end(); } + inline iterator_range indices() const { + return iterator_range(idx_begin(), idx_end()); + } Value *getAggregateOperand() { return getOperand(0); @@ -2166,6 +2206,8 @@ public: return block_begin() + getNumOperands(); } + op_range incoming_values() { return operands(); } + /// getNumIncomingValues - Return the number of incoming edges /// unsigned getNumIncomingValues() const { return getNumOperands(); } @@ -3059,7 +3101,7 @@ public: /// removeAttribute - removes the attribute from the list of attributes. void removeAttribute(unsigned i, Attribute attr); - /// \brief removes the dereferenceable attribute to the list of attributes. + /// \brief adds the dereferenceable attribute to the list of attributes. void addDereferenceableAttr(unsigned i, uint64_t Bytes); /// \brief Determine whether this call has the given attribute.