[PATCH] D35994: Debug info for variables whose type is shrinked to bool

Strahinja Petrovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 1 03:06:53 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL312318: Debug info for variables whose type is shrinked to bool (authored by spetrovic).

Changed prior to commit:
  https://reviews.llvm.org/D35994?vs=113408&id=113526#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35994

Files:
  llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
  llvm/trunk/lib/IR/DebugInfoMetadata.cpp
  llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp


Index: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
===================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp
@@ -643,6 +643,7 @@
     case dwarf::DW_OP_plus_uconst:
     case dwarf::DW_OP_plus:
     case dwarf::DW_OP_minus:
+    case dwarf::DW_OP_mul:
     case dwarf::DW_OP_deref:
     case dwarf::DW_OP_xderef:
       break;
Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -338,6 +338,7 @@
       break;
     case dwarf::DW_OP_plus:
     case dwarf::DW_OP_minus:
+    case dwarf::DW_OP_mul:
       emitOp(Op->getOp());
       break;
     case dwarf::DW_OP_deref:
Index: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
@@ -36,6 +36,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
 #include "llvm/IR/ValueHandle.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -1603,12 +1604,47 @@
   assert(InitVal->getType() != Type::getInt1Ty(GV->getContext()) &&
          "No reason to shrink to bool!");
 
+  SmallVector<DIGlobalVariableExpression *, 1> GVs;
+  GV->getDebugInfo(GVs);
+
   // If initialized to zero and storing one into the global, we can use a cast
   // instead of a select to synthesize the desired value.
   bool IsOneZero = false;
-  if (ConstantInt *CI = dyn_cast<ConstantInt>(OtherVal))
+  if (ConstantInt *CI = dyn_cast<ConstantInt>(OtherVal)){
     IsOneZero = InitVal->isNullValue() && CI->isOne();
 
+    ConstantInt *CIInit = dyn_cast<ConstantInt>(GV->getInitializer());
+    uint64_t ValInit = CIInit->getZExtValue();
+    uint64_t ValOther = CI->getZExtValue();
+    uint64_t ValMinus = ValOther - ValInit;
+
+    for(auto *GVe : GVs){
+      DIGlobalVariable *DGV = GVe->getVariable();
+      DIExpression *E = GVe->getExpression();
+
+      // val * (ValOther - ValInit) + ValInit:
+      // DW_OP_deref DW_OP_constu <ValMinus>
+      // DW_OP_mul DW_OP_constu <ValInit> DW_OP_plus DW_OP_stack_value
+      E = DIExpression::get(NewGV->getContext(),
+                           {dwarf::DW_OP_deref,
+                            dwarf::DW_OP_constu,
+                            ValMinus,
+                            dwarf::DW_OP_mul,
+                            dwarf::DW_OP_constu,
+                            ValInit,
+                            dwarf::DW_OP_plus,
+                            dwarf::DW_OP_stack_value});
+      DIGlobalVariableExpression *DGVE =
+        DIGlobalVariableExpression::get(NewGV->getContext(), DGV, E);
+      NewGV->addDebugInfo(DGVE);
+    }
+  } else {
+    // FIXME: This will only emit address for debugger on which will
+    // be written only 0 or 1.
+    for(auto *GV : GVs)
+      NewGV->addDebugInfo(GV);
+  }
+
   while (!GV->use_empty()) {
     Instruction *UI = cast<Instruction>(GV->user_back());
     if (StoreInst *SI = dyn_cast<StoreInst>(UI)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35994.113526.patch
Type: text/x-patch
Size: 3290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170901/942a33c6/attachment-0001.bin>


More information about the llvm-commits mailing list