[llvm-dev] Link Struct to Metadata

Hong Hu via llvm-dev llvm-dev at lists.llvm.org
Fri Jan 6 20:57:06 PST 2017


Thanks, Adrian.

Currently I'm writing a LLVM pass to do some statistics of C++ class member
usage.The analysis requires C++ class information, like members, functions,
etc. Since there is no such information retained in the LLVM IR, I'm
utilizing the metadata (like DICompositeType, and so on) to retrieve the
class information in LLVM IR. Therefore I need a mapping from the
StructType to the MDString.

I understand that there is no direct mapping now, and want to know the best
way to implement such a map. Now I'm looking into the clang front end, to
understand how the StructType and the MDString are created, and hope there
are some connections between these two there.

I'm still quite new to LLVM, and will be very happy if you can give me some
suggestions.

Regards,
Hu Hong

On 7 January 2017 at 08:25, Adrian Prantl <aprantl at apple.com> wrote:

>
> On Jan 6, 2017, at 2:25 AM, Hong Hu via llvm-dev <llvm-dev at lists.llvm.org>
> wrote:
>
> Hi,
>
> Given one structure type, is there any method to get the metadata that
> describes the structure information?
>
> For example:
>
> %2 = getelementptr inbounds %"class.std::thread", %"class.std::thread"*
> %this, i64 0, i32 0, i32 0, !dbg !2748
>
>
> then I know the pointer operand type is class.std::thread. I want to find
> the associated metadata of this type:
>
> !217 = !DICompositeType(tag: DW_TAG_class_type, name: "thread", scope:
> !34, file: !218, line: 60, size: 64, align: 64, elements: !219, identifier:
> "_ZTSSt6thread")
>
> The challenge is that the structure name is different in the IR
> instruction, from the one in the metadata. One is  class.std::thread,
> while another is _ZTSSt6thread.
>
>
> What you are describing is not really possible.
>
> - %"class.std::thread" is an LLVM type in the LLVM type system.
> - !217 is an LLVM IR metadata node that describes a C++ type.
>
> There exists no direct mapping between these two. The only link between
> the two is when there is a source variable of that type described by a
> llvm.dbg.value or llvm.dbg.declare intrinsic, such as a
> - call @llvm.dbg.value(metadata %s, i64 0, metadata !217, metadata
> !DIExpression())
>
> Can you explain your use-case some more? Perhaps there exists a better
> solution to what you are trying to do.
>
> -- adrian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170107/40c37630/attachment.html>


More information about the llvm-dev mailing list