[llvm] r223806 - Fix a GCC build failure from r223802

David Blaikie dblaikie at gmail.com
Tue Dec 9 11:02:53 PST 2014


On Tue, Dec 9, 2014 at 10:52 AM, Duncan P. N. Exon Smith <
dexonsmith at apple.com> wrote:

> Author: dexonsmith
> Date: Tue Dec  9 12:52:38 2014
> New Revision: 223806
>
> URL: http://llvm.org/viewvc/llvm-project?rev=223806&view=rev
> Log:
> Fix a GCC build failure from r223802
>
> Modified:
>     llvm/trunk/lib/IR/Metadata.cpp
>
> Modified: llvm/trunk/lib/IR/Metadata.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=223806&r1=223805&r2=223806&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/Metadata.cpp (original)
> +++ llvm/trunk/lib/IR/Metadata.cpp Tue Dec  9 12:52:38 2014
> @@ -341,7 +341,8 @@ MDString *MDString::get(LLVMContext &Con
>    if (I != Store.end())
>      return &I->second;
>
> -  auto *Entry = StringMapEntry<MDString>::Create(Str,
> Store.getAllocator());
> +  auto *Entry =
> +      StringMapEntry<MDString>::Create(Str, Store.getAllocator(),
> MDString());
>

Looks like this whole function could maybe be a bit simpler (& avoid the
double lookup on first access, as well as the raw StringMapEntry<>::Create):

auto &IterBool = Store.insert(std::make_pair(Str, MDString()));
if (IterBool.second)
  IterBool.first->second.Entry = &*IterBool.first;
return &IterBool.first->second;

(I'm not even sure it's worth the conditional? Maybe the unconditional
assignment is cheaper?)

(at some point I think we might be able to avoid exposing the ability to
manually create/insert/etc StringMapEntries & pretend, as much as possible,
that they're just a pair like a normal map)

(and I wouldn't mind if this function returned a reference instead of a
pointer, but I realize that's just my own aesthetic preference and a lot of
work to make the change that might not be better)


>    bool WasInserted = Store.insert(Entry);
>    (void)WasInserted;
>    assert(WasInserted && "Expected entry to be inserted");
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141209/cae7a7c9/attachment.html>


More information about the llvm-commits mailing list