[llvm] r331086 - Fix a bug in GlobalOpt's handling of DIExpressions.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 27 14:41:37 PDT 2018
Author: adrian
Date: Fri Apr 27 14:41:36 2018
New Revision: 331086
URL: http://llvm.org/viewvc/llvm-project?rev=331086&view=rev
Log:
Fix a bug in GlobalOpt's handling of DIExpressions.
This patch adds support for fragment expressions
TryToShrinkGlobalToBoolean() which were previously just dropped.
Thanks to Reid Kleckner for providing me a reproducer!
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/IR/DebugInfoMetadata.cpp
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/lib/Transforms/Utils/Local.cpp
llvm/trunk/test/Transforms/GlobalOpt/integer-bool-dwarf.ll
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=331086&r1=331085&r2=331086&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Fri Apr 27 14:41:36 2018
@@ -2402,9 +2402,9 @@ public:
/// Prepend \p DIExpr with the given opcodes and optionally turn it into a
/// stack value.
- static DIExpression *doPrepend(const DIExpression *DIExpr,
- SmallVectorImpl<uint64_t> &Ops,
- bool StackValue = false);
+ static DIExpression *prependOpcodes(const DIExpression *DIExpr,
+ SmallVectorImpl<uint64_t> &Ops,
+ bool StackValue = false);
/// Create a DIExpression to describe one part of an aggregate variable that
/// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=331086&r1=331085&r2=331086&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Fri Apr 27 14:41:36 2018
@@ -785,12 +785,12 @@ DIExpression *DIExpression::prepend(cons
if (DerefAfter)
Ops.push_back(dwarf::DW_OP_deref);
- return doPrepend(Expr, Ops, StackValue);
+ return prependOpcodes(Expr, Ops, StackValue);
}
-DIExpression *DIExpression::doPrepend(const DIExpression *Expr,
- SmallVectorImpl<uint64_t> &Ops,
- bool StackValue) {
+DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
+ SmallVectorImpl<uint64_t> &Ops,
+ bool StackValue) {
if (Expr)
for (auto Op : Expr->expr_ops()) {
// A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=331086&r1=331085&r2=331086&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Fri Apr 27 14:41:36 2018
@@ -1668,15 +1668,11 @@ static bool TryToShrinkGlobalToBoolean(G
// 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});
+ SmallVector<uint64_t, 12> Ops = {
+ dwarf::DW_OP_deref, dwarf::DW_OP_constu, ValMinus,
+ dwarf::DW_OP_mul, dwarf::DW_OP_constu, ValInit,
+ dwarf::DW_OP_plus};
+ E = DIExpression::prependOpcodes(E, Ops, DIExpression::WithStackValue);
DIGlobalVariableExpression *DGVE =
DIGlobalVariableExpression::get(NewGV->getContext(), DGV, E);
NewGV->addDebugInfo(DGVE);
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=331086&r1=331085&r2=331086&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Fri Apr 27 14:41:36 2018
@@ -1522,8 +1522,8 @@ void llvm::salvageDebugInfo(Instruction
auto doSalvage = [&](DbgInfoIntrinsic *DII, SmallVectorImpl<uint64_t> &Ops) {
auto *DIExpr = DII->getExpression();
- DIExpr = DIExpression::doPrepend(DIExpr, Ops,
- DIExpression::WithStackValue);
+ DIExpr =
+ DIExpression::prependOpcodes(DIExpr, Ops, DIExpression::WithStackValue);
DII->setOperand(0, wrapMD(I.getOperand(0)));
DII->setOperand(2, MetadataAsValue::get(I.getContext(), DIExpr));
DEBUG(dbgs() << "SALVAGE: " << *DII << '\n');
Modified: llvm/trunk/test/Transforms/GlobalOpt/integer-bool-dwarf.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/integer-bool-dwarf.ll?rev=331086&r1=331085&r2=331086&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/integer-bool-dwarf.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/integer-bool-dwarf.ll Fri Apr 27 14:41:36 2018
@@ -1,6 +1,10 @@
;RUN: opt -S -globalopt -f %s | FileCheck %s
-;CHECK: !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression(DW_OP_deref, DW_OP_constu, 111, DW_OP_mul, DW_OP_constu, 0, DW_OP_plus, DW_OP_stack_value))
+;CHECK: @foo = internal unnamed_addr global i1 false, align 4, !dbg ![[VAR:.*]]
+;CHECK: ![[VAR]] = !DIGlobalVariableExpression(var: !1, expr:
+;CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_constu, 111, DW_OP_mul,
+;CHECK-SAME: DW_OP_constu, 0, DW_OP_plus, DW_OP_stack_value,
+;CHECK-SAME: DW_OP_LLVM_fragment, 0, 1))
@foo = internal global i32 0, align 4, !dbg !0
@@ -31,7 +35,7 @@ attributes #0 = { noinline nounwind optn
!llvm.module.flags = !{!7, !8, !9}
!llvm.ident = !{!10}
-!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression(DW_OP_LLVM_fragment, 0, 1))
!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !6, isLocal: true, isDefinition: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
!3 = !DIFile(filename: "integer-bool-dwarf.c", directory: "/")
More information about the llvm-commits
mailing list