[llvm] r312169 - SelectionDAG: Emit correct debug info for multi-register function arguments.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 30 13:51:20 PDT 2017


Author: adrian
Date: Wed Aug 30 13:51:20 2017
New Revision: 312169

URL: http://llvm.org/viewvc/llvm-project?rev=312169&view=rev
Log:
SelectionDAG: Emit correct debug info for multi-register function arguments.

Previously we would just describe the first register and then call it
quits. This patch emits fragment expressions for each register.

<rdar://problem/34075307>

Added:
    llvm/trunk/test/DebugInfo/ARM/sdag-split-arg.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=312169&r1=312168&r2=312169&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Wed Aug 30 13:51:20 2017
@@ -45,6 +45,7 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/DIBuilder.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GetElementPtrTypeIterator.h"
 #include "llvm/IR/GlobalVariable.h"
@@ -4808,6 +4809,26 @@ bool SelectionDAGBuilder::EmitFuncArgume
     // Check if ValueMap has reg number.
     DenseMap<const Value *, unsigned>::iterator VMI = FuncInfo.ValueMap.find(V);
     if (VMI != FuncInfo.ValueMap.end()) {
+      auto *Ty = V->getType();
+      const auto &TLI = DAG.getTargetLoweringInfo();
+      EVT VT = TLI.getValueType(DAG.getDataLayout(), Ty);
+      unsigned NumRegs = TLI.getNumRegisters(Ty->getContext(), VT);
+      if (NumRegs > 1) {
+        // The registers are guaranteed to be allocated in sequence.
+        unsigned Offset = 0;
+        MVT RegisterVT = TLI.getRegisterType(Ty->getContext(), VT);
+        unsigned RegisterSize = RegisterVT.getSizeInBits();
+        for (unsigned I = 0; I != NumRegs; ++I) {
+          Op = MachineOperand::CreateReg(VMI->second + I, false);
+          auto *FragmentExpr = DIExpression::createFragmentExpression(
+              Expr, Offset, RegisterSize);
+          FuncInfo.ArgDbgValues.push_back(
+              BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare,
+                      Op->getReg(), Variable, FragmentExpr));
+          Offset += RegisterSize;
+        }
+        return true;
+      }
       Op = MachineOperand::CreateReg(VMI->second, false);
       IsIndirect = IsDbgDeclare;
     }

Added: llvm/trunk/test/DebugInfo/ARM/sdag-split-arg.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/ARM/sdag-split-arg.ll?rev=312169&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/ARM/sdag-split-arg.ll (added)
+++ llvm/trunk/test/DebugInfo/ARM/sdag-split-arg.ll Wed Aug 30 13:51:20 2017
@@ -0,0 +1,77 @@
+; RUN: llc -filetype=asm %s -o - | FileCheck %s
+; Test large integral function arguments passed in multiple registers.
+;
+; Generated from (-Os):
+;
+; signed long long g;
+; void write(signed long long offset);
+; signed long long foo(signed long long offset) {
+;   if (offset != g)
+;     write(offset);
+;   return offset;
+; }
+source_filename = "test.ii"
+target datalayout = "e-m:o-p:32:32-i64:64-a:0:32-n32-S128"
+target triple = "thumbv7k-apple-watchos2.0.0"
+
+ at g = local_unnamed_addr global i64 0, align 8, !dbg !0
+
+; Function Attrs: optsize ssp
+define i64 @_Z3foox(i64 returned) local_unnamed_addr #0 !dbg !13 {
+  tail call void @llvm.dbg.value(metadata i64 %0, metadata !17, metadata !DIExpression()), !dbg !18
+  ; CHECK: @DEBUG_VALUE: foo:offset <- [DW_OP_LLVM_fragment 0 32] %R5
+  ; CHECK: @DEBUG_VALUE: foo:offset <- [DW_OP_LLVM_fragment 32 32] %R4
+
+  %2 = load i64, i64* @g, align 8, !dbg !19, !tbaa !21
+  %3 = icmp eq i64 %2, %0, !dbg !19
+  br i1 %3, label %5, label %4, !dbg !25
+
+; <label>:4:                                      ; preds = %1
+  tail call void @_Z5writex(i64 %0) #3, !dbg !26
+  br label %5, !dbg !26
+
+; <label>:5:                                      ; preds = %1, %4
+  ret i64 %0, !dbg !27
+}
+
+; Function Attrs: optsize
+declare void @_Z5writex(i64) local_unnamed_addr #1
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.value(metadata, metadata, metadata) #2
+
+attributes #0 = { optsize ssp }
+attributes #1 = { optsize }
+attributes #2 = { nounwind readnone speculatable }
+attributes #3 = { optsize }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8, !9, !10, !11}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 6.0.0 (trunk 312148) (llvm/trunk 312165)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "test.ii", directory: "/")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
+!7 = !{i32 2, !"Dwarf Version", i32 4}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"wchar_size", i32 4}
+!10 = !{i32 1, !"min_enum_size", i32 4}
+!11 = !{i32 7, !"PIC Level", i32 2}
+!13 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foox", scope: !3, file: !3, line: 3, type: !14, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !2, variables: !16)
+!14 = !DISubroutineType(types: !15)
+!15 = !{!6, !6}
+!16 = !{!17}
+!17 = !DILocalVariable(name: "offset", arg: 1, scope: !13, file: !3, line: 3, type: !6)
+!18 = !DILocation(line: 3, scope: !13)
+!19 = !DILocation(line: 4, scope: !20)
+!20 = distinct !DILexicalBlock(scope: !13, file: !3, line: 4)
+!21 = !{!22, !22, i64 0}
+!22 = !{!"long long", !23, i64 0}
+!23 = !{!"omnipotent char", !24, i64 0}
+!24 = !{!"Simple C++ TBAA"}
+!25 = !DILocation(line: 4, scope: !13)
+!26 = !DILocation(line: 5, scope: !20)
+!27 = !DILocation(line: 6, scope: !13)




More information about the llvm-commits mailing list