diff options
author | Jay Foad <jay.foad@gmail.com> | 2011-07-13 10:26:04 +0000 |
---|---|---|
committer | Jay Foad <jay.foad@gmail.com> | 2011-07-13 10:26:04 +0000 |
commit | fc6d3a49867cd38954dc40936a88f1907252c6d2 (patch) | |
tree | 427850758eca130b1354d38d7281569bb3528c52 /include/llvm | |
parent | 5d4f9909c49d28db9572acc4513c1a695b0c53da (diff) | |
download | llvm-fc6d3a49867cd38954dc40936a88f1907252c6d2.tar.gz llvm-fc6d3a49867cd38954dc40936a88f1907252c6d2.tar.bz2 llvm-fc6d3a49867cd38954dc40936a88f1907252c6d2.tar.xz |
Convert InsertValueInst and ExtractValueInst APIs to use ArrayRef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135040 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/Analysis/ValueTracking.h | 12 | ||||
-rw-r--r-- | include/llvm/CodeGen/Analysis.h | 7 | ||||
-rw-r--r-- | include/llvm/Constants.h | 5 | ||||
-rw-r--r-- | include/llvm/Instructions.h | 208 | ||||
-rw-r--r-- | include/llvm/Support/ConstantFolder.h | 10 | ||||
-rw-r--r-- | include/llvm/Support/IRBuilder.h | 34 | ||||
-rw-r--r-- | include/llvm/Support/NoFolder.h | 12 | ||||
-rw-r--r-- | include/llvm/Support/TargetFolder.h | 11 |
8 files changed, 70 insertions, 229 deletions
diff --git a/include/llvm/Analysis/ValueTracking.h b/include/llvm/Analysis/ValueTracking.h index d4354bb3ff..68263300c7 100644 --- a/include/llvm/Analysis/ValueTracking.h +++ b/include/llvm/Analysis/ValueTracking.h @@ -15,6 +15,7 @@ #ifndef LLVM_ANALYSIS_VALUETRACKING_H #define LLVM_ANALYSIS_VALUETRACKING_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/Support/DataTypes.h" #include <string> @@ -108,18 +109,9 @@ namespace llvm { /// If InsertBefore is not null, this function will duplicate (modified) /// insertvalues when a part of a nested struct is extracted. Value *FindInsertedValue(Value *V, - const unsigned *idx_begin, - const unsigned *idx_end, + ArrayRef<unsigned> idx_range, Instruction *InsertBefore = 0); - /// This is a convenience wrapper for finding values indexed by a single index - /// only. - inline Value *FindInsertedValue(Value *V, const unsigned Idx, - Instruction *InsertBefore = 0) { - const unsigned Idxs[1] = { Idx }; - return FindInsertedValue(V, &Idxs[0], &Idxs[1], InsertBefore); - } - /// GetPointerBaseWithConstantOffset - Analyze the specified pointer to see if /// it can be expressed as a base pointer plus a constant offset. Return the /// base and offset to the caller. diff --git a/include/llvm/CodeGen/Analysis.h b/include/llvm/CodeGen/Analysis.h index 78bf9fc11a..f8a70293c1 100644 --- a/include/llvm/CodeGen/Analysis.h +++ b/include/llvm/CodeGen/Analysis.h @@ -16,6 +16,7 @@ #include "llvm/Instructions.h" #include "llvm/InlineAsm.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/CodeGen/ValueTypes.h" #include "llvm/CodeGen/ISDOpcodes.h" @@ -37,6 +38,12 @@ unsigned ComputeLinearIndex(const Type *Ty, const unsigned *IndicesEnd, unsigned CurIndex = 0); +inline unsigned ComputeLinearIndex(const Type *Ty, + ArrayRef<unsigned> Indices, + unsigned CurIndex = 0) { + return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex); +} + /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of /// EVTs that represent all the individual underlying /// non-aggregate types that comprise it. diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index db95217796..462d7f01b0 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -855,10 +855,9 @@ public: static Constant *getExtractElement(Constant *Vec, Constant *Idx); static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx); static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask); - static Constant *getExtractValue(Constant *Agg, - const unsigned *IdxList, unsigned NumIdx); + static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs); static Constant *getInsertValue(Constant *Agg, Constant *Val, - const unsigned *IdxList, unsigned NumIdx); + ArrayRef<unsigned> Idxs); /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 4e20d889cb..3472059637 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -20,6 +20,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Attributes.h" #include "llvm/CallingConv.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include <iterator> @@ -1428,70 +1429,18 @@ class ExtractValueInst : public UnaryInstruction { SmallVector<unsigned, 4> Indices; ExtractValueInst(const ExtractValueInst &EVI); - void init(const unsigned *Idx, unsigned NumIdx, - const Twine &NameStr); - void init(unsigned Idx, const Twine &NameStr); - - template<typename RandomAccessIterator> - void init(RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, - const Twine &NameStr, - // This argument ensures that we have an iterator we can - // 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 - // present need to support it. - assert(NumIdx > 0 && "ExtractValueInst must have at least one index"); - - // This requires that the iterator points to contiguous memory. - init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case - // we have to build an array here - } - - /// getIndexedType - Returns the type of the element that would be extracted - /// with an extractvalue instruction with the specified parameters. - /// - /// Null is returned if the indices are invalid for the specified type. - /// - /// FIXME: Use ArrayRef - static Type *getIndexedType(const Type *Agg, - const unsigned *Idx, unsigned NumIdx); - - template<typename RandomAccessIterator> - static Type *getIndexedType(const Type *Ptr, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, - // This argument ensures that we - // have an iterator we can 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. - return getIndexedType(Ptr, &*IdxBegin, NumIdx); - else - return getIndexedType(Ptr, (const unsigned *)0, NumIdx); - } + void init(ArrayRef<unsigned> Idxs, const Twine &NameStr); /// Constructors - Create a extractvalue instruction with a base aggregate /// value and a list of indices. The first ctor can optionally insert before /// an existing instruction, the second appends the new instruction to the /// specified BasicBlock. - template<typename RandomAccessIterator> inline ExtractValueInst(Value *Agg, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, Instruction *InsertBefore); - template<typename RandomAccessIterator> inline ExtractValueInst(Value *Agg, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, BasicBlock *InsertAtEnd); // allocate space for exactly one operand @@ -1502,55 +1451,25 @@ protected: virtual ExtractValueInst *clone_impl() const; public: - template<typename RandomAccessIterator> static ExtractValueInst *Create(Value *Agg, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr = "", Instruction *InsertBefore = 0) { return new - ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore); + ExtractValueInst(Agg, Idxs, NameStr, InsertBefore); } - template<typename RandomAccessIterator> static ExtractValueInst *Create(Value *Agg, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, BasicBlock *InsertAtEnd) { - return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd); - } - - /// Constructors - These two creators are convenience methods because one - /// index extractvalue instructions are much more common than those with - /// more than one. - static ExtractValueInst *Create(Value *Agg, unsigned Idx, - const Twine &NameStr = "", - Instruction *InsertBefore = 0) { - unsigned Idxs[1] = { Idx }; - return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore); - } - static ExtractValueInst *Create(Value *Agg, unsigned Idx, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { - unsigned Idxs[1] = { Idx }; - return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd); + return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd); } /// getIndexedType - Returns the type of the element that would be extracted /// with an extractvalue instruction with the specified parameters. /// /// Null is returned if the indices are invalid for the specified type. - /// - /// FIXME: Remove the templates and just use ArrayRef. - template<typename RandomAccessIterator> - static Type *getIndexedType(const Type *Ptr, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd) { - return getIndexedType(Ptr, IdxBegin, IdxEnd, - typename std::iterator_traits<RandomAccessIterator>:: - iterator_category()); - } - static Type *getIndexedType(const Type *Ptr, unsigned Idx); + static Type *getIndexedType(const Type *Agg, ArrayRef<unsigned> Idxs); typedef const unsigned* idx_iterator; inline idx_iterator idx_begin() const { return Indices.begin(); } @@ -1566,7 +1485,11 @@ public: return 0U; // get index for modifying correct operand } - unsigned getNumIndices() const { // Note: always non-negative + ArrayRef<unsigned> getIndices() const { + return Indices; + } + + unsigned getNumIndices() const { return (unsigned)Indices.size(); } @@ -1584,31 +1507,21 @@ public: } }; -template<typename RandomAccessIterator> ExtractValueInst::ExtractValueInst(Value *Agg, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, Instruction *InsertBefore) - : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), - IdxBegin, IdxEnd)), + : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), ExtractValue, Agg, InsertBefore) { - init(IdxBegin, IdxEnd, NameStr, - typename std::iterator_traits<RandomAccessIterator> - ::iterator_category()); + init(Idxs, NameStr); } -template<typename RandomAccessIterator> ExtractValueInst::ExtractValueInst(Value *Agg, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, BasicBlock *InsertAtEnd) - : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), - IdxBegin, IdxEnd)), + : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), ExtractValue, Agg, InsertAtEnd) { - init(IdxBegin, IdxEnd, NameStr, - typename std::iterator_traits<RandomAccessIterator> - ::iterator_category()); + init(Idxs, NameStr); } @@ -1624,44 +1537,19 @@ class InsertValueInst : public Instruction { void *operator new(size_t, unsigned); // Do not implement InsertValueInst(const InsertValueInst &IVI); - void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx, + void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs, const Twine &NameStr); - void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr); - - template<typename RandomAccessIterator> - void init(Value *Agg, Value *Val, - RandomAccessIterator IdxBegin, RandomAccessIterator IdxEnd, - const Twine &NameStr, - // This argument ensures that we have an iterator we can - // 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 - // present need to support it. - assert(NumIdx > 0 && "InsertValueInst must have at least one index"); - - // This requires that the iterator points to contiguous memory. - init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case - // we have to build an array here - } /// Constructors - Create a insertvalue instruction with a base aggregate /// value, a value to insert, and a list of indices. The first ctor can /// optionally insert before an existing instruction, the second appends /// the new instruction to the specified BasicBlock. - template<typename RandomAccessIterator> inline InsertValueInst(Value *Agg, Value *Val, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, Instruction *InsertBefore); - template<typename RandomAccessIterator> inline InsertValueInst(Value *Agg, Value *Val, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, BasicBlock *InsertAtEnd); /// Constructors - These two constructors are convenience methods because one @@ -1679,37 +1567,17 @@ public: return User::operator new(s, 2); } - template<typename RandomAccessIterator> static InsertValueInst *Create(Value *Agg, Value *Val, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr = "", Instruction *InsertBefore = 0) { - return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd, - NameStr, InsertBefore); + return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore); } - template<typename RandomAccessIterator> static InsertValueInst *Create(Value *Agg, Value *Val, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, BasicBlock *InsertAtEnd) { - return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd, - NameStr, InsertAtEnd); - } - - /// Constructors - These two creators are convenience methods because one - /// index insertvalue instructions are much more common than those with - /// more than one. - static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx, - const Twine &NameStr = "", - Instruction *InsertBefore = 0) { - return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore); - } - static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { - return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd); + return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd); } /// Transparently provide more efficient getOperand methods. @@ -1739,7 +1607,11 @@ public: return 1U; // get index for modifying correct operand } - unsigned getNumIndices() const { // Note: always non-negative + ArrayRef<unsigned> getIndices() const { + return Indices; + } + + unsigned getNumIndices() const { return (unsigned)Indices.size(); } @@ -1762,33 +1634,25 @@ struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<InsertValueInst, 2> { }; -template<typename RandomAccessIterator> InsertValueInst::InsertValueInst(Value *Agg, Value *Val, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, Instruction *InsertBefore) : Instruction(Agg->getType(), InsertValue, OperandTraits<InsertValueInst>::op_begin(this), 2, InsertBefore) { - init(Agg, Val, IdxBegin, IdxEnd, NameStr, - typename std::iterator_traits<RandomAccessIterator> - ::iterator_category()); + init(Agg, Val, Idxs, NameStr); } -template<typename RandomAccessIterator> InsertValueInst::InsertValueInst(Value *Agg, Value *Val, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &NameStr, BasicBlock *InsertAtEnd) : Instruction(Agg->getType(), InsertValue, OperandTraits<InsertValueInst>::op_begin(this), 2, InsertAtEnd) { - init(Agg, Val, IdxBegin, IdxEnd, NameStr, - typename std::iterator_traits<RandomAccessIterator> - ::iterator_category()); + init(Agg, Val, Idxs, NameStr); } DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) diff --git a/include/llvm/Support/ConstantFolder.h b/include/llvm/Support/ConstantFolder.h index d0eaa3e487..733023566a 100644 --- a/include/llvm/Support/ConstantFolder.h +++ b/include/llvm/Support/ConstantFolder.h @@ -210,14 +210,14 @@ public: return ConstantExpr::getShuffleVector(V1, V2, Mask); } - Constant *CreateExtractValue(Constant *Agg, const unsigned *IdxList, - unsigned NumIdx) const { - return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx); + Constant *CreateExtractValue(Constant *Agg, + ArrayRef<unsigned> IdxList) const { + return ConstantExpr::getExtractValue(Agg, IdxList); } Constant *CreateInsertValue(Constant *Agg, Constant *Val, - const unsigned *IdxList, unsigned NumIdx) const { - return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx); + ArrayRef<unsigned> IdxList) const { + return ConstantExpr::getInsertValue(Agg, Val, IdxList); } }; diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index deea572348..6bdbfbb344 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -1194,43 +1194,21 @@ public: return Insert(new ShuffleVectorInst(V1, V2, Mask), Name); } - Value *CreateExtractValue(Value *Agg, unsigned Idx, - const Twine &Name = "") { - if (Constant *AggC = dyn_cast<Constant>(Agg)) - return Insert(Folder.CreateExtractValue(AggC, &Idx, 1), Name); - return Insert(ExtractValueInst::Create(Agg, Idx), Name); - } - - template<typename RandomAccessIterator> Value *CreateExtractValue(Value *Agg, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &Name = "") { if (Constant *AggC = dyn_cast<Constant>(Agg)) - return Insert(Folder.CreateExtractValue(AggC, IdxBegin, IdxEnd-IdxBegin), - Name); - return Insert(ExtractValueInst::Create(Agg, IdxBegin, IdxEnd), Name); + return Insert(Folder.CreateExtractValue(AggC, Idxs), Name); + return Insert(ExtractValueInst::Create(Agg, Idxs), Name); } - Value *CreateInsertValue(Value *Agg, Value *Val, unsigned Idx, - const Twine &Name = "") { - if (Constant *AggC = dyn_cast<Constant>(Agg)) - if (Constant *ValC = dyn_cast<Constant>(Val)) - return Insert(Folder.CreateInsertValue(AggC, ValC, &Idx, 1), Name); - return Insert(InsertValueInst::Create(Agg, Val, Idx), Name); - } - - template<typename RandomAccessIterator> Value *CreateInsertValue(Value *Agg, Value *Val, - RandomAccessIterator IdxBegin, - RandomAccessIterator IdxEnd, + ArrayRef<unsigned> Idxs, const Twine &Name = "") { if (Constant *AggC = dyn_cast<Constant>(Agg)) if (Constant *ValC = dyn_cast<Constant>(Val)) - return Insert(Folder.CreateInsertValue(AggC, ValC, IdxBegin, - IdxEnd - IdxBegin), - Name); - return Insert(InsertValueInst::Create(Agg, Val, IdxBegin, IdxEnd), Name); + return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name); + return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name); } //===--------------------------------------------------------------------===// diff --git a/include/llvm/Support/NoFolder.h b/include/llvm/Support/NoFolder.h index 5ead26ec25..94359a5328 100644 --- a/include/llvm/Support/NoFolder.h +++ b/include/llvm/Support/NoFolder.h @@ -22,6 +22,7 @@ #ifndef LLVM_SUPPORT_NOFOLDER_H #define LLVM_SUPPORT_NOFOLDER_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/Constants.h" #include "llvm/Instructions.h" @@ -269,15 +270,14 @@ public: return new ShuffleVectorInst(V1, V2, Mask); } - Instruction *CreateExtractValue(Constant *Agg, const unsigned *IdxList, - unsigned NumIdx) const { - return ExtractValueInst::Create(Agg, IdxList, IdxList+NumIdx); + Instruction *CreateExtractValue(Constant *Agg, + ArrayRef<unsigned> IdxList) const { + return ExtractValueInst::Create(Agg, IdxList); } Instruction *CreateInsertValue(Constant *Agg, Constant *Val, - const unsigned *IdxList, - unsigned NumIdx) const { - return InsertValueInst::Create(Agg, Val, IdxList, IdxList+NumIdx); + ArrayRef<unsigned> IdxList) const { + return InsertValueInst::Create(Agg, Val, IdxList); } }; diff --git a/include/llvm/Support/TargetFolder.h b/include/llvm/Support/TargetFolder.h index 20ca5571ff..3233a98da9 100644 --- a/include/llvm/Support/TargetFolder.h +++ b/include/llvm/Support/TargetFolder.h @@ -21,6 +21,7 @@ #include "llvm/Constants.h" #include "llvm/InstrTypes.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/Analysis/ConstantFolding.h" namespace llvm { @@ -226,14 +227,14 @@ public: return Fold(ConstantExpr::getShuffleVector(V1, V2, Mask)); } - Constant *CreateExtractValue(Constant *Agg, const unsigned *IdxList, - unsigned NumIdx) const { - return Fold(ConstantExpr::getExtractValue(Agg, IdxList, NumIdx)); + Constant *CreateExtractValue(Constant *Agg, + ArrayRef<unsigned> IdxList) const { + return Fold(ConstantExpr::getExtractValue(Agg, IdxList)); } Constant *CreateInsertValue(Constant *Agg, Constant *Val, - const unsigned *IdxList, unsigned NumIdx) const { - return Fold(ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx)); + ArrayRef<unsigned> IdxList) const { + return Fold(ConstantExpr::getInsertValue(Agg, Val, IdxList)); } }; |