facebookresearch / CompilerGym

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

How to build with llvm-11.1.0 #814

Open zcfh opened 1 year ago

zcfh commented 1 year ago

❓How to build with llvm-11.1.0

I read the install.md and the build was successful with llvm-10. I want to build with llvm-11, refer to the issus 788, I performed some steps, and met two problems, how to solve it?

My build command build branch release/v0.2.5

 cmake3   -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -S . -B build  -DCOMPILER_GYM_LLVM_PROVIDER=external -DLLVM_DIR=/home/distcc/clang-11.1.0/lib/cmake/llvm   -DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld"  -DCOMPILER_GYM_BUILD_EXAMPLES=ON

Problems

  1. Through the shell of the generator, I get the 608 flag, Is this my usage error?

    $ python3 build_tools/llvm/legacy_pass_manager/extract_passes_from_llvm_source_tree.py /llvm-11-srcs-/llvm  |  python3  build_tools/llvm/legacy_pass_manager/make_action_space_genfiles.py  compiler_gym/envs/llvm/service/passes/11.1.0
    $ wc -l compiler_gym/envs/llvm/service/passes/11.1.0/flags.txt
    608 compiler_gym/envs/llvm/service/passes/11.1.0/flags.txt
  2. link error about external/programl. I encountered the following error, read some BUILD files, because the programl depends on llvm-10, I see it does not seem to support llvm11, do I need to modify it myself?

    ld.lld: error: undefined symbol: llvm::parseIR(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&, bool, llvm::StringRef)
    >>> referenced by llvm.cc
    >>>               llvm.pic.o:(programl::ir::llvm::BuildProgramGraph(llvm::MemoryBuffer const&, programl::ProgramGraph*, programl::ProgramGraphOptions const&)) in archive external/programl/programl/src/programl/bazel-bin/programl/ir/llvm/libllvm-10.a
zcfh commented 1 year ago

Problems

  1. Through the shell of the generator, I get the 608 flag, Is this my usage error?
$ python3 build_tools/llvm/legacy_pass_manager/extract_passes_from_llvm_source_tree.py /llvm-11-srcs-/llvm  |  python3  build_tools/llvm/legacy_pass_manager/make_action_space_genfiles.py  compiler_gym/envs/llvm/service/passes/11.1.0
$ wc -l compiler_gym/envs/llvm/service/passes/11.1.0/flags.txt
608 compiler_gym/envs/llvm/service/passes/11.1.0/flags.txt

Problem 1 has been solved, there is a usage method in pass/BUILD, but the release/v0.2.5 does not have this file.

And it needs to add include to take effect, why should this branch be deleted?

`header = Path("llvm/" + str(source_path)[len("lib") : -len("cpp")] + "h")` 
>>>
`header = Path("include/llvm/" + str(source_path)[len("lib") : -len("cpp")] + "h")`
zcfh commented 1 year ago
  1. link error about external/programl. I encountered the following error, read some BUILD files, because the programl depends on llvm-10, I see it does not seem to support llvm11, do I need to modify it myself?
ld.lld: error: undefined symbol: llvm::parseIR(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&, bool, llvm::StringRef)
>>> referenced by llvm.cc
>>>               llvm.pic.o:(programl::ir::llvm::BuildProgramGraph(llvm::MemoryBuffer const&, programl::ProgramGraph*, programl::ProgramGraphOptions const&)) in archive external/programl/programl/src/programl/bazel-bin/programl/ir/llvm/libllvm-10.a

Problem 2 has been solved. Modify deps @llvm//10.0.0 to custom clang11.1.0 bazel workspace.