Re: [cfe-users] Get Source Location details from IR code (Function Pass)

2021-01-26 Thread Bella V via cfe-users
Thanks for the answer.
struct Foo
{int x;};

Void bar() {
struct Foo f;
f.x = 1;
}

I'm trying to access the DILocation for DICompositeType (Foo), that is the
Source Location for struct Foo and struct members. Any pointers.

Regards.

On Sun, Jan 17, 2021 at 11:20 AM David Blaikie  wrote:

> Not sure I understand the question - llvm.dbg.declare can be
> queried/examined/etc through the usual LLVM IR APIs, yes - it's an
> intrinsic call, with operands, etc. It's a DbgVariableIntrinsic (
> https://llvm.org/doxygen/classllvm_1_1DbgVariableIntrinsic.html ) you
> can interrogate for information.
>
> On Fri, Jan 15, 2021 at 7:17 PM Bella V  wrote:
> >
> > Thank you. Also Is there a pragmatically way to access the metadata info
> for local variables within the llvm.dbg.declare.
> > ( llvm::Value does not have local variables).
> >
> > On Tue, Jan 12, 2021 at 1:55 PM David Blaikie 
> wrote:
> >>
> >> You'd have to get IR from somewhere that has attached debug info - such
> as clang -g
> >>
> >> On Tue, Jan 12, 2021 at 1:22 PM Bella V 
> wrote:
> >>>
> >>> Do we have to initially attach some metadata to the Value? Because in
> function pass, when I do F.getAllMetadata(MDs), i do not see any metadata
> appending to MDS.
> >>> F.hasMetadata() also returns false. What would be the way to get
> debugLoc in these scenario?
> >>>
> >>> Thanks and Regards.
> >>>
> >>> On Mon, Jan 11, 2021 at 6:31 PM David Blaikie 
> wrote:
> 
> 
> 
>  On Mon, Jan 11, 2021 at 4:33 PM Ayush Mittal via cfe-users <
> cfe-users@lists.llvm.org> wrote:
> >
> > Hello Cfe Users,
> >
> > Could you please point to an effective way to get Source Location
> details from an IR code.
> > From the documentation, I think this could be a way:
> > Function Pass-> LLVM Value-> MDN->DILocation-> Source Location.
> 
> 
>  Yep, that's about it (I mean, you can do it in a pass, or not - but
> yes, find an llvm::Value and get the debugLoc from that)
> 
> >
> > Please include any example if the above approach is correct too.
> >
> > Thanks and Regards.
> > ___
> > cfe-users mailing list
> > cfe-users@lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Get Source Location details from IR code (Function Pass)

2021-01-26 Thread David Blaikie via cfe-users
the location of composite types isn't stored in a DILocation - it's stored
in the 'file'/'line' attributes of the DICompositeType (similarly, the
members have a 'file' and 'line' attribute).

See for instance line 39 of the LLVM IR in https://godbolt.org/z/o3oce5 :

!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo",
file: !8, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !13,
identifier: "_ZTS3Foo")

Note the 'file:' and 'line: fields there. (the file field refers to !8
which is !8 = !DIFile(filename: "./example.cpp", directory: "/home/ce"))

On Tue, Jan 26, 2021 at 5:15 PM Bella V  wrote:

> Thanks for the answer.
> struct Foo
> {int x;};
>
> Void bar() {
> struct Foo f;
> f.x = 1;
> }
>
> I'm trying to access the DILocation for DICompositeType (Foo), that is the
> Source Location for struct Foo and struct members. Any pointers.
>
> Regards.
>
> On Sun, Jan 17, 2021 at 11:20 AM David Blaikie  wrote:
>
>> Not sure I understand the question - llvm.dbg.declare can be
>> queried/examined/etc through the usual LLVM IR APIs, yes - it's an
>> intrinsic call, with operands, etc. It's a DbgVariableIntrinsic (
>> https://llvm.org/doxygen/classllvm_1_1DbgVariableIntrinsic.html ) you
>> can interrogate for information.
>>
>> On Fri, Jan 15, 2021 at 7:17 PM Bella V 
>> wrote:
>> >
>> > Thank you. Also Is there a pragmatically way to access the metadata
>> info for local variables within the llvm.dbg.declare.
>> > ( llvm::Value does not have local variables).
>> >
>> > On Tue, Jan 12, 2021 at 1:55 PM David Blaikie 
>> wrote:
>> >>
>> >> You'd have to get IR from somewhere that has attached debug info -
>> such as clang -g
>> >>
>> >> On Tue, Jan 12, 2021 at 1:22 PM Bella V 
>> wrote:
>> >>>
>> >>> Do we have to initially attach some metadata to the Value? Because in
>> function pass, when I do F.getAllMetadata(MDs), i do not see any metadata
>> appending to MDS.
>> >>> F.hasMetadata() also returns false. What would be the way to get
>> debugLoc in these scenario?
>> >>>
>> >>> Thanks and Regards.
>> >>>
>> >>> On Mon, Jan 11, 2021 at 6:31 PM David Blaikie 
>> wrote:
>> 
>> 
>> 
>>  On Mon, Jan 11, 2021 at 4:33 PM Ayush Mittal via cfe-users <
>> cfe-users@lists.llvm.org> wrote:
>> >
>> > Hello Cfe Users,
>> >
>> > Could you please point to an effective way to get Source Location
>> details from an IR code.
>> > From the documentation, I think this could be a way:
>> > Function Pass-> LLVM Value-> MDN->DILocation-> Source Location.
>> 
>> 
>>  Yep, that's about it (I mean, you can do it in a pass, or not - but
>> yes, find an llvm::Value and get the debugLoc from that)
>> 
>> >
>> > Please include any example if the above approach is correct too.
>> >
>> > Thanks and Regards.
>> > ___
>> > cfe-users mailing list
>> > cfe-users@lists.llvm.org
>> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Get Source Location details from IR code (Function Pass)

2021-01-26 Thread Bella V via cfe-users
Thank you for the clarification. How do we access DICompositeType: line
numbers from Function &F or Module &M.

On Tue, Jan 26, 2021 at 9:43 PM David Blaikie  wrote:

> the location of composite types isn't stored in a DILocation - it's stored
> in the 'file'/'line' attributes of the DICompositeType (similarly, the
> members have a 'file' and 'line' attribute).
>
> See for instance line 39 of the LLVM IR in https://godbolt.org/z/o3oce5 :
>
> !12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo",
> file: !8, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !13,
> identifier: "_ZTS3Foo")
>
> Note the 'file:' and 'line: fields there. (the file field refers to !8
> which is !8 = !DIFile(filename: "./example.cpp", directory: "/home/ce"))
>
> On Tue, Jan 26, 2021 at 5:15 PM Bella V  wrote:
>
>> Thanks for the answer.
>> struct Foo
>> {int x;};
>>
>> Void bar() {
>> struct Foo f;
>> f.x = 1;
>> }
>>
>> I'm trying to access the DILocation for DICompositeType (Foo), that is
>> the Source Location for struct Foo and struct members. Any pointers.
>>
>> Regards.
>>
>> On Sun, Jan 17, 2021 at 11:20 AM David Blaikie 
>> wrote:
>>
>>> Not sure I understand the question - llvm.dbg.declare can be
>>> queried/examined/etc through the usual LLVM IR APIs, yes - it's an
>>> intrinsic call, with operands, etc. It's a DbgVariableIntrinsic (
>>> https://llvm.org/doxygen/classllvm_1_1DbgVariableIntrinsic.html ) you
>>> can interrogate for information.
>>>
>>> On Fri, Jan 15, 2021 at 7:17 PM Bella V 
>>> wrote:
>>> >
>>> > Thank you. Also Is there a pragmatically way to access the metadata
>>> info for local variables within the llvm.dbg.declare.
>>> > ( llvm::Value does not have local variables).
>>> >
>>> > On Tue, Jan 12, 2021 at 1:55 PM David Blaikie 
>>> wrote:
>>> >>
>>> >> You'd have to get IR from somewhere that has attached debug info -
>>> such as clang -g
>>> >>
>>> >> On Tue, Jan 12, 2021 at 1:22 PM Bella V 
>>> wrote:
>>> >>>
>>> >>> Do we have to initially attach some metadata to the Value? Because
>>> in function pass, when I do F.getAllMetadata(MDs), i do not see any
>>> metadata appending to MDS.
>>> >>> F.hasMetadata() also returns false. What would be the way to get
>>> debugLoc in these scenario?
>>> >>>
>>> >>> Thanks and Regards.
>>> >>>
>>> >>> On Mon, Jan 11, 2021 at 6:31 PM David Blaikie 
>>> wrote:
>>> 
>>> 
>>> 
>>>  On Mon, Jan 11, 2021 at 4:33 PM Ayush Mittal via cfe-users <
>>> cfe-users@lists.llvm.org> wrote:
>>> >
>>> > Hello Cfe Users,
>>> >
>>> > Could you please point to an effective way to get Source Location
>>> details from an IR code.
>>> > From the documentation, I think this could be a way:
>>> > Function Pass-> LLVM Value-> MDN->DILocation-> Source Location.
>>> 
>>> 
>>>  Yep, that's about it (I mean, you can do it in a pass, or not -
>>> but  yes, find an llvm::Value and get the debugLoc from that)
>>> 
>>> >
>>> > Please include any example if the above approach is correct too.
>>> >
>>> > Thanks and Regards.
>>> > ___
>>> > cfe-users mailing list
>>> > cfe-users@lists.llvm.org
>>> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>>>
>>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users