context/scope of instruction

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

context/scope of instruction

Christian Jacobs
Hello,
I need to know how I get the LLVM::IDScope object of an instruction.

My program contains:
call void (...)* @commit(), !dbg !16

!16 = metadata !{i32 16, i32 5, metadata !8, null}

!8 = metadata !{i32 589835, metadata !4, i32 10, i32 1, metadata !2, i32 0} ; [ DW_TAG_lexical_block ]



LLVM::Instruction.hasMetadata() is 0

I got LLVM::Scope for variables over DIGlobalVariable.getContext() and DIVariable.getContext() but how do I get it for instructions?

Regards
Christian Jacobs
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: context/scope of instruction

Devang Patel

On Jan 19, 2012, at 10:12 AM, Christian Jacobs wrote:

> Hello,
> I need to know how I get the LLVM::IDScope object of an instruction.
>
> My program contains:
> call void (...)* @commit(), !dbg !16
>
> !16 = metadata !{i32 16, i32 5, metadata !8, null}
>
> !8 = metadata !{i32 589835, metadata !4, i32 10, i32 1, metadata !2, i32 0} ; [ DW_TAG_lexical_block ]
>

!8 is DIScope here (actually it is DILexicalBlock, which is derived from DIScope).

-
Devang
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: context/scope of instruction

Christian Jacobs

Am 20.01.2012 um 18:12 schrieb Devang Patel:

>
> On Jan 19, 2012, at 10:12 AM, Christian Jacobs wrote:
>
>> Hello,
>> I need to know how I get the LLVM::IDScope object of an instruction.
>>
>> My program contains:
>> call void (...)* @commit(), !dbg !16
>>
>> !16 = metadata !{i32 16, i32 5, metadata !8, null}
>>
>> !8 = metadata !{i32 589835, metadata !4, i32 10, i32 1, metadata !2, i32 0} ; [ DW_TAG_lexical_block ]
>>
>
> !8 is DIScope here (actually it is DILexicalBlock, which is derived from DIScope).

I know. I am writing an LLVM pass and I do not know how I get a hand on the DIScope object.
Which method(s) of the LLVM C++ API do I have to call to get a pointer or reference (!8) to the LLVM::DIScope of an LLVM::Instruction?

Christian


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: context/scope of instruction

Christian Jacobs
Am 20.01.2012 19:36, schrieb Christian Jacobs:

>
> Am 20.01.2012 um 18:12 schrieb Devang Patel:
>
>>
>> On Jan 19, 2012, at 10:12 AM, Christian Jacobs wrote:
>>
>>> Hello,
>>> I need to know how I get the LLVM::IDScope object of an instruction.
>>>
>>> My program contains:
>>> call void (...)* @commit(), !dbg !16
>>>
>>> !16 = metadata !{i32 16, i32 5, metadata !8, null}
>>>
>>> !8 = metadata !{i32 589835, metadata !4, i32 10, i32 1, metadata !2, i32 0} ; [ DW_TAG_lexical_block ]
>>>
>>
>> !8 is DIScope here (actually it is DILexicalBlock, which is derived from DIScope).
>
> I know. I am writing an LLVM pass and I do not know how I get a hand on the DIScope object.
> Which method(s) of the LLVM C++ API do I have to call to get a pointer or reference (!8) to the LLVM::DIScope of an LLVM::Instruction?
>
> Christian
>
I found a solution.
MDNode *node = inst.getMetadata(LLVMContext::MD_dbg);
DIDescriptor descriptor(cast<MDNode>(node->getOperand((unsigned)2)));
assert(descriptor.isScope());
DIScope scope(descriptor);

This article was very helpful:
http://blog.llvm.org/2010/04/extensible-metadata-in-llvm-ir.html

Christian
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev