문제

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!

도움이 되었습니까?

해결책 2

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);

다른 팁

In later versions of LLVM, it is not allowed to cast Metadata from Value (I was on LLVM 7.0.1). Special classes MetadataAsValue and ValueAsMetadata are required for the cast.

CallInst *CI;      /* Call to llvm.dbg.declare */
AllocaInst *AI;    /* AllocaInst is the result */

Metadata *Meta = cast<MetadataAsValue>(CI->getOperand(0))->getMetadata();
if (isa<ValueAsMetadata>(Meta)) {
  Value *V = cast <ValueAsMetadata>(Meta)->getValue();
  AI = cast<AllocaInst>(V);
}

As you can see, the AllocaInst is wrapped inside ValueAsMetadata and then MetadataAsValue.

If you also want the get the DIVariable from this call.

DIVariable *V = cast<DIVariable>(cast<MetadataAsValue>(CI->getOperand(1))->getMetadata());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top