周书林 via llvm-dev
2021-Jun-17 15:24 UTC
[llvm-dev] When I got a Operator by iterating a Value's User, how can I got the relevant Instruction?
Hi, I am using IR to do some dataflow analysis, and I want to get the source location related to the dataflow. In my thought, when I iterate the Users of a Value, there should be an corresponding instruction, then I could get source location from dbg info. However, in some cases, I got some Operators as the Users of a Value, such as GEPOperator, BitCastOperator, etc. My question is, how could I got the corresponding instruction that use this Operator as Operand? For example, when I got the GEPOperator as follows, how could I get the LoadInst? *%39 = load i32, i32* getelementptr inbounds (%struct.TTT, %struct.TTT* @ttt, i32 0, i32 2), align 8, !dbg !971* Sincerely, Shulin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210617/3a7e4ead/attachment.html>
Michael Kruse via llvm-dev
2021-Jun-17 21:10 UTC
[llvm-dev] When I got a Operator by iterating a Value's User, how can I got the relevant Instruction?
Am Do., 17. Juni 2021 um 10:24 Uhr schrieb 周书林 via llvm-dev <llvm-dev at lists.llvm.org>:> %39 = load i32, i32* getelementptr inbounds (%struct.TTT, %struct.TTT* @ttt, i32 0, i32 2), align 8, !dbg !971%39 is the LoadInst, while getelementptr is its second operand. It is inlined because it is an llvm::Constant, not an instruction. Constants do not participate in use/user-chains and hence there is no link from GEP to the LoadInst that is using it. The constant GEP object may be used by an arbitrary number of other instructions, other constants in the same or other functions. Node that there "GEPOperator" can represent either a GetElementPtrInst (i.e. an instruction) or a GEP constant expression (derived from ConstantExpr) Michael