[llvm] 404f0d4 - Simplify away some SmallVector copies. NFCI.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 26 13:48:10 PDT 2021


Oh, neat! Not sure I would've thought of that!

On Mon, Jul 26, 2021 at 10:35 AM Benjamin Kramer via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> Author: Benjamin Kramer
> Date: 2021-07-26T16:33:38+02:00
> New Revision: 404f0d4f7cc7b7497c9725c6c6f20b21df8611bb
>
> URL:
> https://github.com/llvm/llvm-project/commit/404f0d4f7cc7b7497c9725c6c6f20b21df8611bb
> DIFF:
> https://github.com/llvm/llvm-project/commit/404f0d4f7cc7b7497c9725c6c6f20b21df8611bb.diff
>
> LOG: Simplify away some SmallVector copies. NFCI.
>
> The lifetime of the initializer list is the full expression, so we can
> skip storing it in a temporary vector.
>
> Added:
>
>
> Modified:
>     llvm/include/llvm/IR/Constants.h
>     llvm/include/llvm/IR/DerivedTypes.h
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/include/llvm/IR/Constants.h
> b/llvm/include/llvm/IR/Constants.h
> index 142dc2187450..1f716a45b70f 100644
> --- a/llvm/include/llvm/IR/Constants.h
> +++ b/llvm/include/llvm/IR/Constants.h
> @@ -454,8 +454,7 @@ class ConstantStruct final : public ConstantAggregate {
>    template <typename... Csts>
>    static std::enable_if_t<are_base_of<Constant, Csts...>::value, Constant
> *>
>    get(StructType *T, Csts *...Vs) {
> -    SmallVector<Constant *, 8> Values({Vs...});
> -    return get(T, Values);
> +    return get(T, ArrayRef<Constant *>({Vs...}));
>    }
>
>    /// Return an anonymous struct that has the specified elements.
>
> diff  --git a/llvm/include/llvm/IR/DerivedTypes.h
> b/llvm/include/llvm/IR/DerivedTypes.h
> index 7354aa0525b1..b68a912b5f70 100644
> --- a/llvm/include/llvm/IR/DerivedTypes.h
> +++ b/llvm/include/llvm/IR/DerivedTypes.h
> @@ -244,8 +244,7 @@ class StructType : public Type {
>    static std::enable_if_t<are_base_of<Type, Tys...>::value, StructType *>
>    create(StringRef Name, Type *elt1, Tys *... elts) {
>      assert(elt1 && "Cannot create a struct type with no elements with
> this");
> -    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
> -    return create(StructFields, Name);
> +    return create(ArrayRef<Type *>({elt1, elts...}), Name);
>    }
>
>    /// This static method is the primary way to create a literal
> StructType.
> @@ -263,8 +262,7 @@ class StructType : public Type {
>    get(Type *elt1, Tys *... elts) {
>      assert(elt1 && "Cannot create a struct type with no elements with
> this");
>      LLVMContext &Ctx = elt1->getContext();
> -    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
> -    return llvm::StructType::get(Ctx, StructFields);
> +    return StructType::get(Ctx, ArrayRef<Type *>({elt1, elts...}));
>    }
>
>    /// Return the type with the specified name, or null if there is none
> by that
> @@ -306,8 +304,7 @@ class StructType : public Type {
>    std::enable_if_t<are_base_of<Type, Tys...>::value, void>
>    setBody(Type *elt1, Tys *... elts) {
>      assert(elt1 && "Cannot create a struct type with no elements with
> this");
> -    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
> -    setBody(StructFields);
> +    setBody(ArrayRef<Type *>({elt1, elts...}));
>    }
>
>    /// Return true if the specified type is valid as a element type.
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210726/394a4497/attachment.html>


More information about the llvm-commits mailing list