[llvm] r359535 - [DebugInfo] DW_OP_deref_size in PrologEpilogInserter.
Markus Lavin via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 00:58:58 PDT 2019
Author: markus
Date: Tue Apr 30 00:58:57 2019
New Revision: 359535
URL: http://llvm.org/viewvc/llvm-project?rev=359535&view=rev
Log:
[DebugInfo] DW_OP_deref_size in PrologEpilogInserter.
The PrologEpilogInserter need to insert a DW_OP_deref_size before
prepending a memory location expression to an already implicit
expression to avoid having the existing expression act on the memory
address instead of the value behind it.
The reason for using DW_OP_deref_size and not plain DW_OP_deref is that
big-endian targets need to read the right size as simply truncating a
larger read would yield the wrong result (LSB bytes are not at the lower
address).
This re-commit fixes issues reported in the first one. Namely deref was
inserted under wrong conditions and additionally the deref_size argument
was incorrectly encoded.
Differential Revision: https://reviews.llvm.org/D59687
Added:
llvm/trunk/test/CodeGen/X86/prologepilog_deref_size.mir
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
llvm/trunk/lib/IR/DebugInfoMetadata.cpp
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=359535&r1=359534&r2=359535&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Tue Apr 30 00:58:57 2019
@@ -2510,6 +2510,9 @@ public:
/// Return whether this is a piece of an aggregate variable.
bool isFragment() const { return getFragmentInfo().hasValue(); }
+ /// Return whether this is an implicit location description.
+ bool isImplicit() const;
+
/// Append \p Ops with operations to apply the \p Offset.
static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset);
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=359535&r1=359534&r2=359535&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Apr 30 00:58:57 2019
@@ -179,6 +179,10 @@ void DebugLocDwarfExpression::emitUnsign
BS.EmitULEB128(Value, Twine(Value));
}
+void DebugLocDwarfExpression::emitData1(uint8_t Value) {
+ BS.EmitInt8(Value, Twine(Value));
+}
+
void DebugLocDwarfExpression::emitBaseTypeRef(uint64_t Idx) {
assert(Idx < (1ULL << (ULEB128PadSize * 7)) && "Idx wont fit");
BS.EmitULEB128(Idx, Twine(Idx), ULEB128PadSize);
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp?rev=359535&r1=359534&r2=359535&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp Tue Apr 30 00:58:57 2019
@@ -434,6 +434,10 @@ void DwarfExpression::addExpression(DIEx
assert(LocationKind != Register);
emitOp(dwarf::DW_OP_xderef);
break;
+ case dwarf::DW_OP_deref_size:
+ emitOp(dwarf::DW_OP_deref_size);
+ emitData1(Op->getArg(0));
+ break;
default:
llvm_unreachable("unhandled opcode found in expression");
}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.h?rev=359535&r1=359534&r2=359535&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.h Tue Apr 30 00:58:57 2019
@@ -139,6 +139,8 @@ protected:
/// Emit a raw unsigned value.
virtual void emitUnsigned(uint64_t Value) = 0;
+ virtual void emitData1(uint8_t Value) = 0;
+
virtual void emitBaseTypeRef(uint64_t Idx) = 0;
/// Emit a normalized unsigned constant.
@@ -264,6 +266,7 @@ class DebugLocDwarfExpression final : pu
void emitOp(uint8_t Op, const char *Comment = nullptr) override;
void emitSigned(int64_t Value) override;
void emitUnsigned(uint64_t Value) override;
+ void emitData1(uint8_t Value) override;
void emitBaseTypeRef(uint64_t Idx) override;
bool isFrameRegister(const TargetRegisterInfo &TRI,
unsigned MachineReg) override;
@@ -281,6 +284,7 @@ const AsmPrinter &AP;
void emitOp(uint8_t Op, const char *Comment = nullptr) override;
void emitSigned(int64_t Value) override;
void emitUnsigned(uint64_t Value) override;
+ void emitData1(uint8_t Value) override;
void emitBaseTypeRef(uint64_t Idx) override;
bool isFrameRegister(const TargetRegisterInfo &TRI,
unsigned MachineReg) override;
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=359535&r1=359534&r2=359535&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Tue Apr 30 00:58:57 2019
@@ -64,6 +64,10 @@ void DIEDwarfExpression::emitUnsigned(ui
CU.addUInt(DIE, dwarf::DW_FORM_udata, Value);
}
+void DIEDwarfExpression::emitData1(uint8_t Value) {
+ CU.addUInt(DIE, dwarf::DW_FORM_data1, Value);
+}
+
void DIEDwarfExpression::emitBaseTypeRef(uint64_t Idx) {
CU.addBaseTypeRef(DIE, Idx);
}
Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=359535&r1=359534&r2=359535&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Tue Apr 30 00:58:57 2019
@@ -1854,6 +1854,11 @@ bool MIParser::parseDIExpression(MDNode
Elements.push_back(Op);
continue;
}
+ if (unsigned Enc = dwarf::getAttributeEncoding(Token.stringValue())) {
+ lex();
+ Elements.push_back(Enc);
+ continue;
+ }
return error(Twine("invalid DWARF op '") + Token.stringValue() + "'");
}
Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=359535&r1=359534&r2=359535&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Tue Apr 30 00:58:57 2019
@@ -1172,12 +1172,26 @@ void PEI::replaceFrameIndices(MachineBas
assert(i == 0 && "Frame indices can only appear as the first "
"operand of a DBG_VALUE machine instruction");
unsigned Reg;
+ unsigned FrameIdx = MI.getOperand(0).getIndex();
+ unsigned Size = MF.getFrameInfo().getObjectSize(FrameIdx);
+
int64_t Offset =
- TFI->getFrameIndexReference(MF, MI.getOperand(0).getIndex(), Reg);
+ TFI->getFrameIndexReference(MF, FrameIdx, Reg);
MI.getOperand(0).ChangeToRegister(Reg, false /*isDef*/);
MI.getOperand(0).setIsDebug();
- auto *DIExpr = DIExpression::prepend(MI.getDebugExpression(),
- DIExpression::NoDeref, Offset);
+
+ const DIExpression *DIExpr = MI.getDebugExpression();
+ // If we have DBG_VALUE that is indirect and has a Implicit location
+ // expression need to insert a deref before prepending a Memory
+ // location expression. Also after doing this we change the DBG_VALUE
+ // to be direct.
+ if (MI.isIndirectDebugValue() && DIExpr->isImplicit()) {
+ SmallVector<uint64_t, 2> Ops = {dwarf::DW_OP_deref_size, Size};
+ DIExpr = DIExpression::prependOpcodes(DIExpr, Ops, DIExpression::WithStackValue);
+ // Make the DBG_VALUE direct.
+ MI.getOperand(1).ChangeToRegister(0, false);
+ }
+ DIExpr = DIExpression::prepend(DIExpr, DIExpression::NoDeref, Offset);
MI.getOperand(3).setMetadata(DIExpr);
continue;
}
Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=359535&r1=359534&r2=359535&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Tue Apr 30 00:58:57 2019
@@ -833,6 +833,7 @@ unsigned DIExpression::ExprOperand::getS
case dwarf::DW_OP_LLVM_fragment:
return 3;
case dwarf::DW_OP_constu:
+ case dwarf::DW_OP_deref_size:
case dwarf::DW_OP_plus_uconst:
return 2;
default:
@@ -889,6 +890,7 @@ bool DIExpression::isValid() const {
case dwarf::DW_OP_shr:
case dwarf::DW_OP_shra:
case dwarf::DW_OP_deref:
+ case dwarf::DW_OP_deref_size:
case dwarf::DW_OP_xderef:
case dwarf::DW_OP_lit0:
case dwarf::DW_OP_not:
@@ -899,6 +901,19 @@ bool DIExpression::isValid() const {
return true;
}
+bool DIExpression::isImplicit() const {
+ unsigned N = getNumElements();
+ if (isValid() && N > 0) {
+ switch (getElement(N-1)) {
+ case dwarf::DW_OP_stack_value: return true;
+ case dwarf::DW_OP_LLVM_fragment:
+ return N > 1 && getElement(N-2) == dwarf::DW_OP_stack_value;
+ default: break;
+ }
+ }
+ return false;
+}
+
Optional<DIExpression::FragmentInfo>
DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
for (auto I = Start; I != End; ++I)
Added: llvm/trunk/test/CodeGen/X86/prologepilog_deref_size.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/prologepilog_deref_size.mir?rev=359535&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/prologepilog_deref_size.mir (added)
+++ llvm/trunk/test/CodeGen/X86/prologepilog_deref_size.mir Tue Apr 30 00:58:57 2019
@@ -0,0 +1,59 @@
+# RUN: llc -run-pass=prologepilog -o - %s | FileCheck %s
+--- |
+ ; ModuleID = 'dbg.opt.ll'
+ source_filename = "dbg.c"
+ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+ target triple = "x86_64-unknown-linux-gnu"
+
+ ; Function Attrs: noinline nounwind uwtable
+ define dso_local zeroext i16 @foo(i16 zeroext %d0, i16 zeroext %d1, i16 zeroext %d2, i16 zeroext %d3, i16 zeroext %d4, i16 zeroext %d5, i16 zeroext %d6, i16 zeroext %d7, i16 zeroext %d8, i16 signext %x) #0 !dbg !7 {
+ entry:
+ call void @llvm.dbg.value(metadata i16 %x, metadata !32, metadata !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value)), !dbg !34
+ ret i16 %x
+ }
+
+ ; Function Attrs: nounwind readnone speculatable
+ declare void @llvm.dbg.value(metadata, metadata, metadata) #1
+
+ attributes #0 = { noinline nounwind uwtable }
+ attributes #1 = { nounwind readnone speculatable }
+
+ !llvm.dbg.cu = !{!0}
+ !llvm.module.flags = !{!3, !4, !5}
+ !llvm.ident = !{!6}
+
+ !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+ !1 = !DIFile(filename: "dbg.c", directory: "/tmp")
+ !2 = !{}
+ !3 = !{i32 2, !"Dwarf Version", i32 4}
+ !4 = !{i32 2, !"Debug Info Version", i32 3}
+ !5 = !{i32 1, !"wchar_size", i32 4}
+ !6 = !{!"clang version 9.0.0"}
+ !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+ !8 = !DISubroutineType(types: !9)
+ !9 = !{!10, !10, !10, !10, !10, !10, !10, !10, !10, !10, !10}
+ !10 = !DIDerivedType(tag: DW_TAG_typedef, name: "T", file: !1, line: 1, baseType: !11)
+ !11 = !DIBasicType(name: "signed short", size: 16, encoding: DW_ATE_signed)
+ !32 = !DILocalVariable(name: "y", scope: !7, file: !1, line: 3, type: !33)
+ !33 = !DIBasicType(name: "signed int", size: 32, encoding: DW_ATE_signed)
+ !34 = !DILocation(line: 3, column: 20, scope: !7)
+
+...
+---
+name: foo
+tracksRegLiveness: true
+fixedStack:
+ - { id: 0, type: default, offset: 24, size: 2, alignment: 8, stack-id: 0,
+ isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
+ debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+stack: []
+constants: []
+machineFunctionInfo: {}
+body: |
+ bb.0.entry:
+ renamable $ax = MOV16rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (load 2 from %fixed-stack.0, align 8)
+ DBG_VALUE %fixed-stack.0, 0, !32, !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value), debug-location !34
+ RET 0, $ax
+...
+# CHECK: machineFunctionInfo
+# CHECK: DBG_VALUE $rsp, $noreg, !12, !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref_size, 2, DW_OP_LLVM_convert, 16, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value), debug-location !14
More information about the llvm-commits
mailing list