From 393c054cd2c6c6f2f81f5f0da119ffa9f3531086 Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Wed, 13 May 2015 22:43:09 +0000 Subject: [PATCH] Construct ArrayRef from vector ArrayRef already has a SFINAE constructor which can construct ArrayRef from ArrayRef. 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 --- include/llvm/ADT/ArrayRef.h | 19 +++++++++++++++++++ lib/Transforms/Scalar/LICM.cpp | 2 +- lib/Transforms/Scalar/SROA.cpp | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/llvm/ADT/ArrayRef.h b/include/llvm/ADT/ArrayRef.h index f7b055e3a06..1b2bdffc833 100644 --- a/include/llvm/ADT/ArrayRef.h +++ b/include/llvm/ADT/ArrayRef.h @@ -96,6 +96,25 @@ namespace llvm { std::is_convertible::value>::type* = 0) : Data(A.data()), Length(A.size()) {} + /// Construct an ArrayRef from a SmallVector. This is + /// templated in order to avoid instantiating SmallVectorTemplateCommon + /// whenever we copy-construct an ArrayRef. + template + /*implicit*/ ArrayRef(const SmallVectorTemplateCommon &Vec, + typename std::enable_if< + std::is_convertible::value>::type* = 0) + : Data(Vec.data()), Length(Vec.size()) { + } + + /// Construct an ArrayRef from std::vector. This uses SFINAE + /// to ensure that only vectors of pointers can be converted. + template + ArrayRef(const std::vector &Vec, + typename std::enable_if< + std::is_convertible::value>::type* = 0) + : Data(Vec.data()), Length(Vec.size()) {} + /// @} /// @name Simple Operations /// @{ diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index 1ac15fa8905..3d385c04a90 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/lib/Transforms/Scalar/LICM.cpp @@ -929,7 +929,7 @@ bool llvm::promoteLoopAccessesToScalars(AliasSet &AS, // We use the SSAUpdater interface to insert phi nodes as required. SmallVector NewPHIs; SSAUpdater SSA(&NewPHIs); - LoopPromoter Promoter(SomePtr, makeArrayRef(LoopUses), SSA, + LoopPromoter Promoter(SomePtr, LoopUses, SSA, PointerMustAliases, ExitBlocks, InsertPts, PIC, *CurAST, *LI, DL, Alignment, AATags); diff --git a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp index 2e785807759..056dd11b5ab 100644 --- a/lib/Transforms/Scalar/SROA.cpp +++ b/lib/Transforms/Scalar/SROA.cpp @@ -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(); -- 2.34.1