This is an archive of the discontinued LLVM Phabricator instance.

[libc] automemcpy - codegen
ClosedPublic

Authored by gchatelet on Oct 12 2021, 2:34 AM.

Details

Reviewers
courbet
Summary

"automemcpy: A framework for automatic generation of fundamental memory operations"
https://research.google/pubs/pub50338/

This patch implements the concepts presented in the paper, the overall approach is the following:

  • Makes use of constraint programming to model the implementation of a memory function (memcpy, memset, memcmp, bzero, bcmp).
  • Generate the code for all valid implementations
  • Compile the implementations and benchmark them on a set of machines. The benchmark makes use of representative distributions for the function's arguments.
  • Analyze the result and pick "the best" performing function according to the specific environement.

This patch in particular implements the code generation, turning a set of FunctionDescriptors into function implementations in a C++ file.

Diff Detail

Event Timeline

gchatelet created this revision.Oct 12 2021, 2:34 AM
gchatelet requested review of this revision.Oct 12 2021, 2:34 AM

As a general comment, It would be nice to see what a generated file would look like, maybe as a unit test ?

libc/benchmarks/automemcpy/CodeGen.cpp
12 ↗(On Diff #378931)

"Forward declarations of what ? The mem function implementations ?"

13 ↗(On Diff #378931)

"Source code for all the mem function implementations".

303 ↗(On Diff #378931)

It's not a correctness issue, but it's worth nothing that not all architectures have all register sizes, e.g. x86 SSE has 1,2,4,16, but here we'll still be generating an Overlap<8>, which may not be very efficient...

gchatelet updated this revision to Diff 379377.Oct 13 2021, 7:41 AM
gchatelet marked 3 inline comments as done.
  • Address comments, fix typo
libc/benchmarks/automemcpy/CodeGen.cpp
12 ↗(On Diff #378931)

Actually it was not forward declarations but using statements

303 ↗(On Diff #378931)

Acknowledged. Ultimately the benchmark decides so it's not a problem if the implementation performs badly. Actually this is interesting since we get to learn something :D

Working on a unit test to show what the output looks like.

gchatelet updated this revision to Diff 379686.Oct 14 2021, 6:00 AM
  • Add tests for CodeGen
courbet added inline comments.Oct 15 2021, 1:25 AM
libc/benchmarks/automemcpy/lib/CodeGen.cpp
20

typo

37

which Main ?

52

move inside codegen ?

547

Add the usual warning about the file being autogenerated ?

libc/benchmarks/automemcpy/lib/CodeGenMain.cpp
15

This should be a FIXME.

gchatelet updated this revision to Diff 380002.Oct 15 2021, 7:31 AM
gchatelet marked 5 inline comments as done.
  • Address comments for codegen
courbet accepted this revision.Oct 19 2021, 12:10 AM
courbet added inline comments.
libc/benchmarks/automemcpy/lib/CodeGenMain.cpp
15

returns

This revision is now accepted and ready to land.Oct 19 2021, 12:10 AM
gchatelet updated this revision to Diff 380644.Oct 19 2021, 4:31 AM
  • Fix typo
gchatelet marked an inline comment as done.Oct 19 2021, 4:31 AM
gchatelet closed this revision.Oct 28 2021, 4:32 AM

Submitted within D111801.