<div dir="ltr">+Nikola<br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 1, 2017 at 3:05 AM, Strahinja Petrovic via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@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">Author: spetrovic<br>
Date: Fri Sep  1 03:05:27 2017<br>
New Revision: 312318<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=312318&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=312318&view=rev</a><br>
Log:<br>
Debug info for variables whose type is shrinked to bool<br>
<br>
This patch provides such debug information for integer<br>
variables whose type is shrinked to bool by providing<br>
dwarf expression which returns either constant initial<br>
value or other value.<br>
<br>
Patch by Nikola Prica.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D35994" rel="noreferrer" target="_blank">https://reviews.llvm.org/D3599<wbr>4</a><br>
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/AsmPrin<wbr>ter/DwarfExpression.cpp<br>
    llvm/trunk/lib/IR/DebugInfoMet<wbr>adata.cpp<br>
    llvm/trunk/lib/Transforms/IPO/<wbr>GlobalOpt.cpp<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrin<wbr>ter/DwarfExpression.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp?rev=312318&r1=312317&r2=312318&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/CodeGen/A<wbr>smPrinter/DwarfExpression.cpp?<wbr>rev=312318&r1=312317&r2=312318<wbr>&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/CodeGen/AsmPrin<wbr>ter/DwarfExpression.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrin<wbr>ter/DwarfExpression.cpp Fri Sep  1 03:05:27 2017<br>
@@ -338,6 +338,7 @@ void DwarfExpression::addExpression<wbr>(DIEx<br>
       break;<br>
     case dwarf::DW_OP_plus:<br>
     case dwarf::DW_OP_minus:<br>
+    case dwarf::DW_OP_mul:<br>
       emitOp(Op->getOp());<br>
       break;<br>
     case dwarf::DW_OP_deref:<br>
<br>
Modified: llvm/trunk/lib/IR/DebugInfoMet<wbr>adata.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=312318&r1=312317&r2=312318&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/IR/DebugI<wbr>nfoMetadata.cpp?rev=312318&r1=<wbr>312317&r2=312318&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/IR/DebugInfoMet<wbr>adata.cpp (original)<br>
+++ llvm/trunk/lib/IR/DebugInfoMet<wbr>adata.cpp Fri Sep  1 03:05:27 2017<br>
@@ -643,6 +643,7 @@ bool DIExpression::isValid() const {<br>
     case dwarf::DW_OP_plus_uconst:<br>
     case dwarf::DW_OP_plus:<br>
     case dwarf::DW_OP_minus:<br>
+    case dwarf::DW_OP_mul:<br>
     case dwarf::DW_OP_deref:<br>
     case dwarf::DW_OP_xderef:<br>
       break;<br>
<br>
Modified: llvm/trunk/lib/Transforms/IPO/<wbr>GlobalOpt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=312318&r1=312317&r2=312318&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/Transform<wbr>s/IPO/GlobalOpt.cpp?rev=312318<wbr>&r1=312317&r2=312318&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/IPO/<wbr>GlobalOpt.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/IPO/<wbr>GlobalOpt.cpp Fri Sep  1 03:05:27 2017<br>
@@ -36,6 +36,7 @@<br>
 #include "llvm/IR/Module.h"<br>
 #include "llvm/IR/Operator.h"<br>
 #include "llvm/IR/ValueHandle.h"<br>
+#include "llvm/IR/DebugInfoMetadata.h"<br>
 #include "llvm/Pass.h"<br>
 #include "llvm/Support/Debug.h"<br>
 #include "llvm/Support/ErrorHandling.h"<br>
@@ -1603,12 +1604,47 @@ static bool TryToShrinkGlobalToBoolean(G<br>
   assert(InitVal->getType() != Type::getInt1Ty(GV->getContext<wbr>()) &&<br>
          "No reason to shrink to bool!");<br>
<br>
+  SmallVector<DIGlobalVariableEx<wbr>pression *, 1> GVs;<br>
+  GV->getDebugInfo(GVs);<br>
+<br>
   // If initialized to zero and storing one into the global, we can use a cast<br>
   // instead of a select to synthesize the desired value.<br>
   bool IsOneZero = false;<br>
-  if (ConstantInt *CI = dyn_cast<ConstantInt>(OtherVal<wbr>))<br>
+  if (ConstantInt *CI = dyn_cast<ConstantInt>(OtherVal<wbr>)){<br>
     IsOneZero = InitVal->isNullValue() && CI->isOne();<br>
<br>
+    ConstantInt *CIInit = dyn_cast<ConstantInt>(GV->getI<wbr>nitializer());<br>
+    uint64_t ValInit = CIInit->getZExtValue();<br></blockquote><div><br></div><div>I am seeing a crash from a null dereference at this point.  dyn_cast can return in a null pointer and is usually a sign of trouble if it is not check for non-nullness before use.  In this case, CIInit can possibly be null.  I am reducing a test case at the moment, and will update with more details.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    uint64_t ValOther = CI->getZExtValue();<br>
+    uint64_t ValMinus = ValOther - ValInit;<br>
+<br>
+    for(auto *GVe : GVs){<br>
+      DIGlobalVariable *DGV = GVe->getVariable();<br>
+      DIExpression *E = GVe->getExpression();<br>
+<br>
+      // val * (ValOther - ValInit) + ValInit:<br>
+      // DW_OP_deref DW_OP_constu <ValMinus><br>
+      // DW_OP_mul DW_OP_constu <ValInit> DW_OP_plus DW_OP_stack_value<br>
+      E = DIExpression::get(NewGV->getCo<wbr>ntext(),<br>
+                           {dwarf::DW_OP_deref,<br>
+                            dwarf::DW_OP_constu,<br>
+                            ValMinus,<br>
+                            dwarf::DW_OP_mul,<br>
+                            dwarf::DW_OP_constu,<br>
+                            ValInit,<br>
+                            dwarf::DW_OP_plus,<br>
+                            dwarf::DW_OP_stack_value});<br>
+      DIGlobalVariableExpression *DGVE =<br>
+        DIGlobalVariableExpression::ge<wbr>t(NewGV->getContext(), DGV, E);<br>
+      NewGV->addDebugInfo(DGVE);<br>
+    }<br>
+  } else {<br>
+    // FIXME: This will only emit address for debugger on which will<br>
+    // be written only 0 or 1.<br>
+    for(auto *GV : GVs)<br>
+      NewGV->addDebugInfo(GV);<br>
+  }<br>
+<br>
   while (!GV->use_empty()) {<br>
     Instruction *UI = cast<Instruction>(GV->user_bac<wbr>k());<br>
     if (StoreInst *SI = dyn_cast<StoreInst>(UI)) {<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>