<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 23, 2014 at 6:21 PM, Timur Iskhodzhanov <span dir="ltr"><<a href="mailto:timurrrr@google.com" target="_blank">timurrrr@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">2014-10-23 18:10 GMT-07:00 David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>>:<br>
<div><div class="h5">><br>
><br>
> On Thu, Oct 23, 2014 at 4:46 PM, Timur Iskhodzhanov <<a href="mailto:timurrrr@google.com">timurrrr@google.com</a>><br>
> wrote:<br>
>><br>
>> Author: timurrrr<br>
>> Date: Thu Oct 23 18:46:28 2014<br>
>> New Revision: 220536<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=220536&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=220536&view=rev</a><br>
>> Log:<br>
>> Make getDISubprogram(const Function *F) available in LLVM<br>
>><br>
>> Reviewed at <a href="http://reviews.llvm.org/D5950" target="_blank">http://reviews.llvm.org/D5950</a><br>
>><br>
>> Modified:<br>
>>     llvm/trunk/include/llvm/IR/DebugInfo.h<br>
>>     llvm/trunk/lib/IR/DebugInfo.cpp<br>
>>     llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp<br>
>><br>
>> Modified: llvm/trunk/include/llvm/IR/DebugInfo.h<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=220536&r1=220535&r2=220536&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=220536&r1=220535&r2=220536&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- llvm/trunk/include/llvm/IR/DebugInfo.h (original)<br>
>> +++ llvm/trunk/include/llvm/IR/DebugInfo.h Thu Oct 23 18:46:28 2014<br>
>> @@ -961,6 +961,11 @@ public:<br>
>>  /// \brief Find subprogram that is enclosing this scope.<br>
>>  DISubprogram getDISubprogram(const MDNode *Scope);<br>
>><br>
>> +/// \brief Find debug info for a given function.<br>
>> +/// \returns a valid DISubprogram, if found. Otherwise, it returns an<br>
>> empty<br>
>> +/// DISubprogram.<br>
>> +DISubprogram getDISubprogram(const Function *F);<br>
>> +<br>
>>  /// \brief Find underlying composite type.<br>
>>  DICompositeType getDICompositeType(DIType T);<br>
>><br>
>><br>
>> Modified: llvm/trunk/lib/IR/DebugInfo.cpp<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=220536&r1=220535&r2=220536&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=220536&r1=220535&r2=220536&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- llvm/trunk/lib/IR/DebugInfo.cpp (original)<br>
>> +++ llvm/trunk/lib/IR/DebugInfo.cpp Thu Oct 23 18:46:28 2014<br>
>> @@ -912,6 +912,24 @@ DISubprogram llvm::getDISubprogram(const<br>
>>    return DISubprogram();<br>
>>  }<br>
>><br>
>> +DISubprogram llvm::getDISubprogram(const Function *F) {<br>
>> +  // We look for the first instr that has a debug annotation leading back<br>
>> to F.<br>
>> +  const LLVMContext &Ctx = F->getParent()->getContext();<br>
>> +  for (auto &BB : *F) {<br>
>> +    for (auto &Inst : BB.getInstList()) {<br>
>> +      DebugLoc DLoc = Inst.getDebugLoc();<br>
>> +      if (DLoc.isUnknown())<br>
>> +        continue;<br>
>> +      const MDNode *Scope = DLoc.getScopeNode(Ctx);<br>
>> +      DISubprogram Subprogram = getDISubprogram(Scope);<br>
>> +      if (Subprogram.describes(F))<br>
>> +       return Subprogram;<br>
><br>
><br>
> You've changed this in the moving - it used to return on the first<br>
> Instruction with DebugInfo, now it keeps searching.<br>
<br>
</div></div>Yep – we thought the original version was slightly incorrect?<br></blockquote><div><br></div><div>We? (sorry, perhaps I missed some IRC conversation, etc) - this was discussed in code review/on IRC when I described the idea to Diego originally. What problem were you seeing/thinking of?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
> (also, we could change this function to take a reference instead of a<br>
> pointer - I was going to make that change when I saw this semantic change<br>
> that caught me by surprise)<br>
><br>
>><br>
>> +    }<br>
>> +  }<br>
>> +<br>
>> +  return DISubprogram();<br>
>> +}<br>
>> +<br>
>>  DICompositeType llvm::getDICompositeType(DIType T) {<br>
>>    if (T.isCompositeType())<br>
>>      return DICompositeType(T);<br>
>><br>
>> Modified: llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp?rev=220536&r1=220535&r2=220536&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp?rev=220536&r1=220535&r2=220536&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp (original)<br>
>> +++ llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp Thu Oct 23 18:46:28<br>
>> 2014<br>
>> @@ -627,29 +627,6 @@ void SampleProfileLoader::propagateWeigh<br>
>>    }<br>
>>  }<br>
>><br>
>> -/// \brief Locate the DISubprogram for F.<br>
>> -///<br>
>> -/// We look for the first instruction that has a debug annotation<br>
>> -/// leading back to \p F.<br>
>> -///<br>
>> -/// \returns a valid DISubprogram, if found. Otherwise, it returns an<br>
>> empty<br>
>> -/// DISubprogram.<br>
>> -static const DISubprogram getDISubprogram(Function &F, const LLVMContext<br>
>> &Ctx) {<br>
>> -  for (auto &BI : F) {<br>
>> -    BasicBlock *BB = &BI;<br>
>> -    for (auto &Inst : BB->getInstList()) {<br>
>> -      DebugLoc DLoc = Inst.getDebugLoc();<br>
>> -      if (DLoc.isUnknown())<br>
>> -        continue;<br>
>> -      const MDNode *Scope = DLoc.getScopeNode(Ctx);<br>
>> -      DISubprogram Subprogram = getDISubprogram(Scope);<br>
>> -      return Subprogram.describes(&F) ? Subprogram : DISubprogram();<br>
>> -    }<br>
>> -  }<br>
>> -<br>
>> -  return DISubprogram();<br>
>> -}<br>
>> -<br>
>>  /// \brief Get the line number for the function header.<br>
>>  ///<br>
>>  /// This looks up function \p F in the current compilation unit and<br>
>> @@ -662,7 +639,7 @@ static const DISubprogram getDISubprogra<br>
>>  /// \returns the line number where \p F is defined. If it returns 0,<br>
>>  ///          it means that there is no debug information available for \p<br>
>> F.<br>
>>  unsigned SampleProfileLoader::getFunctionLoc(Function &F) {<br>
>> -  const DISubprogram &S = getDISubprogram(F, *Ctx);<br>
>> +  DISubprogram S = getDISubprogram(&F);<br>
>>    if (S.isSubprogram())<br>
>>      return S.getLineNumber();<br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
><br>
</div></div></blockquote></div><br></div></div>