Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Trying to Dump IR or Line Numbers of Loops #493

Closed
wants to merge 1 commit into from

Conversation

mostafaelhoushi
Copy link
Contributor

I have been trying to print line numbers of loops, or print the IR content of loops (in order to extract loop features separately) using these statements:

      L->getLoopID()->dump();
      L->dump();
      L->getLocRange().getStart().dump();
      L->getLocRange().getEnd().dump();
      L->getStartLoc().getLine();

but they all lead to this error:

dyld: lazy symbol binding failed: Symbol not found: __ZNK4llvm8Metadata4dumpEv
  Referenced from: /private/var/tmp/_bazel_melhoushi/29d44ffac89bbd569101bd339ac68a0b/execroot/CompilerGym/bazel-out/darwin-fastbuild/bin/examples/example_unrolling_service/loop_unroller/loop_unroller
  Expected in: flat namespace

dyld: Symbol not found: __ZNK4llvm8Metadata4dumpEv
  Referenced from: /private/var/tmp/_bazel_melhoushi/29d44ffac89bbd569101bd339ac68a0b/execroot/CompilerGym/bazel-out/darwin-fastbuild/bin/examples/example_unrolling_service/loop_unroller/loop_unroller
  Expected in: flat namespace

I have tried to add libLLVMRuntimeDyld as a TARGET to the build system as shown in this pull request but it didn't work. Perhaps I have added it the wrong way. Can @ChrisCummins please take a look?

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 24, 2021
@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2021

Codecov Report

Merging #493 (84be5ce) into development (724f23c) will decrease coverage by 0.50%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #493      +/-   ##
===============================================
- Coverage        87.93%   87.43%   -0.51%     
===============================================
  Files              111      113       +2     
  Lines             6182     6397     +215     
===============================================
+ Hits              5436     5593     +157     
- Misses             746      804      +58     
Impacted Files Coverage Δ
compiler_gym/util/registration.py 80.00% <0.00%> (-20.00%) ⬇️
compiler_gym/envs/gcc/datasets/chstone.py 91.17% <0.00%> (-2.95%) ⬇️
...loop_tool/service/loop_tool_compilation_session.py 88.59% <0.00%> (-1.35%) ⬇️
compiler_gym/wrappers/datasets.py 95.91% <0.00%> (-1.06%) ⬇️
compiler_gym/service/connection.py 78.71% <0.00%> (-0.68%) ⬇️
compiler_gym/envs/compiler_env.py 89.47% <0.00%> (-0.48%) ⬇️
...er_gym/third_party/inst2vec/inst2vec_preprocess.py 73.94% <0.00%> (-0.29%) ⬇️
compiler_gym/wrappers/__init__.py 100.00% <0.00%> (ø)
compiler_gym/envs/llvm/compute_observation.py 89.58% <0.00%> (ø)
compiler_gym/util/executor.py 74.43% <0.00%> (ø)
... and 1 more

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 724f23c...84be5ce. Read the comment docs.

@ChrisCummins
Copy link
Contributor

Hey @mostafaelhoushi, I have seen similar errors before. I think the problem is that there is some library missing in the linker flags for LLVM I define here which causes the required .so file to not be linked into the binary:

https://github.com/ChrisCummins/bazel_llvm/blob/development/10.0.0/BUILD#L477-L672

To be honest, in the one time I encountered a similar problem, I ended up working around it rather than fixing it, because the debugging loop was so slow 😬

I might get a bit of time towards the start of next week to try and see if I can fix it. If not, is there an alternative API you can call to dump the line numbers?

Cheers,
Chris

@ChrisCummins
Copy link
Contributor

@mostafaelhoushi you may find that this kind of error goes away when building with cmake (#498) rather than my janky bazel integration. It isn't yet a full replacement for the bazel build but this may be enough to unblock you.

Cheers,
Chris

@mostafaelhoushi
Copy link
Contributor Author

@mostafaelhoushi you may find that this kind of error goes away when building with cmake (#498) rather than my janky bazel integration. It isn't yet a full replacement for the bazel build but this may be enough to unblock you.

Cheers, Chris

Perfect! I will try it with the docker. Thanks Chris!

@mostafaelhoushi
Copy link
Contributor Author

I have good news.
I was able to get CMake working on the loop unroller in this PR: #530

And then CMake made it easier for me to debug the build error. It turned out that we need to build LLVM in debug mode or add -DLLVM_ENABLE_DUMP during the build of LLVM:
https://github.com/llvm/llvm-project/blob/53dc5258282a8322451cba14b5ad2f670028d196/llvm/lib/Analysis/LoopInfo.cpp#L669-L675

image

Instead of having to modify the build of LLVM, I was able to invoke ->print(llvm::dbgs(), true, true) to print the IR instructions inside the loop.

So now, we can dump the loop with both bazel and CMake!

I will clean up the code and update this PR.

@ChrisCummins
Copy link
Contributor

Fantastic work @mostafaelhoushi! This is a great example of the value of being able to customize the LLVM build that CompilerGym uses. Nice!

cc @sogartar

@mostafaelhoushi
Copy link
Contributor Author

Will close this PR as I am working on another branch to dump loop data

@mostafaelhoushi mostafaelhoushi deleted the print-line-numbers branch January 16, 2022 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants