LongFruit is a tool to:
- Generate compilable random C code excerpts.
- Compile that code with both GCC and Clang. Currently it only targets RISC-V.
- Analyse the the generated assembly code. Currently this means comparing the "cost" of the generated assembly instructions between GCC and Clang. This cost is given by a simple model, which maps instructions to a class (e.g. ALU, load/store) and assigns costs to those classes.
- Identify which cases are interesting. Currently this means cases where the total cost of the assembly generated by Clang is larger than the total cost generated by GCC.
- Minimise interesting cases. This is done by invoking
creduce
and testing potential reductions with the cost estimator. Currently cases are considered valid reductions if the new cost for GCC is equal to the original cost and the cost for Clang is greater than or equal to the original cost. - Store minimized interesting cases.
This tool is currently optimized for simplicity, but it has enough power to find various Clang/LLVM RISC-V codegen patterns that should be improved.
Run longfruit.py
to generate cases for further investigation. Those cases will be stored in files named case-XXXXXXXX.txt
, as they are found.
The information regarding the current code being minimized is stored in scenario.ini
. To manually trigger the cost test run test.py
and check the status code (0 means a valid minimization). To print the test results pass the the -v
option. To manually save the case to a case-XXXXXXXX.txt
file pass the -s
option.
Longfruit depends on creduce
to reduce the interesting cases, so you'll need to install that dependency.
creduce
expects the "interestingness test" program to refer to files that aren't being reduced using absolute paths. Because of that, the test.py
script currently contains a path variable that points to ~/tools/longfruit
. If you install this tool somewhere else you'll need to either change that string or create a symlink.