[PATCH] Make StringMap aware of POD types
Pete Cooper
peter_cooper at apple.com
Tue Mar 18 10:57:50 PDT 2014
Hey Ben
Here’s a patch for the new version. I’ve confirmed what you said that at -O3 this results in ~StringMap() having no loops on POD types and BumpPtrAllocators.
Ok to commit?
Thanks,
Pete
On Mar 17, 2014, at 2:25 PM, Benjamin Kramer <benny.kra at gmail.com> wrote:
>
> On 17.03.2014, at 22:18, Pete Cooper <peter_cooper at apple.com> wrote:
>
>>
>> On Mar 17, 2014, at 1:15 PM, Benjamin Kramer <benny.kra at gmail.com> wrote:
>>
>>>
>>> On 17.03.2014, at 20:38, Chandler Carruth <chandlerc at google.com> wrote:
>>>
>>>>
>>>> On Mon, Mar 17, 2014 at 12:32 PM, Pete Cooper <peter_cooper at apple.com> wrote:
>>>> I was worried about duplication, but actually that might be cleaner. I’ll give that a try now.
>>>>
>>>> If the duplication is a problem, factor that into a private helper function used by both?
>>>
>>> It can be written in two lines, not worth its own function.
>> Agreed.
>>>
>>> for (auto &Entry : this)
>>> Entry.Destroy(Allocator);
>> Thanks for this. Its a nice small snippet. I tweaked it to this:
>>
>> if (!empty()) {
>> for (auto &Entry : *this)
>> Entry.Destroy(Allocator);
>>
>> However, this is still about 10% faster
>>
>>
>> if (!empty()) {
>> for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
>> StringMapEntryBase *&Bucket = TheTable[I];
>> if (Bucket && Bucket != getTombstoneVal()) {
>> static_cast<MapEntryTy*>(Bucket)->Destroy(Allocator);
>> }
>> }
>> }
>>
>> The problem is that iterator++ isn’t getting optimized out. Actually neither is the whole loop I gave, but somehow it runs a bit quicker. I think its failing to inline ++ as it shows up in the trace even on -O3.
>
> The latter loop gets eliminated by clang -O3 if I try it in the dtor of a simple StringMap<void*>. It's probably fine to use this more verbose form, eliminating the iterator loop is surprisingly hard, if possible at all.
>
> - Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140318/d572e5ed/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stringmap.diff
Type: application/octet-stream
Size: 744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140318/d572e5ed/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140318/d572e5ed/attachment-0001.html>
More information about the llvm-commits
mailing list