facebookresearch / CompilerGym

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

Compatibility with LLVM 9 #781

Closed chao-peng closed 1 year ago

chao-peng commented 1 year ago

🐛 Bug

Bitcode generated is not recognised by LLVM 9

To Reproduce

Steps to reproduce the behavior:

  1. Replace ~/.local/share/compiler_gym/llvm-v0 with LLVM 9 bins and libs
  2. Make a simple benchmark (code listed below)
  3. Try to run benchmark

Benchmark code

#include <iostream>
using namespace std;

#if (__clang_major__ == 9) 
void bar(){cout << "1";}
#else
void bar(){cout << "1";}
#endif

Error

compiler_gym.errors.dataset_errors.BenchmarkInitError: Failed to initialize benchmark benchmark://user-v0/20230110T104153-1e11: Failed to compute .text size cost. Command returned exit code 1: /home/pengchao/.local/share/compiler_gym/llvm-v0/bin/clang -w -xir - -o /dev/shm/compiler_gym_pengchao/s/0117T104153-330254-6905/obj-24be.o -c. Error: :55:196: error: expected ')' at end of argument list define available_externally dso_local dereferenceable(272) %"class.std::basic_ostream" @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(%"class.std::basic_ostream" dereferenceable(272) %0, i8* %1) #4 { ^ 1 error generated.

Expected behavior

Environment

Please fill in this checklist:

You may use the environment collection script to generate most of this information. You can get the script and run it with:

wget https://raw.githubusercontent.com/facebookresearch/CompilerGym/stable/build_tools/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

Additional context

ChrisCummins commented 1 year ago

Hi @chao-peng, CompilerGym uses LLVM 10.0.0, and there no compatibility guarantees between LLVM versions. Unfortunately, that means that your LLVM 9 bitcodes will not work. I'd suggest two workarounds:

  1. If you have access to the sources, recompile your bitcodes using LLVM 10.0.0.
  2. Build CompilerGym using LLVM 9. The easiest way would be to build using cmake and specify a local LLVM 9 path using:
cmake ... \
    -DCOMPILER_GYM_LLVM_PROVIDER=external \
    -DLLVM_DIR=/path/to/llvm-9/lib/cmake/llvm

See the full instructions here. Note that this may require changes to CompilerGym's sources as it is very tightly coupled with the LLVM codebase. For example, optimization passes that are new or renamed between LLVM 9 and 10 will break this file.

Cheers, Chris

ChrisCummins commented 1 year ago

Note we do have plans to add support for other LLVM versions (#568), but this will require some significant engineering work on the backend.

Closing this as not a supported feature as of yet, but feel free to follow up with any further questions.

Cheers, Chris