This is an archive of the discontinued LLVM Phabricator instance.

[llvm-exegesis] Add loop mode for repeating the snippet.
ClosedPublic

Authored by courbet on Sep 27 2019, 2:28 AM.

Details

Summary

Before this change the Executable function was made by duplicating the
snippet. This change adds a --repetion-mode={loop|duplicate} flag that
allows choosing between this behaviour and wrapping the snippet instructions
in a loop.

The new mode can help measurements when the snippet fits in the DSB by
short-cirtcuiting decoding. The loop adds a dec + jmp to the measurements, but
since these are not part of the critical path, they execute in parallel
with the measured code and do not impact measurements in practice.

Overview of the change:

  • New SnippetRepetitor abstraction that handles repeating the snippet. The assembler delegates repeating the instructions to this class.
  • ExegesisTarget learns how to decrement loop counter and jump.
  • Some refactoring of the assembler into FunctionFiller/BasicBlockFiller.

Event Timeline

courbet created this revision.Sep 27 2019, 2:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2019, 2:28 AM

Can you point me to the test that actually checks the new assembly?

Can you point me to the test that actually checks the new assembly?

I was hesitant here: I only added integration tests there instead of unit tests because it felt like unit tests would really only be a repetition of the class internals. Given your comment, I'm going to add actual unit tests too.

gchatelet added inline comments.Sep 27 2019, 2:59 AM
llvm/tools/llvm-exegesis/lib/Assembler.cpp
121

remove braces

217

How about FillWith?

llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
68

Can you extract the constant to a varaible?

79

Remove braces

82

ditto

llvm/tools/llvm-exegesis/lib/X86/Target.cpp
513

Add a comment on why R8

563

Maybe use a constant instead of repeating R8 everywhere.

courbet updated this revision to Diff 222137.Sep 27 2019, 5:14 AM

Add unit tests for SnippetRepetitor.

courbet updated this revision to Diff 222141.Sep 27 2019, 5:23 AM

More tests: check live ins.

courbet updated this revision to Diff 222148.Sep 27 2019, 5:41 AM
courbet marked 7 inline comments as done.

Address comments.

gchatelet accepted this revision.Sep 27 2019, 5:49 AM
This revision is now accepted and ready to land.Sep 27 2019, 5:49 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Sep 27 2019, 6:10 AM

This upsets gcc: http://lab.llvm.org:8011/builders/lld-x86_64-ubuntu-fast/builds/6437/steps/build-unified-tree/logs/stdio

/home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp:66:27: error: declaration of ‘std::unique_ptr<llvm::Module> llvm::exegesis::{anonymous}::X86SnippetRepetitorTest::Module’ [-fpermissive]
   std::unique_ptr<Module> Module;
                           ^~~~~~
In file included from /home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/include/llvm/Analysis/TargetLibraryInfo.h:17:0,
                 from /home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/include/llvm/Analysis/AliasAnalysis.h:45,
                 from /home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/include/llvm/CodeGen/MachineInstr.h:23,
                 from /home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/include/llvm/CodeGen/MachineBasicBlock.h:21,
                 from /home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/include/llvm/CodeGen/MachineFunction.h:30,
                 from /home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/tools/llvm-exegesis/lib/Assembler.h:23,
                 from /home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/unittests/tools/llvm-exegesis/X86/../Common/AssemblerUtils.h:12,
                 from /home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp:9:
/home/buildbot/as-builder-4/lld-x86_64-ubuntu-fast/llvm/include/llvm/IR/Module.h:65:7: error: changes meaning of ‘Module’ from ‘class llvm::Module’ [-fpermissive]
 class Module {
       ^~~~~~