facebookresearch / CompilerGym

Reinforcement learning environments for compiler and program optimization tasks
https://compilergym.ai/
MIT License
906 stars 127 forks source link

[llvm] Add a method to compute .text size of the compiled binary #575

Closed ChrisCummins closed 2 years ago

ChrisCummins commented 2 years ago

The ObjectTextSize observation space currently does the equivalent of:

clang -c input.bc -o foo.o
llvm-size foo.o

This fine for the "basic" case, but it is totally inflexible. What if the user wants to pass in a "-D" define flag? Compile for a different architecture? Control the optimizations applied to the backend?

To address these, this PR adds a mechanism by which users can pass in a custom compilation command (e.g. $CC -target foobar -Oz $IN) which the environment can run to then compute the .text section size.

Summary of changes:

As a side note, the relationship between the cost functions and Benchmark class are a total mess, the whole thing is due an overhaul. However, that is beyond the scope of this PR. This PR attempts only to bolt on some new functionality needed to support cross-compiling.

codecov-commenter commented 2 years ago

Codecov Report

Merging #575 (27cf83f) into development (d70408f) will increase coverage by 0.06%. The diff coverage is 100.00%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #575      +/-   ##
===============================================
+ Coverage        88.15%   88.22%   +0.06%     
===============================================
  Files              114      114              
  Lines             6705     6708       +3     
===============================================
+ Hits              5911     5918       +7     
+ Misses             794      790       -4     
Impacted Files Coverage Δ
compiler_gym/envs/llvm/llvm_benchmark.py 93.43% <ø> (ø)
compiler_gym/envs/llvm/llvm_env.py 88.18% <ø> (+0.90%) :arrow_up:
compiler_gym/envs/compiler_env.py 91.33% <100.00%> (+0.81%) :arrow_up:
...loop_tool/service/loop_tool_compilation_session.py 89.79% <0.00%> (-0.69%) :arrow_down:
compiler_gym/service/connection.py 79.01% <0.00%> (+0.32%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d70408f...27cf83f. Read the comment docs.