Construct ArrayRef<const T*> from vector<T>

ArrayRef already has a SFINAE constructor which can construct ArrayRef<const T*> from ArrayRef<T*>.

This adds methods to do the same directly from SmallVector and std::vector.  This avoids an intermediate step through the use of makeArrayRef.

Also update the users of this in LICM and SROA to remove the now unnecessary makeArrayRef call.

Reviewed by David Blaikie.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237309 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper 2015-05-13 22:43:09 +00:00
parent 933e6287fe
commit 393c054cd2
3 changed files with 21 additions and 2 deletions

View File

@ -96,6 +96,25 @@ namespace llvm {
std::is_convertible<U *const *, T const *>::value>::type* = 0)
: Data(A.data()), Length(A.size()) {}
/// Construct an ArrayRef<const T*> from a SmallVector<T*>. This is
/// templated in order to avoid instantiating SmallVectorTemplateCommon<T>
/// whenever we copy-construct an ArrayRef.
template<typename U, typename DummyT>
/*implicit*/ ArrayRef(const SmallVectorTemplateCommon<U*, DummyT> &Vec,
typename std::enable_if<
std::is_convertible<U *const *,
T const *>::value>::type* = 0)
: Data(Vec.data()), Length(Vec.size()) {
}
/// Construct an ArrayRef<const T*> from std::vector<T*>. This uses SFINAE
/// to ensure that only vectors of pointers can be converted.
template<typename U, typename A>
ArrayRef(const std::vector<U *, A> &Vec,
typename std::enable_if<
std::is_convertible<U *const *, T const *>::value>::type* = 0)
: Data(Vec.data()), Length(Vec.size()) {}
/// @}
/// @name Simple Operations
/// @{

View File

@ -929,7 +929,7 @@ bool llvm::promoteLoopAccessesToScalars(AliasSet &AS,
// We use the SSAUpdater interface to insert phi nodes as required.
SmallVector<PHINode*, 16> NewPHIs;
SSAUpdater SSA(&NewPHIs);
LoopPromoter Promoter(SomePtr, makeArrayRef(LoopUses), SSA,
LoopPromoter Promoter(SomePtr, LoopUses, SSA,
PointerMustAliases, ExitBlocks,
InsertPts, PIC, *CurAST, *LI, DL, Alignment, AATags);

View File

@ -4419,7 +4419,7 @@ bool SROA::promoteAllocas(Function &F) {
DeadInsts.push_back(I);
enqueueUsersInWorklist(*I, Worklist, Visited);
}
AllocaPromoter(makeArrayRef(Insts), SSA, *AI, DIB).run(Insts);
AllocaPromoter(Insts, SSA, *AI, DIB).run(Insts);
while (!DeadInsts.empty())
DeadInsts.pop_back_val()->eraseFromParent();
AI->eraseFromParent();