<div dir="ltr"><div class="gmail_default" style="font-size:small">Thanks, Adrian. </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">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.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">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. </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I'm still quite new to LLVM, and will be very happy if you can give me some suggestions. </div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Regards,<div>Hu Hong</div></div></div></div>
<br><div class="gmail_quote">On 7 January 2017 at 08:25, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class=""><br><blockquote type="cite">On Jan 6, 2017, at 2:25 AM, Hong Hu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br><br>Hi,<br><br>Given one structure type, is there any method to get the metadata that describes the structure information?<br><br>For example: <br><br>%2 = getelementptr inbounds %"class.std::thread", %"class.std::thread"* %this, i64 0, i32 0, i32 0, !dbg !2748<br></blockquote><br><blockquote type="cite">then I know the pointer operand type is class.std::thread. I want to find the associated metadata of this type:<br><br>!217 = !DICompositeType(tag: DW_TAG_class_type, name: "thread", scope: !34, file: !218, line: 60, size: 64, align: 64, elements: !219, identifier: "_ZTSSt6thread")                                         <br><br>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. <br><br></blockquote><div><br></div></span><div>What you are describing is not really possible.</div><div><br></div><div><div>- %"class.std::thread" is an LLVM type in the LLVM type system.</div><div>- !217 is an LLVM IR metadata node that describes a C++ type.</div><div><br></div><div>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</div></div><div>- call @llvm.dbg.value(metadata %s, i64 0, metadata !217, metadata !DIExpression())</div><br><div>Can you explain your use-case some more? Perhaps there exists a better solution to what you are trying to do.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- adrian</div></font></span></div></blockquote></div><br></div></div>