2

I have a LLVM bitcode file and I'm running a loop pass on it. Every time I arrive at a loop ("runOnLoop"), I extract several pieces of information about the loop body (i.e. the number of instructions in the body) and print it. However, I need a way to associate this information with a specific loop - in other words, I need to print the "name" of the loop the information was extracted from.

1 Answer 1

1

I'm not sure what you mean by "name", but one way is to print debugging information (line number/column) associated with the loop latch block or something similar.

Another way is to use metadata to uniquely identify each loop and associate the extracted information with that identifier.

I had a similar need too, so I created a pass for that. Please note that this approach is sensitive to compiler optimizations and it does not preserve the ID when that happens (e.g. if a function that contains a loop is inlined). For best results (closer to the source) use it over IR that has been compiled with -O0. Further, optimizations can be applied afterwards, when you're done with your information gathering.

However, for something simple, I'd go with the first approach.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.