David Livshin via llvm-dev
2022-Jan-16 13:37 UTC
[llvm-dev] getting providers of a llvm instruction
Hi Analyzing llvm IR file ( .bc or .ll ) for every instruction it is possible, using the provided functions, to determine the list of instructions that consume it result. What about the other way around – are there llvm functions that allow for every instruction ( or better – for every operand of an instruction ) to determine the list of instructions that provide it with the necessary resources. Being able to know the users of the result of an instruction it is possible to calculate such a data. The question is if it is already calculated and, if yes, how to obtain it. Thank you David -- David Livshin david.livshin at dalsoft.com www.dalsoft.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20220116/06c1437c/attachment.html>
Tim Northover via llvm-dev
2022-Jan-17 09:40 UTC
[llvm-dev] getting providers of a llvm instruction
Hi David, On Sun, 16 Jan 2022 at 21:06, David Livshin via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Analyzing llvm IR file ( .bc or .ll ) for every instruction it is possible, using the provided functions, to determine the list of instructions that consume it result.Yes, this information is tracked pretty efficiently by the LLVM data structures. You can iterate using Value::users (Instruction inherits from Value). So something like: for (auto &U : MyInst->users()) { [...] } ought to work.> What about the other way around – are there llvm functions that allow for every instruction ( or better – for every operand of an instruction ) to determine the list of instructions that provide it with the necessary resources.I think the confusingly named `Value::uses` gives you this information: for (auto &U : MyInst->uses()) { // U is the graph edge between the two values, U.get() is the Value actually being used. Value *V = U.get(); [...] } Cheers. Tim.