<div dir="ltr">Optimized debug info is best effort & not terribly accurate in LLVM currently (it'll always be best effort, it's just that best could be better than it is today), so it's quite possible that a Value you know is in a variable isn't being tracked by debug info anymore because it got lost somewhere along the way.<br><br>When you look at the IR, does it seem that it has debug info intrinsics describing the value you're interested in? If not, did it start out that way & lose it due to optimization somewhere? Which optimization? (print-after-all can help track this sort of thing through an optimization pipeline) Perhaps you can improve the debug info quality of the optimization so it preserves what you need. But realize/remember it'll never be perfect, there's lots of lossy things that optimizations do.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 29, 2016 at 3:41 AM, Dhriti Khanna via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br clear="all"><div><div>If I have an operand as a Value from an instruction like: <font face="monospace, monospace">Value* V = opnd->get();</font> and I am sure this is a variable, I want to know the variable name (in source code) for this Value object. I am doing it like this:</div><div>              </div><div>                                   <font face="monospace, monospace">const Function* Func;</font></div><div><font face="monospace, monospace">                if (const Argument* Arg = dyn_cast<Argument>(V)) </font></div><div><font face="monospace, monospace">                {</font></div><div><font face="monospace, monospace">                  Func = Arg->getParent();</font></div><div><font face="monospace, monospace">                }</font></div><div><font face="monospace, monospace">                else if (const Instruction* I = dyn_cast<Instruction>(V)) </font></div><div><font face="monospace, monospace">                {</font></div><div><font face="monospace, monospace">                  Func = I->getParent()->getParent();</font></div><div><font face="monospace, monospace">                }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">                StringRef name;</font></div><div><font face="monospace, monospace">                if (!Func) </font></div><div><font face="monospace, monospace">                   name = V->getName();</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">                else</font></div><div><font face="monospace, monospace">                {</font></div><div><font face="monospace, monospace">                  const DILocalVariable* Var = NULL;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">                  for (const_inst_iterator Iter = inst_begin(Func), End = inst_end(Func); Iter != End; ++Iter) </font></div><div><font face="monospace, monospace">                  {</font></div><div><font face="monospace, monospace">                    if (const DbgDeclareInst* DbgDeclare = dyn_cast<DbgDeclareInst>(&*Iter)) </font></div><div><font face="monospace, monospace">                    {</font></div><div><font face="monospace, monospace">                      if (DbgDeclare->getAddress() == V) Var = DbgDeclare->getVariable();</font></div><div><font face="monospace, monospace">                    } </font></div><div><font face="monospace, monospace">                    else if (const DbgValueInst* DbgValue = dyn_cast<DbgValueInst>(&*Iter)) </font></div><div><font face="monospace, monospace">                    {</font></div><div><font face="monospace, monospace">                      if (DbgValue->getValue() == V) Var = DbgValue->getVariable();</font></div><div><font face="monospace, monospace">                    }</font></div><div><font face="monospace, monospace">                  }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">                  name = Var->getName();</font></div><div><font face="monospace, monospace">                }</font></div><div><font face="monospace, monospace">                errs() << "\nVariableName: " << name.str() << "\n";</font></div><div><br></div><div>But  this condition: <font face="monospace, monospace">if(DbgDeclare->getAddress() == V)</font> produces false result as the address for the Value object differs from every Value object found in dbg.declare intrinsic. Is this not how one finds the variable name??</div><div>What am I doing wrong?</div></div><div><br></div><div>--</div><div>Regards</div><span class="HOEnZb"><font color="#888888"><div>Dhriti Khanna</div>
</font></span></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>