[llvm] r312318 - Debug info for variables whose type is shrinked to bool
Richard Trieu via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 5 14:44:11 PDT 2017
+Nikola
On Fri, Sep 1, 2017 at 3:05 AM, Strahinja Petrovic via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: spetrovic
> Date: Fri Sep 1 03:05:27 2017
> New Revision: 312318
>
> URL: http://llvm.org/viewvc/llvm-project?rev=312318&view=rev
> Log:
> Debug info for variables whose type is shrinked to bool
>
> This patch provides such debug information for integer
> variables whose type is shrinked to bool by providing
> dwarf expression which returns either constant initial
> value or other value.
>
> Patch by Nikola Prica.
>
> Differential Revision: https://reviews.llvm.org/D35994
>
> Modified:
> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
> llvm/trunk/lib/IR/DebugInfoMetadata.cpp
> llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/A
> smPrinter/DwarfExpression.cpp?rev=312318&r1=312317&r2=312318&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp Fri Sep 1
> 03:05:27 2017
> @@ -338,6 +338,7 @@ void DwarfExpression::addExpression(DIEx
> 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:
>
> Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugI
> nfoMetadata.cpp?rev=312318&r1=312317&r2=312318&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
> +++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Fri Sep 1 03:05:27 2017
> @@ -643,6 +643,7 @@ bool DIExpression::isValid() const {
> 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;
>
> Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transform
> s/IPO/GlobalOpt.cpp?rev=312318&r1=312317&r2=312318&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Fri Sep 1 03:05:27 2017
> @@ -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 @@ static bool TryToShrinkGlobalToBoolean(G
> 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();
>
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.
> + 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)) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170905/0a020c0a/attachment.html>
More information about the llvm-commits
mailing list