简体   繁体   中英

How to pass parameters with LLVM

I'm looking for ways by which I can extract static code features (like number of instructions) during compile time using LLVM and then store these values so that I can use during program execution.

Can this be done by TransformationPasses. I don't get this concept in LLVM documentation.

Your question is too general. TransformationPasses transform your code (for instance dead code elimination). For analyzing there are Analysis passes. You can edit these passes to get what you need.

First, you can write your own analysis pass : http://llvm.org/docs/WritingAnLLVMPass.html . Second, you have functions like runOnFunction() (where you can use instruction iterators, or basic block iterators). For your particular example of counting instructions, just use a counter inside runOnFunction() or a LLVM method.

First, you need to write a pass that computes the information you need. You then need to inject that information into your module. A relatively straightforward way is to generate functions that, when called, return the computed values.

The programmer would then need to call these functions if she wants to receive these special values. The programmer will likely need to add the signatures herself, but your pass will replace the declare with an actual define which just returns a constant value. Those functions should also be annotated as inline.

You can also do this by replacing special variables or parameters or anything else, it's just that function calls seem to me as an elegant approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM