[llvm] r266909 - IR: Use SmallVector instead of std::vector of TrackingMDRef

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 13:59:13 PDT 2016


> On 2016-Apr-20, at 13:28, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Wed, Apr 20, 2016 at 1:14 PM, Duncan P. N. Exon Smith via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> Author: dexonsmith
> Date: Wed Apr 20 15:14:09 2016
> New Revision: 266909
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=266909&view=rev
> Log:
> IR: Use SmallVector instead of std::vector of TrackingMDRef
> 
> Don't use std::vector<TrackingMDRef>, since (at least in some versions
> of libc++) std::vector apparently copies values on grow operations
> instead of moving them.  Found this when I was temporarily deleting the
> copy constructor for TrackingMDRef to investigate a performance
> bottleneck.
> 
> Got a build log? That seems unlikely, since we have vectors of unique_ptr in the codebase. Perhaps you used some specific operation that required a copy?
> 
> I imagine the append you had in the previous patch? Should've been an append with move_iterators? (& maybe that should've been 'assign' instead, I think - in passing)

It's the `emplace_back()` calls.


>  
> 
> Modified:
>     llvm/trunk/include/llvm/IR/DIBuilder.h
>     llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
>     llvm/trunk/lib/IR/DIBuilder.cpp
> 
> Modified: llvm/trunk/include/llvm/IR/DIBuilder.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=266909&r1=266908&r2=266909&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/DIBuilder.h (original)
> +++ llvm/trunk/include/llvm/IR/DIBuilder.h Wed Apr 20 15:14:09 2016
> @@ -51,7 +51,11 @@ namespace llvm {
>      bool AllowUnresolvedNodes;
> 
>      /// Each subprogram's preserved local variables.
> -    DenseMap<MDNode *, std::vector<TrackingMDNodeRef>> PreservedVariables;
> +    ///
> +    /// Do not use a std::vector.  Some versions of libc++ apparently copy
> +    /// instead of move on grow operations, and TrackingMDRef is expensive to
> +    /// copy.
> +    DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> PreservedVariables;
> 
>      DIBuilder(const DIBuilder &) = delete;
>      void operator=(const DIBuilder &) = delete;
> 
> Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=266909&r1=266908&r2=266909&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Wed Apr 20 15:14:09 2016
> @@ -107,7 +107,12 @@ class BitcodeReaderMetadataList {
>    bool AnyFwdRefs;
>    unsigned MinFwdRef;
>    unsigned MaxFwdRef;
> -  std::vector<TrackingMDRef> MetadataPtrs;
> +
> +  /// Array of metadata references.
> +  ///
> +  /// Don't use std::vector here.  Some versions of libc++ copy (instead of
> +  /// move) on resize, and TrackingMDRef is very expensive to copy.
> +  SmallVector<TrackingMDRef, 1> MetadataPtrs;
> 
>    LLVMContext &Context;
>  public:
> 
> Modified: llvm/trunk/lib/IR/DIBuilder.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=266909&r1=266908&r2=266909&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/DIBuilder.cpp (original)
> +++ llvm/trunk/lib/IR/DIBuilder.cpp Wed Apr 20 15:14:09 2016
> @@ -614,7 +614,7 @@ DIGlobalVariable *DIBuilder::createTempG
> 
>  static DILocalVariable *createLocalVariable(
>      LLVMContext &VMContext,
> -    DenseMap<MDNode *, std::vector<TrackingMDNodeRef>> &PreservedVariables,
> +    DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
>      DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
>      unsigned LineNo, DIType *Ty, bool AlwaysPreserve, unsigned Flags) {
>    // FIXME: Why getNonCompileUnitScope()?
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 



More information about the llvm-commits mailing list