Page MenuHomePhabricator

Add minimal test for the ThinLtoJIT example
AbandonedPublic

Authored by sgraenitz on Feb 1 2020, 12:52 PM.

Details

Reviewers
lhames
aprantl
Summary

A lit test for the ThinLtoJIT example from D72486. It will only run in builds configured with -DLLVM_BUILD_EXAMPLES=ON (just like the tests for the Kaleidoscope examples).

The ThinLtoJIT example implements "per-module speculation" for lazy loading and compilation of bitcode. Thus, the test is not self-contained in a single module, but comes with a number .ll files in the Inputs subfolder. These files are excluded from test discovery via the local lit config file.

The test uses a workload() function to simulate CPU load. It's used to give the speculator a chance to submit modules, that will likely be executed soon, asynchronously, before execution reaches them. It's supposed to maximize code coverage and NOT a requirement for the test to succeed. I wanted to use a sleep system function first, but I didn't know how to implement it cross-platform in LLVM IR. So, I chose a function that finds the largest prime-factor of the Nth Fibonacci number. It has exponential complexity and can easily be made dependent on the input argc.

The test's call graph looks like this:

             sub1() - workload(3)
           /
--> main() -- workload(40)
           \
            \           sub21() - workload(4)
             \        /
               sub2() - sub22() - workload(5)
                      \
                        sub23() - workload(6)

All functions are defined in separate .ll files. The module that contains the main entry point is always loaded synchronously (not via the speculator). The same will happen for sub1, workload and sub2, because execution reaches their caller too soon. It will then be blocked for a bit in workload(40) and the speculator will likely be faster to discover the sub2x modules.

The ThinLtoJIT executable is invoked with -print-stats, which dumps the number of synchronously/asynchronously loaded modules on shutdown. Getting these two lines of output is what the test currently checks. The JITed code itself doesn't print anything.

Event Timeline

sgraenitz created this revision.Feb 1 2020, 12:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2020, 12:52 PM
sgraenitz marked 3 inline comments as done.Feb 1 2020, 1:19 PM

I wrote this in C, compiled to LLVM IR (on macOS with a TOT clang) and removed a lot of bulk manually. Would you recommend to commit the C sources too? For now I put them here: https://github.com/weliveindetail/ThinLtoJitTests

llvm/test/Examples/ThinLtoJIT/minimal.test
8

The input files must be assembled into .bc files, because the ThinLTO bitcode reader is not designed for human-readable .ll files.

10

Passing the ThinLTO module index file as input (instead of the actual module files) is a feature.

13

@aprantl Did you show me the regex matchers for lit check lines last year? I cannot find the documentation for it anymore. It would be nice to grab the actual numbers here and check that their sum is 6. Is that possible? (In 99% of cases it will be 3 and 3, but in the end it's a timing issue and I don't want to rely on it.)

aprantl added inline comments.Feb 1 2020, 8:16 PM
llvm/test/Examples/ThinLtoJIT/minimal.test
13

The general documentation is here: https://www.llvm.org/docs/CommandGuide/FileCheck.html

I remember there was discussion in https://reviews.llvm.org/D49084 to add a computation mechanism to FileCheck and apparently this went in:

https://www.llvm.org/docs/CommandGuide/FileCheck.html#filecheck-numeric-substitution-blocks

!

sgraenitz updated this revision to Diff 241933.Feb 2 2020, 11:13 AM
sgraenitz marked 2 inline comments as done.

Use numeric substitution blocks to verify the sum of submitted modules is 6

llvm/test/Examples/ThinLtoJIT/minimal.test
13

Thank you! That's exactly what I was looking for.

sgraenitz abandoned this revision.Aug 14 2020, 7:59 AM