This is an archive of the discontinued LLVM Phabricator instance.

[libc][NFC] Allow memcpy to be inlined
ClosedPublic

Authored by gchatelet on Nov 3 2021, 5:35 AM.

Details

Summary

This allows shipping individual functions without also having to provide
memcpy at the expense of bigger functions.
Next is to use this inlined_memcpy in:

  • loader/linux/x86_64/start.cpp
  • src/string/memmove.cpp
  • src/string/mempcpy.cpp
  • src/string/strcpy.cpp
  • src/string/strdup.cpp
  • src/string/strndup.cpp

Diff Detail

Event Timeline

gchatelet created this revision.Nov 3 2021, 5:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2021, 5:35 AM
gchatelet requested review of this revision.Nov 3 2021, 5:35 AM
michaelrj accepted this revision.Nov 3 2021, 10:04 AM

LGTM with nit

libc/src/string/memory_utils/memcpy_implementations.inl
152 ↗(On Diff #384406)

add a newline at EOF

This revision is now accepted and ready to land.Nov 3 2021, 10:04 AM

Any reason why you have chosen .inl suffix instead of treating them as normal header files? IDEs and other tools are used to .h files (for example Phabricator's UI does not do syntax highlighting).

libc/src/string/memory_utils/memcpy_implementations.inl
37 ↗(On Diff #384406)

Nit and a question: Why give it an inlined_ prefix which kind of implies that there is a non-inlined version somewhere? May be call it memcpy_impl?

gchatelet updated this revision to Diff 384708.Nov 4 2021, 4:58 AM
gchatelet marked an inline comment as done.
  • - Rename .inl -> .h and inlined_memcpy -> inline_memcpy

Any reason why you have chosen .inl suffix instead of treating them as normal header files? IDEs and other tools are used to .h files (for example Phabricator's UI does not do syntax highlighting).

inlextensions are quite common. vscode highlights them correctly, Phabricator can be taught to syntax highlight them correctly (Next to the file name : View Options -> Highlight as)
I tend to use this extension when I want to convey that the content contains implementations that are to be inlined.

Now I've grepped through llvm and indeed it is not a common extension so it's probably better to use .h files.

libc/src/string/memory_utils/memcpy_implementations.inl
37 ↗(On Diff #384406)

I wanted to make it clear at the call site that the code will be inlined, hence the inlined_ prefix (actually inline_ would be better).
memcpy_impl is less clear in that regard, one could infer that there's going to be a call to that function.

gchatelet updated this revision to Diff 384710.Nov 4 2021, 5:07 AM
  • Add header guard
libc/src/string/memory_utils/memcpy_implementations.h