This is an archive of the discontinued LLVM Phabricator instance.

[NFC][llvm][StringMap]Extract createTable and getHashTable functions and add the inline attribute to the getMinBucketToReserveForEntries function.
ClosedPublic

Authored by yihanaa on Mar 17 2022, 10:55 AM.

Details

Summary
  1. Extract createTable and getHashTable functions.
  2. Add the inline attribute to the getMinBucketToReserveForEntries function.
  3. Remove unnecessary local variable HTSize.

Statements in the following order appear in llvm::StringMapImpl::init and llvm::StringMapImpl::RehashTable, so I extracted this code into a function. getHashTable is for the same reason, it appears in llvm::StringMapImpl::FindKey, llvm::StringMapImpl::LookupBucketFor and llvm::StringMapImpl::RehashTable.

auto **Table = static_cast<StringMapEntryBase **>(safe_calloc(
      NewNumBuckets + 1, sizeof(StringMapEntryBase **) + sizeof(unsigned)));

  // Allocate one extra bucket, set it to look filled so the iterators stop at
  // end.
  Table[NewNumBuckets] = (StringMapEntryBase *)2;
unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1);

Diff Detail

Event Timeline

yihanaa created this revision.Mar 17 2022, 10:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 10:55 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
yihanaa requested review of this revision.Mar 17 2022, 10:55 AM

Thanks for adding me. I Just add some little comments since I'm not an expert about this. Maybe others could have a look.

llvm/lib/Support/StringMap.cpp
86–87

The { and } are unnecessary since there is only a single line in if.

220–221

I'm not sure this comment is necessary since the function createTable already has an internal comment.

Thanks for adding me. I Just add some little comments since I'm not an expert about this. Maybe others could have a look.

Thanks for your suggestion, i will remove these useless comments and re-upload the patch.

skan added a comment.Mar 17 2022, 8:00 PM

it's a NFC patch?

skan added inline comments.Mar 17 2022, 8:14 PM
llvm/lib/Support/StringMap.cpp
21

This change is not reflected in the commit message...

57–65

I am not an expert here, Is it always safe to change the order of the three statements?

yihanaa updated this revision to Diff 416387.Mar 17 2022, 10:19 PM
  1. Reflected all the changes in the commit message.
  2. Added some more detailed descriptions.
yihanaa retitled this revision from [llvm][StringMap]Extract createTable and getHashTable functions. to [NFC][llvm][StringMap]Extract createTable and getHashTable functions and add the inline attribute to the getMinBucketToReserveForEntries function..Mar 17 2022, 10:30 PM
yihanaa edited the summary of this revision. (Show Details)

it's a NFC patch?

it is an NFC patch

yihanaa marked 4 inline comments as done.
yihanaa added inline comments.
llvm/lib/Support/StringMap.cpp
57–65

I have updated the summary.

yihanaa updated this revision to Diff 416405.Mar 17 2022, 11:57 PM
yihanaa marked an inline comment as done.

Reformat code.

yihanaa edited reviewers, added: gchatelet; removed: pengfei.Mar 18 2022, 7:19 AM
skan accepted this revision.Mar 22 2022, 1:06 AM

LGTM. The change is straightforward so far.

This revision is now accepted and ready to land.Mar 22 2022, 1:06 AM
skan added a comment.Mar 22 2022, 1:14 AM

Please wait for 2 days to see if there is any objection before landing it.

Please wait for 2 days to see if there is any objection before landing it.

Thanks @skan. I don’t have commit access, can you land this patch for me? (if there are no objections after a few days) Please use “wangyihan 1135831309@qq.com” to commit the change.

skan added a comment.Mar 22 2022, 3:25 AM

Please wait for 2 days to see if there is any objection before landing it.

Thanks @skan. I don’t have commit access, can you land this patch for me? (if there are no objections after a few days) Please use “wangyihan 1135831309@qq.com” to commit the change.

Okay, I will do that.

sepavloff accepted this revision.Mar 22 2022, 5:21 AM

LGTM too.

Thanks!

This revision was landed with ongoing or failed builds.Mar 22 2022, 7:11 PM
This revision was automatically updated to reflect the committed changes.