How get IR value from llvm.dbg.declare

2019-07-28 03:36发布

问题:

Given a llvm.dbg.declare, how can I get its llvm value?

e.g.

call void @llvm.dbg.declare(metadata !{i32** %r}, metadata !23), !dbg !24

I want get the Value i32** %r, not the metadata !{i32** %r}.

Please give me the code!

Thanks!

回答1:

metadata !{i32** %r} is the 1st operand of the call instruction, and i32** %r is the 1st operand of the metadata. So something like this should work:

CallInst I = ... // get the @llvm.dbg.declare call
Value* referredValue = cast<MDNode>(I->getOperand(0))->getOperand(0);